/// /// Copyright (c) 2020-2021 Sensus Slovensko a.s. /// using System; using System.Collections.Generic; using System.Windows.Forms; using log4net; using TBF.BenchControl.Sequences; using TBF.Resources; using Oracle.DataAccess.Client; using System.Diagnostics; using System.Drawing; namespace TBF.BenchControl.DataEntry.S620 { public partial class FormForMechanicalMeters : Form, ICycleBeginOrEndForm, GenericDevices.IHasCompleted { private static readonly ILog log = LogManager.GetLogger(typeof(FormForMechanicalMeters)); /// Number of water meters IList waterMeters; readonly int wmsCount; readonly bool skipFailed; /// To be retrieved after the form is closed string purchaseOrder; public string PurchaseOrder { get { return purchaseOrder; } set { purchaseOrder = value; } } string[] bodyNrText; public string[] BodyNrText { get { return bodyNrText; } set { bodyNrText = value; } } int[] assignedSerialNr; public int[] AssignedSerialNr { get { return assignedSerialNr; } set { assignedSerialNr = value; } } string[] completeSerialNr; public string[] CompleteSerialNr { get { return completeSerialNr; } set { completeSerialNr = value; } } bool[] disabled; public bool[] Disabled { get { return disabled; } set { disabled = value; } } string prefix; /// S/N prefix - Loaded from Oracle DB table VT_AUFTRAG_PD public string Prefix { get { return prefix; } set { prefix = value; } } string suffix; /// S/N suffix - Loaded from Oracle DB table VT_AUFTRAG_PD public string Suffix { get { return suffix; } set { suffix = value; } } /// Loaded from Oracle DB table VT_AUFTRAG_PD int firstSN; /// First serial number int snDigits; /// Number of digits of the middle part of the serial number int pcsCount; /// Pieces count IList foundMeters; IList foundSNsWithinRange; IList assignedSNs; /// Entered manually int snRangeFirst; /// 0 = invalid int snRangeLast; /// 0 = invalid /// Set to 'true' when the form closes public bool Completed { get { return completed; } } bool completed; /// Number of text boxes for serial numbers int textBoxesCount; Label[] labels; ComboBox[] bodyNrBoxes; TextBox[] serialNrBoxes; CheckBox[] checkBoxes; IList enabledBodyNrBoxes; /// combo boxes containing body numbers IList enabledSerialNrBoxes; /// text boxes containing assigned serial numbers IList enabledCounterNrBoxes; /// text boxes containing assigned serial numbers readonly LocalSettings LS; /// Parameterless constructor for common functionality public FormForMechanicalMeters() { InitializeComponent(); ControlBox = false; BackColor = SystemColors.Control; firstSN = 0; snDigits = 0; pcsCount = 0; prefix = null; suffix = null; foundMeters = new List(); foundSNsWithinRange = new List(); assignedSNs = new List(); snRangeFirst = 0; snRangeLast = 0; LS = Program.LocalSettings; textBoxesCount = 40; labels = new Label[] { label1, label2, label3, label4, label5, label6, label7, label8, label9, label10, label11, label12, label13, label14, label15, label16, label17, label18, label19, label20, label21, label22, label23, label24, label25, label26, label27, label28, label29, label30, label31, label32, label33, label34, label35, label36, label37, label38, label39, label40, }; bodyNrBoxes = new ComboBox[] { comboBox1, comboBox2, comboBox3, comboBox4, comboBox5, comboBox6, comboBox7, comboBox8, comboBox9, comboBox10, comboBox11, comboBox12, comboBox13, comboBox14, comboBox15, comboBox16, comboBox17, comboBox18, comboBox19, comboBox20, comboBox21, comboBox22, comboBox23, comboBox24, comboBox25, comboBox26, comboBox27, comboBox28, comboBox29, comboBox30, comboBox31, comboBox32, comboBox33, comboBox34, comboBox35, comboBox36, comboBox37, comboBox38, comboBox39, comboBox40, }; serialNrBoxes = new TextBox[] { textBox1, textBox2, textBox3, textBox4, textBox5, textBox6, textBox7, textBox8, textBox9, textBox10, textBox11, textBox12, textBox13, textBox14, textBox15, textBox16, textBox17, textBox18, textBox19, textBox20, textBox21, textBox22, textBox23, textBox24, textBox25, textBox26, textBox27, textBox28, textBox29, textBox30, textBox31, textBox32, textBox33, textBox34, textBox35, textBox36, textBox37, textBox38, textBox39, textBox40, }; checkBoxes = new CheckBox[] { checkBox1, checkBox2, checkBox3, checkBox4, checkBox5, checkBox6, checkBox7, checkBox8, checkBox9, checkBox10, checkBox11, checkBox12, checkBox13, checkBox14, checkBox15, checkBox16, checkBox17, checkBox18, checkBox19, checkBox20, checkBox21, checkBox22, checkBox23, checkBox24, checkBox25, checkBox26, checkBox27, checkBox28, checkBox29, checkBox30, checkBox31, checkBox32, checkBox33, checkBox34, checkBox35, checkBox36, checkBox37, checkBox38, checkBox39, checkBox40, }; enabledBodyNrBoxes = new List(); enabledSerialNrBoxes = new List(); enabledCounterNrBoxes = new List(); ColorFlashHandler += delegate(object sender, ColorFlashEventArgs args) { if (InvokeRequired) { Invoke(new EventHandler(OnColorFlash), sender, args); } else OnColorFlash(sender, args); }; BeepHandler += delegate(object sender, ColorFlashEventArgs args) { if (InvokeRequired) { Invoke(new EventHandler(OnBeep), sender, args); } else OnBeep(sender, args); }; completed = false; StartForceCloseHandler(); } #region Forced close handling public void StartForceCloseHandler() { UiBridge.Bridge.CloseModelessFormHandler += delegate(object sender, EventArgs args) { if (InvokeRequired) { Invoke(new EventHandler(OnForceClose), sender, args); } else OnForceClose(sender, args); }; } private void OnForceClose(object sender, EventArgs args) { DialogResult = DialogResult.Cancel; Close(); } #endregion /// /// Constructor /// /// Number of text boxes for serial numbers public FormForMechanicalMeters(IList waterMeters) : this() { this.waterMeters = waterMeters; this.wmsCount = waterMeters.Count; this.skipFailed = false; bodyNrText = new string[wmsCount]; assignedSerialNr = new int[wmsCount]; completeSerialNr = new string[wmsCount]; disabled = new bool[wmsCount]; ShuffleTextBoxes(wmsCount, Config.Data.LineSize); } /// /// Make sure the layout of labels/text boxes on the screen /// corresponds to the layout of watermeters of the test bench. /// /// Number of watermeters /// Number of watermeters in one line void ShuffleTextBoxes(int wmsCount, int lineSize) { if (wmsCount < textBoxesCount && lineSize > 0) { int nrLines = (wmsCount + lineSize - 1) / lineSize; int gap = (textBoxesCount - wmsCount) / nrLines; int dest = 0; for (int l = 0; l < nrLines; l++) { for (int i = 0; i < lineSize; i++) { labels[dest] = labels[l * lineSize + l * gap + i]; bodyNrBoxes[dest] = bodyNrBoxes[l * lineSize + l * gap + i]; serialNrBoxes[dest] = serialNrBoxes[l * lineSize + l * gap + i]; checkBoxes[dest] = checkBoxes[l * lineSize + l * gap + i]; dest++; } } textBoxesCount = wmsCount; } } private void CycleBeginningForm_Load(object sender, EventArgs e) { Localize(); PrepareOrderAndSNRangeCombos(); for (int i = 0; i < textBoxesCount; i++) { if (Program.LocalSettings.LastSNTextsCount == textBoxesCount) { bodyNrBoxes[i].Items.Add((Program.LocalSettings.LastSNTexts[i] == null) ? string.Empty : Program.LocalSettings.LastSNTexts[i]); } labels[i].Visible = bodyNrBoxes[i].Visible = serialNrBoxes[i].Visible = checkBoxes[i].Visible = true; if (waterMeters[i] == null || waterMeters[i].Disabled || (skipFailed && !waterMeters[i].PassedFromTests())) { bodyNrBoxes[i].Enabled = serialNrBoxes[i].Enabled = checkBoxes[i].Enabled = false; } else { enabledBodyNrBoxes.Add(bodyNrBoxes[i]); enabledSerialNrBoxes.Add(serialNrBoxes[i]); } if (waterMeters[i] != null && !waterMeters[i].PassedFromTests()) { bodyNrBoxes[i].BackColor = System.Drawing.Color.Pink; serialNrBoxes[i].BackColor = System.Drawing.Color.Pink; } } if (ProcessData.OracleDB != null && ProcessData.OracleDB.SelectedDB != null) { reloadButton.Enabled = true; } } void Localize() { Text = Strings.Data; orderGroupBox.Text = "Výrobná zakázka"; for (int i = 0; i < textBoxesCount; i++) { labels[i].Text = string.Format("Vodomer {0}", i + 1); } firstSNLabel.Text = "prvé s/n"; snDigitsLabel.Text = "číslic"; piecesCountLabel.Text = "kusov"; reloadButton.Text = "Načítať"; snRangeGroupBox.Text = "Rozsah sériových čísel"; fromLabel.Text = "od"; toLabel.Text = "do"; okButton.Text = Strings.OkBtnText; clearButton.Text = Strings.ClearBtnText; serialNumbersGroupBox.Text = "Sériové čísla"; label41.Text = label43.Text = "Číslo púzdra"; label42.Text = label44.Text = "Sériové číslo"; for (int i = 0; i < textBoxesCount; i++) { labels[i].Text = string.Format("Vodomer {0}", i + 1); } } /// /// Load Purchase order combo box items from the LocalSettings PurchaseOrderHistory array /// /// Puchase order ComboBox void PrepareOrderAndSNRangeCombos() { /// Purchase order for (int i = 0; i < LS.PurchaseOrderHistoryCount; i++) orderCB.Items.Add(LS.PurchaseOrderHistory[i]); if (orderCB.Items.Count > 0) orderCB.Text = orderCB.Items[0].ToString(); /// First S/N in selected range for (int i = 0; i < LS.FirstSNHistoryCount; i++) firstSNRangeCB.Items.Add(LS.FirstSNHistory[i]); if (firstSNRangeCB.Items.Count > 0) firstSNRangeCB.Text = firstSNRangeCB.Items[0].ToString(); /// Last S/N in selected range for (int i = 0; i < LS.LastSNHistoryCount; i++) lastSNRangeCB.Items.Add(LS.LastSNHistory[i]); if (lastSNRangeCB.Items.Count > 0) lastSNRangeCB.Text = lastSNRangeCB.Items[0].ToString(); } private void okButton_Click(object sender, EventArgs e) { purchaseOrder = orderCB.Text; Program.LocalSettings.UpdateHistory(orderCB.Text, ref Program.LocalSettings.PurchaseOrderHistory); Program.LocalSettings.UpdateHistory(firstSNRangeCB.Text, ref Program.LocalSettings.FirstSNHistory); Program.LocalSettings.UpdateHistory(lastSNRangeCB.Text, ref Program.LocalSettings.LastSNHistory); Program.LocalSettings.LastSNTexts = bodyNrText; int itmp; for (int i = 0; i < Math.Min(wmsCount, textBoxesCount); i++) { bodyNrText[i] = bodyNrBoxes[i].Text; assignedSerialNr[i] = int.TryParse(serialNrBoxes[i].Text, out itmp) ? itmp : 0; completeSerialNr[i] = string.Format("{0}{1}{2}", (prefix != null) ? prefix : string.Empty, assignedSerialNr[i].ToString(string.Format("D{0}", Math.Max(snDigits, 1))), (suffix != null) ? suffix : string.Empty); disabled[i] = !checkBoxes[i].Checked; } completed = true; Close(); } /// /// When one combo box is updated using drop-down menu, all combo boxes /// are updated by this function. /// private void UpdateAllCombos() { for (int i = 0; i < Math.Min(wmsCount, textBoxesCount); i++) { bodyNrBoxes[i].Text = Program.LocalSettings.LastSNTexts[i]; checkBoxes[i].Checked = !string.IsNullOrEmpty(bodyNrBoxes[i].Text); } } private void clearButton_Click(object sender, EventArgs e) { if (MessageBox.Show("Naozaj chcete všetky kódy vymazať?", "Upozonenie", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == DialogResult.Yes) { for (int i = 0; i < Math.Min(wmsCount, textBoxesCount); i++) { bodyNrBoxes[i].Text = string.Empty; serialNrBoxes[i].Text = string.Empty; checkBoxes[i].Checked = false; } assignedSNs.Clear(); } } private void comboBox1_TextChanged(object s, EventArgs e) { checkBox1.Checked = true; } private void comboBox2_TextChanged(object s, EventArgs e) { checkBox2.Checked = true; } private void comboBox3_TextChanged(object s, EventArgs e) { checkBox3.Checked = true; } private void comboBox4_TextChanged(object s, EventArgs e) { checkBox4.Checked = true; } private void comboBox5_TextChanged(object s, EventArgs e) { checkBox5.Checked = true; } private void comboBox6_TextChanged(object s, EventArgs e) { checkBox6.Checked = true; } private void comboBox7_TextChanged(object s, EventArgs e) { checkBox7.Checked = true; } private void comboBox8_TextChanged(object s, EventArgs e) { checkBox8.Checked = true; } private void comboBox9_TextChanged(object s, EventArgs e) { checkBox9.Checked = true; } private void comboBox10_TextChanged(object s, EventArgs e) { checkBox10.Checked = true; } private void comboBox11_TextChanged(object s, EventArgs e) { checkBox11.Checked = true; } private void comboBox12_TextChanged(object s, EventArgs e) { checkBox12.Checked = true; } private void comboBox13_TextChanged(object s, EventArgs e) { checkBox13.Checked = true; } private void comboBox14_TextChanged(object s, EventArgs e) { checkBox14.Checked = true; } private void comboBox15_TextChanged(object s, EventArgs e) { checkBox15.Checked = true; } private void comboBox16_TextChanged(object s, EventArgs e) { checkBox16.Checked = true; } private void comboBox17_TextChanged(object s, EventArgs e) { checkBox17.Checked = true; } private void comboBox18_TextChanged(object s, EventArgs e) { checkBox18.Checked = true; } private void comboBox19_TextChanged(object s, EventArgs e) { checkBox19.Checked = true; } private void comboBox20_TextChanged(object s, EventArgs e) { checkBox20.Checked = true; } private void comboBox21_TextChanged(object s, EventArgs e) { checkBox21.Checked = true; } private void comboBox22_TextChanged(object s, EventArgs e) { checkBox22.Checked = true; } private void comboBox23_TextChanged(object s, EventArgs e) { checkBox23.Checked = true; } private void comboBox24_TextChanged(object s, EventArgs e) { checkBox24.Checked = true; } private void comboBox25_TextChanged(object s, EventArgs e) { checkBox25.Checked = true; } private void comboBox26_TextChanged(object s, EventArgs e) { checkBox26.Checked = true; } private void comboBox27_TextChanged(object s, EventArgs e) { checkBox27.Checked = true; } private void comboBox28_TextChanged(object s, EventArgs e) { checkBox28.Checked = true; } private void comboBox29_TextChanged(object s, EventArgs e) { checkBox29.Checked = true; } private void comboBox30_TextChanged(object s, EventArgs e) { checkBox30.Checked = true; } private void comboBox31_TextChanged(object s, EventArgs e) { checkBox31.Checked = true; } private void comboBox32_TextChanged(object s, EventArgs e) { checkBox32.Checked = true; } private void comboBox33_TextChanged(object s, EventArgs e) { checkBox33.Checked = true; } private void comboBox34_TextChanged(object s, EventArgs e) { checkBox34.Checked = true; } private void comboBox35_TextChanged(object s, EventArgs e) { checkBox35.Checked = true; } private void comboBox36_TextChanged(object s, EventArgs e) { checkBox36.Checked = true; } private void comboBox37_TextChanged(object s, EventArgs e) { checkBox37.Checked = true; } private void comboBox38_TextChanged(object s, EventArgs e) { checkBox38.Checked = true; } private void comboBox39_TextChanged(object s, EventArgs e) { checkBox39.Checked = true; } private void comboBox40_TextChanged(object s, EventArgs e) { checkBox40.Checked = true; } private void comboBox1_SelectedIndexChanged(object s, EventArgs e) { if (LS.LastSNTextsCount == wmsCount && comboBox1.Text == comboBox1.Items[0].ToString()) UpdateAllCombos(); } private void comboBox2_SelectedIndexChanged(object s, EventArgs e) { if (LS.LastSNTextsCount == wmsCount && comboBox2.Text == comboBox2.Items[0].ToString()) UpdateAllCombos(); } private void comboBox3_SelectedIndexChanged(object s, EventArgs e) { if (LS.LastSNTextsCount == wmsCount && comboBox3.Text == comboBox3.Items[0].ToString()) UpdateAllCombos(); } private void comboBox4_SelectedIndexChanged(object s, EventArgs e) { if (LS.LastSNTextsCount == wmsCount && comboBox4.Text == comboBox4.Items[0].ToString()) UpdateAllCombos(); } private void comboBox5_SelectedIndexChanged(object s, EventArgs e) { if (LS.LastSNTextsCount == wmsCount && comboBox5.Text == comboBox5.Items[0].ToString()) UpdateAllCombos(); } private void comboBox6_SelectedIndexChanged(object s, EventArgs e) { if (LS.LastSNTextsCount == wmsCount && comboBox6.Text == comboBox6.Items[0].ToString()) UpdateAllCombos(); } private void comboBox7_SelectedIndexChanged(object s, EventArgs e) { if (LS.LastSNTextsCount == wmsCount && comboBox7.Text == comboBox7.Items[0].ToString()) UpdateAllCombos(); } private void comboBox8_SelectedIndexChanged(object s, EventArgs e) { if (LS.LastSNTextsCount == wmsCount && comboBox8.Text == comboBox8.Items[0].ToString()) UpdateAllCombos(); } private void comboBox9_SelectedIndexChanged(object s, EventArgs e) { if (LS.LastSNTextsCount == wmsCount && comboBox9.Text == comboBox9.Items[0].ToString()) UpdateAllCombos(); } private void comboBox10_SelectedIndexChanged(object s, EventArgs e) { if (LS.LastSNTextsCount == wmsCount && comboBox10.Text == comboBox10.Items[0].ToString()) UpdateAllCombos(); } private void comboBox11_SelectedIndexChanged(object s, EventArgs e) { if (LS.LastSNTextsCount == wmsCount && comboBox11.Text == comboBox11.Items[0].ToString()) UpdateAllCombos(); } private void comboBox12_SelectedIndexChanged(object s, EventArgs e) { if (LS.LastSNTextsCount == wmsCount && comboBox12.Text == comboBox12.Items[0].ToString()) UpdateAllCombos(); } private void comboBox13_SelectedIndexChanged(object s, EventArgs e) { if (LS.LastSNTextsCount == wmsCount && comboBox13.Text == comboBox13.Items[0].ToString()) UpdateAllCombos(); } private void comboBox14_SelectedIndexChanged(object s, EventArgs e) { if (LS.LastSNTextsCount == wmsCount && comboBox14.Text == comboBox14.Items[0].ToString()) UpdateAllCombos(); } private void comboBox15_SelectedIndexChanged(object s, EventArgs e) { if (LS.LastSNTextsCount == wmsCount && comboBox15.Text == comboBox15.Items[0].ToString()) UpdateAllCombos(); } private void comboBox16_SelectedIndexChanged(object s, EventArgs e) { if (LS.LastSNTextsCount == wmsCount && comboBox16.Text == comboBox16.Items[0].ToString()) UpdateAllCombos(); } private void comboBox17_SelectedIndexChanged(object s, EventArgs e) { if (LS.LastSNTextsCount == wmsCount && comboBox17.Text == comboBox17.Items[0].ToString()) UpdateAllCombos(); } private void comboBox18_SelectedIndexChanged(object s, EventArgs e) { if (LS.LastSNTextsCount == wmsCount && comboBox18.Text == comboBox18.Items[0].ToString()) UpdateAllCombos(); } private void comboBox19_SelectedIndexChanged(object s, EventArgs e) { if (LS.LastSNTextsCount == wmsCount && comboBox19.Text == comboBox19.Items[0].ToString()) UpdateAllCombos(); } private void comboBox20_SelectedIndexChanged(object s, EventArgs e) { if (LS.LastSNTextsCount == wmsCount && comboBox20.Text == comboBox20.Items[0].ToString()) UpdateAllCombos(); } private void comboBox21_SelectedIndexChanged(object s, EventArgs e) { if (LS.LastSNTextsCount == wmsCount && comboBox21.Text == comboBox21.Items[0].ToString()) UpdateAllCombos(); } private void comboBox22_SelectedIndexChanged(object s, EventArgs e) { if (LS.LastSNTextsCount == wmsCount && comboBox22.Text == comboBox22.Items[0].ToString()) UpdateAllCombos(); } private void comboBox23_SelectedIndexChanged(object s, EventArgs e) { if (LS.LastSNTextsCount == wmsCount && comboBox23.Text == comboBox23.Items[0].ToString()) UpdateAllCombos(); } private void comboBox24_SelectedIndexChanged(object s, EventArgs e) { if (LS.LastSNTextsCount == wmsCount && comboBox24.Text == comboBox24.Items[0].ToString()) UpdateAllCombos(); } private void comboBox25_SelectedIndexChanged(object s, EventArgs e) { if (LS.LastSNTextsCount == wmsCount && comboBox25.Text == comboBox25.Items[0].ToString()) UpdateAllCombos(); } private void comboBox26_SelectedIndexChanged(object s, EventArgs e) { if (LS.LastSNTextsCount == wmsCount && comboBox26.Text == comboBox26.Items[0].ToString()) UpdateAllCombos(); } private void comboBox27_SelectedIndexChanged(object s, EventArgs e) { if (LS.LastSNTextsCount == wmsCount && comboBox27.Text == comboBox27.Items[0].ToString()) UpdateAllCombos(); } private void comboBox28_SelectedIndexChanged(object s, EventArgs e) { if (LS.LastSNTextsCount == wmsCount && comboBox28.Text == comboBox28.Items[0].ToString()) UpdateAllCombos(); } private void comboBox29_SelectedIndexChanged(object s, EventArgs e) { if (LS.LastSNTextsCount == wmsCount && comboBox29.Text == comboBox29.Items[0].ToString()) UpdateAllCombos(); } private void comboBox30_SelectedIndexChanged(object s, EventArgs e) { if (LS.LastSNTextsCount == wmsCount && comboBox30.Text == comboBox30.Items[0].ToString()) UpdateAllCombos(); } private void comboBox31_SelectedIndexChanged(object s, EventArgs e) { if (LS.LastSNTextsCount == wmsCount && comboBox31.Text == comboBox31.Items[0].ToString()) UpdateAllCombos(); } private void comboBox32_SelectedIndexChanged(object s, EventArgs e) { if (LS.LastSNTextsCount == wmsCount && comboBox32.Text == comboBox32.Items[0].ToString()) UpdateAllCombos(); } private void comboBox33_SelectedIndexChanged(object s, EventArgs e) { if (LS.LastSNTextsCount == wmsCount && comboBox33.Text == comboBox33.Items[0].ToString()) UpdateAllCombos(); } private void comboBox34_SelectedIndexChanged(object s, EventArgs e) { if (LS.LastSNTextsCount == wmsCount && comboBox34.Text == comboBox34.Items[0].ToString()) UpdateAllCombos(); } private void comboBox35_SelectedIndexChanged(object s, EventArgs e) { if (LS.LastSNTextsCount == wmsCount && comboBox35.Text == comboBox35.Items[0].ToString()) UpdateAllCombos(); } private void comboBox36_SelectedIndexChanged(object s, EventArgs e) { if (LS.LastSNTextsCount == wmsCount && comboBox36.Text == comboBox36.Items[0].ToString()) UpdateAllCombos(); } private void comboBox37_SelectedIndexChanged(object s, EventArgs e) { if (LS.LastSNTextsCount == wmsCount && comboBox37.Text == comboBox37.Items[0].ToString()) UpdateAllCombos(); } private void comboBox38_SelectedIndexChanged(object s, EventArgs e) { if (LS.LastSNTextsCount == wmsCount && comboBox38.Text == comboBox38.Items[0].ToString()) UpdateAllCombos(); } private void comboBox39_SelectedIndexChanged(object s, EventArgs e) { if (LS.LastSNTextsCount == wmsCount && comboBox39.Text == comboBox39.Items[0].ToString()) UpdateAllCombos(); } private void comboBox40_SelectedIndexChanged(object s, EventArgs e) { if (LS.LastSNTextsCount == wmsCount && comboBox40.Text == comboBox40.Items[0].ToString()) UpdateAllCombos(); } private void comboBox1_KeyPress(object s, KeyPressEventArgs e) { ProcKeyPress(s, e, comboBox1); } private void comboBox2_KeyPress(object s, KeyPressEventArgs e) { ProcKeyPress(s, e, comboBox2); } private void comboBox3_KeyPress(object s, KeyPressEventArgs e) { ProcKeyPress(s, e, comboBox3); } private void comboBox4_KeyPress(object s, KeyPressEventArgs e) { ProcKeyPress(s, e, comboBox4); } private void comboBox5_KeyPress(object s, KeyPressEventArgs e) { ProcKeyPress(s, e, comboBox5); } private void comboBox6_KeyPress(object s, KeyPressEventArgs e) { ProcKeyPress(s, e, comboBox6); } private void comboBox7_KeyPress(object s, KeyPressEventArgs e) { ProcKeyPress(s, e, comboBox7); } private void comboBox8_KeyPress(object s, KeyPressEventArgs e) { ProcKeyPress(s, e, comboBox8); } private void comboBox9_KeyPress(object s, KeyPressEventArgs e) { ProcKeyPress(s, e, comboBox9); } private void comboBox10_KeyPress(object s, KeyPressEventArgs e) { ProcKeyPress(s, e, comboBox10); } private void comboBox11_KeyPress(object s, KeyPressEventArgs e) { ProcKeyPress(s, e, comboBox11); } private void comboBox12_KeyPress(object s, KeyPressEventArgs e) { ProcKeyPress(s, e, comboBox12); } private void comboBox13_KeyPress(object s, KeyPressEventArgs e) { ProcKeyPress(s, e, comboBox13); } private void comboBox14_KeyPress(object s, KeyPressEventArgs e) { ProcKeyPress(s, e, comboBox14); } private void comboBox15_KeyPress(object s, KeyPressEventArgs e) { ProcKeyPress(s, e, comboBox15); } private void comboBox16_KeyPress(object s, KeyPressEventArgs e) { ProcKeyPress(s, e, comboBox16); } private void comboBox17_KeyPress(object s, KeyPressEventArgs e) { ProcKeyPress(s, e, comboBox17); } private void comboBox18_KeyPress(object s, KeyPressEventArgs e) { ProcKeyPress(s, e, comboBox18); } private void comboBox19_KeyPress(object s, KeyPressEventArgs e) { ProcKeyPress(s, e, comboBox19); } private void comboBox20_KeyPress(object s, KeyPressEventArgs e) { ProcKeyPress(s, e, comboBox20); } private void comboBox21_KeyPress(object s, KeyPressEventArgs e) { ProcKeyPress(s, e, comboBox21); } private void comboBox22_KeyPress(object s, KeyPressEventArgs e) { ProcKeyPress(s, e, comboBox22); } private void comboBox23_KeyPress(object s, KeyPressEventArgs e) { ProcKeyPress(s, e, comboBox23); } private void comboBox24_KeyPress(object s, KeyPressEventArgs e) { ProcKeyPress(s, e, comboBox24); } private void comboBox25_KeyPress(object s, KeyPressEventArgs e) { ProcKeyPress(s, e, comboBox25); } private void comboBox26_KeyPress(object s, KeyPressEventArgs e) { ProcKeyPress(s, e, comboBox26); } private void comboBox27_KeyPress(object s, KeyPressEventArgs e) { ProcKeyPress(s, e, comboBox27); } private void comboBox28_KeyPress(object s, KeyPressEventArgs e) { ProcKeyPress(s, e, comboBox28); } private void comboBox29_KeyPress(object s, KeyPressEventArgs e) { ProcKeyPress(s, e, comboBox29); } private void comboBox30_KeyPress(object s, KeyPressEventArgs e) { ProcKeyPress(s, e, comboBox30); } private void comboBox31_KeyPress(object s, KeyPressEventArgs e) { ProcKeyPress(s, e, comboBox31); } private void comboBox32_KeyPress(object s, KeyPressEventArgs e) { ProcKeyPress(s, e, comboBox32); } private void comboBox33_KeyPress(object s, KeyPressEventArgs e) { ProcKeyPress(s, e, comboBox33); } private void comboBox34_KeyPress(object s, KeyPressEventArgs e) { ProcKeyPress(s, e, comboBox34); } private void comboBox35_KeyPress(object s, KeyPressEventArgs e) { ProcKeyPress(s, e, comboBox35); } private void comboBox36_KeyPress(object s, KeyPressEventArgs e) { ProcKeyPress(s, e, comboBox36); } private void comboBox37_KeyPress(object s, KeyPressEventArgs e) { ProcKeyPress(s, e, comboBox37); } private void comboBox38_KeyPress(object s, KeyPressEventArgs e) { ProcKeyPress(s, e, comboBox38); } private void comboBox39_KeyPress(object s, KeyPressEventArgs e) { ProcKeyPress(s, e, comboBox39); } private void comboBox40_KeyPress(object s, KeyPressEventArgs e) { ProcKeyPress(s, e, comboBox40); } /// /// Process a key press within any enabled text boxe /// /// /// /// TextBox control which received the event private void ProcKeyPress(object sender, KeyPressEventArgs e, ComboBox currentFocusOwner) { if (e.KeyChar == '+') { /// Process '+' key ..... Form completed okButton_Click(sender, e); } if (e.KeyChar == '\r') { /// Process key ..... Next text field for (int i = 0; i < textBoxesCount; i++) { if (bodyNrBoxes[i] == currentFocusOwner) { bool isUnique = true; int j; for (j = 0; j < i; j++) { if (bodyNrBoxes[i].Text == bodyNrBoxes[j].Text) { isUnique = false; break; } else { bodyNrBoxes[j].ForeColor = Color.Black; } } if (!isUnique) { bodyNrBoxes[j].ForeColor = Color.Red; bodyNrBoxes[i].Text = string.Empty; ColorFlashAndBeep(this, new ColorFlashEventArgs(3000, Color.Yellow, 700, 500)); return; } if (waterMeters[i].PassedFromTests()) { serialNrBoxes[i].Text = GetNextSerialNr().ToString(); /// WM Passed } else { serialNrBoxes[i].Text = "0"; /// WM failed } break; } } if (enabledBodyNrBoxes.Count < 2) return; /// There is just one enabled textbox for (int i = 0; i < enabledBodyNrBoxes.Count; i++) { if (enabledBodyNrBoxes[i] == currentFocusOwner) { /// Change focus to the next enabled text box enabledBodyNrBoxes[(i + 1) % enabledBodyNrBoxes.Count].Focus(); return; } } } } private void orderCB_SelectedIndexChanged(object sender, EventArgs e) { ProcessPO(); } private void reloadButton_Click(object sender, EventArgs e) { ProcessPO(); } void ProcessPO() { if (ReadPurchaseOrderParamsFromDB(ProcessData.OracleDB.SelectedDB, orderCB.Text, out firstSN, out snDigits, out pcsCount, out prefix, out suffix)) { prefixTextBox.Text = (prefix != null) ? prefix : string.Empty; suffixTextBox.Text = (suffix != null) ? suffix : string.Empty; snDigitsTextBox.Text = snDigits.ToString(); firstSNTextBox.Text = firstSN.ToString(string.Format("D{0}", snDigits)); pcsCountTextBox.Text = pcsCount.ToString(); exclamationPOLabel.Visible = false; } else { prefixTextBox.Text = suffixTextBox.Text = string.Empty; firstSNTextBox.Text = snDigitsTextBox.Text = pcsCountTextBox.Text = string.Empty; exclamationPOLabel.Visible = true; } UpdateSNFromTo(); } bool ReadPurchaseOrderParamsFromDB(OracleConnection connection, string orderNr, out int firstSN, out int snDigits, out int piecesCount, out string prefix, out string suffix) { firstSN = 0; piecesCount = 0; snDigits = 0; prefix = null; suffix = null; if (connection == null || string.IsNullOrEmpty(orderNr)) return false; try { connection.Open(); foreach (var status in new string[] { "NEU", "AKTIV" }) { /// STATUS='NEU' OracleCommand cmd = new OracleCommand("select SOLLSTUECK, ERSTE_ZAEHLERNR, PREFIX, SUFFIX, ZNRLAENGE from VT_AUFTRAG_PD" + " where PRODUKTION_ANBID=:1 AND STATUS=:2 AND PRODUKTION_USESTATE=:3 AND AUFTRAGSNUMMER=:4", connection); cmd.Parameters.Add(new OracleParameter { OracleDbType = OracleDbType.Int32, Value = Output.DB.SensusOracle.Database.Anbid_StaraTura }); ///:1 cmd.Parameters.Add(new OracleParameter { OracleDbType = OracleDbType.Varchar2, Value = status }); ///:2 cmd.Parameters.Add(new OracleParameter { OracleDbType = OracleDbType.Int32, Value = 0 }); ///:3 cmd.Parameters.Add(new OracleParameter { OracleDbType = OracleDbType.Varchar2, Value = orderNr }); ///:4 OracleDataReader dr = cmd.ExecuteReader(); while (dr.Read()) { piecesCount = dr.GetInt32(0); firstSN = dr.GetInt32(1); try { prefix = dr.GetString(2); } catch { prefix = null; } try { suffix = dr.GetString(3); } catch { suffix = null; } snDigits = dr.GetInt32(4); } dr.Close(); } if (firstSN == 0 && piecesCount == 0) { string msg2 = string.Format("Nebola nájdená žiadna výrobná zakázka {0}", orderNr); log.Warn(msg2); Debug.WriteLine(msg2); connection.Close(); return false; } foundMeters.Clear(); OracleCommand cmd2 = new OracleCommand("select VT_FERNUM, ZAEHLERNUMMER, HYDR_PRUEFUNG from VT_ZAEHLER_PD" + " where ANBID=:1 AND AUFTRAGSNUMMER=:2 order by ZAEHLERNUMMER asc", connection); cmd2.Parameters.Add(new OracleParameter { OracleDbType = OracleDbType.Int32, Value = Output.DB.SensusOracle.Database.Anbid_StaraTura }); ///:1 cmd2.Parameters.Add(new OracleParameter { OracleDbType = OracleDbType.Varchar2, Value = orderNr }); ///:2 OracleDataReader dr2 = cmd2.ExecuteReader(); while (dr2.Read()) { string bodyNr = dr2.GetString(0); /// Body number int serialNr = dr2.GetInt32(1); /// Assigned serial number when OK, 0 when NOK int result = dr2.GetInt32(2); /// HYDR_PRUEFUNG: 96=OK, 224=OK after a repetition, 97=NOK if (serialNr != 0 && result != 97) { foundMeters.Add(new BodySerNrResult(bodyNr, serialNr, result)); } } dr2.Close(); string msg = string.Format("Výrobná zakázka bola nájdená: prvé S/N = {0}, počet kusov = {1}, doteraz vyrobených {2}", firstSN, piecesCount, foundMeters.Count); log.Warn(msg); Debug.WriteLine(msg); connection.Close(); return true; } catch (Exception exc) { string msg = string.Format("ERROR: ORACLE DB query select AUFTRAGSNUMMER, SOLLSTUECK from VT_AUFTRAG_PD where ... failed: {0}", exc.Message); log.Error(msg); Debug.WriteLine(msg); firstSN = 0; piecesCount = 0; connection.Close(); return false; } } private void firstSNRangeCB_TextChanged(object s, EventArgs e) { UpdateSNFromTo(); } private void lastSNRangeCB_TextChanged(object s, EventArgs e) { UpdateSNFromTo(); } private void firstSNRangeCB_SelectedIndexChanged(object s, EventArgs e) { UpdateSNFromTo(); } private void lastSNRangeCB_SelectedIndexChanged(object s, EventArgs e) { UpdateSNFromTo(); } void UpdateSNFromTo() { bool anyError = false; foundSNsWithinRange.Clear(); int _snRangeFirst; if (int.TryParse(firstSNRangeCB.Text, out _snRangeFirst) && (_snRangeFirst >= firstSN) && (_snRangeFirst < firstSN + pcsCount)) { snRangeFirst = _snRangeFirst; exclamationFromLabel.Visible = false; } else { snRangeFirst = 0; exclamationFromLabel.Visible = true; anyError = true; } int _snRangeLast; if (int.TryParse(lastSNRangeCB.Text, out _snRangeLast) && (_snRangeLast >= firstSN) && (_snRangeLast < firstSN + pcsCount)) { snRangeLast = _snRangeLast; exclamationToLabel.Visible = false; } else { snRangeLast = 0; exclamationToLabel.Visible = true; anyError = true; } if (snRangeFirst > 0 && snRangeLast > 0 && snRangeFirst > snRangeLast) { snRangeFirst = snRangeLast = 0; exclamationFromLabel.Visible = exclamationToLabel.Visible = true; anyError = true; } if (!anyError) { foreach (var mtr in foundMeters) { if (snRangeFirst <= mtr.SerialNr && mtr.SerialNr <= snRangeLast) { foundSNsWithinRange.Add(mtr.SerialNr); } } } serialNumbersGroupBox.Enabled = !anyError; } /// /// Returns next free serial number within specified range or 0 if no appropriate s/n is available /// /// Serial number or 0 int GetNextSerialNr() { for (int sn = snRangeFirst; sn <= snRangeLast; sn++) { if (!foundSNsWithinRange.Contains(sn) && !assignedSNs.Contains(sn)) { /// A free serial number within specified range found assignedSNs.Add(sn); return sn; } } return 0; /// No free serial number found } /// /// Called from the state machine when an operation forces a modeless dialog close. /// public static void ColorFlashAndBeep(object sender, ColorFlashEventArgs args) { if (ColorFlashHandler != null) { try { ColorFlashHandler(sender, args); } catch (Exception) { } } if (BeepHandler != null) { try { BeepHandler(sender, args); } catch (Exception) { } } } public static event EventHandler BeepHandler; public static event EventHandler ColorFlashHandler; void OnBeep(object sender, ColorFlashEventArgs args) { if (args.BeepFrequency > 0 && args.BeepTime > 0) { Console.Beep(args.BeepFrequency, args.BeepTime); } } private static System.Windows.Forms.Timer colorFlashDurationTimer; void OnColorFlash(object sender, ColorFlashEventArgs args) { // start timer here if (colorFlashDurationTimer == null) { colorFlashDurationTimer = new System.Windows.Forms.Timer(); colorFlashDurationTimer.Tick += (s, e) => { ColorFlashAction(); }; } BackColor = args.FlashColor; colorFlashDurationTimer.Interval = args.FlashTime; colorFlashDurationTimer.Start(); } // Specify what you want to happen when the Elapsed event is // raised. private void ColorFlashAction() { BackColor = SystemColors.Control; colorFlashDurationTimer.Stop(); colorFlashDurationTimer.Enabled = false; } } }