diff --git a/Common/IMeasurementCorrection.cs b/Common/IMeasurementCorrection.cs
index 41c92da54..14d22e492 100644
--- a/Common/IMeasurementCorrection.cs
+++ b/Common/IMeasurementCorrection.cs
@@ -5,7 +5,7 @@ namespace Common
public interface IMeasurementCorrection
{
int RangeIx { get; set; }
- float Measurement { get; set; }
- float Correction { get; set; }
+ double Measurement { get; set; }
+ double Correction { get; set; }
}
}
diff --git a/Common/Utils.cs b/Common/Utils.cs
index 995e64cab..96797c54e 100644
--- a/Common/Utils.cs
+++ b/Common/Utils.cs
@@ -1,8 +1,7 @@
///
-/// Copyright (c) 2021 Sensus Slovensko a.s.
+/// Copyright (c) 2021-2022 Sensus Slovensko a.s.
///
using System;
-using System.IO.Ports;
namespace Common
{
@@ -15,32 +14,83 @@ namespace Common
return string.Format("{0} ({1}/{2})", name, repetitionNr, repeats);
}
- public static Parity GetParity(string str, Parity defaultParity = Parity.None)
+ public static string ToNiceString(double value, int sigDigits)
{
- if (str.Equals(Parity.None.ToString())) return Parity.None;
- if (str.Equals(Parity.Even.ToString())) return Parity.Even;
- if (str.Equals(Parity.Odd.ToString())) return Parity.Odd;
- if (str.Equals(Parity.Mark.ToString())) return Parity.Mark;
- if (str.Equals(Parity.Space.ToString())) return Parity.Space;
- return defaultParity;
+ string format = SignificantDigitsToFmt(value, sigDigits);
+ return (format == "F0") ? value.ToString("F0") : value.ToString(format).TrimEnd(new char[] { '0' });
}
- public static StopBits GetStopBits(string str, StopBits defaultStopBits = StopBits.One)
+ public static string SignificantDigitsToFmt(double value, int sigDigits)
{
- if (str.Equals(StopBits.None.ToString())) return StopBits.None;
- if (str.Equals(StopBits.One.ToString())) return StopBits.One;
- if (str.Equals(StopBits.OnePointFive.ToString())) return StopBits.OnePointFive;
- if (str.Equals(StopBits.Two.ToString())) return StopBits.Two;
- return defaultStopBits;
- }
-
- public static Handshake GetHandshake(string str, Handshake defaultHandshake = Handshake.None)
- {
- if (str.Equals(Handshake.None.ToString())) return Handshake.None;
- if (str.Equals(Handshake.RequestToSend.ToString())) return Handshake.RequestToSend;
- if (str.Equals(Handshake.XOnXOff.ToString())) return Handshake.XOnXOff;
- if (str.Equals(Handshake.RequestToSendXOnXOff.ToString())) return Handshake.RequestToSendXOnXOff;
- return defaultHandshake;
+ if (sigDigits == 6)
+ {
+ if (value >= 99999.5 || value < -99999.5) return "F0";
+ else if (value >= 9999.95 || value < -9999.95) return "F1";
+ else if (value >= 999.995 || value < -999.995) return "F2";
+ else if (value >= 99.9995 || value < -99.9995) return "F3";
+ else if (value >= 9.99995 || value < -9.99995) return "F4";
+ else if (value >= 0.999995 || value < -0.999995) return "F5";
+ else if (value >= 0.0999995 || value < -0.0999995) return "F6";
+ else if (value >= 0.00999995 || value < -0.00999995) return "F7";
+ else if (value >= 0.000999995 || value < -0.000999995) return "F8";
+ else if (value >= 0.0000999995 || value < -0.0000999995) return "F9";
+ else return "F10";
+ }
+ else if (sigDigits == 5)
+ {
+ if (value >= 9999.5 || value < -9999.5) return "F0";
+ else if (value >= 999.95 || value < -999.95) return "F1";
+ else if (value >= 99.995 || value < -99.995) return "F2";
+ else if (value >= 9.9995 || value < -9.9995) return "F3";
+ else if (value >= 0.99995 || value < -0.99995) return "F4";
+ else if (value >= 0.099995 || value < -0.099995) return "F5";
+ else if (value >= 0.0099995 || value < -0.0099995) return "F6";
+ else if (value >= 0.00099995 || value < -0.00099995) return "F7";
+ else if (value >= 0.000099995 || value < -0.000099995) return "F8";
+ else return "F9";
+ }
+ else if (sigDigits == 4)
+ {
+ if (value >= 999.5 || value < -999.5) return "F0";
+ else if (value >= 99.95 || value < -99.95) return "F1";
+ else if (value >= 9.995 || value < -9.995) return "F2";
+ else if (value >= 0.9995 || value < -0.9995) return "F3";
+ else if (value >= 0.09995 || value < -0.09995) return "F4";
+ else if (value >= 0.009995 || value < -0.009995) return "F5";
+ else if (value >= 0.0009995 || value < -0.0009995) return "F6";
+ else if (value >= 0.00009995 || value < -0.00009995) return "F7";
+ else return "F8";
+ }
+ else if (sigDigits == 3)
+ {
+ if (value >= 99.5 || value < -99.5) return "F0";
+ else if (value >= 9.95 || value < -9.95) return "F1";
+ else if (value >= 0.995 || value < -0.995) return "F2";
+ else if (value >= 0.0995 || value < -0.0995) return "F3";
+ else if (value >= 0.00995 || value < -0.00995) return "F4";
+ else if (value >= 0.000995 || value < -0.000995) return "F5";
+ else if (value >= 0.0000995 || value < -0.0000995) return "F6";
+ else return "F7";
+ }
+ else if (sigDigits == 2)
+ {
+ if (value >= 9.5 || value < -9.5) return "F0";
+ else if (value >= 0.95 || value < -0.95) return "F1";
+ else if (value >= 0.095 || value < -0.095) return "F2";
+ else if (value >= 0.0095 || value < -0.0095) return "F3";
+ else if (value >= 0.00095 || value < -0.00095) return "F4";
+ else if (value >= 0.000095 || value < -0.000095) return "F5";
+ else return "F6";
+ }
+ else /// if (sigDigits == 1)
+ {
+ if (value >= 0.95 || value < -0.95) return "F0";
+ else if (value >= 0.095 || value < -0.095) return "F1";
+ else if (value >= 0.0095 || value < -0.0095) return "F2";
+ else if (value >= 0.00095 || value < -0.00095) return "F3";
+ else if (value >= 0.000095 || value < -0.000095) return "F4";
+ else return "F5";
+ }
}
}
}
diff --git a/Config/Entities/MeasurementCorrection.cs b/Config/Entities/MeasurementCorrection.cs
index 11ea46195..a43a58f12 100644
--- a/Config/Entities/MeasurementCorrection.cs
+++ b/Config/Entities/MeasurementCorrection.cs
@@ -1,5 +1,5 @@
///
-/// Copyright (c) 2013-2021 Sensus Slovensko a.s.
+/// Copyright (c) 2013-2022 Sensus Slovensko a.s.
///
using System;
using System.Collections.Generic;
@@ -10,8 +10,8 @@ namespace Config.Entities
{
public virtual int Id { get; protected set; }
public virtual int RangeIx { get; set; } /// 0..5
- public virtual float Measurement { get; set; }
- public virtual float Correction { get; set; }
+ public virtual double Measurement { get; set; }
+ public virtual double Correction { get; set; }
public MeasurementCorrection()
{
diff --git a/Config/Utils.cs b/Config/Utils.cs
index 248fc8092..4855b11cc 100644
--- a/Config/Utils.cs
+++ b/Config/Utils.cs
@@ -1,5 +1,5 @@
///
-/// Copyright (c) 2017-2018 Sensus Slovensko a.s.
+/// Copyright (c) 2017-2022 Sensus Slovensko a.s.
///
using System;
using System.Collections.Generic;
@@ -11,80 +11,6 @@ namespace Config
{
public static class Utils
{
- public static string SignificantDigitsToFmt(double value, int sigDigits)
- {
- if (sigDigits == 6)
- {
- if (value >= 99999.5 || value < -99999.5) return "F0";
- else if (value >= 9999.95 || value < -9999.95) return "F1";
- else if (value >= 999.995 || value < -999.995) return "F2";
- else if (value >= 99.9995 || value < -99.9995) return "F3";
- else if (value >= 9.99995 || value < -9.99995) return "F4";
- else if (value >= 0.999995 || value < -0.999995) return "F5";
- else if (value >= 0.0999995 || value < -0.0999995) return "F6";
- else if (value >= 0.00999995 || value < -0.00999995) return "F7";
- else if (value >= 0.000999995 || value < -0.000999995) return "F8";
- else if (value >= 0.0000999995 || value < -0.0000999995) return "F9";
- else return "F10";
- }
- else if (sigDigits == 5)
- {
- if (value >= 9999.5 || value < -9999.5) return "F0";
- else if (value >= 999.95 || value < -999.95) return "F1";
- else if (value >= 99.995 || value < -99.995) return "F2";
- else if (value >= 9.9995 || value < -9.9995) return "F3";
- else if (value >= 0.99995 || value < -0.99995) return "F4";
- else if (value >= 0.099995 || value < -0.099995) return "F5";
- else if (value >= 0.0099995 || value < -0.0099995) return "F6";
- else if (value >= 0.00099995 || value < -0.00099995) return "F7";
- else if (value >= 0.000099995 || value < -0.000099995) return "F8";
- else return "F9";
- }
- else if (sigDigits == 4)
- {
- if (value >= 999.5 || value < -999.5) return "F0";
- else if (value >= 99.95 || value < -99.95) return "F1";
- else if (value >= 9.995 || value < -9.995) return "F2";
- else if (value >= 0.9995 || value < -0.9995) return "F3";
- else if (value >= 0.09995 || value < -0.09995) return "F4";
- else if (value >= 0.009995 || value < -0.009995) return "F5";
- else if (value >= 0.0009995 || value < -0.0009995) return "F6";
- else if (value >= 0.00009995 || value < -0.00009995) return "F7";
- else return "F8";
- }
- else if (sigDigits == 3)
- {
- if (value >= 99.5 || value < -99.5) return "F0";
- else if (value >= 9.95 || value < -9.95) return "F1";
- else if (value >= 0.995 || value < -0.995) return "F2";
- else if (value >= 0.0995 || value < -0.0995) return "F3";
- else if (value >= 0.00995 || value < -0.00995) return "F4";
- else if (value >= 0.000995 || value < -0.000995) return "F5";
- else if (value >= 0.0000995 || value < -0.0000995) return "F6";
- else return "F7";
- }
- else if (sigDigits == 2)
- {
- if (value >= 9.5 || value < -9.5) return "F0";
- else if (value >= 0.95 || value < -0.95) return "F1";
- else if (value >= 0.095 || value < -0.095) return "F2";
- else if (value >= 0.0095 || value < -0.0095) return "F3";
- else if (value >= 0.00095 || value < -0.00095) return "F4";
- else if (value >= 0.000095 || value < -0.000095) return "F5";
- else return "F6";
- }
- else /// if (sigDigits == 1)
- {
- if (value >= 0.95 || value < -0.95) return "F0";
- else if (value >= 0.095 || value < -0.095) return "F1";
- else if (value >= 0.0095 || value < -0.0095) return "F2";
- else if (value >= 0.00095 || value < -0.00095) return "F3";
- else if (value >= 0.000095 || value < -0.000095) return "F4";
- else return "F5";
- }
- }
-
-
///
/// Extract and return a DB server from a MySQL connection string.
///
diff --git a/Results/WMeterRsltItemSpec.cs b/Results/WMeterRsltItemSpec.cs
index 9d4bc64c0..a3700dcf3 100644
--- a/Results/WMeterRsltItemSpec.cs
+++ b/Results/WMeterRsltItemSpec.cs
@@ -1,5 +1,5 @@
///
-/// Copyright (c) 2013-2018 Sensus Slovensko a.s.
+/// Copyright (c) 2013-2022 Sensus Slovensko a.s.
///
using System;
using System.Collections.Generic;
@@ -677,7 +677,7 @@ namespace Results
int significantDigits;
if (int.TryParse(precision.Substring(1), out significantDigits))
{
- precision = Config.Utils.SignificantDigitsToFmt(val, significantDigits);
+ precision = Common.Utils.SignificantDigitsToFmt(val, significantDigits);
}
}
@@ -715,7 +715,7 @@ namespace Results
int significantDigits;
if (int.TryParse(precision.Substring(1), out significantDigits))
{
- precision = Config.Utils.SignificantDigitsToFmt(val1, significantDigits);
+ precision = Common.Utils.SignificantDigitsToFmt(val1, significantDigits);
}
}
diff --git a/TBF/Properties/AssemblyInfo.cs b/TBF/Properties/AssemblyInfo.cs
index d851f9749..6b1ec7de8 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.28.1925.0")]
-[assembly: AssemblyFileVersion("2.28.1925.0")]
+[assembly: AssemblyVersion("2.29.1926.0")]
+[assembly: AssemblyFileVersion("2.29.1926.0")]
diff --git a/TBF/Rig/Ambient/Comet/AmbientCfgCtrl.cs b/TBF/Rig/Ambient/Comet/AmbientCfgCtrl.cs
index 6ca3129c3..70c029d9c 100644
--- a/TBF/Rig/Ambient/Comet/AmbientCfgCtrl.cs
+++ b/TBF/Rig/Ambient/Comet/AmbientCfgCtrl.cs
@@ -88,10 +88,10 @@ namespace TBF.Rig.Ambient.Comet
config.Name = nameTextBox.Text;
config.ComPortNr = int.Parse(comPortNrTextBox.Text);
config.BaudRate = int.Parse(baudRateTextBox.Text);
- config.Parity = Common.Utils.GetParity(parityComboBox.SelectedItem.ToString());
+ config.Parity = Utils.GetParity(parityComboBox.SelectedItem.ToString());
config.DataBits = int.Parse(dataBitsTextBox.Text);
- config.StopBits = Common.Utils.GetStopBits(stopBitsComboBox.SelectedItem.ToString());
- config.Handshake = Common.Utils.GetHandshake(handshakeComboBox.SelectedItem.ToString());
+ config.StopBits = Utils.GetStopBits(stopBitsComboBox.SelectedItem.ToString());
+ config.Handshake = Utils.GetHandshake(handshakeComboBox.SelectedItem.ToString());
config.SetDtrToOne = setDtrCheckBox.Checked;
return flags;
diff --git a/TBF/Rig/Ambient/Greco/AmbientCfgCtrl.cs b/TBF/Rig/Ambient/Greco/AmbientCfgCtrl.cs
index 1fd8354d6..ff13c0620 100644
--- a/TBF/Rig/Ambient/Greco/AmbientCfgCtrl.cs
+++ b/TBF/Rig/Ambient/Greco/AmbientCfgCtrl.cs
@@ -86,10 +86,10 @@ namespace TBF.Rig.Ambient.Greco
config.Name = nameTextBox.Text;
config.ComPortNr = int.Parse(comPortNrTextBox.Text);
config.BaudRate = int.Parse(baudRateTextBox.Text);
- config.Parity = Common.Utils.GetParity(parityComboBox.SelectedItem.ToString());
+ config.Parity = Utils.GetParity(parityComboBox.SelectedItem.ToString());
config.DataBits = int.Parse(dataBitsTextBox.Text);
- config.StopBits = Common.Utils.GetStopBits(stopBitsComboBox.SelectedItem.ToString());
- config.Handshake = Common.Utils.GetHandshake(handshakeComboBox.SelectedItem.ToString());
+ config.StopBits = Utils.GetStopBits(stopBitsComboBox.SelectedItem.ToString());
+ config.Handshake = Utils.GetHandshake(handshakeComboBox.SelectedItem.ToString());
return flags;
}
diff --git a/TBF/Rig/Danfoss/VLT2800/PumpCfgCtrl.cs b/TBF/Rig/Danfoss/VLT2800/PumpCfgCtrl.cs
index f1a7c4692..00afe824a 100644
--- a/TBF/Rig/Danfoss/VLT2800/PumpCfgCtrl.cs
+++ b/TBF/Rig/Danfoss/VLT2800/PumpCfgCtrl.cs
@@ -96,9 +96,9 @@ namespace TBF.Rig.Danfoss.VLT2800
config.BusAddress = int.Parse(busAddressTextBox.Text);
config.ComPortNr = int.Parse(comPortNrTextBox.Text);
config.BaudRate = int.Parse(baudRateTextBox.Text);
- config.Parity = Common.Utils.GetParity(parityComboBox.SelectedItem.ToString());
+ config.Parity = Utils.GetParity(parityComboBox.SelectedItem.ToString());
config.DataBits = int.Parse(dataBitsTextBox.Text);
- config.StopBits = Common.Utils.GetStopBits(stopBitsComboBox.SelectedItem.ToString());
+ config.StopBits = Utils.GetStopBits(stopBitsComboBox.SelectedItem.ToString());
return flags;
}
diff --git a/TBF/Rig/Keithley/Multimeter_2010_RS232/MultimeterCfgCtrl.cs b/TBF/Rig/Keithley/Multimeter_2010_RS232/MultimeterCfgCtrl.cs
index 692b8d268..43ac6d65b 100644
--- a/TBF/Rig/Keithley/Multimeter_2010_RS232/MultimeterCfgCtrl.cs
+++ b/TBF/Rig/Keithley/Multimeter_2010_RS232/MultimeterCfgCtrl.cs
@@ -88,10 +88,10 @@ namespace TBF.Rig.Keithley.Multimeter_2010_RS232
config.Name = nameTextBox.Text;
config.ComPortNr = int.Parse(comPortNrTextBox.Text);
config.BaudRate = int.Parse(baudRateTextBox.Text);
- config.Parity = Common.Utils.GetParity(parityComboBox.SelectedItem.ToString());
+ config.Parity = Utils.GetParity(parityComboBox.SelectedItem.ToString());
config.DataBits = int.Parse(dataBitsTextBox.Text);
- config.StopBits = Common.Utils.GetStopBits(stopBitsComboBox.SelectedItem.ToString());
- config.Handshake = Common.Utils.GetHandshake(handshakeComboBox.SelectedItem.ToString());
+ config.StopBits = Utils.GetStopBits(stopBitsComboBox.SelectedItem.ToString());
+ config.Handshake = Utils.GetHandshake(handshakeComboBox.SelectedItem.ToString());
return flags;
}
diff --git a/TBF/Rig/MettlerToledo/Multi/BalanceCfgCtrl.cs b/TBF/Rig/MettlerToledo/Multi/BalanceCfgCtrl.cs
index 19eda155c..bd3cb3bfc 100644
--- a/TBF/Rig/MettlerToledo/Multi/BalanceCfgCtrl.cs
+++ b/TBF/Rig/MettlerToledo/Multi/BalanceCfgCtrl.cs
@@ -200,10 +200,10 @@ namespace TBF.Rig.MettlerToledo.Multi
{
config.ComPortNr = int.Parse(comPortNrTextBox.Text);
config.BaudRate = int.Parse(baudRateTextBox.Text);
- config.Parity = Common.Utils.GetParity(parityComboBox.SelectedItem.ToString());
+ config.Parity = Utils.GetParity(parityComboBox.SelectedItem.ToString());
config.DataBits = int.Parse(dataBitsTextBox.Text);
- config.StopBits = Common.Utils.GetStopBits(stopBitsComboBox.SelectedItem.ToString());
- config.Handshake = Common.Utils.GetHandshake(handshakeComboBox.SelectedItem.ToString());
+ config.StopBits = Utils.GetStopBits(stopBitsComboBox.SelectedItem.ToString());
+ config.Handshake = Utils.GetHandshake(handshakeComboBox.SelectedItem.ToString());
}
return flags;
diff --git a/TBF/Rig/MettlerToledo/Standard/BalanceCfgCtrl.cs b/TBF/Rig/MettlerToledo/Standard/BalanceCfgCtrl.cs
index becba0879..325209aa5 100644
--- a/TBF/Rig/MettlerToledo/Standard/BalanceCfgCtrl.cs
+++ b/TBF/Rig/MettlerToledo/Standard/BalanceCfgCtrl.cs
@@ -214,10 +214,10 @@ namespace TBF.Rig.MettlerToledo.Standard
config.ComPortNr = int.Parse(comPortNrTextBox.Text);
config.BaudRate = int.Parse(baudRateTextBox.Text);
- config.Parity = Common.Utils.GetParity(parityComboBox.SelectedItem.ToString());
+ config.Parity = Utils.GetParity(parityComboBox.SelectedItem.ToString());
config.DataBits = int.Parse(dataBitsTextBox.Text);
- config.StopBits = Common.Utils.GetStopBits(stopBitsComboBox.SelectedItem.ToString());
- config.Handshake = Common.Utils.GetHandshake(handshakeComboBox.SelectedItem.ToString());
+ config.StopBits = Utils.GetStopBits(stopBitsComboBox.SelectedItem.ToString());
+ config.Handshake = Utils.GetHandshake(handshakeComboBox.SelectedItem.ToString());
return flags;
}
diff --git a/TBF/Rig/Modbus/Common/ModbusCfgCtrl.cs b/TBF/Rig/Modbus/Common/ModbusCfgCtrl.cs
index fd9e7ef00..d564f6c12 100644
--- a/TBF/Rig/Modbus/Common/ModbusCfgCtrl.cs
+++ b/TBF/Rig/Modbus/Common/ModbusCfgCtrl.cs
@@ -88,10 +88,10 @@ namespace TBF.Rig.Modbus.Common
config.Name = nameTextBox.Text;
config.ComPortNr = int.Parse(comPortNrTextBox.Text);
config.BaudRate = int.Parse(baudRateTextBox.Text);
- config.Parity = global::Common.Utils.GetParity(parityComboBox.SelectedItem.ToString());
+ config.Parity = Utils.GetParity(parityComboBox.SelectedItem.ToString());
config.DataBits = int.Parse(dataBitsTextBox.Text);
- config.StopBits = global::Common.Utils.GetStopBits(stopBitsComboBox.SelectedItem.ToString());
- config.Handshake = global::Common.Utils.GetHandshake(handshakeComboBox.SelectedItem.ToString());
+ config.StopBits = Utils.GetStopBits(stopBitsComboBox.SelectedItem.ToString());
+ config.Handshake = Utils.GetHandshake(handshakeComboBox.SelectedItem.ToString());
return flags;
}
diff --git a/TBF/Rig/RegisterReaders/KPackE/Radio/RadioCfgCtrl.cs b/TBF/Rig/RegisterReaders/KPackE/Radio/RadioCfgCtrl.cs
index 90a19c6d8..d8bf593f4 100644
--- a/TBF/Rig/RegisterReaders/KPackE/Radio/RadioCfgCtrl.cs
+++ b/TBF/Rig/RegisterReaders/KPackE/Radio/RadioCfgCtrl.cs
@@ -88,10 +88,10 @@ namespace TBF.Rig.RegisterReaders.KPackE.Radio
config.Name = nameTextBox.Text;
config.ComPortNr = int.Parse(comPortNrTextBox.Text);
config.BaudRate = int.Parse(baudRateTextBox.Text);
- config.Parity = Common.Utils.GetParity(parityComboBox.SelectedItem.ToString());
+ config.Parity = Utils.GetParity(parityComboBox.SelectedItem.ToString());
config.DataBits = int.Parse(dataBitsTextBox.Text);
- config.StopBits = Common.Utils.GetStopBits(stopBitsComboBox.SelectedItem.ToString());
- config.Handshake = Common.Utils.GetHandshake(handshakeComboBox.SelectedItem.ToString());
+ config.StopBits = Utils.GetStopBits(stopBitsComboBox.SelectedItem.ToString());
+ config.Handshake = Utils.GetHandshake(handshakeComboBox.SelectedItem.ToString());
return flags;
}
diff --git a/TBF/Rig/RegisterReaders/S640Stream/S640StreamCfg.cs b/TBF/Rig/RegisterReaders/S640Stream/S640StreamCfg.cs
index ec4e536af..e82c812fa 100644
--- a/TBF/Rig/RegisterReaders/S640Stream/S640StreamCfg.cs
+++ b/TBF/Rig/RegisterReaders/S640Stream/S640StreamCfg.cs
@@ -117,13 +117,13 @@ namespace TBF.Rig.RegisterReaders.S640Stream
{
switch (i)
{
- case 0: Position = int.Parse(str); return CfgUpdateFlags.RestartRqrd;
- case 1: ComPortNr = int.Parse(str); return CfgUpdateFlags.RestartRqrd;
- case 2: BaudRate = int.Parse(str); return CfgUpdateFlags.RestartRqrd;
- case 3: Parity = Common.Utils.GetParity(str); return CfgUpdateFlags.RestartRqrd;
- case 4: DataBits = int.Parse(str); return CfgUpdateFlags.RestartRqrd;
- case 5: StopBits = Common.Utils.GetStopBits(str); return CfgUpdateFlags.RestartRqrd;
- case 6: Handshake = Common.Utils.GetHandshake(str); return CfgUpdateFlags.RestartRqrd;
+ case 0: Position = int.Parse(str); return CfgUpdateFlags.RestartRqrd;
+ case 1: ComPortNr = int.Parse(str); return CfgUpdateFlags.RestartRqrd;
+ case 2: BaudRate = int.Parse(str); return CfgUpdateFlags.RestartRqrd;
+ case 3: Parity = Utils.GetParity(str); return CfgUpdateFlags.RestartRqrd;
+ case 4: DataBits = int.Parse(str); return CfgUpdateFlags.RestartRqrd;
+ case 5: StopBits = Utils.GetStopBits(str); return CfgUpdateFlags.RestartRqrd;
+ case 6: Handshake = Utils.GetHandshake(str); return CfgUpdateFlags.RestartRqrd;
default: return CfgUpdateFlags.None;
}
}
diff --git a/TBF/Rig/RegisterReaders/SerialStream/SerialStreamCfg.cs b/TBF/Rig/RegisterReaders/SerialStream/SerialStreamCfg.cs
index 601be0146..700be018e 100644
--- a/TBF/Rig/RegisterReaders/SerialStream/SerialStreamCfg.cs
+++ b/TBF/Rig/RegisterReaders/SerialStream/SerialStreamCfg.cs
@@ -121,12 +121,12 @@ namespace TBF.Rig.RegisterReaders.SerialStream
{
switch (i)
{
- case 0: ComPortNr = int.Parse(str); return CfgUpdateFlags.RestartRqrd;
- case 1: BaudRate = int.Parse(str); return CfgUpdateFlags.RestartRqrd;
- case 2: Parity = Common.Utils.GetParity(str); return CfgUpdateFlags.RestartRqrd;
- case 3: DataBits = int.Parse(str); return CfgUpdateFlags.RestartRqrd;
- case 4: StopBits = Common.Utils.GetStopBits(str); return CfgUpdateFlags.RestartRqrd;
- case 5: Handshake = Common.Utils.GetHandshake(str); return CfgUpdateFlags.RestartRqrd;
+ case 0: ComPortNr = int.Parse(str); return CfgUpdateFlags.RestartRqrd;
+ case 1: BaudRate = int.Parse(str); return CfgUpdateFlags.RestartRqrd;
+ case 2: Parity = Utils.GetParity(str); return CfgUpdateFlags.RestartRqrd;
+ case 3: DataBits = int.Parse(str); return CfgUpdateFlags.RestartRqrd;
+ case 4: StopBits = Utils.GetStopBits(str); return CfgUpdateFlags.RestartRqrd;
+ case 5: Handshake = Utils.GetHandshake(str); return CfgUpdateFlags.RestartRqrd;
default: return CfgUpdateFlags.None;
}
}
diff --git a/TBF/UI/Bench/Metrology/MetrologyDlgBalanceTab.Designer.cs b/TBF/UI/Bench/Metrology/MetrologyDlgBalanceTab.Designer.cs
index af7a12eb0..b493833b1 100644
--- a/TBF/UI/Bench/Metrology/MetrologyDlgBalanceTab.Designer.cs
+++ b/TBF/UI/Bench/Metrology/MetrologyDlgBalanceTab.Designer.cs
@@ -33,6 +33,8 @@ namespace TBF.UI.Bench.Metrology
{
this.cmpntNameLabel = new System.Windows.Forms.Label();
this.splitContainer1 = new System.Windows.Forms.SplitContainer();
+ this.unitLabel = new System.Windows.Forms.Label();
+ this.unitComboBox = new System.Windows.Forms.ComboBox();
this.calibrationGroupBox = new System.Windows.Forms.GroupBox();
this.calibExpirationDateTimePicker = new System.Windows.Forms.DateTimePicker();
this.calibDateTimePicker = new System.Windows.Forms.DateTimePicker();
@@ -87,6 +89,8 @@ namespace TBF.UI.Bench.Metrology
//
// splitContainer1.Panel1
//
+ this.splitContainer1.Panel1.Controls.Add(this.unitLabel);
+ this.splitContainer1.Panel1.Controls.Add(this.unitComboBox);
this.splitContainer1.Panel1.Controls.Add(this.calibrationGroupBox);
this.splitContainer1.Panel1.Controls.Add(this.buoancyGroupBox);
this.splitContainer1.Panel1.Controls.Add(this.nameGroupBox);
@@ -99,6 +103,24 @@ namespace TBF.UI.Bench.Metrology
this.splitContainer1.SplitterDistance = 150;
this.splitContainer1.TabIndex = 1;
//
+ // unitLabel
+ //
+ this.unitLabel.AutoSize = true;
+ this.unitLabel.Location = new System.Drawing.Point(507, 116);
+ this.unitLabel.Name = "unitLabel";
+ this.unitLabel.Size = new System.Drawing.Size(68, 13);
+ this.unitLabel.TabIndex = 12;
+ this.unitLabel.Text = "Unit of mass:";
+ //
+ // unitComboBox
+ //
+ this.unitComboBox.FormattingEnabled = true;
+ this.unitComboBox.Location = new System.Drawing.Point(592, 113);
+ this.unitComboBox.Name = "unitComboBox";
+ this.unitComboBox.Size = new System.Drawing.Size(62, 21);
+ this.unitComboBox.TabIndex = 11;
+ this.unitComboBox.SelectedIndexChanged += new System.EventHandler(this.unitComboBox_SelectedIndexChanged);
+ //
// calibrationGroupBox
//
this.calibrationGroupBox.Controls.Add(this.calibExpirationDateTimePicker);
@@ -315,7 +337,7 @@ namespace TBF.UI.Bench.Metrology
// correctedLabel
//
this.correctedLabel.AutoSize = true;
- this.correctedLabel.Location = new System.Drawing.Point(17, 40);
+ this.correctedLabel.Location = new System.Drawing.Point(11, 40);
this.correctedLabel.Name = "correctedLabel";
this.correctedLabel.Size = new System.Drawing.Size(53, 13);
this.correctedLabel.TabIndex = 3;
@@ -324,7 +346,7 @@ namespace TBF.UI.Bench.Metrology
// measuredLabel
//
this.measuredLabel.AutoSize = true;
- this.measuredLabel.Location = new System.Drawing.Point(17, 18);
+ this.measuredLabel.Location = new System.Drawing.Point(11, 18);
this.measuredLabel.Name = "measuredLabel";
this.measuredLabel.Size = new System.Drawing.Size(54, 13);
this.measuredLabel.TabIndex = 2;
@@ -354,6 +376,7 @@ namespace TBF.UI.Bench.Metrology
this.Size = new System.Drawing.Size(668, 400);
this.Load += new System.EventHandler(this.MetrologyDlgBalanceTab_Load);
this.splitContainer1.Panel1.ResumeLayout(false);
+ this.splitContainer1.Panel1.PerformLayout();
this.splitContainer1.Panel2.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).EndInit();
this.splitContainer1.ResumeLayout(false);
@@ -398,5 +421,7 @@ namespace TBF.UI.Bench.Metrology
private System.Windows.Forms.Label calibCertificateNrLabel;
private System.Windows.Forms.DateTimePicker calibExpirationDateTimePicker;
private System.Windows.Forms.DateTimePicker calibDateTimePicker;
+ private System.Windows.Forms.Label unitLabel;
+ private System.Windows.Forms.ComboBox unitComboBox;
}
}
diff --git a/TBF/UI/Bench/Metrology/MetrologyDlgBalanceTab.cs b/TBF/UI/Bench/Metrology/MetrologyDlgBalanceTab.cs
index 23a90dfdf..7c111c673 100644
--- a/TBF/UI/Bench/Metrology/MetrologyDlgBalanceTab.cs
+++ b/TBF/UI/Bench/Metrology/MetrologyDlgBalanceTab.cs
@@ -1,13 +1,14 @@
///
-/// Copyright (c) 2013-2020 Sensus Slovensko a.s.
+/// Copyright (c) 2013-2022 Sensus Slovensko a.s.
///
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Windows.Forms;
using log4net;
-using Config.Entities;
+using Common;
using Common.Forms;
+using Config.Entities;
using TBF.Resources;
using TBF.UI.Shared;
@@ -17,16 +18,19 @@ namespace TBF.UI.Bench.Metrology
{
static readonly ILog log = LogManager.GetLogger(typeof(MetrologyDlgBalanceTab));
+ public const Unit DefaultUnit = Unit.kg;
+ public const int SignifDigits = 5;
+
///
/// Component entity that has a list of 'measurement-correction' pairs
/// to be updated in the database on OK.
///
+ Component meterEntity;
public Component MeterEntity
{
get { return meterEntity; }
set { meterEntity = value; }
}
- Component meterEntity;
///
/// Balance configuration (with buoyancy parameters)
@@ -49,6 +53,8 @@ namespace TBF.UI.Bench.Metrology
Control correctionTextBox;
Control errorTextBox;
+ Unit currentUnit;
+
public MetrologyDlgBalanceTab()
{
InitializeComponent();
@@ -68,26 +74,41 @@ namespace TBF.UI.Bench.Metrology
Localize();
- /// Panel1
+ /// Panel1
cmpntNameLabel.Text = meterEntity.Name;
- measuredTextBox.Text = string.Empty;
- correctedTextBox.Text = string.Empty;
+
+ for (Unit u = 0; u < Unit.Count; u++)
+ if (Units.IsMass(u))
+ unitComboBox.Items.Add(u.ToDescription());
/// Panel2
this.Controls.Add(measurementTextBox = new TextBox());
this.Controls.Add(correctionTextBox = new TextBox());
this.Controls.Add(errorTextBox = new TextBox());
+ currentUnit = DefaultUnit;
+ unitComboBox.Text = currentUnit.ToDescription();
+ InitializeColumns(listViewEx, currentUnit);
+ RefreshAll();
+
listViewEx.SubItemClicked += new SubItemEventHandler(listViewEx_SubItemClicked);
listViewEx.SubItemEndEditing += new SubItemEndEditingEventHandler(listViewEx_SubItemEndEditing);
+ unitComboBox.SelectedIndexChanged += new System.EventHandler(unitComboBox_SelectedIndexChanged);
+ }
- listViewEx.Columns.Add(new ColumnHeader() { Text = Strings.Nr, Width = 60 });
- listViewEx.Columns.Add(new ColumnHeader() { Text = string.Format("{0} [kg]", Strings.Mass), Width = 100 });
- listViewEx.Columns.Add(new ColumnHeader() { Text = string.Format("{0} [g]", Strings.Correction), Width = 100 });
- listViewEx.Columns.Add(new ColumnHeader() { Text = string.Format("{0} [%]", Strings.Error), Width = 100 });
+ void InitializeColumns(ListView lv, Unit unit)
+ {
+ lv.Columns.Clear();
+ lv.Columns.Add(new ColumnHeader() { Text = Strings.Nr, Width = 40 });
+ lv.Columns.Add(new ColumnHeader() { Text = string.Format("{0} [{1}]", Strings.Mass, unit.ToDescription()), Width = 120 });
+ lv.Columns.Add(new ColumnHeader() { Text = string.Format("{0} [{1}]", Strings.Correction, unit.ToDescription()), Width = 150 });
+ lv.Columns.Add(new ColumnHeader() { Text = string.Format("{0} [%]", Strings.Error), Width = 100 });
- RefreshAll();
- }
+ measuredLabel.Text = string.Format("{0} [{1}]:", Strings.Measured, unit.ToDescription());
+ correctedLabel.Text = string.Format("{0} [{1}]:", Strings.Corrected, unit.ToDescription());
+ measuredTextBox.Text = string.Empty;
+ correctedTextBox.Text = string.Empty;
+ }
void Localize()
{
@@ -103,10 +124,7 @@ namespace TBF.UI.Bench.Metrology
buoyancyHumiLabel.Text = string.Format("{0} [%]", Strings.Ambient_humidity);
airDensityLabel.Text = Strings.Air_density_kg_m3;
weightStandardDensityLabel.Text = Strings.Ref_mass_dens_kg_m3;
-
testGroupBox.Text = Strings.Test_measured_corrected;
- measuredLabel.Text = Strings.Measured;
- correctedLabel.Text = Strings.Corrected;
}
void RefreshAll()
@@ -133,8 +151,12 @@ namespace TBF.UI.Bench.Metrology
int nr = listViewEx.Items.Count + 1;
ListViewItem lvi = new ListViewItem(nr.ToString());
lvi.Tag = corr;
- lvi.SubItems.Add(corr.Measurement.ToString());
- lvi.SubItems.Add((1000 * corr.Correction).ToString());
+ lvi.SubItems.Add(Units.ConvertTo(currentUnit, corr.Measurement).ToString());
+ double trueValue = corr.Measurement + corr.Correction;
+ double difference = Units.IsDefaultUnit(currentUnit)
+ ? corr.Correction
+ : Units.ConvertTo(currentUnit, trueValue) - Units.ConvertTo(currentUnit, corr.Measurement);
+ lvi.SubItems.Add(Common.Utils.ToNiceString(difference, SignifDigits));
if (corr.Measurement == 0)
{
@@ -142,8 +164,8 @@ namespace TBF.UI.Bench.Metrology
}
else
{
- double error = Config.Formulas.ErrorFromVolumes(corr.Measurement, corr.Measurement + corr.Correction);
- lvi.SubItems.Add(error.ToString(Config.Utils.SignificantDigitsToFmt(error, 5)));
+ double error = Config.Formulas.ErrorFromVolumes(corr.Measurement, trueValue);
+ lvi.SubItems.Add(Common.Utils.ToNiceString(error, SignifDigits));
}
listViewEx.Items.Add(lvi);
@@ -166,13 +188,13 @@ namespace TBF.UI.Bench.Metrology
}
void listViewEx_SubItemEndEditing(object sender, SubItemEndEditingEventArgs e)
- {
+ {
if (ParseItem(e.Item, e.SubItem, e.DisplayText)) return;
/// New value is NOK, revert the original text
- e.DisplayText = e.Item.Text;
- e.Cancel = true;
- }
+ e.DisplayText = e.Item.Text;
+ e.Cancel = true;
+ }
///
/// Parse text of a ListViewItem
@@ -180,18 +202,23 @@ namespace TBF.UI.Bench.Metrology
/// true = value parsed OK
bool ParseItem(ListViewItem item, int subItem, string strValue)
{
- double dblValue = 0;
- if (subItem == 1 && Utils.TryParseEDouble(strValue, out dblValue) && dblValue >= 0)
+ double oriMeasurement; /// Measurement in selected units
+ double measurement; /// Measurement in default units
+ double difference; /// Correction in selected unit
+ double correction; /// Correction in default unit
+ double error = 0;
+
+ if (subItem == 1 && Utils.TryParseEDouble(strValue, out oriMeasurement) && (measurement = Units.ConvertFrom(currentUnit, oriMeasurement)) >= 0)
{
- (item.Tag as MeasurementCorrection).Measurement = (float)dblValue;
+ (item.Tag as MeasurementCorrection).Measurement = measurement;
/// Update error (if possible)
- double correction1000;
- if (Utils.TryParseEDouble(item.SubItems[2].Text, out correction1000) && (dblValue != 0))
+ if (Utils.TryParseEDouble(item.SubItems[2].Text, out difference) && (measurement != 0))
{
- double correction = correction1000 / 1000;
- double error = Config.Formulas.ErrorFromVolumes(dblValue, dblValue + correction);
- item.SubItems[3].Text = error.ToString(Config.Utils.SignificantDigitsToFmt(error, 5));
+ correction = Units.IsDefaultUnit(currentUnit) ? difference
+ : Units.ConvertFrom(currentUnit, oriMeasurement + difference) - Units.ConvertFrom(currentUnit, oriMeasurement);
+ error = Config.Formulas.ErrorFromVolumes(measurement, measurement + correction);
+ item.SubItems[3].Text = Common.Utils.ToNiceString(error, SignifDigits);
}
else
{
@@ -200,39 +227,48 @@ namespace TBF.UI.Bench.Metrology
return true;
}
- else if (subItem == 2 && Utils.TryParseEDouble(strValue, out dblValue))
+ else if (subItem == 2 && Utils.TryParseEDouble(strValue, out difference))
{
- double correctionInDefaultUnits = dblValue / 1000;
- (item.Tag as MeasurementCorrection).Correction = (float)correctionInDefaultUnits;
+ if (Utils.TryParseEDouble(item.SubItems[1].Text, out oriMeasurement))
+ {
+ measurement = Units.ConvertFrom(currentUnit, oriMeasurement);
+ correction = Units.IsDefaultUnit(currentUnit) ? difference
+ : Units.ConvertFrom(currentUnit, oriMeasurement + difference) - Units.ConvertFrom(currentUnit, oriMeasurement);
+ (item.Tag as MeasurementCorrection).Correction = correction;
- /// Update error (if possible)
- double measurement;
- if (Utils.TryParseEDouble(item.SubItems[1].Text, out measurement) && (measurement != 0))
- {
- double error = Config.Formulas.ErrorFromVolumes(measurement, measurement + correctionInDefaultUnits);
- item.SubItems[3].Text = error.ToString(Config.Utils.SignificantDigitsToFmt(error, 5));
- }
- else
- {
- item.SubItems[3].Text = Strings.NaN;
- }
+ /// Update error (if possible)
+ if (measurement != 0)
+ {
+ error = Config.Formulas.ErrorFromVolumes(measurement, measurement + correction);
+ item.SubItems[3].Text = Common.Utils.ToNiceString(error, SignifDigits);
+ }
+ else
+ {
+ item.SubItems[3].Text = Strings.NaN;
+ }
- return true;
+ return true;
+ }
+ else
+ {
+ return false;
+ }
}
- else if (subItem == 3 && ((strValue == Strings.NaN) || Utils.TryParseEDouble(strValue, out dblValue)))
+ else if (subItem == 3 && ((strValue == Strings.NaN) || Utils.TryParseEDouble(strValue, out error)))
{
if (strValue == Strings.NaN)
{
}
else
{
- double measurement;
- if (Utils.TryParseEDouble(item.SubItems[1].Text, out measurement) && measurement != 0)
+ if (Utils.TryParseEDouble(item.SubItems[1].Text, out oriMeasurement) && (measurement = Units.ConvertFrom(currentUnit, oriMeasurement)) != 0)
{
- double correction = Config.Formulas.CorrectionFromError(measurement, dblValue);
- double correction1000 = 1000 * correction;
- item.SubItems[2].Text = correction1000.ToString(Config.Utils.SignificantDigitsToFmt(correction1000, 5));
- (item.Tag as MeasurementCorrection).Correction = (float)correction;
+ correction = Config.Formulas.CorrectionFromError(measurement, error);
+ (item.Tag as MeasurementCorrection).Correction = correction;
+ difference = Units.IsDefaultUnit(currentUnit)
+ ? correction
+ : Units.ConvertTo(currentUnit, measurement + correction) - oriMeasurement;
+ item.SubItems[2].Text = Common.Utils.ToNiceString(difference, SignifDigits);
}
}
@@ -372,18 +408,18 @@ namespace TBF.UI.Bench.Metrology
private void measuredTextBox_TextChanged(object sender, EventArgs e)
{
- float measured;
- if (float.TryParse(measuredTextBox.Text,
+ double measured;
+ if (double.TryParse(measuredTextBox.Text,
NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign | NumberStyles.AllowExponent,
CultureInfo.CurrentCulture,
out measured) ||
- float.TryParse(measuredTextBox.Text,
+ double.TryParse(measuredTextBox.Text,
NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign | NumberStyles.AllowExponent,
CultureInfo.InvariantCulture,
out measured))
{
- double corrected = MeasurementCorrection.CorrectedValue(measured, meterEntity.Corrections);
- correctedTextBox.Text = corrected.ToString();
+ double corrected = MeasurementCorrection.CorrectedValue(Units.ConvertFrom(currentUnit, measured), meterEntity.Corrections);
+ correctedTextBox.Text = Units.ConvertTo(currentUnit, corrected).ToString();
}
}
@@ -400,5 +436,20 @@ namespace TBF.UI.Bench.Metrology
{
session.SaveOrUpdate(MeterEntity);
}
+
+ private void unitComboBox_SelectedIndexChanged(object sender, EventArgs e)
+ {
+ for (Unit u = 0; u < Unit.Count; u++)
+ {
+ if (u.ToDescription() == unitComboBox.Text)
+ {
+ currentUnit = u;
+ break;
+ }
+ }
+
+ InitializeColumns(listViewEx, currentUnit);
+ RefreshAll();
+ }
}
}
diff --git a/TBF/UI/Bench/Metrology/MetrologyDlgFlowMeterTab.Designer.cs b/TBF/UI/Bench/Metrology/MetrologyDlgFlowMeterTab.Designer.cs
index 62915ebbf..8f05448de 100644
--- a/TBF/UI/Bench/Metrology/MetrologyDlgFlowMeterTab.Designer.cs
+++ b/TBF/UI/Bench/Metrology/MetrologyDlgFlowMeterTab.Designer.cs
@@ -32,7 +32,11 @@ namespace TBF.UI.Bench.Metrology
private void InitializeComponent()
{
this.splitContainer1 = new System.Windows.Forms.SplitContainer();
+ this.unitLabel = new System.Windows.Forms.Label();
+ this.unitComboBox = new System.Windows.Forms.ComboBox();
this.calibrationGroupBox = new System.Windows.Forms.GroupBox();
+ this.calibExpirationDateTimePicker = new System.Windows.Forms.DateTimePicker();
+ this.calibDateTimePicker = new System.Windows.Forms.DateTimePicker();
this.calibValidDateLabel = new System.Windows.Forms.Label();
this.calibDateLabel = new System.Windows.Forms.Label();
this.calibCertificateNrTextBox = new System.Windows.Forms.TextBox();
@@ -47,8 +51,6 @@ namespace TBF.UI.Bench.Metrology
this.correctedLabel = new System.Windows.Forms.Label();
this.measuredLabel = new System.Windows.Forms.Label();
this.listViewEx = new Common.Forms.ListViewEx();
- this.calibExpirationDateTimePicker = new System.Windows.Forms.DateTimePicker();
- this.calibDateTimePicker = new System.Windows.Forms.DateTimePicker();
((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit();
this.splitContainer1.Panel1.SuspendLayout();
this.splitContainer1.Panel2.SuspendLayout();
@@ -68,6 +70,8 @@ namespace TBF.UI.Bench.Metrology
//
// splitContainer1.Panel1
//
+ this.splitContainer1.Panel1.Controls.Add(this.unitLabel);
+ this.splitContainer1.Panel1.Controls.Add(this.unitComboBox);
this.splitContainer1.Panel1.Controls.Add(this.calibrationGroupBox);
this.splitContainer1.Panel1.Controls.Add(this.nameGroupBox);
this.splitContainer1.Panel1.Controls.Add(this.testGroupBox);
@@ -79,6 +83,24 @@ namespace TBF.UI.Bench.Metrology
this.splitContainer1.SplitterDistance = 102;
this.splitContainer1.TabIndex = 2;
//
+ // unitLabel
+ //
+ this.unitLabel.AutoSize = true;
+ this.unitLabel.Location = new System.Drawing.Point(21, 76);
+ this.unitLabel.Name = "unitLabel";
+ this.unitLabel.Size = new System.Drawing.Size(63, 13);
+ this.unitLabel.TabIndex = 10;
+ this.unitLabel.Text = "Unit of flow:";
+ //
+ // unitComboBox
+ //
+ this.unitComboBox.FormattingEnabled = true;
+ this.unitComboBox.Location = new System.Drawing.Point(107, 73);
+ this.unitComboBox.Name = "unitComboBox";
+ this.unitComboBox.Size = new System.Drawing.Size(62, 21);
+ this.unitComboBox.TabIndex = 9;
+ this.unitComboBox.SelectedIndexChanged += new System.EventHandler(this.unitComboBox_SelectedIndexChanged);
+ //
// calibrationGroupBox
//
this.calibrationGroupBox.Controls.Add(this.calibExpirationDateTimePicker);
@@ -94,6 +116,26 @@ namespace TBF.UI.Bench.Metrology
this.calibrationGroupBox.TabStop = false;
this.calibrationGroupBox.Text = "Calibration";
//
+ // calibExpirationDateTimePicker
+ //
+ this.calibExpirationDateTimePicker.CustomFormat = "dd.MM.yyyy";
+ this.calibExpirationDateTimePicker.Enabled = false;
+ this.calibExpirationDateTimePicker.Format = System.Windows.Forms.DateTimePickerFormat.Custom;
+ this.calibExpirationDateTimePicker.Location = new System.Drawing.Point(140, 59);
+ this.calibExpirationDateTimePicker.Name = "calibExpirationDateTimePicker";
+ this.calibExpirationDateTimePicker.Size = new System.Drawing.Size(82, 20);
+ this.calibExpirationDateTimePicker.TabIndex = 19;
+ //
+ // calibDateTimePicker
+ //
+ this.calibDateTimePicker.CustomFormat = "dd.MM.yyyy";
+ this.calibDateTimePicker.Enabled = false;
+ this.calibDateTimePicker.Format = System.Windows.Forms.DateTimePickerFormat.Custom;
+ this.calibDateTimePicker.Location = new System.Drawing.Point(140, 37);
+ this.calibDateTimePicker.Name = "calibDateTimePicker";
+ this.calibDateTimePicker.Size = new System.Drawing.Size(82, 20);
+ this.calibDateTimePicker.TabIndex = 18;
+ //
// calibValidDateLabel
//
this.calibValidDateLabel.AutoSize = true;
@@ -136,7 +178,7 @@ namespace TBF.UI.Bench.Metrology
this.nameGroupBox.Controls.Add(this.cmpntNameLabel);
this.nameGroupBox.Location = new System.Drawing.Point(16, 10);
this.nameGroupBox.Name = "nameGroupBox";
- this.nameGroupBox.Size = new System.Drawing.Size(160, 86);
+ this.nameGroupBox.Size = new System.Drawing.Size(160, 53);
this.nameGroupBox.TabIndex = 5;
this.nameGroupBox.TabStop = false;
this.nameGroupBox.Text = "Component";
@@ -198,7 +240,7 @@ namespace TBF.UI.Bench.Metrology
// correctedLabel
//
this.correctedLabel.AutoSize = true;
- this.correctedLabel.Location = new System.Drawing.Point(17, 40);
+ this.correctedLabel.Location = new System.Drawing.Point(11, 40);
this.correctedLabel.Name = "correctedLabel";
this.correctedLabel.Size = new System.Drawing.Size(53, 13);
this.correctedLabel.TabIndex = 3;
@@ -207,7 +249,7 @@ namespace TBF.UI.Bench.Metrology
// measuredLabel
//
this.measuredLabel.AutoSize = true;
- this.measuredLabel.Location = new System.Drawing.Point(17, 18);
+ this.measuredLabel.Location = new System.Drawing.Point(11, 18);
this.measuredLabel.Name = "measuredLabel";
this.measuredLabel.Size = new System.Drawing.Size(54, 13);
this.measuredLabel.TabIndex = 2;
@@ -228,26 +270,6 @@ namespace TBF.UI.Bench.Metrology
this.listViewEx.View = System.Windows.Forms.View.Details;
this.listViewEx.SelectedIndexChanged += new System.EventHandler(this.listViewEx_SelectedIndexChanged);
//
- // calibExpirationDateTimePicker
- //
- this.calibExpirationDateTimePicker.CustomFormat = "dd.MM.yyyy";
- this.calibExpirationDateTimePicker.Enabled = false;
- this.calibExpirationDateTimePicker.Format = System.Windows.Forms.DateTimePickerFormat.Custom;
- this.calibExpirationDateTimePicker.Location = new System.Drawing.Point(140, 59);
- this.calibExpirationDateTimePicker.Name = "calibExpirationDateTimePicker";
- this.calibExpirationDateTimePicker.Size = new System.Drawing.Size(82, 20);
- this.calibExpirationDateTimePicker.TabIndex = 19;
- //
- // calibDateTimePicker
- //
- this.calibDateTimePicker.CustomFormat = "dd.MM.yyyy";
- this.calibDateTimePicker.Enabled = false;
- this.calibDateTimePicker.Format = System.Windows.Forms.DateTimePickerFormat.Custom;
- this.calibDateTimePicker.Location = new System.Drawing.Point(140, 37);
- this.calibDateTimePicker.Name = "calibDateTimePicker";
- this.calibDateTimePicker.Size = new System.Drawing.Size(82, 20);
- this.calibDateTimePicker.TabIndex = 18;
- //
// MetrologyDlgFlowMeterTab
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
@@ -257,6 +279,7 @@ namespace TBF.UI.Bench.Metrology
this.Size = new System.Drawing.Size(650, 400);
this.Load += new System.EventHandler(this.MetrologyDlgFlowMeterTab_Load);
this.splitContainer1.Panel1.ResumeLayout(false);
+ this.splitContainer1.Panel1.PerformLayout();
this.splitContainer1.Panel2.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).EndInit();
this.splitContainer1.ResumeLayout(false);
@@ -290,6 +313,8 @@ namespace TBF.UI.Bench.Metrology
private System.Windows.Forms.Label tempFromToLabel;
private System.Windows.Forms.DateTimePicker calibExpirationDateTimePicker;
private System.Windows.Forms.DateTimePicker calibDateTimePicker;
+ private System.Windows.Forms.Label unitLabel;
+ private System.Windows.Forms.ComboBox unitComboBox;
}
}
diff --git a/TBF/UI/Bench/Metrology/MetrologyDlgFlowMeterTab.cs b/TBF/UI/Bench/Metrology/MetrologyDlgFlowMeterTab.cs
index 8b72a3acf..a72e01e06 100644
--- a/TBF/UI/Bench/Metrology/MetrologyDlgFlowMeterTab.cs
+++ b/TBF/UI/Bench/Metrology/MetrologyDlgFlowMeterTab.cs
@@ -1,13 +1,14 @@
///
-/// Copyright (c) 2013-2019 Sensus Slovensko a.s.
+/// Copyright (c) 2013-2022 Sensus Slovensko a.s.
///
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Windows.Forms;
using log4net;
-using Config.Entities;
+using Common;
using Common.Forms;
+using Config.Entities;
using TBF.Resources;
using TBF.UI.Shared;
@@ -17,6 +18,9 @@ namespace TBF.UI.Bench.Metrology
{
static readonly ILog log = LogManager.GetLogger(typeof(MetrologyDlgFlowMeterTab));
+ public const Unit DefaultUnit = Unit.m3ph;
+ public const int SignifDigits = 5;
+
///
/// Component entity that has a list of 'measurement-correction' pairs
/// to be updated in the database on OK.
@@ -51,6 +55,7 @@ namespace TBF.UI.Bench.Metrology
readonly int rangeIx; /// 0 (no range) or 1..5 (range #)
readonly bool isLastFlowMeterRange; /// true when this is the last range of this flow meter.
/// This is to prevent double saving of the meter entity to a DB
+ Unit currentUnit;
public MetrologyDlgFlowMeterTab() : this(0, true) {}
@@ -87,28 +92,39 @@ namespace TBF.UI.Bench.Metrology
pressFromToLabel.Text = string.Format("{0} {1} {2} {3} bar", Strings.from, CalibInfoCfg.GetPressLo(rangeIx), Strings.to, CalibInfoCfg.GetPressHi(rangeIx));
}
- testGroupBox.Text = Strings.Test_measured_corrected;
- measuredLabel.Text = Strings.Measured;
- correctedLabel.Text = Strings.Corrected;
- measuredTextBox.Text = string.Empty;
- correctedTextBox.Text = string.Empty;
+ for (Unit u = 0; u < Unit.Count; u++)
+ if (Units.IsFlow(u))
+ unitComboBox.Items.Add(u.ToDescription());
/// Panel2
this.Controls.Add(measurementTextBox = new TextBox());
this.Controls.Add(correctionTextBox = new TextBox());
this.Controls.Add(errorTextBox = new TextBox());
+ currentUnit = DefaultUnit;
+ unitComboBox.Text = currentUnit.ToDescription();
+ InitializeColumns(listViewEx, currentUnit);
+ RefreshAll(rangeIx);
+
listViewEx.SubItemClicked += new SubItemEventHandler(listViewEx_SubItemClicked);
listViewEx.SubItemEndEditing += new SubItemEndEditingEventHandler(listViewEx_SubItemEndEditing);
-
- listViewEx.Columns.Add(new ColumnHeader() { Text = Strings.Nr, Width = 60 });
- listViewEx.Columns.Add(new ColumnHeader() { Text = string.Format("{0} [m3/h]", Strings.Flow), Width = 100 });
- listViewEx.Columns.Add(new ColumnHeader() { Text = string.Format("{0} [l/h]", Strings.Correction), Width = 100 });
- listViewEx.Columns.Add(new ColumnHeader() { Text = string.Format("{0} [%]", Strings.Error), Width = 100 });
-
- RefreshAll(rangeIx);
+ unitComboBox.SelectedIndexChanged += new System.EventHandler(unitComboBox_SelectedIndexChanged);
}
+ void InitializeColumns(ListView lv, Unit unit)
+ {
+ lv.Columns.Clear();
+ lv.Columns.Add(new ColumnHeader() { Text = Strings.Nr, Width = 40 });
+ lv.Columns.Add(new ColumnHeader() { Text = string.Format("{0} [{1}]", Strings.Flow, unit.ToDescription()), Width = 120 });
+ lv.Columns.Add(new ColumnHeader() { Text = string.Format("{0} [{1}]", Strings.Correction, unit.ToDescription()), Width = 150 });
+ lv.Columns.Add(new ColumnHeader() { Text = string.Format("{0} [%]", Strings.Error), Width = 100 });
+
+ measuredLabel.Text = string.Format("{0} [{1}]:", Strings.Measured, unit.ToDescription());
+ correctedLabel.Text = string.Format("{0} [{1}]:", Strings.Corrected, unit.ToDescription());
+ measuredTextBox.Text = string.Empty;
+ correctedTextBox.Text = string.Empty;
+ }
+
void Localize()
{
nameGroupBox.Text = Strings.Component;
@@ -117,10 +133,7 @@ namespace TBF.UI.Bench.Metrology
calibCertificateNrLabel.Text = Strings.Certificate;
calibDateLabel.Text = Strings.Date;
calibValidDateLabel.Text = Strings.Valid_until;
-
testGroupBox.Text = Strings.Test_measured_corrected;
- measuredLabel.Text = Strings.Measured;
- correctedLabel.Text = Strings.Corrected;
}
void RefreshAll(int rangeIx1)
@@ -144,8 +157,12 @@ namespace TBF.UI.Bench.Metrology
int nr = listViewEx.Items.Count + 1;
ListViewItem lvi = new ListViewItem(nr.ToString());
lvi.Tag = corr;
- lvi.SubItems.Add(corr.Measurement.ToString());
- lvi.SubItems.Add((1000 * corr.Correction).ToString());
+ lvi.SubItems.Add(Units.ConvertTo(currentUnit, corr.Measurement).ToString());
+ double trueValue = corr.Measurement + corr.Correction;
+ double difference = Units.IsDefaultUnit(currentUnit)
+ ? corr.Correction
+ : Units.ConvertTo(currentUnit, trueValue) - Units.ConvertTo(currentUnit, corr.Measurement);
+ lvi.SubItems.Add(Common.Utils.ToNiceString(difference, SignifDigits));
if (corr.Measurement == 0)
{
@@ -153,11 +170,11 @@ namespace TBF.UI.Bench.Metrology
}
else
{
- double error = Config.Formulas.ErrorFromVolumes(corr.Measurement, corr.Measurement + corr.Correction);
- lvi.SubItems.Add(error.ToString(Config.Utils.SignificantDigitsToFmt(error, 5)));
+ double error = Config.Formulas.ErrorFromVolumes(corr.Measurement, trueValue);
+ lvi.SubItems.Add(Common.Utils.ToNiceString(error, SignifDigits));
}
- listViewEx.Items.Add(lvi);
+ listViewEx.Items.Add(lvi);
}
void listViewEx_SubItemClicked(object sender, SubItemEventArgs e)
@@ -174,16 +191,16 @@ namespace TBF.UI.Bench.Metrology
{
listViewEx.StartEditing(correctionTextBox, e.Item, e.SubItem);
}
- }
+ }
void listViewEx_SubItemEndEditing(object sender, SubItemEndEditingEventArgs e)
- {
+ {
if (ParseItem(e.Item, e.SubItem, e.DisplayText)) return;
/// New value is NOK, revert the original text
- e.DisplayText = e.Item.Text;
- e.Cancel = true;
- }
+ e.DisplayText = e.Item.Text;
+ e.Cancel = true;
+ }
///
/// Parse text of a ListViewItem
@@ -191,18 +208,23 @@ namespace TBF.UI.Bench.Metrology
/// true = value parsed OK
bool ParseItem(ListViewItem item, int subItem, string strValue)
{
- double dblValue = 0;
- if (subItem == 1 && Utils.TryParseEDouble(strValue, out dblValue) && dblValue >= 0)
+ double oriMeasurement; /// Measurement in selected units
+ double measurement; /// Measurement in default units
+ double difference; /// Correction in selected unit
+ double correction; /// Correction in default unit
+ double error = 0;
+
+ if (subItem == 1 && Utils.TryParseEDouble(strValue, out oriMeasurement) && (measurement = Units.ConvertFrom(currentUnit, oriMeasurement)) >= 0)
{
- (item.Tag as MeasurementCorrection).Measurement = (float)dblValue;
+ (item.Tag as MeasurementCorrection).Measurement = measurement;
/// Update error (if possible)
- double correction1000;
- if (Utils.TryParseEDouble(item.SubItems[2].Text, out correction1000) && (dblValue != 0))
+ if (Utils.TryParseEDouble(item.SubItems[2].Text, out difference) && (measurement != 0))
{
- double correction = correction1000 / 1000;
- double error = Config.Formulas.ErrorFromVolumes(dblValue, dblValue + correction);
- item.SubItems[3].Text = error.ToString(Config.Utils.SignificantDigitsToFmt(error, 5));
+ correction = Units.IsDefaultUnit(currentUnit) ? difference
+ : Units.ConvertFrom(currentUnit, oriMeasurement + difference) - Units.ConvertFrom(currentUnit, oriMeasurement);
+ error = Config.Formulas.ErrorFromVolumes(measurement, measurement + correction);
+ item.SubItems[3].Text = Common.Utils.ToNiceString(error, SignifDigits);
}
else
{
@@ -211,39 +233,48 @@ namespace TBF.UI.Bench.Metrology
return true;
}
- else if (subItem == 2 && Utils.TryParseEDouble(strValue, out dblValue))
+ else if (subItem == 2 && Utils.TryParseEDouble(strValue, out difference))
{
- double correctionInDefaultUnits = dblValue / 1000;
- (item.Tag as MeasurementCorrection).Correction = (float)correctionInDefaultUnits;
+ if (Utils.TryParseEDouble(item.SubItems[1].Text, out oriMeasurement))
+ {
+ measurement = Units.ConvertFrom(currentUnit, oriMeasurement);
+ correction = Units.IsDefaultUnit(currentUnit) ? difference
+ : Units.ConvertFrom(currentUnit, oriMeasurement + difference) - Units.ConvertFrom(currentUnit, oriMeasurement);
+ (item.Tag as MeasurementCorrection).Correction = correction;
- /// Update error (if possible)
- double measurement;
- if (Utils.TryParseEDouble(item.SubItems[1].Text, out measurement) && (measurement != 0))
- {
- double error = Config.Formulas.ErrorFromVolumes(measurement, measurement + correctionInDefaultUnits);
- item.SubItems[3].Text = error.ToString(Config.Utils.SignificantDigitsToFmt(error, 5));
- }
- else
- {
- item.SubItems[3].Text = Strings.NaN;
- }
+ /// Update error (if possible)
+ if (measurement != 0)
+ {
+ error = Config.Formulas.ErrorFromVolumes(measurement, measurement + correction);
+ item.SubItems[3].Text = Common.Utils.ToNiceString(error, SignifDigits);
+ }
+ else
+ {
+ item.SubItems[3].Text = Strings.NaN;
+ }
- return true;
+ return true;
+ }
+ else
+ {
+ return false;
+ }
}
- else if (subItem == 3 && ((strValue == Strings.NaN) || Utils.TryParseEDouble(strValue, out dblValue)))
+ else if (subItem == 3 && ((strValue == Strings.NaN) || Utils.TryParseEDouble(strValue, out error)))
{
if (strValue == Strings.NaN)
{
}
else
{
- double measurement;
- if (Utils.TryParseEDouble(item.SubItems[1].Text, out measurement) && measurement != 0)
+ if (Utils.TryParseEDouble(item.SubItems[1].Text, out oriMeasurement) && (measurement = Units.ConvertFrom(currentUnit, oriMeasurement)) != 0)
{
- double correction = Config.Formulas.CorrectionFromError(measurement, dblValue);
- double correction1000 = 1000 * correction;
- item.SubItems[2].Text = correction1000.ToString(Config.Utils.SignificantDigitsToFmt(correction1000, 5));
- (item.Tag as MeasurementCorrection).Correction = (float)correction;
+ correction = Config.Formulas.CorrectionFromError(measurement, error);
+ (item.Tag as MeasurementCorrection).Correction = correction;
+ difference = Units.IsDefaultUnit(currentUnit)
+ ? correction
+ : Units.ConvertTo(currentUnit, measurement + correction) - oriMeasurement;
+ item.SubItems[2].Text = Common.Utils.ToNiceString(difference, SignifDigits);
}
}
@@ -369,18 +400,19 @@ namespace TBF.UI.Bench.Metrology
private void measuredTextBox_TextChanged(object sender, EventArgs e)
{
- float measured;
- if (float.TryParse(measuredTextBox.Text,
+ double measured;
+ if (double.TryParse(measuredTextBox.Text,
NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign | NumberStyles.AllowExponent,
CultureInfo.CurrentCulture,
out measured) ||
- float.TryParse(measuredTextBox.Text,
+ double.TryParse(measuredTextBox.Text,
NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign | NumberStyles.AllowExponent,
CultureInfo.InvariantCulture,
out measured))
{
- double corrected = MeasurementCorrection.CorrectedValue(measured, meterEntity.Corrections);
- correctedTextBox.Text = corrected.ToString();
+ double raw = Units.ConvertFrom(currentUnit, measured);
+ double corrected = raw + MeasurementCorrection.GetCorrection(raw, MeterEntity.Corrections); /// !!! rangeIx is ignored
+ correctedTextBox.Text = Units.ConvertTo(currentUnit, corrected).ToString();
}
}
@@ -402,5 +434,20 @@ namespace TBF.UI.Bench.Metrology
session.SaveOrUpdate(MeterEntity);
}
}
+
+ private void unitComboBox_SelectedIndexChanged(object sender, EventArgs e)
+ {
+ for (Unit u = 0; u < Unit.Count; u++)
+ {
+ if (u.ToDescription() == unitComboBox.Text)
+ {
+ currentUnit = u;
+ break;
+ }
+ }
+
+ InitializeColumns(listViewEx, currentUnit);
+ RefreshAll(rangeIx);
+ }
}
}
diff --git a/TBF/UI/Bench/Metrology/MetrologyDlgPressMeterTab.Designer.cs b/TBF/UI/Bench/Metrology/MetrologyDlgPressMeterTab.Designer.cs
index 9f2353bcd..b4f2cb543 100644
--- a/TBF/UI/Bench/Metrology/MetrologyDlgPressMeterTab.Designer.cs
+++ b/TBF/UI/Bench/Metrology/MetrologyDlgPressMeterTab.Designer.cs
@@ -32,7 +32,11 @@ namespace TBF.UI.Bench.Metrology
private void InitializeComponent()
{
this.splitContainer1 = new System.Windows.Forms.SplitContainer();
+ this.unitLabel = new System.Windows.Forms.Label();
+ this.unitComboBox = new System.Windows.Forms.ComboBox();
this.calibrationGroupBox = new System.Windows.Forms.GroupBox();
+ this.calibExpirationDateTimePicker = new System.Windows.Forms.DateTimePicker();
+ this.calibDateTimePicker = new System.Windows.Forms.DateTimePicker();
this.calibValidDateLabel = new System.Windows.Forms.Label();
this.calibDateLabel = new System.Windows.Forms.Label();
this.calibCertificateNrTextBox = new System.Windows.Forms.TextBox();
@@ -45,8 +49,6 @@ namespace TBF.UI.Bench.Metrology
this.componentLabel = new System.Windows.Forms.Label();
this.cmpntNameLabel = new System.Windows.Forms.Label();
this.listViewEx = new Common.Forms.ListViewEx();
- this.calibExpirationDateTimePicker = new System.Windows.Forms.DateTimePicker();
- this.calibDateTimePicker = new System.Windows.Forms.DateTimePicker();
((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit();
this.splitContainer1.Panel1.SuspendLayout();
this.splitContainer1.Panel2.SuspendLayout();
@@ -65,6 +67,8 @@ namespace TBF.UI.Bench.Metrology
//
// splitContainer1.Panel1
//
+ this.splitContainer1.Panel1.Controls.Add(this.unitLabel);
+ this.splitContainer1.Panel1.Controls.Add(this.unitComboBox);
this.splitContainer1.Panel1.Controls.Add(this.calibrationGroupBox);
this.splitContainer1.Panel1.Controls.Add(this.testGroupBox);
this.splitContainer1.Panel1.Controls.Add(this.componentLabel);
@@ -73,10 +77,28 @@ namespace TBF.UI.Bench.Metrology
// splitContainer1.Panel2
//
this.splitContainer1.Panel2.Controls.Add(this.listViewEx);
- this.splitContainer1.Size = new System.Drawing.Size(600, 300);
+ this.splitContainer1.Size = new System.Drawing.Size(650, 300);
this.splitContainer1.SplitterDistance = 110;
this.splitContainer1.TabIndex = 2;
//
+ // unitLabel
+ //
+ this.unitLabel.AutoSize = true;
+ this.unitLabel.Location = new System.Drawing.Point(14, 56);
+ this.unitLabel.Name = "unitLabel";
+ this.unitLabel.Size = new System.Drawing.Size(84, 13);
+ this.unitLabel.TabIndex = 10;
+ this.unitLabel.Text = "Unit of pressure:";
+ //
+ // unitComboBox
+ //
+ this.unitComboBox.FormattingEnabled = true;
+ this.unitComboBox.Location = new System.Drawing.Point(123, 53);
+ this.unitComboBox.Name = "unitComboBox";
+ this.unitComboBox.Size = new System.Drawing.Size(62, 21);
+ this.unitComboBox.TabIndex = 9;
+ this.unitComboBox.SelectedIndexChanged += new System.EventHandler(this.unitComboBox_SelectedIndexChanged);
+ //
// calibrationGroupBox
//
this.calibrationGroupBox.Controls.Add(this.calibExpirationDateTimePicker);
@@ -92,6 +114,26 @@ namespace TBF.UI.Bench.Metrology
this.calibrationGroupBox.TabStop = false;
this.calibrationGroupBox.Text = "Calibration";
//
+ // calibExpirationDateTimePicker
+ //
+ this.calibExpirationDateTimePicker.CustomFormat = "dd.MM.yyyy";
+ this.calibExpirationDateTimePicker.Enabled = false;
+ this.calibExpirationDateTimePicker.Format = System.Windows.Forms.DateTimePickerFormat.Custom;
+ this.calibExpirationDateTimePicker.Location = new System.Drawing.Point(117, 59);
+ this.calibExpirationDateTimePicker.Name = "calibExpirationDateTimePicker";
+ this.calibExpirationDateTimePicker.Size = new System.Drawing.Size(82, 20);
+ this.calibExpirationDateTimePicker.TabIndex = 19;
+ //
+ // calibDateTimePicker
+ //
+ this.calibDateTimePicker.CustomFormat = "dd.MM.yyyy";
+ this.calibDateTimePicker.Enabled = false;
+ this.calibDateTimePicker.Format = System.Windows.Forms.DateTimePickerFormat.Custom;
+ this.calibDateTimePicker.Location = new System.Drawing.Point(117, 37);
+ this.calibDateTimePicker.Name = "calibDateTimePicker";
+ this.calibDateTimePicker.Size = new System.Drawing.Size(82, 20);
+ this.calibDateTimePicker.TabIndex = 18;
+ //
// calibValidDateLabel
//
this.calibValidDateLabel.AutoSize = true;
@@ -113,7 +155,7 @@ namespace TBF.UI.Bench.Metrology
// calibCertificateNrTextBox
//
this.calibCertificateNrTextBox.Enabled = false;
- this.calibCertificateNrTextBox.Location = new System.Drawing.Point(120, 15);
+ this.calibCertificateNrTextBox.Location = new System.Drawing.Point(117, 15);
this.calibCertificateNrTextBox.Name = "calibCertificateNrTextBox";
this.calibCertificateNrTextBox.Size = new System.Drawing.Size(82, 20);
this.calibCertificateNrTextBox.TabIndex = 11;
@@ -135,14 +177,14 @@ namespace TBF.UI.Bench.Metrology
this.testGroupBox.Controls.Add(this.measuredLabel);
this.testGroupBox.Location = new System.Drawing.Point(428, 12);
this.testGroupBox.Name = "testGroupBox";
- this.testGroupBox.Size = new System.Drawing.Size(157, 86);
+ this.testGroupBox.Size = new System.Drawing.Size(200, 86);
this.testGroupBox.TabIndex = 4;
this.testGroupBox.TabStop = false;
this.testGroupBox.Text = "Test";
//
// correctedTextBox
//
- this.correctedTextBox.Location = new System.Drawing.Point(74, 48);
+ this.correctedTextBox.Location = new System.Drawing.Point(115, 49);
this.correctedTextBox.Name = "correctedTextBox";
this.correctedTextBox.ReadOnly = true;
this.correctedTextBox.Size = new System.Drawing.Size(73, 20);
@@ -150,7 +192,7 @@ namespace TBF.UI.Bench.Metrology
//
// measuredTextBox
//
- this.measuredTextBox.Location = new System.Drawing.Point(74, 23);
+ this.measuredTextBox.Location = new System.Drawing.Point(115, 24);
this.measuredTextBox.Name = "measuredTextBox";
this.measuredTextBox.Size = new System.Drawing.Size(73, 20);
this.measuredTextBox.TabIndex = 4;
@@ -159,7 +201,7 @@ namespace TBF.UI.Bench.Metrology
// correctedLabel
//
this.correctedLabel.AutoSize = true;
- this.correctedLabel.Location = new System.Drawing.Point(7, 51);
+ this.correctedLabel.Location = new System.Drawing.Point(7, 52);
this.correctedLabel.Name = "correctedLabel";
this.correctedLabel.Size = new System.Drawing.Size(53, 13);
this.correctedLabel.TabIndex = 3;
@@ -168,7 +210,7 @@ namespace TBF.UI.Bench.Metrology
// measuredLabel
//
this.measuredLabel.AutoSize = true;
- this.measuredLabel.Location = new System.Drawing.Point(6, 30);
+ this.measuredLabel.Location = new System.Drawing.Point(7, 27);
this.measuredLabel.Name = "measuredLabel";
this.measuredLabel.Size = new System.Drawing.Size(54, 13);
this.measuredLabel.TabIndex = 2;
@@ -201,39 +243,19 @@ namespace TBF.UI.Bench.Metrology
this.listViewEx.GridLines = true;
this.listViewEx.Location = new System.Drawing.Point(0, 0);
this.listViewEx.Name = "listViewEx";
- this.listViewEx.Size = new System.Drawing.Size(600, 186);
+ this.listViewEx.Size = new System.Drawing.Size(650, 186);
this.listViewEx.TabIndex = 0;
this.listViewEx.UseCompatibleStateImageBehavior = false;
this.listViewEx.View = System.Windows.Forms.View.Details;
this.listViewEx.SelectedIndexChanged += new System.EventHandler(this.listViewEx_SelectedIndexChanged);
//
- // calibExpirationDateTimePicker
- //
- this.calibExpirationDateTimePicker.CustomFormat = "dd.MM.yyyy";
- this.calibExpirationDateTimePicker.Enabled = false;
- this.calibExpirationDateTimePicker.Format = System.Windows.Forms.DateTimePickerFormat.Custom;
- this.calibExpirationDateTimePicker.Location = new System.Drawing.Point(120, 59);
- this.calibExpirationDateTimePicker.Name = "calibExpirationDateTimePicker";
- this.calibExpirationDateTimePicker.Size = new System.Drawing.Size(82, 20);
- this.calibExpirationDateTimePicker.TabIndex = 19;
- //
- // calibDateTimePicker
- //
- this.calibDateTimePicker.CustomFormat = "dd.MM.yyyy";
- this.calibDateTimePicker.Enabled = false;
- this.calibDateTimePicker.Format = System.Windows.Forms.DateTimePickerFormat.Custom;
- this.calibDateTimePicker.Location = new System.Drawing.Point(120, 37);
- this.calibDateTimePicker.Name = "calibDateTimePicker";
- this.calibDateTimePicker.Size = new System.Drawing.Size(82, 20);
- this.calibDateTimePicker.TabIndex = 18;
- //
// MetrologyDlgPressMeterTab
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this.splitContainer1);
this.Name = "MetrologyDlgPressMeterTab";
- this.Size = new System.Drawing.Size(600, 300);
+ this.Size = new System.Drawing.Size(650, 300);
this.Load += new System.EventHandler(this.MetrologyDlgPressMeterTab_Load);
this.splitContainer1.Panel1.ResumeLayout(false);
this.splitContainer1.Panel1.PerformLayout();
@@ -266,6 +288,8 @@ namespace TBF.UI.Bench.Metrology
private System.Windows.Forms.Label calibCertificateNrLabel;
private System.Windows.Forms.DateTimePicker calibExpirationDateTimePicker;
private System.Windows.Forms.DateTimePicker calibDateTimePicker;
+ private System.Windows.Forms.Label unitLabel;
+ private System.Windows.Forms.ComboBox unitComboBox;
}
}
diff --git a/TBF/UI/Bench/Metrology/MetrologyDlgPressMeterTab.cs b/TBF/UI/Bench/Metrology/MetrologyDlgPressMeterTab.cs
index 4227e8b02..993b71dd9 100644
--- a/TBF/UI/Bench/Metrology/MetrologyDlgPressMeterTab.cs
+++ b/TBF/UI/Bench/Metrology/MetrologyDlgPressMeterTab.cs
@@ -1,13 +1,14 @@
///
-/// Copyright (c) 2013-2020 Sensus Slovensko a.s.
+/// Copyright (c) 2013-2022 Sensus Slovensko a.s.
///
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Windows.Forms;
using log4net;
-using Config.Entities;
+using Common;
using Common.Forms;
+using Config.Entities;
using TBF.Resources;
using TBF.UI.Shared;
@@ -17,6 +18,9 @@ namespace TBF.UI.Bench.Metrology
{
static readonly ILog log = LogManager.GetLogger(typeof(MetrologyDlgPressMeterTab));
+ public const Unit DefaultUnit = Unit.bar;
+ public const int SignifDigits = 5;
+
///
/// Component entity that has a list of 'measurement-correction' pairs
/// to be updated in the database on OK.
@@ -49,6 +53,8 @@ namespace TBF.UI.Bench.Metrology
Control correctionTextBox;
Control errorTextBox;
+ Unit currentUnit;
+
public MetrologyDlgPressMeterTab()
{
InitializeComponent();
@@ -68,34 +74,46 @@ namespace TBF.UI.Bench.Metrology
Localize();
- /// Panel1
+ /// Panel1
cmpntNameLabel.Text = meterEntity.Name;
+ for (Unit u = 0; u < Unit.Count; u++)
+ if (Units.IsPressure(u))
+ unitComboBox.Items.Add(u.ToDescription());
+
/// Panel2
this.Controls.Add(measurementTextBox = new TextBox());
this.Controls.Add(correctionTextBox = new TextBox());
this.Controls.Add(errorTextBox = new TextBox());
+ currentUnit = DefaultUnit;
+ unitComboBox.Text = currentUnit.ToDescription();
+ InitializeColumns(listViewEx, currentUnit);
+ RefreshAll();
+
listViewEx.SubItemClicked += new SubItemEventHandler(listViewEx_SubItemClicked);
listViewEx.SubItemEndEditing += new SubItemEndEditingEventHandler(listViewEx_SubItemEndEditing);
+ unitComboBox.SelectedIndexChanged += new System.EventHandler(this.unitComboBox_SelectedIndexChanged);
+ }
- listViewEx.Columns.Add(new ColumnHeader() { Text = Strings.Nr, Width = 60 });
- listViewEx.Columns.Add(new ColumnHeader() { Text = string.Format("{0} [bar]", Strings.Pressure), Width = 100 });
- listViewEx.Columns.Add(new ColumnHeader() { Text = string.Format("{0} [mbar]", Strings.Correction), Width = 100 });
- listViewEx.Columns.Add(new ColumnHeader() { Text = string.Format("{0} [%]", Strings.Error), Width = 100 });
+ void InitializeColumns(ListView lv, Unit unit)
+ {
+ lv.Columns.Clear();
+ lv.Columns.Add(new ColumnHeader() { Text = Strings.Nr, Width = 60 });
+ lv.Columns.Add(new ColumnHeader() { Text = string.Format("{0} [{1}]", Strings.Pressure, unit.ToDescription()), Width = 100 });
+ lv.Columns.Add(new ColumnHeader() { Text = string.Format("{0} [{1}]", Strings.Correction, unit.ToDescription()), Width = 100 });
+ lv.Columns.Add(new ColumnHeader() { Text = string.Format("{0} [%]", Strings.Error), Width = 100 });
- RefreshAll();
- }
+ measuredLabel.Text = string.Format("{0} [{1}]:", Strings.Measured, unit.ToDescription());
+ correctedLabel.Text = string.Format("{0} [{1}]:", Strings.Corrected, unit.ToDescription());
+ measuredTextBox.Text = string.Empty;
+ correctedTextBox.Text = string.Empty;
+ }
void Localize()
{
componentLabel.Text = Strings.Component;
testGroupBox.Text = Strings.Test_measured_corrected;
- measuredLabel.Text = Strings.Measured;
- correctedLabel.Text = Strings.Corrected;
- measuredTextBox.Text = string.Empty;
- correctedTextBox.Text = string.Empty;
-
calibrationGroupBox.Text = Strings.Calibration;
calibCertificateNrLabel.Text = Strings.Certificate;
calibDateLabel.Text = Strings.Date;
@@ -120,8 +138,12 @@ namespace TBF.UI.Bench.Metrology
int nr = listViewEx.Items.Count + 1;
ListViewItem lvi = new ListViewItem(nr.ToString());
lvi.Tag = corr;
- lvi.SubItems.Add(corr.Measurement.ToString());
- lvi.SubItems.Add((1000 * corr.Correction).ToString());
+ lvi.SubItems.Add(Units.ConvertTo(currentUnit, corr.Measurement).ToString());
+ double trueValue = corr.Measurement + corr.Correction;
+ double difference = Units.IsDefaultUnit(currentUnit)
+ ? corr.Correction
+ : Units.ConvertTo(currentUnit, trueValue) - Units.ConvertTo(currentUnit, corr.Measurement);
+ lvi.SubItems.Add(Common.Utils.ToNiceString(difference, SignifDigits));
if (corr.Measurement == 0)
{
@@ -129,8 +151,8 @@ namespace TBF.UI.Bench.Metrology
}
else
{
- double error = Config.Formulas.ErrorFromVolumes(corr.Measurement, corr.Measurement + corr.Correction);
- lvi.SubItems.Add(error.ToString(Config.Utils.SignificantDigitsToFmt(error, 5)));
+ double error = Config.Formulas.ErrorFromVolumes(corr.Measurement, trueValue);
+ lvi.SubItems.Add(Common.Utils.ToNiceString(error, SignifDigits));
}
listViewEx.Items.Add(lvi);
@@ -167,18 +189,23 @@ namespace TBF.UI.Bench.Metrology
/// true = value parsed OK
bool ParseItem(ListViewItem item, int subItem, string strValue)
{
- double dblValue = 0;
- if (subItem == 1 && Utils.TryParseEDouble(strValue, out dblValue) && dblValue >= 0)
+ double oriMeasurement; /// Measurement in selected units
+ double measurement; /// Measurement in default units
+ double difference; /// Correction in selected unit
+ double correction; /// Correction in default unit
+ double error = 0;
+
+ if (subItem == 1 && Utils.TryParseEDouble(strValue, out oriMeasurement) && (measurement = Units.ConvertFrom(currentUnit, oriMeasurement)) >= 0)
{
- (item.Tag as MeasurementCorrection).Measurement = (float)dblValue;
+ (item.Tag as MeasurementCorrection).Measurement = measurement;
/// Update error (if possible)
- double correction1000;
- if (Utils.TryParseEDouble(item.SubItems[2].Text, out correction1000) && (dblValue != 0))
+ if (Utils.TryParseEDouble(item.SubItems[2].Text, out difference) && (measurement != 0))
{
- double correction = correction1000 / 1000;
- double error = Config.Formulas.ErrorFromVolumes(dblValue, dblValue + correction);
- item.SubItems[3].Text = error.ToString(Config.Utils.SignificantDigitsToFmt(error, 5));
+ correction = Units.IsDefaultUnit(currentUnit) ? difference
+ : Units.ConvertFrom(currentUnit, oriMeasurement + difference) - Units.ConvertFrom(currentUnit, oriMeasurement);
+ error = Config.Formulas.ErrorFromVolumes(measurement, measurement + correction);
+ item.SubItems[3].Text = Common.Utils.ToNiceString(error, SignifDigits);
}
else
{
@@ -187,39 +214,48 @@ namespace TBF.UI.Bench.Metrology
return true;
}
- else if (subItem == 2 && Utils.TryParseEDouble(strValue, out dblValue))
+ else if (subItem == 2 && Utils.TryParseEDouble(strValue, out difference))
{
- double correctionInDefaultUnits = dblValue / 1000;
- (item.Tag as MeasurementCorrection).Correction = (float)correctionInDefaultUnits;
+ if (Utils.TryParseEDouble(item.SubItems[1].Text, out oriMeasurement))
+ {
+ measurement = Units.ConvertFrom(currentUnit, oriMeasurement);
+ correction = Units.IsDefaultUnit(currentUnit) ? difference
+ : Units.ConvertFrom(currentUnit, oriMeasurement + difference) - Units.ConvertFrom(currentUnit, oriMeasurement);
+ (item.Tag as MeasurementCorrection).Correction = correction;
- /// Update error (if possible)
- double measurement;
- if (Utils.TryParseEDouble(item.SubItems[1].Text, out measurement) && (measurement != 0))
- {
- double error = Config.Formulas.ErrorFromVolumes(measurement, measurement + correctionInDefaultUnits);
- item.SubItems[3].Text = error.ToString(Config.Utils.SignificantDigitsToFmt(error, 5));
- }
- else
- {
- item.SubItems[3].Text = Strings.NaN;
- }
+ /// Update error (if possible)
+ if (measurement != 0)
+ {
+ error = Config.Formulas.ErrorFromVolumes(measurement, measurement + correction);
+ item.SubItems[3].Text = Common.Utils.ToNiceString(error, SignifDigits);
+ }
+ else
+ {
+ item.SubItems[3].Text = Strings.NaN;
+ }
- return true;
+ return true;
+ }
+ else
+ {
+ return false;
+ }
}
- else if (subItem == 3 && ((strValue == Strings.NaN) || Utils.TryParseEDouble(strValue, out dblValue)))
+ else if (subItem == 3 && ((strValue == Strings.NaN) || Utils.TryParseEDouble(strValue, out error)))
{
if (strValue == Strings.NaN)
{
}
else
{
- double measurement;
- if (Utils.TryParseEDouble(item.SubItems[1].Text, out measurement) && measurement != 0)
+ if (Utils.TryParseEDouble(item.SubItems[1].Text, out oriMeasurement) && (measurement = Units.ConvertFrom(currentUnit, oriMeasurement)) != 0)
{
- double correction = Config.Formulas.CorrectionFromError(measurement, dblValue);
- double correction1000 = 1000 * correction;
- item.SubItems[2].Text = correction1000.ToString(Config.Utils.SignificantDigitsToFmt(correction1000, 5));
- (item.Tag as MeasurementCorrection).Correction = (float)correction;
+ correction = Config.Formulas.CorrectionFromError(measurement, error);
+ (item.Tag as MeasurementCorrection).Correction = correction;
+ difference = Units.IsDefaultUnit(currentUnit)
+ ? correction
+ : Units.ConvertTo(currentUnit, measurement + correction) - oriMeasurement;
+ item.SubItems[2].Text = Common.Utils.ToNiceString(difference, SignifDigits);
}
}
@@ -349,18 +385,18 @@ namespace TBF.UI.Bench.Metrology
private void measuredTextBox_TextChanged(object sender, EventArgs e)
{
- float measured;
- if (float.TryParse(measuredTextBox.Text,
+ double measured;
+ if (double.TryParse(measuredTextBox.Text,
NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign | NumberStyles.AllowExponent,
CultureInfo.CurrentCulture,
out measured) ||
- float.TryParse(measuredTextBox.Text,
+ double.TryParse(measuredTextBox.Text,
NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign | NumberStyles.AllowExponent,
CultureInfo.InvariantCulture,
out measured))
{
- double corrected = MeasurementCorrection.CorrectedValue(measured, meterEntity.Corrections);
- correctedTextBox.Text = corrected.ToString();
+ double corrected = MeasurementCorrection.CorrectedValue(Units.ConvertFrom(currentUnit, measured), meterEntity.Corrections);
+ correctedTextBox.Text = Units.ConvertTo(currentUnit, corrected).ToString();
}
}
@@ -377,5 +413,20 @@ namespace TBF.UI.Bench.Metrology
{
session.SaveOrUpdate(MeterEntity);
}
+
+ private void unitComboBox_SelectedIndexChanged(object sender, EventArgs e)
+ {
+ for (Unit u = 0; u < Unit.Count; u++)
+ {
+ if (u.ToDescription() == unitComboBox.Text)
+ {
+ currentUnit = u;
+ break;
+ }
+ }
+
+ InitializeColumns(listViewEx, currentUnit);
+ RefreshAll();
+ }
}
}
diff --git a/TBF/UI/Bench/Metrology/MetrologyDlgTempMeterTab.Designer.cs b/TBF/UI/Bench/Metrology/MetrologyDlgTempMeterTab.Designer.cs
index 278383285..1e40e27a9 100644
--- a/TBF/UI/Bench/Metrology/MetrologyDlgTempMeterTab.Designer.cs
+++ b/TBF/UI/Bench/Metrology/MetrologyDlgTempMeterTab.Designer.cs
@@ -32,7 +32,11 @@ namespace TBF.UI.Bench.Metrology
private void InitializeComponent()
{
this.splitContainer1 = new System.Windows.Forms.SplitContainer();
+ this.unitLabel = new System.Windows.Forms.Label();
+ this.unitComboBox = new System.Windows.Forms.ComboBox();
this.calibrationGroupBox = new System.Windows.Forms.GroupBox();
+ this.calibExpirationDateTimePicker = new System.Windows.Forms.DateTimePicker();
+ this.calibDateTimePicker = new System.Windows.Forms.DateTimePicker();
this.calibValidDateLabel = new System.Windows.Forms.Label();
this.calibDateLabel = new System.Windows.Forms.Label();
this.calibCertificateNrTextBox = new System.Windows.Forms.TextBox();
@@ -45,8 +49,6 @@ namespace TBF.UI.Bench.Metrology
this.componentLabel = new System.Windows.Forms.Label();
this.cmpntNameLabel = new System.Windows.Forms.Label();
this.listViewEx = new Common.Forms.ListViewEx();
- this.calibExpirationDateTimePicker = new System.Windows.Forms.DateTimePicker();
- this.calibDateTimePicker = new System.Windows.Forms.DateTimePicker();
((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit();
this.splitContainer1.Panel1.SuspendLayout();
this.splitContainer1.Panel2.SuspendLayout();
@@ -65,6 +67,8 @@ namespace TBF.UI.Bench.Metrology
//
// splitContainer1.Panel1
//
+ this.splitContainer1.Panel1.Controls.Add(this.unitLabel);
+ this.splitContainer1.Panel1.Controls.Add(this.unitComboBox);
this.splitContainer1.Panel1.Controls.Add(this.calibrationGroupBox);
this.splitContainer1.Panel1.Controls.Add(this.testGroupBox);
this.splitContainer1.Panel1.Controls.Add(this.componentLabel);
@@ -73,10 +77,27 @@ namespace TBF.UI.Bench.Metrology
// splitContainer1.Panel2
//
this.splitContainer1.Panel2.Controls.Add(this.listViewEx);
- this.splitContainer1.Size = new System.Drawing.Size(600, 300);
+ this.splitContainer1.Size = new System.Drawing.Size(650, 300);
this.splitContainer1.SplitterDistance = 110;
this.splitContainer1.TabIndex = 2;
//
+ // unitLabel
+ //
+ this.unitLabel.AutoSize = true;
+ this.unitLabel.Location = new System.Drawing.Point(14, 60);
+ this.unitLabel.Name = "unitLabel";
+ this.unitLabel.Size = new System.Drawing.Size(100, 13);
+ this.unitLabel.TabIndex = 8;
+ this.unitLabel.Text = "Unit of temperature:";
+ //
+ // unitComboBox
+ //
+ this.unitComboBox.FormattingEnabled = true;
+ this.unitComboBox.Location = new System.Drawing.Point(123, 57);
+ this.unitComboBox.Name = "unitComboBox";
+ this.unitComboBox.Size = new System.Drawing.Size(62, 21);
+ this.unitComboBox.TabIndex = 1;
+ //
// calibrationGroupBox
//
this.calibrationGroupBox.Controls.Add(this.calibExpirationDateTimePicker);
@@ -92,6 +113,26 @@ namespace TBF.UI.Bench.Metrology
this.calibrationGroupBox.TabStop = false;
this.calibrationGroupBox.Text = "Calibration";
//
+ // calibExpirationDateTimePicker
+ //
+ this.calibExpirationDateTimePicker.CustomFormat = "dd.MM.yyyy";
+ this.calibExpirationDateTimePicker.Enabled = false;
+ this.calibExpirationDateTimePicker.Format = System.Windows.Forms.DateTimePickerFormat.Custom;
+ this.calibExpirationDateTimePicker.Location = new System.Drawing.Point(117, 59);
+ this.calibExpirationDateTimePicker.Name = "calibExpirationDateTimePicker";
+ this.calibExpirationDateTimePicker.Size = new System.Drawing.Size(82, 20);
+ this.calibExpirationDateTimePicker.TabIndex = 19;
+ //
+ // calibDateTimePicker
+ //
+ this.calibDateTimePicker.CustomFormat = "dd.MM.yyyy";
+ this.calibDateTimePicker.Enabled = false;
+ this.calibDateTimePicker.Format = System.Windows.Forms.DateTimePickerFormat.Custom;
+ this.calibDateTimePicker.Location = new System.Drawing.Point(117, 37);
+ this.calibDateTimePicker.Name = "calibDateTimePicker";
+ this.calibDateTimePicker.Size = new System.Drawing.Size(82, 20);
+ this.calibDateTimePicker.TabIndex = 18;
+ //
// calibValidDateLabel
//
this.calibValidDateLabel.AutoSize = true;
@@ -113,7 +154,7 @@ namespace TBF.UI.Bench.Metrology
// calibCertificateNrTextBox
//
this.calibCertificateNrTextBox.Enabled = false;
- this.calibCertificateNrTextBox.Location = new System.Drawing.Point(120, 15);
+ this.calibCertificateNrTextBox.Location = new System.Drawing.Point(117, 15);
this.calibCertificateNrTextBox.Name = "calibCertificateNrTextBox";
this.calibCertificateNrTextBox.Size = new System.Drawing.Size(82, 20);
this.calibCertificateNrTextBox.TabIndex = 11;
@@ -135,14 +176,14 @@ namespace TBF.UI.Bench.Metrology
this.testGroupBox.Controls.Add(this.measuredLabel);
this.testGroupBox.Location = new System.Drawing.Point(428, 12);
this.testGroupBox.Name = "testGroupBox";
- this.testGroupBox.Size = new System.Drawing.Size(157, 86);
+ this.testGroupBox.Size = new System.Drawing.Size(200, 86);
this.testGroupBox.TabIndex = 4;
this.testGroupBox.TabStop = false;
this.testGroupBox.Text = "Test";
//
// correctedTextBox
//
- this.correctedTextBox.Location = new System.Drawing.Point(74, 49);
+ this.correctedTextBox.Location = new System.Drawing.Point(115, 49);
this.correctedTextBox.Name = "correctedTextBox";
this.correctedTextBox.ReadOnly = true;
this.correctedTextBox.Size = new System.Drawing.Size(73, 20);
@@ -150,7 +191,7 @@ namespace TBF.UI.Bench.Metrology
//
// measuredTextBox
//
- this.measuredTextBox.Location = new System.Drawing.Point(74, 24);
+ this.measuredTextBox.Location = new System.Drawing.Point(115, 24);
this.measuredTextBox.Name = "measuredTextBox";
this.measuredTextBox.Size = new System.Drawing.Size(73, 20);
this.measuredTextBox.TabIndex = 4;
@@ -168,7 +209,7 @@ namespace TBF.UI.Bench.Metrology
// measuredLabel
//
this.measuredLabel.AutoSize = true;
- this.measuredLabel.Location = new System.Drawing.Point(6, 31);
+ this.measuredLabel.Location = new System.Drawing.Point(7, 27);
this.measuredLabel.Name = "measuredLabel";
this.measuredLabel.Size = new System.Drawing.Size(54, 13);
this.measuredLabel.TabIndex = 2;
@@ -201,39 +242,19 @@ namespace TBF.UI.Bench.Metrology
this.listViewEx.GridLines = true;
this.listViewEx.Location = new System.Drawing.Point(0, 0);
this.listViewEx.Name = "listViewEx";
- this.listViewEx.Size = new System.Drawing.Size(600, 186);
+ this.listViewEx.Size = new System.Drawing.Size(650, 186);
this.listViewEx.TabIndex = 0;
this.listViewEx.UseCompatibleStateImageBehavior = false;
this.listViewEx.View = System.Windows.Forms.View.Details;
this.listViewEx.SelectedIndexChanged += new System.EventHandler(this.listViewEx_SelectedIndexChanged);
//
- // calibExpirationDateTimePicker
- //
- this.calibExpirationDateTimePicker.CustomFormat = "dd.MM.yyyy";
- this.calibExpirationDateTimePicker.Enabled = false;
- this.calibExpirationDateTimePicker.Format = System.Windows.Forms.DateTimePickerFormat.Custom;
- this.calibExpirationDateTimePicker.Location = new System.Drawing.Point(120, 59);
- this.calibExpirationDateTimePicker.Name = "calibExpirationDateTimePicker";
- this.calibExpirationDateTimePicker.Size = new System.Drawing.Size(82, 20);
- this.calibExpirationDateTimePicker.TabIndex = 19;
- //
- // calibDateTimePicker
- //
- this.calibDateTimePicker.CustomFormat = "dd.MM.yyyy";
- this.calibDateTimePicker.Enabled = false;
- this.calibDateTimePicker.Format = System.Windows.Forms.DateTimePickerFormat.Custom;
- this.calibDateTimePicker.Location = new System.Drawing.Point(120, 37);
- this.calibDateTimePicker.Name = "calibDateTimePicker";
- this.calibDateTimePicker.Size = new System.Drawing.Size(82, 20);
- this.calibDateTimePicker.TabIndex = 18;
- //
// MetrologyDlgTempMeterTab
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this.splitContainer1);
this.Name = "MetrologyDlgTempMeterTab";
- this.Size = new System.Drawing.Size(600, 300);
+ this.Size = new System.Drawing.Size(650, 300);
this.Load += new System.EventHandler(this.MetrologyDlgTempMeterTab_Load);
this.splitContainer1.Panel1.ResumeLayout(false);
this.splitContainer1.Panel1.PerformLayout();
@@ -266,6 +287,8 @@ namespace TBF.UI.Bench.Metrology
private System.Windows.Forms.Label calibCertificateNrLabel;
private System.Windows.Forms.DateTimePicker calibExpirationDateTimePicker;
private System.Windows.Forms.DateTimePicker calibDateTimePicker;
+ private System.Windows.Forms.Label unitLabel;
+ private System.Windows.Forms.ComboBox unitComboBox;
}
}
diff --git a/TBF/UI/Bench/Metrology/MetrologyDlgTempMeterTab.cs b/TBF/UI/Bench/Metrology/MetrologyDlgTempMeterTab.cs
index d702fae10..1eaef544d 100644
--- a/TBF/UI/Bench/Metrology/MetrologyDlgTempMeterTab.cs
+++ b/TBF/UI/Bench/Metrology/MetrologyDlgTempMeterTab.cs
@@ -1,13 +1,14 @@
///
-/// Copyright (c) 2017-2020 Sensus Slovensko a.s.
+/// Copyright (c) 2017-2022 Sensus Slovensko a.s.
///
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Windows.Forms;
using log4net;
-using Config.Entities;
+using Common;
using Common.Forms;
+using Config.Entities;
using TBF.Resources;
using TBF.UI.Shared;
@@ -17,6 +18,9 @@ namespace TBF.UI.Bench.Metrology
{
static readonly ILog log = LogManager.GetLogger(typeof(MetrologyDlgTempMeterTab));
+ public const Unit DefaultUnit = Unit.C;
+ public const int SignifDigits = 5;
+
///
/// Component entity that has a list of 'measurement-correction' pairs
/// to be updated in the database on OK.
@@ -29,7 +33,7 @@ namespace TBF.UI.Bench.Metrology
}
///
- /// Balance configuration (with buoyancy parameters)
+ /// Calibration information configuration
///
public Rig.GenericDevices.ICalibInfoCfg CalibInfoCfg;
@@ -49,6 +53,8 @@ namespace TBF.UI.Bench.Metrology
Control correctionTextBox;
Control errorTextBox;
+ Unit currentUnit;
+
public MetrologyDlgTempMeterTab()
{
InitializeComponent();
@@ -57,8 +63,8 @@ namespace TBF.UI.Bench.Metrology
calibExpirationDateTimePicker.CustomFormat = Constants.DateFormat;
calibExpirationDateTimePicker.MinDate = Constants.MinDate;
toBeRemoved = new List();
- unlocked = false;
- }
+ unlocked = false;
+ }
private void MetrologyDlgTempMeterTab_Load(object sender, System.EventArgs e)
{
@@ -71,31 +77,43 @@ namespace TBF.UI.Bench.Metrology
/// Panel1
cmpntNameLabel.Text = meterEntity.Name;
+ for (Unit u = 0; u < Unit.Count; u++)
+ if (Units.IsTemperature(u))
+ unitComboBox.Items.Add(u.ToDescription());
+
/// Panel2
this.Controls.Add(measurementTextBox = new TextBox());
this.Controls.Add(correctionTextBox = new TextBox());
this.Controls.Add(errorTextBox = new TextBox());
+ currentUnit = DefaultUnit;
+ unitComboBox.Text = currentUnit.ToDescription();
+ InitializeColumns(listViewEx, currentUnit);
+ RefreshAll();
+
listViewEx.SubItemClicked += new SubItemEventHandler(listViewEx_SubItemClicked);
listViewEx.SubItemEndEditing += new SubItemEndEditingEventHandler(listViewEx_SubItemEndEditing);
-
- listViewEx.Columns.Add(new ColumnHeader() { Text = Strings.Nr, Width = 40 });
- listViewEx.Columns.Add(new ColumnHeader() { Text = string.Format("{0} [°C]", Strings.Temperature), Width = 120 });
- listViewEx.Columns.Add(new ColumnHeader() { Text = string.Format("{0} [1/1000 °C]", Strings.Correction), Width = 150 });
- listViewEx.Columns.Add(new ColumnHeader() { Text = string.Format("{0} [%]", Strings.Error), Width = 100 });
-
- RefreshAll();
+ unitComboBox.SelectedIndexChanged += new System.EventHandler(unitComboBox_SelectedIndexChanged);
}
+ void InitializeColumns(ListView lv, Unit unit)
+ {
+ lv.Columns.Clear();
+ lv.Columns.Add(new ColumnHeader() { Text = Strings.Nr, Width = 40 });
+ lv.Columns.Add(new ColumnHeader() { Text = string.Format("{0} [{1}]", Strings.Temperature, unit.ToDescription()), Width = 120 });
+ lv.Columns.Add(new ColumnHeader() { Text = string.Format("{0} [{1}]", Strings.Correction, unit.ToDescription()), Width = 150 });
+ lv.Columns.Add(new ColumnHeader() { Text = string.Format("{0} [%]", Strings.Error), Width = 100 });
+
+ measuredLabel.Text = string.Format("{0} [{1}]:", Strings.Measured, unit.ToDescription());
+ correctedLabel.Text = string.Format("{0} [{1}]:", Strings.Corrected, unit.ToDescription());
+ measuredTextBox.Text = string.Empty;
+ correctedTextBox.Text = string.Empty;
+ }
+
void Localize()
{
componentLabel.Text = Strings.Component;
testGroupBox.Text = Strings.Test_measured_corrected;
- measuredLabel.Text = Strings.Measured;
- correctedLabel.Text = Strings.Corrected;
- measuredTextBox.Text = string.Empty;
- correctedTextBox.Text = string.Empty;
-
calibrationGroupBox.Text = Strings.Calibration;
calibCertificateNrLabel.Text = Strings.Certificate;
calibDateLabel.Text = Strings.Date;
@@ -111,7 +129,7 @@ namespace TBF.UI.Bench.Metrology
calibExpirationDateTimePicker.Value = (CalibInfoCfg.CalibValidDate < Constants.MinDate) ? Constants.MinDate : CalibInfoCfg.CalibValidDate;
}
- listViewEx.Items.Clear();
+ listViewEx.Items.Clear();
foreach (var corr in MeterEntity.Corrections) AddOneLVI(corr);
}
@@ -120,8 +138,12 @@ namespace TBF.UI.Bench.Metrology
int nr = listViewEx.Items.Count + 1;
ListViewItem lvi = new ListViewItem(nr.ToString());
lvi.Tag = corr;
- lvi.SubItems.Add(corr.Measurement.ToString());
- lvi.SubItems.Add((1000 * corr.Correction).ToString());
+ lvi.SubItems.Add(Units.ConvertTo(currentUnit, corr.Measurement).ToString());
+ double trueValue = corr.Measurement + corr.Correction;
+ double difference = Units.IsDefaultUnit(currentUnit)
+ ? corr.Correction
+ : Units.ConvertTo(currentUnit, trueValue) - Units.ConvertTo(currentUnit, corr.Measurement);
+ lvi.SubItems.Add(Common.Utils.ToNiceString(difference, SignifDigits));
if (corr.Measurement == 0)
{
@@ -129,8 +151,8 @@ namespace TBF.UI.Bench.Metrology
}
else
{
- double error = Config.Formulas.ErrorFromVolumes(corr.Measurement, corr.Measurement + corr.Correction);
- lvi.SubItems.Add(error.ToString(Config.Utils.SignificantDigitsToFmt(error, 5)));
+ double error = Config.Formulas.ErrorFromVolumes(corr.Measurement, trueValue);
+ lvi.SubItems.Add(Common.Utils.ToNiceString(error, SignifDigits));
}
listViewEx.Items.Add(lvi);
@@ -167,18 +189,23 @@ namespace TBF.UI.Bench.Metrology
/// true = value parsed OK
bool ParseItem(ListViewItem item, int subItem, string strValue)
{
- double dblValue = 0;
- if (subItem == 1 && Utils.TryParseEDouble(strValue, out dblValue) && dblValue >= 0)
+ double oriMeasurement; /// Measurement in selected units
+ double measurement; /// Measurement in default units
+ double difference; /// Correction in selected unit
+ double correction; /// Correction in default unit
+ double error = 0;
+
+ if (subItem == 1 && Utils.TryParseEDouble(strValue, out oriMeasurement) && (measurement = Units.ConvertFrom(currentUnit, oriMeasurement)) >= 0)
{
- (item.Tag as MeasurementCorrection).Measurement = (float)dblValue;
+ (item.Tag as MeasurementCorrection).Measurement = measurement;
/// Update error (if possible)
- double correction1000;
- if (Utils.TryParseEDouble(item.SubItems[2].Text, out correction1000) && (dblValue != 0))
+ if (Utils.TryParseEDouble(item.SubItems[2].Text, out difference) && (measurement != 0))
{
- double correction = correction1000 / 1000;
- double error = Config.Formulas.ErrorFromVolumes(dblValue, dblValue + correction);
- item.SubItems[3].Text = error.ToString(Config.Utils.SignificantDigitsToFmt(error, 5));
+ correction = Units.IsDefaultUnit(currentUnit) ? difference
+ : Units.ConvertFrom(currentUnit, oriMeasurement + difference) - Units.ConvertFrom(currentUnit, oriMeasurement);
+ error = Config.Formulas.ErrorFromVolumes(measurement, measurement + correction);
+ item.SubItems[3].Text = Common.Utils.ToNiceString(error, SignifDigits);
}
else
{
@@ -187,39 +214,48 @@ namespace TBF.UI.Bench.Metrology
return true;
}
- else if (subItem == 2 && Utils.TryParseEDouble(strValue, out dblValue))
+ else if (subItem == 2 && Utils.TryParseEDouble(strValue, out difference))
{
- double correctionInDefaultUnits = dblValue / 1000;
- (item.Tag as MeasurementCorrection).Correction = (float)correctionInDefaultUnits;
+ if (Utils.TryParseEDouble(item.SubItems[1].Text, out oriMeasurement))
+ {
+ measurement = Units.ConvertFrom(currentUnit, oriMeasurement);
+ correction = Units.IsDefaultUnit(currentUnit) ? difference
+ : Units.ConvertFrom(currentUnit, oriMeasurement + difference) - Units.ConvertFrom(currentUnit, oriMeasurement);
+ (item.Tag as MeasurementCorrection).Correction = correction;
- /// Update error (if possible)
- double measurement;
- if (Utils.TryParseEDouble(item.SubItems[1].Text, out measurement) && (measurement != 0))
- {
- double error = Config.Formulas.ErrorFromVolumes(measurement, measurement + correctionInDefaultUnits);
- item.SubItems[3].Text = error.ToString(Config.Utils.SignificantDigitsToFmt(error, 5));
- }
- else
- {
- item.SubItems[3].Text = Strings.NaN;
- }
+ /// Update error (if possible)
+ if (measurement != 0)
+ {
+ error = Config.Formulas.ErrorFromVolumes(measurement, measurement + correction);
+ item.SubItems[3].Text = Common.Utils.ToNiceString(error, SignifDigits);
+ }
+ else
+ {
+ item.SubItems[3].Text = Strings.NaN;
+ }
- return true;
+ return true;
+ }
+ else
+ {
+ return false;
+ }
}
- else if (subItem == 3 && ((strValue == Strings.NaN) || Utils.TryParseEDouble(strValue, out dblValue)))
+ else if (subItem == 3 && ((strValue == Strings.NaN) || Utils.TryParseEDouble(strValue, out error)))
{
if (strValue == Strings.NaN)
{
}
else
{
- double measurement;
- if (Utils.TryParseEDouble(item.SubItems[1].Text, out measurement) && measurement != 0)
+ if (Utils.TryParseEDouble(item.SubItems[1].Text, out oriMeasurement) && (measurement = Units.ConvertFrom(currentUnit, oriMeasurement)) != 0)
{
- double correction = Config.Formulas.CorrectionFromError(measurement, dblValue);
- double correction1000 = 1000 * correction;
- item.SubItems[2].Text = correction1000.ToString(Config.Utils.SignificantDigitsToFmt(correction1000, 5));
- (item.Tag as MeasurementCorrection).Correction = (float)correction;
+ correction = Config.Formulas.CorrectionFromError(measurement, error);
+ (item.Tag as MeasurementCorrection).Correction = correction;
+ difference = Units.IsDefaultUnit(currentUnit)
+ ? correction
+ : Units.ConvertTo(currentUnit, measurement + correction) - oriMeasurement;
+ item.SubItems[2].Text = Common.Utils.ToNiceString(difference, SignifDigits);
}
}
@@ -349,18 +385,18 @@ namespace TBF.UI.Bench.Metrology
private void measuredTextBox_TextChanged(object sender, EventArgs e)
{
- float measured;
- if (float.TryParse(measuredTextBox.Text,
+ double measured;
+ if (double.TryParse(measuredTextBox.Text,
NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign | NumberStyles.AllowExponent,
CultureInfo.CurrentCulture,
out measured) ||
- float.TryParse(measuredTextBox.Text,
+ double.TryParse(measuredTextBox.Text,
NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign | NumberStyles.AllowExponent,
CultureInfo.InvariantCulture,
out measured))
{
- double corrected = MeasurementCorrection.CorrectedValue(measured, meterEntity.Corrections);
- correctedTextBox.Text = corrected.ToString();
+ double corrected = MeasurementCorrection.CorrectedValue(Units.ConvertFrom(currentUnit, measured), meterEntity.Corrections);
+ correctedTextBox.Text = Units.ConvertTo(currentUnit, corrected).ToString();
}
}
@@ -377,5 +413,20 @@ namespace TBF.UI.Bench.Metrology
{
session.SaveOrUpdate(MeterEntity);
}
+
+ private void unitComboBox_SelectedIndexChanged(object sender, EventArgs e)
+ {
+ for (Unit u = 0; u < Unit.Count; u++)
+ {
+ if (u.ToDescription() == unitComboBox.Text)
+ {
+ currentUnit = u;
+ break;
+ }
+ }
+
+ InitializeColumns(listViewEx, currentUnit);
+ RefreshAll();
+ }
}
}
diff --git a/TBF/UI/Graphs/GraphsTabPageCtrl.cs b/TBF/UI/Graphs/GraphsTabPageCtrl.cs
index 55cee9bcb..610d9e78c 100644
--- a/TBF/UI/Graphs/GraphsTabPageCtrl.cs
+++ b/TBF/UI/Graphs/GraphsTabPageCtrl.cs
@@ -347,7 +347,7 @@ namespace TBF.UI.Graphs
private string RenderYLabel(DataSource s, float value)
{
- return value.ToString(Config.Utils.SignificantDigitsToFmt(value, 2));
+ return value.ToString(Common.Utils.SignificantDigitsToFmt(value, 2));
}
private void checkBox1_CheckedChanged(object sender, EventArgs e) { Program.LocalSettings.Graph1_On = checkBox1.Checked; AnyCBChanged(); }
diff --git a/TBF/UI/Procedures/TestWizard/OracleWZTypSelection.cs b/TBF/UI/Procedures/TestWizard/OracleWZTypSelection.cs
index d42fec4a0..35c71c336 100644
--- a/TBF/UI/Procedures/TestWizard/OracleWZTypSelection.cs
+++ b/TBF/UI/Procedures/TestWizard/OracleWZTypSelection.cs
@@ -1,5 +1,5 @@
///
-/// Copyright (c) 2019 Sensus Slovensko a.s.
+/// Copyright (c) 2019-2022 Sensus Slovensko a.s.
///
using System;
using System.Collections.Generic;
@@ -277,7 +277,7 @@ namespace TBF.UI.Procedures.TestWizard
Qfrom.ToString(),
Qto.ToString(),
ti.TestTime.ToString(),
- volumeLtr.ToString(Config.Utils.SignificantDigitsToFmt(volumeLtr, 4)),
+ volumeLtr.ToString(Common.Utils.SignificantDigitsToFmt(volumeLtr, 4)),
(ti.ErrLimLoFromDB - ti.Uncertainty).ToString(),
(ti.ErrLimHiFromDB + ti.Uncertainty).ToString(),
ti.Uncertainty.ToString(),
diff --git a/TBF/Utils.cs b/TBF/Utils.cs
index bae640230..cbecb5a8c 100644
--- a/TBF/Utils.cs
+++ b/TBF/Utils.cs
@@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
using System.Globalization;
+using System.IO.Ports;
using System.Linq;
using System.Text;
using Config.Entities;
@@ -316,7 +317,7 @@ namespace TBF
}
else if (significantDigits <= 5)
{
- string fmt = Config.Utils.SignificantDigitsToFmt(value, significantDigits);
+ string fmt = Common.Utils.SignificantDigitsToFmt(value, significantDigits);
return altCulture ? value.ToString(fmt, Program.AltCulture) : value.ToString(fmt);
}
else
@@ -357,5 +358,33 @@ namespace TBF
!fname.Contains('>') &&
!fname.Contains('|');
}
- }
+
+ public static Parity GetParity(string str, Parity defaultParity = Parity.None)
+ {
+ if (str.Equals(Parity.None.ToString())) return Parity.None;
+ if (str.Equals(Parity.Even.ToString())) return Parity.Even;
+ if (str.Equals(Parity.Odd.ToString())) return Parity.Odd;
+ if (str.Equals(Parity.Mark.ToString())) return Parity.Mark;
+ if (str.Equals(Parity.Space.ToString())) return Parity.Space;
+ return defaultParity;
+ }
+
+ public static StopBits GetStopBits(string str, StopBits defaultStopBits = StopBits.One)
+ {
+ if (str.Equals(StopBits.None.ToString())) return StopBits.None;
+ if (str.Equals(StopBits.One.ToString())) return StopBits.One;
+ if (str.Equals(StopBits.OnePointFive.ToString())) return StopBits.OnePointFive;
+ if (str.Equals(StopBits.Two.ToString())) return StopBits.Two;
+ return defaultStopBits;
+ }
+
+ public static Handshake GetHandshake(string str, Handshake defaultHandshake = Handshake.None)
+ {
+ if (str.Equals(Handshake.None.ToString())) return Handshake.None;
+ if (str.Equals(Handshake.RequestToSend.ToString())) return Handshake.RequestToSend;
+ if (str.Equals(Handshake.XOnXOff.ToString())) return Handshake.XOnXOff;
+ if (str.Equals(Handshake.RequestToSendXOnXOff.ToString())) return Handshake.RequestToSendXOnXOff;
+ return defaultHandshake;
+ }
+ }
}