2015-04-15 18:32:56 +00:00
|
|
|
///
|
|
|
|
|
/// Copyright (c) 2013-2015 Sensus Metering Systems
|
|
|
|
|
///
|
2014-07-28 07:54:35 +00:00
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Xml.Serialization;
|
|
|
|
|
|
|
|
|
|
namespace TBF
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Class to be serialized to an XML file...
|
|
|
|
|
/// Public members are local settings.
|
|
|
|
|
/// These settings are modified by dialogs invoked by menu items
|
|
|
|
|
/// Edit->Preferences ... PreferencesDlg ... S1.1(language, etc. local settings), and
|
|
|
|
|
/// Edit->Advanced settings ... AdvancedSettingsDlg ... S1.2(spec. where bench settings are stored)
|
|
|
|
|
/// </summary>
|
|
|
|
|
[XmlRootAttribute("TestBenchFramework")]
|
|
|
|
|
public class LocalSettings
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
2015-04-22 22:58:29 +00:00
|
|
|
/// User interface language (used as CultureInfo(..) constructor argument).
|
2014-07-28 07:54:35 +00:00
|
|
|
/// </summary>
|
|
|
|
|
public string Language = "en";
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Names and database settings of test benches.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[XmlArrayAttribute("TestBenches")]
|
2015-12-04 16:17:20 +00:00
|
|
|
public Config.DatabaseSettings[] TestBenches;
|
2014-07-28 07:54:35 +00:00
|
|
|
|
|
|
|
|
[XmlIgnore]
|
2015-02-28 20:36:33 +00:00
|
|
|
public int BenchesCount { get { return (TestBenches != null) ? TestBenches.GetLength(0) : 0; } }
|
2014-07-28 07:54:35 +00:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Currently selected bench name (local or remote) or null (= no selection done).
|
|
|
|
|
/// </summary>
|
|
|
|
|
[XmlElementAttribute("LastBench")]
|
|
|
|
|
public string LastBenchName;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Currently selected procedure name or null (= no selection done yet).
|
|
|
|
|
/// </summary>
|
|
|
|
|
[XmlElementAttribute("LastProcedure")]
|
|
|
|
|
public string LastProcedureName;
|
2015-02-02 17:09:05 +00:00
|
|
|
public int BatchNr;
|
2015-01-25 07:11:40 +00:00
|
|
|
|
2015-05-15 13:06:06 +00:00
|
|
|
public float RealDensity;
|
|
|
|
|
public float AtTemperature;
|
|
|
|
|
|
2014-07-28 07:54:35 +00:00
|
|
|
public int RightPaneHorizSplitterDistance;
|
2015-12-03 22:37:14 +00:00
|
|
|
public int TopPaneVerticalSplitterDistance;
|
2014-07-28 07:54:35 +00:00
|
|
|
|
2014-09-07 10:36:40 +00:00
|
|
|
/// MainWnd
|
|
|
|
|
public int MainWndLeft;
|
|
|
|
|
public int MainWndTop;
|
|
|
|
|
public int MainWndWidth;
|
|
|
|
|
public int MainWndHeight;
|
|
|
|
|
public bool ManiWndMaximized;
|
|
|
|
|
|
2014-09-07 07:34:28 +00:00
|
|
|
/// Components
|
|
|
|
|
public int ComponentsDlgLeft;
|
|
|
|
|
public int ComponentsDlgTop;
|
|
|
|
|
public int ComponentsDlgWidth;
|
|
|
|
|
public int ComponentsDlgHeight;
|
|
|
|
|
|
2015-11-23 14:11:46 +00:00
|
|
|
[XmlArrayAttribute("ComponentsColumnWidths")]
|
|
|
|
|
public int[] ComponentsColumnWidths;
|
|
|
|
|
[XmlIgnore]
|
|
|
|
|
public int ComponentsColumnCount { get { return (ComponentsColumnWidths != null) ? ComponentsColumnWidths.Length : 0; } }
|
|
|
|
|
|
2014-09-07 07:34:28 +00:00
|
|
|
/// Paths
|
|
|
|
|
public int PathsDlgLeft;
|
|
|
|
|
public int PathsDlgTop;
|
|
|
|
|
public int PathsDlgWidth;
|
|
|
|
|
public int PathsDlgHeight;
|
|
|
|
|
|
2015-08-19 11:04:47 +00:00
|
|
|
/// iPerlCommunicationsForm
|
|
|
|
|
public int iPerlCommunicationsFormLeft;
|
|
|
|
|
public int iPerlCommunicationsFormTop;
|
|
|
|
|
|
2014-09-03 11:42:46 +00:00
|
|
|
[XmlArrayAttribute("FeedingColumnWidths")]
|
|
|
|
|
public int[] FeedingColumnWidths;
|
|
|
|
|
[XmlIgnore]
|
|
|
|
|
public int FeedingColumnCount { get { return (FeedingColumnWidths != null) ? FeedingColumnWidths.Length : 0; } }
|
|
|
|
|
|
|
|
|
|
[XmlArrayAttribute("BenchColumnWidths")]
|
|
|
|
|
public int[] BenchColumnWidths;
|
|
|
|
|
[XmlIgnore]
|
|
|
|
|
public int BenchColumnCount { get { return (BenchColumnWidths != null) ? BenchColumnWidths.Length : 0; } }
|
|
|
|
|
|
|
|
|
|
[XmlArrayAttribute("OutputColumnWidths")]
|
|
|
|
|
public int[] OutputColumnWidths;
|
|
|
|
|
[XmlIgnore]
|
|
|
|
|
public int OutputColumnCount { get { return (OutputColumnWidths != null) ? OutputColumnWidths.Length : 0; } }
|
|
|
|
|
|
|
|
|
|
[XmlArrayAttribute("MetersColumnWidths")]
|
|
|
|
|
public int[] MetersColumnWidths;
|
|
|
|
|
[XmlIgnore]
|
|
|
|
|
public int MetersColumnCount { get { return (MetersColumnWidths != null) ? MetersColumnWidths.Length : 0; } }
|
|
|
|
|
|
2014-09-07 07:34:28 +00:00
|
|
|
/// Transitions
|
|
|
|
|
public int TransitionsDlgLeft;
|
|
|
|
|
public int TransitionsDlgTop;
|
|
|
|
|
public int TransitionsDlgWidth;
|
|
|
|
|
public int TransitionsDlgHeight;
|
|
|
|
|
|
|
|
|
|
[XmlArrayAttribute("TransitionsColumnWidths")]
|
|
|
|
|
public int[] TransitionsColumnWidths;
|
|
|
|
|
[XmlIgnore]
|
|
|
|
|
public int TransitionsColumnCount { get { return (TransitionsColumnWidths != null) ? TransitionsColumnWidths.Length : 0; } }
|
|
|
|
|
|
|
|
|
|
/// Metrology
|
|
|
|
|
public int MetrologyDlgLeft;
|
|
|
|
|
public int MetrologyDlgTop;
|
|
|
|
|
public int MetrologyDlgWidth;
|
|
|
|
|
public int MetrologyDlgHeight;
|
|
|
|
|
|
2015-11-26 22:51:49 +00:00
|
|
|
|
2014-09-07 07:34:28 +00:00
|
|
|
/// Procedures
|
|
|
|
|
public int ProceduresDlgLeft;
|
|
|
|
|
public int ProceduresDlgTop;
|
|
|
|
|
public int ProceduresDlgWidth;
|
|
|
|
|
public int ProceduresDlgHeight;
|
|
|
|
|
|
2015-11-23 14:11:46 +00:00
|
|
|
[XmlArrayAttribute("ProceduresColumnWidths")]
|
|
|
|
|
public int[] ProceduresColumnWidths;
|
|
|
|
|
[XmlIgnore]
|
|
|
|
|
public int ProceduresColumnCount { get { return (ProceduresColumnWidths != null) ? ProceduresColumnWidths.Length : 0; } }
|
|
|
|
|
|
2014-09-07 07:34:28 +00:00
|
|
|
/// OneProcedure
|
|
|
|
|
public int OneProcedureDlgLeft;
|
|
|
|
|
public int OneProcedureDlgTop;
|
|
|
|
|
public int OneProcedureDlgWidth;
|
|
|
|
|
public int OneProcedureDlgHeight;
|
|
|
|
|
|
2015-03-26 08:25:22 +00:00
|
|
|
public int PrintOrderLeft;
|
|
|
|
|
public int PrintOrderTop;
|
|
|
|
|
|
2015-11-26 22:51:49 +00:00
|
|
|
[XmlArrayAttribute("HistoryColumnWidths")]
|
|
|
|
|
public int[] HistoryColumnWidths;
|
|
|
|
|
[XmlIgnore]
|
|
|
|
|
public int HistoryColumnCount { get { return (HistoryColumnWidths != null) ? HistoryColumnWidths.Length : 0; } }
|
|
|
|
|
|
|
|
|
|
|
2015-04-21 20:15:36 +00:00
|
|
|
/// Serial numbers
|
|
|
|
|
public string[] LastSNTexts;
|
|
|
|
|
[XmlIgnore]
|
|
|
|
|
public int LastSNTextsCount { get { return (LastSNTexts != null) ? LastSNTexts.Length : 0; } }
|
|
|
|
|
|
2015-06-12 18:50:06 +00:00
|
|
|
public string[] LastMainSNTexts;
|
|
|
|
|
[XmlIgnore]
|
|
|
|
|
public int LastMainSNTextsCount { get { return (LastMainSNTexts != null) ? LastMainSNTexts.Length : 0; } }
|
|
|
|
|
|
|
|
|
|
public string[] LastAuxSNTexts;
|
|
|
|
|
[XmlIgnore]
|
|
|
|
|
public int LastAuxSNTextsCount { get { return (LastAuxSNTexts != null) ? LastAuxSNTexts.Length : 0; } }
|
|
|
|
|
|
2015-03-26 05:38:03 +00:00
|
|
|
/// Purchase order history
|
|
|
|
|
public string[] PurchaseOrderHistory;
|
|
|
|
|
[XmlIgnore]
|
|
|
|
|
public int PurchaseOrderHistoryCount { get { return (PurchaseOrderHistory != null) ? PurchaseOrderHistory.Length : 0; } }
|
|
|
|
|
|
2015-03-27 08:07:44 +00:00
|
|
|
/// Tester history
|
|
|
|
|
public string[] TesterHistory;
|
|
|
|
|
[XmlIgnore]
|
|
|
|
|
public int TesterHistoryCount { get { return (TesterHistory != null) ? TesterHistory.Length : 0; } }
|
|
|
|
|
|
2015-04-22 05:11:09 +00:00
|
|
|
public bool PrintOrderOnlyGoodResult;
|
2015-04-21 05:34:41 +00:00
|
|
|
public bool PrintOrderOnlyLastResult;
|
|
|
|
|
|
2015-01-12 14:09:09 +00:00
|
|
|
/// Configuration of results
|
2015-12-04 16:17:20 +00:00
|
|
|
public Config.Entities.MetersArrangement ResultsConfigMeters;
|
|
|
|
|
public Config.Entities.TestsArrangement ResultsConfigTests;
|
2015-05-21 10:13:15 +00:00
|
|
|
public int ResultsConfigMetersInOneGroup;
|
2015-01-13 04:00:59 +00:00
|
|
|
public string[] RsltItems_Screen_SingleWM;
|
|
|
|
|
public string[] RsltItems_Screen_CombinedWM;
|
|
|
|
|
public string[] RsltItems_Printer_SingleWM;
|
|
|
|
|
public string[] RsltItems_Printer_CombinedWM;
|
2015-01-18 10:22:53 +00:00
|
|
|
public string[] RsltItems_Disk_SingleWM;
|
|
|
|
|
public string[] RsltItems_Disk_CombinedWM;
|
2014-07-28 07:54:35 +00:00
|
|
|
|
2015-01-16 02:06:50 +00:00
|
|
|
[XmlArrayAttribute("RsltsSingleClmnWdths")]
|
|
|
|
|
public int[] RsltsSingleClmnWdths;
|
|
|
|
|
[XmlIgnore]
|
|
|
|
|
public int RsltsSingleClmnCount { get { return (RsltsSingleClmnWdths != null) ? RsltsSingleClmnWdths.Length : 0; } }
|
|
|
|
|
|
|
|
|
|
[XmlArrayAttribute("RsltsCombinedClmnWdths")]
|
|
|
|
|
public int[] RsltsCombinedClmnWdths;
|
|
|
|
|
[XmlIgnore]
|
|
|
|
|
public int RsltsCombinedClmnCount { get { return (RsltsCombinedClmnWdths != null) ? RsltsCombinedClmnWdths.Length : 0; } }
|
|
|
|
|
|
2014-07-28 07:54:35 +00:00
|
|
|
[XmlIgnore]
|
|
|
|
|
public readonly bool AlwaysAskPasswdWhenUnlocking;
|
|
|
|
|
|
|
|
|
|
[XmlIgnore]
|
|
|
|
|
public readonly bool RestoreUserWhenLeavingDialog;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public LocalSettings()
|
|
|
|
|
{
|
|
|
|
|
AlwaysAskPasswdWhenUnlocking = false;
|
|
|
|
|
RestoreUserWhenLeavingDialog = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Load public fields of this class from the XML file.
|
|
|
|
|
/// </summary>
|
2015-02-28 20:36:33 +00:00
|
|
|
/// <returns>LocalSettings object or null when Load() fails</returns>
|
|
|
|
|
public static LocalSettings Load(string fileName)
|
2014-07-28 07:54:35 +00:00
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2015-02-28 20:36:33 +00:00
|
|
|
using (TextReader reader = new StreamReader(fileName))
|
2014-07-28 07:54:35 +00:00
|
|
|
{
|
|
|
|
|
LocalSettings ls = (new XmlSerializer(typeof(LocalSettings))).Deserialize(reader) as LocalSettings;
|
|
|
|
|
// Copy the settings just in case De-serialize() completes OK
|
2015-02-28 20:36:33 +00:00
|
|
|
return ls;
|
2014-07-28 07:54:35 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
string msg = e.Message;
|
2015-02-28 20:36:33 +00:00
|
|
|
return null;
|
2014-07-28 07:54:35 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Save public fields of this class to the XML file.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void Save()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
using (TextWriter writer = new StreamWriter(Program.LocalSettingsFileName))
|
|
|
|
|
{
|
|
|
|
|
(new XmlSerializer(typeof(LocalSettings))).Serialize(writer, this);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
string msg = e.Message;
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-03-26 05:38:03 +00:00
|
|
|
|
|
|
|
|
/// <summary>
|
2015-03-27 08:07:44 +00:00
|
|
|
/// Updates history stored in a string array by a new latest string.
|
2015-03-26 05:38:03 +00:00
|
|
|
/// </summary>
|
2015-03-27 08:07:44 +00:00
|
|
|
/// <param name="lastStrValue">Lste entered string</param>
|
2015-03-26 08:25:22 +00:00
|
|
|
/// <returns>true = updated and saved</returns>
|
2015-03-27 08:07:44 +00:00
|
|
|
public bool UpdateHistory(string lastStrValue, ref string[] history, int maxHistoryLen = 10)
|
2015-03-26 05:38:03 +00:00
|
|
|
{
|
2015-03-27 08:07:44 +00:00
|
|
|
if (string.IsNullOrEmpty(lastStrValue)) return false;
|
2015-03-26 08:25:22 +00:00
|
|
|
|
2015-03-27 08:07:44 +00:00
|
|
|
int currentHistoryCount = (history != null) ? history.Length : 0;
|
2015-03-26 05:38:03 +00:00
|
|
|
|
|
|
|
|
int match = -1;
|
2015-03-27 08:07:44 +00:00
|
|
|
for (int i = 0; i < currentHistoryCount; i++)
|
2015-03-26 05:38:03 +00:00
|
|
|
{
|
2015-03-27 08:07:44 +00:00
|
|
|
if (history[i] == lastStrValue)
|
2015-03-26 05:38:03 +00:00
|
|
|
{
|
|
|
|
|
match = i;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-27 08:07:44 +00:00
|
|
|
if (match >= 0 || currentHistoryCount >= maxHistoryLen)
|
2015-03-26 05:38:03 +00:00
|
|
|
{
|
2015-03-26 08:25:22 +00:00
|
|
|
/// History does not have to be (because of a match) or should not be extended (because of the lenght)
|
2015-06-06 14:52:09 +00:00
|
|
|
if (match < 0) match = currentHistoryCount - 1;
|
2015-03-26 05:38:03 +00:00
|
|
|
|
|
|
|
|
for (int j = match; j > 0; j--)
|
|
|
|
|
{
|
2015-03-27 08:07:44 +00:00
|
|
|
history[j] = history[j - 1];
|
2015-03-26 05:38:03 +00:00
|
|
|
}
|
2015-03-27 08:07:44 +00:00
|
|
|
history[0] = lastStrValue;
|
2015-03-26 05:38:03 +00:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
/// History wiil be extended, new item inserted at the beginning
|
2015-03-27 08:07:44 +00:00
|
|
|
string[] newHistory = new string[currentHistoryCount + 1];
|
|
|
|
|
newHistory[0] = lastStrValue;
|
|
|
|
|
for (int j = 1; j <= currentHistoryCount; j++)
|
2015-03-26 05:38:03 +00:00
|
|
|
{
|
2015-03-27 08:07:44 +00:00
|
|
|
newHistory[j] = history[j - 1];
|
2015-03-26 05:38:03 +00:00
|
|
|
}
|
2015-03-27 08:07:44 +00:00
|
|
|
history = newHistory;
|
2015-03-26 05:38:03 +00:00
|
|
|
}
|
|
|
|
|
Save();
|
2015-03-26 08:25:22 +00:00
|
|
|
return true;
|
2015-03-26 05:38:03 +00:00
|
|
|
}
|
|
|
|
|
|
2014-07-28 07:54:35 +00:00
|
|
|
}
|
|
|
|
|
}
|