TBF.UI.Bench.Uncertainties : Modifications, 3 tab pages completed, 2 in preparation.
This commit is contained in:
@@ -0,0 +1,264 @@
|
||||
///
|
||||
/// 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 Results.Forms;
|
||||
using TBF.Resources;
|
||||
using TBF.UI.Shared;
|
||||
|
||||
namespace TBF.UI.Bench.Uncertainties
|
||||
{
|
||||
public partial class UncertntDlgTempMeterTab : UserControl, IUncetaintiesDlgTab
|
||||
{
|
||||
static readonly ILog log = LogManager.GetLogger(typeof(UncertntDlgTempMeterTab));
|
||||
|
||||
/// <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<Uncertainty> ToBeRemoved
|
||||
{
|
||||
get { return toBeRemoved; }
|
||||
set { toBeRemoved = value; }
|
||||
}
|
||||
IList<Uncertainty> toBeRemoved;
|
||||
|
||||
UncertaintiesDlg parent;
|
||||
bool unlocked;
|
||||
Control[] textBoxes;
|
||||
|
||||
public UncertntDlgTempMeterTab()
|
||||
{
|
||||
InitializeComponent();
|
||||
toBeRemoved = new List<Uncertainty>();
|
||||
}
|
||||
|
||||
private void UncertntDlgTempMeterTab_Load(object sender, System.EventArgs e)
|
||||
{
|
||||
if (meterEntity == null) return;
|
||||
|
||||
parent = ParentForm as UncertaintiesDlg;
|
||||
|
||||
/// Panel1
|
||||
cmpntLabel.Text = Strings.Component;
|
||||
cmpntNameLabel.Text = meterEntity.Name;
|
||||
|
||||
/// Panel2
|
||||
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 = 100 });
|
||||
listViewEx.Columns.Add(new ColumnHeader() { Text = string.Format("{0} [1/1000 °C]", Strings.Main_uncertainty), Width = 120 });
|
||||
listViewEx.Columns.Add(new ColumnHeader() { Text = string.Format("{0} [1/1000 °C]", Strings.Resolution), Width = 100 });
|
||||
listViewEx.Columns.Add(new ColumnHeader() { Text = string.Format("{0} [1/1000 °C/year]", Strings.Drift_per_year), Width = 120 });
|
||||
listViewEx.Columns.Add(new ColumnHeader() { Text = string.Format("{0} [1/1000 °C]", Strings.Conditions), Width = 100 });
|
||||
listViewEx.Columns.Add(new ColumnHeader() { Text = string.Format("{0} [1/1000 °C]", Strings.Uncertainty_of_correction), Width = 160 });
|
||||
|
||||
textBoxes = new TextBox[listViewEx.Columns.Count];
|
||||
for (int i = 1; i < textBoxes.Length; i++)
|
||||
{
|
||||
this.Controls.Add(textBoxes[i] = new TextBox());
|
||||
}
|
||||
|
||||
RefreshAll();
|
||||
}
|
||||
|
||||
void RefreshAll()
|
||||
{
|
||||
listViewEx.Items.Clear();
|
||||
foreach (var uncrtnty in MeterEntity.Uncertainties) AddOneLVI(uncrtnty);
|
||||
}
|
||||
|
||||
void AddOneLVI(Uncertainty corr)
|
||||
{
|
||||
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.MainUncertainty).ToString());
|
||||
lvi.SubItems.Add((1000 * corr.Resolution).ToString());
|
||||
lvi.SubItems.Add((1000 * corr.DriftPerYr).ToString());
|
||||
lvi.SubItems.Add((1000 * corr.Conditions).ToString());
|
||||
lvi.SubItems.Add((1000 * corr.UncertaintyOfCorrection).ToString());
|
||||
|
||||
listViewEx.Items.Add(lvi);
|
||||
}
|
||||
|
||||
void listViewEx_SubItemClicked(object sender, SubItemEventArgs e)
|
||||
{
|
||||
if (unlocked && (e.SubItem >= 1) && (e.SubItem < listViewEx.Columns.Count))
|
||||
{
|
||||
/// This is not the first column
|
||||
listViewEx.StartEditing(textBoxes[e.SubItem], 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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse text of a ListViewItem
|
||||
/// </summary>
|
||||
/// <returns>true = value parsed OK</returns>
|
||||
bool ParseItem(ListViewItem item, int subItem, string strValue)
|
||||
{
|
||||
Uncertainty uncrtnty = item.Tag as Uncertainty;
|
||||
double dblValue = 0;
|
||||
if ((uncrtnty != null) && Utils.TryParseEDouble(strValue, out dblValue) && (dblValue >= 0))
|
||||
{
|
||||
double inDefaultUnits = dblValue / 1000;
|
||||
switch (subItem)
|
||||
{
|
||||
case 1:
|
||||
uncrtnty.Measurement = (float)dblValue;
|
||||
return true;
|
||||
case 2:
|
||||
uncrtnty.MainUncertainty = (float)inDefaultUnits;
|
||||
return true;
|
||||
case 3:
|
||||
uncrtnty.Resolution = (float)inDefaultUnits;
|
||||
return true;
|
||||
case 4:
|
||||
uncrtnty.DriftPerYr = (float)inDefaultUnits;
|
||||
return true;
|
||||
case 5:
|
||||
uncrtnty.Conditions = (float)inDefaultUnits;
|
||||
return true;
|
||||
case 6:
|
||||
uncrtnty.UncertaintyOfCorrection = (float)inDefaultUnits;
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
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()
|
||||
{
|
||||
Uncertainty uncrtnty = new Uncertainty();
|
||||
MeterEntity.Uncertainties.Add(uncrtnty);
|
||||
AddOneLVI(uncrtnty);
|
||||
|
||||
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];
|
||||
|
||||
Uncertainty selected =
|
||||
(Uncertainty)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);
|
||||
}
|
||||
}
|
||||
|
||||
public string GetWarningsBeforeSaving(ref Dictionary<string, string> renmInfo)
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
public void UpdateRelatedItems(Dictionary<string, string> renameInfo)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user