diff --git a/.gitignore b/.gitignore index 2fe11e915..914bf30ad 100644 --- a/.gitignore +++ b/.gitignore @@ -29,5 +29,6 @@ Users/obj/ UserManagement/bin/ UserManagement/obj/ Doc/ +.vs/ *.suo *.bak diff --git a/Results/Entities/WaterMeter.cs b/Results/Entities/WaterMeter.cs index d3e4e090d..a061b65f3 100644 --- a/Results/Entities/WaterMeter.cs +++ b/Results/Entities/WaterMeter.cs @@ -528,6 +528,12 @@ namespace Results.Entities return NokColor; } } + else if (Disabled) + { + /// Water meter was not completed yet => did not pass, did not fail + message = Strings.This_position_is_disabled; + return NotCompletedColor; + } else { /// Water meter was not completed yet => did not pass, did not fail diff --git a/Results/Forms/BatchResultsDlg.cs b/Results/Forms/BatchResultsDlg.cs index 1bb6158f5..86d553692 100644 --- a/Results/Forms/BatchResultsDlg.cs +++ b/Results/Forms/BatchResultsDlg.cs @@ -1,10 +1,5 @@ using System; using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Linq; -using System.Text; using System.Windows.Forms; using log4net; using Config.Entities; @@ -18,43 +13,33 @@ namespace Results.Forms { static readonly ILog log = LogManager.GetLogger(typeof(BatchResultsDlg)); - - DateTime lastRedraw; - DateTime lastSizeChange; - bool loaded; - /// /// Public members /// + public Results.BatchResults Results; + public IList Items; public MetersArrangement MetersArrangement; public TestsArrangement TestsArrangement; public int NrMetersInOneGroup; - - public IList RsltItems_Screen_SingleWM; - public IList RsltItems_Screen_CombinedWM; - public IList RsltItems_Screen_HeatM; - public int[] RsltsClmnWidths { set { rsltsClmnWidths = value; } } - + public bool ShowDisabledPositions; + public int MinWidth; + public int MinHeight; public int PopupResultsLeft; public int PopupResultsTop; public int PopupResultsWidth; public int PopupResultsHeight; + public int[] RsltsClmnWidths; - public Results.BatchResults Results { set { Display(value); } } /// /// Private members /// - Results.BatchResults results; - MetersKind metersKind; - - OneWMResultsCtrl firstListView; - public int[] rsltsClmnWidths; - int rsltsClmnCount { get { return (rsltsClmnWidths != null) ? rsltsClmnWidths.Length : 0; } } - - int lvWidth; - int lvHeight; - + IOneWMResultsCtrl[] wmRsltsCtrl; /// An array of controls with water meter results. + IOneWMResultsCtrl firstEnabledControl; + DateTime lastRedraw; + DateTime lastSizeChange; + int metersInOneGroup; + int nrGroups; Timer timer; @@ -62,310 +47,193 @@ namespace Results.Forms public BatchResultsDlg() { InitializeComponent(); - Text = Strings.Results; + firstEnabledControl = null; lastSizeChange = DateTime.Now; + nrGroups = 1; + metersInOneGroup = 1; - // Create a timer with a ten second interval. + /// Create a timer with one second interval. timer = new Timer(); - timer.Interval = 500; /// ms + timer.Interval = 1000; /// ms timer.Tick += new EventHandler(OnTimer); timer.Start(); } private void BatchResultsDlg_Load(object sender, EventArgs e) { - if (PopupResultsLeft != 0) Left = PopupResultsLeft; - if (PopupResultsTop != 0) Top = PopupResultsTop; - if (PopupResultsWidth != 0) Width = PopupResultsWidth; + if (PopupResultsLeft != 0) Left = PopupResultsLeft; + if (PopupResultsTop != 0) Top = PopupResultsTop; + if (PopupResultsWidth != 0) Width = PopupResultsWidth; if (PopupResultsHeight != 0) Height = PopupResultsHeight; - loaded = true; - if (results != null) Redraw(); - } - - public void Display(Results.BatchResults results) - { - this.results = results; - if (loaded) Redraw(); + CreateControlsAndFillPanel(Results); + UpdateColumnWidths(RsltsClmnWidths); + UpdateResults(Results); } - IList GetRsltItems(MetersKind metersKind) + /// + /// Handle double-click inside a water meter results control + /// + void OnDoubleClick(object sender, Results.Forms.WaterMeterEventArgs args) { - IList srcItems; - switch (metersKind) + if (Results.WaterMeters != null && args.WMPosition > 0) { - default: - case MetersKind.Single: srcItems = RsltItems_Screen_SingleWM; break; - case MetersKind.Combined: srcItems = RsltItems_Screen_CombinedWM; break; - case MetersKind.HeatMeter: srcItems = RsltItems_Screen_HeatM; break; + foreach (var wm in Results.WaterMeters) + { + if ((wm != null) && (wm.WMPosition == args.WMPosition)) + { + ShowMoreWMResults(wm); + return; + } + } } - IList copiedItems = new List(); - foreach (var it in srcItems) copiedItems.Add(it.Clone()); - return copiedItems; + MessageBox.Show(Strings.No_water_meter); + return; + } + + + void UpdateColumnWidths(int[] columnWidths) + { + foreach (var ctrl in wmRsltsCtrl) ctrl.Update(columnWidths); + } + + void UpdateScrollpositions(int scrollStart) + { + /// TODO } /// /// Re-draw the results. Apply new settings if they changed. /// - public void Redraw() + void CreateControlsAndFillPanel(Results.BatchResults results) { - lastRedraw = DateTime.Now; - - this.SuspendLayout(); - - try + if ((results == null) || (results.WMPositionsCount == 0)) { - /// Determine how many water meters were enabled for result evaluation and printing - int enabledWMsCount = 0; - for (int i = 0; i < results.WMPositionsCount; i++) - { - if (results.WaterMeters[i] != null && !results.WaterMeters[i].Disabled) - { - enabledWMsCount++; - } - } - - int metersInOneGroup = Math.Max(1, Math.Min(enabledWMsCount, NrMetersInOneGroup)); - int nrGroups = Math.Max(1, (enabledWMsCount + metersInOneGroup - 1) / metersInOneGroup); - - if (MetersArrangement == MetersArrangement.Horizontally) - { - flowLayoutPanel.FlowDirection = FlowDirection.LeftToRight; - lvWidth = flowLayoutPanel.Width / metersInOneGroup - 6; - lvHeight = flowLayoutPanel.Height / nrGroups - 6; - } - else - { - flowLayoutPanel.FlowDirection = FlowDirection.TopDown; - lvWidth = flowLayoutPanel.Width / nrGroups - 6; - lvHeight = flowLayoutPanel.Height / metersInOneGroup - 6; - } + /// There are no water meters at all flowLayoutPanel.Controls.Clear(); - flowLayoutPanel.WrapContents = true; - flowLayoutPanel.AutoScroll = true; - - bool first = true; - for (int i = 0; i < results.WMPositionsCount; i++) - { - if (results.WaterMeters[i] != null && !results.WaterMeters[i].Disabled) - { - OneWMResultsCtrl lview = (TestsArrangement == TestsArrangement.Rows) - ? GetResultsTestsAreRows(results.WaterMeters[i], i + 1) - : GetResultsTestsAreColumns(results.WaterMeters[i], i + 1); - if (lview != null) - { - flowLayoutPanel.Controls.Add(lview); - if (first) - { - firstListView = lview; - first = false; - } - - lview.WMResultsClickedHandler += delegate(object sender, Results.Forms.WaterMeterEventArgs args) - { - if (InvokeRequired) - { - Invoke(new EventHandler(OnDoubleClick), sender, args); - } - else - { - OnDoubleClick(sender, args); - } - }; - } - } - } - } - catch (Exception e) - { - log.FatalFormat("Redrawing results failed : {0}", e.Message); - if (e.InnerException != null) - { - log.FatalFormat("InnerMessage : {0}", e.InnerException.Message); - } - log.FatalFormat("StackTrace : {0}{1}", Environment.NewLine, e.StackTrace); - } - - this.ResumeLayout(false); - } - - - /// - /// Get an empty ListView control with appropriate parameters. - /// - /// ListView control - OneWMResultsCtrl GetListView(Color backColor, Results.Entities.WaterMeter wm) - { - return new OneWMResultsCtrl(backColor, lvWidth, lvHeight, wm); - } - /// - OneWMResultsCtrl GetListView(Results.Entities.WaterMeter wm) - { - return GetListView(Color.White, wm); - } - - - /// - /// Get a ListView control filled with results of the meter 'mtr' - /// - /// Water meter number (1-based): 1 .. Config.Data.WMsCount - /// ListView object - OneWMResultsCtrl GetResultsTestsAreRows(Results.Entities.WaterMeter wMtr, int printedWMNr) - { - metersKind = wMtr.Compound() ? MetersKind.Combined : (wMtr.HeatMeter() ? MetersKind.HeatMeter : MetersKind.Single); - - string message = string.Empty; - Color commonBackColor = wMtr.GetColorOfResults(false, out message); - 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 - lview.Caption = string.Format("s/n = {0}", string.IsNullOrEmpty(wMtr.SerialNr) ? string.Empty : wMtr.SerialNr); -#endif - - IList items = GetRsltItems(metersKind); - - if (items == null || items.Count == 0) return lview; - - // Header - lview.Columns.Add(printedWMNr.ToString(), (rsltsClmnCount > 0) ? rsltsClmnWidths[0] : 40); - int col = 1; - foreach (var item in items) - { - lview.Columns.Add(item.Caption, (rsltsClmnCount > col) ? rsltsClmnWidths[col] : 70); - col++; - } - - - IList testNames = wMtr.GetAllDecoratedTestNames(); - int ix = 0; - foreach (var mtr in wMtr.MeterTestRslts) - { - if (mtr != null && mtr.IsPilotRslt() && mtr.TestDone && mtr.Publish() != Config.Entities.Publish.Never - && mtr.Publish() != Config.Entities.Publish.Internal) - { - ListViewItem lvi = new ListViewItem(testNames[ix++]); - - for (int i = 0; i < items.Count; i++) - { - string str = items[i].Print(wMtr, mtr.Name()); - - /// Extract and use color information - string[] texts = str.Split(new char[] { '|' }); - if (texts.Length == 1) - { - lvi.SubItems.Add(str); - } - else if (texts.Length == 2) - { - Color color = texts[1].Equals("Green") ? Color.Green : (texts[1].Equals("Red") ? Color.Red : Color.White); - lvi.UseItemStyleForSubItems = false; - lvi.SubItems.Add(texts[0]); - lvi.SubItems[lvi.SubItems.Count - 1].BackColor = color; - } - else - { - lvi.SubItems.Add(string.Empty); - } - } - - lview.Items.Add(lvi); - } - } - - return lview; - } - - - /// - /// Get a ListView control filled with results of the meter 'mtr' - /// - /// Water meter number (1-based): 1 .. Config.Data.WMsCount - /// ListView object - OneWMResultsCtrl GetResultsTestsAreColumns(Results.Entities.WaterMeter wMtr, int printedWMNr) - { - metersKind = wMtr.Compound() ? MetersKind.Combined : (wMtr.HeatMeter() ? MetersKind.HeatMeter : MetersKind.Single); - - string message; - Color commonBackColor = wMtr.GetColorOfResults(false, out message); - 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 - lview.Caption = string.Format("s/n = {0}", string.IsNullOrEmpty(wMtr.SerialNr) ? string.Empty : wMtr.SerialNr); -#endif - - IList items = GetRsltItems(metersKind); - - if (items == null || items.Count == 0) return lview; - - // Header - lview.Columns.Add(printedWMNr.ToString(), (rsltsClmnCount > 0) ? rsltsClmnWidths[0] : 40); - int i = 1; - foreach (var str in wMtr.GetAllDecoratedTestNames()) - { - lview.Columns.Add(str, (rsltsClmnCount > i) ? rsltsClmnWidths[i] : 70); - i++; - } - - foreach (var item in items) - { - ListViewItem lvi = new ListViewItem(item.Caption); - - foreach (var mtr in wMtr.MeterTestRslts) - { - if (mtr != null && mtr.IsPilotRslt() && mtr.TestDone && mtr.Publish() != Config.Entities.Publish.Never && - mtr.Publish() != Config.Entities.Publish.Internal) - { - string str = item.Print(wMtr, mtr.Name()); - - string[] texts = str.Split(new char[] { '|' }); - if (texts.Length == 1) - { - lvi.SubItems.Add(str); - } - else if (texts.Length == 2) - { - Color color = texts[1].Equals("Green") ? Color.Green : (texts[1].Equals("Red") ? Color.Red : Color.White); - lvi.UseItemStyleForSubItems = false; - lvi.SubItems.Add(texts[0]); - lvi.SubItems[lvi.SubItems.Count - 1].BackColor = color; - } - else - { - lvi.SubItems.Add(string.Empty); - } - } - } - - lview.Items.Add(lvi); - } - - return lview; - } - - - void OnDoubleClick(object sender, Results.Forms.WaterMeterEventArgs args) - { - if ( args.WM == null || args.WM.Disabled) - { - MessageBox.Show(Strings.No_water_meter); + wmRsltsCtrl = new OneWMResultsRowsCtrl[0]; + firstEnabledControl = null; return; } - else if ((TracingDB.DB.SessionFactory == null) || string.IsNullOrEmpty(args.WM.SerialNr)) + + /// + /// Determine water meter positions count + /// + int displayedControlsCount = 0; + for (int i = 0; i < results.WaterMeters.Length; i++) { - new Results.Forms.MoreWMResultsDlg( args.WM, null).ShowDialog(); + if (results.WaterMeters[i] != null) + { + if (ShowDisabledPositions || !results.WaterMeters[i].Disabled) + { + displayedControlsCount++; + } + } + } + + /// + /// Calculate geometry + /// + metersInOneGroup = Math.Max(1, Math.Min(displayedControlsCount, NrMetersInOneGroup)); + nrGroups = Math.Max(1, (displayedControlsCount + metersInOneGroup - 1) / metersInOneGroup); + + int oneWidth; + int oneHeight; + /// + if (MetersArrangement == MetersArrangement.Horizontally) + { + flowLayoutPanel.FlowDirection = FlowDirection.LeftToRight; + oneWidth = Math.Max(MinWidth, flowLayoutPanel.Width / metersInOneGroup - 6); + oneHeight = Math.Max(MinHeight, flowLayoutPanel.Height / nrGroups - 6); + } + else + { + flowLayoutPanel.FlowDirection = FlowDirection.TopDown; + oneWidth = Math.Max(MinWidth, flowLayoutPanel.Width / nrGroups - 6); + oneHeight = Math.Max(MinHeight, flowLayoutPanel.Height / metersInOneGroup - 6); + } + + /// + /// Create controls and fill the FlowLayoutPanel + /// + flowLayoutPanel.SuspendLayout(); + flowLayoutPanel.Controls.Clear(); + flowLayoutPanel.WrapContents = true; + flowLayoutPanel.AutoScroll = true; + + wmRsltsCtrl = new IOneWMResultsCtrl[displayedControlsCount]; + int ix = 0; + firstEnabledControl = null; + for (int i = 0; i < results.WaterMeters.Length; i++) + { + if (results.WaterMeters[i] != null) + { + if (!results.WaterMeters[i].Disabled || ShowDisabledPositions) + { + /// Create one water meter position / control + wmRsltsCtrl[ix] = (TestsArrangement == TestsArrangement.Rows) + ? new OneWMResultsRowsCtrl() as IOneWMResultsCtrl + : new OneWMResultsColumnsCtrl() as IOneWMResultsCtrl; + wmRsltsCtrl[ix].Width = oneWidth; + wmRsltsCtrl[ix].Height = oneHeight; + wmRsltsCtrl[ix].Update(Items); + wmRsltsCtrl[ix].WMResultsClickedHandler += delegate(object s, Results.Forms.WaterMeterEventArgs args) + { + if (InvokeRequired) + { + Invoke(new EventHandler(OnDoubleClick), s, args); + } + else + { + OnDoubleClick(s, args); + } + }; + + flowLayoutPanel.Controls.Add(wmRsltsCtrl[ix] as UserControl); + if ((firstEnabledControl == null) && !results.WaterMeters[i].Disabled) firstEnabledControl = wmRsltsCtrl[ix]; + ix++; + } + } + } + + flowLayoutPanel.ResumeLayout(); + + lastRedraw = DateTime.Now; + } + + + void UpdateResults(Results.BatchResults batchResults) + { + if ((batchResults != null) && (batchResults.WaterMeters != null)) + { + int ctrlIx = 0; + for (int i = 0; i < batchResults.WaterMeters.Length; i++) + { + if (!batchResults.WaterMeters[i].Disabled || ShowDisabledPositions) + { + if (ctrlIx < wmRsltsCtrl.Length) wmRsltsCtrl[ctrlIx++].Update(batchResults.WaterMeters[i]); + } + } + } + } + + + void ShowMoreWMResults(Results.Entities.WaterMeter wm) + { + if ((TracingDB.DB.SessionFactory == null) || string.IsNullOrEmpty(wm.SerialNr)) + { + new Results.Forms.MoreWMResultsDlg(wm, null).ShowDialog(); } else { using (ISession session = TracingDB.DB.SessionFactory.OpenSession()) { IList refRecords = session.QueryOver() - .Where(x => (x.Code == args.WM.SerialNr)) + .Where(x => (x.Code == wm.SerialNr)) .OrderBy(x => x.TimeStamp).Desc .List(); for (int i = 0; i < refRecords.Count; i++) @@ -391,7 +259,7 @@ namespace Results.Forms } } - new Results.Forms.MoreWMResultsDlg(args.WM, refRecords).ShowDialog(); + new Results.Forms.MoreWMResultsDlg(wm, refRecords).ShowDialog(); } } } @@ -405,6 +273,7 @@ namespace Results.Forms PopupResultsHeight = Height; } + private void flowLayoutPanel_SizeChanged(object sender, EventArgs e) { lastSizeChange = DateTime.Now; @@ -414,13 +283,40 @@ namespace Results.Forms { if (DateTime.Compare(lastSizeChange, lastRedraw) > 0) { - /// The last size change was later then the last redraw + /// The last size change was more recent then the last redraw DateTime now = DateTime.Now; if (DateTime.Compare(lastSizeChange + new TimeSpan(0, 0, 1), now) < 0) { - /// More then 1s since the last size change - Redraw(); + /// More then 1 second since the last panel size change + + /// Calculate geometry + int oneWidth; + int oneHeight; + /// + if (MetersArrangement == MetersArrangement.Horizontally) + { + flowLayoutPanel.FlowDirection = FlowDirection.LeftToRight; + oneWidth = Math.Max(MinWidth, flowLayoutPanel.Width / metersInOneGroup - 6); + oneHeight = Math.Max(MinHeight, flowLayoutPanel.Height / nrGroups - 6); + } + else + { + flowLayoutPanel.FlowDirection = FlowDirection.TopDown; + oneWidth = Math.Max(MinWidth, flowLayoutPanel.Width / nrGroups - 6); + oneHeight = Math.Max(MinHeight, flowLayoutPanel.Height / metersInOneGroup - 6); + } + + /// Update size of controls + flowLayoutPanel.SuspendLayout(); + /// + foreach (var oneCtrl in wmRsltsCtrl) + { + oneCtrl.Width = oneWidth; + oneCtrl.Height = oneHeight; + } + /// + flowLayoutPanel.ResumeLayout(); } } } diff --git a/Results/Forms/IOneWMResultsCtrl.cs b/Results/Forms/IOneWMResultsCtrl.cs new file mode 100644 index 000000000..dbdfb527d --- /dev/null +++ b/Results/Forms/IOneWMResultsCtrl.cs @@ -0,0 +1,25 @@ +/// +/// Copyright (c) 2019 Sensus Slovensko a.s. +/// +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Windows.Forms; + +namespace Results.Forms +{ + public interface IOneWMResultsCtrl + { + event EventHandler WMResultsClickedHandler; + + bool Disabled { get; } /// true when water meter position is disabled + int WMPosition { get; } /// 1-based WM position + int Width { get; set; } /// Control width + int Height { get; set; } /// Control height + ListView.ColumnHeaderCollection Columns { get; } /// Embedded ListView control columns + + void Update(int[] columnWidths); + void Update(IList items); + void Update(Results.Entities.WaterMeter wMtr); + } +} diff --git a/Results/Forms/MoreWMResultsDlg.Designer.cs b/Results/Forms/MoreWMResultsDlg.Designer.cs index 1dcf645fc..b7f7762fd 100644 --- a/Results/Forms/MoreWMResultsDlg.Designer.cs +++ b/Results/Forms/MoreWMResultsDlg.Designer.cs @@ -29,15 +29,13 @@ private void InitializeComponent() { this.tabControl1 = new System.Windows.Forms.TabControl(); - this.allResultsTabPage = new System.Windows.Forms.TabPage(); this.graphsTabPage = new System.Windows.Forms.TabPage(); this.productionTracingTabPage = new System.Windows.Forms.TabPage(); this.productionTracingSplitContainer = new System.Windows.Forms.SplitContainer(); this.messageLabel = new System.Windows.Forms.Label(); this.tracingResultsListView = new System.Windows.Forms.ListView(); - this.oneWMResultsCtrl = new Results.Forms.OneWMResultsCtrl(); + this.allResultsTabPage = new System.Windows.Forms.TabPage(); this.tabControl1.SuspendLayout(); - this.allResultsTabPage.SuspendLayout(); this.productionTracingTabPage.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.productionTracingSplitContainer)).BeginInit(); this.productionTracingSplitContainer.Panel1.SuspendLayout(); @@ -57,17 +55,6 @@ this.tabControl1.Size = new System.Drawing.Size(1195, 448); this.tabControl1.TabIndex = 0; // - // allResultsTabPage - // - this.allResultsTabPage.Controls.Add(this.oneWMResultsCtrl); - this.allResultsTabPage.Location = new System.Drawing.Point(4, 22); - this.allResultsTabPage.Name = "allResultsTabPage"; - this.allResultsTabPage.Padding = new System.Windows.Forms.Padding(3); - this.allResultsTabPage.Size = new System.Drawing.Size(1187, 422); - this.allResultsTabPage.TabIndex = 0; - this.allResultsTabPage.Text = "All results"; - this.allResultsTabPage.UseVisualStyleBackColor = true; - // // graphsTabPage // this.graphsTabPage.Location = new System.Drawing.Point(4, 22); @@ -133,14 +120,15 @@ this.tracingResultsListView.UseCompatibleStateImageBehavior = false; this.tracingResultsListView.View = System.Windows.Forms.View.Details; // - // oneWMResultsCtrl + // allResultsTabPage // - this.oneWMResultsCtrl.Caption = ""; - this.oneWMResultsCtrl.Dock = System.Windows.Forms.DockStyle.Fill; - this.oneWMResultsCtrl.Location = new System.Drawing.Point(3, 3); - this.oneWMResultsCtrl.Name = "oneWMResultsCtrl"; - this.oneWMResultsCtrl.Size = new System.Drawing.Size(1181, 416); - this.oneWMResultsCtrl.TabIndex = 0; + this.allResultsTabPage.Location = new System.Drawing.Point(4, 22); + this.allResultsTabPage.Name = "allResultsTabPage"; + this.allResultsTabPage.Padding = new System.Windows.Forms.Padding(3); + this.allResultsTabPage.Size = new System.Drawing.Size(1187, 422); + this.allResultsTabPage.TabIndex = 0; + this.allResultsTabPage.Text = "All results"; + this.allResultsTabPage.UseVisualStyleBackColor = true; // // MoreWMResultsDlg // @@ -152,7 +140,6 @@ this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; this.Text = "Water meter results"; this.tabControl1.ResumeLayout(false); - this.allResultsTabPage.ResumeLayout(false); this.productionTracingTabPage.ResumeLayout(false); this.productionTracingSplitContainer.Panel1.ResumeLayout(false); this.productionTracingSplitContainer.Panel1.PerformLayout(); @@ -166,12 +153,12 @@ #endregion private System.Windows.Forms.TabControl tabControl1; - private System.Windows.Forms.TabPage allResultsTabPage; - private OneWMResultsCtrl oneWMResultsCtrl; + private OneWMResultsRowsCtrl oneWMResultsCtrl; private System.Windows.Forms.TabPage graphsTabPage; private System.Windows.Forms.TabPage productionTracingTabPage; private System.Windows.Forms.SplitContainer productionTracingSplitContainer; private System.Windows.Forms.Label messageLabel; private System.Windows.Forms.ListView tracingResultsListView; + private System.Windows.Forms.TabPage allResultsTabPage; } } \ No newline at end of file diff --git a/Results/Forms/MoreWMResultsDlg.cs b/Results/Forms/MoreWMResultsDlg.cs index bd8e93c8b..dd6e36cc9 100644 --- a/Results/Forms/MoreWMResultsDlg.cs +++ b/Results/Forms/MoreWMResultsDlg.cs @@ -51,57 +51,57 @@ namespace Results.Forms /// Water meter entity void ShowAllResults(Results.Entities.WaterMeter wMtr) { - string message; - Color commonBackColor = wMtr.GetColorOfResults(false, out message); /// Ony message is used later on -#if ORACLE_DB - oneWMResultsCtrl.Caption = string.Format("{0} ({1}) {2}", (string.IsNullOrEmpty(wMtr.SerialNr) ? string.Empty : wMtr.SerialNr), (wMtr.Pruefindex % 100), message); -#else - oneWMResultsCtrl.Caption = string.Format("s/n = {0}", string.IsNullOrEmpty(wMtr.SerialNr) ? string.Empty : wMtr.SerialNr); -#endif +// string message; +// Color commonBackColor = wMtr.GetColorOfResults(false, out message); /// Ony message is used later on +//#if ORACLE_DB +// oneWMResultsCtrl.Caption = string.Format("{0} ({1}) {2}", (string.IsNullOrEmpty(wMtr.SerialNr) ? string.Empty : wMtr.SerialNr), (wMtr.Pruefindex % 100), message); +//#else +// oneWMResultsCtrl.Caption = string.Format("s/n = {0}", string.IsNullOrEmpty(wMtr.SerialNr) ? string.Empty : wMtr.SerialNr); +//#endif - IList items = Results.WMeterRsltItemSpec.AllItems; +// IList items = Results.WMeterRsltItemSpec.AllItems; - // Header - oneWMResultsCtrl.Columns.Add(wMtr.WMPosition.ToString(), 100); - int i = 1; - foreach (var str in wMtr.GetAllDecoratedTestNames()) - { - oneWMResultsCtrl.Columns.Add(str, 100); - i++; - } +// // Header +// oneWMResultsCtrl.Columns.Add(wMtr.WMPosition.ToString(), 100); +// int i = 1; +// foreach (var str in wMtr.GetAllDecoratedTestNames()) +// { +// oneWMResultsCtrl.Columns.Add(str, 100); +// i++; +// } - foreach (var item in items) - { - ListViewItem lvi = new ListViewItem(item.Name); +// foreach (var item in items) +// { +// ListViewItem lvi = new ListViewItem(item.Name); - foreach (var mtr in wMtr.MeterTestRslts) - { - if (mtr != null && mtr.IsPilotRslt() && mtr.TestDone && mtr.Publish() != Config.Entities.Publish.Never && - mtr.Publish() != Config.Entities.Publish.Internal) - { - string str = item.Print(wMtr, mtr.Name()); +// foreach (var mtr in wMtr.MeterTestRslts) +// { +// if (mtr != null && mtr.IsPilotRslt() && mtr.TestDone && mtr.Publish() != Config.Entities.Publish.Never && +// mtr.Publish() != Config.Entities.Publish.Internal) +// { +// string str = item.Print(wMtr, mtr.Name()); - string[] texts = str.Split(new char[] { '|' }); - if (texts.Length == 1) - { - lvi.SubItems.Add(str); - } - else if (texts.Length == 2) - { - Color color = texts[1].Equals("Green") ? Color.Green : (texts[1].Equals("Red") ? Color.Red : Color.White); - lvi.UseItemStyleForSubItems = false; - lvi.SubItems.Add(texts[0]); - lvi.SubItems[lvi.SubItems.Count - 1].BackColor = color; - } - else - { - lvi.SubItems.Add(string.Empty); - } - } - } +// string[] texts = str.Split(new char[] { '|' }); +// if (texts.Length == 1) +// { +// lvi.SubItems.Add(str); +// } +// else if (texts.Length == 2) +// { +// Color color = texts[1].Equals("Green") ? Color.Green : (texts[1].Equals("Red") ? Color.Red : Color.White); +// lvi.UseItemStyleForSubItems = false; +// lvi.SubItems.Add(texts[0]); +// lvi.SubItems[lvi.SubItems.Count - 1].BackColor = color; +// } +// else +// { +// lvi.SubItems.Add(string.Empty); +// } +// } +// } - oneWMResultsCtrl.Items.Add(lvi); - } +// oneWMResultsCtrl.Items.Add(lvi); +// } } diff --git a/Results/Forms/OneWMResultsColumnsCtrl.Designer.cs b/Results/Forms/OneWMResultsColumnsCtrl.Designer.cs new file mode 100644 index 000000000..ca8e0a63a --- /dev/null +++ b/Results/Forms/OneWMResultsColumnsCtrl.Designer.cs @@ -0,0 +1,103 @@ +namespace Results.Forms +{ + partial class OneWMResultsColumnsCtrl + { + /// + /// 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.splitContainer1 = new System.Windows.Forms.SplitContainer(); + this.tBox = new System.Windows.Forms.TextBox(); + this.lView = new System.Windows.Forms.ListView(); + ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit(); + this.splitContainer1.Panel1.SuspendLayout(); + 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.Panel1; + this.splitContainer1.Location = new System.Drawing.Point(0, 0); + this.splitContainer1.Name = "splitContainer1"; + this.splitContainer1.Orientation = System.Windows.Forms.Orientation.Horizontal; + // + // splitContainer1.Panel1 + // + this.splitContainer1.Panel1.Controls.Add(this.tBox); + // + // splitContainer1.Panel2 + // + this.splitContainer1.Panel2.Controls.Add(this.lView); + this.splitContainer1.Size = new System.Drawing.Size(352, 318); + this.splitContainer1.SplitterDistance = 25; + this.splitContainer1.SplitterWidth = 1; + this.splitContainer1.TabIndex = 0; + // + // tBox + // + this.tBox.Dock = System.Windows.Forms.DockStyle.Fill; + this.tBox.Location = new System.Drawing.Point(0, 0); + 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 + // + this.lView.Dock = System.Windows.Forms.DockStyle.Fill; + this.lView.FullRowSelect = true; + this.lView.GridLines = true; + this.lView.Location = new System.Drawing.Point(0, 0); + this.lView.Name = "lView"; + this.lView.Size = new System.Drawing.Size(352, 292); + this.lView.TabIndex = 0; + this.lView.UseCompatibleStateImageBehavior = false; + this.lView.View = System.Windows.Forms.View.Details; + // + // OneWMResultsCtrl + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.splitContainer1); + this.Name = "OneWMResultsCtrl"; + this.Size = new System.Drawing.Size(352, 318); + this.splitContainer1.Panel1.ResumeLayout(false); + this.splitContainer1.Panel1.PerformLayout(); + 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.TextBox tBox; + private System.Windows.Forms.ListView lView; + } +} diff --git a/Results/Forms/OneWMResultsColumnsCtrl.cs b/Results/Forms/OneWMResultsColumnsCtrl.cs new file mode 100644 index 000000000..c0cc28ad7 --- /dev/null +++ b/Results/Forms/OneWMResultsColumnsCtrl.cs @@ -0,0 +1,159 @@ +/// +/// Copyright (c) 2019 Sensus Slovensko a.s. +/// +using System; +using System.Drawing; +using System.Windows.Forms; +using System.Collections.Generic; + +namespace Results.Forms +{ + public partial class OneWMResultsColumnsCtrl : UserControl, IOneWMResultsCtrl + { + public event EventHandler WMResultsClickedHandler; + /// + private void tBox_MouseDoubleClick(object sender, MouseEventArgs e) + { + try + { + if (WMResultsClickedHandler != null) WMResultsClickedHandler(sender, new WaterMeterEventArgs(wmPosition)); + } + catch (Exception) + { + } + } + + + bool disabled; + int wmPosition; /// 1-based water meter position + string caption; + Color bkColor; + int[] columnWidths; + IList items; + + + public bool Disabled { get { return disabled; } } /// Read only + public int WMPosition { get { return wmPosition; } } /// Read only + public ListView.ColumnHeaderCollection Columns { get { return lView.Columns; } } /// Read only + + + public OneWMResultsColumnsCtrl() + { + InitializeComponent(); + disabled = false; + wmPosition = 0; + tBox.Text = caption = "---"; + tBox.BackColor = lView.BackColor = bkColor = Color.White; + items = new List(); + columnWidths = new int[0]; + } + + public void Update(int[] columnWidths) + { + this.columnWidths = columnWidths; + + /// Always update ListView column widths + int col = 0; + foreach (ColumnHeader column in lView.Columns) + { + column.Width = (columnWidths != null && columnWidths.Length > col) ? columnWidths[col] : ((col == 0) ? 40 : 70); + col++; + } + } + + public void Update(IList items) + { + this.items = items; + } + + public void Update(Results.Entities.WaterMeter wMtr) + { + if (wMtr == null || wMtr.Disabled) + { + /// Water meter position is disabled + this.disabled = true; + lView.Items.Clear(); + tBox.Text = caption = "---"; + tBox.BackColor = lView.BackColor = bkColor = Color.White; + return; + } + + /// Update background color + string message = string.Empty; + Update(wMtr.GetColorOfResults(false, out message)); + + /// Update caption +#if ORACLE_DB + tBox.Text = caption = string.Format("{0} ({1}) {2}", (string.IsNullOrEmpty(wMtr.SerialNr) ? string.Empty : wMtr.SerialNr), (wMtr.Pruefindex % 100), message); +#else + tBox.Text = caption = string.Format("s/n = {0}", string.IsNullOrEmpty(wMtr.SerialNr) ? string.Empty : wMtr.SerialNr); +#endif + + /// Header + lView.Columns.Add(wmPosition.ToString(), (columnWidths.Length > 0) ? columnWidths[0] : 40); + int col = 1; + foreach (var str in wMtr.GetAllDecoratedTestNames()) + { + lView.Columns.Add(str, (columnWidths.Length > col) ? columnWidths[col] : 70); + col++; + } + + lView.Items.Clear(); + if (items == null || items.Count == 0) return; + + foreach (var item in items) + { + ListViewItem lvi = new ListViewItem(item.Caption); + + foreach (var mtr in wMtr.MeterTestRslts) + { + if (mtr != null && mtr.IsPilotRslt() && mtr.TestDone && mtr.Publish() != Config.Entities.Publish.Never && + mtr.Publish() != Config.Entities.Publish.Internal) + { + string str = item.Print(wMtr, mtr.Name()); + + string[] texts = str.Split(new char[] { '|' }); + if (texts.Length == 1) + { + lvi.SubItems.Add(str); + } + else if (texts.Length == 2) + { + Color color = texts[1].Equals("Green") ? Color.Green : (texts[1].Equals("Red") ? Color.Red : Color.White); + lvi.UseItemStyleForSubItems = false; + lvi.SubItems.Add(texts[0]); + lvi.SubItems[lvi.SubItems.Count - 1].BackColor = color; + } + else + { + lvi.SubItems.Add(string.Empty); + } + } + } + + lView.Items.Add(lvi); + } + } + + /// + /// Private + /// + + void Update(int wmPosition) + { + this.wmPosition = wmPosition; + if (lView.Columns.Count > 0) + { + lView.Columns[0].Text = wmPosition.ToString(); + } + } + + void Update(Color backColor) + { + if (this.bkColor != backColor) + { + tBox.BackColor = lView.BackColor = this.bkColor = backColor; + } + } + } +} diff --git a/Results/Forms/OneWMResultsCtrl.resx b/Results/Forms/OneWMResultsColumnsCtrl.resx similarity index 100% rename from Results/Forms/OneWMResultsCtrl.resx rename to Results/Forms/OneWMResultsColumnsCtrl.resx diff --git a/Results/Forms/OneWMResultsCtrl.cs b/Results/Forms/OneWMResultsCtrl.cs deleted file mode 100644 index 5ff82fbde..000000000 --- a/Results/Forms/OneWMResultsCtrl.cs +++ /dev/null @@ -1,41 +0,0 @@ -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, 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/OneWMResultsCtrl.Designer.cs b/Results/Forms/OneWMResultsRowsCtrl.Designer.cs similarity index 99% rename from Results/Forms/OneWMResultsCtrl.Designer.cs rename to Results/Forms/OneWMResultsRowsCtrl.Designer.cs index 79a69e87d..3319e17a6 100644 --- a/Results/Forms/OneWMResultsCtrl.Designer.cs +++ b/Results/Forms/OneWMResultsRowsCtrl.Designer.cs @@ -1,6 +1,6 @@ namespace Results.Forms { - partial class OneWMResultsCtrl + partial class OneWMResultsRowsCtrl { /// /// Required designer variable. diff --git a/Results/Forms/OneWMResultsRowsCtrl.cs b/Results/Forms/OneWMResultsRowsCtrl.cs new file mode 100644 index 000000000..4fdf85265 --- /dev/null +++ b/Results/Forms/OneWMResultsRowsCtrl.cs @@ -0,0 +1,169 @@ +/// +/// Copyright (c) 2019 Sensus Slovensko a.s. +/// +using System; +using System.Drawing; +using System.Windows.Forms; +using System.Collections.Generic; + +namespace Results.Forms +{ + public partial class OneWMResultsRowsCtrl : UserControl, IOneWMResultsCtrl + { + public event EventHandler WMResultsClickedHandler; + /// + private void tBox_MouseDoubleClick(object sender, MouseEventArgs e) + { + try + { + if (WMResultsClickedHandler != null) WMResultsClickedHandler(sender, new WaterMeterEventArgs(wmPosition)); + } + catch (Exception) + { + } + } + + + bool disabled; + int wmPosition; /// 1-based water meter position + string caption; + Color bkColor; + int[] columnWidths; + IList items; + + + public bool Disabled { get { return disabled; } } /// Read only + public int WMPosition { get { return wmPosition; } } /// Read only + public ListView.ColumnHeaderCollection Columns { get { return lView.Columns; } } /// Read only + + + public OneWMResultsRowsCtrl() + { + InitializeComponent(); + disabled = false; + wmPosition = 0; + tBox.Text = caption = "---"; + tBox.BackColor = lView.BackColor = bkColor = Color.White; + items = new List(); + columnWidths = new int[0]; + } + + public void Update(int[] columnWidths) + { + this.columnWidths = columnWidths; + + /// Always update ListView column widths + int col = 0; + foreach (ColumnHeader column in lView.Columns) + { + column.Width = (columnWidths != null && columnWidths.Length > col) ? columnWidths[col] : ((col == 0) ? 40 : 70); + col++; + } + } + + public void Update(IList items) + { + this.items = items; + + /// Always draw ListView header + lView.Columns.Clear(); + lView.Columns.Add(wmPosition.ToString(), (columnWidths.Length > 0) ? columnWidths[0] : 40); + + if (items == null || items.Count == 0) return; + int col = 1; + foreach (var item in items) + { + lView.Columns.Add(item.Caption, (columnWidths.Length > col) ? columnWidths[col] : 70); + col++; + } + } + + public void Update(Results.Entities.WaterMeter wMtr) + { + if (wMtr == null || wMtr.Disabled) + { + /// Water meter position is disabled + this.disabled = true; + lView.Items.Clear(); + tBox.Text = caption = "---"; + tBox.BackColor = lView.BackColor = bkColor = Color.White; + return; + } + + /// Update background color + string message = string.Empty; + Update(wMtr.GetColorOfResults(false, out message)); + + /// Update caption +#if ORACLE_DB + tBox.Text = caption = string.Format("{0} ({1}) {2}", (string.IsNullOrEmpty(wMtr.SerialNr) ? string.Empty : wMtr.SerialNr), (wMtr.Pruefindex % 100), message); +#else + tBox.Text = caption = string.Format("s/n = {0}", string.IsNullOrEmpty(wMtr.SerialNr) ? string.Empty : wMtr.SerialNr); +#endif + + Update(wMtr.WMPosition); + + /// Update test results + IList testNames = wMtr.GetAllDecoratedTestNames(); + int ix = 0; + lView.Items.Clear(); + foreach (var mtr in wMtr.MeterTestRslts) + { + if (mtr != null && mtr.IsPilotRslt() && mtr.TestDone && mtr.Publish() != Config.Entities.Publish.Never + && mtr.Publish() != Config.Entities.Publish.Internal) + { + ListViewItem lvi = new ListViewItem(testNames[ix++]); + + if (items != null) + { + for (int i = 0; i < items.Count; i++) + { + string str = items[i].Print(wMtr, mtr.Name()); + + /// Extract and use color information + string[] texts = str.Split(new char[] { '|' }); + if (texts.Length == 1) + { + lvi.SubItems.Add(str); + } + else if (texts.Length == 2) + { + Color color = texts[1].Equals("Green") ? Color.Green : (texts[1].Equals("Red") ? Color.Red : Color.White); + lvi.UseItemStyleForSubItems = false; + lvi.SubItems.Add(texts[0]); + lvi.SubItems[lvi.SubItems.Count - 1].BackColor = color; + } + else + { + lvi.SubItems.Add(string.Empty); + } + } + } + + lView.Items.Add(lvi); + } + } + } + + /// + /// Private + /// + + void Update(int wmPosition) + { + this.wmPosition = wmPosition; + if (lView.Columns.Count > 0) + { + lView.Columns[0].Text = wmPosition.ToString(); + } + } + + void Update(Color backColor) + { + if (this.bkColor != backColor) + { + tBox.BackColor = lView.BackColor = this.bkColor = backColor; + } + } + } +} diff --git a/Results/Forms/OneWMResultsRowsCtrl.resx b/Results/Forms/OneWMResultsRowsCtrl.resx new file mode 100644 index 000000000..1af7de150 --- /dev/null +++ b/Results/Forms/OneWMResultsRowsCtrl.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 index 0e48fef79..7c1996223 100644 --- a/Results/Forms/WaterMeterEventArgs.cs +++ b/Results/Forms/WaterMeterEventArgs.cs @@ -7,8 +7,8 @@ namespace Results.Forms { public class WaterMeterEventArgs : EventArgs { - public Results.Entities.WaterMeter WM; + public int WMPosition; - public WaterMeterEventArgs(Results.Entities.WaterMeter wm) { WM = wm; } + public WaterMeterEventArgs(int wmPosition) { WMPosition = wmPosition; } } } diff --git a/Results/Properties/AssemblyInfo.cs b/Results/Properties/AssemblyInfo.cs index c1129bb59..0124712b1 100644 --- a/Results/Properties/AssemblyInfo.cs +++ b/Results/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ using System.Runtime.InteropServices; // 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("2.18.1278.0")] -[assembly: AssemblyFileVersion("2.18.1278.0")] +[assembly: AssemblyVersion("2.18.1290.0")] +[assembly: AssemblyFileVersion("2.18.1290.0")] diff --git a/Results/Resources/Strings.Designer.cs b/Results/Resources/Strings.Designer.cs index 112ee6011..e8ce3a18a 100644 --- a/Results/Resources/Strings.Designer.cs +++ b/Results/Resources/Strings.Designer.cs @@ -1230,6 +1230,15 @@ namespace Results.Resources { } } + /// + /// Looks up a localized string similar to This position is disabled. + /// + internal static string This_position_is_disabled { + get { + return ResourceManager.GetString("This_position_is_disabled", resourceCulture); + } + } + /// /// Looks up a localized string similar to to. /// diff --git a/Results/Resources/Strings.cs.resx b/Results/Resources/Strings.cs.resx index 03d3edcc1..a9fb36b8a 100644 --- a/Results/Resources/Strings.cs.resx +++ b/Results/Resources/Strings.cs.resx @@ -333,4 +333,7 @@ Průtok + + Taro pozice je vypnuta + \ No newline at end of file diff --git a/Results/Resources/Strings.resx b/Results/Resources/Strings.resx index 0d085eb63..570edb2bf 100644 --- a/Results/Resources/Strings.resx +++ b/Results/Resources/Strings.resx @@ -816,4 +816,7 @@ Relative error + + This position is disabled + \ No newline at end of file diff --git a/Results/Results.csproj b/Results/Results.csproj index e76f173ff..cee49bddd 100644 --- a/Results/Results.csproj +++ b/Results/Results.csproj @@ -75,6 +75,7 @@ BatchResultsDlg.cs + Component @@ -87,11 +88,17 @@ MoreWMResultsDlg.cs - + UserControl - - OneWMResultsCtrl.cs + + OneWMResultsColumnsCtrl.cs + + + UserControl + + + OneWMResultsRowsCtrl.cs UserControl @@ -187,8 +194,11 @@ MoreWMResultsDlg.cs - - OneWMResultsCtrl.cs + + OneWMResultsColumnsCtrl.cs + + + OneWMResultsRowsCtrl.cs ResultsConfigCtrl.cs diff --git a/TBF/Forms/PreviousResultsDlg.cs b/TBF/Forms/PreviousResultsDlg.cs index 4640def63..329910222 100644 --- a/TBF/Forms/PreviousResultsDlg.cs +++ b/TBF/Forms/PreviousResultsDlg.cs @@ -235,43 +235,62 @@ namespace TBF.Forms public void DoShowResults(object sender, PreviousResultIdEventArgs data) { - Results.Forms.BatchResultsDlg dlg = new Results.Forms.BatchResultsDlg(); - dlg.PopupResultsLeft = Program.LocalSettings.PopupResultsLeft; - dlg.PopupResultsTop = Program.LocalSettings.PopupResultsTop; - dlg.PopupResultsWidth = Program.LocalSettings.PopupResultsWidth; - dlg.PopupResultsHeight = Program.LocalSettings.PopupResultsHeight; - - dlg.MetersArrangement = Program.LocalSettings.ResultsConfigMeters; - dlg.TestsArrangement = Program.LocalSettings.ResultsConfigTests; - dlg.NrMetersInOneGroup = Math.Max(1, Program.LocalSettings.ResultsConfigMetersInOneGroup); - - dlg.RsltItems_Screen_SingleWM = Results.WMeterRsltItemSpec.FromStrArray(Program.LocalSettings.RsltItems_Screen_SingleWM); - dlg.RsltItems_Screen_CombinedWM = Results.WMeterRsltItemSpec.FromStrArray(Program.LocalSettings.RsltItems_Screen_CombinedWM); - dlg.RsltItems_Screen_HeatM = Results.WMeterRsltItemSpec.FromStrArray(Program.LocalSettings.RsltItems_Screen_HeatM); - dlg.RsltsClmnWidths = Program.LocalSettings.RsltsClmnWidths; - foreach (var b in batches) { if (b.BatchNr == data.BatchNr) { - dlg.Results = Results.BatchResults.FromBatch(b); - dlg.Text = string.Format(Strings.Results_of_batch_0, b.BatchNr); + if (b.WaterMeters == null || b.WaterMeters.Count == 0) + { + return; /// No water meters in the selected batch + } + + /// Prepare result items + IList items = null; + foreach (var wm in b.WaterMeters) + { + if (wm != null) + { + if (wm.WaterMeterData.Compound) + { + items = Results.WMeterRsltItemSpec.FromStrArray(Program.LocalSettings.RsltItems_Screen_CombinedWM); + } + else if (wm.WaterMeterData.HeatMeter) + { + items = Results.WMeterRsltItemSpec.FromStrArray(Program.LocalSettings.RsltItems_Screen_HeatM); + } + else + { + items = Results.WMeterRsltItemSpec.FromStrArray(Program.LocalSettings.RsltItems_Screen_SingleWM); + } + break; + } + } + if (items == null) items = new List(); + + /// Show dialog with results + Results.Forms.BatchResultsDlg dlg = new Results.Forms.BatchResultsDlg + { + Text = string.Format(Strings.Results_of_batch_0, b.BatchNr), + Results = Results.BatchResults.FromBatch(b), + Items = items, + PopupResultsLeft = Program.LocalSettings.PopupResultsLeft, + PopupResultsTop = Program.LocalSettings.PopupResultsTop, + PopupResultsWidth = Program.LocalSettings.PopupResultsWidth, + PopupResultsHeight = Program.LocalSettings.PopupResultsHeight, + MetersArrangement = Program.LocalSettings.ResultsConfigMeters, + TestsArrangement = Program.LocalSettings.ResultsConfigTests, + NrMetersInOneGroup = Math.Max(1, Program.LocalSettings.ResultsConfigMetersInOneGroup), + ShowDisabledPositions = Program.LocalSettings.ShowDisabledPositions, + MinWidth = Program.LocalSettings.ResultsConfigMinWidth, + MinHeight = Program.LocalSettings.ResultsConfigMinHeight, + RsltsClmnWidths = Program.LocalSettings.RsltsClmnWidths, + }; + dlg.Show(); + break; } } - - //if (dlg.PopupResultsLeft != Program.LocalSettings.PopupResultsLeft || - // dlg.PopupResultsTop != Program.LocalSettings.PopupResultsTop || - // dlg.PopupResultsWidth != Program.LocalSettings.PopupResultsWidth || - // dlg.PopupResultsHeight != Program.LocalSettings.PopupResultsHeight) - //{ - // Program.LocalSettings.PopupResultsLeft = dlg.PopupResultsLeft; - // Program.LocalSettings.PopupResultsTop = dlg.PopupResultsTop; - // Program.LocalSettings.PopupResultsWidth = dlg.PopupResultsWidth; - // Program.LocalSettings.PopupResultsHeight = dlg.PopupResultsHeight; - // Program.LocalSettings.Save(); - //} } diff --git a/TBF/Forms/ResultsArrangementDlg.Designer.cs b/TBF/Forms/ResultsArrangementDlg.Designer.cs index ef17feab9..b2a71853a 100644 --- a/TBF/Forms/ResultsArrangementDlg.Designer.cs +++ b/TBF/Forms/ResultsArrangementDlg.Designer.cs @@ -35,6 +35,7 @@ namespace TBF.Forms this.testsColumnsRadioButton = new System.Windows.Forms.RadioButton(); this.testsArangementGroupBox = new System.Windows.Forms.GroupBox(); this.metersArangementGroupBox = new System.Windows.Forms.GroupBox(); + this.showDisabledCheckBox = new System.Windows.Forms.CheckBox(); this.minHeightTextBox = new System.Windows.Forms.TextBox(); this.minHeightLabel = new System.Windows.Forms.Label(); this.minWidthTextBox = new System.Windows.Forms.TextBox(); @@ -88,6 +89,7 @@ namespace TBF.Forms // // metersArangementGroupBox // + this.metersArangementGroupBox.Controls.Add(this.showDisabledCheckBox); this.metersArangementGroupBox.Controls.Add(this.minHeightTextBox); this.metersArangementGroupBox.Controls.Add(this.minHeightLabel); this.metersArangementGroupBox.Controls.Add(this.minWidthTextBox); @@ -103,6 +105,17 @@ namespace TBF.Forms this.metersArangementGroupBox.TabStop = false; this.metersArangementGroupBox.Text = "Arangement of tested meters"; // + // showDisabledCheckBox + // + this.showDisabledCheckBox.AutoSize = true; + this.showDisabledCheckBox.Enabled = false; + this.showDisabledCheckBox.Location = new System.Drawing.Point(200, 44); + this.showDisabledCheckBox.Name = "showDisabledCheckBox"; + this.showDisabledCheckBox.Size = new System.Drawing.Size(139, 17); + this.showDisabledCheckBox.TabIndex = 10; + this.showDisabledCheckBox.Text = "Show disabled positions"; + this.showDisabledCheckBox.UseVisualStyleBackColor = true; + // // minHeightTextBox // this.minHeightTextBox.Enabled = false; @@ -263,5 +276,6 @@ namespace TBF.Forms private System.Windows.Forms.Label minHeightLabel; private System.Windows.Forms.TextBox minWidthTextBox; private System.Windows.Forms.Label minWidthLabel; + private System.Windows.Forms.CheckBox showDisabledCheckBox; } } \ No newline at end of file diff --git a/TBF/Forms/ResultsArrangementDlg.cs b/TBF/Forms/ResultsArrangementDlg.cs index bed300446..8c5ed95b8 100644 --- a/TBF/Forms/ResultsArrangementDlg.cs +++ b/TBF/Forms/ResultsArrangementDlg.cs @@ -22,6 +22,7 @@ namespace TBF.Forms public TestsArrangement TestsArrangement; public MetersArrangement MetersArrangement; public int NrMetersInOneGroup; + public bool ShowDisabledPositions; public int MinWidth; public int MinHeight; @@ -62,6 +63,7 @@ namespace TBF.Forms horizontallyRadioButton.Text = Strings.Horizontally; verticallyRadioButton.Text = Strings.Vertically; nrMetersLabel.Text = string.Format("{0}:", Strings.Nr_meters_in_a_group); + showDisabledCheckBox.Text = Strings.Show_disabled_positions; minWidthLabel.Text = string.Format("{0}:", Strings.Min_width); minHeightLabel.Text = string.Format("{0}:", Strings.Min_height); unlockButton.Text = Strings.UnlockBtnText; @@ -79,6 +81,7 @@ namespace TBF.Forms horizontallyRadioButton.Checked = (MetersArrangement == MetersArrangement.Horizontally); verticallyRadioButton.Checked = (MetersArrangement == MetersArrangement.Vertically); nrMetersTextBox.Text = NrMetersInOneGroup.ToString(); + showDisabledCheckBox.Checked = ShowDisabledPositions; minWidthTextBox.Text = MinWidth.ToString(); minHeightTextBox.Text = MinHeight.ToString(); } @@ -113,6 +116,7 @@ namespace TBF.Forms verticallyRadioButton.Enabled = true; horizontallyRadioButton.Enabled = true; nrMetersTextBox.Enabled = true; + showDisabledCheckBox.Enabled = true; minWidthTextBox.Enabled = true; minHeightTextBox.Enabled = true; resultsConfigCtrl.Unlocked = true; @@ -121,11 +125,9 @@ namespace TBF.Forms void okButton_Click(object sender, EventArgs e) { - if (testsColumnsRadioButton.Checked) TestsArrangement = TestsArrangement.Columns; - else TestsArrangement = TestsArrangement.Rows; - - if (horizontallyRadioButton.Checked) MetersArrangement = MetersArrangement.Horizontally; - else MetersArrangement = MetersArrangement.Vertically; + TestsArrangement = testsColumnsRadioButton.Checked ? TestsArrangement.Columns : TestsArrangement.Rows; + MetersArrangement = horizontallyRadioButton.Checked ? MetersArrangement.Horizontally : MetersArrangement.Vertically; + ShowDisabledPositions = showDisabledCheckBox.Checked; int tmpInt; if (int.TryParse(nrMetersTextBox.Text, out tmpInt) && tmpInt > 0) { NrMetersInOneGroup = tmpInt; } diff --git a/TBF/LocalSettings.cs b/TBF/LocalSettings.cs index 9f9bc6300..a153b27bd 100644 --- a/TBF/LocalSettings.cs +++ b/TBF/LocalSettings.cs @@ -240,6 +240,7 @@ namespace TBF public Config.Entities.MetersArrangement ResultsConfigMeters; public Config.Entities.TestsArrangement ResultsConfigTests; public int ResultsConfigMetersInOneGroup; + public bool ShowDisabledPositions; public int ResultsConfigMinWidth; public int ResultsConfigMinHeight; public string[] RsltItems_Screen_SingleWM; diff --git a/TBF/Properties/AssemblyInfo.cs b/TBF/Properties/AssemblyInfo.cs index 3ef5e9aef..42d652fd8 100644 --- a/TBF/Properties/AssemblyInfo.cs +++ b/TBF/Properties/AssemblyInfo.cs @@ -29,5 +29,5 @@ using System.Runtime.InteropServices; // Build Number // Revision // -[assembly: AssemblyVersion("2.18.1285.0")] -[assembly: AssemblyFileVersion("2.18.1285.0")] +[assembly: AssemblyVersion("2.18.1290.0")] +[assembly: AssemblyFileVersion("2.18.1290.0")] diff --git a/TBF/Resources/Strings.Designer.cs b/TBF/Resources/Strings.Designer.cs index 764f4cedd..75a8fb477 100644 --- a/TBF/Resources/Strings.Designer.cs +++ b/TBF/Resources/Strings.Designer.cs @@ -4506,6 +4506,15 @@ namespace TBF.Resources { } } + /// + /// Looks up a localized string similar to Show disabled positions. + /// + internal static string Show_disabled_positions { + get { + return ResourceManager.GetString("Show_disabled_positions", resourceCulture); + } + } + /// /// Looks up a localized string similar to Shut down computer after exiting Test Bench Framework. /// diff --git a/TBF/Resources/Strings.cs.resx b/TBF/Resources/Strings.cs.resx index 120d9d379..3d983a451 100644 --- a/TBF/Resources/Strings.cs.resx +++ b/TBF/Resources/Strings.cs.resx @@ -1461,4 +1461,7 @@ Ukládání výsledků zlyhalo + + Zobrazit vypnuté pozice + \ No newline at end of file diff --git a/TBF/Resources/Strings.resx b/TBF/Resources/Strings.resx index ce8eda8d2..e9ff632e3 100644 --- a/TBF/Resources/Strings.resx +++ b/TBF/Resources/Strings.resx @@ -2032,4 +2032,7 @@ Saving results failed + + Show disabled positions + \ No newline at end of file diff --git a/TBF/Screens/ResultsTabPageCtrl.Designer.cs b/TBF/Screens/ResultsTabPageCtrl.Designer.cs index 8d8eba0fa..b9395086a 100644 --- a/TBF/Screens/ResultsTabPageCtrl.Designer.cs +++ b/TBF/Screens/ResultsTabPageCtrl.Designer.cs @@ -246,6 +246,7 @@ namespace TBF.Screens this.flowLayoutPanel.Name = "flowLayoutPanel"; this.flowLayoutPanel.Size = new System.Drawing.Size(1315, 660); this.flowLayoutPanel.TabIndex = 0; + this.flowLayoutPanel.SizeChanged += new System.EventHandler(this.flowLayoutPanel_SizeChanged); // // ResultsTabPageCtrl // diff --git a/TBF/Screens/ResultsTabPageCtrl.cs b/TBF/Screens/ResultsTabPageCtrl.cs index 3ea8955a5..b814af6f3 100644 --- a/TBF/Screens/ResultsTabPageCtrl.cs +++ b/TBF/Screens/ResultsTabPageCtrl.cs @@ -1,5 +1,5 @@ /// -/// Copyright (c) 2013-2018 Sensus Slovensko a.s. +/// Copyright (c) 2013-2019 Sensus Slovensko a.s. /// using System; using System.Collections.Generic; @@ -35,6 +35,7 @@ namespace TBF.Screens public MetersArrangement MetersArrangement; public TestsArrangement TestsArrangement; public int NrMetersInOneGroup; + public bool ShowDisabledPositions; public int MinWidth; public int MinHeight; @@ -42,11 +43,17 @@ namespace TBF.Screens public IList RsltItems_Screen_CombinedWM; public IList RsltItems_Screen_HeatM; - MetersKind metersKind; - OneWMResultsCtrl firstListView; + MetersKind metersKind; + IList currentItems; + IOneWMResultsCtrl[] wmRsltsCtrl; /// An array of controls with water meter results. + IOneWMResultsCtrl firstEnabledControl; + DateTime lastRedraw; + DateTime lastSizeChange; + int metersInOneGroup; + int nrGroups; + + Timer timer; - int lvWidth; - int lvHeight; /// /// Constructor @@ -55,16 +62,25 @@ namespace TBF.Screens { InitializeComponent(); + wmRsltsCtrl = new IOneWMResultsCtrl[0]; /// No water meters displayed => array with zero length + firstEnabledControl = null; /// No water meters displayed => firstListView is null + currentItems = new List(); + nrGroups = 1; + metersInOneGroup = 1; + if (Program.LocalSettings != null) { MetersArrangement = Program.LocalSettings.ResultsConfigMeters; TestsArrangement = Program.LocalSettings.ResultsConfigTests; NrMetersInOneGroup = Math.Max(1, Program.LocalSettings.ResultsConfigMetersInOneGroup); + ShowDisabledPositions = Program.LocalSettings.ShowDisabledPositions; MinWidth = Program.LocalSettings.ResultsConfigMinWidth; MinHeight = Program.LocalSettings.ResultsConfigMinHeight; RsltItems_Screen_SingleWM = Results.WMeterRsltItemSpec.FromStrArray(Program.LocalSettings.RsltItems_Screen_SingleWM); RsltItems_Screen_CombinedWM = Results.WMeterRsltItemSpec.FromStrArray(Program.LocalSettings.RsltItems_Screen_CombinedWM); RsltItems_Screen_HeatM = Results.WMeterRsltItemSpec.FromStrArray(Program.LocalSettings.RsltItems_Screen_HeatM); + + currentItems = GetRsltItems(metersKind); } Bridge.ProcedureSelectedHandler += delegate(object sender, ProcedureSelectedEventArgs args) @@ -90,24 +106,41 @@ namespace TBF.Screens else OnButtonsEtc(sndr, args); }; - } + + + lastSizeChange = DateTime.Now; + + /// Create a timer with one second interval. + timer = new Timer(); + timer.Interval = 1000; /// ms + timer.Tick += new EventHandler(OnTimer); + timer.Start(); + } void OnProcedureSelected(object sender, ProcedureSelectedEventArgs args) { - if ((TBF.BenchControl.Sequences.ProcessData.BatchRslts != null) && (Program.LocalSettings != null)) + Results.BatchResults batchResults = TBF.BenchControl.Sequences.ProcessData.BatchRslts; + + if ((batchResults != null) && (Program.LocalSettings != null)) { - Results.Utils.GetCounterStates(TBF.BenchControl.Sequences.ProcessData.BatchRslts.Batch, Program.LocalSettings.Counters); + Results.Utils.GetCounterStates(batchResults.Batch, Program.LocalSettings.Counters); } - RedrawAll(TBF.BenchControl.Sequences.ProcessData.BatchRslts); + + if (IsLayoutChangedDueToData(batchResults)) CreateControlsAndFillPanel(batchResults); + UpdateResults(batchResults); } void OnTestCompleted(object sender, TestCompletedEventArgs args) { - if ((TBF.BenchControl.Sequences.ProcessData.BatchRslts != null) && (Program.LocalSettings != null)) + Results.BatchResults batchResults = TBF.BenchControl.Sequences.ProcessData.BatchRslts; + + if ((batchResults != null) && (Program.LocalSettings != null)) { - Results.Utils.GetCounterStates(TBF.BenchControl.Sequences.ProcessData.BatchRslts.Batch, Program.LocalSettings.Counters); + Results.Utils.GetCounterStates(batchResults.Batch, Program.LocalSettings.Counters); } - RedrawAll(TBF.BenchControl.Sequences.ProcessData.BatchRslts); + + if (IsLayoutChangedDueToData(batchResults)) CreateControlsAndFillPanel(batchResults); + UpdateResults(TBF.BenchControl.Sequences.ProcessData.BatchRslts); } void OnButtonsEtc(object sender, UiBridge.ButtonsEtcEventArgs args) @@ -154,7 +187,9 @@ namespace TBF.Screens { Results.Utils.GetCounterStates(TBF.BenchControl.Sequences.ProcessData.BatchRslts.Batch, Program.LocalSettings.Counters); } - RedrawAll(TBF.BenchControl.Sequences.ProcessData.BatchRslts); + + CreateControlsAndFillPanel(TBF.BenchControl.Sequences.ProcessData.BatchRslts); + UpdateResults(TBF.BenchControl.Sequences.ProcessData.BatchRslts); } @@ -179,7 +214,7 @@ namespace TBF.Screens /// - /// Invoke a configuration dialog + /// Handle button at the top of this form: Invoke a configuration dialog /// private void configureButton_Click(object sender, EventArgs e) { @@ -189,6 +224,7 @@ namespace TBF.Screens dlg.TestsArrangement = TestsArrangement; dlg.MetersArrangement = MetersArrangement; dlg.NrMetersInOneGroup = NrMetersInOneGroup; + dlg.ShowDisabledPositions = ShowDisabledPositions; dlg.MinWidth = MinWidth; dlg.MinHeight = MinHeight; dlg.SelectedItems = GetRsltItems(metersKind); @@ -196,13 +232,25 @@ namespace TBF.Screens DialogResult dr = dlg.ShowDialog(); if (dr == DialogResult.OK && dlg.Unlocked) { - Program.LocalSettings.ResultsConfigMeters = MetersArrangement = dlg.MetersArrangement;; - Program.LocalSettings.ResultsConfigTests = TestsArrangement = dlg.TestsArrangement; - Program.LocalSettings.ResultsConfigMetersInOneGroup = NrMetersInOneGroup = dlg.NrMetersInOneGroup; - Program.LocalSettings.ResultsConfigMinWidth = MinWidth = dlg.MinWidth; - Program.LocalSettings.ResultsConfigMinHeight = MinHeight = dlg.MinHeight; + bool isLayoutChangedDueToConfig = false; - switch (metersKind) + if ((MetersArrangement != dlg.MetersArrangement) || + (TestsArrangement != dlg.TestsArrangement) || + (NrMetersInOneGroup != dlg.NrMetersInOneGroup) || + (ShowDisabledPositions != dlg.ShowDisabledPositions) || + (MinWidth != dlg.MinWidth) || + (MinHeight != dlg.MinHeight)) + { + Program.LocalSettings.ResultsConfigMeters = MetersArrangement = dlg.MetersArrangement;; + Program.LocalSettings.ResultsConfigTests = TestsArrangement = dlg.TestsArrangement; + Program.LocalSettings.ResultsConfigMetersInOneGroup = NrMetersInOneGroup = dlg.NrMetersInOneGroup; + Program.LocalSettings.ShowDisabledPositions = ShowDisabledPositions = dlg.ShowDisabledPositions; + Program.LocalSettings.ResultsConfigMinWidth = MinWidth = dlg.MinWidth; + Program.LocalSettings.ResultsConfigMinHeight = MinHeight = dlg.MinHeight; + isLayoutChangedDueToConfig = true; + } + + switch (metersKind) { default: case MetersKind.Single: @@ -218,313 +266,36 @@ namespace TBF.Screens Program.LocalSettings.RsltItems_Screen_HeatM = Results.WMeterRsltItemSpec.ToStrArray(RsltItems_Screen_HeatM); break; } + UpdateItems(dlg.SelectedItems); Program.LocalSettings.Save(); - } - if ((TBF.BenchControl.Sequences.ProcessData.BatchRslts != null) && (Program.LocalSettings != null)) - { - Results.Utils.GetCounterStates(TBF.BenchControl.Sequences.ProcessData.BatchRslts.Batch, Program.LocalSettings.Counters); - } - RedrawAll(TBF.BenchControl.Sequences.ProcessData.BatchRslts); - } - - /// - /// Clear the results - /// - private void showPreviousResultsButton_Click(object sender, EventArgs e) - { - new TBF.Forms.PreviousResultsDlg().ShowDialog(); - } - - private void reloadPreviousResultsButton_Click(object sender, EventArgs e) - { - new TBF.Forms.PreviousResultsDlg(TBF.Forms.PreviousResultsMode.Reload).ShowDialog(); - } - - private void fixPreviousResultsButton_Click(object sender, EventArgs e) - { - new TBF.Forms.PreviousResultsDlg(TBF.Forms.PreviousResultsMode.Fix).ShowDialog(); - } - - #region Redraw - - /// - /// Re-draw the results. Apply new settings if they changed. - /// - void RedrawAll(Results.BatchResults results) - { - this.SuspendLayout(); - - if (results == null) - { - flowLayoutPanel.Controls.Clear(); - ResumeLayout(false); - return; - } - - try - { - /// Determine how many water meters were enabled for result evaluation and printing - int enabledWMsCount = 0; - for (int i = 0; i < results.WMPositionsCount; i++) - { - if (results.WaterMeters[i] != null && !results.WaterMeters[i].Disabled) - { - enabledWMsCount++; - } - } - - int metersInOneGroup = Math.Max(1, Math.Min(enabledWMsCount, NrMetersInOneGroup)); - int nrGroups = Math.Max(1, (enabledWMsCount + metersInOneGroup - 1) / metersInOneGroup); - - if (MetersArrangement == MetersArrangement.Horizontally) - { - flowLayoutPanel.FlowDirection = FlowDirection.LeftToRight; - lvWidth = Math.Max(MinWidth, flowLayoutPanel.Width / metersInOneGroup - 6); - lvHeight = Math.Max(MinHeight, flowLayoutPanel.Height / nrGroups - 6); - } - else - { - flowLayoutPanel.FlowDirection = FlowDirection.TopDown; - lvWidth = Math.Max(MinWidth, flowLayoutPanel.Width / nrGroups - 6); - lvHeight = Math.Max(MinHeight, flowLayoutPanel.Height / metersInOneGroup - 6); - } - flowLayoutPanel.Controls.Clear(); - flowLayoutPanel.WrapContents = true; - flowLayoutPanel.AutoScroll = true; - - bool first = true; - for (int i = 0; i < results.WMPositionsCount; i++) - { - if (results.WaterMeters[i] != null && !results.WaterMeters[i].Disabled) - { - OneWMResultsCtrl lview = (TestsArrangement == TestsArrangement.Rows) - ? GetResultsTestsAreRows(results.WaterMeters[i], i + 1) - : GetResultsTestsAreColumns(results.WaterMeters[i], i + 1); - if (lview != null) - { - flowLayoutPanel.Controls.Add(lview); - if (first) - { - firstListView = lview; - first = false; - } - - lview.WMResultsClickedHandler += delegate(object sender, Results.Forms.WaterMeterEventArgs args) - { - if (InvokeRequired) - { - Invoke(new EventHandler(OnDoubleClick), sender, args); - } - else - { - OnDoubleClick(sender, args); - } - }; - } - } - } - } - catch (Exception e) - { - log.FatalFormat("Redrawing results failed : {0}", e.Message); - if (e.InnerException != null) - { - log.FatalFormat("InnerMessage : {0}", e.InnerException.Message); - } - log.FatalFormat("StackTrace : {0}{1}", Environment.NewLine, e.StackTrace); - } - - this.ResumeLayout(false); - } - - - /// - /// Get an empty ListView control with appropriate parameters. - /// - /// ListView control - OneWMResultsCtrl GetListView(Color backColor, Results.Entities.WaterMeter wm) - { - return new OneWMResultsCtrl(backColor, lvWidth, lvHeight, wm); - } - /// - OneWMResultsCtrl GetListView(Results.Entities.WaterMeter wm) - { - return GetListView(Color.White, wm); - } - - - /// - /// Get a ListView control filled with results of the meter 'mtr' - /// - /// Water meter number (1-based): 1 .. Config.Data.WMsCount - /// ListView object - OneWMResultsCtrl GetResultsTestsAreRows(Results.Entities.WaterMeter wMtr, int printedWMNr) - { - metersKind = wMtr.Compound() ? MetersKind.Combined : (wMtr.HeatMeter() ? MetersKind.HeatMeter : MetersKind.Single); - - string message = string.Empty; -#if ORACLE_DB - bool maxRepeatsExceeded = ((TBF.BenchControl.Sequences.ProcessData.BenchInfo is TBF.BenchControl.BenchInfo.iPerl.Component) && - (wMtr.Pruefindex % 100) >= (TBF.BenchControl.Sequences.ProcessData.BenchInfo as TBF.BenchControl.BenchInfo.iPerl.Component).MaxTestIndex); - Color commonBackColor = wMtr.GetColorOfResults(maxRepeatsExceeded, out message); - OneWMResultsCtrl lview = GetListView(commonBackColor, wMtr); - lview.Caption = string.Format("{0} ({1}) {2}", (string.IsNullOrEmpty(wMtr.SerialNr) ? string.Empty : wMtr.SerialNr), (wMtr.Pruefindex % 100), message); -#else - Color commonBackColor = wMtr.GetColorOfResults(false, out message); - OneWMResultsCtrl lview = GetListView(commonBackColor, wMtr); - lview.Caption = string.Format("s/n = {0}", string.IsNullOrEmpty(wMtr.SerialNr) ? string.Empty : wMtr.SerialNr); -#endif - - IList items = GetRsltItems(metersKind); - - if (items == null || items.Count == 0) return lview; - - // Header - TBF.LocalSettings ls = Program.LocalSettings; - lview.Columns.Add(printedWMNr.ToString(), (ls.RsltsClmnCount > 0) ? ls.RsltsClmnWidths[0] : 40); - int col = 1; - foreach (var item in items) - { - lview.Columns.Add(item.Caption, (ls.RsltsClmnCount > col) ? ls.RsltsClmnWidths[col] : 70); - col++; - } - - - IList testNames = wMtr.GetAllDecoratedTestNames(); - int ix = 0; - foreach (var mtr in wMtr.MeterTestRslts) - { - if (mtr != null && - (mtr.CompoundMeterId == (byte)CompoundMeterId.Single || - mtr.CompoundMeterId == (byte)CompoundMeterId.Compound || - mtr.CompoundMeterId == (byte)CompoundMeterId.HeatMeterEnergy) && - mtr.TestDone && - mtr.Publish() != Config.Entities.Publish.Never && - mtr.Publish() != Config.Entities.Publish.Internal) - { - ListViewItem lvi = new ListViewItem(testNames[ix++]); - - for (int i = 0; i < items.Count; i++) - { - string str = items[i].Print(wMtr, mtr.Name()); - - /// Extract and use color information - string[] texts = str.Split(new char[] { '|' }); - if (texts.Length == 1) - { - lvi.SubItems.Add(str); - } - else if (texts.Length == 2) - { - Color color = texts[1].Equals("Green") ? Color.Green : (texts[1].Equals("Red") ? Color.Red : commonBackColor); - lvi.UseItemStyleForSubItems = false; - lvi.SubItems.Add(texts[0]); - lvi.SubItems[lvi.SubItems.Count - 1].BackColor = color; - } - else - { - lvi.SubItems.Add(string.Empty); - } - } - - lview.Items.Add(lvi); - } - } - - return lview; - } - - - /// - /// Get a ListView control filled with results of the meter 'mtr' - /// - /// Water meter number (1-based): 1 .. Config.Data.WMsCount - /// ListView object - OneWMResultsCtrl GetResultsTestsAreColumns(Results.Entities.WaterMeter wMtr, int printedWMNr) - { - metersKind = wMtr.Compound() ? MetersKind.Combined : (wMtr.HeatMeter() ? MetersKind.HeatMeter : MetersKind.Single); - - string message; -#if ORACLE_DB - bool maxRepeatsExceeded = ((TBF.BenchControl.Sequences.ProcessData.BenchInfo is TBF.BenchControl.BenchInfo.iPerl.Component) && - (wMtr.Pruefindex % 100) >= (TBF.BenchControl.Sequences.ProcessData.BenchInfo as TBF.BenchControl.BenchInfo.iPerl.Component).MaxTestIndex); - Color commonBackColor = wMtr.GetColorOfResults(maxRepeatsExceeded, out message); - OneWMResultsCtrl lview = GetListView(commonBackColor, wMtr); - lview.Caption = string.Format("{0} ({1}) {2}", (string.IsNullOrEmpty(wMtr.SerialNr) ? string.Empty : wMtr.SerialNr), (wMtr.Pruefindex % 100), message); -#else - Color commonBackColor = wMtr.GetColorOfResults(false, out message); - OneWMResultsCtrl lview = GetListView(commonBackColor, wMtr); - lview.Caption = string.Format("s/n = {0}", string.IsNullOrEmpty(wMtr.SerialNr) ? string.Empty : wMtr.SerialNr); -#endif - - IList items = GetRsltItems(metersKind); - - if (items == null || items.Count == 0) return lview; - - // Header - TBF.LocalSettings ls = Program.LocalSettings; - lview.Columns.Add(printedWMNr.ToString(), (ls.RsltsClmnCount > 0) ? ls.RsltsClmnWidths[0] : 40); - int i = 1; - foreach (var str in wMtr.GetAllDecoratedTestNames()) - { - lview.Columns.Add(str, (ls.RsltsClmnCount > i) ? ls.RsltsClmnWidths[i] : 70); - i++; - } - - foreach (var item in items) - { - ListViewItem lvi = new ListViewItem(item.Caption); - - foreach (var mtr in wMtr.MeterTestRslts) + if ((TBF.BenchControl.Sequences.ProcessData.BatchRslts != null) && (Program.LocalSettings != null)) { - if (mtr != null && - (mtr.CompoundMeterId == (byte)CompoundMeterId.Single || - mtr.CompoundMeterId == (byte)CompoundMeterId.Compound || - mtr.CompoundMeterId == (byte)CompoundMeterId.HeatMeterEnergy) && - mtr.TestDone && - mtr.Publish() != Config.Entities.Publish.Never && - mtr.Publish() != Config.Entities.Publish.Internal) - { - string str = item.Print(wMtr, mtr.Name()); - - string[] texts = str.Split(new char[] { '|' }); - if (texts.Length == 1) - { - lvi.SubItems.Add(str); - } - else if (texts.Length == 2) - { - Color color = texts[1].Equals("Green") ? Color.Green : (texts[1].Equals("Red") ? Color.Red : commonBackColor); - lvi.UseItemStyleForSubItems = false; - lvi.SubItems.Add(texts[0]); - lvi.SubItems[lvi.SubItems.Count - 1].BackColor = color; - } - else - { - lvi.SubItems.Add(string.Empty); - } - } + Results.Utils.GetCounterStates(TBF.BenchControl.Sequences.ProcessData.BatchRslts.Batch, Program.LocalSettings.Counters); } - lview.Items.Add(lvi); - } + if (isLayoutChangedDueToConfig) + { + CreateControlsAndFillPanel(TBF.BenchControl.Sequences.ProcessData.BatchRslts); + } - return lview; + UpdateResults(TBF.BenchControl.Sequences.ProcessData.BatchRslts); + } } - #endregion Redraw - + /// + /// Handle button at the top of this form: Propagate column widths + /// private void columnWidthsButton_Click(object sender, EventArgs e) { - if (firstListView == null) return; + if (firstEnabledControl == null) return; - /// Update the column widths - Program.LocalSettings.RsltsClmnWidths = new int[firstListView.Columns.Count]; - for (int i = 0; i < firstListView.Columns.Count; i++) + /// Get column widths from the first control + Program.LocalSettings.RsltsClmnWidths = new int[firstEnabledControl.Columns.Count]; + for (int i = 0; i < firstEnabledControl.Columns.Count; i++) { - Program.LocalSettings.RsltsClmnWidths[i] = firstListView.Columns[i].Width; + Program.LocalSettings.RsltsClmnWidths[i] = firstEnabledControl.Columns[i].Width; } Program.LocalSettings.Save(); @@ -532,30 +303,243 @@ namespace TBF.Screens { Results.Utils.GetCounterStates(TBF.BenchControl.Sequences.ProcessData.BatchRslts.Batch, Program.LocalSettings.Counters); } - RedrawAll(TBF.BenchControl.Sequences.ProcessData.BatchRslts); + + UpdateColumnWidths(Program.LocalSettings.RsltsClmnWidths); } + /// + /// Handle other buttons at the top of this form + /// + private void showPreviousResultsButton_Click(object sender, EventArgs e) + { + new TBF.Forms.PreviousResultsDlg().ShowDialog(); + } + private void reloadPreviousResultsButton_Click(object sender, EventArgs e) + { + new TBF.Forms.PreviousResultsDlg(TBF.Forms.PreviousResultsMode.Reload).ShowDialog(); + } + private void fixPreviousResultsButton_Click(object sender, EventArgs e) + { + new TBF.Forms.PreviousResultsDlg(TBF.Forms.PreviousResultsMode.Fix).ShowDialog(); + } + /// + /// Handle double-click inside a water meter results control + /// void OnDoubleClick(object sender, Results.Forms.WaterMeterEventArgs args) { - if (args.WM == null || args.WM.Disabled) + int waterMetersCount = TBF.BenchControl.Sequences.ProcessData.BatchRslts.WaterMeters.Length; + + Results.Entities.WaterMeter wm; + if ((args.WMPosition <= 0) || (args.WMPosition > waterMetersCount) || + ((wm = TBF.BenchControl.Sequences.ProcessData.BatchRslts.WaterMeters[args.WMPosition - 1]) == null)) { MessageBox.Show(Strings.No_water_meter); return; } - else if ((TracingDB.DB.SessionFactory == null) || string.IsNullOrEmpty(args.WM.SerialNr)) + + ShowMoreWMResults(wm); + } + + + void UpdateColumnWidths(int[] columnWidths) + { + foreach (var ctrl in wmRsltsCtrl) ctrl.Update(columnWidths); + } + + void UpdateScrollpositions(int scrollStart) + { + /// TODO + } + + + void UpdateItems(IList items) + { + bool updateItems = false; + if (currentItems.Count != items.Count) { - new Results.Forms.MoreWMResultsDlg(args.WM, null).ShowDialog(); + /// Current and new item counts are different + updateItems = true; + } + else + { + /// Current and new item counts are the same + for (int i = 0; i < currentItems.Count; i++) + { + if (currentItems[i] != items[i]) + { + updateItems = true; + break; + } + } + } + + if (updateItems) + { + /// Update items in all controls + currentItems = items; + foreach (var oneCtrl in wmRsltsCtrl) oneCtrl.Update(items); + } + } + + + bool IsLayoutChangedDueToData(Results.BatchResults results) + { + if (results == null || results.WaterMeters == null || results.WaterMeters.Length == 0) + { + /// 'results' contain no water meters, wmRsltsCtrl.Lenght == 0 expected + return (wmRsltsCtrl.Length != 0); /// true when there are currently water meters on screen + } + + /// + /// Determine water meter positions count + /// + int displayedWatermetersCount = 0; + for (int i = 0; i < results.WaterMeters.Length; i++) + { + if (results.WaterMeters[i] != null) + { + if (ShowDisabledPositions || !results.WaterMeters[i].Disabled) + { + displayedWatermetersCount++; + } + } + } + + return (displayedWatermetersCount != wmRsltsCtrl.Length); + } + + + /// + /// Re-draw the results. Apply new settings if they changed. + /// + void CreateControlsAndFillPanel(Results.BatchResults results) + { + if ((results == null) || (results.WMPositionsCount == 0)) + { + /// There are no water meters at all + flowLayoutPanel.Controls.Clear(); + wmRsltsCtrl = new OneWMResultsRowsCtrl[0]; + firstEnabledControl = null; + return; + } + + /// + /// Determine water meter positions count + /// + int displayedControlsCount = 0; + for (int i = 0; i < results.WaterMeters.Length; i++) + { + if (results.WaterMeters[i] != null) + { + if (ShowDisabledPositions || !results.WaterMeters[i].Disabled) + { + displayedControlsCount++; + } + } + } + + /// + /// Calculate geometry + /// + metersInOneGroup = Math.Max(1, Math.Min(displayedControlsCount, NrMetersInOneGroup)); + nrGroups = Math.Max(1, (displayedControlsCount + metersInOneGroup - 1) / metersInOneGroup); + + int oneWidth; + int oneHeight; + /// + if (MetersArrangement == MetersArrangement.Horizontally) + { + flowLayoutPanel.FlowDirection = FlowDirection.LeftToRight; + oneWidth = Math.Max(MinWidth, flowLayoutPanel.Width / metersInOneGroup - 6); + oneHeight = Math.Max(MinHeight, flowLayoutPanel.Height / nrGroups - 6); + } + else + { + flowLayoutPanel.FlowDirection = FlowDirection.TopDown; + oneWidth = Math.Max(MinWidth, flowLayoutPanel.Width / nrGroups - 6); + oneHeight = Math.Max(MinHeight, flowLayoutPanel.Height / metersInOneGroup - 6); + } + + /// + /// Create controls and fill the FlowLayoutPanel + /// + flowLayoutPanel.SuspendLayout(); + flowLayoutPanel.Controls.Clear(); + flowLayoutPanel.WrapContents = true; + flowLayoutPanel.AutoScroll = true; + + wmRsltsCtrl = new IOneWMResultsCtrl[displayedControlsCount]; + int ix = 0; + firstEnabledControl = null; + for (int i = 0; i < results.WaterMeters.Length; i++) + { + if (results.WaterMeters[i] != null) + { + if (!results.WaterMeters[i].Disabled || ShowDisabledPositions) + { + /// Create one water meter position / control + wmRsltsCtrl[ix] = (TestsArrangement == TestsArrangement.Rows) + ? new OneWMResultsRowsCtrl() as IOneWMResultsCtrl + : new OneWMResultsColumnsCtrl() as IOneWMResultsCtrl; + wmRsltsCtrl[ix].Width = oneWidth; + wmRsltsCtrl[ix].Height = oneHeight; + wmRsltsCtrl[ix].Update(currentItems); + wmRsltsCtrl[ix].WMResultsClickedHandler += delegate(object s, Results.Forms.WaterMeterEventArgs args) + { + if (InvokeRequired) + { + Invoke(new EventHandler(OnDoubleClick), s, args); + } + else + { + OnDoubleClick(s, args); + } + }; + + flowLayoutPanel.Controls.Add(wmRsltsCtrl[ix] as UserControl); + if ((firstEnabledControl == null) && !results.WaterMeters[i].Disabled) firstEnabledControl = wmRsltsCtrl[ix]; + ix++; + } + } + } + + UpdateColumnWidths(Program.LocalSettings.RsltsClmnWidths); + + flowLayoutPanel.ResumeLayout(); + } + + + void UpdateResults(Results.BatchResults batchResults) + { + if ((batchResults != null) && (batchResults.WaterMeters != null)) + { + int ctrlIx = 0; + for (int i = 0; i < batchResults.WaterMeters.Length; i++) + { + if (!batchResults.WaterMeters[i].Disabled || ShowDisabledPositions) + { + if (ctrlIx < wmRsltsCtrl.Length) wmRsltsCtrl[ctrlIx++].Update(batchResults.WaterMeters[i]); + } + } + } + } + + + void ShowMoreWMResults(Results.Entities.WaterMeter wm) + { + if ((TracingDB.DB.SessionFactory == null) || string.IsNullOrEmpty(wm.SerialNr)) + { + new Results.Forms.MoreWMResultsDlg(wm, null).ShowDialog(); } else { - IList refRecords = null; using (ISession session = TracingDB.DB.SessionFactory.OpenSession()) { - refRecords = session.QueryOver() - .Where(x => (x.Code == args.WM.SerialNr)) - .OrderBy(x => x.TimeStamp).Desc - .List(); + 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]; @@ -579,7 +563,55 @@ namespace TBF.Screens } } - new Results.Forms.MoreWMResultsDlg(args.WM, refRecords).ShowDialog(); + new Results.Forms.MoreWMResultsDlg(wm, refRecords).ShowDialog(); + } + } + } + + + private void flowLayoutPanel_SizeChanged(object sender, EventArgs e) + { + lastSizeChange = DateTime.Now; + } + + private void OnTimer(object source, EventArgs e) + { + if (DateTime.Compare(lastSizeChange, lastRedraw) > 0) + { + /// The last size change was more recent then the last redraw + + DateTime now = DateTime.Now; + if (DateTime.Compare(lastSizeChange + new TimeSpan(0, 0, 1), now) < 0) + { + /// More then 1 second since the last panel size change + + /// Calculate geometry + int oneWidth; + int oneHeight; + /// + if (MetersArrangement == MetersArrangement.Horizontally) + { + flowLayoutPanel.FlowDirection = FlowDirection.LeftToRight; + oneWidth = Math.Max(MinWidth, flowLayoutPanel.Width / metersInOneGroup - 6); + oneHeight = Math.Max(MinHeight, flowLayoutPanel.Height / nrGroups - 6); + } + else + { + flowLayoutPanel.FlowDirection = FlowDirection.TopDown; + oneWidth = Math.Max(MinWidth, flowLayoutPanel.Width / nrGroups - 6); + oneHeight = Math.Max(MinHeight, flowLayoutPanel.Height / metersInOneGroup - 6); + } + + /// Update size of controls + flowLayoutPanel.SuspendLayout(); + /// + foreach (var oneCtrl in wmRsltsCtrl) + { + oneCtrl.Width = oneWidth; + oneCtrl.Height = oneHeight; + } + /// + flowLayoutPanel.ResumeLayout(); } } }