2019-08-12 17:47:58 +00:00
|
|
|
|
///
|
|
|
|
|
|
/// Copyright (c) 2019 Sensus Slovensko a.s.
|
|
|
|
|
|
///
|
|
|
|
|
|
using System;
|
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
using System.Collections.Generic;
|
2021-09-23 09:46:40 +00:00
|
|
|
|
using Common;
|
2019-08-12 17:47:58 +00:00
|
|
|
|
|
|
|
|
|
|
namespace Results.Forms
|
|
|
|
|
|
{
|
|
|
|
|
|
public partial class OneWMResultsRowsCtrl : UserControl, IOneWMResultsCtrl
|
|
|
|
|
|
{
|
|
|
|
|
|
public event EventHandler<WaterMeterEventArgs> WMResultsClickedHandler;
|
|
|
|
|
|
///
|
|
|
|
|
|
private void tBox_MouseDoubleClick(object sender, MouseEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
if (WMResultsClickedHandler != null) WMResultsClickedHandler(sender, new WaterMeterEventArgs(wmPosition));
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception)
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool disabled;
|
|
|
|
|
|
int wmPosition; /// 1-based water meter position
|
|
|
|
|
|
string caption;
|
|
|
|
|
|
Color bkColor;
|
|
|
|
|
|
int[] columnWidths;
|
|
|
|
|
|
IList<Results.WMeterRsltItemSpec> items;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public bool Disabled { get { return disabled; } } /// Read only
|
|
|
|
|
|
public int WMPosition { get { return wmPosition; } } /// Read only
|
|
|
|
|
|
public ListView.ColumnHeaderCollection Columns { get { return lView.Columns; } } /// Read only
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public OneWMResultsRowsCtrl()
|
|
|
|
|
|
{
|
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
|
disabled = false;
|
|
|
|
|
|
wmPosition = 0;
|
|
|
|
|
|
tBox.Text = caption = "---";
|
|
|
|
|
|
tBox.BackColor = lView.BackColor = bkColor = Color.White;
|
|
|
|
|
|
items = new List<Results.WMeterRsltItemSpec>();
|
|
|
|
|
|
columnWidths = new int[0];
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void Update(int[] columnWidths)
|
|
|
|
|
|
{
|
|
|
|
|
|
this.columnWidths = columnWidths;
|
|
|
|
|
|
|
|
|
|
|
|
/// Always update ListView column widths
|
|
|
|
|
|
int col = 0;
|
|
|
|
|
|
foreach (ColumnHeader column in lView.Columns)
|
|
|
|
|
|
{
|
|
|
|
|
|
column.Width = (columnWidths != null && columnWidths.Length > col) ? columnWidths[col] : ((col == 0) ? 40 : 70);
|
|
|
|
|
|
col++;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void Update(IList<Results.WMeterRsltItemSpec> items)
|
|
|
|
|
|
{
|
|
|
|
|
|
this.items = items;
|
|
|
|
|
|
|
|
|
|
|
|
/// Always draw ListView header
|
|
|
|
|
|
lView.Columns.Clear();
|
2019-09-23 05:15:32 +00:00
|
|
|
|
lView.Columns.Add(wmPosition.ToString(), (columnWidths != null && columnWidths.Length > 0) ? columnWidths[0] : 40);
|
2019-08-12 17:47:58 +00:00
|
|
|
|
|
|
|
|
|
|
if (items == null || items.Count == 0) return;
|
|
|
|
|
|
int col = 1;
|
|
|
|
|
|
foreach (var item in items)
|
|
|
|
|
|
{
|
2019-09-23 05:15:32 +00:00
|
|
|
|
lView.Columns.Add(item.Caption, (columnWidths != null && columnWidths.Length > col) ? columnWidths[col] : 70);
|
2019-08-12 17:47:58 +00:00
|
|
|
|
col++;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void Update(Results.Entities.WaterMeter wMtr)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (wMtr == null || wMtr.Disabled)
|
|
|
|
|
|
{
|
|
|
|
|
|
/// Water meter position is disabled
|
|
|
|
|
|
this.disabled = true;
|
|
|
|
|
|
lView.Items.Clear();
|
|
|
|
|
|
tBox.Text = caption = "---";
|
|
|
|
|
|
tBox.BackColor = lView.BackColor = bkColor = Color.White;
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Update background color
|
|
|
|
|
|
string message = string.Empty;
|
2021-06-01 05:55:20 +00:00
|
|
|
|
UpdateBkColor(wMtr.GetColorOfResults(false, out message));
|
2019-08-12 17:47:58 +00:00
|
|
|
|
|
|
|
|
|
|
/// Update caption
|
|
|
|
|
|
#if ORACLE_DB
|
|
|
|
|
|
tBox.Text = caption = string.Format("{0} ({1}) {2}", (string.IsNullOrEmpty(wMtr.SerialNr) ? string.Empty : wMtr.SerialNr), (wMtr.Pruefindex % 100), message);
|
|
|
|
|
|
#else
|
|
|
|
|
|
tBox.Text = caption = string.Format("s/n = {0}", string.IsNullOrEmpty(wMtr.SerialNr) ? string.Empty : wMtr.SerialNr);
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
2021-06-01 05:55:20 +00:00
|
|
|
|
UpdateWMPos(wMtr.WMPosition);
|
2019-08-12 17:47:58 +00:00
|
|
|
|
|
|
|
|
|
|
/// Update test results
|
|
|
|
|
|
IList<string> testNames = wMtr.GetAllDecoratedTestNames();
|
|
|
|
|
|
int ix = 0;
|
|
|
|
|
|
lView.Items.Clear();
|
|
|
|
|
|
foreach (var mtr in wMtr.MeterTestRslts)
|
|
|
|
|
|
{
|
2021-09-23 09:46:40 +00:00
|
|
|
|
if (mtr != null && mtr.IsPilotRslt() && mtr.TestDone && mtr.Publish() != Publish.Never
|
|
|
|
|
|
&& mtr.Publish() != Publish.Internal)
|
2019-08-12 17:47:58 +00:00
|
|
|
|
{
|
|
|
|
|
|
ListViewItem lvi = new ListViewItem(testNames[ix++]);
|
|
|
|
|
|
|
|
|
|
|
|
if (items != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
for (int i = 0; i < items.Count; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
string str = items[i].Print(wMtr, mtr.Name());
|
|
|
|
|
|
|
|
|
|
|
|
/// Extract and use color information
|
|
|
|
|
|
string[] texts = str.Split(new char[] { '|' });
|
|
|
|
|
|
if (texts.Length == 1)
|
|
|
|
|
|
{
|
|
|
|
|
|
lvi.SubItems.Add(str);
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (texts.Length == 2)
|
|
|
|
|
|
{
|
|
|
|
|
|
Color color = texts[1].Equals("Green") ? Color.Green : (texts[1].Equals("Red") ? Color.Red : Color.White);
|
|
|
|
|
|
lvi.UseItemStyleForSubItems = false;
|
|
|
|
|
|
lvi.SubItems.Add(texts[0]);
|
|
|
|
|
|
lvi.SubItems[lvi.SubItems.Count - 1].BackColor = color;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
lvi.SubItems.Add(string.Empty);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
lView.Items.Add(lvi);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
///
|
|
|
|
|
|
/// Private
|
|
|
|
|
|
///
|
|
|
|
|
|
|
2021-06-01 05:55:20 +00:00
|
|
|
|
void UpdateWMPos(int wmPosition)
|
2019-08-12 17:47:58 +00:00
|
|
|
|
{
|
|
|
|
|
|
this.wmPosition = wmPosition;
|
|
|
|
|
|
if (lView.Columns.Count > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
lView.Columns[0].Text = wmPosition.ToString();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-06-01 05:55:20 +00:00
|
|
|
|
void UpdateBkColor(Color backColor)
|
2019-08-12 17:47:58 +00:00
|
|
|
|
{
|
|
|
|
|
|
if (this.bkColor != backColor)
|
|
|
|
|
|
{
|
|
|
|
|
|
tBox.BackColor = lView.BackColor = this.bkColor = backColor;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|