2015-04-15 18:32:56 +00:00
|
|
|
|
///
|
|
|
|
|
|
/// Copyright (c) 2013-2015 Sensus Metering Systems
|
|
|
|
|
|
///
|
|
|
|
|
|
using System;
|
2014-07-28 07:54:35 +00:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Globalization;
|
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
using log4net;
|
2015-12-04 16:17:20 +00:00
|
|
|
|
using Config.Entities;
|
2014-07-28 07:54:35 +00:00
|
|
|
|
using TBF.Resources;
|
|
|
|
|
|
|
|
|
|
|
|
namespace TBF.UiControls
|
|
|
|
|
|
{
|
|
|
|
|
|
public partial class MetrologyDlgBalanceTab : UserControl, IMetrologyDlgTab
|
|
|
|
|
|
{
|
|
|
|
|
|
static readonly ILog log = LogManager.GetLogger(typeof(MetrologyDlgBalanceTab));
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Component entity that has a list of 'measurement-correction' pairs
|
|
|
|
|
|
/// to be updated in the database on OK.
|
|
|
|
|
|
/// </summary>
|
2015-12-04 16:17:20 +00:00
|
|
|
|
public Component MeterEntity
|
2014-07-28 07:54:35 +00:00
|
|
|
|
{
|
|
|
|
|
|
get { return meterEntity; }
|
|
|
|
|
|
set { meterEntity = value; }
|
|
|
|
|
|
}
|
2015-12-04 16:17:20 +00:00
|
|
|
|
Component meterEntity;
|
2014-07-28 07:54:35 +00:00
|
|
|
|
|
2016-04-25 10:28:21 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Balance configuration (with buoyancy parameters)
|
|
|
|
|
|
/// </summary>
|
2017-03-28 21:47:32 +00:00
|
|
|
|
public BenchControl.GenericDevices.IScaleCfg BalanceCfg;
|
2016-04-25 10:28:21 +00:00
|
|
|
|
|
2014-07-28 07:54:35 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// A list of 'measurement-correction' pairs to be deleted from the database on OK.
|
|
|
|
|
|
/// </summary>
|
2015-12-04 16:17:20 +00:00
|
|
|
|
public IList<MeasurementCorrection> ToBeRemoved
|
2014-07-28 07:54:35 +00:00
|
|
|
|
{
|
|
|
|
|
|
get { return toBeRemoved; }
|
|
|
|
|
|
set { toBeRemoved = value; }
|
|
|
|
|
|
}
|
2015-12-04 16:17:20 +00:00
|
|
|
|
IList<MeasurementCorrection> toBeRemoved;
|
2014-07-28 07:54:35 +00:00
|
|
|
|
|
|
|
|
|
|
MetrologyDlg parent;
|
|
|
|
|
|
bool unlocked;
|
|
|
|
|
|
Control measurementTextBox;
|
|
|
|
|
|
Control correctionTextBox;
|
|
|
|
|
|
|
|
|
|
|
|
public MetrologyDlgBalanceTab()
|
|
|
|
|
|
{
|
|
|
|
|
|
InitializeComponent();
|
2015-12-04 16:17:20 +00:00
|
|
|
|
toBeRemoved = new List<MeasurementCorrection>();
|
2014-07-28 07:54:35 +00:00
|
|
|
|
unlocked = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void MetrologyDlgBalanceTab_Load(object sender, System.EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (meterEntity == null) return;
|
|
|
|
|
|
|
|
|
|
|
|
parent = ParentForm as MetrologyDlg;
|
|
|
|
|
|
|
2016-04-25 10:28:21 +00:00
|
|
|
|
Localize();
|
2014-07-28 07:54:35 +00:00
|
|
|
|
|
2016-04-25 10:28:21 +00:00
|
|
|
|
/// Panel1
|
|
|
|
|
|
cmpntNameLabel.Text = meterEntity.Name;
|
2014-07-28 07:54:35 +00:00
|
|
|
|
measuredTextBox.Text = string.Empty;
|
|
|
|
|
|
correctedTextBox.Text = string.Empty;
|
|
|
|
|
|
|
|
|
|
|
|
/// Panel2
|
|
|
|
|
|
measurementTextBox = new TextBox();
|
|
|
|
|
|
correctionTextBox = new TextBox();
|
|
|
|
|
|
this.Controls.Add(measurementTextBox);
|
|
|
|
|
|
this.Controls.Add(correctionTextBox);
|
|
|
|
|
|
|
2016-08-19 08:43:48 +00:00
|
|
|
|
listViewEx.SubItemClicked += new Results.Forms.SubItemEventHandler(listViewEx_SubItemClicked);
|
|
|
|
|
|
listViewEx.SubItemRightClicked += new Results.Forms.SubItemEventHandler(listViewEx_SubItemRightClicked);
|
|
|
|
|
|
listViewEx.SubItemEndEditing += new Results.Forms.SubItemEndEditingEventHandler(listViewEx_SubItemEndEditing);
|
2014-07-28 07:54:35 +00:00
|
|
|
|
|
|
|
|
|
|
listViewEx.Columns.Add(new ColumnHeader() { Text = Strings.Nr, Width = 60 });
|
|
|
|
|
|
listViewEx.Columns.Add(new ColumnHeader() { Text = Strings.Mass_kg, Width = 100 });
|
|
|
|
|
|
listViewEx.Columns.Add(new ColumnHeader() { Text = Strings.Correction_g, Width = 100 });
|
|
|
|
|
|
|
|
|
|
|
|
RefreshAll();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-04-25 10:28:21 +00:00
|
|
|
|
void Localize()
|
|
|
|
|
|
{
|
2016-05-18 17:19:31 +00:00
|
|
|
|
nameGroupBox.Text = Strings.Component;
|
|
|
|
|
|
|
|
|
|
|
|
calibrationGroupBox.Text = Strings.Calibration;
|
|
|
|
|
|
calibCertificateNrLabel.Text = Strings.Certificate;
|
|
|
|
|
|
calibDateLabel.Text = Strings.Date;
|
|
|
|
|
|
calibValidDateLabel.Text = Strings.Valid_until;
|
|
|
|
|
|
|
2016-05-28 11:40:58 +00:00
|
|
|
|
buoyancyTempLabel.Text = Strings.Ambient_temperature + " [°C]";
|
|
|
|
|
|
buoyancyPressLabel.Text = Strings.Ambient_pressure + " [mbar]";
|
|
|
|
|
|
buoyancyHumiLabel.Text = Strings.Ambient_humidity + " [%]";
|
|
|
|
|
|
airDensityLabel.Text = Strings.Air_density_kg_m3;
|
|
|
|
|
|
weightStandardDensityLabel.Text = Strings.Ref_mass_dens_kg_m3;
|
2016-04-25 10:28:21 +00:00
|
|
|
|
|
|
|
|
|
|
testGroupBox.Text = Strings.Test_measured_corrected;
|
|
|
|
|
|
measuredLabel.Text = Strings.Measured;
|
|
|
|
|
|
correctedLabel.Text = Strings.Corrected;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2014-07-28 07:54:35 +00:00
|
|
|
|
void RefreshAll()
|
|
|
|
|
|
{
|
2016-04-25 10:28:21 +00:00
|
|
|
|
if (BalanceCfg != null)
|
|
|
|
|
|
{
|
2016-04-25 13:25:23 +00:00
|
|
|
|
calibCertificateNrTextBox.Text = BalanceCfg.CalibCertificateNr;
|
|
|
|
|
|
calibDateTextBox.Text = BalanceCfg.CalibDate.ToShortDateString();
|
|
|
|
|
|
calibValidDateTextBox.Text = BalanceCfg.CalibValidDate.ToShortDateString();
|
|
|
|
|
|
|
2016-04-25 10:28:21 +00:00
|
|
|
|
buoyancyTempTextBox.Text = BalanceCfg.BuoyancyTemp.ToString("F2");
|
|
|
|
|
|
buoyancyPressTextBox.Text = BalanceCfg.BuoyancyPress.ToString("F4");
|
|
|
|
|
|
buoyancyHumiTextBox.Text = BalanceCfg.BuoyancyHumi.ToString("F1");
|
2016-04-25 13:25:23 +00:00
|
|
|
|
/// airDensityTextBox.Text = //calculate air density
|
|
|
|
|
|
weightStandardDensityTextBox.Text = BalanceCfg.WeightStandardDensity.ToString("F1");
|
2016-04-25 10:28:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2014-07-28 07:54:35 +00:00
|
|
|
|
listViewEx.Items.Clear();
|
|
|
|
|
|
foreach (var corr in MeterEntity.Corrections) AddOneLVI(corr);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2015-12-04 16:17:20 +00:00
|
|
|
|
void AddOneLVI(MeasurementCorrection corr)
|
2014-07-28 07:54:35 +00:00
|
|
|
|
{
|
|
|
|
|
|
int nr = listViewEx.Items.Count + 1;
|
|
|
|
|
|
ListViewItem lvi = new ListViewItem(nr.ToString());
|
|
|
|
|
|
lvi.SubItems.Add(corr.Measurement.ToString());
|
|
|
|
|
|
lvi.SubItems.Add((corr.Correction * 1000.0f).ToString());
|
|
|
|
|
|
lvi.Tag = corr;
|
|
|
|
|
|
listViewEx.Items.Add(lvi);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-08-19 08:43:48 +00:00
|
|
|
|
void listViewEx_SubItemClicked(object sender, Results.Forms.SubItemEventArgs e)
|
2014-07-28 07:54:35 +00:00
|
|
|
|
{
|
|
|
|
|
|
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);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-08-19 08:43:48 +00:00
|
|
|
|
void listViewEx_SubItemRightClicked(object sender, Results.Forms.SubItemEventArgs e)
|
2016-08-15 09:23:00 +00:00
|
|
|
|
{
|
|
|
|
|
|
if (!unlocked || e.SubItem < 1 || e.SubItem > 2) return;
|
2014-07-28 07:54:35 +00:00
|
|
|
|
|
2016-08-15 09:23:00 +00:00
|
|
|
|
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)
|
|
|
|
|
|
{
|
2017-03-20 20:25:39 +00:00
|
|
|
|
if (value != null && item.SubItems.Count > columnNr)
|
2016-08-15 09:23:00 +00:00
|
|
|
|
{
|
|
|
|
|
|
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;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-08-19 08:43:48 +00:00
|
|
|
|
void listViewEx_SubItemEndEditing(object sender, Results.Forms.SubItemEndEditingEventArgs e)
|
2016-08-15 09:23:00 +00:00
|
|
|
|
{
|
|
|
|
|
|
if (ParseItem(e.Item, e.SubItem, e.DisplayText)) return;
|
|
|
|
|
|
|
|
|
|
|
|
/// New value NOK, revert the original text
|
|
|
|
|
|
e.DisplayText = e.Item.Text;
|
|
|
|
|
|
e.Cancel = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Parse text of a ListViewItem
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <returns>true = value parsed OK</returns>
|
|
|
|
|
|
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.0f;
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2014-07-28 07:54:35 +00:00
|
|
|
|
|
|
|
|
|
|
public void Unlock()
|
|
|
|
|
|
{
|
|
|
|
|
|
unlocked = true;
|
|
|
|
|
|
|
2016-04-25 13:25:23 +00:00
|
|
|
|
calibCertificateNrTextBox.Enabled = true;
|
|
|
|
|
|
calibDateTextBox.Enabled = true;
|
|
|
|
|
|
calibValidDateTextBox.Enabled = true;
|
2016-04-28 10:47:23 +00:00
|
|
|
|
|
2016-04-25 10:28:21 +00:00
|
|
|
|
buoyancyTempTextBox.Enabled = true;
|
|
|
|
|
|
buoyancyPressTextBox.Enabled = true;
|
|
|
|
|
|
buoyancyHumiTextBox.Enabled = true;
|
2016-04-25 13:25:23 +00:00
|
|
|
|
weightStandardDensityTextBox.Enabled = true;
|
2016-04-25 10:28:21 +00:00
|
|
|
|
|
2014-07-28 07:54:35 +00:00
|
|
|
|
if (listViewEx.SelectedItems.Count == 1)
|
|
|
|
|
|
{
|
|
|
|
|
|
int ix = listViewEx.SelectedIndices[0];
|
|
|
|
|
|
listViewEx.Focus();
|
|
|
|
|
|
listViewEx.Items[ix].Selected = true;
|
|
|
|
|
|
listViewEx.Items[ix].EnsureVisible();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void OkBtnClicked()
|
|
|
|
|
|
{
|
2016-04-25 13:25:23 +00:00
|
|
|
|
if (BalanceCfg != null)
|
2016-04-25 10:28:21 +00:00
|
|
|
|
{
|
2016-04-25 13:25:23 +00:00
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
BalanceCfg.CalibCertificateNr = calibCertificateNrTextBox.Text;
|
|
|
|
|
|
BalanceCfg.CalibDate = DateTime.Parse(calibDateTextBox.Text);
|
|
|
|
|
|
BalanceCfg.CalibValidDate = DateTime.Parse(calibValidDateTextBox.Text);
|
|
|
|
|
|
|
|
|
|
|
|
BalanceCfg.BuoyancyTemp = Utils.ParseSFloat(buoyancyTempTextBox.Text);
|
|
|
|
|
|
BalanceCfg.BuoyancyPress = Utils.ParseUFloat(buoyancyPressTextBox.Text);
|
|
|
|
|
|
BalanceCfg.BuoyancyHumi = Utils.ParseUFloat(buoyancyHumiTextBox.Text);
|
|
|
|
|
|
BalanceCfg.WeightStandardDensity = Utils.ParseUFloat(weightStandardDensityTextBox.Text);
|
|
|
|
|
|
|
|
|
|
|
|
Component modified = BalanceCfg.CreateDbEntity();
|
|
|
|
|
|
MeterEntity.Parameters = modified.Parameters;
|
|
|
|
|
|
}
|
|
|
|
|
|
catch
|
|
|
|
|
|
{
|
2016-05-28 11:40:58 +00:00
|
|
|
|
MessageBox.Show(Strings.Invalid_buoyancy_parameter_Correct_pls,
|
|
|
|
|
|
Strings.Error,
|
|
|
|
|
|
MessageBoxButtons.OK,
|
|
|
|
|
|
MessageBoxIcon.Exclamation);
|
2016-04-25 13:25:23 +00:00
|
|
|
|
}
|
2016-04-25 10:28:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2014-07-28 07:54:35 +00:00
|
|
|
|
|
|
|
|
|
|
public void CancelBtnClicked()
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void AddOne()
|
|
|
|
|
|
{
|
2015-12-04 16:17:20 +00:00
|
|
|
|
MeasurementCorrection corr = new MeasurementCorrection();
|
2014-07-28 07:54:35 +00:00
|
|
|
|
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];
|
|
|
|
|
|
|
2015-12-04 16:17:20 +00:00
|
|
|
|
MeasurementCorrection selected =
|
|
|
|
|
|
(MeasurementCorrection)listViewEx.SelectedItems[0].Tag;
|
2014-07-28 07:54:35 +00:00
|
|
|
|
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()
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Event handler that indicates the selected item position
|
|
|
|
|
|
/// and updates 'Remove', 'Up' and 'Down' buttons in the parent dialog.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
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))
|
|
|
|
|
|
{
|
2016-01-03 01:05:35 +00:00
|
|
|
|
double corrected = BenchControl.Formulas.CorrectedValue(measured, meterEntity.Corrections);
|
2014-07-28 07:54:35 +00:00
|
|
|
|
correctedTextBox.Text = corrected.ToString();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|