1. Results.ItemID.Passed gives always the meter result, 2. Results.WMeterRsltItemSpec.Merge added + UI changes

This commit is contained in:
Milan Hanajik 2023-10-05 12:56:26 +02:00
parent e3f1f2711b
commit 36d661c75e
6 changed files with 146 additions and 116 deletions

View File

@ -22,6 +22,7 @@ namespace Results.Forms
Precision,
Width,
Alignment,
Merge,
TestID,
Count,
}
@ -91,7 +92,8 @@ namespace Results.Forms
selectedResultsListViewEx.Columns.Add(new ColumnHeader { Text = Strings.Precision });
selectedResultsListViewEx.Columns.Add(new ColumnHeader { Text = Strings.Width });
selectedResultsListViewEx.Columns.Add(new ColumnHeader { Text = Strings.Alignment });
if (!SupressTestIDColumn)
selectedResultsListViewEx.Columns.Add(new ColumnHeader { Text = Strings.Merge });
if (!SupressTestIDColumn)
{
selectedResultsListViewEx.Columns.Add(new ColumnHeader { Text = Strings.Test_ID });
}
@ -99,12 +101,16 @@ namespace Results.Forms
/// Create controls used by ListViewEx to edit items
unitsCB = new ComboBox();
ComboBox alignmentCB = new ComboBox();
var alignmentCB = new ComboBox();
for (Alignment a = 0; a < Alignment.Count; a++)
{
alignmentCB.Items.Add(a.ToDescription());
}
var mergeCB = new ComboBox();
mergeCB.Items.Add(Strings.No);
mergeCB.Items.Add(Strings.Yes);
editors = new Control[]
{
null,
@ -114,6 +120,7 @@ namespace Results.Forms
new TextBox(), /// precision
new TextBox(), /// width
alignmentCB,
mergeCB,
new TextBox(), /// testID
};
foreach (var edi in editors)
@ -198,7 +205,20 @@ namespace Results.Forms
}
break; /// Error
case Column.TestID: item.TestID = e.DisplayText; return;
case Column.Merge:
if (editors[e.SubItem].Text == Strings.Yes)
{
item.Merge = true;
return;
}
else if (editors[e.SubItem].Text == Strings.No)
{
item.Merge = false;
return;
}
break; /// Error
case Column.TestID: item.TestID = e.DisplayText; return;
default:
return; /// OK
@ -324,17 +344,18 @@ namespace Results.Forms
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.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
lvi.SubItems.Add(item.Caption); /// Header
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
lvi.SubItems.Add(item.Merge ? Strings.Yes : Strings.No); /// Merge
if (!SupressTestIDColumn)
{
lvi.SubItems.Add(item.TestID); /// TestID
lvi.SubItems.Add(item.TestID); /// TestID
}
selectedResultsListViewEx.Items.Add(lvi);

View File

@ -1,5 +1,5 @@
///
/// Copyright (c) 2016-2021 Sensus Slovensko a.s.
/// Copyright (c) 2016-2023 Sensus Slovensko a.s.
///
using System;

View File

@ -19,7 +19,7 @@ namespace Results.Resources {
// class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Strings {
@ -573,6 +573,15 @@ namespace Results.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to Merge.
/// </summary>
internal static string Merge {
get {
return ResourceManager.GetString("Merge", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Meter type.
/// </summary>

View File

@ -348,4 +348,7 @@
<data name="Workstep" xml:space="preserve">
<value>Krok</value>
</data>
<data name="Merge" xml:space="preserve">
<value>Spojit</value>
</data>
</root>

View File

@ -849,4 +849,7 @@
<data name="Workstep" xml:space="preserve">
<value>Workstep</value>
</data>
<data name="Merge" xml:space="preserve">
<value>Merge</value>
</data>
</root>

View File

@ -1,5 +1,5 @@
///
/// Copyright (c) 2013-2022 Sensus Slovensko a.s.
/// Copyright (c) 2013-2023 Sensus Slovensko a.s.
///
using System;
using System.Collections.Generic;
@ -7,6 +7,7 @@ using Common;
using Results.Entities;
using Results.Resources;
using System.Globalization;
using System.Linq;
namespace Results
{
@ -28,6 +29,7 @@ namespace Results
public string Precision; /// Specifies precision for the output
public int Width; /// Specifies the number of characters of the output, 0 = automatic
public Alignment Alignment; /// Specifies alignment for the output
public bool Merge; /// true = items are merged into one cell for a meter, for all tests
public WMeterRsltItemSpec Clone()
{
@ -39,6 +41,7 @@ namespace Results
item2.Precision = Precision;
item2.Width = Width;
item2.Alignment = Alignment;
item2.Merge = Merge;
return item2;
}
@ -102,24 +105,15 @@ namespace Results
Format = string.Empty;
Precision = string.Empty;
TestID = string.Empty;
Merge = false;
}
///
/// Constructor without ToolTip text
/// Constructor without a ToolTip text
///
public WMeterRsltItemSpec(ItemID itemId, string name, Quantity quantity, ItemCategory category, PrintDlgt printDlgt)
: this(itemId, name, null, quantity, category, printDlgt)
{
Uid = (int)itemId;
OldUid = itemId.ToString().Replace("__", "/").Replace('_', ' ');
Name = name;
ToolTipText = null;
Quantity = quantity;
Category = category;
this.printDlgt = printDlgt;
Format = string.Empty;
Precision = string.Empty;
TestID = string.Empty;
}
@ -145,6 +139,17 @@ namespace Results
AllItems.Add(new WMeterRsltItemSpec(ItemID.Test_method, Strings.Test_method + "()", Quantity.String, ItemCategory.TestData, (w,t,u,f,p) => FormatStr(f, (w.GetTestRslt(t) == null) ? "" : w.GetTestRslt(t).Method())));
AllItems.Add(new WMeterRsltItemSpec(ItemID.Test_Method_Elde, Strings.Test_method + " Elde ()", Quantity.String, ItemCategory.TestData, (w,t,u,f,p) => FormatStr(f, (w.GetTestRslt(t) == null) ? "" : w.GetTestRslt(t).MethodElde())));
AllItems.Add(new WMeterRsltItemSpec(ItemID.RefFlowmeter, "Ref. flowmeter", Quantity.String, ItemCategory.TestResult, (w,t,u,f,p) => (w.GetTestRslt(t) != null) ? FormatStr(f, w.GetTestRslt(t).RefFlowmeter()) : string.Empty));
AllItems.Add(new WMeterRsltItemSpec(ItemID.Scale, "Scale", Quantity.String, ItemCategory.TestResult, (w,t,u,f,p) => (w.GetTestRslt(t) != null) ? FormatStr(f, w.GetTestRslt(t).Scale()) : string.Empty));
AllItems.Add(new WMeterRsltItemSpec(ItemID.Diverter, "Diverter", Quantity.String, ItemCategory.TestResult, (w,t,u,f,p) => (w.GetTestRslt(t) != null) ? FormatStr(f, w.GetTestRslt(t).Diverter()) : string.Empty));
AllItems.Add(new WMeterRsltItemSpec(ItemID.RegValve, "Reg. valve", Quantity.String, ItemCategory.TestResult, (w,t,u,f,p) => (w.GetTestRslt(t) != null) ? FormatStr(f, w.GetTestRslt(t).RegValve()) : string.Empty));
AllItems.Add(new WMeterRsltItemSpec(ItemID.TestDone, Strings.Test_done + "()", Quantity.Boolean, ItemCategory.TestResult, (w,t,u,f,p) => FormatBool(f, (w.GetMeterTestRslt(t) != null) && w.GetMeterTestRslt(t).TestDone)));
AllItems.Add(new WMeterRsltItemSpec(ItemID.TestPassed, Strings.Test_passed + "()", Quantity.Boolean, ItemCategory.TestResult, (w,t,u,f,p) => FormatBool(f, (w.GetMeterTestRslt(t) != null) && w.GetMeterTestRslt(t).Passed)));
AllItems.Add(new WMeterRsltItemSpec(ItemID.Passed, Strings.Result, Quantity.Boolean, ItemCategory.MeterResult, (w,t,u,f,p) => w.PassedColorStr(f)));
AllItems.Add(new WMeterRsltItemSpec(ItemID.ThreeState, "Three state result",Quantity.Enumerated, ItemCategory.MeterResult, (w,t,u,f,p) => FormatThreeState(f, w.ThreeStateFromTests())));
AllItems.Add(new WMeterRsltItemSpec(ItemID.ResultOrErrorFlags,"Winiki lub E", Quantity.String, ItemCategory.MeterResult, (w,t,u,f,p) => (w.GetMeterTestRslt(t) != null) ? FormatStr(f, w.GetMeterTestRslt(t).PassedOrErrorFlagsStr())
: FormatStr(f, w.PassedOrErrorFlagsStr()))); /// PL specific result
///
/// Volume
///
@ -319,17 +324,6 @@ namespace Results
AllItems.Add(new WMeterRsltItemSpec(ItemID.Error, string.Format("{0} rel. ()", Strings.VName_Error), Strings.Tooltip_E_rel, Quantity.Error, ItemCategory.MeterResult, (w,t,u,f,p) => (w.GetMeterTestRslt(t) != null) ? FormatDbl(u, f, p, "V2", w.GetMeterTestRslt(t).Error) : string.Empty));
AllItems.Add(new WMeterRsltItemSpec(ItemID.Error_heat_mtr_vol, string.Format("{0} rel.hm.vol. ()", Strings.VName_Error), Quantity.Error, ItemCategory.MeterResult, (w,t,u,f,p) => (w.GetMeterTestRslt(t, CompoundMeterId.HeatMeterVolume) != null) ? FormatDbl(u, f, p, "V2", w.GetMeterTestRslt(t, CompoundMeterId.HeatMeterVolume).Error) : string.Empty));
#endif
AllItems.Add(new WMeterRsltItemSpec(ItemID.Passed, Strings.Result, Quantity.Boolean, ItemCategory.MeterResult, (w,t,u,f,p) => string.IsNullOrEmpty(t) ? w.PassedColorStr(f)
: ((w.GetMeterTestRslt(t) == null) ? "" : w.GetMeterTestRslt(t).PassedColorStr(f))));
AllItems.Add(new WMeterRsltItemSpec(ItemID.ThreeState, "Three state result", Quantity.Enumerated, ItemCategory.MeterResult, (w,t,u,f,p) => FormatThreeState(f, w.ThreeStateFromTests())));
AllItems.Add(new WMeterRsltItemSpec(ItemID.RefFlowmeter, "Ref. flowmeter", Quantity.String, ItemCategory.TestResult, (w,t,u,f,p) => (w.GetTestRslt(t) != null) ? FormatStr(f, w.GetTestRslt(t).RefFlowmeter()) : string.Empty));
AllItems.Add(new WMeterRsltItemSpec(ItemID.Scale, "Scale", Quantity.String, ItemCategory.TestResult, (w,t,u,f,p) => (w.GetTestRslt(t) != null) ? FormatStr(f, w.GetTestRslt(t).Scale()) : string.Empty));
AllItems.Add(new WMeterRsltItemSpec(ItemID.Diverter, "Diverter", Quantity.String, ItemCategory.TestResult, (w,t,u,f,p) => (w.GetTestRslt(t) != null) ? FormatStr(f, w.GetTestRslt(t).Diverter()) : string.Empty));
AllItems.Add(new WMeterRsltItemSpec(ItemID.RegValve, "Reg. valve", Quantity.String, ItemCategory.TestResult, (w,t,u,f,p) => (w.GetTestRslt(t) != null) ? FormatStr(f, w.GetTestRslt(t).RegValve()) : string.Empty));
AllItems.Add(new WMeterRsltItemSpec(ItemID.ResultOrErrorFlags, "Winiki lub E", Quantity.String, ItemCategory.MeterResult,(w, t, u, f, p) => (w.GetMeterTestRslt(t) != null) ? FormatStr(f, w.GetMeterTestRslt(t).PassedOrErrorFlagsStr())
: FormatStr(f, w.PassedOrErrorFlagsStr()))); /// PL specific result
///
/// Water meter info
@ -463,8 +457,6 @@ namespace Results
AllItems.Add(new WMeterRsltItemSpec(ItemID.Prod_Q2CorrLR, "Prod iPerl Q2Corr LR", Quantity.Number, ItemCategory.MeterResult, (w,t,u,f,p) => FormatInt(f, w.ProdQ2CorrLR)));
#endif
AllItems.Add(new WMeterRsltItemSpec(ItemID.TestDone, Strings.Test_done + "()", Quantity.Boolean, ItemCategory.TestResult, (w,t,u,f,p) => FormatBool(f, (w.GetMeterTestRslt(t) != null) && w.GetMeterTestRslt(t).TestDone)));
AllItems.Add(new WMeterRsltItemSpec(ItemID.TestPassed, Strings.Test_passed + "()", Quantity.Boolean, ItemCategory.TestResult, (w,t,u,f,p) => FormatBool(f, (w.GetMeterTestRslt(t) != null) && w.GetMeterTestRslt(t).Passed)));
AllItems.Add(new WMeterRsltItemSpec(ItemID.ErrorFlags, Strings.Error_flags + "()", Quantity.String, ItemCategory.TestResult, (w,t,u,f,p) => FormatStr(f, (w.GetTestRslt(t) != null) ? w.GetTestRslt(t).ErrorFlagsStr() : w.ErrorFlagsStr())));
AllItems.Add(new WMeterRsltItemSpec(ItemID.ErrorFlagsEx, Strings.Error_flags + "Ex", Quantity.String, ItemCategory.MeterResult, (w,t,u,f,p) => FormatStr(f, w.ErrorFlagsStrEx())));
AllItems.Add(new WMeterRsltItemSpec(ItemID.InfoFlags, Strings.Info_flags + "()", Quantity.String, ItemCategory.TestResult, (w,t,u,f,p) => FormatStr(f, (w.GetTestRslt(t) != null) ? w.GetTestRslt(t).InfoFlagsStr() : w.InfoFlagsStr())));
@ -737,7 +729,7 @@ namespace Results
if (items[i].Format == null) items[i].Format = string.Empty;
if (items[i].Precision == null) items[i].Precision = string.Empty;
result[i] = string.Format("{0}~{1}~{2}~{3}~{4}~{5}~{6}~{7}",
result[i] = string.Format("{0}~{1}~{2}~{3}~{4}~{5}~{6}~{7}~{8}",
items[i].Uid,
items[i].Caption.Replace("~", "\n"),
items[i].TestID,
@ -745,7 +737,8 @@ namespace Results
items[i].Format.Replace("~", "\n"),
items[i].Precision,
items[i].Width,
items[i].Alignment);
items[i].Alignment,
items[i].Merge);
}
return result;
}
@ -757,101 +750,102 @@ namespace Results
/// <returns></returns>
public static IList<WMeterRsltItemSpec> FromStrArray(string[] strArray)
{
IList<WMeterRsltItemSpec> result = new List<WMeterRsltItemSpec>();
var result = new List<WMeterRsltItemSpec>();
if (strArray == null) return result;
if (strArray != null)
for (int i = 0; i < strArray.Length; i++)
{
for (int i = 0; i < strArray.Length; i++)
{
try
WMeterRsltItemSpec item = null;
try
{
if (!strArray[i].Contains("~"))
{
WMeterRsltItemSpec item;
///
/// Old style results item specification -> convert it
///
bool isItemCreated = false;
foreach (var it in AllItems)
{
if (strArray[i].Equals(it.OldUid))
{
item = it.Clone();
item.Caption = item.Name.Replace("()", "").Replace(" *", "");
item.Units = 0; /// use default units
item.Format = null; /// the same like format string "{0}"
item.Precision = null;
item.Width = 0; /// do not ad any extra spaces
item.Alignment = Alignment.Left;
isItemCreated = true;
break;
}
}
if (!isItemCreated)
{
item = GetItem(0);
item.Caption = "Prs.Err.";
item.Format = string.Format("Parse error: {0}", strArray[i]);
}
}
else
{
string[] field = strArray[i].Split(new char[] { '~' });
if (!strArray[i].Contains("~"))
{
///
/// Old style results item specification -> convert it
///
bool added = false;
foreach (var it in AllItems)
{
if (strArray[i].Equals(it.OldUid))
{
item = it.Clone();
item.Caption = item.Name.Replace("()", "").Replace(" *", "");
item.Units = 0; /// use default units
item.Format = null; /// the same like format string "{0}"
item.Precision = null;
item.Width = 0; /// do not ad any extra spaces
item.Alignment = Alignment.Left;
result.Add(item);
added = true;
break;
}
}
if (!added)
{
item = GetItem(0);
item.Caption = "Prs.Err.";
item.Format = string.Format("Parse error: {0}", strArray[i]);
result.Add(item);
}
}
else if ((item = GetItem(int.Parse(field[0]))) != null)
if (field.Length >= 8 && (item = GetItem(int.Parse(field[0]))) != null)
{
///
/// Load the new style results item specification
///
///
/// Load the new style results item specification
///
item.Caption = field[1].Replace("\n", "~");
item.TestID = field[2];
item.Units = 0;
for (Unit u = 0; u < Unit.Count; u++)
{
if (u.ToString().Equals(field[3])) { item.Units = u; break; }
}
item.Format = field[4].Replace("\n", "~");
item.Precision = field[5];
item.Width = int.Parse(field[6]);
item.Alignment = 0;
for (Alignment a = 0; a < Alignment.Count; a++)
{
if (a.ToString().Equals(field[7])) { item.Alignment = a; break; }
}
item.TestID = field[2];
item.Units = 0;
for (Unit u = 0; u < Unit.Count; u++)
{
if (u.ToString().Equals(field[3])) { item.Units = u; break; }
}
item.Format = field[4].Replace("\n", "~");
item.Precision = field[5];
item.Width = int.Parse(field[6]);
item.Alignment = 0;
for (Alignment a = 0; a < Alignment.Count; a++)
{
if (a.ToString().Equals(field[7])) { item.Alignment = a; break; }
}
result.Add(item);
}
bool merge;
if (field.Length >= 9 && bool.TryParse(field[8], out merge)) item.Merge = merge;
}
else
{
///
/// Create an item with parse error information
///
WMeterRsltItemSpec item2 = GetItem(0);
item2.Caption = "Prs.Err.";
item2.Format = string.Format("Parse error: {0}", strArray[i]);
result.Add(item2);
item = GetItem(0);
item.Caption = "Prs.Err.";
item.Format = string.Format("Parse error: {0}", strArray[i]);
}
}
catch
{
WMeterRsltItemSpec item = GetItem(0);
item.Caption = "Prs.Err.";
item.Format = string.Format("Parse error: {0}", strArray[i]);
result.Add(item);
}
}
}
catch
{
item = GetItem(0);
item.Caption = "Prs.Err.";
item.Format = string.Format("Parse error: {0}", strArray[i]);
}
}
return result;
result.Add(item);
}
return result;
}
public static WMeterRsltItemSpec GetItem(int uid)
{
foreach (var item in AllItems)
{
if (item.Uid == uid) return item.Clone();
}
return null;
var foundItem = AllItems.FirstOrDefault(x => x.Uid == uid);
return (foundItem != null) ? foundItem.Clone() : null;
}