277 lines
8.3 KiB
C#
277 lines
8.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Windows.Forms;
|
|
using log4net;
|
|
using NHibernate;
|
|
|
|
using TBF.BenchControl.Generic;
|
|
using TBF.BenchControl.GenericDevices;
|
|
using TBF.Entities;
|
|
using TBF.Resources;
|
|
using TBF.UiControls;
|
|
|
|
namespace TBF
|
|
{
|
|
public partial class TransitionsDlg : Form, IParentOfListViewEx
|
|
{
|
|
static readonly ILog log = LogManager.GetLogger(typeof(TransitionsDlg));
|
|
|
|
/// Used when re-scaling the dialog: 100% = 96dpi, 125% = 120dpi, 150% = 144dpi
|
|
public readonly int Dpi;
|
|
public const int Dpi100pct = 96;
|
|
|
|
/// <summary>
|
|
/// Fluent-NHibernate database session
|
|
/// </summary>
|
|
public ISession Session;
|
|
|
|
/// <summary>
|
|
/// Procedure to be updated by this dialog.
|
|
/// Set by the constructor or updated by the parent after creation and before loading.
|
|
/// </summary>
|
|
public IList<Entities.TransitionSequence> LoadedSequences;
|
|
|
|
/// <summary>
|
|
/// A list of tests to be deleted after closing this dialog
|
|
/// </summary>
|
|
public IList<Entities.TransitionStep> ToBeDeletedSteps;
|
|
|
|
|
|
/// Auxiliary public lists used also by user controls in tab pages
|
|
public IList<BenchControl.Generic.IComponent> TbfComponents;
|
|
public IList<IValve> Valves;
|
|
public IList<IRegulValve> RegulValves;
|
|
|
|
|
|
IList<TransitionStepsCtrl> transStepsCtrls;
|
|
|
|
bool unlocked;
|
|
|
|
public TransitionsDlg()
|
|
{
|
|
/// Detect display setting: 100% = 96dpi, 125% = 120dpi, 150% = 144dpi.
|
|
Dpi = (int)this.CreateGraphics().DpiX;
|
|
|
|
InitializeComponent();
|
|
|
|
/// SharedDlgButtons configuration
|
|
sharedButtons.RequiredGroupMembership = Grp.GID.Metrologists;
|
|
sharedButtons.OptionalButtons = SharedButtons.Buttons.Add | SharedButtons.Buttons.Remove |
|
|
SharedButtons.Buttons.Up | SharedButtons.Buttons.Down |
|
|
SharedButtons.Buttons.NewTab | SharedButtons.Buttons.RenameTab |
|
|
SharedButtons.Buttons.RemoveTab;
|
|
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;
|
|
sharedButtons.NewTabClicked += newTabButton_Click;
|
|
sharedButtons.RenameTabClicked += renameTabButton_Click;
|
|
sharedButtons.RemoveTabClicked += removeTabButton_Click;
|
|
|
|
transStepsCtrls = new List<TransitionStepsCtrl>();
|
|
ToBeDeletedSteps = new List<Entities.TransitionStep>();
|
|
}
|
|
|
|
void Localize()
|
|
{
|
|
Text = Strings.Transitions;
|
|
}
|
|
|
|
private void ProcedureDlg_Load(object sender, EventArgs e)
|
|
{
|
|
/// Load the procedures
|
|
Session = FluentCommon.CreateSession(Database.Procedures);
|
|
LoadedSequences = Session.CreateQuery("FROM TransitionSequence ORDER BY ItemNr")
|
|
.List<Entities.TransitionSequence>();
|
|
|
|
/// Prepare a list of components and a list of all valves in the test bench
|
|
TbfComponents = BenchControl.TbfComponents.LoadComponentsFromDB(Session);
|
|
Valves = BenchControl.GenericDevices.ValveBase.MasterValves(TbfComponents);
|
|
RegulValves = new List<IRegulValve>();
|
|
foreach (var cmpnt in TbfComponents)
|
|
{
|
|
if (cmpnt is IRegulValve) RegulValves.Add(cmpnt as IRegulValve);
|
|
}
|
|
|
|
/// Create a tab with a TestParamsCtrl control for each used test method
|
|
foreach (var sequence in LoadedSequences) AddTab(sequence);
|
|
|
|
/// Now refresh the content of the dialog
|
|
RefreshAllTabs();
|
|
}
|
|
|
|
void AddTab(TransitionSequence sequence)
|
|
{
|
|
TabPage nwTab = new TabPage(sequence.Name);
|
|
TransitionStepsCtrl newCtrl = new TransitionStepsCtrl();
|
|
transStepsCtrls.Add(newCtrl);
|
|
nwTab.Controls.Add(newCtrl);
|
|
this.tabControl.TabPages.Add(nwTab);
|
|
newCtrl.Initialize(sequence, this, this.tabControl.TabPages[this.tabControl.TabPages.Count - 1]);
|
|
}
|
|
|
|
void RefreshAllTabs()
|
|
{
|
|
foreach (var ctrl in transStepsCtrls) ctrl.Refresh();
|
|
}
|
|
|
|
private void Unlocked(object sender, EventArgs e)
|
|
{
|
|
unlocked = true;
|
|
foreach (var ctrl in transStepsCtrls) ctrl.Unlock();
|
|
}
|
|
|
|
private void newTabButton_Click(object sender, EventArgs e)
|
|
{
|
|
int tabId = LoadedSequences.Count;
|
|
Forms.TabNameDlg dlg = new Forms.TabNameDlg();
|
|
dlg.TabNameLabel = Strings.New_transition_name;
|
|
dlg.TabName = "Tr1";
|
|
dlg.ShowDialog();
|
|
TransitionSequence sequence = new TransitionSequence(dlg.TabName, tabId);
|
|
LoadedSequences.Add(sequence);
|
|
AddTab(sequence);
|
|
transStepsCtrls[tabId].Unlock();
|
|
tabControl.SelectTab(tabId);
|
|
}
|
|
|
|
private void renameTabButton_Click(object sender, EventArgs e)
|
|
{
|
|
}
|
|
|
|
private void removeTabButton_Click(object sender, EventArgs e)
|
|
{
|
|
}
|
|
|
|
private void okButton_Click(object sender, EventArgs e)
|
|
{
|
|
if (transStepsCtrls.Count > slctdTab) transStepsCtrls[slctdTab].OkBtnClicked();
|
|
|
|
using (var transaction = Session.BeginTransaction())
|
|
{
|
|
foreach (var sequence in LoadedSequences)
|
|
{
|
|
Session.SaveOrUpdate(sequence);
|
|
}
|
|
try { transaction.Commit(); }
|
|
catch { }
|
|
}
|
|
|
|
DialogResult = DialogResult.OK;
|
|
Close();
|
|
return;
|
|
}
|
|
|
|
private void cancelButton_Click(object sender, EventArgs e)
|
|
{
|
|
DialogResult = DialogResult.Cancel;
|
|
Close();
|
|
return;
|
|
}
|
|
|
|
int slctdTab;
|
|
|
|
private void tabControl_SelectedIndexChanged(object sender, EventArgs e)
|
|
{
|
|
if (transStepsCtrls.Count > slctdTab)
|
|
{
|
|
transStepsCtrls[slctdTab].OkBtnClicked();
|
|
}
|
|
slctdTab = tabControl.SelectedIndex;
|
|
sharedButtons.SetEnabled(SharedButtons.Buttons.Add, true);
|
|
sharedButtons.DisableButtons(SharedButtons.Buttons.Remove);
|
|
RefreshAllTabs();
|
|
}
|
|
|
|
private void addButton_Click(object sender, EventArgs e)
|
|
{
|
|
if (transStepsCtrls.Count > slctdTab) transStepsCtrls[slctdTab].AddOne();
|
|
}
|
|
|
|
private void removeButton_Click(object sender, EventArgs e)
|
|
{
|
|
if (transStepsCtrls.Count > slctdTab) transStepsCtrls[slctdTab].RemoveSelected();
|
|
}
|
|
|
|
private void upButton_Click(object sender, EventArgs e)
|
|
{
|
|
if (transStepsCtrls.Count > slctdTab) transStepsCtrls[slctdTab].MoveUpSelected();
|
|
}
|
|
|
|
private void downButton_Click(object sender, EventArgs e)
|
|
{
|
|
if (transStepsCtrls.Count > slctdTab) transStepsCtrls[slctdTab].MoveDownSelected();
|
|
}
|
|
|
|
public void UpdateButtonStates(SharedButtons.SelectedItemPos selectedItemPos)
|
|
{
|
|
if (selectedItemPos == SharedButtons.SelectedItemPos.None)
|
|
{
|
|
sharedButtons.DisableButtons(SharedButtons.Buttons.Remove | SharedButtons.Buttons.Up | SharedButtons.Buttons.Down);
|
|
}
|
|
else if (selectedItemPos == SharedButtons.SelectedItemPos.First)
|
|
{
|
|
sharedButtons.EnableButtons(SharedButtons.Buttons.Remove | SharedButtons.Buttons.Down);
|
|
sharedButtons.DisableButtons(SharedButtons.Buttons.Up);
|
|
}
|
|
else if (selectedItemPos == SharedButtons.SelectedItemPos.Last)
|
|
{
|
|
sharedButtons.EnableButtons(SharedButtons.Buttons.Remove | SharedButtons.Buttons.Up);
|
|
sharedButtons.DisableButtons(SharedButtons.Buttons.Down);
|
|
}
|
|
else if (selectedItemPos == SharedButtons.SelectedItemPos.FirstAndLast)
|
|
{
|
|
sharedButtons.EnableButtons(SharedButtons.Buttons.Remove);
|
|
sharedButtons.DisableButtons(SharedButtons.Buttons.Up | SharedButtons.Buttons.Down);
|
|
}
|
|
else
|
|
{
|
|
sharedButtons.EnableButtons(SharedButtons.Buttons.Remove | SharedButtons.Buttons.Up | SharedButtons.Buttons.Down);
|
|
}
|
|
}
|
|
|
|
private void purgeStartCtrl_SelectedIndexChanged(object sender, EventArgs e)
|
|
{
|
|
SelectedIndexChanged(sender, e);
|
|
}
|
|
|
|
private void purgeEndCtrl_SelectedIndexChanged(object sender, EventArgs e)
|
|
{
|
|
SelectedIndexChanged(sender, e);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Common part for three xxxListViewEx_SelectedIndexChanged event handlers
|
|
/// </summary>
|
|
/// <param name="listViewEx"></param>
|
|
void SelectedIndexChanged(object sender, EventArgs e)
|
|
{
|
|
ListViewEx listViewEx = sender as ListViewEx;
|
|
if (listViewEx.SelectedItems.Count != 1)
|
|
{
|
|
UpdateButtonStates(SharedButtons.SelectedItemPos.None);
|
|
}
|
|
else if (listViewEx.Items.Count == 1)
|
|
{
|
|
UpdateButtonStates(SharedButtons.SelectedItemPos.FirstAndLast);
|
|
}
|
|
else if (listViewEx.SelectedIndices[0] == 0)
|
|
{
|
|
UpdateButtonStates(SharedButtons.SelectedItemPos.First);
|
|
}
|
|
else if (listViewEx.SelectedIndices[0] == (listViewEx.Items.Count - 1))
|
|
{
|
|
UpdateButtonStates(SharedButtons.SelectedItemPos.Last);
|
|
}
|
|
else
|
|
{
|
|
UpdateButtonStates(SharedButtons.SelectedItemPos.Middle);
|
|
}
|
|
}
|
|
}
|
|
}
|