A – Registration and execution - Register GenesisCommunication Factory in the component list. - Separate the Genesis form and sequence from iPerl communication. B – Communication activities - Restore initialization, connection, PCB reading, password and login. - Include grouped login, mode switching and disconnection. - Support processing up to 10 slots. C1 – Input calibration factors - Read three factors from Water meters / Text1–Text3. - Validate integer values in the range 1–65535. - Preserve the default of 15625 when all three fields are empty. D – Q3 calibration - Connect the Prepare Q3 → measurement → Write Q3 workflow. - Add channel processing to FlyingStart and FlyingStartMassCollection. - Reset previous measurement data and validate calculated factors. - Mark factors as stored only after StoreCalibration succeeds. E – Results and database - Store calibration factors separately for each meter and channel. - Add result entities, mappings and Q3 data. - Extend DB.cs / EnsureSchema to create and update the schema. - Preserve compatibility with the existing binary format. Validation: - Debug build and 18 tests passed. - Simulated communication runs follow the same activity sequence. - The complete Q3 workflow has not yet been verified on hardware. Known limitation: - An inherited mismatch in simulated responses and error propagation can produce an incorrect OK result; this change does not fix it.
178 lines
6.2 KiB
C#
178 lines
6.2 KiB
C#
///
|
|
/// Copyright (c) 2019-2022 Sensus Slovensko a.s.
|
|
///
|
|
using System;
|
|
using System.Drawing;
|
|
using System.Windows.Forms;
|
|
using System.Collections.Generic;
|
|
using Common;
|
|
|
|
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();
|
|
lView.Columns.Add(wmPosition.ToString(), (columnWidths != null && columnWidths.Length > 0) ? columnWidths[0] : 40);
|
|
|
|
if (items == null || items.Count == 0) return;
|
|
int col = 1;
|
|
foreach (var item in items)
|
|
{
|
|
lView.Columns.Add(item.Caption, (columnWidths != null && columnWidths.Length > col) ? columnWidths[col] : 70);
|
|
col++;
|
|
}
|
|
}
|
|
|
|
public void Update(Results.Entities.WaterMeter wMtr)
|
|
{
|
|
if (wMtr == null || (wMtr.Disabled && wMtr.Q3Channel == 0))
|
|
{
|
|
/// 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;
|
|
UpdateBkColor(wMtr.GetColorOfResults(false, out message));
|
|
|
|
/// Update caption
|
|
#if ORACLE_DB
|
|
tBox.Text = caption = string.Format("{0} ({1}) {2} {3}",
|
|
wMtr.WMPosition,
|
|
wMtr.Pruefindex == 0 ? "?" : string.Format("{0}x", wMtr.Pruefindex % 100),
|
|
(string.IsNullOrEmpty(wMtr.SerialNr) ? string.Empty : wMtr.SerialNr),
|
|
message);
|
|
#else
|
|
tBox.Text = caption = string.Format("s/n = {0}", string.IsNullOrEmpty(wMtr.SerialNr) ? string.Empty : wMtr.SerialNr);
|
|
#endif
|
|
|
|
UpdateWMPos(wMtr.WMPosition);
|
|
|
|
/// Update test results
|
|
IList<string> testNames = wMtr.GetAllDecoratedTestNames();
|
|
int ix = 0;
|
|
lView.Items.Clear();
|
|
foreach (var mtr in wMtr.MeterTestRslts)
|
|
{
|
|
if (mtr != null && mtr.IsPilotRslt() &&
|
|
(mtr.Q3Channel!=0 || (mtr.TestDone &&
|
|
mtr.Publish() != Publish.Never &&
|
|
mtr.Publish() != Publish.Internal)
|
|
) )
|
|
{
|
|
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
|
|
///
|
|
|
|
void UpdateWMPos(int wmPosition)
|
|
{
|
|
this.wmPosition = wmPosition;
|
|
if (lView.Columns.Count > 0)
|
|
{
|
|
lView.Columns[0].Text = wmPosition.ToString();
|
|
}
|
|
}
|
|
|
|
void UpdateBkColor(Color backColor)
|
|
{
|
|
if (this.bkColor != backColor)
|
|
{
|
|
tBox.BackColor = lView.BackColor = this.bkColor = backColor;
|
|
}
|
|
}
|
|
}
|
|
}
|