diff --git a/TBF/Resources/Strings.Designer.cs b/TBF/Resources/Strings.Designer.cs index 2bbfba710..bf9ddd423 100644 --- a/TBF/Resources/Strings.Designer.cs +++ b/TBF/Resources/Strings.Designer.cs @@ -1194,6 +1194,24 @@ namespace TBF.Resources { } } + /// + /// 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 Database and water meters selection. + /// + internal static string Database_and_water_meters_selection { + get { + return ResourceManager.GetString("Database_and_water_meters_selection", resourceCulture); + } + } + /// /// Looks up a localized string similar to Database Settings. /// diff --git a/TBF/Resources/Strings.resx b/TBF/Resources/Strings.resx index ae84bb13a..0e9781a75 100644 --- a/TBF/Resources/Strings.resx +++ b/TBF/Resources/Strings.resx @@ -2350,4 +2350,10 @@ Do you really want to delete all codes ? + + Database + + + Database and water meters selection + \ No newline at end of file diff --git a/TBF/TBF.csproj b/TBF/TBF.csproj index 06e58be5d..9f344e0c6 100644 --- a/TBF/TBF.csproj +++ b/TBF/TBF.csproj @@ -2387,6 +2387,12 @@ ResultsTabPageCtrl.cs + + Form + + + SendAgainDBAndWMSelectionForm.cs + Form @@ -3255,6 +3261,9 @@ ResultsTabPageCtrl.cs + + SendAgainDBAndWMSelectionForm.cs + BenchesDlg.cs diff --git a/TBF/UI/ResultsMI/PreviousResultsDlg.cs b/TBF/UI/ResultsMI/PreviousResultsDlg.cs index e4dfae90b..7ebd7b6e6 100644 --- a/TBF/UI/ResultsMI/PreviousResultsDlg.cs +++ b/TBF/UI/ResultsMI/PreviousResultsDlg.cs @@ -16,6 +16,7 @@ using Results; using Results.Entities; using TBF.Resources; using TBF.Rig.Output.DB.SensusOracle; +using TBF.Rig.Sequences; namespace TBF.UI.ResultsMI { @@ -204,66 +205,31 @@ namespace TBF.UI.ResultsMI if (b.BatchNr == data.BatchNr) { #if ORACLE_DB - //System.IO.StreamWriter logger; - //string fname = "C:\\TBF\\Logs\\test.log"; - //try { logger = new System.IO.StreamWriter(System.IO.File.Create(fname)); } - //catch - //{ - // logger = null; - // log.ErrorFormat("Was not able to open LU log file {0}", fname); - //} - //Database.WriteLogsToDisk(logger, b); - - using (ISession configSession = TBF.DB.CreateSession(DBKind.Config)) + if (ProcessData.OracleDB == null) { - IList cmpntEntities = configSession.QueryOver() - .OrderBy(x => x.ItemNr).Asc - .Where(x => (x.ClassName == "Sensus-Oracle-Database")) - .List(); + MessageBox.Show("No database"); + return; + } - if (cmpntEntities.Count == 0) - { - MessageBox.Show("Nepodarilo sa uložiť, neviem načítať nastavenia Oracle databázy", - Strings.Error, - MessageBoxButtons.OK, - MessageBoxIcon.Error); - return; - } + var dlg = new SendAgainDBAndWMSelectionForm(); + if (dlg.ShowDialog() != DialogResult.OK) return; - TBF.Rig.Output.DB.SensusOracle.DatabaseCfg cfg = TBF.Rig.ComponentCfgBase.CreateFromDbEntity(DatabaseCfg.Serializer, cmpntEntities[0], null) - as TBF.Rig.Output.DB.SensusOracle.DatabaseCfg; + OracleConnection conn; + switch (dlg.SelectedDB) + { + default: + case DBUsed.Production: conn = ProcessData.OracleDB.ProductionDB; break; + case DBUsed.Quality: conn = ProcessData.OracleDB.QualityDB; break; + case DBUsed.Test: conn = ProcessData.OracleDB.TestDB; break; + } - /// TODO: Implement database selection - MessageBox.Show(string.Format("Výsledky budú zapísané do produkčnej databázy"), - Strings.Information, - MessageBoxButtons.OK, - MessageBoxIcon.Information); - - OracleConnection conn; - switch (DBUsed.Production) - { - default: - case DBUsed.Production: - conn = new OracleConnection("Data Source=STARA01.WORLD;User Id=deltachef;Password=deltachef;"); - break; - case DBUsed.Quality: - conn = new OracleConnection("Data Source=STARA01.WORLD;User Id=deltaqual;Password=test;"); - break; - case DBUsed.Test: - conn = new OracleConnection("Data Source=STARA_TEST.WORLD;User Id=deltachef;Password=deltachef;"); - break; - } - - - if ((TBF.Rig.Sequences.ProcessData.OracleDB != null) && - (TBF.Rig.Sequences.ProcessData.OracleDB.WriteResultsToDB(conn, b, WMKind.Mechanical, true) == Retv.OK)) - { - b.RsltsSent = true; /// Result was successfully sent - session.SaveOrUpdate(b); /// Update MySQL DB - session.Flush(); - (sender as PreviousResultCtrl).Sent = true; /// Update UI - Redraw(); - } + if (ProcessData.OracleDB.WriteResultsToDB(conn, b, dlg.SelectedWM, true) == Retv.OK) + { + b.RsltsSent = true; /// Result was successfully sent + session.SaveOrUpdate(b); /// Update MySQL DB + session.Flush(); + (sender as PreviousResultCtrl).Sent = true; /// Update UI + Redraw(); } #endif } diff --git a/TBF/UI/ResultsMI/SendAgainDBAndWMSelectionForm.Designer.cs b/TBF/UI/ResultsMI/SendAgainDBAndWMSelectionForm.Designer.cs new file mode 100644 index 000000000..4e41323a3 --- /dev/null +++ b/TBF/UI/ResultsMI/SendAgainDBAndWMSelectionForm.Designer.cs @@ -0,0 +1,123 @@ +namespace TBF.UI.ResultsMI +{ + partial class SendAgainDBAndWMSelectionForm + { + /// + /// 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.databaseComboBox = new System.Windows.Forms.ComboBox(); + this.databaseLabel = new System.Windows.Forms.Label(); + this.waterMetersLabel = new System.Windows.Forms.Label(); + this.waterMetersComboBox = new System.Windows.Forms.ComboBox(); + this.okButton = new System.Windows.Forms.Button(); + this.cancelButton = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // databaseComboBox + // + this.databaseComboBox.FormattingEnabled = true; + this.databaseComboBox.Location = new System.Drawing.Point(151, 27); + this.databaseComboBox.Name = "databaseComboBox"; + this.databaseComboBox.Size = new System.Drawing.Size(163, 21); + this.databaseComboBox.TabIndex = 0; + // + // databaseLabel + // + this.databaseLabel.AutoSize = true; + this.databaseLabel.Location = new System.Drawing.Point(36, 30); + this.databaseLabel.Name = "databaseLabel"; + this.databaseLabel.Size = new System.Drawing.Size(53, 13); + this.databaseLabel.TabIndex = 1; + this.databaseLabel.Text = "Database"; + // + // waterMetersLabel + // + this.waterMetersLabel.AutoSize = true; + this.waterMetersLabel.Location = new System.Drawing.Point(36, 65); + this.waterMetersLabel.Name = "waterMetersLabel"; + this.waterMetersLabel.Size = new System.Drawing.Size(70, 13); + this.waterMetersLabel.TabIndex = 2; + this.waterMetersLabel.Text = "Water meters"; + // + // waterMetersComboBox + // + this.waterMetersComboBox.FormattingEnabled = true; + this.waterMetersComboBox.Location = new System.Drawing.Point(151, 62); + this.waterMetersComboBox.Name = "waterMetersComboBox"; + this.waterMetersComboBox.Size = new System.Drawing.Size(163, 21); + this.waterMetersComboBox.TabIndex = 3; + // + // okButton + // + this.okButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.okButton.Location = new System.Drawing.Point(106, 115); + this.okButton.Name = "okButton"; + this.okButton.Size = new System.Drawing.Size(92, 40); + this.okButton.TabIndex = 4; + this.okButton.Text = "OK"; + this.okButton.UseVisualStyleBackColor = true; + this.okButton.Click += new System.EventHandler(this.okButton_Click); + // + // cancelButton + // + this.cancelButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.cancelButton.Location = new System.Drawing.Point(222, 115); + this.cancelButton.Name = "cancelButton"; + this.cancelButton.Size = new System.Drawing.Size(92, 40); + this.cancelButton.TabIndex = 5; + this.cancelButton.Text = "Cancel"; + this.cancelButton.UseVisualStyleBackColor = true; + this.cancelButton.Click += new System.EventHandler(this.cancelButton_Click); + // + // SendAgainDBAndWMSelectionForm + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(347, 181); + this.Controls.Add(this.cancelButton); + this.Controls.Add(this.okButton); + this.Controls.Add(this.waterMetersComboBox); + this.Controls.Add(this.waterMetersLabel); + this.Controls.Add(this.databaseLabel); + this.Controls.Add(this.databaseComboBox); + this.Name = "SendAgainDBAndWMSelectionForm"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; + this.Text = "Database and water meter selection"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.ComboBox databaseComboBox; + private System.Windows.Forms.Label databaseLabel; + private System.Windows.Forms.Label waterMetersLabel; + private System.Windows.Forms.ComboBox waterMetersComboBox; + private System.Windows.Forms.Button okButton; + private System.Windows.Forms.Button cancelButton; + } +} \ No newline at end of file diff --git a/TBF/UI/ResultsMI/SendAgainDBAndWMSelectionForm.cs b/TBF/UI/ResultsMI/SendAgainDBAndWMSelectionForm.cs new file mode 100644 index 000000000..991af7385 --- /dev/null +++ b/TBF/UI/ResultsMI/SendAgainDBAndWMSelectionForm.cs @@ -0,0 +1,70 @@ +/// +/// Copyright (c) 2021 Sensus Slovensko a.s. +/// +using System; +using System.Windows.Forms; +using TBF.Rig.Output.DB.SensusOracle; +using TBF.Resources; + +namespace TBF.UI.ResultsMI +{ + public partial class SendAgainDBAndWMSelectionForm : Form + { + public DBUsed SelectedDB; + public WMKind SelectedWM; + + public SendAgainDBAndWMSelectionForm() + { + InitializeComponent(); + + Localize(); + + databaseComboBox.Items.Add(DBUsed.Production); + databaseComboBox.Items.Add(DBUsed.Test); + databaseComboBox.Items.Add(DBUsed.Quality); + databaseComboBox.Text = databaseComboBox.Items[0].ToString(); + + waterMetersComboBox.Items.Add(WMKind.iPERL); + waterMetersComboBox.Items.Add(WMKind.Mechanical); + waterMetersComboBox.Text = waterMetersComboBox.Items[0].ToString(); + } + + void Localize() + { + Text = Strings.Database_and_water_meters_selection; + databaseLabel.Text = Strings.Database; + waterMetersLabel.Text = Strings.Water_meters; + okButton.Text = Strings.OkBtnText; + cancelButton.Text = Strings.CancelBtnText; + } + + private void okButton_Click(object sender, EventArgs e) + { + for (DBUsed db = DBUsed.Production; db < DBUsed.Count; db++) + { + if (db.ToString() == databaseComboBox.Text) + { + SelectedDB = db; + for (WMKind wm = WMKind.iPERL; wm < WMKind.Count; wm++) + { + if (wm.ToString() == waterMetersComboBox.Text) + { + SelectedWM = wm; + DialogResult = DialogResult.OK; + Close(); + return; + } + } + } + } + + MessageBox.Show("Invalid selection"); + } + + private void cancelButton_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/TBF/UI/ResultsMI/SendAgainDBAndWMSelectionForm.resx b/TBF/UI/ResultsMI/SendAgainDBAndWMSelectionForm.resx new file mode 100644 index 000000000..1af7de150 --- /dev/null +++ b/TBF/UI/ResultsMI/SendAgainDBAndWMSelectionForm.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