Purchase order history in Local settings

This commit is contained in:
Milan Hanajik 2015-03-26 06:38:03 +01:00
parent 0323efe57c
commit 847862a554
4 changed files with 84 additions and 7 deletions

View File

@ -37,15 +37,11 @@ namespace TBF.BenchControl.DataEntry.Standard
Height = 147 + WaterMetersCount * 90;
}
/// <summary> Parameterless constructor for 3 watermeters </summary>
public CycleBeginningForm()
: this(3)
{
}
private void CycleBeginningForm_Load(object sender, EventArgs e)
{
Localize();
PrepareOrderCombo(orderComboBox);
if (WaterMetersCount < 1) groupBox1.Visible = false;
if (WaterMetersCount < 2) groupBox2.Visible = false;
@ -58,6 +54,7 @@ namespace TBF.BenchControl.DataEntry.Standard
void Localize()
{
Text = Strings.Data;
orderGroupBox.Text = Strings.Purchase_Order;
groupBox1.Text = Strings.Water_Meter + " 1";
groupBox2.Text = Strings.Water_Meter + " 2";
groupBox3.Text = Strings.Water_Meter + " 3";
@ -73,9 +70,28 @@ namespace TBF.BenchControl.DataEntry.Standard
okButton.Text = Strings.OkBtnText;
}
private void okButton_Click(object sender, EventArgs e)
/// <summary>
/// Load Purchase order combo box items from the LocalSettings PurchaseOrderHistory array
/// </summary>
/// <param name="orderComboBox">Puchase order ComboBox</param>
void PrepareOrderCombo(ComboBox orderComboBox)
{
for (int i = 0; i < Program.LocalSettings.PurchaseOrderHistoryCount; i++)
{
orderComboBox.Items.Add(Program.LocalSettings.PurchaseOrderHistory[i]);
}
if (orderComboBox.Items.Count > 0)
{
orderComboBox.Text = orderComboBox.Items[0].ToString();
}
}
private void okButton_Click(object sender, EventArgs e)
{
PurchaseOrder = orderComboBox.Text;
Program.LocalSettings.UpdatePurchaseOrderHistory(orderComboBox.Text);
if (WaterMetersCount >= 1) { SNText[0] = textBox1.Text; Disabled[0] = !checkBox1.Checked; }
if (WaterMetersCount >= 2) { SNText[1] = textBox2.Text; Disabled[1] = !checkBox2.Checked; }
if (WaterMetersCount >= 3) { SNText[2] = textBox3.Text; Disabled[2] = !checkBox3.Checked; }

View File

@ -126,6 +126,11 @@ namespace TBF
public int OneProcedureDlgWidth;
public int OneProcedureDlgHeight;
/// Purchase order history
public string[] PurchaseOrderHistory;
[XmlIgnore]
public int PurchaseOrderHistoryCount { get { return (PurchaseOrderHistory != null) ? PurchaseOrderHistory.Length : 0; } }
/// Configuration of results
public Forms.ResultsConfig.Meters ResultsConfigMeters;
public Forms.ResultsConfig.TestsAre ResultsConfigTests;
@ -198,5 +203,49 @@ namespace TBF
string msg = e.Message;
}
}
/// <summary>
/// Updates purchase order history
/// </summary>
/// <param name="lastPurchaseOrder"></param>
public void UpdatePurchaseOrderHistory(string lastPurchaseOrder)
{
if (string.IsNullOrEmpty(lastPurchaseOrder)) return;
int match = -1;
for (int i = 0; i < PurchaseOrderHistoryCount; i++)
{
if (PurchaseOrderHistory[i] == lastPurchaseOrder)
{
match = i;
break;
}
}
if (match >= 0 || PurchaseOrderHistoryCount >= 10)
{
/// History does not have to be or should not be extended
if (match < 0) match = PurchaseOrderHistoryCount - 1;
for (int j = match; j > 0; j--)
{
PurchaseOrderHistory[j] = PurchaseOrderHistory[j - 1];
}
Program.LocalSettings.PurchaseOrderHistory[0] = lastPurchaseOrder;
}
else
{
/// History wiil be extended, new item inserted at the beginning
string[] newHistory = new string[Program.LocalSettings.PurchaseOrderHistoryCount + 1];
newHistory[0] = lastPurchaseOrder;
for (int j = 1; j <= PurchaseOrderHistoryCount; j++)
{
newHistory[j] = PurchaseOrderHistory[j - 1];
}
PurchaseOrderHistory = newHistory;
}
Save();
}
}
}

View File

@ -1626,6 +1626,15 @@ namespace TBF.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to Purchase Order.
/// </summary>
internal static string Purchase_Order {
get {
return ResourceManager.GetString("Purchase_Order", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Fill the test bench with water?.
/// </summary>

View File

@ -994,4 +994,7 @@
<data name="Closing_valve_Pump_off" xml:space="preserve">
<value>Closing input valve, switching the pump off</value>
</data>
<data name="Purchase_Order" xml:space="preserve">
<value>Purchase Order</value>
</data>
</root>