Refactoring : TestBenchFramework --> TBF ver. 2.18.789
This commit is contained in:
@@ -0,0 +1,263 @@
|
||||
///
|
||||
/// Copyright (c) 2016 Sensus Metering Systems
|
||||
///
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Windows.Forms;
|
||||
using log4net;
|
||||
using TBF.BenchControl.GenericDevices;
|
||||
using TBF.Resources;
|
||||
|
||||
namespace TBF.BenchControl.TestMethods.Endurance
|
||||
{
|
||||
public partial class CycleDlg : Form, TBF.UiControls.IParentOfListViewEx
|
||||
{
|
||||
static readonly ILog log = LogManager.GetLogger(typeof(CycleDlg));
|
||||
|
||||
/// Used when re-scaling the dialog: 100% = 96dpi, 125% = 120dpi, 150% = 144dpi
|
||||
public readonly int Dpi;
|
||||
public const int Dpi100pct = 96;
|
||||
|
||||
/// <summary>
|
||||
/// Transition sequences to be updated by this dialog.
|
||||
/// Set by the constructor or updated by the parent after creation and before loading.
|
||||
/// </summary>
|
||||
public IList<CycleStep> EnduranceCycle;
|
||||
|
||||
|
||||
/// Auxiliary public lists used also by user controls in tab pages
|
||||
public IList<BenchControl.Generic.IComponent> TbfComponents;
|
||||
public IList<IValve> Valves;
|
||||
|
||||
|
||||
TBF.UiControls.ITabWithListViewEx seqStepsCtrl;
|
||||
|
||||
|
||||
public CycleDlg()
|
||||
: this(new List<CycleStep>())
|
||||
{
|
||||
}
|
||||
|
||||
public CycleDlg(IList<CycleStep> cycle)
|
||||
{
|
||||
/// Detect display setting: 100% = 96dpi, 125% = 120dpi, 150% = 144dpi.
|
||||
Dpi = (int)this.CreateGraphics().DpiX;
|
||||
|
||||
InitializeComponent();
|
||||
|
||||
/// SharedDlgButtons configuration
|
||||
sharedButtons.RequiredGroupMembership = Users.Grp.GID.Metrologists;
|
||||
sharedButtons.OptionalButtons = TBF.UiControls.SharedButtons.Buttons.Add |
|
||||
TBF.UiControls.SharedButtons.Buttons.Remove |
|
||||
TBF.UiControls.SharedButtons.Buttons.Up |
|
||||
TBF.UiControls.SharedButtons.Buttons.Down;
|
||||
sharedButtons.Unlocked += Unlocked;
|
||||
sharedButtons.OKClicked += okButton_Click;
|
||||
sharedButtons.CancelClicked += cancelButton_Click;
|
||||
sharedButtons.AddClicked += addButton_Click;
|
||||
sharedButtons.RemoveClicked += removeButton_Click;
|
||||
sharedButtons.UpClicked += upButton_Click;
|
||||
sharedButtons.DownClicked += downButton_Click;
|
||||
|
||||
seqStepsCtrl = new CycleStepsCtrl();
|
||||
|
||||
/// Prepare a list of valves for the endurance test
|
||||
TbfComponents = BenchControl.TbfComponents.LoadComponentsFromDB(Config.FluentCommon.CreateSession(Users.Entities.DBKind.Config));
|
||||
Valves = new List<IValve>();
|
||||
for (int bitNr = 0; bitNr < 8; bitNr++)
|
||||
{
|
||||
foreach (var vlv in TbfComponents)
|
||||
{
|
||||
if (vlv is BenchControl.Elde.Valve.Valve && (vlv as BenchControl.Elde.Valve.Valve).BitPosition == bitNr)
|
||||
{
|
||||
Valves.Add(vlv as IValve);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
EnduranceCycle = (cycle != null) ? cycle : new List<CycleStep>(); /// TODO: Load from component parameters
|
||||
|
||||
/// Create a tab with sequence steps for each sequence ordered by ItemNr.
|
||||
AddCycleStepsTab(EnduranceCycle);
|
||||
}
|
||||
|
||||
void AddCycleStepsTab(IList<CycleStep> sequence)
|
||||
{
|
||||
TabPage nwTab = new TabPage();
|
||||
nwTab.Tag = sequence;
|
||||
CycleStepsCtrl newCtrl = new CycleStepsCtrl();
|
||||
seqStepsCtrl = newCtrl;
|
||||
nwTab.Controls.Add(newCtrl);
|
||||
tabControl.TabPages.Add(nwTab);
|
||||
newCtrl.Initialize(sequence, this, tabControl.TabPages[tabControl.TabPages.Count - 1]);
|
||||
newCtrl.SelectedIndexChanged += new System.EventHandler(SelectedIndexChanged);
|
||||
}
|
||||
|
||||
private void CycleDlg_Load(object sender, EventArgs e)
|
||||
{
|
||||
Localize();
|
||||
|
||||
TBF.LocalSettings ls = Program.LocalSettings;
|
||||
Width = (ls.EnduranceDlgWidth > 0) ? ls.EnduranceDlgWidth : 1050;
|
||||
Height = (ls.EnduranceDlgHeight > 0) ? ls.EnduranceDlgHeight : 360;
|
||||
Left = (ls.EnduranceDlgLeft != 0) ? ls.EnduranceDlgLeft : 150;
|
||||
Top = (ls.EnduranceDlgTop != 0) ? ls.EnduranceDlgTop : 150;
|
||||
|
||||
/// Now refresh the content of the dialog
|
||||
RefreshAllTabs();
|
||||
}
|
||||
|
||||
void Localize()
|
||||
{
|
||||
Text = Strings.Endurance_cycle_steps;
|
||||
}
|
||||
|
||||
void RefreshAllTabs()
|
||||
{
|
||||
if (seqStepsCtrl != null) (seqStepsCtrl as Results.Forms.ListViewEx).Refresh();
|
||||
}
|
||||
|
||||
private void Unlocked(object sender, EventArgs e)
|
||||
{
|
||||
if (seqStepsCtrl != null) seqStepsCtrl.Unlock();
|
||||
}
|
||||
|
||||
private void okButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (seqStepsCtrl != null) seqStepsCtrl.OkBtnClicked();
|
||||
|
||||
//if (EnduranceCycle != null)
|
||||
//{
|
||||
// using (var transaction = Session.BeginTransaction())
|
||||
// {
|
||||
// try
|
||||
// {
|
||||
// Session.SaveOrUpdate(EnduranceCycle);
|
||||
// transaction.Commit();
|
||||
// }
|
||||
// catch (Exception e2)
|
||||
// {
|
||||
// MessageBox.Show(Strings.Cannot_save_changes, Strings.Error, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
|
||||
// log.ErrorFormat("Update of sequence 'Tr1' in the database failed: {0}", e2.Message);
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
||||
Program.LocalSettings.EnduranceDlgLeft = Location.X;
|
||||
Program.LocalSettings.EnduranceDlgTop = Location.Y;
|
||||
Program.LocalSettings.EnduranceDlgWidth = Size.Width;
|
||||
Program.LocalSettings.EnduranceDlgHeight = Size.Height;
|
||||
Program.LocalSettings.Save();
|
||||
|
||||
DialogResult = DialogResult.OK;
|
||||
Close();
|
||||
return;
|
||||
}
|
||||
|
||||
private void cancelButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
Program.LocalSettings.EnduranceDlgLeft = Location.X;
|
||||
Program.LocalSettings.EnduranceDlgTop = Location.Y;
|
||||
Program.LocalSettings.EnduranceDlgWidth = Size.Width;
|
||||
Program.LocalSettings.EnduranceDlgHeight = Size.Height;
|
||||
Program.LocalSettings.Save();
|
||||
|
||||
DialogResult = DialogResult.Cancel;
|
||||
Close();
|
||||
return;
|
||||
}
|
||||
|
||||
int slctdTab;
|
||||
|
||||
private void tabControl_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
if (seqStepsCtrl != null)
|
||||
{
|
||||
seqStepsCtrl.OkBtnClicked();
|
||||
}
|
||||
slctdTab = tabControl.SelectedIndex;
|
||||
sharedButtons.SetEnabled(TBF.UiControls.SharedButtons.Buttons.Add, true);
|
||||
sharedButtons.DisableButtons(TBF.UiControls.SharedButtons.Buttons.Remove);
|
||||
RefreshAllTabs();
|
||||
}
|
||||
|
||||
private void addButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (seqStepsCtrl != null) seqStepsCtrl.AddOne();
|
||||
}
|
||||
|
||||
private void removeButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (seqStepsCtrl != null) seqStepsCtrl.RemoveSelected();
|
||||
}
|
||||
|
||||
private void upButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (seqStepsCtrl != null) seqStepsCtrl.MoveUpSelected();
|
||||
}
|
||||
|
||||
private void downButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (seqStepsCtrl != null) seqStepsCtrl.MoveDownSelected();
|
||||
}
|
||||
|
||||
public void UpdateButtonStates(TBF.UiControls.SharedButtons.SelectedItemPos selectedItemPos)
|
||||
{
|
||||
if (selectedItemPos == TBF.UiControls.SharedButtons.SelectedItemPos.None)
|
||||
{
|
||||
sharedButtons.DisableButtons(TBF.UiControls.SharedButtons.Buttons.Up |
|
||||
TBF.UiControls.SharedButtons.Buttons.Down);
|
||||
}
|
||||
else if (selectedItemPos == TBF.UiControls.SharedButtons.SelectedItemPos.First)
|
||||
{
|
||||
sharedButtons.EnableButtons(TBF.UiControls.SharedButtons.Buttons.Down);
|
||||
sharedButtons.DisableButtons(TBF.UiControls.SharedButtons.Buttons.Up);
|
||||
}
|
||||
else if (selectedItemPos == TBF.UiControls.SharedButtons.SelectedItemPos.Last)
|
||||
{
|
||||
sharedButtons.EnableButtons(TBF.UiControls.SharedButtons.Buttons.Up);
|
||||
sharedButtons.DisableButtons(TBF.UiControls.SharedButtons.Buttons.Down);
|
||||
}
|
||||
else if (selectedItemPos == TBF.UiControls.SharedButtons.SelectedItemPos.FirstAndLast)
|
||||
{
|
||||
sharedButtons.DisableButtons(TBF.UiControls.SharedButtons.Buttons.Up |
|
||||
TBF.UiControls.SharedButtons.Buttons.Down);
|
||||
}
|
||||
else
|
||||
{
|
||||
sharedButtons.EnableButtons(TBF.UiControls.SharedButtons.Buttons.Up |
|
||||
TBF.UiControls.SharedButtons.Buttons.Down);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Common part for three xxxListViewEx_SelectedIndexChanged event handlers
|
||||
/// </summary>
|
||||
/// <param name="listViewEx"></param>
|
||||
void SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
Results.Forms.ListViewEx listViewEx = sender as Results.Forms.ListViewEx;
|
||||
if (listViewEx.SelectedItems.Count != 1)
|
||||
{
|
||||
UpdateButtonStates(TBF.UiControls.SharedButtons.SelectedItemPos.None);
|
||||
}
|
||||
else if (listViewEx.Items.Count == 1)
|
||||
{
|
||||
UpdateButtonStates(TBF.UiControls.SharedButtons.SelectedItemPos.FirstAndLast);
|
||||
}
|
||||
else if (listViewEx.SelectedIndices[0] == 0)
|
||||
{
|
||||
UpdateButtonStates(TBF.UiControls.SharedButtons.SelectedItemPos.First);
|
||||
}
|
||||
else if (listViewEx.SelectedIndices[0] == (listViewEx.Items.Count - 1))
|
||||
{
|
||||
UpdateButtonStates(TBF.UiControls.SharedButtons.SelectedItemPos.Last);
|
||||
}
|
||||
else
|
||||
{
|
||||
UpdateButtonStates(TBF.UiControls.SharedButtons.SelectedItemPos.Middle);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user