From 05bdf0dc0658c37e6e8186d959210a717f489a35 Mon Sep 17 00:00:00 2001 From: Milan Hanajik Date: Tue, 4 Jun 2019 15:32:36 +0200 Subject: [PATCH] TURA_IPERL || TURA_SPECIAL : TracingResultsDlg shown after a double-click on a WM results. --- Results/Forms/BatchResultsDlg.cs | 76 ++++++++++- Results/Forms/OneWMResultsCtrl.Designer.cs | 1 + Results/Forms/OneWMResultsCtrl.cs | 19 ++- Results/Forms/TracingResultsDlg.Designer.cs | 65 ++++++++++ Results/Forms/TracingResultsDlg.cs | 44 +++++++ Results/Forms/TracingResultsDlg.resx | 120 ++++++++++++++++++ Results/Forms/WaterMeterEventArgs.cs | 14 ++ Results/Resources/Strings.Designer.cs | 72 +++++++++++ Results/Resources/Strings.cs.resx | 24 ++++ Results/Resources/Strings.resx | 24 ++++ Results/Results.csproj | 14 ++ .../DB/ProductionTracing/MonitoringCfg.cs | 2 +- .../Output/DB/ProductionTracing/Tracing.cs | 4 +- TBF/Screens/ResultsTabPageCtrl.cs | 78 +++++++++++- 14 files changed, 542 insertions(+), 15 deletions(-) create mode 100644 Results/Forms/TracingResultsDlg.Designer.cs create mode 100644 Results/Forms/TracingResultsDlg.cs create mode 100644 Results/Forms/TracingResultsDlg.resx create mode 100644 Results/Forms/WaterMeterEventArgs.cs diff --git a/Results/Forms/BatchResultsDlg.cs b/Results/Forms/BatchResultsDlg.cs index 58ba6d6fb..3686604d9 100644 --- a/Results/Forms/BatchResultsDlg.cs +++ b/Results/Forms/BatchResultsDlg.cs @@ -9,6 +9,8 @@ using System.Windows.Forms; using log4net; using Config.Entities; using Results.Resources; +using NHibernate; +using TracingDB.Entities; namespace Results.Forms { @@ -171,6 +173,20 @@ namespace Results.Forms firstListView = lview; first = false; } + +#if TURA_IPERL || TURA_SPECIAL + lview.WMResultsClickedHandler += delegate(object sender, Results.Forms.WaterMeterEventArgs args) + { + if (InvokeRequired) + { + Invoke(new EventHandler(OnDoubleClick), sender, args); + } + else + { + OnDoubleClick(sender, args); + } + }; +#endif } } } @@ -193,11 +209,11 @@ namespace Results.Forms /// Get an empty ListView control with appropriate parameters. /// /// ListView control - OneWMResultsCtrl GetListView(Color backColor) + OneWMResultsCtrl GetListView(Color backColor, Results.Entities.WaterMeter wm) { - return new OneWMResultsCtrl(backColor, lvWidth, lvHeight); + return new OneWMResultsCtrl(backColor, lvWidth, lvHeight, wm); } - OneWMResultsCtrl GetListView() { return GetListView(Color.White); } + OneWMResultsCtrl GetListView(Results.Entities.WaterMeter wm) { return GetListView(Color.White, wm); } /// @@ -286,7 +302,7 @@ namespace Results.Forms string message = string.Empty; Color commonBackColor = GetColorOfResults(wMtr, out message); - OneWMResultsCtrl lview = GetListView(commonBackColor); + OneWMResultsCtrl lview = GetListView(commonBackColor, wMtr); #if ORACLE_DB lview.Caption = string.Format("{0} ({1}) {2}", (string.IsNullOrEmpty(wMtr.SerialNr) ? string.Empty : wMtr.SerialNr), (wMtr.Pruefindex % 100), message); #else @@ -358,7 +374,7 @@ namespace Results.Forms string message; Color commonBackColor = GetColorOfResults(wMtr, out message); - OneWMResultsCtrl lview = GetListView(commonBackColor); + OneWMResultsCtrl lview = GetListView(commonBackColor, wMtr); #if ORACLE_DB lview.Caption = string.Format("{0} ({1}) {2}", (string.IsNullOrEmpty(wMtr.SerialNr) ? string.Empty : wMtr.SerialNr), (wMtr.Pruefindex % 100), message); #else @@ -414,6 +430,56 @@ namespace Results.Forms return lview; } + + void OnDoubleClick(object sender, Results.Forms.WaterMeterEventArgs args) + { + Results.Entities.WaterMeter wm = args.WM; + + if (wm == null || wm.Disabled || string.IsNullOrEmpty(wm.SerialNr)) + { + MessageBox.Show("No water meter or missing S/N"); + } + else if (TracingDB.DB.SessionFactory == null) + { + MessageBox.Show("No access to tracing database"); + } + else + { + using (ISession session = TracingDB.DB.SessionFactory.OpenSession()) + { + IList refRecords = session.QueryOver() + .Where(x => (x.Code == wm.SerialNr)) + .OrderBy(x => x.TimeStamp).Desc + .List(); + for (int i = 0; i < refRecords.Count; i++) + { + ReferenceRecord refR = refRecords[i]; + if ((refR.Records != null) && (refR.Records.Count > 0)) + { + /// Reference record has additional records/parts (i.e. it is PCB assembly workflow step) + /// + foreach (var rec in refR.Records) + { + if (rec.Part.OraDBType.ToLower().Contains("flowtube")) + { + /// rec.Part is a flowtube + /// + IList flowtubeRRs = session.QueryOver() + .Where(x => (x.Code == rec.Code)) + .OrderBy(x => x.TimeStamp).Desc + .List(); + foreach (var rr in flowtubeRRs) refRecords.Add(rr); + } + } + } + } + + new Results.Forms.TracingResultsDlg(refRecords).ShowDialog(); + } + } + } + + private void BatchResultsDlg_FormClosing(object sender, FormClosingEventArgs e) { PopupResultsLeft = Left; diff --git a/Results/Forms/OneWMResultsCtrl.Designer.cs b/Results/Forms/OneWMResultsCtrl.Designer.cs index 8518c834a..79a69e87d 100644 --- a/Results/Forms/OneWMResultsCtrl.Designer.cs +++ b/Results/Forms/OneWMResultsCtrl.Designer.cs @@ -64,6 +64,7 @@ this.tBox.Name = "tBox"; this.tBox.Size = new System.Drawing.Size(352, 20); this.tBox.TabIndex = 0; + this.tBox.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(this.tBox_MouseDoubleClick); // // lView // diff --git a/Results/Forms/OneWMResultsCtrl.cs b/Results/Forms/OneWMResultsCtrl.cs index 1189aaa5b..5ff82fbde 100644 --- a/Results/Forms/OneWMResultsCtrl.cs +++ b/Results/Forms/OneWMResultsCtrl.cs @@ -1,26 +1,41 @@ -using System.Drawing; +using System; +using System.Drawing; using System.Windows.Forms; +using log4net; namespace Results.Forms { public partial class OneWMResultsCtrl : UserControl { + static readonly ILog log = LogManager.GetLogger(typeof(OneWMResultsCtrl)); + + public event EventHandler WMResultsClickedHandler; + public OneWMResultsCtrl() { InitializeComponent(); } - public OneWMResultsCtrl(Color backColor, int lvWidth, int lvHeight) + public OneWMResultsCtrl(Color backColor, int lvWidth, int lvHeight, Results.Entities.WaterMeter wm) : this() { lView.BackColor = backColor; tBox.BackColor = backColor; Size = new System.Drawing.Size(lvWidth, lvHeight); + WM = wm; } + public Results.Entities.WaterMeter WM; public string Caption { get { return tBox.Text; } set { tBox.Text = value; } } public ListView.ColumnHeaderCollection Columns { get { return lView.Columns; } } public ListView.ListViewItemCollection Items { get { return lView.Items; } } public Color BColor { set { lView.BackColor = value; tBox.BackColor = value; } } + + private void tBox_MouseDoubleClick(object sender, MouseEventArgs e) + { + if (WMResultsClickedHandler == null) return; + try { WMResultsClickedHandler(sender, new WaterMeterEventArgs(WM)); } + catch (Exception exc) { log.Error("WMResultsClickedHandler(...) failed", exc); } + } } } diff --git a/Results/Forms/TracingResultsDlg.Designer.cs b/Results/Forms/TracingResultsDlg.Designer.cs new file mode 100644 index 000000000..3e1c71060 --- /dev/null +++ b/Results/Forms/TracingResultsDlg.Designer.cs @@ -0,0 +1,65 @@ +namespace Results.Forms +{ + partial class TracingResultsDlg + { + /// + /// 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.tracingResultsListView = new System.Windows.Forms.ListView(); + this.SuspendLayout(); + // + // tracingResultsListView + // + this.tracingResultsListView.Dock = System.Windows.Forms.DockStyle.Fill; + this.tracingResultsListView.GridLines = true; + this.tracingResultsListView.Location = new System.Drawing.Point(0, 0); + this.tracingResultsListView.Name = "tracingResultsListView"; + this.tracingResultsListView.Size = new System.Drawing.Size(1228, 178); + this.tracingResultsListView.TabIndex = 0; + this.tracingResultsListView.UseCompatibleStateImageBehavior = false; + this.tracingResultsListView.View = System.Windows.Forms.View.Details; + // + // TracingResultsDlg + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(1228, 178); + this.Controls.Add(this.tracingResultsListView); + this.MaximizeBox = false; + this.MinimizeBox = false; + this.Name = "TracingResultsDlg"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; + this.Text = "TracingResultsDlg"; + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.ListView tracingResultsListView; + + } +} \ No newline at end of file diff --git a/Results/Forms/TracingResultsDlg.cs b/Results/Forms/TracingResultsDlg.cs new file mode 100644 index 000000000..7053d372b --- /dev/null +++ b/Results/Forms/TracingResultsDlg.cs @@ -0,0 +1,44 @@ +/// +/// Copyright (c) 2019 Sensus Slovensko a.s. +/// +using System; +using System.Collections.Generic; +using System.Windows.Forms; +using TracingDB.Entities; +using Results.Resources; + +namespace Results.Forms +{ + public partial class TracingResultsDlg : Form + { + public TracingResultsDlg(IList rRecords) + { + InitializeComponent(); + + Text = Strings.Production_tracing_results; + + tracingResultsListView.Columns.Add(Strings.Date_and_time, 110); + tracingResultsListView.Columns.Add(Strings.Step, 100); + tracingResultsListView.Columns.Add(Strings.Workplace, 100); + tracingResultsListView.Columns.Add(Strings.Name, 100); + tracingResultsListView.Columns.Add(Strings.Result, 70); + tracingResultsListView.Columns.Add(Strings.Part, 90); + tracingResultsListView.Columns.Add(Strings.Code, 150); + tracingResultsListView.Columns.Add(Strings.Workflow, 450); + + foreach (var rr in rRecords) + { + tracingResultsListView.Items.Add(new ListViewItem(new string[] { + rr.TimeStamp.ToString("dd.MM.yyyy HH:mm"), + rr.Workstep.Name, + rr.Workplace, + rr.UserName, + rr.Result == 0 ? "OK" : "NOK", + rr.Workstep.ReferencePart.Name, + rr.Code, + rr.Process.Name, + })); + } + } + } +} diff --git a/Results/Forms/TracingResultsDlg.resx b/Results/Forms/TracingResultsDlg.resx new file mode 100644 index 000000000..1af7de150 --- /dev/null +++ b/Results/Forms/TracingResultsDlg.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/Results/Forms/WaterMeterEventArgs.cs b/Results/Forms/WaterMeterEventArgs.cs new file mode 100644 index 000000000..0e48fef79 --- /dev/null +++ b/Results/Forms/WaterMeterEventArgs.cs @@ -0,0 +1,14 @@ +/// +/// Copyright (c) 2019 Sensus Slovensko a.s. +/// +using System; + +namespace Results.Forms +{ + public class WaterMeterEventArgs : EventArgs + { + public Results.Entities.WaterMeter WM; + + public WaterMeterEventArgs(Results.Entities.WaterMeter wm) { WM = wm; } + } +} diff --git a/Results/Resources/Strings.Designer.cs b/Results/Resources/Strings.Designer.cs index 260ef23e7..95dd5f6fc 100644 --- a/Results/Resources/Strings.Designer.cs +++ b/Results/Resources/Strings.Designer.cs @@ -186,6 +186,15 @@ namespace Results.Resources { } } + /// + /// Looks up a localized string similar to Code. + /// + internal static string Code { + get { + return ResourceManager.GetString("Code", resourceCulture); + } + } + /// /// Looks up a localized string similar to Compound. /// @@ -213,6 +222,15 @@ namespace Results.Resources { } } + /// + /// Looks up a localized string similar to Date and time. + /// + internal static string Date_and_time { + get { + return ResourceManager.GetString("Date_and_time", resourceCulture); + } + } + /// /// Looks up a localized string similar to Density. /// @@ -528,6 +546,15 @@ namespace Results.Resources { } } + /// + /// Looks up a localized string similar to Name. + /// + internal static string Name { + get { + return ResourceManager.GetString("Name", resourceCulture); + } + } + /// /// Looks up a localized string similar to No. /// @@ -654,6 +681,15 @@ namespace Results.Resources { } } + /// + /// Looks up a localized string similar to Part. + /// + internal static string Part { + get { + return ResourceManager.GetString("Part", resourceCulture); + } + } + /// /// Looks up a localized string similar to OK. /// @@ -735,6 +771,15 @@ namespace Results.Resources { } } + /// + /// Looks up a localized string similar to Production tracing results. + /// + internal static string Production_tracing_results { + get { + return ResourceManager.GetString("Production_tracing_results", resourceCulture); + } + } + /// /// Looks up a localized string similar to Protocol. /// @@ -987,6 +1032,15 @@ namespace Results.Resources { } } + /// + /// Looks up a localized string similar to Step. + /// + internal static string Step { + get { + return ResourceManager.GetString("Step", resourceCulture); + } + } + /// /// Looks up a localized string similar to T amb. /// @@ -1986,6 +2040,24 @@ namespace Results.Resources { } } + /// + /// 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 Workplace. + /// + internal static string Workplace { + get { + return ResourceManager.GetString("Workplace", resourceCulture); + } + } + /// /// Looks up a localized string similar to Wrong iPerl counting direction. /// diff --git a/Results/Resources/Strings.cs.resx b/Results/Resources/Strings.cs.resx index 6f7533d13..90b99f139 100644 --- a/Results/Resources/Strings.cs.resx +++ b/Results/Resources/Strings.cs.resx @@ -279,4 +279,28 @@ Probíhá test + + Datum a čas + + + Jméno + + + Krok + + + Pracovisko + + + Pracovný postup + + + Výsledky sledování výroby + + + Kód + + + Součástka + \ No newline at end of file diff --git a/Results/Resources/Strings.resx b/Results/Resources/Strings.resx index 11c20851a..ec4db417d 100644 --- a/Results/Resources/Strings.resx +++ b/Results/Resources/Strings.resx @@ -768,4 +768,28 @@ Counter {0} + + Date and time + + + Name + + + Step + + + Workplace + + + Workflow + + + Production tracing results + + + Code + + + Part + \ No newline at end of file diff --git a/Results/Results.csproj b/Results/Results.csproj index 106ac4193..fa8c9c43c 100644 --- a/Results/Results.csproj +++ b/Results/Results.csproj @@ -98,6 +98,13 @@ ResultsConfigDlg.cs + + Form + + + TracingResultsDlg.cs + + @@ -148,6 +155,10 @@ {743DF7DB-C7B6-42EB-986D-0F485E5588E4} Config + + {EFEC8A31-3022-4DA7-A8F6-16D30A94C3FF} + TracingDB + {6E5CB0E9-E1B6-4E5D-AC6E-B1049E180F2B} Users @@ -174,6 +185,9 @@ ResultsConfigDlg.cs + + TracingResultsDlg.cs + ResXFileCodeGenerator Resources.Designer.cs diff --git a/TBF/BenchControl/Output/DB/ProductionTracing/MonitoringCfg.cs b/TBF/BenchControl/Output/DB/ProductionTracing/MonitoringCfg.cs index e76a830fc..b9e8ad1b2 100644 --- a/TBF/BenchControl/Output/DB/ProductionTracing/MonitoringCfg.cs +++ b/TBF/BenchControl/Output/DB/ProductionTracing/MonitoringCfg.cs @@ -28,7 +28,7 @@ namespace TBF.BenchControl.Output.DB.ProductionTracing { ParentName = string.Empty; Workplace = "WR10"; - ConnStr = "SERVER=10.42.128.16; DATABASE=st_wr_shared_config; UID=u9305784; PASSWORD=p89344390; CHARSET=utf8;"; + ConnStr = "SERVER=10.42.128.16; DATABASE=sledovanie2019; UID=vyroba2019; PASSWORD=qwerty; CHARSET=utf8;"; CheckPreviousRecords = true; SaveTracingRecords = true; } diff --git a/TBF/BenchControl/Output/DB/ProductionTracing/Tracing.cs b/TBF/BenchControl/Output/DB/ProductionTracing/Tracing.cs index 259ab1f44..5f7f37798 100644 --- a/TBF/BenchControl/Output/DB/ProductionTracing/Tracing.cs +++ b/TBF/BenchControl/Output/DB/ProductionTracing/Tracing.cs @@ -62,7 +62,7 @@ namespace TBF.BenchControl.Output.DB.ProductionTracing Results.Entities.Batch batch; - ISessionFactory sessionFactory; /// Factory to create database sessions that is initialized in the constructor + ISessionFactory sessionFactory; /// Factory to create database sessions that is initialized in the constructor IList processes; Dictionary processDictionary; Dictionary> workstepsDictionary; @@ -83,6 +83,7 @@ namespace TBF.BenchControl.Output.DB.ProductionTracing : base(cfg) { tracingCfg = cfg as MonitoringCfg; + if (tracingCfg == null) throw new ArgumentException("tracingCfg"); currentOpState = OpState.None; log.Debug(this.ToString()); } @@ -116,6 +117,7 @@ namespace TBF.BenchControl.Output.DB.ProductionTracing DateTime.Now + new TimeSpan(15, 0, 0, 0)); session.Flush(); session.Close(); + TracingDB.DB.SessionFactory = sessionFactory; if (session != null) session.Dispose(); currentProcess = null; diff --git a/TBF/Screens/ResultsTabPageCtrl.cs b/TBF/Screens/ResultsTabPageCtrl.cs index 71df44af5..6f53b655a 100644 --- a/TBF/Screens/ResultsTabPageCtrl.cs +++ b/TBF/Screens/ResultsTabPageCtrl.cs @@ -13,6 +13,8 @@ using Config.Entities; using TBF.Resources; using TBF.UiBridge; using Results.Forms; +using TracingDB.Entities; +using NHibernate; namespace TBF.Screens { @@ -308,6 +310,20 @@ namespace TBF.Screens firstListView = lview; first = false; } + +#if TURA_IPERL || TURA_SPECIAL + lview.WMResultsClickedHandler += delegate(object sender, Results.Forms.WaterMeterEventArgs args) + { + if (InvokeRequired) + { + Invoke(new EventHandler(OnDoubleClick), sender, args); + } + else + { + OnDoubleClick(sender, args); + } + }; +#endif } } } @@ -325,15 +341,16 @@ namespace TBF.Screens this.ResumeLayout(false); } + /// /// Get an empty ListView control with appropriate parameters. /// /// ListView control - OneWMResultsCtrl GetListView(Color backColor) + OneWMResultsCtrl GetListView(Color backColor, Results.Entities.WaterMeter wm) { - return new OneWMResultsCtrl(backColor, lvWidth, lvHeight); + return new OneWMResultsCtrl(backColor, lvWidth, lvHeight, wm); } - OneWMResultsCtrl GetListView() { return GetListView(Color.White); } + OneWMResultsCtrl GetListView(Results.Entities.WaterMeter wm) { return GetListView(Color.White, wm); } /// @@ -434,7 +451,7 @@ namespace TBF.Screens string message = string.Empty; Color commonBackColor = GetColorOfResults(wMtr, out message); - OneWMResultsCtrl lview = GetListView(commonBackColor); + OneWMResultsCtrl lview = GetListView(commonBackColor, wMtr); #if ORACLE_DB lview.Caption = string.Format("{0} ({1}) {2}", (string.IsNullOrEmpty(wMtr.SerialNr) ? string.Empty : wMtr.SerialNr), (wMtr.Pruefindex % 100), message); #else @@ -512,7 +529,7 @@ namespace TBF.Screens string message; Color commonBackColor = GetColorOfResults(wMtr, out message); - OneWMResultsCtrl lview = GetListView(commonBackColor); + OneWMResultsCtrl lview = GetListView(commonBackColor, wMtr); #if ORACLE_DB lview.Caption = string.Format("{0} ({1}) {2}", (string.IsNullOrEmpty(wMtr.SerialNr) ? string.Empty : wMtr.SerialNr), (wMtr.Pruefindex % 100), message); #else @@ -594,5 +611,54 @@ namespace TBF.Screens } RedrawAll(TBF.BenchControl.Sequences.ProcessData.BatchRslts); } - } + + + void OnDoubleClick(object sender, Results.Forms.WaterMeterEventArgs args) + { + Results.Entities.WaterMeter wm = args.WM; + + if (wm == null || wm.Disabled || string.IsNullOrEmpty(wm.SerialNr)) + { + MessageBox.Show("No water meter or missing S/N"); + } + else if (TracingDB.DB.SessionFactory == null) + { + MessageBox.Show("No access to tracing database"); + } + else + { + using (ISession session = TracingDB.DB.SessionFactory.OpenSession()) + { + IList refRecords = session.QueryOver() + .Where(x => (x.Code == wm.SerialNr)) + .OrderBy(x => x.TimeStamp).Desc + .List(); + for (int i = 0; i < refRecords.Count; i++) + { + ReferenceRecord refR = refRecords[i]; + if ((refR.Records != null) && (refR.Records.Count > 0)) + { + /// Reference record has additional records/parts (i.e. it is PCB assembly workflow step) + /// + foreach (var rec in refR.Records) + { + if (rec.Part.OraDBType.ToLower().Contains("flowtube")) + { + /// rec.Part is a flowtube + /// + IList flowtubeRRs = session.QueryOver() + .Where(x => (x.Code == rec.Code)) + .OrderBy(x => x.TimeStamp).Desc + .List(); + foreach (var rr in flowtubeRRs) refRecords.Add(rr); + } + } + } + } + + new Results.Forms.TracingResultsDlg(refRecords).ShowDialog(); + } + } + } + } }