Only relevant units are displayed by ComboBox when using ResultsConfigDlg

This commit is contained in:
Milan Hanajik 2017-02-15 10:57:37 +01:00
parent a90ba0c546
commit efc4668200
6 changed files with 29 additions and 565 deletions

View File

@ -9,7 +9,7 @@ namespace Config
{
public enum Unit
{
None,
[Description("---")] None,
[Description("l")] l, /// * 1 liter
[Description("m3")] m3, /// 1000 l

View File

@ -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<WMeterRsltItemSpec> 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);
}

View File

@ -108,12 +108,6 @@
<DesignTime>True</DesignTime>
<DependentUpon>Strings.resx</DependentUpon>
</Compile>
<Compile Include="UiControls\BatchResultsCtrl.cs">
<SubType>UserControl</SubType>
</Compile>
<Compile Include="UiControls\BatchResultsCtrl.Designer.cs">
<DependentUpon>BatchResultsCtrl.cs</DependentUpon>
</Compile>
<Compile Include="Utils.cs" />
<Compile Include="WMeterRsltItemSpec.cs" />
</ItemGroup>
@ -143,16 +137,15 @@
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
<EmbeddedResource Include="Resources\Strings.cs.resx" />
<EmbeddedResource Include="Resources\Strings.de.resx" />
<EmbeddedResource Include="Resources\Strings.de.resx">
<SubType>Designer</SubType>
</EmbeddedResource>
<EmbeddedResource Include="Resources\Strings.pl.resx" />
<EmbeddedResource Include="Resources\Strings.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Strings.Designer.cs</LastGenOutput>
</EmbeddedResource>
<EmbeddedResource Include="Resources\Strings.ru.resx" />
<EmbeddedResource Include="UiControls\BatchResultsCtrl.resx">
<DependentUpon>BatchResultsCtrl.cs</DependentUpon>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<None Include="Resources\Headpic.png" />

View File

@ -1,57 +0,0 @@
namespace Results.UiControls
{
partial class BatchResultsCtrl
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Component Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
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;
}
}

View File

@ -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<Results.ItemSpec> RsltItems_Screen_SingleWM;
public IList<Results.ItemSpec> 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();
}
/// <summary>
/// Re-draw the results. Apply new settings if they changed.
/// </summary>
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);
}
/// <summary>
/// Get an empty ListView control with appropriate parameters.
/// </summary>
/// <returns>ListView control</returns>
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;
}
/// <summary>
/// Get decorated test names for a specified watermeter
/// </summary>
/// <param name="wMtr">Watermeter results entity</param>
/// <returns>A list of strings</returns>
IList<string> GetAllDecoratedTestNames(Results.Entities.WaterMeter wMtr)
{
IList<string> testNames = new List<string>();
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;
}
/// <summary>
/// Get a ListView control filled with results of the meter 'mtr'
/// </summary>
/// <param name="mtr">Water meter number (1-based): 1 .. Config.Data.WMsCount</param>
/// <returns>ListView object</returns>
ListView GetResultsTestsAreRows(Results.Entities.WaterMeter wMtr, int printedWMNr)
{
compound = wMtr.Compound();
ListView lview = GetListView();
IList<Results.ItemSpec> 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<string> 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;
}
/// <summary>
/// Get a ListView control filled with results of the meter 'mtr'
/// </summary>
/// <param name="mtr">Water meter number (1-based): 1 .. Config.Data.WMsCount</param>
/// <returns>ListView object</returns>
ListView GetResultsTestsAreColumns(Results.Entities.WaterMeter wMtr, int printedWMNr)
{
compound = wMtr.Compound();
ListView lview = GetListView();
IList<Results.ItemSpec> 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;
}
}
}

View File

@ -1,120 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>