287 lines
11 KiB
C#
287 lines
11 KiB
C#
///
|
|
/// Copyright (c) 2013-2018 Sensus Slovensko a.s.
|
|
///
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Windows.Forms;
|
|
using log4net;
|
|
using TBF.Resources;
|
|
|
|
namespace TBF.Rig.DataEntry.Standard6
|
|
{
|
|
public partial class CycleBeginningForm : Form, GenericDevices.IHasCompleted
|
|
{
|
|
private static readonly ILog log = LogManager.GetLogger(typeof(CycleBeginningForm));
|
|
|
|
/// <summary> Number of text boxes for serial numbers </summary>
|
|
public readonly int WaterMetersCount;
|
|
public readonly bool RemarksEnabled;
|
|
|
|
/// To be retrieved after the form is closed
|
|
public string PurchaseOrder;
|
|
public string[] SNText;
|
|
public bool[] Disabled;
|
|
public string[] Remark;
|
|
|
|
/// Set to 'true' when the form closes
|
|
public bool Completed { get { return completed; } }
|
|
bool completed;
|
|
|
|
IList<ComboBox> enabledComboBoxes;
|
|
|
|
ComboBox[] comboBoxes;
|
|
CheckBox[] checkBoxes;
|
|
ComboBox[] remarkBoxes;
|
|
|
|
/// <summary>
|
|
/// Constructor
|
|
/// </summary>
|
|
/// <param name="waterMetersCount">Number of text boxes for serial numbers</param>
|
|
public CycleBeginningForm(int waterMetersCount, bool remarksEnabled)
|
|
{
|
|
InitializeComponent();
|
|
|
|
this.Icon = Properties.Resources.TBF_icon;
|
|
|
|
ControlBox = false;
|
|
|
|
comboBoxes = new ComboBox[] { comboBox1, comboBox2, comboBox3, comboBox4, comboBox5, comboBox6 };
|
|
checkBoxes = new CheckBox[] { checkBox1, checkBox2, checkBox3, checkBox4, checkBox5, checkBox6 };
|
|
remarkBoxes = new ComboBox[] { remarkComboBox1, remarkComboBox2, remarkComboBox3, remarkComboBox4, remarkComboBox5, remarkComboBox6 };
|
|
|
|
this.WaterMetersCount = Math.Min(waterMetersCount, comboBoxes.Length);
|
|
this.RemarksEnabled = remarksEnabled;
|
|
|
|
SNText = new string[WaterMetersCount];
|
|
Disabled = new bool[WaterMetersCount];
|
|
Remark = new string[WaterMetersCount];
|
|
enabledComboBoxes = new List<ComboBox>();
|
|
|
|
completed = false;
|
|
StartForceCloseHandler();
|
|
}
|
|
|
|
/// <summary> Parameterless constructor for all watermeters </summary>
|
|
public CycleBeginningForm()
|
|
: this(TBF.Data.WMsCount, false)
|
|
{
|
|
}
|
|
|
|
private void CycleBeginningForm_Load(object sender, EventArgs e)
|
|
{
|
|
Localize();
|
|
|
|
DEUtils.PrepareCombo(orderComboBox, Program.LocalSettings.PurchaseOrderHistory);
|
|
|
|
for (int i = 0; i < WaterMetersCount; i++)
|
|
{
|
|
DEUtils.PrepareCombo(remarkBoxes[i], Program.LocalSettings.RemarkHistory, true);
|
|
}
|
|
|
|
if (Program.LocalSettings.LastSNTextsCount == WaterMetersCount)
|
|
{
|
|
if (WaterMetersCount >= 1) comboBox1.Items.Add((Program.LocalSettings.LastSNTexts[0] == null) ? string.Empty : Program.LocalSettings.LastSNTexts[0]);
|
|
if (WaterMetersCount >= 2) comboBox2.Items.Add((Program.LocalSettings.LastSNTexts[1] == null) ? string.Empty : Program.LocalSettings.LastSNTexts[1]);
|
|
if (WaterMetersCount >= 3) comboBox3.Items.Add((Program.LocalSettings.LastSNTexts[2] == null) ? string.Empty : Program.LocalSettings.LastSNTexts[2]);
|
|
if (WaterMetersCount >= 4) comboBox4.Items.Add((Program.LocalSettings.LastSNTexts[3] == null) ? string.Empty : Program.LocalSettings.LastSNTexts[3]);
|
|
if (WaterMetersCount >= 5) comboBox5.Items.Add((Program.LocalSettings.LastSNTexts[4] == null) ? string.Empty : Program.LocalSettings.LastSNTexts[4]);
|
|
if (WaterMetersCount >= 6) comboBox6.Items.Add((Program.LocalSettings.LastSNTexts[5] == null) ? string.Empty : Program.LocalSettings.LastSNTexts[5]);
|
|
}
|
|
|
|
if (WaterMetersCount >= 1) { enabledComboBoxes.Add(comboBox1); } else { comboBox1.Visible = false; label1.Visible = false; checkBox1.Visible = false; }
|
|
if (WaterMetersCount >= 2) { enabledComboBoxes.Add(comboBox2); } else { comboBox2.Visible = false; label2.Visible = false; checkBox2.Visible = false; }
|
|
if (WaterMetersCount >= 3) { enabledComboBoxes.Add(comboBox3); } else { comboBox3.Visible = false; label3.Visible = false; checkBox3.Visible = false; }
|
|
if (WaterMetersCount >= 4) { enabledComboBoxes.Add(comboBox4); } else { comboBox4.Visible = false; label4.Visible = false; checkBox4.Visible = false; }
|
|
if (WaterMetersCount >= 5) { enabledComboBoxes.Add(comboBox5); } else { comboBox5.Visible = false; label5.Visible = false; checkBox5.Visible = false; }
|
|
if (WaterMetersCount >= 6) { enabledComboBoxes.Add(comboBox6); } else { comboBox6.Visible = false; label6.Visible = false; checkBox6.Visible = false; }
|
|
|
|
if (RemarksEnabled)
|
|
{
|
|
if (WaterMetersCount >= 1) { remarkComboBox1.Visible = true; remarkLabel.Visible = true; }
|
|
if (WaterMetersCount >= 2) { remarkComboBox2.Visible = true; }
|
|
if (WaterMetersCount >= 3) { remarkComboBox3.Visible = true; }
|
|
if (WaterMetersCount >= 4) { remarkComboBox4.Visible = true; }
|
|
if (WaterMetersCount >= 5) { remarkComboBox5.Visible = true; }
|
|
if (WaterMetersCount >= 6) { remarkComboBox6.Visible = true; }
|
|
}
|
|
|
|
Height = 177 + WaterMetersCount * 46;
|
|
if (!RemarksEnabled) Width -= remarkComboBox1.Width;
|
|
//Size = new System.Drawing.Size(RemarksEnabled ? 1045 : 624, 177 + WaterMetersCount * 46);
|
|
}
|
|
|
|
void Localize()
|
|
{
|
|
Text = Strings.Data;
|
|
orderLabel.Text = Strings.Purchase_order;
|
|
snLabel.Text = Strings.Serial_number;
|
|
remarkLabel.Text = Strings.Remark;
|
|
okButton.Text = Strings.OkBtnText;
|
|
clearButton.Text = Strings.ClearBtnText;
|
|
|
|
label1.Text = Strings.Water_Meter + " 1";
|
|
label2.Text = Strings.Water_Meter + " 2";
|
|
label3.Text = Strings.Water_Meter + " 3";
|
|
label4.Text = Strings.Water_Meter + " 4";
|
|
label5.Text = Strings.Water_Meter + " 5";
|
|
label6.Text = Strings.Water_Meter + " 6";
|
|
}
|
|
|
|
|
|
private void okButton_Click(object sender, EventArgs e)
|
|
{
|
|
PurchaseOrder = orderComboBox.Text;
|
|
Program.LocalSettings.UpdateHistory(orderComboBox.Text, ref Program.LocalSettings.PurchaseOrderHistory);
|
|
|
|
Program.LocalSettings.LastSNTexts = SNText;
|
|
|
|
for (int i = 0; i < WaterMetersCount; i++)
|
|
{
|
|
Program.LocalSettings.UpdateHistory(remarkBoxes[i].Text, ref Program.LocalSettings.RemarkHistory, 20);
|
|
SNText[i] = comboBoxes[i].Text;
|
|
Disabled[i] = !checkBoxes[i].Checked;
|
|
Remark[i] = remarkBoxes[i].Text;
|
|
}
|
|
|
|
completed = true;
|
|
Close();
|
|
}
|
|
|
|
|
|
private void UpdateAllCombos()
|
|
{
|
|
for (int i = 0; i < WaterMetersCount; i++)
|
|
{
|
|
comboBoxes[i].Text = Program.LocalSettings.LastSNTexts[i];
|
|
checkBoxes[i].Checked = !string.IsNullOrEmpty(comboBoxes[i].Text);
|
|
}
|
|
}
|
|
|
|
private void comboBox1_TextChanged(object sender, EventArgs e) { checkBox1.Checked = true; }
|
|
private void comboBox2_TextChanged(object sender, EventArgs e) { checkBox2.Checked = true; }
|
|
private void comboBox3_TextChanged(object sender, EventArgs e) { checkBox3.Checked = true; }
|
|
private void comboBox4_TextChanged(object sender, EventArgs e) { checkBox4.Checked = true; }
|
|
private void comboBox5_TextChanged(object sender, EventArgs e) { checkBox5.Checked = true; }
|
|
private void comboBox6_TextChanged(object sender, EventArgs e) { checkBox6.Checked = true; }
|
|
|
|
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
|
|
{
|
|
if (Program.LocalSettings.LastSNTextsCount == WaterMetersCount)
|
|
{
|
|
if (comboBox1.Text.Equals(Program.LocalSettings.LastSNTexts[0]))
|
|
UpdateAllCombos();
|
|
}
|
|
}
|
|
private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
|
|
{
|
|
if (Program.LocalSettings.LastSNTextsCount == WaterMetersCount)
|
|
{
|
|
if (comboBox2.Text.Equals(Program.LocalSettings.LastSNTexts[1]))
|
|
UpdateAllCombos();
|
|
}
|
|
}
|
|
private void comboBox3_SelectedIndexChanged(object sender, EventArgs e)
|
|
{
|
|
if (Program.LocalSettings.LastSNTextsCount == WaterMetersCount)
|
|
{
|
|
if (comboBox3.Text.Equals(Program.LocalSettings.LastSNTexts[2]))
|
|
UpdateAllCombos();
|
|
}
|
|
}
|
|
private void comboBox4_SelectedIndexChanged(object sender, EventArgs e)
|
|
{
|
|
if (Program.LocalSettings.LastSNTextsCount == WaterMetersCount)
|
|
{
|
|
if (comboBox4.Text.Equals(Program.LocalSettings.LastSNTexts[3]))
|
|
UpdateAllCombos();
|
|
}
|
|
}
|
|
private void comboBox5_SelectedIndexChanged(object sender, EventArgs e)
|
|
{
|
|
if (Program.LocalSettings.LastSNTextsCount == WaterMetersCount)
|
|
{
|
|
if (comboBox5.Text.Equals(Program.LocalSettings.LastSNTexts[4]))
|
|
UpdateAllCombos();
|
|
}
|
|
}
|
|
private void comboBox6_SelectedIndexChanged(object sender, EventArgs e)
|
|
{
|
|
if (Program.LocalSettings.LastSNTextsCount == WaterMetersCount)
|
|
{
|
|
if (comboBox6.Text.Equals(Program.LocalSettings.LastSNTexts[5]))
|
|
UpdateAllCombos();
|
|
}
|
|
}
|
|
|
|
|
|
private void clearButton_Click(object sender, EventArgs e)
|
|
{
|
|
for (int i = 0; i < WaterMetersCount; i++)
|
|
{
|
|
comboBoxes[i].Text = string.Empty;
|
|
checkBoxes[i].Checked = false;
|
|
}
|
|
}
|
|
|
|
|
|
#region Forced close handling
|
|
|
|
public void StartForceCloseHandler()
|
|
{
|
|
UiBridge.Bridge.CloseModelessFormHandler += delegate(object sender, EventArgs args)
|
|
{
|
|
if (InvokeRequired) { Invoke(new EventHandler<EventArgs>(OnForceClose), sender, args); }
|
|
else OnForceClose(sender, args);
|
|
};
|
|
}
|
|
|
|
private void OnForceClose(object sender, EventArgs args)
|
|
{
|
|
DialogResult = DialogResult.Cancel;
|
|
Close();
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
/// <summary>
|
|
/// Process a key press within any enabled text boxe
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
/// <param name="currentFocusOwner">TextBox control which received the event</param>
|
|
private void ProcKeyPress(object sender, KeyPressEventArgs e, ComboBox currentFocusOwner)
|
|
{
|
|
#if !CEVAK_200
|
|
if (e.KeyChar == '+')
|
|
{
|
|
/// Process '+' key ..... Form completed
|
|
okButton_Click(sender, e);
|
|
}
|
|
#endif
|
|
if (e.KeyChar == '\r')
|
|
{
|
|
/// Process <enter> key ..... Next text field
|
|
if (enabledComboBoxes.Count < 2) return; /// There is just one enabled textbox
|
|
|
|
for (int i = 0; i < enabledComboBoxes.Count; i++)
|
|
{
|
|
if (enabledComboBoxes[i] == currentFocusOwner)
|
|
{
|
|
/// Change focus to the next enabled text box
|
|
enabledComboBoxes[(i + 1) % enabledComboBoxes.Count].Focus();
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private void comboBox1_KeyPress(object sndr, KeyPressEventArgs e) { ProcKeyPress(sndr, e, comboBox1); }
|
|
private void comboBox2_KeyPress(object sndr, KeyPressEventArgs e) { ProcKeyPress(sndr, e, comboBox2); }
|
|
private void comboBox3_KeyPress(object sndr, KeyPressEventArgs e) { ProcKeyPress(sndr, e, comboBox3); }
|
|
private void comboBox4_KeyPress(object sndr, KeyPressEventArgs e) { ProcKeyPress(sndr, e, comboBox4); }
|
|
private void comboBox5_KeyPress(object sndr, KeyPressEventArgs e) { ProcKeyPress(sndr, e, comboBox5); }
|
|
private void comboBox6_KeyPress(object sndr, KeyPressEventArgs e) { ProcKeyPress(sndr, e, comboBox6); }
|
|
}
|
|
}
|