From 44761ff41192e66fa23dbc784a74f368c6b4ce21 Mon Sep 17 00:00:00 2001 From: Milan Hanajik Date: Fri, 12 Nov 2021 08:01:54 +0100 Subject: [PATCH] OrderManagement project added, ver. 3.1.1809 --- .gitignore | 2 + OrderManagement/App.config | 6 + OrderManagement/EditOrderDlg.Designer.cs | 99 +++++ OrderManagement/EditOrderDlg.cs | 92 ++++ OrderManagement/EditOrderDlg.resx | 120 ++++++ OrderManagement/EditParametersCtrl.cs | 131 ++++++ .../EditParametersCtrl.designer.cs | 71 ++++ OrderManagement/EditParametersCtrl.resx | 120 ++++++ OrderManagement/LocalSettings.cs | 243 +++++++++++ OrderManagement/OrderManagement.csproj | 163 +++++++ .../OrderManagementDlg.Designer.cs | 180 ++++++++ OrderManagement/OrderManagementDlg.cs | 276 ++++++++++++ OrderManagement/OrderManagementDlg.resx | 123 ++++++ OrderManagement/Program.cs | 251 +++++++++++ OrderManagement/Properties/AssemblyInfo.cs | 36 ++ .../Properties/Resources.Designer.cs | 71 ++++ OrderManagement/Properties/Resources.resx | 117 ++++++ .../Properties/Settings.Designer.cs | 30 ++ OrderManagement/Properties/Settings.settings | 7 + OrderManagement/Resources/Strings.Designer.cs | 396 ++++++++++++++++++ OrderManagement/Resources/Strings.resx | 231 ++++++++++ OrderManagement/Resources/Strings.sk.resx | 219 ++++++++++ .../SampleConfig/log4netConfig.xml | 23 + OrderManagement/SettingsDlg.Designer.cs | 179 ++++++++ OrderManagement/SettingsDlg.cs | 126 ++++++ OrderManagement/SettingsDlg.resx | 120 ++++++ TBF.sln | 12 + TBF/Properties/AssemblyInfo.cs | 4 +- clean.bat | 4 + 29 files changed, 3450 insertions(+), 2 deletions(-) create mode 100644 OrderManagement/App.config create mode 100644 OrderManagement/EditOrderDlg.Designer.cs create mode 100644 OrderManagement/EditOrderDlg.cs create mode 100644 OrderManagement/EditOrderDlg.resx create mode 100644 OrderManagement/EditParametersCtrl.cs create mode 100644 OrderManagement/EditParametersCtrl.designer.cs create mode 100644 OrderManagement/EditParametersCtrl.resx create mode 100644 OrderManagement/LocalSettings.cs create mode 100644 OrderManagement/OrderManagement.csproj create mode 100644 OrderManagement/OrderManagementDlg.Designer.cs create mode 100644 OrderManagement/OrderManagementDlg.cs create mode 100644 OrderManagement/OrderManagementDlg.resx create mode 100644 OrderManagement/Program.cs create mode 100644 OrderManagement/Properties/AssemblyInfo.cs create mode 100644 OrderManagement/Properties/Resources.Designer.cs create mode 100644 OrderManagement/Properties/Resources.resx create mode 100644 OrderManagement/Properties/Settings.Designer.cs create mode 100644 OrderManagement/Properties/Settings.settings create mode 100644 OrderManagement/Resources/Strings.Designer.cs create mode 100644 OrderManagement/Resources/Strings.resx create mode 100644 OrderManagement/Resources/Strings.sk.resx create mode 100644 OrderManagement/SampleConfig/log4netConfig.xml create mode 100644 OrderManagement/SettingsDlg.Designer.cs create mode 100644 OrderManagement/SettingsDlg.cs create mode 100644 OrderManagement/SettingsDlg.resx diff --git a/.gitignore b/.gitignore index a8737564b..4ee4dfb00 100644 --- a/.gitignore +++ b/.gitignore @@ -26,6 +26,8 @@ GraphLib/bin GraphLib/obj MergeResultsDBs/bin MergeResultsDBs/obj +OrderManagement/bin +OrderManagement/obj TracingDB/bin TracingDB/obj ResetBatchNr/bin diff --git a/OrderManagement/App.config b/OrderManagement/App.config new file mode 100644 index 000000000..56efbc7b5 --- /dev/null +++ b/OrderManagement/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/OrderManagement/EditOrderDlg.Designer.cs b/OrderManagement/EditOrderDlg.Designer.cs new file mode 100644 index 000000000..723d70255 --- /dev/null +++ b/OrderManagement/EditOrderDlg.Designer.cs @@ -0,0 +1,99 @@ +namespace OrderManagement +{ + partial class EditOrderDlg + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.splitContainer1 = new System.Windows.Forms.SplitContainer(); + this.cancelButton = new System.Windows.Forms.Button(); + this.okButton = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit(); + this.splitContainer1.Panel2.SuspendLayout(); + this.splitContainer1.SuspendLayout(); + this.SuspendLayout(); + // + // splitContainer1 + // + this.splitContainer1.Dock = System.Windows.Forms.DockStyle.Fill; + this.splitContainer1.FixedPanel = System.Windows.Forms.FixedPanel.Panel2; + this.splitContainer1.Location = new System.Drawing.Point(0, 0); + this.splitContainer1.Name = "splitContainer1"; + // + // splitContainer1.Panel2 + // + this.splitContainer1.Panel2.Controls.Add(this.cancelButton); + this.splitContainer1.Panel2.Controls.Add(this.okButton); + this.splitContainer1.Size = new System.Drawing.Size(685, 352); + this.splitContainer1.SplitterDistance = 555; + this.splitContainer1.TabIndex = 0; + // + // cancelButton + // + this.cancelButton.ImeMode = System.Windows.Forms.ImeMode.NoControl; + this.cancelButton.Location = new System.Drawing.Point(21, 70); + this.cancelButton.Name = "cancelButton"; + this.cancelButton.Size = new System.Drawing.Size(85, 40); + this.cancelButton.TabIndex = 6; + this.cancelButton.Text = "Cancel"; + this.cancelButton.UseVisualStyleBackColor = true; + this.cancelButton.Click += new System.EventHandler(this.cancelButton_Click); + // + // okButton + // + this.okButton.ImeMode = System.Windows.Forms.ImeMode.NoControl; + this.okButton.Location = new System.Drawing.Point(21, 20); + this.okButton.Name = "okButton"; + this.okButton.Size = new System.Drawing.Size(85, 40); + this.okButton.TabIndex = 5; + this.okButton.Text = "OK"; + this.okButton.UseVisualStyleBackColor = true; + this.okButton.Click += new System.EventHandler(this.okButton_Click); + // + // EditOrderDlg + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(685, 352); + this.Controls.Add(this.splitContainer1); + this.Name = "EditOrderDlg"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; + this.Text = "EditOrderDlg"; + this.splitContainer1.Panel2.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).EndInit(); + this.splitContainer1.ResumeLayout(false); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.SplitContainer splitContainer1; + private System.Windows.Forms.Button cancelButton; + private System.Windows.Forms.Button okButton; + + } +} \ No newline at end of file diff --git a/OrderManagement/EditOrderDlg.cs b/OrderManagement/EditOrderDlg.cs new file mode 100644 index 000000000..9705d7201 --- /dev/null +++ b/OrderManagement/EditOrderDlg.cs @@ -0,0 +1,92 @@ +/// +/// Copyright (c) 2021 Sensus Slovensko a.s. +/// +using System; +using System.Collections.Generic; +using System.Linq; +using System.Windows.Forms; +using SharedDatabase.Entities; +using OrderManagement.Resources; +using NHibernate; + +namespace OrderManagement +{ + public partial class EditOrderDlg : Form + { + ISession session; + OrderInfo order; + IList listOfOrders; + bool editMode; + string oriPOName; + + EditParametersCtrl editParametersCtrl; + + public EditOrderDlg(ISession session, OrderInfo order, IList listOfOrders, bool editMode = false) + { + InitializeComponent(); + + this.session = session; + this.order = order; + this.listOfOrders = listOfOrders; + this.editMode = editMode; + oriPOName = order.POName; + + editParametersCtrl = new EditParametersCtrl(this.order); + editParametersCtrl.Dock = DockStyle.Fill; + editParametersCtrl.Unlock(); + splitContainer1.Panel1.Controls.Add(editParametersCtrl); + + Localize(); + } + + void Localize() + { + okButton.Text = Strings.OK; + cancelButton.Text = Strings.Cancel; + } + + private void okButton_Click(object sender, EventArgs e) + { + OrderInfo orderWithTheSameName = listOfOrders.FirstOrDefault(x => (x.POName == order.POName)); + + if (orderWithTheSameName != null && (!editMode || order.POName != oriPOName)) + { + MessageBox.Show(Strings.Order_with_the_same_ID_already_exists); + return; + } + + DialogResult = Save() ? DialogResult.OK : DialogResult.Cancel; + Close(); + } + + bool Save() + { + ITransaction transaction = session.BeginTransaction(); + + try + { + Cursor.Current = Cursors.WaitCursor; + + session.SaveOrUpdate(order); + transaction.Commit(); + session.Flush(); + Cursor.Current = Cursors.Default; + return true; + } + catch (Exception exc) + { + transaction.Rollback(); + MessageBox.Show(string.Format("{0}{1}{2}", Strings.Saving_order_failed, Environment.NewLine, exc.Message), + Strings.Error, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); + Cursor.Current = Cursors.Default; + return false; + } + } + + private void cancelButton_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/OrderManagement/EditOrderDlg.resx b/OrderManagement/EditOrderDlg.resx new file mode 100644 index 000000000..1af7de150 --- /dev/null +++ b/OrderManagement/EditOrderDlg.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/OrderManagement/EditParametersCtrl.cs b/OrderManagement/EditParametersCtrl.cs new file mode 100644 index 000000000..bb2ae5044 --- /dev/null +++ b/OrderManagement/EditParametersCtrl.cs @@ -0,0 +1,131 @@ +/// +/// Copyright (c) 2021 Sensus Slovensko a.s. +/// +using System; +using System.Collections.Generic; +using System.Windows.Forms; +using log4net; +using Common; +using OrderManagement.Resources; + +namespace OrderManagement +{ + public partial class EditParametersCtrl : UserControl + { + static readonly ILog log = LogManager.GetLogger(typeof(EditParametersCtrl)); + + IParamsProvider paramsProvider; + Control[] editors; + CfgUpdateFlags flags; + + public EditParametersCtrl() + { + InitializeComponent(); + } + + /// + /// Constructor + /// + /// Parameters provider implementing IComponentCfg and IParamsProvider + /// A list of parents or null, null hides parentComboBox + public EditParametersCtrl(object paramsProvider) + : this() + { + this.paramsProvider = paramsProvider as IParamsProvider; + if (this.paramsProvider == null) throw(new ArgumentException("paramsProvider")); + + editors = new Control[this.paramsProvider.ParamsCount()]; + for (int i = 0; i < this.paramsProvider.ParamsCount(); i++) + { + ICollection values = this.paramsProvider.ParamValues(i); + if (values == null) + { + editors[i] = new TextBox(); + } + else + { + ComboBox cb = new ComboBox(); + foreach (var v in values) cb.Items.Add(v); + editors[i] = cb; + } + editors[i].Visible = false; + this.Controls.Add(editors[i]); + } + + flags = CfgUpdateFlags.None; + + paramsListViewEx.SubItemClicked += new Common.Forms.SubItemEventHandler(paramsListViewEx_SubItemClicked); + paramsListViewEx.SubItemEndEditing += new Common.Forms.SubItemEndEditingEventHandler(paramsListViewEx_SubItemEndEditing); + } + + private void EntryFormCfgCtrl_Load(object sender, EventArgs e) + { + paramsListViewEx.Columns.Add(Strings.Parameter, 150); + paramsListViewEx.Columns.Add(Strings.Value, 400); + Redraw(); + } + + public void Closing() + { + /// Close CmdResponse handlers here + } + + void Redraw() + { + if (paramsProvider == null) return; /// Control was not loaded, settings were not changed + + paramsListViewEx.Items.Clear(); + for (int i = 0; i < paramsProvider.ParamsCount(); i++) + { + ListViewItem lvi = new ListViewItem(paramsProvider.ParamName(i)); + lvi.SubItems.Add(paramsProvider.ToString(i)); + lvi.Tag = i; + paramsListViewEx.Items.Add(lvi); + } + } + + public void Unlock() + { + paramsListViewEx.Enabled = true; + } + + public CfgUpdateFlags VerifyCfg(ref string message) + { + return CfgUpdateFlags.Error; + } + + public CfgUpdateFlags UpdateCfg() + { + if (paramsProvider == null) return CfgUpdateFlags.Error; /// Control was not loaded, settings were not changed + + CfgUpdateFlags f = this.flags; + + return f; + } + + private void paramsListViewEx_SubItemClicked(object sender, Common.Forms.SubItemEventArgs e) + { + if (e.SubItem != 1) return; + int itemNr = (int)e.Item.Tag; + paramsListViewEx.StartEditing(editors[itemNr], e.Item, e.SubItem); + } + + private void paramsListViewEx_SubItemEndEditing(object sender, Common.Forms.SubItemEndEditingEventArgs e) + { + if (e.SubItem != 1) return; + int itemNr = (int)e.Item.Tag; + + string message; + if (paramsProvider.ValidateParam(itemNr, e.DisplayText, out message)) + { + flags |= paramsProvider.UpdateParam(itemNr, e.DisplayText); + } + else + { + MessageBox.Show(message); + e.DisplayText = e.Item.SubItems[e.SubItem].Text; + e.Cancel = true; + } + } + } +} diff --git a/OrderManagement/EditParametersCtrl.designer.cs b/OrderManagement/EditParametersCtrl.designer.cs new file mode 100644 index 000000000..f4a55c0af --- /dev/null +++ b/OrderManagement/EditParametersCtrl.designer.cs @@ -0,0 +1,71 @@ +/// +/// Copyright (c) 2021 Sensus Slovensko a.s. +/// +namespace OrderManagement +{ + partial class EditParametersCtrl + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Component Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.paramsListViewEx = new Common.Forms.ListViewEx(); + this.SuspendLayout(); + // + // paramsListViewEx + // + this.paramsListViewEx.AllowColumnReorder = true; + this.paramsListViewEx.Dock = System.Windows.Forms.DockStyle.Fill; + this.paramsListViewEx.DoubleClickActivation = false; + this.paramsListViewEx.Enabled = false; + this.paramsListViewEx.FullRowSelect = true; + this.paramsListViewEx.GridLines = true; + this.paramsListViewEx.LabelWrap = false; + this.paramsListViewEx.Location = new System.Drawing.Point(0, 0); + this.paramsListViewEx.Name = "paramsListViewEx"; + this.paramsListViewEx.Size = new System.Drawing.Size(491, 356); + this.paramsListViewEx.TabIndex = 0; + this.paramsListViewEx.UseCompatibleStateImageBehavior = false; + this.paramsListViewEx.View = System.Windows.Forms.View.Details; + this.paramsListViewEx.SubItemClicked += new Common.Forms.SubItemEventHandler(this.paramsListViewEx_SubItemClicked); + this.paramsListViewEx.SubItemEndEditing += new Common.Forms.SubItemEndEditingEventHandler(this.paramsListViewEx_SubItemEndEditing); + // + // EditParametersCtrl + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.paramsListViewEx); + this.Name = "EditParametersCtrl"; + this.Size = new System.Drawing.Size(491, 356); + this.Load += new System.EventHandler(this.EntryFormCfgCtrl_Load); + this.ResumeLayout(false); + + } + + #endregion + + private Common.Forms.ListViewEx paramsListViewEx; + } +} diff --git a/OrderManagement/EditParametersCtrl.resx b/OrderManagement/EditParametersCtrl.resx new file mode 100644 index 000000000..1af7de150 --- /dev/null +++ b/OrderManagement/EditParametersCtrl.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/OrderManagement/LocalSettings.cs b/OrderManagement/LocalSettings.cs new file mode 100644 index 000000000..30fc7180f --- /dev/null +++ b/OrderManagement/LocalSettings.cs @@ -0,0 +1,243 @@ +/// +/// Copyright (c) 2021 Sensus Slovensko a.s. +/// +using System; +using System.Collections.Generic; +using System.IO; +using System.Security.Cryptography; +using System.Text; +using System.Xml.Serialization; + +namespace OrderManagement +{ + /// + /// Class to be serialized to an XML file... + /// + [XmlRootAttribute("SNPrinting")] + public class LocalSettings + { + static XmlSerializer serializer = XmlSerializer.FromTypes(new[] { typeof(LocalSettings) })[0]; + + /// Configuration file ecryption/decryption key and initialization vector + static byte[] key = new byte[] { 83, 254, 105, 64, 184, 201, 195, 127, 52, 99, 77, 45, 252, 132, 163, 156 }; + static byte[] IV = new byte[] { 189, 23, 137, 56, 204, 241, 242, 118, 28, 89, 9, 198, 224, 111, 186, 125 }; + + public Mode Mode; + public string Language; /// User interface language used as CultureInfo(..) constructor argument + public int DelayBetweenLabels; /// Delay between printing two consecutive labels in ms + public bool IsUserLoginRequired; /// true = require user login on program start-up + public string TracingDBConnString; /// Connection string to MySQL database with production tracing records + public string UsersDBConnString; /// Connection string to MySQL database with authorized users + public string[] SapNumberHistory; /// SAP number history + public string[] SeparatorHistory; /// Separator history + public int CurrentSNTrail; /// Serial number trail to be printed now + public int RemainingSNsCount; /// Remaining count of serial numbers to be printed in this session + + + /// Parameterless constructor required by serialization + public LocalSettings() { } + + public LocalSettings(bool createNew) + { + if (createNew) + { + Mode = Mode.Standalone; + Language = "EN"; + DelayBetweenLabels = 1000; + IsUserLoginRequired = false; + TracingDBConnString = string.Empty; + UsersDBConnString = string.Empty; + SapNumberHistory = new string[] { }; + SeparatorHistory = new string[] { "4VQ" }; + CurrentSNTrail = 1; + RemainingSNsCount = 0; + } + } + + /// + /// Load public fields of this class from the XML file. + /// + /// LocalSettings object or null when Load() fails + public static LocalSettings Load(string fileName) + { + try + { + bool isEncrypted = true; + using (StreamReader reader = new StreamReader(fileName)) + { + isEncrypted = !reader.ReadLine().StartsWith(" + /// Save public fields of this class to the XML file. + /// + public void Save() + { + try + { + /// Encrypt and write to file 'Program.LocalSettingsFileName' + using (RijndaelManaged aes = new RijndaelManaged { Padding = PaddingMode.Zeros }) + { + using (FileStream fsCrypt = new FileStream(Program.LocalSettingsFileName, FileMode.Create)) + { + using (ICryptoTransform encryptor = aes.CreateEncryptor(key, IV)) + { + using (CryptoStream cs = new CryptoStream(fsCrypt, encryptor, CryptoStreamMode.Write)) + { + using (MemoryStream mStream = new MemoryStream()) + { + using (var writer = new StreamWriter(mStream)) + { + /// Serialize and write settings to a memory stream + serializer.Serialize(writer, this); + writer.Flush(); + mStream.Position = 0; + + using (var reader = new StreamReader(mStream)) + { + /// Encrypt and write to file 'Program.LocalSettingsFileName' + int data; + while ((data = mStream.ReadByte()) != -1) cs.WriteByte((byte)data); + } + } + } + } + } + } + } + } + catch (Exception e) + { + string msg = e.Message; + } + } + + /// + /// Updates history stored in a string array by a new latest string. + /// + /// Last entered string + /// true = history updated + public static bool UpdateHistory(string lastStrValue, ref string[] history) + { + const int MaxHistoryLen = 10; + + if (string.IsNullOrEmpty(lastStrValue)) return false; + + int currentHistoryLength = (history != null) ? history.Length : 0; + + int match = -1; + for (int i = 0; i < currentHistoryLength; i++) + { + if (history[i] == lastStrValue) + { + match = i; + break; + } + } + + if (match >= 0 || currentHistoryLength >= MaxHistoryLen) + { + /// History does not have to be extended (because of a match) or should not be extended (because of the lenght) + if (match < 0) match = currentHistoryLength - 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[currentHistoryLength + 1]; + newHistory[0] = lastStrValue; + for (int j = 1; j <= currentHistoryLength; j++) + { + newHistory[j] = history[j - 1]; + } + history = newHistory; + } + + return true; + } + + /// + /// Load Purchase order combo box items from the LocalSettings PurchaseOrderHistory array + /// + /// Puchase order ComboBox + public static void PrepareCombo(string[] history, System.Windows.Forms.ComboBox comboBox) + { + if (history != null) + { + for (int i = 0; i < history.Length; i++) + { + comboBox.Items.Add(history[i]); + } + } + + if (comboBox.Items.Count > 0) + { + comboBox.Text = comboBox.Items[0].ToString(); + } + } + } + + + public enum Mode + { + Standalone, + WithDatabase, + } +} diff --git a/OrderManagement/OrderManagement.csproj b/OrderManagement/OrderManagement.csproj new file mode 100644 index 000000000..465ba181a --- /dev/null +++ b/OrderManagement/OrderManagement.csproj @@ -0,0 +1,163 @@ + + + + + Debug + AnyCPU + {7DF40C07-9A1D-403B-91D3-D45660E6D3B1} + WinExe + Properties + OrderManagement + OrderManagement + v4.7.2 + 512 + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + false + true + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + false + true + + + OrderManagement.Program + + + + ..\packages\FluentNHibernate.2.0.3.0\lib\net40\FluentNHibernate.dll + + + ..\packages\Iesi.Collections.4.0.0.4000\lib\net40\Iesi.Collections.dll + + + ..\packages\log4net.2.0.2\lib\net40-full\log4net.dll + + + ..\packages\MySql.Data.6.6.5\lib\net40\MySql.Data.dll + + + ..\packages\NHibernate.4.0.4.4000\lib\net40\NHibernate.dll + + + + + + + + + + + + + + + UserControl + + + EditParametersCtrl.cs + + + Form + + + EditOrderDlg.cs + + + + Form + + + OrderManagementDlg.cs + + + + + True + True + Strings.resx + + + Form + + + SettingsDlg.cs + + + EditParametersCtrl.cs + + + EditOrderDlg.cs + + + OrderManagementDlg.cs + + + ResXFileCodeGenerator + Resources.Designer.cs + Designer + + + True + Resources.resx + + + ResXFileCodeGenerator + Strings.Designer.cs + + + + SettingsDlg.cs + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + True + Settings.settings + True + + + + + + + + {c8939821-ba5c-4988-a3d0-bf53b74865c7} + Common + + + {211b5e3f-9996-48a7-abde-c878dd2d71c2} + SharedDatabase + + + + + Always + + + + + \ No newline at end of file diff --git a/OrderManagement/OrderManagementDlg.Designer.cs b/OrderManagement/OrderManagementDlg.Designer.cs new file mode 100644 index 000000000..3a77d1213 --- /dev/null +++ b/OrderManagement/OrderManagementDlg.Designer.cs @@ -0,0 +1,180 @@ +namespace OrderManagement +{ + partial class OrderManagementDlg + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.menuStrip1 = new System.Windows.Forms.MenuStrip(); + this.settingsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.splitContainer1 = new System.Windows.Forms.SplitContainer(); + this.listViewEx1 = new Common.Forms.ListViewEx(); + this.addButton = new System.Windows.Forms.Button(); + this.editButton = new System.Windows.Forms.Button(); + this.closeButton = new System.Windows.Forms.Button(); + this.deleteButton = new System.Windows.Forms.Button(); + this.menuStrip1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit(); + this.splitContainer1.Panel1.SuspendLayout(); + this.splitContainer1.Panel2.SuspendLayout(); + this.splitContainer1.SuspendLayout(); + this.SuspendLayout(); + // + // menuStrip1 + // + this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.settingsToolStripMenuItem}); + this.menuStrip1.Location = new System.Drawing.Point(0, 0); + this.menuStrip1.Name = "menuStrip1"; + this.menuStrip1.Size = new System.Drawing.Size(1349, 24); + this.menuStrip1.TabIndex = 0; + this.menuStrip1.Text = "menuStrip1"; + // + // settingsToolStripMenuItem + // + this.settingsToolStripMenuItem.Name = "settingsToolStripMenuItem"; + this.settingsToolStripMenuItem.Size = new System.Drawing.Size(61, 20); + this.settingsToolStripMenuItem.Text = "Settings"; + this.settingsToolStripMenuItem.Click += new System.EventHandler(this.settingsToolStripMenuItem_Click); + // + // splitContainer1 + // + this.splitContainer1.Dock = System.Windows.Forms.DockStyle.Fill; + this.splitContainer1.FixedPanel = System.Windows.Forms.FixedPanel.Panel2; + this.splitContainer1.Location = new System.Drawing.Point(0, 24); + this.splitContainer1.Name = "splitContainer1"; + // + // splitContainer1.Panel1 + // + this.splitContainer1.Panel1.Controls.Add(this.listViewEx1); + // + // splitContainer1.Panel2 + // + this.splitContainer1.Panel2.Controls.Add(this.addButton); + this.splitContainer1.Panel2.Controls.Add(this.editButton); + this.splitContainer1.Panel2.Controls.Add(this.closeButton); + this.splitContainer1.Panel2.Controls.Add(this.deleteButton); + this.splitContainer1.Size = new System.Drawing.Size(1349, 481); + this.splitContainer1.SplitterDistance = 1214; + this.splitContainer1.TabIndex = 1; + // + // listViewEx1 + // + this.listViewEx1.AllowColumnReorder = true; + this.listViewEx1.Dock = System.Windows.Forms.DockStyle.Fill; + this.listViewEx1.DoubleClickActivation = false; + this.listViewEx1.FullRowSelect = true; + this.listViewEx1.GridLines = true; + this.listViewEx1.Location = new System.Drawing.Point(0, 0); + this.listViewEx1.Name = "listViewEx1"; + this.listViewEx1.Size = new System.Drawing.Size(1214, 481); + this.listViewEx1.TabIndex = 0; + this.listViewEx1.UseCompatibleStateImageBehavior = false; + this.listViewEx1.View = System.Windows.Forms.View.Details; + this.listViewEx1.ColumnClick += new System.Windows.Forms.ColumnClickEventHandler(this.listViewEx1_ColumnClick); + this.listViewEx1.DoubleClick += new System.EventHandler(this.listViewEx1_DoubleClick); + // + // addButton + // + this.addButton.ImeMode = System.Windows.Forms.ImeMode.NoControl; + this.addButton.Location = new System.Drawing.Point(23, 88); + this.addButton.Name = "addButton"; + this.addButton.Size = new System.Drawing.Size(85, 40); + this.addButton.TabIndex = 2; + this.addButton.Text = "Add"; + this.addButton.UseVisualStyleBackColor = true; + this.addButton.Click += new System.EventHandler(this.addButton_Click); + // + // editButton + // + this.editButton.ImeMode = System.Windows.Forms.ImeMode.NoControl; + this.editButton.Location = new System.Drawing.Point(23, 133); + this.editButton.Name = "editButton"; + this.editButton.Size = new System.Drawing.Size(85, 40); + this.editButton.TabIndex = 3; + this.editButton.Text = "Edit"; + this.editButton.UseVisualStyleBackColor = true; + this.editButton.Click += new System.EventHandler(this.editButton_Click); + // + // closeButton + // + this.closeButton.ImeMode = System.Windows.Forms.ImeMode.NoControl; + this.closeButton.Location = new System.Drawing.Point(23, 21); + this.closeButton.Name = "closeButton"; + this.closeButton.Size = new System.Drawing.Size(85, 40); + this.closeButton.TabIndex = 4; + this.closeButton.Text = "Close"; + this.closeButton.UseVisualStyleBackColor = true; + this.closeButton.Click += new System.EventHandler(this.closeButton_Click); + // + // deleteButton + // + this.deleteButton.ImeMode = System.Windows.Forms.ImeMode.NoControl; + this.deleteButton.Location = new System.Drawing.Point(23, 178); + this.deleteButton.Name = "deleteButton"; + this.deleteButton.Size = new System.Drawing.Size(85, 40); + this.deleteButton.TabIndex = 5; + this.deleteButton.Text = "Delete"; + this.deleteButton.UseVisualStyleBackColor = true; + this.deleteButton.Click += new System.EventHandler(this.deleteButton_Click); + // + // OrderManagementDlg + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.AutoScroll = true; + this.ClientSize = new System.Drawing.Size(1349, 505); + this.Controls.Add(this.splitContainer1); + this.Controls.Add(this.menuStrip1); + this.MainMenuStrip = this.menuStrip1; + this.Name = "OrderManagementDlg"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; + this.Text = "Order Management"; + this.Load += new System.EventHandler(this.OrderManagementDlg_Load); + this.menuStrip1.ResumeLayout(false); + this.menuStrip1.PerformLayout(); + this.splitContainer1.Panel1.ResumeLayout(false); + this.splitContainer1.Panel2.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).EndInit(); + this.splitContainer1.ResumeLayout(false); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.MenuStrip menuStrip1; + private System.Windows.Forms.ToolStripMenuItem settingsToolStripMenuItem; + private System.Windows.Forms.SplitContainer splitContainer1; + private System.Windows.Forms.Button addButton; + private System.Windows.Forms.Button editButton; + private System.Windows.Forms.Button closeButton; + private System.Windows.Forms.Button deleteButton; + private Common.Forms.ListViewEx listViewEx1; + } +} + diff --git a/OrderManagement/OrderManagementDlg.cs b/OrderManagement/OrderManagementDlg.cs new file mode 100644 index 000000000..2e75eab37 --- /dev/null +++ b/OrderManagement/OrderManagementDlg.cs @@ -0,0 +1,276 @@ +/// +/// Copyright (c) 2021 Sensus Slovensko a.s. +/// +using System; +using System.Collections.Generic; +using System.Windows.Forms; +using log4net; +using Common; +using SharedDatabase.Entities; +using OrderManagement.Resources; +using Common.Forms; + +namespace OrderManagement +{ + public partial class OrderManagementDlg : Form + { + private static readonly ILog log = LogManager.GetLogger(typeof(OrderManagementDlg)); + + NHibernate.ISession session; + IList listOfOrders; /// null in Standalone mode + + MySortOrder sortOrder = MySortOrder.Ascending; + int sortColumn = -1; /// 0-based index of column to be used for sorting + + public OrderManagementDlg() + { + try + { + string culture = Program.LocalSettings.Language.Replace('_', '-'); + System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(culture); + } + catch (Exception) + { + MessageBox.Show("Selected language is not supported.\nUsing English.", + "Warning", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); + System.Threading.Thread.CurrentThread.CurrentUICulture = + new System.Globalization.CultureInfo("en"); + } + + InitializeComponent(); + + Text = string.Format("{0} v.{1}", Program.ProgramName, Program.Version); ; + } + + public OrderManagementDlg(NHibernate.ISession session, IList listOfOrders) + : this() + { + this.session = session; + this.listOfOrders = listOfOrders; + } + + private void OrderManagementDlg_Load(object sender, EventArgs e) + { + Localize(); + + InitializeColumns(listViewEx1); + foreach (var oi in listOfOrders) AddRow(listViewEx1, oi); + } + + void Localize() + { + settingsToolStripMenuItem.Text = Strings.Settings; + } + + enum Clmn + { + Order, + State, + Workflow, + Procedure, + Variant, + Pieces, + SNPrefix, + SNFirst, + SNDigitsCount, + SNSuffix, + RAPrefix, + RAFirst, + RADigitsCount, + RASuffix, + Remark, + Count + } + + void InitializeColumns(ListView lv) + { + lv.Columns.Add(new ColumnHeader { Text = Strings.Order, Width = 80 }); + lv.Columns.Add(new ColumnHeader { Text = Strings.State, Width = 80 }); + lv.Columns.Add(new ColumnHeader { Text = Strings.Workflow, Width = 150 }); + lv.Columns.Add(new ColumnHeader { Text = Strings.Test_procedure, Width = 150 }); + lv.Columns.Add(new ColumnHeader { Text = Strings.Variant_code, Width = 150 }); + lv.Columns.Add(new ColumnHeader { Text = Strings.Pieces_count, Width = 80 }); + lv.Columns.Add(new ColumnHeader { Text = Strings.SN + " " + Strings.prefix, Width = 80 }); + lv.Columns.Add(new ColumnHeader { Text = Strings.SN + " " + Strings.first, Width = 80 }); + lv.Columns.Add(new ColumnHeader { Text = Strings.SN + " " + Strings.digits_count, Width = 80 }); + lv.Columns.Add(new ColumnHeader { Text = Strings.SN + " " + Strings.suffix, Width = 80 }); + lv.Columns.Add(new ColumnHeader { Text = Strings.RA + " " + Strings.prefix, Width = 80 }); + lv.Columns.Add(new ColumnHeader { Text = Strings.RA + " " + Strings.first, Width = 80 }); + lv.Columns.Add(new ColumnHeader { Text = Strings.RA + " " + Strings.digits_count, Width = 80 }); + lv.Columns.Add(new ColumnHeader { Text = Strings.RA + " " + Strings.suffix, Width = 80 }); + lv.Columns.Add(new ColumnHeader { Text = Strings.Remark, Width = 200 }); + } + + void AddRow(ListView lv, OrderInfo o) + { + ListViewItem lvi = new ListViewItem(o.POName); + lvi.SubItems.Add(((OrderState)o.POState).ToString()); + lvi.SubItems.Add(o.Workflow); + lvi.SubItems.Add(o.TestProcedure); + lvi.SubItems.Add(o.VariantCode); + lvi.SubItems.Add(o.PiecesCount.ToString()); + lvi.SubItems.Add(o.SNPrefix); + lvi.SubItems.Add(o.SNFirst.ToString(string.Format("D{0}", o.SNDigitsCount))); + lvi.SubItems.Add(o.SNDigitsCount.ToString()); + lvi.SubItems.Add(o.SNSuffix); + lvi.SubItems.Add(o.RAPrefix); + lvi.SubItems.Add(o.RAFirst.ToString(string.Format("D{0}", o.RADigitsCount))); + lvi.SubItems.Add(o.RADigitsCount.ToString()); + lvi.SubItems.Add(o.RASuffix); + lvi.SubItems.Add(o.Remark); + lvi.Tag = o; + lv.Items.Add(lvi); + } + + void UpdateRow(ListViewItem lvi, OrderInfo o) + { + int i = 0; + lvi.SubItems[i++].Text = o.POName; + lvi.SubItems[i++].Text = ((OrderState)o.POState).ToString(); + lvi.SubItems[i++].Text = o.Workflow; + lvi.SubItems[i++].Text = o.TestProcedure; + lvi.SubItems[i++].Text = o.VariantCode; + lvi.SubItems[i++].Text = o.PiecesCount.ToString(); + lvi.SubItems[i++].Text = o.SNPrefix; + lvi.SubItems[i++].Text = o.SNFirst.ToString(string.Format("D{0}", o.SNDigitsCount)); + lvi.SubItems[i++].Text = o.SNDigitsCount.ToString(); + lvi.SubItems[i++].Text = o.SNSuffix; + lvi.SubItems[i++].Text = o.RAPrefix; + lvi.SubItems[i++].Text = o.RAFirst.ToString(string.Format("D{0}", o.RADigitsCount)); + lvi.SubItems[i++].Text = o.RADigitsCount.ToString(); + lvi.SubItems[i++].Text = o.RASuffix; + lvi.SubItems[i++].Text = o.Remark; + } + + private void settingsToolStripMenuItem_Click(object sender, EventArgs e) + { + try + { + Common.GlobalData.RemoteUsersDB = new Common.DBSettings(Common.DBType.MySql, Program.LocalSettings.UsersDBConnString); + + DialogResult dr = new SharedDatabase.Forms.LoginDlg().ShowDialog(); + if (dr != DialogResult.OK) return; + + dr = new SettingsDlg(Program.LocalSettings).ShowDialog(); + if (dr == DialogResult.OK) + { + Program.LocalSettings.Save(); + MessageBox.Show(Strings.Program_restart_is_required); + Close(); + } + } + catch (Exception exc) + { + log.ErrorFormat("Failed to connect to the database of users: {0}", exc.Message); + } + } + + private void closeButton_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.OK; + Close(); + } + + private void addButton_Click(object sender, EventArgs e) + { + /// + /// Determine the next production order name + /// + string candidatePOName = string.Empty; + int candidatePONr; + foreach (var o in listOfOrders) + { + if (string.Compare(candidatePOName, o.POName, StringComparison.InvariantCulture) < 0) candidatePOName = o.POName; + } + if (int.TryParse(candidatePOName, out candidatePONr)) + { + candidatePONr++; + candidatePOName = candidatePONr.ToString(string.Format("D{0}", candidatePOName.Length)); + } + + /// + /// Create and edit the order + /// + var order = new OrderInfo(candidatePOName); + + if (new EditOrderDlg(session, order, listOfOrders).ShowDialog() == DialogResult.OK) + { + listOfOrders.Add(order); + AddRow(listViewEx1, order); + } + } + + private void listViewEx1_DoubleClick(object sender, EventArgs e) + { + editButton_Click(sender, e); + } + + private void editButton_Click(object sender, EventArgs e) + { + if (listViewEx1.SelectedItems.Count == 1 && listViewEx1.SelectedItems[0].Tag is OrderInfo) + { + OrderInfo order = listViewEx1.SelectedItems[0].Tag as OrderInfo; + if (order.POState == (sbyte)OrderState.New) + { + if (new EditOrderDlg(session, order, listOfOrders, true).ShowDialog() == DialogResult.OK) + { + UpdateRow(listViewEx1.SelectedItems[0], order); + } + } + else + { + MessageBox.Show(Strings.You_can_only_edit_New_porduction_orders); + } + } + } + + private void deleteButton_Click(object sender, EventArgs e) + { + if (listViewEx1.SelectedItems.Count == 1 && listViewEx1.SelectedItems[0].Tag is OrderInfo) + { + OrderInfo order = listViewEx1.SelectedItems[0].Tag as OrderInfo; + if (order.POState == (sbyte)OrderState.New) + { + if (MessageBox.Show(Strings.Are_you_sure, Strings.Warning, MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == DialogResult.Yes) + { + if (new EditOrderDlg(session, order, listOfOrders).ShowDialog() == DialogResult.OK) + { + UpdateRow(listViewEx1.SelectedItems[0], order); + } + } + } + else + { + MessageBox.Show(Strings.You_can_only_delete_New_porduction_orders); + } + } + } + + private void listViewEx1_ColumnClick(object sender, ColumnClickEventArgs e) + { + if (e.Column == sortColumn) + { + /// Clicked on the same column header => increment to the next applicable MySortOrder + sortOrder = (sortOrder == MySortOrder.Ascending) ? MySortOrder.Descending : MySortOrder.Ascending; + } + else + { + /// Clicked on another column header => set sortOrder to MySortOrder.Ascending + sortColumn = e.Column; + sortOrder = MySortOrder.Ascending; + } + + if (sortColumn == (int)Clmn.State || sortColumn == (int)Clmn.Pieces || sortColumn == (int)Clmn.SNFirst || sortColumn == (int)Clmn.SNDigitsCount) + { + listViewEx1.ListViewItemSorter = new LviIntColumnComparer(sortColumn, sortOrder); + } + else + { + listViewEx1.ListViewItemSorter = new LviTextColumnComparer(sortColumn, sortOrder); + } + + listViewEx1.SetSortIcon(sortColumn, sortOrder); + listViewEx1.Sort(); + } + } +} diff --git a/OrderManagement/OrderManagementDlg.resx b/OrderManagement/OrderManagementDlg.resx new file mode 100644 index 000000000..d5494e305 --- /dev/null +++ b/OrderManagement/OrderManagementDlg.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + \ No newline at end of file diff --git a/OrderManagement/Program.cs b/OrderManagement/Program.cs new file mode 100644 index 000000000..7cb28951e --- /dev/null +++ b/OrderManagement/Program.cs @@ -0,0 +1,251 @@ +/// +/// Copyright (c) 2021 Sensus Slovensko a.s. +/// +using System; +using System.Collections.Generic; +using System.IO; +using System.Reflection; +using System.Windows.Forms; +using log4net; +using NHibernate; +using Common; +using SharedDatabase; +using SharedDatabase.Entities; +using OrderManagement.Resources; + +namespace OrderManagement +{ + static class Program + { + /// Constants + public static GID[] SettingsAccessLevel = new GID[] { GID.TraceabilityManagement }; /// Group membership to access settings + public const string ProgramName = "Order Management"; + public const string ConfigFName = "config.xml"; + public const string BackupConfigFName = "config.backup.xml"; + public const string Log4NetConfigFName = "log4netConfig.xml"; + + /// Program information + public static readonly string Version; /// version string + public static readonly DateTime BuildDateTime; /// date and time of program build + public static readonly string ExeDirectory; + public static readonly string ConfigDirectory; + public static readonly string LogDirectory; + public static readonly string LocalSettingsFileName; + public static readonly string LocalSettingsBackupName; + + /// Local settings + public static LocalSettings LocalSettings; + + /// log4net + static ILog log; + + + static Program() + { + /// Program version string + Assembly thisAssembly = Assembly.GetExecutingAssembly(); + Version ver = thisAssembly.GetName().Version; + Version = string.Format("{0}.{1}.{2}", ver.Major, ver.Minor, ver.Build); + BuildDateTime = new FileInfo(thisAssembly.Location).LastWriteTime; + + /// Local program configuration directory including the trailing backslash + ExeDirectory = Path.GetDirectoryName(thisAssembly.Location); + ConfigDirectory = Path.Combine(ExeDirectory, "..\\Cfg"); + LogDirectory = Path.Combine(ExeDirectory, "..", "Logs"); + LocalSettingsFileName = Path.Combine(ConfigDirectory, ConfigFName); + LocalSettingsBackupName = Path.Combine(ConfigDirectory, BackupConfigFName); + } + + + /// + /// The main entry point for the application. + /// + [STAThread] + static void Main() + { + /// + /// Check if another instance is running + /// + Assembly thisAssembly = Assembly.GetExecutingAssembly(); + string processName = Path.GetFileNameWithoutExtension(thisAssembly.Location); + if (System.Diagnostics.Process.GetProcessesByName(processName).Length > 1) + { + MessageBox.Show(string.Format("{0}{1}{2}", string.Format(Strings.Program_0_is_running_already, ProgramName), + Environment.NewLine, + Strings.Close_it_please), + Strings.Error, + MessageBoxButtons.OK, + MessageBoxIcon.Asterisk); + return; + } + + AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(MyHandler); + + bool configDirectoryCreated = false; + if (!Directory.Exists(ConfigDirectory) || new DirectoryInfo(ConfigDirectory).GetFileSystemInfos().Length == 0) + { + MessageBox.Show(string.Format("{0}{1}{2}", Strings.Program_is_running_for_the_1st_time_on_this_PC, + Environment.NewLine, + Strings.Default_settings_are_used), + Strings.Warning, + MessageBoxButtons.OK, + MessageBoxIcon.Exclamation); + /// + /// Create a new config subdirectory + /// + Directory.CreateDirectory(ConfigDirectory); + configDirectoryCreated = true; + + Program.LocalSettings = new LocalSettings(true); + Program.LocalSettings.Save(); + + if (File.Exists(Path.Combine(ExeDirectory, "SampleConfig", Log4NetConfigFName))) + { + File.Copy(Path.Combine(ExeDirectory, "SampleConfig", Log4NetConfigFName), + Path.Combine(ConfigDirectory, Log4NetConfigFName)); + } + + File.SetAttributes(Path.Combine(ConfigDirectory, Log4NetConfigFName), FileAttributes.Normal); + } + + /// + /// Configue and start logging + /// + log4net.Config.XmlConfigurator.Configure(new FileInfo(Path.Combine(ConfigDirectory, Log4NetConfigFName))); + log = LogManager.GetLogger(typeof(Program)); + log.Fatal("--------------------------------------------------------------------------------"); + log.FatalFormat("{0} ver.{1}", ProgramName, Version); + log.FatalFormat("Executable directory is {0}", ExeDirectory); + if (configDirectoryCreated) + { + log.Fatal("A new config directory and configuration files created !"); + } + + /// + /// Load the local settings + /// + LocalSettings = LocalSettings.Load(Program.LocalSettingsFileName); + if (LocalSettings == null) + { + /// Loading local seetings from regular config file failed. Use the backup + LocalSettings = LocalSettings.Load(Program.LocalSettingsBackupName); + if (LocalSettings == null) + { + log.FatalFormat("Local settings: Could not load file {0}, nor {1}.", ConfigFName, BackupConfigFName); + log.Fatal("Application terminated."); + MessageBox.Show(string.Format("Could not load file {0}, nor {1}.", ConfigFName, BackupConfigFName), "Fatal error"); + return; /// Fatal error + } + else + { + LocalSettings.Save(); /// Save the settings to overwrite the wrong file + log.FatalFormat("Local settings: Could not load file {0}, successfully loaded {1}", ConfigFName, BackupConfigFName); + } + } + else + { + /// Loading local seetings from the regular config file was successful. Update the backup + File.Copy(Program.LocalSettingsFileName, Program.LocalSettingsBackupName, true); + } + + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + + /// + /// User login + /// + if (LocalSettings.IsUserLoginRequired && !string.IsNullOrEmpty(LocalSettings.UsersDBConnString)) + { + try + { + Common.GlobalData.RemoteUsersDB = new DBSettings(Common.DBType.MySql, LocalSettings.UsersDBConnString); + + DialogResult dr = new SharedDatabase.Forms.LoginDlg().ShowDialog(); + if (dr != DialogResult.OK) return; + } + catch (Exception exc) + { + log.ErrorFormat("Failed to connect to the database of users: {0}", exc.Message); + } + } + + ISession session; + IList listOfOrders = null; + while (true) + { + try + { + session = SharedDatabase.TracingDB.CreateSession(LocalSettings.TracingDBConnString); + listOfOrders = session.QueryOver().List(); + break; + } + catch (Exception exc) + { + log.FatalFormat("Failed to connect to production tracing database: {0}", exc.Message); + if (exc.InnerException != null) + { + log.FatalFormat("InnerException: {0}", exc.InnerException.Message); + } + + MessageBox.Show(string.Format("Failed to connect to production tracing database:{0}{1}", Environment.NewLine, exc.Message)); + + if (new SettingsDlg(Program.LocalSettings).ShowDialog() == DialogResult.OK) + { + LocalSettings.Save(); + } + else + { + return; + } + } + } + + try + { + OrderManagementDlg dlg = new OrderManagementDlg(session, listOfOrders); + Application.Run(dlg); + } + catch (Exception e) + { + LogException(log, "Exception in Application.Run(MainWnd)", e); + + MessageBox.Show("Program crashed:" + + Environment.NewLine + Environment.NewLine + e.Message + + ((e.InnerException == null) ? string.Empty : (Environment.NewLine + e.InnerException.Message)) + + Environment.NewLine + e.StackTrace, + "Fatal error", + MessageBoxButtons.OK, + MessageBoxIcon.Exclamation); + } + } + + + static void MyHandler(object sender, UnhandledExceptionEventArgs args) + { + Exception e = args.ExceptionObject as Exception; + if (e == null) return; + + LogException(log, "Unhandled exception", e); + + MessageBox.Show("Program crashed:" + + Environment.NewLine + Environment.NewLine + e.Message + + ((e.InnerException == null) ? string.Empty : (Environment.NewLine + e.InnerException.Message)) + + Environment.NewLine + e.StackTrace, + "Fatal error", + MessageBoxButtons.OK, + MessageBoxIcon.Exclamation); + } + + static void LogException(ILog log, string description, Exception e) + { + log.FatalFormat("---------------( {0} )---------------", description); + log.FatalFormat("Message : {0}", e.Message); + if (e.InnerException != null) + { + log.FatalFormat("InnerMessage : {0}", e.InnerException.Message); + } + log.FatalFormat("StackTrace : {0}{1}", Environment.NewLine, e.StackTrace); + log.Fatal("--------------------------------------"); + } + } +} diff --git a/OrderManagement/Properties/AssemblyInfo.cs b/OrderManagement/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..ff6a9917a --- /dev/null +++ b/OrderManagement/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("OrderManagement")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("OrderManagement")] +[assembly: AssemblyCopyright("Copyright © 2021")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("f6b32e4f-1445-4970-bafa-dcd39d36f9b3")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/OrderManagement/Properties/Resources.Designer.cs b/OrderManagement/Properties/Resources.Designer.cs new file mode 100644 index 000000000..5272afde1 --- /dev/null +++ b/OrderManagement/Properties/Resources.Designer.cs @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace OrderManagement.Properties +{ + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources + { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() + { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager + { + get + { + if ((resourceMan == null)) + { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("OrderManagement.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture + { + get + { + return resourceCulture; + } + set + { + resourceCulture = value; + } + } + } +} diff --git a/OrderManagement/Properties/Resources.resx b/OrderManagement/Properties/Resources.resx new file mode 100644 index 000000000..af7dbebba --- /dev/null +++ b/OrderManagement/Properties/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/OrderManagement/Properties/Settings.Designer.cs b/OrderManagement/Properties/Settings.Designer.cs new file mode 100644 index 000000000..d7df153f7 --- /dev/null +++ b/OrderManagement/Properties/Settings.Designer.cs @@ -0,0 +1,30 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace OrderManagement.Properties +{ + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase + { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default + { + get + { + return defaultInstance; + } + } + } +} diff --git a/OrderManagement/Properties/Settings.settings b/OrderManagement/Properties/Settings.settings new file mode 100644 index 000000000..39645652a --- /dev/null +++ b/OrderManagement/Properties/Settings.settings @@ -0,0 +1,7 @@ + + + + + + + diff --git a/OrderManagement/Resources/Strings.Designer.cs b/OrderManagement/Resources/Strings.Designer.cs new file mode 100644 index 000000000..bba9027c1 --- /dev/null +++ b/OrderManagement/Resources/Strings.Designer.cs @@ -0,0 +1,396 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace OrderManagement.Resources { + using System; + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Strings { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Strings() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("OrderManagement.Resources.Strings", typeof(Strings).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// + /// Looks up a localized string similar to Are you sure ?. + /// + internal static string Are_you_sure { + get { + return ResourceManager.GetString("Are_you_sure", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Cancel. + /// + internal static string Cancel { + get { + return ResourceManager.GetString("Cancel", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Close it please using 'Task manager'. + /// + internal static string Close_it_please { + get { + return ResourceManager.GetString("Close_it_please", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Connection string for production tracing database. + /// + internal static string Connection_string_tracing_DB { + get { + return ResourceManager.GetString("Connection_string_tracing_DB", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Connection string for database of users. + /// + internal static string Connection_string_users_DB { + get { + return ResourceManager.GetString("Connection_string_users_DB", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Database. + /// + internal static string Database { + get { + return ResourceManager.GetString("Database", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Default settings are used.. + /// + internal static string Default_settings_are_used { + get { + return ResourceManager.GetString("Default_settings_are_used", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to digits count. + /// + internal static string digits_count { + get { + return ResourceManager.GetString("digits_count", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Error. + /// + internal static string Error { + get { + return ResourceManager.GetString("Error", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to first. + /// + internal static string first { + get { + return ResourceManager.GetString("first", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Invalid '{0}'. + /// + internal static string Invalid_0 { + get { + return ResourceManager.GetString("Invalid_0", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Language, 语言, Sprache, jazyk. + /// + internal static string Language_etc { + get { + return ResourceManager.GetString("Language_etc", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to OK. + /// + internal static string OK { + get { + return ResourceManager.GetString("OK", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Order. + /// + internal static string Order { + get { + return ResourceManager.GetString("Order", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Order with the same ID already exists. + /// + internal static string Order_with_the_same_ID_already_exists { + get { + return ResourceManager.GetString("Order_with_the_same_ID_already_exists", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Parameter. + /// + internal static string Parameter { + get { + return ResourceManager.GetString("Parameter", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Pieces count. + /// + internal static string Pieces_count { + get { + return ResourceManager.GetString("Pieces_count", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to prefix. + /// + internal static string prefix { + get { + return ResourceManager.GetString("prefix", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Program '{0}' is running already.. + /// + internal static string Program_0_is_running_already { + get { + return ResourceManager.GetString("Program_0_is_running_already", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Program is running for the 1st time on this PC.. + /// + internal static string Program_is_running_for_the_1st_time_on_this_PC { + get { + return ResourceManager.GetString("Program_is_running_for_the_1st_time_on_this_PC", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Program restart is required. + /// + internal static string Program_restart_is_required { + get { + return ResourceManager.GetString("Program_restart_is_required", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to R.A.. + /// + internal static string RA { + get { + return ResourceManager.GetString("RA", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Remark. + /// + internal static string Remark { + get { + return ResourceManager.GetString("Remark", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Save. + /// + internal static string Save { + get { + return ResourceManager.GetString("Save", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Saving an order failed. + /// + internal static string Saving_order_failed { + get { + return ResourceManager.GetString("Saving_order_failed", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Settings. + /// + internal static string Settings { + get { + return ResourceManager.GetString("Settings", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to S/N. + /// + internal static string SN { + get { + return ResourceManager.GetString("SN", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to State. + /// + internal static string State { + get { + return ResourceManager.GetString("State", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to suffix. + /// + internal static string suffix { + get { + return ResourceManager.GetString("suffix", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Test procedure. + /// + internal static string Test_procedure { + get { + return ResourceManager.GetString("Test_procedure", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to User login is required. + /// + internal static string User_login_is_required { + get { + return ResourceManager.GetString("User_login_is_required", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Value. + /// + internal static string Value { + get { + return ResourceManager.GetString("Value", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Variant code. + /// + internal static string Variant_code { + get { + return ResourceManager.GetString("Variant_code", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Warning. + /// + internal static string Warning { + get { + return ResourceManager.GetString("Warning", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Workflow. + /// + internal static string Workflow { + get { + return ResourceManager.GetString("Workflow", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to You can only delete 'New' porduction orders. + /// + internal static string You_can_only_delete_New_porduction_orders { + get { + return ResourceManager.GetString("You_can_only_delete_New_porduction_orders", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to You can only edit 'New' porduction orders. + /// + internal static string You_can_only_edit_New_porduction_orders { + get { + return ResourceManager.GetString("You_can_only_edit_New_porduction_orders", resourceCulture); + } + } + } +} diff --git a/OrderManagement/Resources/Strings.resx b/OrderManagement/Resources/Strings.resx new file mode 100644 index 000000000..7e5decef1 --- /dev/null +++ b/OrderManagement/Resources/Strings.resx @@ -0,0 +1,231 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Are you sure ? + + + Cancel + + + Close it please using 'Task manager' + + + Connection string for production tracing database + + + Connection string for database of users + + + Database + + + Default settings are used. + + + Error + + + first + + + Invalid '{0}' + + + Language, 语言, Sprache, jazyk + + + Order + + + State + + + Pieces count + + + prefix + + + Program '{0}' is running already. + + + Program is running for the 1st time on this PC. + + + Program restart is required + + + Remark + + + Save + + + Settings + + + digits count + + + suffix + + + Test procedure + + + User login is required + + + Variant code + + + Warning + + + Workflow + + + OK + + + Parameter + + + Value + + + Saving an order failed + + + Order with the same ID already exists + + + R.A. + + + S/N + + + You can only edit 'New' porduction orders + + + You can only delete 'New' porduction orders + + \ No newline at end of file diff --git a/OrderManagement/Resources/Strings.sk.resx b/OrderManagement/Resources/Strings.sk.resx new file mode 100644 index 000000000..17a80338c --- /dev/null +++ b/OrderManagement/Resources/Strings.sk.resx @@ -0,0 +1,219 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Ste si istí ? + + + Zrušiť + + + Zavrite ho prosím 'Správcom úloh' (Task manager). + + + Konfigurácia databázy sledovania výroby + + + Konfigurácia databázy používateľov + + + Databáza + + + Použijú sa základné nastavenia + + + Chyba + + + prvá/é + + + Neplatný(á,é) {0} + + + Language, 语言, Sprache, jazyk + + + Zákazka + + + Stav + + + Počet kusov + + + Prefix + + + Program '[0}' už beží. + + + Program bol spustený na tomto počítači prvý krát. + + + je potrebný reštart programu + + + Poznámka + + + Uložíť + + + Nastavenia + + + počet číslic + + + Suffix + + + Testovacia procedúra + + + Vyžaduje sa prihlásenie používateľa + + + Kód variantu + + + Upozornenie + + + Pracovný postup + + + OK + + + Parameter + + + Hodnota + + + Chyba pri ukladaní zákazky + + + Existuje zákazka s rovnakým ID + + \ No newline at end of file diff --git a/OrderManagement/SampleConfig/log4netConfig.xml b/OrderManagement/SampleConfig/log4netConfig.xml new file mode 100644 index 000000000..40c55cdea --- /dev/null +++ b/OrderManagement/SampleConfig/log4netConfig.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/OrderManagement/SettingsDlg.Designer.cs b/OrderManagement/SettingsDlg.Designer.cs new file mode 100644 index 000000000..a2f3d7c9e --- /dev/null +++ b/OrderManagement/SettingsDlg.Designer.cs @@ -0,0 +1,179 @@ +namespace OrderManagement +{ + partial class SettingsDlg + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.commonGroupBox = new System.Windows.Forms.GroupBox(); + this.loginRequiredCheckBox = new System.Windows.Forms.CheckBox(); + this.languageComboBox = new System.Windows.Forms.ComboBox(); + this.languageLabel = new System.Windows.Forms.Label(); + this.connStrForTracingGroupBox = new System.Windows.Forms.GroupBox(); + this.tracingDBConnStringTextBox = new System.Windows.Forms.TextBox(); + this.connStrForUsersGroupBox = new System.Windows.Forms.GroupBox(); + this.usersDBConnStringTextBox = new System.Windows.Forms.TextBox(); + this.saveButton = new System.Windows.Forms.Button(); + this.cancelButton = new System.Windows.Forms.Button(); + this.commonGroupBox.SuspendLayout(); + this.connStrForTracingGroupBox.SuspendLayout(); + this.connStrForUsersGroupBox.SuspendLayout(); + this.SuspendLayout(); + // + // commonGroupBox + // + this.commonGroupBox.Controls.Add(this.loginRequiredCheckBox); + this.commonGroupBox.Controls.Add(this.languageComboBox); + this.commonGroupBox.Controls.Add(this.languageLabel); + this.commonGroupBox.Location = new System.Drawing.Point(12, 12); + this.commonGroupBox.Name = "commonGroupBox"; + this.commonGroupBox.Size = new System.Drawing.Size(418, 87); + this.commonGroupBox.TabIndex = 16; + this.commonGroupBox.TabStop = false; + // + // loginRequiredCheckBox + // + this.loginRequiredCheckBox.AutoSize = true; + this.loginRequiredCheckBox.Location = new System.Drawing.Point(22, 53); + this.loginRequiredCheckBox.Name = "loginRequiredCheckBox"; + this.loginRequiredCheckBox.Size = new System.Drawing.Size(114, 17); + this.loginRequiredCheckBox.TabIndex = 2; + this.loginRequiredCheckBox.Text = "User login required"; + this.loginRequiredCheckBox.UseVisualStyleBackColor = true; + // + // languageComboBox + // + this.languageComboBox.FormattingEnabled = true; + this.languageComboBox.Location = new System.Drawing.Point(292, 17); + this.languageComboBox.Name = "languageComboBox"; + this.languageComboBox.Size = new System.Drawing.Size(80, 21); + this.languageComboBox.TabIndex = 1; + // + // languageLabel + // + this.languageLabel.AutoSize = true; + this.languageLabel.Location = new System.Drawing.Point(19, 20); + this.languageLabel.Name = "languageLabel"; + this.languageLabel.Size = new System.Drawing.Size(134, 13); + this.languageLabel.TabIndex = 0; + this.languageLabel.Text = "Language, Sprache, Jazyk"; + // + // connStrForTracingGroupBox + // + this.connStrForTracingGroupBox.Controls.Add(this.tracingDBConnStringTextBox); + this.connStrForTracingGroupBox.Location = new System.Drawing.Point(12, 108); + this.connStrForTracingGroupBox.Name = "connStrForTracingGroupBox"; + this.connStrForTracingGroupBox.Size = new System.Drawing.Size(660, 50); + this.connStrForTracingGroupBox.TabIndex = 17; + this.connStrForTracingGroupBox.TabStop = false; + this.connStrForTracingGroupBox.Text = "Connection string for production tracing records"; + // + // tracingDBConnStringTextBox + // + this.tracingDBConnStringTextBox.Location = new System.Drawing.Point(19, 18); + this.tracingDBConnStringTextBox.Name = "tracingDBConnStringTextBox"; + this.tracingDBConnStringTextBox.Size = new System.Drawing.Size(617, 20); + this.tracingDBConnStringTextBox.TabIndex = 0; + // + // connStrForUsersGroupBox + // + this.connStrForUsersGroupBox.Controls.Add(this.usersDBConnStringTextBox); + this.connStrForUsersGroupBox.Location = new System.Drawing.Point(12, 167); + this.connStrForUsersGroupBox.Name = "connStrForUsersGroupBox"; + this.connStrForUsersGroupBox.Size = new System.Drawing.Size(660, 50); + this.connStrForUsersGroupBox.TabIndex = 18; + this.connStrForUsersGroupBox.TabStop = false; + this.connStrForUsersGroupBox.Text = "Connection string for central DB of users"; + // + // usersDBConnStringTextBox + // + this.usersDBConnStringTextBox.Location = new System.Drawing.Point(19, 18); + this.usersDBConnStringTextBox.Name = "usersDBConnStringTextBox"; + this.usersDBConnStringTextBox.Size = new System.Drawing.Size(617, 20); + this.usersDBConnStringTextBox.TabIndex = 0; + // + // saveButton + // + this.saveButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.saveButton.Location = new System.Drawing.Point(475, 29); + this.saveButton.Name = "saveButton"; + this.saveButton.Size = new System.Drawing.Size(74, 47); + this.saveButton.TabIndex = 19; + this.saveButton.Text = "Save"; + this.saveButton.UseVisualStyleBackColor = true; + this.saveButton.Click += new System.EventHandler(this.saveButton_Click); + // + // cancelButton + // + this.cancelButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.cancelButton.Location = new System.Drawing.Point(577, 29); + this.cancelButton.Name = "cancelButton"; + this.cancelButton.Size = new System.Drawing.Size(71, 47); + this.cancelButton.TabIndex = 20; + this.cancelButton.Text = "Cancel"; + this.cancelButton.UseVisualStyleBackColor = true; + this.cancelButton.Click += new System.EventHandler(this.cancelButton_Click); + // + // SettingsDlg + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(688, 232); + this.ControlBox = false; + this.Controls.Add(this.cancelButton); + this.Controls.Add(this.saveButton); + this.Controls.Add(this.connStrForUsersGroupBox); + this.Controls.Add(this.connStrForTracingGroupBox); + this.Controls.Add(this.commonGroupBox); + this.Name = "SettingsDlg"; + this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; + this.Text = "Settings"; + this.Load += new System.EventHandler(this.SettingsDlg_Load); + this.commonGroupBox.ResumeLayout(false); + this.commonGroupBox.PerformLayout(); + this.connStrForTracingGroupBox.ResumeLayout(false); + this.connStrForTracingGroupBox.PerformLayout(); + this.connStrForUsersGroupBox.ResumeLayout(false); + this.connStrForUsersGroupBox.PerformLayout(); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.GroupBox commonGroupBox; + private System.Windows.Forms.ComboBox languageComboBox; + private System.Windows.Forms.Label languageLabel; + private System.Windows.Forms.CheckBox loginRequiredCheckBox; + private System.Windows.Forms.GroupBox connStrForTracingGroupBox; + private System.Windows.Forms.TextBox tracingDBConnStringTextBox; + private System.Windows.Forms.GroupBox connStrForUsersGroupBox; + private System.Windows.Forms.TextBox usersDBConnStringTextBox; + private System.Windows.Forms.Button saveButton; + private System.Windows.Forms.Button cancelButton; + } +} \ No newline at end of file diff --git a/OrderManagement/SettingsDlg.cs b/OrderManagement/SettingsDlg.cs new file mode 100644 index 000000000..32c7f591f --- /dev/null +++ b/OrderManagement/SettingsDlg.cs @@ -0,0 +1,126 @@ +/// +/// Copyright (c) 2021 Sensus Slovensko a.s. +/// +using System; +using System.Windows.Forms; +using OrderManagement.Resources; + +namespace OrderManagement +{ + public partial class SettingsDlg : Form + { + private LocalSettings ls; + + public SettingsDlg() + { + InitializeComponent(); + } + + public SettingsDlg(LocalSettings localSettings) + { + InitializeComponent(); + this.ls = localSettings; + } + + void Localize() + { + Text = Strings.Settings; + languageLabel.Text = Strings.Language_etc; + loginRequiredCheckBox.Text = Strings.User_login_is_required; + saveButton.Text = Strings.Save; + cancelButton.Text = Strings.Cancel; + connStrForTracingGroupBox.Text = Strings.Connection_string_tracing_DB; + connStrForUsersGroupBox.Text = Strings.Connection_string_users_DB; + } + + private void SettingsDlg_Load(object sender, EventArgs e) + { + Localize(); + + languageComboBox.Items.Add("EN"); + languageComboBox.Items.Add("ZH_CN"); + languageComboBox.Items.Add("DE"); + languageComboBox.Items.Add("SK"); + languageComboBox.Text = ls.Language; + + if (ls == null) return; + + loginRequiredCheckBox.Checked = ls.IsUserLoginRequired; + + tracingDBConnStringTextBox.Text = ls.TracingDBConnString; + usersDBConnStringTextBox.Text = ls.UsersDBConnString; + } + + /// + /// Verifies UI content + /// + /// None-empty string (message) when invalid + string IsUIContentValid() + { + if (!languageComboBox.Items.Contains(languageComboBox.Text)) + { + return "Invalid language"; + } + + return null; + } + + /// + /// Updates settings, checks for differences compared to previous setrtings + /// + /// true when settings are different + bool UpdateSettings() + { + if (ls == null) return false; + + bool isDifferent = false; + + if (ls.Language != languageComboBox.Text) + { + ls.Language = languageComboBox.Text; + isDifferent = true; + } + + if (ls.IsUserLoginRequired != loginRequiredCheckBox.Checked) + { + ls.IsUserLoginRequired = loginRequiredCheckBox.Checked; + isDifferent = true; + } + + if (ls.TracingDBConnString != tracingDBConnStringTextBox.Text) + { + ls.TracingDBConnString = tracingDBConnStringTextBox.Text; + isDifferent = true; + } + + if (ls.UsersDBConnString != usersDBConnStringTextBox.Text) + { + ls.UsersDBConnString = usersDBConnStringTextBox.Text; + isDifferent = true; + } + + return isDifferent; + } + + private void saveButton_Click(object sender, EventArgs e) + { + string message = IsUIContentValid(); + if (string.IsNullOrEmpty(message)) + { + UpdateSettings(); + DialogResult = DialogResult.OK; + Close(); + } + else + { + MessageBox.Show(message); + } + } + + private void cancelButton_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/OrderManagement/SettingsDlg.resx b/OrderManagement/SettingsDlg.resx new file mode 100644 index 000000000..1af7de150 --- /dev/null +++ b/OrderManagement/SettingsDlg.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/TBF.sln b/TBF.sln index 18799c8e8..81a28c9e6 100644 --- a/TBF.sln +++ b/TBF.sln @@ -78,6 +78,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SharedDatabase", "SharedDat EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FeatureVectorCalculator", "FeatureVectorCalculator\FeatureVectorCalculator.csproj", "{6280F3F9-139A-48E3-8C88-25EB4124E982}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OrderManagement", "OrderManagement\OrderManagement.csproj", "{7DF40C07-9A1D-403B-91D3-D45660E6D3B1}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -332,6 +334,16 @@ Global {6280F3F9-139A-48E3-8C88-25EB4124E982}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU {6280F3F9-139A-48E3-8C88-25EB4124E982}.Release|Mixed Platforms.Build.0 = Release|Any CPU {6280F3F9-139A-48E3-8C88-25EB4124E982}.Release|x86.ActiveCfg = Release|Any CPU + {7DF40C07-9A1D-403B-91D3-D45660E6D3B1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7DF40C07-9A1D-403B-91D3-D45660E6D3B1}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7DF40C07-9A1D-403B-91D3-D45660E6D3B1}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU + {7DF40C07-9A1D-403B-91D3-D45660E6D3B1}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU + {7DF40C07-9A1D-403B-91D3-D45660E6D3B1}.Debug|x86.ActiveCfg = Debug|Any CPU + {7DF40C07-9A1D-403B-91D3-D45660E6D3B1}.Release|Any CPU.ActiveCfg = Release|Any CPU + {7DF40C07-9A1D-403B-91D3-D45660E6D3B1}.Release|Any CPU.Build.0 = Release|Any CPU + {7DF40C07-9A1D-403B-91D3-D45660E6D3B1}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU + {7DF40C07-9A1D-403B-91D3-D45660E6D3B1}.Release|Mixed Platforms.Build.0 = Release|Any CPU + {7DF40C07-9A1D-403B-91D3-D45660E6D3B1}.Release|x86.ActiveCfg = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/TBF/Properties/AssemblyInfo.cs b/TBF/Properties/AssemblyInfo.cs index a9e2b0aed..030f5410b 100644 --- a/TBF/Properties/AssemblyInfo.cs +++ b/TBF/Properties/AssemblyInfo.cs @@ -29,5 +29,5 @@ using System.Runtime.InteropServices; // Build Number // Revision // -[assembly: AssemblyVersion("3.1.1806.0")] -[assembly: AssemblyFileVersion("3.1.1806.0")] +[assembly: AssemblyVersion("3.1.1809.0")] +[assembly: AssemblyFileVersion("3.1.1809.0")] diff --git a/clean.bat b/clean.bat index 92dfd6b7c..859188b46 100644 --- a/clean.bat +++ b/clean.bat @@ -26,6 +26,10 @@ rmdir /s /q GraphLib\bin rmdir /s /q GraphLib\obj rmdir /s /q MergeResultsDBs\bin rmdir /s /q MergeResultsDBs\obj +rmdir /s /q OrderManagement\bin\Debug +rmdir /s /q OrderManagement\bin\Release +rmdir /s /q OrderManagement\bin\Logs +rmdir /s /q OrderManagement\obj rmdir /s /q TracingDB\bin rmdir /s /q TracingDB\obj rmdir /s /q ResetBatchNr\bin