235 lines
6.9 KiB
C#
235 lines
6.9 KiB
C#
///
|
|
/// Copyright (c) 2018 Sensus Slovensko a.s.
|
|
///
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Drawing;
|
|
using System.Windows.Forms;
|
|
using log4net;
|
|
using Config.Entities;
|
|
using TBF.Resources;
|
|
|
|
namespace TBF.BenchControl.TestMethods.PulsesTest
|
|
{
|
|
public partial class WMPulsesForm12 : Form, GenericDevices.IHasCompleted
|
|
{
|
|
private static readonly ILog log = LogManager.GetLogger(typeof(WMPulsesForm12));
|
|
|
|
const int MaxWMsCount = 12; /// Implementation limit of this form
|
|
|
|
///
|
|
/// Updated in constructor
|
|
///
|
|
readonly int waterMetersCount; /// Number of text boxes for serial numbers
|
|
readonly bool[] disabled;
|
|
int textBoxesCount;
|
|
Label[] labels;
|
|
TextBox[] pulsesCountTextBox;
|
|
Rectangle[] rects;
|
|
|
|
///
|
|
/// Updated in OnAdjustmentInProgress()
|
|
///
|
|
double[] pulsesCount; /// Created in constructor
|
|
double minPulsesCount;
|
|
|
|
///
|
|
/// Set to 'true' when the form closes
|
|
///
|
|
public bool Completed { get { return completed; } }
|
|
bool completed;
|
|
|
|
|
|
/// <summary> Parameterless constructor for 3 watermeters </summary>
|
|
public WMPulsesForm12()
|
|
{
|
|
InitializeComponent();
|
|
ControlBox = false;
|
|
|
|
textBoxesCount = MaxWMsCount;
|
|
|
|
labels = new Label[MaxWMsCount]
|
|
{
|
|
wmPulsesCountLabel1, wmPulsesCountLabel2, wmPulsesCountLabel3, wmPulsesCountLabel4,
|
|
wmPulsesCountLabel5, wmPulsesCountLabel6, wmPulsesCountLabel7, wmPulsesCountLabel8,
|
|
wmPulsesCountLabel9, wmPulsesCountLabel10, wmPulsesCountLabel11, wmPulsesCountLabel12,
|
|
};
|
|
pulsesCountTextBox = new TextBox[MaxWMsCount]
|
|
{
|
|
wmPulsesCountTextBox1, wmPulsesCountTextBox2, wmPulsesCountTextBox3, wmPulsesCountTextBox4,
|
|
wmPulsesCountTextBox5, wmPulsesCountTextBox6, wmPulsesCountTextBox7, wmPulsesCountTextBox8,
|
|
wmPulsesCountTextBox9, wmPulsesCountTextBox10, wmPulsesCountTextBox11, wmPulsesCountTextBox12,
|
|
};
|
|
|
|
rects = new Rectangle[MaxWMsCount];
|
|
for (int i = 0; i < MaxWMsCount; i++)
|
|
{
|
|
int row = i % 12;
|
|
int col = i / 12;
|
|
rects[i] = new Rectangle(350 + col * 557, 25 + row * 47, 230, 37);
|
|
}
|
|
|
|
completed = false;
|
|
minPulsesCount = 1; /// Must be >0 so that initially the indication is RED
|
|
|
|
StartForceCloseHandler();
|
|
|
|
/// Attach to 'AdjustmentInProgress' handler
|
|
UiBridge.Bridge.PulsesTestInProgressHandler += delegate(object sender, UiBridge.PulsesTestInProgressEventArgs args)
|
|
{
|
|
if (InvokeRequired)
|
|
{
|
|
Invoke(new EventHandler<UiBridge.PulsesTestInProgressEventArgs>(OnPulsesTestInProgress), sender, args);
|
|
}
|
|
else OnPulsesTestInProgress(sender, args);
|
|
};
|
|
}
|
|
|
|
/// <summary>
|
|
/// Constructor
|
|
/// </summary>
|
|
/// <param name="waterMetersCount">Number of text boxes for serial numbers</param>
|
|
public WMPulsesForm12(IList<GenericDevices.IWaterMeter> waterMeters)
|
|
: this()
|
|
{
|
|
waterMetersCount = waterMeters.Count;
|
|
|
|
ShuffleTextBoxes(waterMetersCount, TBF.Data.LineSize);
|
|
|
|
disabled = new bool[waterMetersCount];
|
|
for (int i = 0; i < waterMetersCount; i++) disabled[i] = waterMeters[i].Disabled;
|
|
|
|
pulsesCount = new double[waterMetersCount];
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Make sure the layout of labels/text boxes on the screen
|
|
/// corresponds to the layout of watermeters of the test bench.
|
|
/// </summary>
|
|
/// <param name="wmsCount">Number of watermeters</param>
|
|
/// <param name="lineSize">Number of watermeters in one line</param>
|
|
void ShuffleTextBoxes(int wmsCount, int lineSize)
|
|
{
|
|
if (wmsCount < textBoxesCount && lineSize > 0)
|
|
{
|
|
int nrLines = (wmsCount + lineSize - 1) / lineSize;
|
|
int gap = (textBoxesCount - wmsCount) / nrLines;
|
|
|
|
int dest = 0;
|
|
for (int l = 0; l < nrLines; l++)
|
|
{
|
|
for (int i = 0; i < lineSize; i++)
|
|
{
|
|
labels[dest] = labels[l * lineSize + l * gap + i];
|
|
pulsesCountTextBox[dest] = pulsesCountTextBox[l * lineSize + l * gap + i];
|
|
rects[dest] = rects[l * lineSize + l * gap + i];
|
|
dest++;
|
|
}
|
|
}
|
|
textBoxesCount = wmsCount;
|
|
}
|
|
}
|
|
|
|
|
|
void Localize()
|
|
{
|
|
Text = Strings.Water_Meter_States;
|
|
for (int i = 0; i < textBoxesCount; i++)
|
|
{
|
|
labels[i].Text = string.Format("WM{0} {1}", i + 1, Strings.Pulses);
|
|
}
|
|
}
|
|
|
|
private void WMPulsesForm12_Load(object sender, EventArgs e)
|
|
{
|
|
Localize();
|
|
|
|
//Height = 50 + 90 * WaterMetersCount;
|
|
|
|
for (int i = 0; i < textBoxesCount; i++)
|
|
{
|
|
labels[i].Visible = pulsesCountTextBox[i].Visible = (disabled == null || i >= disabled.Length || !disabled[i]);
|
|
pulsesCountTextBox[i].Text = "---";
|
|
}
|
|
}
|
|
|
|
void OnPulsesTestInProgress(object sender, UiBridge.PulsesTestInProgressEventArgs args)
|
|
{
|
|
string testName = args.TestName;
|
|
minPulsesCount = args.MinPulsesCount;
|
|
|
|
Results.Entities.TestRslt tr = TBF.BenchControl.Sequences.ProcessData.BatchRslts.GetTestRslt(testName, 0);
|
|
|
|
int count = Math.Min(waterMetersCount, TBF.BenchControl.Sequences.ProcessData.BatchRslts.WMPositionsCount);
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
Results.Entities.MeterTestRslt mtr = TBF.BenchControl.Sequences.ProcessData.BatchRslts.GetMeterTestRslt(testName, i, CompoundMeterId.Single);
|
|
if (mtr != null) pulsesCount[i] = mtr.PulsesMeter;
|
|
}
|
|
|
|
Redraw();
|
|
}
|
|
|
|
void Redraw()
|
|
{
|
|
for (int i = 0; i < textBoxesCount; i++)
|
|
{
|
|
pulsesCountTextBox[i].Text = pulsesCount[i].ToString("F0");
|
|
Invalidate(rects[i]);
|
|
}
|
|
}
|
|
|
|
private void WMPulsesForm12_Paint(object sender, PaintEventArgs e)
|
|
{
|
|
System.Drawing.Graphics graphics = this.CreateGraphics();
|
|
|
|
for (int i = 0; i < waterMetersCount; i++)
|
|
{
|
|
if (!disabled[i])
|
|
{
|
|
PaintOne(graphics, rects[i], pulsesCount[i], minPulsesCount);
|
|
}
|
|
}
|
|
}
|
|
|
|
void PaintOne(System.Drawing.Graphics g, Rectangle r, double value, double limLo)
|
|
{
|
|
Rectangle rect1 = new Rectangle(r.Left, r.Top, r.Width / 3, r.Height);
|
|
Rectangle rect2 = new Rectangle(r.Left + r.Width / 3, r.Top, r.Width / 3, r.Height);
|
|
Rectangle rect3 = new Rectangle(r.Left + 2 * (r.Width / 3), r.Top, r.Width / 3, r.Height);
|
|
|
|
Brush redBrush = new SolidBrush(Color.FromName("Salmon"));
|
|
Brush greenBrush = new SolidBrush(Color.FromName("LightGreen"));
|
|
Brush centBrush = new SolidBrush(Color.FromName("Green"));
|
|
if (value >= limLo)
|
|
{
|
|
g.FillRectangle(greenBrush, rect2);
|
|
}
|
|
else
|
|
{
|
|
g.FillRectangle(redBrush, rect2);
|
|
}
|
|
}
|
|
|
|
#region Forced close handling
|
|
|
|
public void StartForceCloseHandler()
|
|
{
|
|
UiBridge.Bridge.CloseModelessFormHandler += delegate(object sender, EventArgs args)
|
|
{
|
|
if (InvokeRequired) { Invoke(new EventHandler<EventArgs>(OnForceClose), sender, args); }
|
|
else OnForceClose(sender, args);
|
|
};
|
|
}
|
|
|
|
void OnForceClose(object sender, EventArgs args)
|
|
{
|
|
DialogResult = DialogResult.Cancel;
|
|
Close();
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|