From efc4668200499d88093a7718f682db702b50719c Mon Sep 17 00:00:00 2001 From: Milan Hanajik Date: Wed, 15 Feb 2017 10:57:37 +0100 Subject: [PATCH] Only relevant units are displayed by ComboBox when using ResultsConfigDlg --- Config/Units.cs | 2 +- Results/Forms/ResultsConfigDlg.cs | 44 ++- Results/Results.csproj | 13 +- .../UiControls/BatchResultsCtrl.Designer.cs | 57 --- Results/UiControls/BatchResultsCtrl.cs | 358 ------------------ Results/UiControls/BatchResultsCtrl.resx | 120 ------ 6 files changed, 29 insertions(+), 565 deletions(-) delete mode 100644 Results/UiControls/BatchResultsCtrl.Designer.cs delete mode 100644 Results/UiControls/BatchResultsCtrl.cs delete mode 100644 Results/UiControls/BatchResultsCtrl.resx diff --git a/Config/Units.cs b/Config/Units.cs index 1fb95b504..95225e07f 100644 --- a/Config/Units.cs +++ b/Config/Units.cs @@ -9,7 +9,7 @@ namespace Config { public enum Unit { - None, + [Description("---")] None, [Description("l")] l, /// * 1 liter [Description("m3")] m3, /// 1000 l diff --git a/Results/Forms/ResultsConfigDlg.cs b/Results/Forms/ResultsConfigDlg.cs index 403fd11c1..b1828c56c 100644 --- a/Results/Forms/ResultsConfigDlg.cs +++ b/Results/Forms/ResultsConfigDlg.cs @@ -28,7 +28,8 @@ namespace Results.Forms Alignment, Count, } - Control[] editors; + Control[] editors; /// all editors except of units + ComboBox unitsCB; /// units combo box public IList AvailableItems; @@ -71,12 +72,7 @@ namespace Results.Forms selectedResultsListViewEx.Columns.Add(new ColumnHeader { Text = Strings.Alignment }); /// Create controls used by ListViewEx to edit items - ComboBox unitsCB = new ComboBox(); - unitsCB.Items.Add("---"); /// Use "---" instead of "None" - for (Config.Unit u = (Config.Unit)1; u < Config.Unit.Count; u++) - { - unitsCB.Items.Add(u.ToString().Replace("Pct", "%").Replace('p', '/')); - } + unitsCB = new ComboBox(); ComboBox alignmentCB = new ComboBox(); for (Config.Entities.Alignment a = 0; a < Config.Entities.Alignment.Count; a++) @@ -113,7 +109,18 @@ namespace Results.Forms void selectedResultsListViewEx_SubItemClicked(object sender, SubItemEventArgs e) { - if ((e.SubItem > 0) && (e.SubItem < (int)Column.Count)) + if (e.SubItem == (int)Column.Units) + { + Config.Quantity quantity = (e.Item.Tag as WMeterRsltItemSpec).Quantity; + unitsCB.Items.Clear(); + unitsCB.Items.Add(Config.Unit.None.ToDescription()); /// "---" + for (Config.Unit u = (Config.Unit)1; u < Config.Unit.Count; u++) + { + if (Config.Units.IsQuantity(u, quantity)) unitsCB.Items.Add(u.ToDescription()); + } + selectedResultsListViewEx.StartEditing(unitsCB, e.Item, e.SubItem); + } + else if ((e.SubItem > 0) && (e.SubItem < (int)Column.Count)) { selectedResultsListViewEx.StartEditing(editors[e.SubItem], e.Item, e.SubItem); } @@ -132,10 +139,9 @@ namespace Results.Forms case Column.Precision: item.Precision = e.DisplayText; return; case Column.Units: - if (editors[e.SubItem].Text == "---") { item.Units = 0; return; }; - for (Config.Unit u = (Config.Unit)1; u < Config.Unit.Count; u++) + for (Config.Unit u = 0; u < Config.Unit.Count; u++) { - if (u.ToString().Replace("Pct", "%").Replace('p', '/').Equals(editors[e.SubItem].Text)) + if (u.ToDescription().Equals(unitsCB.Text)) { item.Units = u; return; /// OK @@ -195,15 +201,15 @@ namespace Results.Forms selectedResultsListViewEx.Items.Clear(); foreach (var item in SelectedItems) { - ListViewItem lvi = new ListViewItem(item.Name); /// Item + ListViewItem lvi = new ListViewItem(item.Name); /// Item lvi.Tag = item; - lvi.SubItems.Add(item.Caption); /// Header - lvi.SubItems.Add(item.TestID); /// TestID - lvi.SubItems.Add((item.Units == Config.Unit.None) ? "---" : item.Units.ToString().Replace("Pct", "%").Replace('p', '/')); /// Units - lvi.SubItems.Add(item.Format); /// Format - lvi.SubItems.Add(item.Precision); /// Precision - lvi.SubItems.Add(item.Width.ToString()); /// Width - lvi.SubItems.Add(item.Alignment.ToDescription()); /// Alignment + lvi.SubItems.Add(item.Caption); /// Header + lvi.SubItems.Add(item.TestID); /// TestID + lvi.SubItems.Add(item.Units.ToDescription()); /// Units + lvi.SubItems.Add(item.Format); /// Format + lvi.SubItems.Add(item.Precision); /// Precision + lvi.SubItems.Add(item.Width.ToString()); /// Width + lvi.SubItems.Add(item.Alignment.ToDescription()); /// Alignment selectedResultsListViewEx.Items.Add(lvi); } diff --git a/Results/Results.csproj b/Results/Results.csproj index 0bb2caa00..c9045bf94 100644 --- a/Results/Results.csproj +++ b/Results/Results.csproj @@ -108,12 +108,6 @@ True Strings.resx - - UserControl - - - BatchResultsCtrl.cs - @@ -143,16 +137,15 @@ Resources.Designer.cs - + + Designer + ResXFileCodeGenerator Strings.Designer.cs - - BatchResultsCtrl.cs - diff --git a/Results/UiControls/BatchResultsCtrl.Designer.cs b/Results/UiControls/BatchResultsCtrl.Designer.cs deleted file mode 100644 index 266132e23..000000000 --- a/Results/UiControls/BatchResultsCtrl.Designer.cs +++ /dev/null @@ -1,57 +0,0 @@ -namespace Results.UiControls -{ - partial class BatchResultsCtrl - { - /// - /// 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.flowLayoutPanel = new System.Windows.Forms.FlowLayoutPanel(); - this.SuspendLayout(); - // - // flowLayoutPanel - // - this.flowLayoutPanel.Dock = System.Windows.Forms.DockStyle.Fill; - this.flowLayoutPanel.Location = new System.Drawing.Point(0, 0); - this.flowLayoutPanel.Name = "flowLayoutPanel"; - this.flowLayoutPanel.Size = new System.Drawing.Size(1000, 735); - this.flowLayoutPanel.TabIndex = 0; - // - // BatchResultsCtrl - // - this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.Controls.Add(this.flowLayoutPanel); - this.Name = "BatchResultsCtrl"; - this.Size = new System.Drawing.Size(1000, 735); - this.ResumeLayout(false); - - } - - #endregion - - private System.Windows.Forms.FlowLayoutPanel flowLayoutPanel; - } -} diff --git a/Results/UiControls/BatchResultsCtrl.cs b/Results/UiControls/BatchResultsCtrl.cs deleted file mode 100644 index f77c7dbc6..000000000 --- a/Results/UiControls/BatchResultsCtrl.cs +++ /dev/null @@ -1,358 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Drawing; -using System.Windows.Forms; -using log4net; -using Config.Entities; - -namespace Results.UiControls -{ - public partial class BatchResultsCtrl : UserControl - { - static readonly ILog log = LogManager.GetLogger(typeof(BatchResultsCtrl)); - - /// - /// Public members - /// - public MetersArrangement MetersArrangement; - public TestsArrangement TestsArrangement; - public int NrMetersInOneGroup; - - public IList RsltItems_Screen_SingleWM; - public IList RsltItems_Screen_CombinedWM; - public int[] RsltsClmnWidths - { - get - { - if (firstListView == null) return null; - - /// Update and return column widths - int[] temp = new int[firstListView.Columns.Count]; - for (int i = 0; i < firstListView.Columns.Count; i++) - { - temp[i] = firstListView.Columns[i].Width; - } - rsltsClmnWidths = temp; - return temp; - } - set - { - rsltsClmnWidths = value; - } - } - - public bool Compound { get { return Compound; } } /// To inform configuration dialog which configuration is active - - /// - /// Private members - /// - Results.BatchResults results; - bool compound; - - ListView firstListView; - public int[] rsltsClmnWidths; - int rsltsClmnCount { get { return (rsltsClmnWidths != null) ? rsltsClmnWidths.Length : 0; } } - - int lvWidth; - int lvHeight; - - - public BatchResultsCtrl() - { - InitializeComponent(); - } - - public void Display(Results.BatchResults results) - { - this.results = results; - Redraw(); - } - - - /// - /// Re-draw the results. Apply new settings if they changed. - /// - public void Redraw() - { - this.SuspendLayout(); - - 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 + NrMetersInOneGroup - 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; - } - 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) - { - if (TestsArrangement == TestsArrangement.Rows) - { - ListView lview = GetResultsTestsAreRows(results.WaterMeters[i], i + 1); - if (first) { firstListView = lview; first = false; } - if (lview != null) flowLayoutPanel.Controls.Add(lview); - } - else - { - ListView lview = GetResultsTestsAreColumns(results.WaterMeters[i], i + 1); - if (first) { firstListView = lview; first = false; } - if (lview != null) flowLayoutPanel.Controls.Add(lview); - } - } - } - } - 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 - ListView GetListView() - { - ListView lview = new ListView(); - lview.AllowColumnReorder = false; - lview.Dock = System.Windows.Forms.DockStyle.None; - lview.FullRowSelect = true; - lview.GridLines = true; - lview.Location = new System.Drawing.Point(0, 0); - lview.Size = new System.Drawing.Size(lvWidth, lvHeight); - lview.TabIndex = 0; - lview.UseCompatibleStateImageBehavior = false; - lview.View = System.Windows.Forms.View.Details; - return lview; - } - - - /// - /// Get decorated test names for a specified watermeter - /// - /// Watermeter results entity - /// A list of strings - IList GetAllDecoratedTestNames(Results.Entities.WaterMeter wMtr) - { - IList testNames = new List(); - - foreach (var mtr in wMtr.MeterTestRslts) - { - if ((mtr.CompoundMeterId == (byte)CompoundMeterId.Single || mtr.CompoundMeterId == (byte)CompoundMeterId.Compound) - && mtr.TestDone - && (mtr.Publish() != Config.Entities.Publish.Never) - && (mtr.Publish() != Config.Entities.Publish.Internal)) - { - testNames.Add(mtr.Name()); - } - } - - return testNames; - } - - - /// - /// Get a ListView control filled with results of the meter 'mtr' - /// - /// Water meter number (1-based): 1 .. Config.Data.WMsCount - /// ListView object - ListView GetResultsTestsAreRows(Results.Entities.WaterMeter wMtr, int printedWMNr) - { - compound = wMtr.Compound(); - - ListView lview = GetListView(); - - IList items = (compound ? RsltItems_Screen_CombinedWM : RsltItems_Screen_SingleWM); - if (items == null || items.Count == 0) return lview; - - // Header - lview.Columns.Add(printedWMNr.ToString(), (rsltsClmnCount > 0) ? rsltsClmnWidths[0] : 40); - int i = 1; - foreach (var item in items) - { - lview.Columns.Add(item.ClmnHeaderText, (rsltsClmnCount > i) ? rsltsClmnWidths[i] : 70); - i++; - } - - - IList testNames = GetAllDecoratedTestNames(wMtr); - int ix = 0; - foreach (var mtr in wMtr.MeterTestRslts) - { - if ((mtr.CompoundMeterId == (byte)CompoundMeterId.Single || mtr.CompoundMeterId == (byte)CompoundMeterId.Compound) - && mtr.TestDone - && (mtr.Publish() != Config.Entities.Publish.Never) - && (mtr.Publish() != Config.Entities.Publish.Internal)) - { - ListViewItem lvi = new ListViewItem(testNames[ix++]); - - foreach (var item in items) - { - string str; - if (compound) - { - var main = wMtr.GetMeterTestRslt(mtr.Name(), CompoundMeterId.CompoundMain); - var aux = wMtr.GetMeterTestRslt(mtr.Name(), CompoundMeterId.CompoundAux); - str = (item.CanPrintCompoundMeter && main != null && aux != null) - ? item.PrintCombined(main, aux, mtr) - : string.Empty; - } - else - { - str = item.CanPrintSingle ? item.Print(mtr) : 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); - } - } - - 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 - ListView GetResultsTestsAreColumns(Results.Entities.WaterMeter wMtr, int printedWMNr) - { - compound = wMtr.Compound(); - - ListView lview = GetListView(); - - IList items = (compound ? RsltItems_Screen_CombinedWM : RsltItems_Screen_SingleWM); - 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 GetAllDecoratedTestNames(wMtr)) - { - lview.Columns.Add(str, (rsltsClmnCount > i) ? rsltsClmnWidths[i] : 70); - i++; - } - - foreach (var item in items) - { - ListViewItem lvi = new ListViewItem(item.ClmnHeaderText); - if (compound) - { - foreach (var mtr in wMtr.MeterTestRslts) - { - if (mtr.CompoundMeterId == (byte)CompoundMeterId.Compound && mtr.TestDone - && (mtr.Publish() != Config.Entities.Publish.Never) - && (mtr.Publish() != Config.Entities.Publish.Internal)) - { - var main = wMtr.GetMeterTestRslt(mtr.Name(), CompoundMeterId.CompoundMain); - var aux = wMtr.GetMeterTestRslt(mtr.Name(), CompoundMeterId.CompoundAux); - - string str = (item.CanPrintCompoundMeter && main != null && aux != null) - ? item.PrintCombined(main, aux, mtr) - : 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); - } - } - } - } - else - { - foreach (var mtr in wMtr.MeterTestRslts) - { - if (mtr.TestDone && (mtr.Publish() != Config.Entities.Publish.Never) - && (mtr.Publish() != Config.Entities.Publish.Internal)) - { - string str = !item.CanPrintSingle ? string.Empty : item.Print(mtr); - - 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; - } - } -} diff --git a/Results/UiControls/BatchResultsCtrl.resx b/Results/UiControls/BatchResultsCtrl.resx deleted file mode 100644 index 1af7de150..000000000 --- a/Results/UiControls/BatchResultsCtrl.resx +++ /dev/null @@ -1,120 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 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