2019-12-19 07:23:58 +00:00
|
|
|
|
///
|
|
|
|
|
|
/// Copyright (c) 2019 Sensus Slovensko a.s.
|
|
|
|
|
|
///
|
|
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
2021-09-23 09:46:40 +00:00
|
|
|
|
using Common;
|
2019-12-19 07:23:58 +00:00
|
|
|
|
using Config;
|
|
|
|
|
|
using Results.Entities;
|
|
|
|
|
|
using Results.Resources;
|
|
|
|
|
|
using System.Globalization;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Results
|
|
|
|
|
|
{
|
|
|
|
|
|
public class ManualEntryItemSpec
|
|
|
|
|
|
{
|
|
|
|
|
|
///
|
|
|
|
|
|
/// Public fields
|
|
|
|
|
|
///
|
|
|
|
|
|
public readonly int Uid;
|
|
|
|
|
|
public readonly string Name; /// Name-s of all items must be unique
|
|
|
|
|
|
public readonly string ToolTipText; /// Tool-Tip Text
|
|
|
|
|
|
public readonly Quantity Quantity; /// Quantity
|
|
|
|
|
|
public readonly ItemCategory Category; ///
|
|
|
|
|
|
public string Caption; /// Specifies item description to be printed as a caption (in the header, etc.)
|
2022-01-23 18:56:15 +00:00
|
|
|
|
public Unit Units; /// Specifies units for the output
|
2019-12-19 07:23:58 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public ManualEntryItemSpec Clone()
|
|
|
|
|
|
{
|
|
|
|
|
|
ManualEntryItemSpec item = new ManualEntryItemSpec((ItemID)Uid, Name, ToolTipText, Quantity, Category, updateDlgt);
|
|
|
|
|
|
item.Caption = Caption;
|
|
|
|
|
|
item.Units = Units;
|
|
|
|
|
|
return item;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
///
|
|
|
|
|
|
/// Function to pick a MeterTestResult field and convert it into a string
|
|
|
|
|
|
///
|
|
|
|
|
|
public delegate bool UpdateDlgt(string str, MeterTestRslt meterTestRslt);
|
|
|
|
|
|
|
|
|
|
|
|
private readonly UpdateDlgt updateDlgt;
|
|
|
|
|
|
|
|
|
|
|
|
public bool Update(string str, MeterTestRslt meterTestRslt)
|
|
|
|
|
|
{
|
|
|
|
|
|
return (updateDlgt != null) ? updateDlgt(str, meterTestRslt) : true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static bool ParseBool(string str, out bool success)
|
|
|
|
|
|
{
|
|
|
|
|
|
bool b;
|
|
|
|
|
|
success = bool.TryParse(str, out b);
|
|
|
|
|
|
return b;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static int ParseInt(string str, out bool success)
|
|
|
|
|
|
{
|
|
|
|
|
|
int i;
|
|
|
|
|
|
success = int.TryParse(str, out i);
|
|
|
|
|
|
return i;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static float ParseFloat(string str, out bool success)
|
|
|
|
|
|
{
|
|
|
|
|
|
float f;
|
|
|
|
|
|
success = float.TryParse(str, NumberStyles.AllowDecimalPoint, CultureInfo.CurrentCulture, out f) ||
|
|
|
|
|
|
float.TryParse(str, NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out f);
|
|
|
|
|
|
return f;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static double ParseDouble(string str, out bool success)
|
|
|
|
|
|
{
|
|
|
|
|
|
double d;
|
|
|
|
|
|
success = double.TryParse(str, NumberStyles.AllowDecimalPoint, CultureInfo.CurrentCulture, out d) ||
|
|
|
|
|
|
double.TryParse(str, NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out d);
|
|
|
|
|
|
return d;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
///
|
|
|
|
|
|
/// Public constructor
|
|
|
|
|
|
///
|
|
|
|
|
|
public ManualEntryItemSpec(ItemID itemId, string name, string toolTipText, Quantity quantity, ItemCategory category, UpdateDlgt updateDlgt)
|
|
|
|
|
|
{
|
|
|
|
|
|
Uid = (int)itemId;
|
|
|
|
|
|
Name = name;
|
|
|
|
|
|
ToolTipText = toolTipText;
|
|
|
|
|
|
Quantity = quantity;
|
|
|
|
|
|
Category = category;
|
|
|
|
|
|
this.updateDlgt = updateDlgt;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// Static list of all available items
|
|
|
|
|
|
public static readonly IList<ManualEntryItemSpec> AllItems;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Initializes the <see cref="ManualEntryItemSpec"/> class.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// Static constructor that initializes the list of all items
|
|
|
|
|
|
static ManualEntryItemSpec()
|
|
|
|
|
|
{
|
|
|
|
|
|
AllItems = new List<ManualEntryItemSpec>();
|
|
|
|
|
|
|
|
|
|
|
|
AllItems.Add(new ManualEntryItemSpec(ItemID.P_PMax_test_mean,
|
|
|
|
|
|
string.Format("{0} PMax mean", Strings.VName_Press),
|
|
|
|
|
|
"PMax test pressure",
|
|
|
|
|
|
Quantity.Pressure,
|
|
|
|
|
|
ItemCategory.TestResult,
|
|
|
|
|
|
(str, mtr) => { bool r;
|
|
|
|
|
|
mtr.TestRslt.PressUpMean = mtr.TestRslt.PressDownMean = ParseFloat(str, out r);
|
|
|
|
|
|
return r; }));
|
|
|
|
|
|
AllItems.Add(new ManualEntryItemSpec(ItemID.T_line_mean,
|
|
|
|
|
|
string.Format("{0} LN ME", Strings.VName_Temp),
|
|
|
|
|
|
Strings.Tooltip_T_ln_me,
|
|
|
|
|
|
Quantity.Temperature,
|
|
|
|
|
|
ItemCategory.TestResult,
|
|
|
|
|
|
(str, mtr) => { bool r;
|
|
|
|
|
|
mtr.TestRslt.TempUpMean = mtr.TestRslt.TempDownMean = ParseFloat(str, out r);
|
|
|
|
|
|
return r; }));
|
|
|
|
|
|
AllItems.Add(new ManualEntryItemSpec(ItemID.Test_time,
|
|
|
|
|
|
Strings.T_s,
|
|
|
|
|
|
"Test time",
|
|
|
|
|
|
Quantity.Time,
|
2020-01-07 10:05:31 +00:00
|
|
|
|
ItemCategory.MeterResult,
|
|
|
|
|
|
(str, mtr) => { bool r;
|
|
|
|
|
|
mtr.TestTime = ParseDouble(str, out r);
|
|
|
|
|
|
return r; }));
|
|
|
|
|
|
AllItems.Add(new ManualEntryItemSpec(ItemID.PMax_test_time,
|
|
|
|
|
|
"Pressure test time",
|
|
|
|
|
|
"Pressure test time",
|
|
|
|
|
|
Quantity.Time,
|
|
|
|
|
|
ItemCategory.MeterResult,
|
2019-12-19 07:23:58 +00:00
|
|
|
|
(str, mtr) => { bool r;
|
2020-01-07 10:05:31 +00:00
|
|
|
|
mtr.TestTime = ParseDouble(str, out r);
|
2019-12-19 07:23:58 +00:00
|
|
|
|
return r; }));
|
|
|
|
|
|
AllItems.Add(new ManualEntryItemSpec(ItemID.TestPassed,
|
|
|
|
|
|
Strings.Test_passed,
|
|
|
|
|
|
"Passed",
|
|
|
|
|
|
Quantity.Boolean,
|
|
|
|
|
|
ItemCategory.MeterResult,
|
|
|
|
|
|
(str, mtr) => { bool r;
|
|
|
|
|
|
mtr.Passed = ParseBool(str, out r);
|
|
|
|
|
|
return r; }));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Converts a list of 'Output item specifications' to a string array
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="items"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public static string[] ToStrArray(IList<ManualEntryItemSpec> items)
|
|
|
|
|
|
{
|
|
|
|
|
|
int count = (items != null) ? items.Count : 0;
|
|
|
|
|
|
string[] result = new string[count];
|
|
|
|
|
|
for (int i = 0; i < count; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (items[i].Caption == null) items[i].Caption = string.Empty;
|
|
|
|
|
|
|
|
|
|
|
|
result[i] = string.Format("{0}~{1}~{2}",
|
|
|
|
|
|
items[i].Uid,
|
|
|
|
|
|
items[i].Caption.Replace("~", "\n"),
|
|
|
|
|
|
items[i].Units);
|
|
|
|
|
|
}
|
|
|
|
|
|
return result;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Converts a string array to a list of 'Output item specifications'
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="strArray"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public static IList<ManualEntryItemSpec> FromStrArray(string[] strArray)
|
|
|
|
|
|
{
|
|
|
|
|
|
IList<ManualEntryItemSpec> result = new List<ManualEntryItemSpec>();
|
|
|
|
|
|
|
|
|
|
|
|
if (strArray != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
for (int i = 0; i < strArray.Length; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
ManualEntryItemSpec item;
|
|
|
|
|
|
string[] field = strArray[i].Split(new char[] { '~' });
|
|
|
|
|
|
|
|
|
|
|
|
if (!strArray[i].Contains("~"))
|
|
|
|
|
|
{
|
|
|
|
|
|
item = GetItem(0);
|
|
|
|
|
|
item.Caption = "Prs.Err.";
|
|
|
|
|
|
result.Add(item);
|
|
|
|
|
|
}
|
|
|
|
|
|
else if ((item = GetItem(int.Parse(field[0]))) != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
///
|
|
|
|
|
|
/// Load the new style results item specification
|
|
|
|
|
|
///
|
|
|
|
|
|
item.Caption = field[1].Replace("\n", "~");
|
|
|
|
|
|
item.Units = 0;
|
2022-01-23 18:56:15 +00:00
|
|
|
|
for (Unit u = 0; u < Unit.Count; u++)
|
2019-12-19 07:23:58 +00:00
|
|
|
|
{
|
|
|
|
|
|
if (u.ToString().Equals(field[2])) { item.Units = u; break; }
|
|
|
|
|
|
}
|
|
|
|
|
|
result.Add(item);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
///
|
|
|
|
|
|
/// Create an item with parse error information
|
|
|
|
|
|
///
|
|
|
|
|
|
ManualEntryItemSpec item2 = GetItem(0);
|
|
|
|
|
|
item2.Caption = "Prs.Err.";
|
|
|
|
|
|
result.Add(item2);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
catch
|
|
|
|
|
|
{
|
|
|
|
|
|
ManualEntryItemSpec item = GetItem(0);
|
|
|
|
|
|
item.Caption = "Prs.Err.";
|
|
|
|
|
|
result.Add(item);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return result;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static ManualEntryItemSpec GetItem(int uid)
|
|
|
|
|
|
{
|
|
|
|
|
|
foreach (var item in AllItems)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (item.Uid == uid) return item.Clone();
|
|
|
|
|
|
}
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static ManualEntryItemSpec GetItem(ItemID itemId)
|
|
|
|
|
|
{
|
|
|
|
|
|
return GetItem((int)itemId);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override string ToString()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!string.IsNullOrEmpty(Caption))
|
|
|
|
|
|
return Caption;
|
|
|
|
|
|
else
|
|
|
|
|
|
return ((ItemID)Uid).ToString();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|