2016-04-24 06:55:39 +00:00
|
|
|
|
///
|
|
|
|
|
|
/// Copyright (c) 2013-2016 Sensus Metering Systems
|
|
|
|
|
|
///
|
|
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Windows.Forms;
|
2016-04-29 05:40:34 +00:00
|
|
|
|
using log4net;
|
2016-04-24 06:55:39 +00:00
|
|
|
|
using Config.Entities;
|
|
|
|
|
|
using TBF.Resources;
|
2016-04-29 05:40:34 +00:00
|
|
|
|
using TBF.UiControls;
|
2016-04-24 06:55:39 +00:00
|
|
|
|
|
|
|
|
|
|
namespace TBF.BenchControl.Output.FileWriters.Basic
|
|
|
|
|
|
{
|
|
|
|
|
|
public partial class ResultsConfigDlg : Form
|
|
|
|
|
|
{
|
2016-04-29 05:40:34 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// ListViewEx columns
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
enum Column
|
|
|
|
|
|
{
|
|
|
|
|
|
Item,
|
|
|
|
|
|
Header,
|
|
|
|
|
|
TestID,
|
|
|
|
|
|
Units,
|
|
|
|
|
|
Format,
|
|
|
|
|
|
Precision,
|
|
|
|
|
|
Width,
|
|
|
|
|
|
Alignment,
|
|
|
|
|
|
Count,
|
|
|
|
|
|
}
|
|
|
|
|
|
Control[] editors;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public IList<Results.WMeterRsltItemSpec> AvailableItems;
|
|
|
|
|
|
public IList<Results.WMeterRsltItemSpec> SelectedItems;
|
|
|
|
|
|
|
2016-04-24 06:55:39 +00:00
|
|
|
|
|
|
|
|
|
|
public bool Compound; /// false = single meter items, true = combined meter items
|
|
|
|
|
|
|
|
|
|
|
|
public ResultsConfigDlg()
|
|
|
|
|
|
{
|
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Localize()
|
|
|
|
|
|
{
|
|
|
|
|
|
Text = Strings.Configuration;
|
|
|
|
|
|
availableResultsLabel.Text = Strings.Available_results;
|
|
|
|
|
|
selectedResultsLabel.Text = Strings.Selected_results;
|
|
|
|
|
|
addButton.Text = Strings.Add;
|
|
|
|
|
|
removeButton.Text = Strings.Remove;
|
|
|
|
|
|
removeAllButton.Text = Strings.Remove_all;
|
|
|
|
|
|
okButton.Text = Strings.OkBtnText;
|
|
|
|
|
|
cancelButton.Text = Strings.CancelBtnText;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ResultsConfig_Load(object sender, EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
Localize();
|
2016-04-29 05:40:34 +00:00
|
|
|
|
|
|
|
|
|
|
/// Add columns to ListViewEx
|
|
|
|
|
|
selectedResultsListViewEx.Columns.Add(new ColumnHeader { Text = "Item", Width = 120 });
|
|
|
|
|
|
selectedResultsListViewEx.Columns.Add(new ColumnHeader { Text = "Header" });
|
|
|
|
|
|
selectedResultsListViewEx.Columns.Add(new ColumnHeader { Text = "Test ID" });
|
|
|
|
|
|
selectedResultsListViewEx.Columns.Add(new ColumnHeader { Text = "Units" });
|
|
|
|
|
|
selectedResultsListViewEx.Columns.Add(new ColumnHeader { Text = "Format" });
|
|
|
|
|
|
selectedResultsListViewEx.Columns.Add(new ColumnHeader { Text = "Precision" });
|
|
|
|
|
|
selectedResultsListViewEx.Columns.Add(new ColumnHeader { Text = "Width" });
|
|
|
|
|
|
selectedResultsListViewEx.Columns.Add(new ColumnHeader { Text = "Alignment" });
|
|
|
|
|
|
|
|
|
|
|
|
/// Create controls used by ListViewEx to edit items
|
|
|
|
|
|
ComboBox unitsCB = new ComboBox();
|
|
|
|
|
|
unitsCB.Items.Add("---"); /// Use "---" instead of "None"
|
|
|
|
|
|
for (Config.Unit u = (Config.Unit)1; u < Config.Unit.Count; u++)
|
|
|
|
|
|
{
|
|
|
|
|
|
unitsCB.Items.Add(u.ToString().Replace('p','/'));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ComboBox alignmentCB = new ComboBox();
|
|
|
|
|
|
for (Config.Entities.Alignment a = 0; a < Config.Entities.Alignment.Count; a++)
|
|
|
|
|
|
{
|
|
|
|
|
|
alignmentCB.Items.Add(a.ToString());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
editors = new Control[]
|
|
|
|
|
|
{
|
|
|
|
|
|
null,
|
|
|
|
|
|
new TextBox(),
|
|
|
|
|
|
new TextBox(),
|
|
|
|
|
|
unitsCB,
|
|
|
|
|
|
new TextBox(),
|
|
|
|
|
|
new TextBox(),
|
|
|
|
|
|
new TextBox(),
|
|
|
|
|
|
alignmentCB,
|
|
|
|
|
|
};
|
|
|
|
|
|
foreach (var edi in editors) Controls.Add(edi);
|
|
|
|
|
|
|
|
|
|
|
|
selectedResultsListViewEx.SubItemClicked += new SubItemEventHandler(selectedResultsListViewEx_SubItemClicked);
|
|
|
|
|
|
selectedResultsListViewEx.SubItemEndEditing += new SubItemEndEditingEventHandler(selectedResultsListViewEx_SubItemEndEditing);
|
|
|
|
|
|
|
|
|
|
|
|
RedrawAvailable();
|
2016-04-24 06:55:39 +00:00
|
|
|
|
RedrawSelected();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-04-29 05:40:34 +00:00
|
|
|
|
void selectedResultsListViewEx_SubItemClicked(object sender, SubItemEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
if ((e.SubItem > 0) && (e.SubItem < (int)Column.Count))
|
|
|
|
|
|
{
|
|
|
|
|
|
selectedResultsListViewEx.StartEditing(editors[e.SubItem], e.Item, e.SubItem);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void selectedResultsListViewEx_SubItemEndEditing(object sender, SubItemEndEditingEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
ListViewItem lvi = e.Item;
|
|
|
|
|
|
Results.WMeterRsltItemSpec item = lvi.Tag as Results.WMeterRsltItemSpec;
|
|
|
|
|
|
|
|
|
|
|
|
switch ((Column)e.SubItem)
|
|
|
|
|
|
{
|
|
|
|
|
|
case Column.Header: item.Header = e.DisplayText; return;
|
|
|
|
|
|
case Column.TestID: item.TestID = e.DisplayText; return;
|
|
|
|
|
|
case Column.Format: item.Format = e.DisplayText; return;
|
|
|
|
|
|
case Column.Precision: item.Precision = e.DisplayText; return;
|
|
|
|
|
|
|
|
|
|
|
|
case Column.Units:
|
|
|
|
|
|
if (editors[e.SubItem].Text == "---") { item.Units = 0; return; };
|
|
|
|
|
|
for (Config.Unit u = (Config.Unit)1; u < Config.Unit.Count; u++)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (u.ToString().Replace('p', '/').Equals(editors[e.SubItem].Text))
|
|
|
|
|
|
{
|
|
|
|
|
|
item.Units = u;
|
|
|
|
|
|
return; /// OK
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
break; /// Error
|
|
|
|
|
|
|
|
|
|
|
|
case Column.Alignment:
|
|
|
|
|
|
for (Config.Entities.Alignment a = 0; a < Config.Entities.Alignment.Count; a++)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (a.ToString().Equals(editors[e.SubItem].Text))
|
|
|
|
|
|
{
|
|
|
|
|
|
item.Alignment = a;
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
break; /// Error
|
|
|
|
|
|
|
|
|
|
|
|
case Column.Width:
|
|
|
|
|
|
{
|
|
|
|
|
|
int width;
|
|
|
|
|
|
if (Int32.TryParse(editors[e.SubItem].Text, out width) && width >= 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
item.Width = width;
|
|
|
|
|
|
return; /// OK
|
|
|
|
|
|
}
|
|
|
|
|
|
break; /// Error
|
|
|
|
|
|
}
|
|
|
|
|
|
default:
|
|
|
|
|
|
return; /// OK
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
e.DisplayText = e.Item.SubItems[e.SubItem].Text;
|
|
|
|
|
|
e.Cancel = true;
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-04-24 06:55:39 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Redraw selected items (right hand side)
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
void RedrawAvailable()
|
|
|
|
|
|
{
|
|
|
|
|
|
availableResultsListBox.Items.Clear();
|
2016-04-29 05:40:34 +00:00
|
|
|
|
AvailableItems = new List<Results.WMeterRsltItemSpec>();
|
|
|
|
|
|
foreach (var item in Results.WMeterRsltItemSpec.AllItems)
|
2016-04-24 06:55:39 +00:00
|
|
|
|
{
|
2016-04-29 05:40:34 +00:00
|
|
|
|
AvailableItems.Add(item);
|
|
|
|
|
|
availableResultsListBox.Items.Add(item.Name);
|
2016-04-24 06:55:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Redraw selected items (right hand side)
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
void RedrawSelected()
|
|
|
|
|
|
{
|
2016-04-29 05:40:34 +00:00
|
|
|
|
selectedResultsListViewEx.Items.Clear();
|
2016-04-24 06:55:39 +00:00
|
|
|
|
foreach (var item in SelectedItems)
|
|
|
|
|
|
{
|
2016-04-29 05:40:34 +00:00
|
|
|
|
ListViewItem lvi = new ListViewItem(item.Name); /// Item
|
|
|
|
|
|
lvi.Tag = item;
|
|
|
|
|
|
lvi.SubItems.Add(item.Header); /// Header
|
|
|
|
|
|
lvi.SubItems.Add(item.TestID); /// TestID
|
|
|
|
|
|
lvi.SubItems.Add((item.Units == Config.Unit.None) ? "---" : item.Units.ToString().Replace('p', '/')); /// Units
|
|
|
|
|
|
lvi.SubItems.Add(item.Format); /// Format
|
|
|
|
|
|
lvi.SubItems.Add(item.Precision); /// Precision
|
|
|
|
|
|
lvi.SubItems.Add(item.Width.ToString()); /// Width
|
|
|
|
|
|
lvi.SubItems.Add(item.Alignment.ToString()); /// Alignment
|
|
|
|
|
|
|
|
|
|
|
|
selectedResultsListViewEx.Items.Add(lvi);
|
2016-04-24 06:55:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-04-29 05:40:34 +00:00
|
|
|
|
void UpdateSelectedFromView()
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-04-24 06:55:39 +00:00
|
|
|
|
void availableResultsListBox_DoubleClick(object sender, EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
/// Double click works when just one item is selected
|
|
|
|
|
|
if (availableResultsListBox.SelectedIndices.Count == 1)
|
|
|
|
|
|
{
|
2016-04-29 05:40:34 +00:00
|
|
|
|
var oriItem = AvailableItems[availableResultsListBox.SelectedIndices[0]];
|
|
|
|
|
|
SelectedItems.Add(oriItem.Clone());
|
2016-04-24 06:55:39 +00:00
|
|
|
|
RedrawAvailable();
|
|
|
|
|
|
RedrawSelected();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void addButton_Click(object sender, EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
/// Append at the end, this code supports multiple selected items,
|
|
|
|
|
|
/// although ListBox control settings may limit the max.number of selected items to one.
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = availableResultsListBox.SelectedIndices.Count - 1; i >= 0; i--)
|
|
|
|
|
|
{
|
2016-04-29 05:40:34 +00:00
|
|
|
|
var oriItem = AvailableItems[availableResultsListBox.SelectedIndices[i]];
|
|
|
|
|
|
SelectedItems.Add(oriItem.Clone());
|
2016-04-24 06:55:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
RedrawAvailable();
|
|
|
|
|
|
RedrawSelected();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void selectedResultsListBox_DoubleClick(object sender, EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
/// Double click works when just one item is selected
|
|
|
|
|
|
|
2016-04-29 05:40:34 +00:00
|
|
|
|
if (selectedResultsListViewEx.SelectedIndices.Count == 1)
|
2016-04-24 06:55:39 +00:00
|
|
|
|
{
|
2016-04-29 05:40:34 +00:00
|
|
|
|
SelectedItems.RemoveAt(selectedResultsListViewEx.SelectedIndices[0]);
|
2016-04-24 06:55:39 +00:00
|
|
|
|
RedrawAvailable();
|
|
|
|
|
|
RedrawSelected();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void removeButton_Click(object sender, EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
/// Remove from the list (the last selected item first so that the indexes are not affected)
|
|
|
|
|
|
|
2016-04-29 05:40:34 +00:00
|
|
|
|
for (int i = selectedResultsListViewEx.SelectedIndices.Count - 1; i >= 0; i--)
|
2016-04-24 06:55:39 +00:00
|
|
|
|
{
|
2016-04-29 05:40:34 +00:00
|
|
|
|
SelectedItems.RemoveAt(selectedResultsListViewEx.SelectedIndices[i]);
|
2016-04-24 06:55:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
RedrawAvailable();
|
|
|
|
|
|
RedrawSelected();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void removeAllButton_Click(object sender, EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
/// Remove all items from 'Selected' list
|
|
|
|
|
|
|
|
|
|
|
|
SelectedItems.Clear();
|
|
|
|
|
|
RedrawAvailable();
|
|
|
|
|
|
RedrawSelected();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void okButton_Click(object sender, EventArgs e)
|
|
|
|
|
|
{
|
2016-04-29 05:40:34 +00:00
|
|
|
|
DialogResult = DialogResult.OK;
|
2016-04-24 06:55:39 +00:00
|
|
|
|
Close();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|