diff --git a/Config/Formulas.cs b/Config/Formulas.cs index 5730085a5..ba6199e50 100644 --- a/Config/Formulas.cs +++ b/Config/Formulas.cs @@ -221,45 +221,60 @@ namespace Config return error; } - /// - /// Calculates corrected value form a list of corrections by interpolation. - /// It is assumed that values in the list 'corrections' are sorted. - /// - /// Raw uncorrected value - /// Sorted (value, correction) pairs - /// Corrected value - public static double CorrectedValue(double rawValue, IList corrections) - { - if (corrections == null || corrections.Count == 0) return rawValue; - if (rawValue < corrections[0].Measurement) - { - return rawValue + corrections[0].Correction; - } + /// + /// Calculates corrected value from a list of corrections by interpolation. + /// It is assumed that values in the list 'corrections' are sorted. + /// + /// Raw uncorrected value + /// Sorted (value, correction) pairs + /// Corrected value + public static double CorrectedValue(double rawValue, IList corrections) + { + return rawValue + GetCorrection(rawValue, corrections); + } - int count = corrections.Count; - for (int i = 1; i < count; i++) - { - if (rawValue < corrections[i].Measurement) - { - double d1 = rawValue - corrections[i-1].Measurement; - double d2 = corrections[i].Measurement - rawValue; + /// + /// Get a correction from a list of corrections by interpolation. + /// It is assumed that values in the list 'corrections' are sorted. + /// + /// Raw uncorrected value + /// Sorted (value, correction) pairs + /// Corrected value + public static double GetCorrection(double rawValue, IList corrections) + { + if ((corrections == null) || (corrections.Count == 0)) return 0; /// No correction - double corr; - if (d1 + d2 <= float.Epsilon) - { - corr = (corrections[i - 1].Correction + corrections[i].Correction) / 2.0; - } - else - { - corr = (corrections[i - 1].Correction * d2 + corrections[i].Correction * d1) / (d1 + d2); - } - return rawValue + corr; - } - } + if (rawValue < corrections[0].Measurement) + { + /// rawValue is below the lowest value in the correction table + return corrections[0].Correction; + } - return rawValue + corrections[count - 1].Correction; - } + int count = corrections.Count; + for (int i = 1; i < count; i++) + { + if (rawValue < corrections[i].Measurement) + { + double d1 = rawValue - corrections[i - 1].Measurement; + double d2 = corrections[i].Measurement - rawValue; + + if (d1 + d2 <= float.Epsilon) + { + /// Neigboring values in the corection table are close to each other -> calculate the average + return (corrections[i - 1].Correction + corrections[i].Correction) / 2.0; + } + else + { + /// Interpolate the correction from neigboring values in the corection table + return (corrections[i - 1].Correction * d2 + corrections[i].Correction * d1) / (d1 + d2); + } + } + } + + /// rawValue is above the highest value in the correction table + return corrections[count - 1].Correction; + } /// diff --git a/TBF/BenchControl/Dummy/Diverter/Component.cs b/TBF/BenchControl/Dummy/Diverter/Component.cs index 6794d0911..b159c6c40 100644 --- a/TBF/BenchControl/Dummy/Diverter/Component.cs +++ b/TBF/BenchControl/Dummy/Diverter/Component.cs @@ -32,5 +32,10 @@ namespace TBF.BenchControl.Dummy.Diverter public int ThresholdGate { get { return 50; } } public int ThresholdLo { get { return 10; } } public int ThresholdHi { get { return 90; } } + + public double TestTimeCorrection(double flow) + { + return 0; + } } } diff --git a/TBF/BenchControl/Elde/Diverter/Diverter.cs b/TBF/BenchControl/Elde/Diverter/Diverter.cs index 55e80b27e..3a727e7f7 100644 --- a/TBF/BenchControl/Elde/Diverter/Diverter.cs +++ b/TBF/BenchControl/Elde/Diverter/Diverter.cs @@ -46,6 +46,15 @@ namespace TBF.BenchControl.Elde.Diverter public int ThresholdHi { get { return diverterCfg.ThresholdHi; } } + /// + /// For a given flow in [m3/h] returns a test time correction in [s] + /// + public double TestTimeCorrection(double flow) + { + return Config.Formulas.GetCorrection(flow, Corrections); + } + + public Diverter() { } diff --git a/TBF/BenchControl/GenericDevices/IDiverter.cs b/TBF/BenchControl/GenericDevices/IDiverter.cs index 1eacfd490..75140c742 100644 --- a/TBF/BenchControl/GenericDevices/IDiverter.cs +++ b/TBF/BenchControl/GenericDevices/IDiverter.cs @@ -1,5 +1,5 @@ /// -/// Copyright (c) 2013-2015 Sensus Metering Systems +/// Copyright (c) 2013-2019 Sensus Slovensko a.s. /// using TBF.BenchControl.Generic; @@ -32,5 +32,12 @@ namespace TBF.BenchControl.GenericDevices /// Threshold for high level when diverter transition time is measured in %, 0..100 /// int ThresholdHi { get; } + + /// + /// For a given flow in [m3/h] returns a test time correction in [s] + /// + /// Flow in [m3/h] + /// Test time correction in [s] + double TestTimeCorrection(double flow); } } diff --git a/TBF/MetrologyDlg.cs b/TBF/MetrologyDlg.cs index f2ccc2837..6bc974012 100644 --- a/TBF/MetrologyDlg.cs +++ b/TBF/MetrologyDlg.cs @@ -67,7 +67,7 @@ namespace TBF { BenchControl.Generic.IComponentFactory factory = TbfComponents.CmpntFactoryFromClassName(cmpnt.ClassName); - /// Balance tab-pages + /// Tab-pages for scales if (factory is BenchControl.MettlerToledo.Standard.BalanceFactory || factory is BenchControl.MettlerToledo.Standard.BalanceOldFactory || factory is BenchControl.MettlerToledo.Standard.BalanceNewFactory || @@ -84,21 +84,7 @@ namespace TBF metrologyTabControl.TabPages.Add(tabPage); } - /// Level meters for tanks tab-pages - if (factory is BenchControl.Hart.Nivotrack.Factory) - { - levelMetersCount++; - TabPage tabPage = new TabPage(" " + cmpnt.Name + " "); - MetrologyDlgLevelMeterTab uiControl = new MetrologyDlgLevelMeterTab(); - uiControl.MeterEntity = cmpnt; - uiControl.CalibInfoCfg = factory.CmpntCfgFromCmpntEntity(cmpnt) as BenchControl.GenericDevices.ICalibInfoCfg; - uiControl.Dock = DockStyle.Fill; - tabPage.Tag = uiControl; - tabPage.Controls.Add(uiControl); - metrologyTabControl.TabPages.Add(tabPage); - } - - /// Flowmeter tab-pages + /// Tab-pages for flowmeters if (factory is BenchControl.Elde.FlowMeter.FlowMeterFactory) { BenchControl.Elde.FlowMeter.FlowMeterCfg flowMeterCfg = factory.CmpntCfgFromCmpntEntity(cmpnt) as BenchControl.Elde.FlowMeter.FlowMeterCfg; @@ -120,7 +106,7 @@ namespace TBF } } - /// Pressure meter tab-pages + /// Tab-pages for pressure meters if (factory is BenchControl.Elde.PressureMeter.PressureMeterFactory || factory is BenchControl.Elde.PressureMeterInternal.PressureMeterFactory || factory is BenchControl.Modbus.PressureMeter.Meret.Factory) @@ -135,7 +121,7 @@ namespace TBF metrologyTabControl.TabPages.Add(tabPage); } - /// Temperature meter tab-pages + /// Tab-pages for temperature meters if (factory is BenchControl.Elde.TempMeter.TempMeterFactory || factory is BenchControl.Elde.TempMeterInternal.TempMeterFactory) { @@ -149,7 +135,7 @@ namespace TBF metrologyTabControl.TabPages.Add(tabPage); } - /// Platinum resistance temperature meter tab-pages + /// Tab-pages for platinum resistance temperature meters if (factory is BenchControl.Keithley.TempMeter.Factory) { platinumTempMetersCount++; @@ -162,6 +148,34 @@ namespace TBF tabPage.Controls.Add(uiControl); metrologyTabControl.TabPages.Add(tabPage); } + + /// Tab-pages for diverters + if (factory is BenchControl.Elde.Diverter.DiverterFactory) + { + levelMetersCount++; + TabPage tabPage = new TabPage(" " + cmpnt.Name + " "); + MetrologyDlgDiverterTab uiControl = new MetrologyDlgDiverterTab(); + uiControl.MeterEntity = cmpnt; + uiControl.CalibInfoCfg = factory.CmpntCfgFromCmpntEntity(cmpnt) as BenchControl.GenericDevices.ICalibInfoCfg; + uiControl.Dock = DockStyle.Fill; + tabPage.Tag = uiControl; + tabPage.Controls.Add(uiControl); + metrologyTabControl.TabPages.Add(tabPage); + } + + /// Tab-pages for level meters inside water tanks + if (factory is BenchControl.Hart.Nivotrack.Factory) + { + levelMetersCount++; + TabPage tabPage = new TabPage(" " + cmpnt.Name + " "); + MetrologyDlgLevelMeterTab uiControl = new MetrologyDlgLevelMeterTab(); + uiControl.MeterEntity = cmpnt; + uiControl.CalibInfoCfg = factory.CmpntCfgFromCmpntEntity(cmpnt) as BenchControl.GenericDevices.ICalibInfoCfg; + uiControl.Dock = DockStyle.Fill; + tabPage.Tag = uiControl; + tabPage.Controls.Add(uiControl); + metrologyTabControl.TabPages.Add(tabPage); + } } } diff --git a/TBF/TBF.csproj b/TBF/TBF.csproj index a596e1430..0e831b0f4 100644 --- a/TBF/TBF.csproj +++ b/TBF/TBF.csproj @@ -2236,6 +2236,12 @@ MetrologyDlgDensityTab.cs + + UserControl + + + MetrologyDlgDiverterTab.cs + UserControl @@ -3181,6 +3187,9 @@ MetrologyDlgDensityTab.cs + + MetrologyDlgDiverterTab.cs + MetrologyDlgFlowMeterTab.cs diff --git a/TBF/UiControls/MetrologyDlgDiverterTab.Designer.cs b/TBF/UiControls/MetrologyDlgDiverterTab.Designer.cs new file mode 100644 index 000000000..85f1272c5 --- /dev/null +++ b/TBF/UiControls/MetrologyDlgDiverterTab.Designer.cs @@ -0,0 +1,291 @@ +/// +/// Copyright (c) 2019 Sensus Slovensko a.s. +/// +namespace TBF.UiControls +{ + partial class MetrologyDlgDiverterTab + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Component Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.splitContainer1 = new System.Windows.Forms.SplitContainer(); + this.calibrationGroupBox = new System.Windows.Forms.GroupBox(); + this.calibValidDateTextBox = new System.Windows.Forms.TextBox(); + this.calibValidDateLabel = new System.Windows.Forms.Label(); + this.calibDateTextBox = new System.Windows.Forms.TextBox(); + this.calibDateLabel = new System.Windows.Forms.Label(); + this.calibCertificateNrTextBox = new System.Windows.Forms.TextBox(); + this.calibCertificateNrLabel = new System.Windows.Forms.Label(); + this.nameGroupBox = new System.Windows.Forms.GroupBox(); + this.pressFromToLabel = new System.Windows.Forms.Label(); + this.tempFromToLabel = new System.Windows.Forms.Label(); + this.cmpntNameLabel = new System.Windows.Forms.Label(); + this.testGroupBox = new System.Windows.Forms.GroupBox(); + this.correctedTextBox = new System.Windows.Forms.TextBox(); + this.measuredTextBox = new System.Windows.Forms.TextBox(); + this.correctedLabel = new System.Windows.Forms.Label(); + this.measuredLabel = new System.Windows.Forms.Label(); + this.listViewEx = new Results.Forms.ListViewEx(); + ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit(); + this.splitContainer1.Panel1.SuspendLayout(); + this.splitContainer1.Panel2.SuspendLayout(); + this.splitContainer1.SuspendLayout(); + this.calibrationGroupBox.SuspendLayout(); + this.nameGroupBox.SuspendLayout(); + this.testGroupBox.SuspendLayout(); + this.SuspendLayout(); + // + // splitContainer1 + // + this.splitContainer1.Dock = System.Windows.Forms.DockStyle.Fill; + this.splitContainer1.FixedPanel = System.Windows.Forms.FixedPanel.Panel1; + this.splitContainer1.Location = new System.Drawing.Point(0, 0); + this.splitContainer1.Name = "splitContainer1"; + this.splitContainer1.Orientation = System.Windows.Forms.Orientation.Horizontal; + // + // splitContainer1.Panel1 + // + this.splitContainer1.Panel1.Controls.Add(this.calibrationGroupBox); + this.splitContainer1.Panel1.Controls.Add(this.nameGroupBox); + this.splitContainer1.Panel1.Controls.Add(this.testGroupBox); + // + // splitContainer1.Panel2 + // + this.splitContainer1.Panel2.Controls.Add(this.listViewEx); + this.splitContainer1.Size = new System.Drawing.Size(650, 400); + this.splitContainer1.SplitterDistance = 102; + this.splitContainer1.TabIndex = 2; + // + // calibrationGroupBox + // + this.calibrationGroupBox.Controls.Add(this.calibValidDateTextBox); + this.calibrationGroupBox.Controls.Add(this.calibValidDateLabel); + this.calibrationGroupBox.Controls.Add(this.calibDateTextBox); + this.calibrationGroupBox.Controls.Add(this.calibDateLabel); + this.calibrationGroupBox.Controls.Add(this.calibCertificateNrTextBox); + this.calibrationGroupBox.Controls.Add(this.calibCertificateNrLabel); + this.calibrationGroupBox.Location = new System.Drawing.Point(186, 10); + this.calibrationGroupBox.Name = "calibrationGroupBox"; + this.calibrationGroupBox.Size = new System.Drawing.Size(228, 86); + this.calibrationGroupBox.TabIndex = 7; + this.calibrationGroupBox.TabStop = false; + this.calibrationGroupBox.Text = "Calibration"; + // + // calibValidDateTextBox + // + this.calibValidDateTextBox.Enabled = false; + this.calibValidDateTextBox.Location = new System.Drawing.Point(140, 59); + this.calibValidDateTextBox.Name = "calibValidDateTextBox"; + this.calibValidDateTextBox.Size = new System.Drawing.Size(82, 20); + this.calibValidDateTextBox.TabIndex = 15; + // + // calibValidDateLabel + // + this.calibValidDateLabel.AutoSize = true; + this.calibValidDateLabel.Location = new System.Drawing.Point(17, 62); + this.calibValidDateLabel.Name = "calibValidDateLabel"; + this.calibValidDateLabel.Size = new System.Drawing.Size(52, 13); + this.calibValidDateLabel.TabIndex = 14; + this.calibValidDateLabel.Text = "Valid until"; + // + // calibDateTextBox + // + this.calibDateTextBox.Enabled = false; + this.calibDateTextBox.Location = new System.Drawing.Point(140, 37); + this.calibDateTextBox.Name = "calibDateTextBox"; + this.calibDateTextBox.Size = new System.Drawing.Size(82, 20); + this.calibDateTextBox.TabIndex = 13; + // + // calibDateLabel + // + this.calibDateLabel.AutoSize = true; + this.calibDateLabel.Location = new System.Drawing.Point(17, 40); + this.calibDateLabel.Name = "calibDateLabel"; + this.calibDateLabel.Size = new System.Drawing.Size(30, 13); + this.calibDateLabel.TabIndex = 12; + this.calibDateLabel.Text = "Date"; + // + // calibCertificateNrTextBox + // + this.calibCertificateNrTextBox.Enabled = false; + this.calibCertificateNrTextBox.Location = new System.Drawing.Point(140, 15); + this.calibCertificateNrTextBox.Name = "calibCertificateNrTextBox"; + this.calibCertificateNrTextBox.Size = new System.Drawing.Size(82, 20); + this.calibCertificateNrTextBox.TabIndex = 11; + // + // calibCertificateNrLabel + // + this.calibCertificateNrLabel.AutoSize = true; + this.calibCertificateNrLabel.Location = new System.Drawing.Point(17, 18); + this.calibCertificateNrLabel.Name = "calibCertificateNrLabel"; + this.calibCertificateNrLabel.Size = new System.Drawing.Size(69, 13); + this.calibCertificateNrLabel.TabIndex = 10; + this.calibCertificateNrLabel.Text = "Certificate nr."; + // + // nameGroupBox + // + this.nameGroupBox.Controls.Add(this.pressFromToLabel); + this.nameGroupBox.Controls.Add(this.tempFromToLabel); + 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.TabIndex = 5; + this.nameGroupBox.TabStop = false; + this.nameGroupBox.Text = "Component"; + // + // pressFromToLabel + // + this.pressFromToLabel.AutoSize = true; + this.pressFromToLabel.Location = new System.Drawing.Point(14, 62); + this.pressFromToLabel.Name = "pressFromToLabel"; + this.pressFromToLabel.Size = new System.Drawing.Size(0, 13); + this.pressFromToLabel.TabIndex = 2; + // + // tempFromToLabel + // + this.tempFromToLabel.AutoSize = true; + this.tempFromToLabel.Location = new System.Drawing.Point(14, 44); + this.tempFromToLabel.Name = "tempFromToLabel"; + this.tempFromToLabel.Size = new System.Drawing.Size(0, 13); + this.tempFromToLabel.TabIndex = 1; + // + // cmpntNameLabel + // + this.cmpntNameLabel.AutoSize = true; + this.cmpntNameLabel.Location = new System.Drawing.Point(43, 22); + this.cmpntNameLabel.Name = "cmpntNameLabel"; + this.cmpntNameLabel.Size = new System.Drawing.Size(64, 13); + this.cmpntNameLabel.TabIndex = 0; + this.cmpntNameLabel.Text = "cmpntName"; + // + // testGroupBox + // + this.testGroupBox.Controls.Add(this.correctedTextBox); + this.testGroupBox.Controls.Add(this.measuredTextBox); + this.testGroupBox.Controls.Add(this.correctedLabel); + this.testGroupBox.Controls.Add(this.measuredLabel); + this.testGroupBox.Location = new System.Drawing.Point(424, 10); + this.testGroupBox.Name = "testGroupBox"; + this.testGroupBox.Size = new System.Drawing.Size(170, 88); + this.testGroupBox.TabIndex = 4; + this.testGroupBox.TabStop = false; + this.testGroupBox.Text = "Correction test"; + // + // correctedTextBox + // + this.correctedTextBox.Location = new System.Drawing.Point(91, 37); + this.correctedTextBox.Name = "correctedTextBox"; + this.correctedTextBox.ReadOnly = true; + this.correctedTextBox.Size = new System.Drawing.Size(73, 20); + this.correctedTextBox.TabIndex = 5; + // + // measuredTextBox + // + this.measuredTextBox.Location = new System.Drawing.Point(91, 15); + this.measuredTextBox.Name = "measuredTextBox"; + this.measuredTextBox.Size = new System.Drawing.Size(73, 20); + this.measuredTextBox.TabIndex = 4; + this.measuredTextBox.TextChanged += new System.EventHandler(this.measuredTextBox_TextChanged); + // + // correctedLabel + // + this.correctedLabel.AutoSize = true; + this.correctedLabel.Location = new System.Drawing.Point(17, 40); + this.correctedLabel.Name = "correctedLabel"; + this.correctedLabel.Size = new System.Drawing.Size(53, 13); + this.correctedLabel.TabIndex = 3; + this.correctedLabel.Text = "Corrected"; + // + // measuredLabel + // + this.measuredLabel.AutoSize = true; + this.measuredLabel.Location = new System.Drawing.Point(17, 18); + this.measuredLabel.Name = "measuredLabel"; + this.measuredLabel.Size = new System.Drawing.Size(54, 13); + this.measuredLabel.TabIndex = 2; + this.measuredLabel.Text = "Measured"; + // + // listViewEx + // + this.listViewEx.AllowColumnReorder = true; + this.listViewEx.Dock = System.Windows.Forms.DockStyle.Fill; + this.listViewEx.DoubleClickActivation = false; + this.listViewEx.FullRowSelect = true; + this.listViewEx.GridLines = true; + this.listViewEx.Location = new System.Drawing.Point(0, 0); + this.listViewEx.Name = "listViewEx"; + this.listViewEx.Size = new System.Drawing.Size(650, 294); + 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); + // + // MetrologyDlgLevelMeterTab + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.splitContainer1); + this.Name = "MetrologyDlgLevelMeterTab"; + this.Size = new System.Drawing.Size(650, 400); + this.Load += new System.EventHandler(this.MetrologyDlgDiverterTab_Load); + this.splitContainer1.Panel1.ResumeLayout(false); + this.splitContainer1.Panel2.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).EndInit(); + this.splitContainer1.ResumeLayout(false); + this.calibrationGroupBox.ResumeLayout(false); + this.calibrationGroupBox.PerformLayout(); + this.nameGroupBox.ResumeLayout(false); + this.nameGroupBox.PerformLayout(); + this.testGroupBox.ResumeLayout(false); + this.testGroupBox.PerformLayout(); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.SplitContainer splitContainer1; + private System.Windows.Forms.Label cmpntNameLabel; + private Results.Forms.ListViewEx listViewEx; + private System.Windows.Forms.GroupBox testGroupBox; + private System.Windows.Forms.TextBox correctedTextBox; + private System.Windows.Forms.TextBox measuredTextBox; + private System.Windows.Forms.Label correctedLabel; + private System.Windows.Forms.Label measuredLabel; + private System.Windows.Forms.GroupBox nameGroupBox; + private System.Windows.Forms.GroupBox calibrationGroupBox; + private System.Windows.Forms.TextBox calibValidDateTextBox; + private System.Windows.Forms.Label calibValidDateLabel; + private System.Windows.Forms.TextBox calibDateTextBox; + private System.Windows.Forms.Label calibDateLabel; + private System.Windows.Forms.TextBox calibCertificateNrTextBox; + private System.Windows.Forms.Label calibCertificateNrLabel; + private System.Windows.Forms.Label pressFromToLabel; + private System.Windows.Forms.Label tempFromToLabel; + + } +} diff --git a/TBF/UiControls/MetrologyDlgDiverterTab.cs b/TBF/UiControls/MetrologyDlgDiverterTab.cs new file mode 100644 index 000000000..d26ae9722 --- /dev/null +++ b/TBF/UiControls/MetrologyDlgDiverterTab.cs @@ -0,0 +1,342 @@ +/// +/// Copyright (c) 2019 Sensus Slovensko a.s. +/// +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Windows.Forms; +using log4net; +using Config.Entities; +using TBF.Resources; + +namespace TBF.UiControls +{ + public partial class MetrologyDlgDiverterTab : UserControl, IMetrologyDlgTab + { + static readonly ILog log = LogManager.GetLogger(typeof(MetrologyDlgLevelMeterTab)); + + /// + /// 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; } + } + + /// + /// Calibration information configuration + /// + public BenchControl.GenericDevices.ICalibInfoCfg CalibInfoCfg; + + /// + /// A list of 'measurement-correction' pairs to be deleted from the database on OK. + /// + public IList ToBeRemoved + { + get { return toBeRemoved; } + set { toBeRemoved = value; } + } + IList toBeRemoved; + + MetrologyDlg parent; + bool unlocked; + Control measurementTextBox; + Control correctionTextBox; + + + public MetrologyDlgDiverterTab() + { + InitializeComponent(); + toBeRemoved = new List(); + } + + private void MetrologyDlgDiverterTab_Load(object sender, System.EventArgs e) + { + if (meterEntity == null) return; + + parent = ParentForm as MetrologyDlg; + + Localize(); + + /// Panel1 + cmpntNameLabel.Text = meterEntity.Name; + testGroupBox.Text = Strings.Test_measured_corrected; + measuredLabel.Text = Strings.Measured; + correctedLabel.Text = Strings.Corrected; + measuredTextBox.Text = string.Empty; + correctedTextBox.Text = string.Empty; + + /// Panel2 + measurementTextBox = new TextBox(); + correctionTextBox = new TextBox(); + this.Controls.Add(measurementTextBox); + this.Controls.Add(correctionTextBox); + + listViewEx.SubItemClicked += new Results.Forms.SubItemEventHandler(listViewEx_SubItemClicked); + listViewEx.SubItemRightClicked += new Results.Forms.SubItemEventHandler(listViewEx_SubItemRightClicked); + listViewEx.SubItemEndEditing += new Results.Forms.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} [ms]", Strings.Correction), Width = 100 }); + + RefreshAll(); + } + + void Localize() + { + nameGroupBox.Text = Strings.Component; + + calibrationGroupBox.Text = Strings.Calibration; + 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() + { + if (CalibInfoCfg != null) + { + calibCertificateNrTextBox.Text = CalibInfoCfg.CalibCertificateNr; + calibDateTextBox.Text = CalibInfoCfg.CalibDate.ToShortDateString(); + calibValidDateTextBox.Text = CalibInfoCfg.CalibValidDate.ToShortDateString(); + } + + listViewEx.Items.Clear(); + foreach (var corr in MeterEntity.Corrections) + { + AddOneLVI(corr); + } + } + + void AddOneLVI(MeasurementCorrection corr) + { + int nr = listViewEx.Items.Count + 1; + ListViewItem lvi = new ListViewItem(nr.ToString()); + lvi.SubItems.Add(corr.Measurement.ToString()); + lvi.SubItems.Add((1000 * corr.Correction).ToString()); + lvi.Tag = corr; + listViewEx.Items.Add(lvi); + } + + void listViewEx_SubItemClicked(object sender, Results.Forms.SubItemEventArgs e) + { + if (unlocked && e.SubItem == 1) + { + listViewEx.StartEditing(measurementTextBox, e.Item, e.SubItem); + } + else if (unlocked && e.SubItem == 2) + { + listViewEx.StartEditing(correctionTextBox, e.Item, e.SubItem); + } + } + + void listViewEx_SubItemRightClicked(object sender, Results.Forms.SubItemEventArgs e) + { + if (!unlocked || e.SubItem < 1 || e.SubItem > 2) return; + + if (DialogResult.Yes == MessageBox.Show(Strings.Do_you_want_to_copy_this_value_to_all_cells_below_this_cell, + Strings.Confirmation, MessageBoxButtons.YesNo, MessageBoxIcon.Question)) + { + int columnNr = e.SubItem; + string value = null; + System.Drawing.Color backColor = System.Drawing.Color.White; + + foreach (ListViewItem item in listViewEx.Items) + { + if (value != null && item.SubItems.Count > columnNr) + { + item.SubItems[columnNr].Text = value; + item.SubItems[columnNr].BackColor = backColor; + ParseItem(item, columnNr, value); + } + else if (item == e.Item) + { + value = item.SubItems[columnNr].Text; + backColor = item.SubItems[columnNr].BackColor; + } + } + } + } + + void listViewEx_SubItemEndEditing(object sender, Results.Forms.SubItemEndEditingEventArgs e) + { + if (ParseItem(e.Item, e.SubItem, e.DisplayText)) return; + + /// New value NOK, revert the original text + e.DisplayText = e.Item.Text; + e.Cancel = true; + } + + /// + /// Parse text of a ListViewItem + /// + /// true = value parsed OK + bool ParseItem(ListViewItem item, int subItem, string value) + { + float fvalue; + if (subItem == 1 && Utils.TryParseEFloat(value, out fvalue) && fvalue >= 0) + { + (item.Tag as MeasurementCorrection).Measurement = fvalue; + return true; + } + else if (subItem == 2 && Utils.TryParseEFloat(value, out fvalue)) + { + (item.Tag as MeasurementCorrection).Correction = fvalue / 1000; + return true; + } + else + { + return false; + } + } + + public void Unlock() + { + unlocked = true; + + calibCertificateNrTextBox.Enabled = true; + calibDateTextBox.Enabled = true; + calibValidDateTextBox.Enabled = true; + + if (listViewEx.SelectedItems.Count == 1) + { + int ix = listViewEx.SelectedIndices[0]; + listViewEx.Focus(); + listViewEx.Items[ix].Selected = true; + listViewEx.Items[ix].EnsureVisible(); + } + } + + public void OkBtnClicked() + { + if (CalibInfoCfg != null) + { + try + { + CalibInfoCfg.CalibCertificateNr = calibCertificateNrTextBox.Text; + CalibInfoCfg.CalibDate = DateTime.Parse(calibDateTextBox.Text); + CalibInfoCfg.CalibValidDate = DateTime.Parse(calibValidDateTextBox.Text); + + Component modified = CalibInfoCfg.CreateDbEntity(); + MeterEntity.Parameters = modified.Parameters; + } + catch + { + MessageBox.Show(Strings.Invalid_calib_info_Correct_pls, + Strings.Error, + MessageBoxButtons.OK, + MessageBoxIcon.Exclamation); + } + } + } + + public void CancelBtnClicked() + { + } + + public void AddOne() + { + MeasurementCorrection corr = new MeasurementCorrection(); + MeterEntity.Corrections.Add(corr); + AddOneLVI(corr); + + listViewEx.Focus(); + listViewEx.SelectedItems.Clear(); + listViewEx.Items[listViewEx.Items.Count - 1].Selected = true; + listViewEx.Items[listViewEx.Items.Count - 1].EnsureVisible(); + } + + public void RemoveSelected() + { + if (listViewEx.SelectedItems.Count != 1) return; + + int removeItemNr = listViewEx.SelectedIndices[0]; + + MeasurementCorrection selected = (MeasurementCorrection)listViewEx.SelectedItems[0].Tag; + if (selected.Id != 0) toBeRemoved.Add(selected); + MeterEntity.Corrections.RemoveAt(removeItemNr); + RefreshAll(); + + if (removeItemNr < listViewEx.Items.Count) + { + listViewEx.Focus(); + listViewEx.Items[removeItemNr].Selected = true; + listViewEx.Items[removeItemNr].EnsureVisible(); + } + else + { + parent.UpdateButtonStates(SharedButtons.SelectedItemPos.None); + } + } + + public void MoveUpSelected() + { + } + + public void MoveDownSelected() + { + } + + /// + /// Event handler that indicates the selected item position + /// and updates 'Remove', 'Up' and 'Down' buttons in the parent dialog. + /// + private void listViewEx_SelectedIndexChanged(object sender, EventArgs e) + { + if (listViewEx.SelectedItems.Count != 1) + { + parent.UpdateButtonStates(SharedButtons.SelectedItemPos.None); + } + else if (listViewEx.Items.Count == 1) + { + parent.UpdateButtonStates(SharedButtons.SelectedItemPos.FirstAndLast); + } + else if (listViewEx.SelectedIndices[0] == 0) + { + parent.UpdateButtonStates(SharedButtons.SelectedItemPos.First); + } + else if (listViewEx.SelectedIndices[0] == (listViewEx.Items.Count - 1)) + { + parent.UpdateButtonStates(SharedButtons.SelectedItemPos.Last); + } + else + { + parent.UpdateButtonStates(SharedButtons.SelectedItemPos.Middle); + } + } + + private void measuredTextBox_TextChanged(object sender, EventArgs e) + { + float measured; + if (float.TryParse(measuredTextBox.Text, + NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign | NumberStyles.AllowExponent, + CultureInfo.CurrentCulture, + out measured) || + float.TryParse(measuredTextBox.Text, + NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign | NumberStyles.AllowExponent, + CultureInfo.InvariantCulture, + out measured)) + { + double corrected = Config.Formulas.CorrectedValue(measured, meterEntity.Corrections); + correctedTextBox.Text = corrected.ToString(); + } + } + + public string GetWarningsBeforeSaving(ref Dictionary renmInfo) + { + return string.Empty; + } + + public void UpdateRelatedItems(Dictionary renameInfo) + { + } + } +} diff --git a/TBF/UiControls/MetrologyDlgDiverterTab.resx b/TBF/UiControls/MetrologyDlgDiverterTab.resx new file mode 100644 index 000000000..1af7de150 --- /dev/null +++ b/TBF/UiControls/MetrologyDlgDiverterTab.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file