DataEntry.Uni Items passed in a list, w/o limits, Cfg with arrays, TODO: TestStartEndForm

This commit is contained in:
Milan Hanajik 2023-05-12 15:36:27 +02:00
parent b67857f658
commit b2a7cfb0d4
8 changed files with 1136 additions and 1270 deletions

View File

@ -249,17 +249,22 @@ namespace TBF
public string[] LastBgComm1;
public string[] LastBgComm2;
public string[] LastBgComm3;
///
public string[] LastBgColA;
public string[] LastBgColB;
public string[] LastBgColC;
public string[] LastBgColD;
public string[] LastBgColE;
///
public string[] LastEnComm1;
public string[] LastEnComm2;
public string[] LastEnComm3;
///
public string[] LastEnColA;
public string[] LastEnColB;
public string[] LastEnColC;
public string[] LastEnColD;
public string[] LastEnColE;
/// Purchase order history
public string[] PurchaseOrderHistory;

View File

@ -71,8 +71,9 @@ namespace TBF.Rig.Configs.ParamsProvider
foreach (var p in parents) parentComboBox.Items.Add(p.Name);
}
editors = new Control[paramsProvider.ParamsCount()];
for (int i = 0; i < paramsProvider.ParamsCount(); i++)
int paramsCount = paramsProvider.ParamsCount();
editors = new Control[paramsCount];
for (int i = 0; i < paramsCount; i++)
{
ICollection<string> values = paramsProvider.ParamValues(i);
if (values == null)
@ -130,7 +131,8 @@ namespace TBF.Rig.Configs.ParamsProvider
if (parentComboBox.Visible) parentComboBox.Text = Config.ParentName;
paramsListViewEx.Items.Clear();
for (int i = 0; i < paramsProvider.ParamsCount(); i++)
int paramsCount = paramsProvider.ParamsCount();
for (int i = 0; i < paramsCount; i++)
{
ListViewItem lvi = new ListViewItem(paramsProvider.ParamName(i));
lvi.SubItems.Add(paramsProvider.ToString(i));

View File

@ -21,9 +21,7 @@ namespace TBF.Rig.DataEntry.Uni
readonly int lineSize;
readonly Sz sz;
readonly bool isLrOrder; /// true = controls obtain focus after ENTER key in left-right order, false = top-down order
readonly DEItem item1;
readonly DEItem item2;
readonly DEItem item3;
readonly IList<DEItem> commonItems;
readonly IList<DEItem> colItems;
readonly bool isEnd;
readonly string formCloseKeys;
@ -32,6 +30,7 @@ namespace TBF.Rig.DataEntry.Uni
readonly WaterMeter firstValidWM;
readonly int wmsCount;
readonly int linesCount;
readonly int commonItemsCount;
/// Size and layout related values
readonly Font font;
@ -45,13 +44,14 @@ namespace TBF.Rig.DataEntry.Uni
readonly int checkBoxWid;
/// UI elements
readonly ComboBox comboBox1; /// Combo box for the 1st common item
readonly ComboBox comboBox2; /// Combo box for the 2nd common item
readonly ComboBox comboBox3; /// Combo box for the 3rd common item
readonly Label[] commonLabels;
readonly ComboBox[] commonComboBoxes;
readonly Label[] labels; /// Labels for water meter numbers
readonly ComboBox[,] comboBoxes; /// Combo boxes for values in columns
readonly CheckBox[] checkBoxes; /// Check boxes for water meter enable/disable
readonly LocalSettings ls;
bool isHandlersEnabled; /// Initially false, set to true after ComboBoxes are filled with data
/// Set to 'true' when the form closes
@ -74,7 +74,7 @@ namespace TBF.Rig.DataEntry.Uni
/// </summary>
/// <param name="wmsCount">Number of text boxes for serial numbers</param>
public CycleBgEnForm(IList<WaterMeter> waterMeters, int lineSize, string title, Sz sz, bool isLrOrder, string formCloseKeys,
DEItem item1, DEItem item2, DEItem item3, IList<DEItem> colItems, bool isEnd = false)
IList<DEItem> commonItems, IList<DEItem> colItems, bool isEnd = false)
{
InitializeComponent();
ControlBox = false;
@ -86,17 +86,20 @@ namespace TBF.Rig.DataEntry.Uni
this.sz = sz;
this.isLrOrder = isLrOrder;
this.formCloseKeys = !string.IsNullOrEmpty(formCloseKeys) ? formCloseKeys : string.Empty;
this.item1 = item1;
this.item2 = item2;
this.item3 = item3;
this.commonItems = commonItems;
this.colItems = colItems;
this.isEnd = isEnd;
ls = Program.LocalSettings;
/// Readonly variables derived from arguments
commonItemsCount = (commonItems == null) ? 0 : commonItems.Count;
wmsCount = (waterMeters == null) ? 0 : waterMeters.Count;
linesCount = (wmsCount + Math.Max(1, lineSize) - 1) / Math.Max(1, lineSize);
firstValidWM = (waterMeters != null) ? waterMeters.FirstOrDefault(x => (x != null && !x.Disabled)) : null;
///
commonLabels = new Label[commonItemsCount];
commonComboBoxes = new ComboBox[commonItemsCount];
labels = new Label[wmsCount];
comboBoxes = new ComboBox[colItems.Count, wmsCount];
checkBoxes = new CheckBox[wmsCount];
@ -146,128 +149,63 @@ namespace TBF.Rig.DataEntry.Uni
///
/// Group box with common items
///
int groupBoxHeight = 0;
int groupBoxWidth = 0;
if (item1.Content != Content.None)
int groupBoxHeight = 0;
if (commonItemsCount > 0)
{
var groupBox = new GroupBox();
int label1Width = Convert.ToInt32(Graphics.FromImage(new Bitmap(1, 1)).MeasureString(item1.Caption, font).Width);
var label1 = new Label
int labelsWidth = 0;
for (int ix = 0; ix < commonItemsCount; ix++)
{
Text = item1.Caption,
Font = font,
Location = new Point(margin, 2 * spacing),
Size = new Size(label1Width + spacing, meterHeight),
TextAlign = ContentAlignment.MiddleLeft,
TabIndex = tabIndex++,
Parent = groupBox,
};
groupBox.Controls.Add(label1);
int labelsWidth = label1Width;
if (item2.Content != Content.None)
{
int label2Width = Convert.ToInt32(Graphics.FromImage(new Bitmap(1, 1)).MeasureString(item2.Caption, font).Width);
var label2 = new Label
int oneLabelWidth = Convert.ToInt32(Graphics.FromImage(new Bitmap(1, 1)).MeasureString(commonItems[ix].Caption, font).Width);
var oneLabel = new Label
{
Text = item2.Caption,
Text = commonItems[ix].Caption,
Font = font,
Location = new Point(margin, 3 * spacing + meterHeight),
Size = new Size(label2Width + spacing, meterHeight),
Location = new Point(margin, (ix + 2) * spacing + ix * meterHeight),
Size = new Size(oneLabelWidth + spacing, meterHeight),
TextAlign = ContentAlignment.MiddleLeft,
TabIndex = tabIndex++,
Parent = groupBox,
};
groupBox.Controls.Add(label2);
labelsWidth = Math.Max(labelsWidth, label2Width);
if (item3.Content != Content.None)
{
int label3Width = Convert.ToInt32(Graphics.FromImage(new Bitmap(1, 1)).MeasureString(item3.Caption, font).Width);
var label3 = new Label
{
Text = item3.Caption,
Font = font,
Location = new Point(margin, 4 * spacing + 2 * meterHeight),
Size = new Size(label3Width + spacing, meterHeight),
TextAlign = ContentAlignment.MiddleLeft,
TabIndex = tabIndex++,
Parent = groupBox,
};
groupBox.Controls.Add(label3);
labelsWidth = Math.Max(labelsWidth, label3Width);
}
groupBox.Controls.Add(oneLabel);
labelsWidth = Math.Max(labelsWidth, oneLabelWidth);
}
comboBox1 = new ComboBox
int combosWidth = 0;
for (int ix = 0; ix < commonItemsCount; ix++)
{
Name = "-1~1",
Location = new Point(margin + spacing + labelsWidth, 2 * spacing),
Size = new Size(item1.Width, meterHeight),
Enabled = (item1.Action != Action.LoadReadOnly),
Font = font,
TabIndex = tabIndex++,
Parent = groupBox,
};
comboBox1.SelectedIndexChanged += new System.EventHandler(this.comboBox_SelectedIndexChanged);
comboBox1.TextChanged += new System.EventHandler(this.comboBox_TextChanged);
comboBox1.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.comboBox_KeyPress);
AddHistoryToCombo(comboBox1, isEnd ? Program.LocalSettings.LastEnComm1 : Program.LocalSettings.LastBgComm1);
groupBox.Controls.Add(comboBox1);
int combosWidth = item1.Width;
if (item2.Content != Content.None)
{
comboBox2 = new ComboBox
var cb = new ComboBox
{
Name = "-1~2",
Location = new Point(margin + spacing + labelsWidth, 3 * spacing + meterHeight),
Size = new Size(item2.Width, meterHeight),
Enabled = (item2.Action != Action.LoadReadOnly),
Name = string.Format("-1~{0}", ix + 1),
Location = new Point(margin + spacing + labelsWidth, (ix + 2) * spacing + ix * meterHeight),
Size = new Size(commonItems[ix].Width, meterHeight),
Enabled = (commonItems[ix].Action != Ac.LoadReadOnly),
Font = font,
TabIndex = tabIndex++,
Parent = groupBox,
};
comboBox2.SelectedIndexChanged += new System.EventHandler(this.comboBox_SelectedIndexChanged);
comboBox2.TextChanged += new System.EventHandler(this.comboBox_TextChanged);
comboBox2.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.comboBox_KeyPress);
cb.SelectedIndexChanged += new System.EventHandler(this.comboBox_SelectedIndexChanged);
cb.TextChanged += new System.EventHandler(this.comboBox_TextChanged);
cb.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.comboBox_KeyPress);
AddHistoryToCombo(comboBox2, isEnd ? Program.LocalSettings.LastEnComm2 : Program.LocalSettings.LastBgComm2);
groupBox.Controls.Add(comboBox2);
combosWidth = Math.Max(combosWidth, item2.Width);
if (item3.Content != Content.None)
switch (ix)
{
comboBox3 = new ComboBox
{
Name = "-1~3",
Location = new Point(margin + spacing + labelsWidth, 4 * spacing + 2 * meterHeight),
Size = new Size(item3.Width, meterHeight),
Enabled = (item3.Action != Action.LoadReadOnly),
Font = font,
TabIndex = tabIndex++,
Parent = groupBox,
};
comboBox3.SelectedIndexChanged += new System.EventHandler(this.comboBox_SelectedIndexChanged);
comboBox3.TextChanged += new System.EventHandler(this.comboBox_TextChanged);
comboBox3.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.comboBox_KeyPress);
AddHistoryToCombo(comboBox3, isEnd ? Program.LocalSettings.LastEnComm3 : Program.LocalSettings.LastBgComm3);
groupBox.Controls.Add(comboBox3);
combosWidth = Math.Max(combosWidth, item3.Width);
case 0: AddHistoryToCombo(cb, isEnd ? ls.LastEnComm1 : ls.LastBgComm1); break;
case 1: AddHistoryToCombo(cb, isEnd ? ls.LastEnComm2 : ls.LastBgComm2); break;
case 2: AddHistoryToCombo(cb, isEnd ? ls.LastEnComm3 : ls.LastBgComm3); break;
}
}
commonComboBoxes[ix] = cb;
groupBox.Controls.Add(cb);
combosWidth = Math.Max(combosWidth, commonItems[ix].Width);
}
///
groupBox.Location = new Point(margin, margin - spacing);
groupBoxWidth = labelsWidth + combosWidth + 2 * margin + spacing;
groupBoxHeight = (item3.Content != Content.None) ? 3 * meterHeight + 5 * spacing
: (item2.Content != Content.None) ? 2 * meterHeight + 4 * spacing
: meterHeight + 3 * spacing;
groupBoxHeight = commonItemsCount * meterHeight + (commonItemsCount + 2) * spacing;
groupBox.Size = new Size(groupBoxWidth, groupBoxHeight);
groupBox.Font = font;
groupBox.TabIndex = tabIndex++;
@ -331,7 +269,7 @@ namespace TBF.Rig.DataEntry.Uni
Name = string.Format("{0}~{1}", k, wmPos0),
Location = new Point(left, top),
Size = new Size(ci.Width, meterHeight),
Enabled = (ci.Action != Action.LoadReadOnly && !waterMeters[wmPos0].Disabled),
Enabled = (ci.Action != Ac.LoadReadOnly && !waterMeters[wmPos0].Disabled),
Font = font,
TabIndex = tabIndex++,
Parent = this,
@ -373,19 +311,17 @@ namespace TBF.Rig.DataEntry.Uni
InitializeBoxes();
/// Set focus to the first enabled ComboBox
if (comboBox1 != null && comboBox1.Enabled)
bool activeControlFound = false;
for (int ix = 0; ix < commonItemsCount; ix++)
{
ActiveControl = comboBox1;
if (commonComboBoxes[ix].Enabled)
{
ActiveControl = commonComboBoxes[ix];
activeControlFound = true;
break;
}
}
else if (comboBox2 != null && comboBox2.Enabled)
{
ActiveControl = comboBox2;
}
else if (comboBox3 != null && comboBox3.Enabled)
{
ActiveControl = comboBox3;
}
else
if (!activeControlFound)
{
/// Initialize k,j so that after the 1st increment k = 0 and j = 0
int k, j;
@ -421,7 +357,7 @@ namespace TBF.Rig.DataEntry.Uni
}
/// <summary>
/// Returns an array of strings from Program.LocalSettings.
/// Returns an array of strings from ls.
/// Never returns null, null is converted to new string[0].
/// </summary>
/// <param name="isEnd">false = Beginning of cycle, true = End of cycle</param>
@ -433,38 +369,24 @@ namespace TBF.Rig.DataEntry.Uni
{
switch (k)
{
default:
case 0:
if (Program.LocalSettings.LastEnColA == null) Program.LocalSettings.LastEnColA = new string[0];
return Program.LocalSettings.LastEnColA;
case 1:
if (Program.LocalSettings.LastEnColB == null) Program.LocalSettings.LastEnColB = new string[0];
return Program.LocalSettings.LastEnColB;
case 2:
if (Program.LocalSettings.LastEnColC == null) Program.LocalSettings.LastEnColC = new string[0];
return Program.LocalSettings.LastEnColC;
case 3:
if (Program.LocalSettings.LastEnColD == null) Program.LocalSettings.LastEnColD = new string[0];
return Program.LocalSettings.LastEnColD;
case 0: if (ls.LastEnColA == null) ls.LastEnColA = new string[0]; return ls.LastEnColA;
case 1: if (ls.LastEnColB == null) ls.LastEnColB = new string[0]; return ls.LastEnColB;
case 2: if (ls.LastEnColC == null) ls.LastEnColC = new string[0]; return ls.LastEnColC;
case 3: if (ls.LastEnColD == null) ls.LastEnColD = new string[0]; return ls.LastEnColD;
case 4: if (ls.LastEnColE == null) ls.LastEnColE = new string[0]; return ls.LastEnColE;
default: return new string[0];
}
}
else
{
switch (k)
{
default:
case 0:
if (Program.LocalSettings.LastBgColA == null) Program.LocalSettings.LastBgColA = new string[0];
return Program.LocalSettings.LastBgColA;
case 1:
if (Program.LocalSettings.LastBgColB == null) Program.LocalSettings.LastBgColB = new string[0];
return Program.LocalSettings.LastBgColB;
case 2:
if (Program.LocalSettings.LastBgColC == null) Program.LocalSettings.LastBgColC = new string[0];
return Program.LocalSettings.LastBgColC;
case 3:
if (Program.LocalSettings.LastBgColD == null) Program.LocalSettings.LastBgColD = new string[0];
return Program.LocalSettings.LastBgColD;
case 0: if (ls.LastBgColA == null) ls.LastBgColA = new string[0]; return ls.LastBgColA;
case 1: if (ls.LastBgColB == null) ls.LastBgColB = new string[0]; return ls.LastBgColB;
case 2: if (ls.LastBgColC == null) ls.LastBgColC = new string[0]; return ls.LastBgColC;
case 3: if (ls.LastBgColD == null) ls.LastBgColD = new string[0]; return ls.LastBgColD;
case 4: if (ls.LastBgColE == null) ls.LastBgColE = new string[0]; return ls.LastBgColE;
default: return new string[0];
}
}
}
@ -484,30 +406,26 @@ namespace TBF.Rig.DataEntry.Uni
isHandlersEnabled = false;
/// Common combo boxes
var commCBs = new ComboBox[] { comboBox1, comboBox2, comboBox3 };
int ix = 0;
foreach (var commItem in new DEItem[] { item1, item2, item3 })
for (int ix = 0; ix < commonItemsCount; ix++)
{
if (commItem.Content == Content.None) break;
switch (commItem.Action)
switch (commonItems[ix].Action)
{
default:
case Action.Clear:
commCBs[ix].Text = string.Empty;
case Ac.Clear:
commonComboBoxes[ix].Text = string.Empty;
break;
case Action.HistoryLast:
commCBs[ix].Text = commCBs[ix].Items.Count > 0 ? commCBs[ix].Items[0].ToString() : string.Empty;
case Ac.HistoryLast:
commonComboBoxes[ix].Text = (commonComboBoxes[ix].Items.Count > 0)
? commonComboBoxes[ix].Items[0].ToString()
: string.Empty;
break;
case Action.Load:
case Action.LoadReadOnly:
commCBs[ix].Text = GetContent(commItem.Content, firstValidWM);
case Ac.Load:
case Ac.LoadReadOnly:
commonComboBoxes[ix].Text = DEUtils.GetContent(commonItems[ix].Content, firstValidWM);
break;
}
ix++;
}
/// Table
@ -516,22 +434,22 @@ namespace TBF.Rig.DataEntry.Uni
switch (colItems[k].Action)
{
default:
case Action.Clear:
case Ac.Clear:
for (int i = 0; i < wmsCount; i++) comboBoxes[k, i].Text = string.Empty;
break;
case Action.HistoryLast:
case Ac.HistoryLast:
for (int i = 0; i < wmsCount; i++)
{
comboBoxes[k, i].Text = comboBoxes[k, i].Items.Count > 0 ? comboBoxes[k, i].Items[0].ToString() : string.Empty;
}
break;
case Action.Load:
case Action.LoadReadOnly:
case Ac.Load:
case Ac.LoadReadOnly:
for (int i = 0; i < wmsCount; i++)
{
comboBoxes[k, i].Text = GetContent(colItems[k].Content, WaterMeters[i]);
comboBoxes[k, i].Text = DEUtils.GetContent(colItems[k].Content, WaterMeters[i]);
}
break;
}
@ -551,31 +469,27 @@ namespace TBF.Rig.DataEntry.Uni
/// </summary>
void UpdateWMsFromBoxes()
{
if (item1.Content != Content.None && firstValidWM != null)
for (int ix = 0; ix < commonItemsCount; ix++ )
{
PutContent(item1.Content, firstValidWM, comboBox1.Text);
if (item1.Action != Action.LoadReadOnly)
DEUtils.PutContent(commonItems[ix].Content, firstValidWM, commonComboBoxes[ix].Text);
if (commonItems[ix].Action != Ac.LoadReadOnly)
{
if (isEnd) Program.LocalSettings.UpdateHistory(comboBox1.Text, ref Program.LocalSettings.LastEnComm1);
else Program.LocalSettings.UpdateHistory(comboBox1.Text, ref Program.LocalSettings.LastBgComm1);
}
if (item2.Content != Content.None)
{
PutContent(item2.Content, firstValidWM, comboBox2.Text);
if (item2.Action != Action.LoadReadOnly)
if (isEnd)
{
if (isEnd) Program.LocalSettings.UpdateHistory(comboBox2.Text, ref Program.LocalSettings.LastEnComm2);
else Program.LocalSettings.UpdateHistory(comboBox2.Text, ref Program.LocalSettings.LastBgComm2);
}
if (item3.Content != Content.None)
{
PutContent(item3.Content, firstValidWM, comboBox3.Text);
if (item3.Action != Action.LoadReadOnly)
switch (ix)
{
if (isEnd) Program.LocalSettings.UpdateHistory(comboBox3.Text, ref Program.LocalSettings.LastEnComm3);
else Program.LocalSettings.UpdateHistory(comboBox3.Text, ref Program.LocalSettings.LastBgComm3);
case 0: ls.UpdateHistory(commonComboBoxes[ix].Text, ref ls.LastEnComm1); break;
case 1: ls.UpdateHistory(commonComboBoxes[ix].Text, ref ls.LastEnComm2); break;
case 2: ls.UpdateHistory(commonComboBoxes[ix].Text, ref ls.LastEnComm3); break;
}
}
else
{
switch (ix)
{
case 0: ls.UpdateHistory(commonComboBoxes[ix].Text, ref ls.LastBgComm1); break;
case 1: ls.UpdateHistory(commonComboBoxes[ix].Text, ref ls.LastBgComm2); break;
case 2: ls.UpdateHistory(commonComboBoxes[ix].Text, ref ls.LastBgComm3); break;
}
}
}
@ -584,29 +498,18 @@ namespace TBF.Rig.DataEntry.Uni
/// Propagate common (batch) values to water meters in case of
/// Content.BatchAndWmOrder, Content.BatchAndWmRemark, Content.YearOfCalibration and Content.ArchivePath
///
if (item1.Content == Content.BatchAndWmOrder ||
(item1.Content != Content.None && item2.Content == Content.BatchAndWmOrder) ||
(item1.Content != Content.None && item2.Content != Content.None && item2.Content == Content.BatchAndWmOrder))
foreach (var wm in WaterMeters)
{
foreach (var wm in WaterMeters) if (wm != null && !wm.Disabled) wm.PurchaseOrder = firstValidWM.Batch.PurchaseOrder;
}
else if (item1.Content == Content.BatchAndWmRemark ||
(item1.Content != Content.None && item2.Content == Content.BatchAndWmRemark) ||
(item1.Content != Content.None && item2.Content != Content.None && item2.Content == Content.BatchAndWmRemark))
{
foreach (var wm in WaterMeters) if (wm != null && !wm.Disabled) wm.Remark = firstValidWM.Batch.Remark;
}
else if (item1.Content == Content.YearOfCalibration ||
(item1.Content != Content.None && item2.Content == Content.YearOfCalibration) ||
(item1.Content != Content.None && item2.Content != Content.None && item2.Content == Content.YearOfCalibration))
{
foreach (var wm in WaterMeters) if (wm != null && !wm.Disabled) wm.YearOfProduction = firstValidWM.YearOfProduction;
}
else if (item1.Content == Content.ArchivePath ||
(item1.Content != Content.None && item2.Content == Content.ArchivePath) ||
(item1.Content != Content.None && item2.Content != Content.None && item2.Content == Content.ArchivePath))
{
foreach (var wm in WaterMeters) if (wm != null && !wm.Disabled) wm.ArchivePath = firstValidWM.ArchivePath;
if (wm != null && !wm.Disabled)
{
switch (commonItems[ix].Content)
{
case Ct.BatchAndWmOrder: wm.PurchaseOrder = firstValidWM.Batch.PurchaseOrder; break;
case Ct.BatchAndWmRemark: wm.Remark = firstValidWM.Batch.Remark; break;
case Ct.YearOfCalibration: wm.YearOfProduction = firstValidWM.YearOfProduction; break;
case Ct.ArchivePath: wm.ArchivePath = firstValidWM.ArchivePath; break;
}
}
}
}
@ -616,33 +519,33 @@ namespace TBF.Rig.DataEntry.Uni
var currentVals = new string[wmsCount];
for (int i = 0; i < wmsCount; i++)
{
PutContent(colItems[k].Content, WaterMeters[i], comboBoxes[k, i].Text);
DEUtils.PutContent(colItems[k].Content, WaterMeters[i], comboBoxes[k, i].Text);
currentVals[i] = comboBoxes[k, i].Text;
}
/// Update history
if (colItems[k].Action != Action.LoadReadOnly)
if (colItems[k].Action != Ac.LoadReadOnly)
{
if (isEnd)
{
switch (k)
{
default:
case 0: Program.LocalSettings.LastEnColA = currentVals; break;
case 1: Program.LocalSettings.LastEnColB = currentVals; break;
case 2: Program.LocalSettings.LastEnColC = currentVals; break;
case 3: Program.LocalSettings.LastEnColD = currentVals; break;
case 0: ls.LastEnColA = currentVals; break;
case 1: ls.LastEnColB = currentVals; break;
case 2: ls.LastEnColC = currentVals; break;
case 3: ls.LastEnColD = currentVals; break;
case 4: ls.LastEnColE = currentVals; break;
}
}
else
{
switch (k)
{
default:
case 0: Program.LocalSettings.LastBgColA = currentVals; break;
case 1: Program.LocalSettings.LastBgColB = currentVals; break;
case 2: Program.LocalSettings.LastBgColC = currentVals; break;
case 3: Program.LocalSettings.LastBgColD = currentVals; break;
case 0: ls.LastBgColA = currentVals; break;
case 1: ls.LastBgColB = currentVals; break;
case 2: ls.LastBgColC = currentVals; break;
case 3: ls.LastBgColD = currentVals; break;
case 4: ls.LastBgColE = currentVals; break;
}
}
}
@ -654,79 +557,6 @@ namespace TBF.Rig.DataEntry.Uni
}
}
string GetContent(Content content, WaterMeter wm)
{
if (wm == null) return string.Empty;
switch (content)
{
default:
case Content.None: return string.Empty;
case Content.SerialNr: return (!wm.Disabled && wm.SerialNr != null) ? wm.SerialNr : string.Empty;
case Content.SerialNrAux: return (!wm.Disabled && wm.SerialNrAux != null) ? wm.SerialNrAux : string.Empty;
case Content.RadioAddress: return (!wm.Disabled && wm.RadioAddress != null) ? wm.RadioAddress : string.Empty;
case Content.YearOfCalibration: return (!wm.Disabled) ? wm.YearOfProduction.ToString() : string.Empty;
case Content.StartState: return (!wm.Disabled && wm.GetStartState() != null) ? wm.GetStartState() : string.Empty;
case Content.EndState: return (!wm.Disabled && wm.EndState != null) ? wm.EndState : string.Empty;
case Content.ArchivePath: return (!wm.Disabled && wm.ArchivePath != null) ? wm.ArchivePath : string.Empty;
case Content.WmOrder: return (!wm.Disabled && wm.PurchaseOrder != null) ? wm.PurchaseOrder : string.Empty;
case Content.BatchOrder: return (wm.Batch != null && wm.Batch.PurchaseOrder != null) ? wm.Batch.PurchaseOrder : string.Empty;
case Content.BatchAndWmOrder: return (wm.Batch != null && wm.Batch.PurchaseOrder != null) ? wm.Batch.PurchaseOrder : string.Empty;
case Content.WmRemark: return (!wm.Disabled && wm.Remark != null) ? wm.Remark : string.Empty;
case Content.BatchRemark: return (wm.Batch != null && wm.Batch.Remark != null) ? wm.Batch.Remark : string.Empty;
case Content.BatchAndWmRemark: return (wm.Batch != null && wm.Batch.Remark != null) ? wm.Batch.Remark : string.Empty;
#if ORACLE_DB
case Content.Prefix: return (!wm.Disabled && wm.Prefix != null) ? wm.Prefix : string.Empty;
case Content.Suffix: return (!wm.Disabled && wm.Suffix != null) ? wm.Suffix : string.Empty;
#endif
}
}
void PutContent(Content content, WaterMeter wm, string value)
{
if (wm == null || wm.Disabled) return;
int year;
switch (content)
{
default:
case Content.None: return;
case Content.SerialNr: wm.SerialNr = value; return;
case Content.SerialNrAux: wm.SerialNrAux = value; return;
case Content.RadioAddress: wm.RadioAddress = value; return;
case Content.YearOfCalibration: if (int.TryParse(value, out year)) wm.YearOfProduction = year; return;
case Content.StartState: wm.SetStartState(value); return;
case Content.EndState: wm.EndState = value; return;
case Content.ArchivePath: wm.ArchivePath = value; return;
case Content.WmOrder:
wm.PurchaseOrder = value;
return;
case Content.BatchOrder:
case Content.BatchAndWmOrder:
if (wm.Batch != null) wm.Batch.PurchaseOrder = value;
return;
case Content.WmRemark:
wm.Remark = value;
return;
case Content.BatchRemark:
case Content.BatchAndWmRemark:
if (wm.Batch != null) wm.Batch.Remark = value;
return;
#if ORACLE_DB
case Content.Prefix: wm.Prefix = value; return;
case Content.Suffix: wm.Suffix = value; return;
#endif
}
}
private void clearButton_Click(object sender, EventArgs e)
{
InitializeBoxes();
@ -783,22 +613,19 @@ namespace TBF.Rig.DataEntry.Uni
{
if (k < 0)
{
if (j == 1 && comboBox2 != null)
for (int ix = j; ix < commonItemsCount; ix++)
{
comboBox2.Focus();
return;
}
else if (j == 2 && comboBox3 != null)
{
comboBox3.Focus();
return;
}
else
{
/// Initialize k,j so that after the 1st increment k = 0 and j = 0
if (isLrOrder) { k = -1; j = 0; }
else { k = 0; j = -1; }
if (commonComboBoxes[ix].Enabled)
{
commonComboBoxes[ix].Focus();
return;
}
}
/// No next enabled common item found:
/// Initialize k,j so that after the 1st increment k = 0 and j = 0
if (isLrOrder) { k = -1; j = 0; }
else { k = 0; j = -1; }
}
/// Change focus

View File

@ -7,7 +7,10 @@ using Common;
namespace TBF.Rig.DataEntry.Uni
{
public enum Action
///
/// Ac = Action
///
public enum Ac
{
[Description("Clear")] Clear, /// Clear when the form is open, save on OK
[Description("Last from history")] HistoryLast,
@ -16,7 +19,10 @@ namespace TBF.Rig.DataEntry.Uni
Count,
}
public enum Content
///
/// Ct = Content
///
public enum Ct
{
[Description("None")] None,
[Description("Serial nr.")] SerialNr,
@ -41,12 +47,12 @@ namespace TBF.Rig.DataEntry.Uni
public class DEItem
{
public readonly Content Content;
public readonly Ct Content;
public readonly string Caption;
public readonly Action Action;
public readonly Ac Action;
public readonly int Width;
public DEItem(Content content, string caption, Action action, int width)
public DEItem(Ct content, string caption, Ac action, int width)
{
Content = content;
Caption = caption;
@ -54,11 +60,23 @@ namespace TBF.Rig.DataEntry.Uni
Width = width;
}
static IList<DEItem> items = new List<DEItem>();
///
public static void ClearItems() { items.Clear(); }
public static void AddItem(DEItem item) { items.Add(item); }
public static void AddItem(Ct content, string caption, Ac action, int width)
{
items.Add(new DEItem(content, caption, action, width));
}
public static IList<DEItem> GetItems() { return items; }
static IList<DEItem> columns = new List<DEItem>();
///
public static void ClearColumns() { columns.Clear(); }
public static void AddColumn(DEItem column) { columns.Add(column); }
public static void AddColumn(Content content, string caption, Action action, int width)
public static void AddColumn(Ct content, string caption, Ac action, int width)
{
columns.Add(new DEItem(content, caption, action, width));
}

View File

@ -0,0 +1,83 @@
///
/// Copyright (c) 2023 Sensus Slovensko a.s.
///
using System;
using Results.Entities;
namespace TBF.Rig.DataEntry.Uni
{
public class DEUtils
{
public static string GetContent(Ct content, WaterMeter wm)
{
if (wm == null) return string.Empty;
switch (content)
{
default:
case Ct.None: return string.Empty;
case Ct.SerialNr: return (!wm.Disabled && wm.SerialNr != null) ? wm.SerialNr : string.Empty;
case Ct.SerialNrAux: return (!wm.Disabled && wm.SerialNrAux != null) ? wm.SerialNrAux : string.Empty;
case Ct.RadioAddress: return (!wm.Disabled && wm.RadioAddress != null) ? wm.RadioAddress : string.Empty;
case Ct.YearOfCalibration: return (!wm.Disabled) ? wm.YearOfProduction.ToString() : string.Empty;
case Ct.StartState: return (!wm.Disabled && wm.GetStartState() != null) ? wm.GetStartState() : string.Empty;
case Ct.EndState: return (!wm.Disabled && wm.EndState != null) ? wm.EndState : string.Empty;
case Ct.ArchivePath: return (!wm.Disabled && wm.ArchivePath != null) ? wm.ArchivePath : string.Empty;
case Ct.WmOrder: return (!wm.Disabled && wm.PurchaseOrder != null) ? wm.PurchaseOrder : string.Empty;
case Ct.BatchOrder: return (wm.Batch != null && wm.Batch.PurchaseOrder != null) ? wm.Batch.PurchaseOrder : string.Empty;
case Ct.BatchAndWmOrder: return (wm.Batch != null && wm.Batch.PurchaseOrder != null) ? wm.Batch.PurchaseOrder : string.Empty;
case Ct.WmRemark: return (!wm.Disabled && wm.Remark != null) ? wm.Remark : string.Empty;
case Ct.BatchRemark: return (wm.Batch != null && wm.Batch.Remark != null) ? wm.Batch.Remark : string.Empty;
case Ct.BatchAndWmRemark: return (wm.Batch != null && wm.Batch.Remark != null) ? wm.Batch.Remark : string.Empty;
#if ORACLE_DB
case Content.Prefix: return (!wm.Disabled && wm.Prefix != null) ? wm.Prefix : string.Empty;
case Content.Suffix: return (!wm.Disabled && wm.Suffix != null) ? wm.Suffix : string.Empty;
#endif
}
}
public static void PutContent(Ct content, WaterMeter wm, string value)
{
if (wm == null || wm.Disabled) return;
int year;
switch (content)
{
default:
case Ct.None: return;
case Ct.SerialNr: wm.SerialNr = value; return;
case Ct.SerialNrAux: wm.SerialNrAux = value; return;
case Ct.RadioAddress: wm.RadioAddress = value; return;
case Ct.YearOfCalibration: if (int.TryParse(value, out year)) wm.YearOfProduction = year; return;
case Ct.StartState: wm.SetStartState(value); return;
case Ct.EndState: wm.EndState = value; return;
case Ct.ArchivePath: wm.ArchivePath = value; return;
case Ct.WmOrder:
wm.PurchaseOrder = value;
return;
case Ct.BatchOrder:
case Ct.BatchAndWmOrder:
if (wm.Batch != null) wm.Batch.PurchaseOrder = value;
return;
case Ct.WmRemark:
wm.Remark = value;
return;
case Ct.BatchRemark:
case Ct.BatchAndWmRemark:
if (wm.Batch != null) wm.Batch.Remark = value;
return;
#if ORACLE_DB
case Content.Prefix: wm.Prefix = value; return;
case Content.Suffix: wm.Suffix = value; return;
#endif
}
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -132,39 +132,51 @@ namespace TBF.Rig.DataEntry.Uni
///
void OpenBeginningDlg(EntryFormNoStartEnd myRef)
{
var item1 = new DEItem(myCfg.BgItem1Content, myCfg.BgItem1Caption, myCfg.BgItem1Action, myCfg.BgItem1Width);
var item2 = new DEItem(myCfg.BgItem2Content, myCfg.BgItem2Caption, myCfg.BgItem2Action, myCfg.BgItem2Width);
var item3 = new DEItem(myCfg.BgItem3Content, myCfg.BgItem3Caption, myCfg.BgItem3Action, myCfg.BgItem3Width);
DEItem.ClearItems();
for (int i = 0; i < myCfg.GetBgItemsCount(); i++)
{
if (myCfg.BgItemContent[i] != Ct.None)
{
DEItem.AddItem(myCfg.BgItemContent[i], myCfg.BgItemCaption[i], myCfg.BgItemAction[i], myCfg.BgItemWidth[i]);
}
}
DEItem.ClearColumns();
if (myCfg.BgColAContent != Content.None) DEItem.AddColumn(myCfg.BgColAContent, myCfg.BgColACaption, myCfg.BgColAAction, myCfg.BgColAWidth);
if (myCfg.BgColBContent != Content.None) DEItem.AddColumn(myCfg.BgColBContent, myCfg.BgColBCaption, myCfg.BgColBAction, myCfg.BgColBWidth);
if (myCfg.BgColCContent != Content.None) DEItem.AddColumn(myCfg.BgColCContent, myCfg.BgColCCaption, myCfg.BgColCAction, myCfg.BgColCWidth);
if (myCfg.BgColDContent != Content.None) DEItem.AddColumn(myCfg.BgColDContent, myCfg.BgColDCaption, myCfg.BgColDAction, myCfg.BgColDWidth);
if (myCfg.BgColEContent != Content.None) DEItem.AddColumn(myCfg.BgColEContent, myCfg.BgColECaption, myCfg.BgColEAction, myCfg.BgColEWidth);
var columns = DEItem.GetColumns();
for (int i = 0; i < myCfg.GetBgColumnsCount(); i++)
{
if (myCfg.BgColumnContent[i] != Ct.None)
{
DEItem.AddColumn(myCfg.BgColumnContent[i], myCfg.BgColumnCaption[i], myCfg.BgColumnAction[i], myCfg.BgColumnWidth[i]);
}
}
modelessDlg = new CycleBgEnForm(waterMeters, TBF.Data.LineSize, myCfg.BgTitle, myCfg.BgSize, myCfg.BgIsLrOrder, myCfg.BgFormCloseKeys,
item1, item2, item3, columns, false);
DEItem.GetItems(), DEItem.GetColumns(), false);
modelessDlg.Show();
}
///
void OpenEndDlg(EntryFormNoStartEnd myRef)
{
var item1 = new DEItem(myCfg.EnItem1Content, myCfg.EnItem1Caption, myCfg.EnItem1Action, myCfg.EnItem1Width);
var item2 = new DEItem(myCfg.EnItem2Content, myCfg.EnItem2Caption, myCfg.EnItem2Action, myCfg.EnItem2Width);
var item3 = new DEItem(myCfg.EnItem3Content, myCfg.EnItem3Caption, myCfg.EnItem3Action, myCfg.EnItem3Width);
DEItem.ClearItems();
for (int i = 0; i < myCfg.GetEnItemsCount(); i++)
{
if (myCfg.EnItemContent[i] != Ct.None)
{
DEItem.AddItem(myCfg.EnItemContent[i], myCfg.EnItemCaption[i], myCfg.EnItemAction[i], myCfg.EnItemWidth[i]);
}
}
DEItem.ClearColumns();
if (myCfg.EnColAContent != Content.None) DEItem.AddColumn(myCfg.EnColAContent, myCfg.EnColACaption, myCfg.EnColAAction, myCfg.EnColAWidth);
if (myCfg.EnColBContent != Content.None) DEItem.AddColumn(myCfg.EnColBContent, myCfg.EnColBCaption, myCfg.EnColBAction, myCfg.EnColBWidth);
if (myCfg.EnColCContent != Content.None) DEItem.AddColumn(myCfg.EnColCContent, myCfg.EnColCCaption, myCfg.EnColCAction, myCfg.EnColCWidth);
if (myCfg.EnColDContent != Content.None) DEItem.AddColumn(myCfg.EnColDContent, myCfg.EnColDCaption, myCfg.EnColDAction, myCfg.EnColDWidth);
if (myCfg.EnColEContent != Content.None) DEItem.AddColumn(myCfg.EnColEContent, myCfg.EnColECaption, myCfg.EnColEAction, myCfg.EnColEWidth);
var columns = DEItem.GetColumns();
for (int i = 0; i < myCfg.GetEnColumnsCount(); i++)
{
if (myCfg.EnColumnContent[i] != Ct.None)
{
DEItem.AddColumn(myCfg.EnColumnContent[i], myCfg.EnColumnCaption[i], myCfg.EnColumnAction[i], myCfg.EnColumnWidth[i]);
}
}
modelessDlg = new CycleBgEnForm(waterMeters, TBF.Data.LineSize, myCfg.EnTitle, myCfg.EnSize, myCfg.EnIsLrOrder, myCfg.EnFormCloseKeys,
item1, item2, item3, columns, true);
DEItem.GetItems(), DEItem.GetColumns(), true);
modelessDlg.Show();
}
///
@ -189,13 +201,13 @@ namespace TBF.Rig.DataEntry.Uni
switch (currentOp)
{
case CurrentOp.ShowFormAtCycleBeginning:
if (myCfg.ShowCycleBeginningForm)
if (myCfg.BgShowForm)
{
Program.MainWnd.Invoke(new EntryFormDlgt(OpenBeginningDlg), this);
}
break;
case CurrentOp.ShowFormAtCycleEnd:
if (myCfg.ShowCycleEndForm)
if (myCfg.EnShowForm)
{
Program.MainWnd.Invoke(new EntryFormDlgt(OpenEndDlg), this);
}

View File

@ -541,6 +541,7 @@
<DependentUpon>CycleBgEnForm.cs</DependentUpon>
</Compile>
<Compile Include="Rig\DataEntry\Uni\DEItem.cs" />
<Compile Include="Rig\DataEntry\Uni\DEUtils.cs" />
<Compile Include="Rig\DataEntry\Uni\EntryForm.cs" />
<Compile Include="Rig\DataEntry\Uni\EntryFormCfg.cs" />
<Compile Include="Rig\DataEntry\Uni\EntryFormNoStartEnd.cs" />