Refactorization : BenchControl -> Rig
This commit is contained in:
@@ -0,0 +1,185 @@
|
||||
///
|
||||
/// 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.Rig.TestMethods.PulsesTestManual
|
||||
{
|
||||
public partial class ManualPulsesForm24 : Form, GenericDevices.IHasCompleted, IHasGetPassed
|
||||
{
|
||||
private static readonly ILog log = LogManager.GetLogger(typeof(ManualPulsesForm24));
|
||||
|
||||
const int MaxWMsCount = 24; /// 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;
|
||||
CheckBox[] pulsesCountOKCheckBox;
|
||||
|
||||
///
|
||||
/// Result of manual pulses test
|
||||
///
|
||||
bool[] passed;
|
||||
public bool GetPassed(int i) { return (i >= 0 && i < passed.Length) ? passed[i] : false; }
|
||||
|
||||
///
|
||||
/// 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 ManualPulsesForm24()
|
||||
{
|
||||
InitializeComponent();
|
||||
ControlBox = false;
|
||||
|
||||
textBoxesCount = MaxWMsCount;
|
||||
|
||||
labels = new Label[MaxWMsCount]
|
||||
{
|
||||
wmPulsesCountLabel1, wmPulsesCountLabel2, wmPulsesCountLabel3, wmPulsesCountLabel4,
|
||||
wmPulsesCountLabel5, wmPulsesCountLabel6, wmPulsesCountLabel7, wmPulsesCountLabel8,
|
||||
wmPulsesCountLabel9, wmPulsesCountLabel10, wmPulsesCountLabel11, wmPulsesCountLabel12,
|
||||
wmPulsesCountLabel13, wmPulsesCountLabel14, wmPulsesCountLabel15, wmPulsesCountLabel16,
|
||||
wmPulsesCountLabel17, wmPulsesCountLabel18, wmPulsesCountLabel19, wmPulsesCountLabel20,
|
||||
wmPulsesCountLabel21, wmPulsesCountLabel22, wmPulsesCountLabel23, wmPulsesCountLabel24,
|
||||
};
|
||||
pulsesCountOKCheckBox = new CheckBox[MaxWMsCount]
|
||||
{
|
||||
pulsesCountOKCheckBox1, pulsesCountOKCheckBox2, pulsesCountOKCheckBox3, pulsesCountOKCheckBox4,
|
||||
pulsesCountOKCheckBox5, pulsesCountOKCheckBox6, pulsesCountOKCheckBox7, pulsesCountOKCheckBox8,
|
||||
pulsesCountOKCheckBox9, pulsesCountOKCheckBox10, pulsesCountOKCheckBox11, pulsesCountOKCheckBox12,
|
||||
pulsesCountOKCheckBox13, pulsesCountOKCheckBox14, pulsesCountOKCheckBox15, pulsesCountOKCheckBox16,
|
||||
pulsesCountOKCheckBox17, pulsesCountOKCheckBox18, pulsesCountOKCheckBox19, pulsesCountOKCheckBox20,
|
||||
pulsesCountOKCheckBox21, pulsesCountOKCheckBox22, pulsesCountOKCheckBox23, pulsesCountOKCheckBox24,
|
||||
};
|
||||
|
||||
completed = false;
|
||||
minPulsesCount = 1; /// Must be >0 so that initially the indication is RED
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructor
|
||||
/// </summary>
|
||||
/// <param name="waterMetersCount">Number of text boxes for serial numbers</param>
|
||||
public ManualPulsesForm24(IList<GenericDevices.IWaterMeter> waterMeters)
|
||||
: this()
|
||||
{
|
||||
waterMetersCount = waterMeters.Count;
|
||||
|
||||
ShuffleTextBoxes(waterMetersCount, Config.Data.LineSize);
|
||||
|
||||
disabled = new bool[waterMetersCount];
|
||||
passed = new bool[waterMetersCount];
|
||||
for (int i = 0; i < waterMetersCount; i++)
|
||||
{
|
||||
disabled[i] = waterMeters[i].Disabled;
|
||||
passed[i] = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <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];
|
||||
pulsesCountOKCheckBox[dest] = pulsesCountOKCheckBox[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("{0} {1}", Strings.Water_Meter, i + 1);
|
||||
pulsesCountOKCheckBox[i].Text = Strings.Pulses_count_is_OK;
|
||||
}
|
||||
okButton.Text = Strings.OkBtnText;
|
||||
}
|
||||
|
||||
private void WMPulsesForm24_Load(object sender, EventArgs e)
|
||||
{
|
||||
Localize();
|
||||
|
||||
//Height = 50 + 90 * WaterMetersCount;
|
||||
|
||||
for (int i = 0; i < textBoxesCount; i++)
|
||||
{
|
||||
labels[i].Visible = (disabled == null || i >= disabled.Length || !disabled[i]);
|
||||
pulsesCountOKCheckBox[i].Visible = (disabled == null || i >= disabled.Length || !disabled[i]);
|
||||
pulsesCountOKCheckBox[i].Checked = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void okButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
int count = Math.Min(waterMetersCount, TBF.Rig.Sequences.ProcessData.BatchRslts.WMPositionsCount);
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
passed[i] = pulsesCountOKCheckBox[i].Checked;
|
||||
}
|
||||
|
||||
completed = true;
|
||||
Close();
|
||||
}
|
||||
|
||||
#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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user