238 lines
6.6 KiB
C#
238 lines
6.6 KiB
C#
///
|
|
/// Copyright (c) 2013-2015 Sensus Metering Systems
|
|
///
|
|
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 MetrologyDlgFlowMeterTab : UserControl, IMetrologyDlgTab
|
|
{
|
|
static readonly ILog log = LogManager.GetLogger(typeof(MetrologyDlgFlowMeterTab));
|
|
|
|
/// <summary>
|
|
/// Component entity that has a list of 'measurement-correction' pairs
|
|
/// to be updated in the database on OK.
|
|
/// </summary>
|
|
Component meterEntity;
|
|
public Component MeterEntity
|
|
{
|
|
get { return meterEntity; }
|
|
set { meterEntity = value; }
|
|
}
|
|
|
|
/// <summary>
|
|
/// A list of 'measurement-correction' pairs to be deleted from the database on OK.
|
|
/// </summary>
|
|
public IList<MeasurementCorrection> ToBeRemoved
|
|
{
|
|
get { return toBeRemoved; }
|
|
set { toBeRemoved = value; }
|
|
}
|
|
IList<MeasurementCorrection> toBeRemoved;
|
|
|
|
MetrologyDlg parent;
|
|
bool unlocked;
|
|
Control measurementTextBox;
|
|
Control correctionTextBox;
|
|
|
|
public MetrologyDlgFlowMeterTab()
|
|
{
|
|
InitializeComponent();
|
|
toBeRemoved = new List<MeasurementCorrection>();
|
|
}
|
|
|
|
private void MetrologyDlgFlowMeterTab_Load(object sender, System.EventArgs e)
|
|
{
|
|
if (meterEntity == null) return;
|
|
|
|
parent = ParentForm as MetrologyDlg;
|
|
|
|
/// 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 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 = Strings.Flow_m3h, Width = 100 });
|
|
listViewEx.Columns.Add(new ColumnHeader() { Text = Strings.Correction_lph, Width = 100 });
|
|
|
|
RefreshAll();
|
|
}
|
|
|
|
void RefreshAll()
|
|
{
|
|
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((corr.Correction * 1000.0f).ToString());
|
|
lvi.Tag = corr;
|
|
listViewEx.Items.Add(lvi);
|
|
}
|
|
|
|
void listViewEx_SubItemClicked(object sender, 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_SubItemEndEditing(object sender, SubItemEndEditingEventArgs e)
|
|
{
|
|
float value;
|
|
if (e.SubItem == 1 && Utils.TryParseEFloat(e.DisplayText, out value) && value >= 0)
|
|
{
|
|
(e.Item.Tag as MeasurementCorrection).Measurement = value;
|
|
return;
|
|
}
|
|
else if (e.SubItem == 2 && Utils.TryParseEFloat(e.DisplayText, out value))
|
|
{
|
|
(e.Item.Tag as MeasurementCorrection).Correction = value / 1000.0f;
|
|
return;
|
|
}
|
|
|
|
e.DisplayText = e.Item.Text;
|
|
e.Cancel = true;
|
|
}
|
|
|
|
public void Unlock()
|
|
{
|
|
unlocked = 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()
|
|
{
|
|
}
|
|
|
|
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()
|
|
{
|
|
}
|
|
|
|
/// <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))
|
|
{
|
|
double corrected = BenchControl.Formulas.CorrectedValue(measured, meterEntity.Corrections);
|
|
correctedTextBox.Text = corrected.ToString();
|
|
}
|
|
}
|
|
}
|
|
}
|