227 lines
7.3 KiB
C#
227 lines
7.3 KiB
C#
///
|
|
/// Copyright (c) 2018-2020 Sensus Slovensko a.s.
|
|
///
|
|
using System;
|
|
using System.IO;
|
|
using System.Text;
|
|
using System.Xml.Serialization;
|
|
|
|
namespace ResultsBrowser
|
|
{
|
|
/// <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("ResultsBrowser")]
|
|
public class LocalSettings
|
|
{
|
|
/// <summary>
|
|
/// User interface language (used as CultureInfo(..) constructor argument).
|
|
/// </summary>
|
|
public string Language;
|
|
|
|
/// Names of servers.
|
|
public string Bench1;
|
|
public string Bench2;
|
|
public string Bench3;
|
|
public string Bench4;
|
|
public string Bench5;
|
|
public string Bench6;
|
|
public string Bench7;
|
|
public string Bench8;
|
|
public string Bench9;
|
|
|
|
/// Database settings of servers.
|
|
public string ConnectionString1;
|
|
public string ConnectionString2;
|
|
public string ConnectionString3;
|
|
public string ConnectionString4;
|
|
public string ConnectionString5;
|
|
public string ConnectionString6;
|
|
public string ConnectionString7;
|
|
public string ConnectionString8;
|
|
public string ConnectionString9;
|
|
|
|
public bool Bench1Selected;
|
|
public bool Bench2Selected;
|
|
public bool Bench3Selected;
|
|
public bool Bench4Selected;
|
|
public bool Bench5Selected;
|
|
public bool Bench6Selected;
|
|
public bool Bench7Selected;
|
|
public bool Bench8Selected;
|
|
public bool Bench9Selected;
|
|
|
|
public string TimePeriodFormat;
|
|
|
|
/// Statistics options
|
|
public bool TwoDim;
|
|
public string RowItemCaption;
|
|
public string RowItemCaption2;
|
|
public string RowItemCaption3;
|
|
public string ColumnItemCaption;
|
|
public string ColumnItemCaption2;
|
|
public string ColumnItemCaption3;
|
|
public string RowTestSpecifier;
|
|
public string RowTestSpecifier2;
|
|
public string RowTestSpecifier3;
|
|
public string ColumnTestSpecifier;
|
|
public string ColumnTestSpecifier2;
|
|
public string ColumnTestSpecifier3;
|
|
|
|
|
|
public bool FilterPurchaseOrder;
|
|
public bool FilterProcedure;
|
|
public bool FilterBatchNr;
|
|
public bool FilterDate;
|
|
public bool ResolveManually;
|
|
|
|
/// MainWnd
|
|
public int MainWndLeft;
|
|
public int MainWndTop;
|
|
public int MainWndWidth;
|
|
public int MainWndHeight;
|
|
public bool ManiWndMaximized;
|
|
public int SplitterDistance;
|
|
|
|
/// Last configuration file name
|
|
public string LastConfigFileName;
|
|
|
|
/// Purchase order history
|
|
public string LastPurchaseOrder;
|
|
public string[] PurchaseOrderHistory;
|
|
[XmlIgnore]
|
|
public int PurchaseOrderHistoryCount { get { return (PurchaseOrderHistory != null) ? PurchaseOrderHistory.Length : 0; } }
|
|
|
|
/// Procedure history
|
|
public string LastProcedure;
|
|
public string[] ProcedureHistory;
|
|
[XmlIgnore]
|
|
public int ProcedureHistoryCount { get { return (ProcedureHistory != null) ? ProcedureHistory.Length : 0; } }
|
|
|
|
/// BatchNr range
|
|
public string BatchFrom;
|
|
public string BatchTo;
|
|
|
|
/// Report file name history
|
|
public string LastReportFileName;
|
|
public string[] ReportFileNameHistory;
|
|
[XmlIgnore]
|
|
public int ReportFileNameHistoryCount { get { return (ReportFileNameHistory != null) ? ReportFileNameHistory.Length : 0; } }
|
|
|
|
/// Report configuration
|
|
public string[] ReportItems_Single;
|
|
public string[] ReportItems_Compound;
|
|
|
|
public LocalSettings()
|
|
{
|
|
#if TURA_IPERL || TURA_IPERL_NEW || TURA_SPECIAL
|
|
Bench1 = "WR10";
|
|
Bench2 = "WR11";
|
|
Bench3 = "WR13";
|
|
Bench4 = "WR14";
|
|
Bench5 = "WR15";
|
|
Bench6 = "WR18";
|
|
Bench7 = "WR19";
|
|
ConnectionString1 = "SERVER=10.42.129.253; DATABASE=st-wr10-r; UID=vysledky; PASSWORD=GAqx76QUB6NbnpZP; CharSet=utf8;";
|
|
ConnectionString2 = "SERVER=10.42.129.27; DATABASE=st-wr11-r; UID=vysledky; PASSWORD=GAqx76QUB6NbnpZP; CharSet=utf8;";
|
|
ConnectionString3 = "SERVER=10.42.128.138; DATABASE=st-wr13-r; UID=vysledky; PASSWORD=GAqx76QUB6NbnpZP; CharSet=utf8;";
|
|
ConnectionString4 = "SERVER=10.42.128.146; DATABASE=st-wr14-r; UID=vysledky; PASSWORD=GAqx76QUB6NbnpZP; CharSet=utf8;";
|
|
ConnectionString5 = "SERVER=10.42.130.97; DATABASE=st-wr15-r; UID=vysledky; PASSWORD=GAqx76QUB6NbnpZP; CharSet=utf8;";
|
|
ConnectionString6 = "SERVER=10.42.130.165; DATABASE=st-wr18-r; UID=vysledky; PASSWORD=GAqx76QUB6NbnpZP; CharSet=utf8;";
|
|
ConnectionString7 = "SERVER=10.42.128.159; DATABASE=st-wr19-r; UID=vysledky; PASSWORD=GAqx76QUB6NbnpZP; CharSet=utf8;";
|
|
Language = "SK";
|
|
#endif
|
|
}
|
|
|
|
/// <summary>
|
|
/// Load public fields of this class from the XML file.
|
|
/// </summary>
|
|
public static LocalSettings Load(string fileName)
|
|
{
|
|
try
|
|
{
|
|
using (TextReader reader = new StreamReader(fileName))
|
|
{
|
|
LocalSettings ls = (new XmlSerializer(typeof(LocalSettings))).Deserialize(reader) as LocalSettings;
|
|
// Copy the settings just in case De-serialize() completes OK
|
|
return ls;
|
|
}
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
string msg = e.Message;
|
|
return null;
|
|
}
|
|
}
|
|
|
|
/// <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;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Updates history stored in a string array by a new latest string.
|
|
/// </summary>
|
|
/// <param name="lastStrValue">Lste entered string</param>
|
|
/// <returns>true = updated and saved</returns>
|
|
public bool UpdateHistory(string lastStrValue, ref string[] history, int maxHistoryLen = 10)
|
|
{
|
|
if (string.IsNullOrEmpty(lastStrValue)) return false;
|
|
|
|
int currentHistoryCount = (history != null) ? history.Length : 0;
|
|
|
|
int match = -1;
|
|
for (int i = 0; i < currentHistoryCount; i++)
|
|
{
|
|
if (history[i] == lastStrValue)
|
|
{
|
|
match = i;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (match >= 0 || currentHistoryCount >= maxHistoryLen)
|
|
{
|
|
/// History does not have to be (because of a match) or should not be extended (because of the lenght)
|
|
if (match < 0) match = currentHistoryCount - 1;
|
|
|
|
for (int j = match; j > 0; j--)
|
|
{
|
|
history[j] = history[j - 1];
|
|
}
|
|
history[0] = lastStrValue;
|
|
}
|
|
else
|
|
{
|
|
/// History wiil be extended, new item inserted at the beginning
|
|
string[] newHistory = new string[currentHistoryCount + 1];
|
|
newHistory[0] = lastStrValue;
|
|
for (int j = 1; j <= currentHistoryCount; j++)
|
|
{
|
|
newHistory[j] = history[j - 1];
|
|
}
|
|
history = newHistory;
|
|
}
|
|
Save();
|
|
return true;
|
|
}
|
|
}
|
|
}
|