From 847862a55467cbe53bcc4cedc5bef1ae2a2bb719 Mon Sep 17 00:00:00 2001 From: Milan Hanajik Date: Thu, 26 Mar 2015 06:38:03 +0100 Subject: [PATCH] Purchase order history in Local settings --- .../DataEntry/Standard/CycleBeginningForm.cs | 30 +++++++++--- TestBenchFramework/LocalSettings.cs | 49 +++++++++++++++++++ .../Resources/Strings.Designer.cs | 9 ++++ TestBenchFramework/Resources/Strings.resx | 3 ++ 4 files changed, 84 insertions(+), 7 deletions(-) diff --git a/TestBenchFramework/BenchControl/DataEntry/Standard/CycleBeginningForm.cs b/TestBenchFramework/BenchControl/DataEntry/Standard/CycleBeginningForm.cs index f87a41123..9795573c2 100644 --- a/TestBenchFramework/BenchControl/DataEntry/Standard/CycleBeginningForm.cs +++ b/TestBenchFramework/BenchControl/DataEntry/Standard/CycleBeginningForm.cs @@ -37,15 +37,11 @@ namespace TBF.BenchControl.DataEntry.Standard Height = 147 + WaterMetersCount * 90; } - /// Parameterless constructor for 3 watermeters - 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) + /// + /// Load Purchase order combo box items from the LocalSettings PurchaseOrderHistory array + /// + /// Puchase order ComboBox + 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; } diff --git a/TestBenchFramework/LocalSettings.cs b/TestBenchFramework/LocalSettings.cs index b9507000c..e91012724 100644 --- a/TestBenchFramework/LocalSettings.cs +++ b/TestBenchFramework/LocalSettings.cs @@ -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; } } + + /// + /// Updates purchase order history + /// + /// + 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(); + } + } } diff --git a/TestBenchFramework/Resources/Strings.Designer.cs b/TestBenchFramework/Resources/Strings.Designer.cs index 578cd1a60..ae80a3444 100644 --- a/TestBenchFramework/Resources/Strings.Designer.cs +++ b/TestBenchFramework/Resources/Strings.Designer.cs @@ -1626,6 +1626,15 @@ namespace TBF.Resources { } } + /// + /// Looks up a localized string similar to Purchase Order. + /// + internal static string Purchase_Order { + get { + return ResourceManager.GetString("Purchase_Order", resourceCulture); + } + } + /// /// Looks up a localized string similar to Fill the test bench with water?. /// diff --git a/TestBenchFramework/Resources/Strings.resx b/TestBenchFramework/Resources/Strings.resx index c74b6fa1b..b262ab136 100644 --- a/TestBenchFramework/Resources/Strings.resx +++ b/TestBenchFramework/Resources/Strings.resx @@ -994,4 +994,7 @@ Closing input valve, switching the pump off + + Purchase Order + \ No newline at end of file