Refactoring : TestBenchFramework --> TBF ver. 2.18.789
This commit is contained in:
@@ -0,0 +1,629 @@
|
||||
///
|
||||
/// Copyright (c) 2013-2017 Sensus Metering Systems
|
||||
///
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Windows.Forms;
|
||||
using log4net;
|
||||
using NHibernate;
|
||||
using Config.Entities;
|
||||
using TBF.BenchControl.Generic;
|
||||
using TBF.BenchControl.GenericDevices;
|
||||
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;
|
||||
|
||||
IList<Procedure> procedures;
|
||||
IList<Test> tests;
|
||||
|
||||
Dictionary<string, string> renameInfo; /// Pairs original name / new name
|
||||
|
||||
|
||||
/// <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<TransitionSequence> TransitionSequences;
|
||||
public IList<TransitionSequence> RemovedTransitionSequences;
|
||||
|
||||
/// <summary>
|
||||
/// Virtual bench sequences to be updated by this dialog.
|
||||
/// Set by the constructor or updated by the parent after creation and before loading.
|
||||
/// </summary>
|
||||
public IList<VirtualBenchSequence> VirtualBenchSequences;
|
||||
public IList<VirtualBenchSequence> RemovedVirtualBenchSequences;
|
||||
|
||||
|
||||
/// 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<ITabWithListViewEx> seqStepsCtrls;
|
||||
|
||||
public TransitionsDlg()
|
||||
{
|
||||
/// 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 = 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;
|
||||
|
||||
seqStepsCtrls = new List<ITabWithListViewEx>();
|
||||
|
||||
/// Open the database
|
||||
Session = Config.FluentCommon.CreateSession(Users.Entities.DBKind.Config);
|
||||
|
||||
/// 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) && !(cmpnt is BenchControl.Elde.RegulValveTandem.RegulValveTandem))
|
||||
{
|
||||
RegulValves.Add(cmpnt as IRegulValve);
|
||||
}
|
||||
}
|
||||
|
||||
/// Load the sequences
|
||||
/// Note: Each sequence (in both sequences together) has a unique ItemNr (0 .. N-1)
|
||||
TransitionSequences = Session.QueryOver<TransitionSequence>().OrderBy(x => x.ItemNr).Asc.List();
|
||||
VirtualBenchSequences = Session.QueryOver<VirtualBenchSequence>().OrderBy(x => x.ItemNr).Asc.List();
|
||||
procedures = Session.QueryOver<Procedure>().List();
|
||||
tests = Session.QueryOver<Test>().List();
|
||||
|
||||
RemovedTransitionSequences = new List<TransitionSequence>();
|
||||
RemovedVirtualBenchSequences = new List<VirtualBenchSequence>();
|
||||
|
||||
/// Create a tab with sequence steps for each sequence ordered by ItemNr.
|
||||
foreach (var transSeq in TransitionSequences)
|
||||
{
|
||||
transSeq.OriName = transSeq.Name;
|
||||
AddTransitionSeqTab(transSeq);
|
||||
}
|
||||
|
||||
foreach (var vBenchSeq in VirtualBenchSequences)
|
||||
{
|
||||
vBenchSeq.OriName = vBenchSeq.Name;
|
||||
AddVirtualBenchSeqTab(vBenchSeq);
|
||||
}
|
||||
}
|
||||
|
||||
void AddTransitionSeqTab(TransitionSequence sequence)
|
||||
{
|
||||
TabPage nwTab = new TabPage(sequence.Name);
|
||||
nwTab.Tag = sequence;
|
||||
TransitionStepsCtrl newCtrl = new TransitionStepsCtrl();
|
||||
seqStepsCtrls.Add(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);
|
||||
}
|
||||
|
||||
void AddVirtualBenchSeqTab(VirtualBenchSequence sequence)
|
||||
{
|
||||
TabPage nwTab = new TabPage(sequence.Name);
|
||||
nwTab.Tag = sequence;
|
||||
VirtualBenchStepsCtrl newCtrl = new VirtualBenchStepsCtrl();
|
||||
seqStepsCtrls.Add(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 TransitionsDlg_Load(object sender, EventArgs e)
|
||||
{
|
||||
Localize();
|
||||
|
||||
TBF.LocalSettings ls = Program.LocalSettings;
|
||||
Width = (ls.TransitionsDlgWidth > 0) ? ls.TransitionsDlgWidth : 1050;
|
||||
Height = (ls.TransitionsDlgHeight > 0) ? ls.TransitionsDlgHeight : 360;
|
||||
Left = (ls.TransitionsDlgLeft != 0) ? ls.TransitionsDlgLeft : 150;
|
||||
Top = (ls.TransitionsDlgTop != 0) ? ls.TransitionsDlgTop : 150;
|
||||
|
||||
/// Now refresh the content of the dialog
|
||||
RefreshAllTabs();
|
||||
}
|
||||
|
||||
void Localize()
|
||||
{
|
||||
Text = Strings.Transitions;
|
||||
}
|
||||
|
||||
void RefreshAllTabs()
|
||||
{
|
||||
foreach (var ctrl in seqStepsCtrls) (ctrl as Results.Forms.ListViewEx).Refresh();
|
||||
}
|
||||
|
||||
private void Unlocked(object sender, EventArgs e)
|
||||
{
|
||||
foreach (var ctrl in seqStepsCtrls) ctrl.Unlock();
|
||||
}
|
||||
|
||||
private void newTabButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
Forms.TabNameDlg dlg;
|
||||
bool nameUsed;
|
||||
int tabId = TransitionSequences.Count + VirtualBenchSequences.Count;
|
||||
|
||||
do
|
||||
{
|
||||
/// Find an unused procedure name
|
||||
string newName;
|
||||
for (int nameId = 1; true; nameId++)
|
||||
{
|
||||
newName = "Tr" + nameId.ToString();
|
||||
nameUsed = false;
|
||||
foreach (var seq in TransitionSequences) if (seq.Name.Equals(newName)) nameUsed = true;
|
||||
if (!nameUsed) break;
|
||||
}
|
||||
|
||||
dlg = new Forms.TabNameDlg();
|
||||
dlg.TabNameLabel = Strings.New_transition_name;
|
||||
dlg.TabName = newName;
|
||||
|
||||
if (DialogResult.OK != dlg.ShowDialog()) return;
|
||||
|
||||
foreach (var seq in TransitionSequences) if (seq.Name.Equals(dlg.TabName)) nameUsed = true;
|
||||
if (nameUsed) MessageBox.Show(Strings.Please_choose_another_transition_sequence_name,
|
||||
Strings.Warning,
|
||||
MessageBoxButtons.OK,
|
||||
MessageBoxIcon.Information);
|
||||
}
|
||||
while (nameUsed);
|
||||
|
||||
if (dlg.IsVirtualBenchSeq)
|
||||
{
|
||||
VirtualBenchSequence sequence = new VirtualBenchSequence(dlg.TabName, tabId);
|
||||
VirtualBenchSequences.Add(sequence);
|
||||
AddVirtualBenchSeqTab(sequence);
|
||||
seqStepsCtrls[tabId].Unlock();
|
||||
}
|
||||
else
|
||||
{
|
||||
TransitionSequence sequence = new TransitionSequence(dlg.TabName, tabId);
|
||||
TransitionSequences.Add(sequence);
|
||||
AddTransitionSeqTab(sequence);
|
||||
seqStepsCtrls[tabId].Unlock();
|
||||
}
|
||||
tabControl.SelectTab(tabId);
|
||||
}
|
||||
|
||||
private void renameTabButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
TabPage tabPage = tabControl.SelectedTab;
|
||||
TransitionSequence transitionSeq = tabPage.Tag as TransitionSequence;
|
||||
VirtualBenchSequence virtualBenchSeq = tabPage.Tag as VirtualBenchSequence;
|
||||
|
||||
Forms.TabNameDlg dlg = new Forms.TabNameDlg(true);
|
||||
dlg.TabNameLabel = Strings.New_transition_name;
|
||||
|
||||
if (dlg.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
bool nameUsed = false;
|
||||
foreach (var seq in TransitionSequences) if (seq != transitionSeq && seq.Name == dlg.TabName) nameUsed = true;
|
||||
foreach (var seq in VirtualBenchSequences) if (seq != virtualBenchSeq && seq.Name == dlg.TabName) nameUsed = true;
|
||||
|
||||
if (nameUsed)
|
||||
{
|
||||
MessageBox.Show(Strings.Please_choose_another_transition_sequence_name,
|
||||
Strings.Warning,
|
||||
MessageBoxButtons.OK,
|
||||
MessageBoxIcon.Information);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (transitionSeq != null)
|
||||
{
|
||||
transitionSeq.Name = dlg.TabName;
|
||||
tabPage.Text = dlg.TabName;
|
||||
}
|
||||
else if (virtualBenchSeq != null)
|
||||
{
|
||||
virtualBenchSeq.Name = dlg.TabName;
|
||||
tabPage.Text = dlg.TabName;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void removeTabButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
TabPage tabPage = tabControl.SelectedTab;
|
||||
TransitionSequence transitionSeq = tabPage.Tag as TransitionSequence;
|
||||
VirtualBenchSequence virtualBenchSeq = tabPage.Tag as VirtualBenchSequence;
|
||||
|
||||
if (DialogResult.Yes == MessageBox.Show(string.Format(Strings.Do_you_really_want_to_delete_sequence_0, tabPage.Text),
|
||||
Strings.Warning,
|
||||
MessageBoxButtons.YesNo,
|
||||
MessageBoxIcon.Question))
|
||||
{
|
||||
if (transitionSeq != null)
|
||||
{
|
||||
RemovedTransitionSequences.Add(transitionSeq);
|
||||
TransitionSequences.Remove(transitionSeq);
|
||||
tabControl.TabPages.Remove(tabPage);
|
||||
}
|
||||
else if (virtualBenchSeq != null)
|
||||
{
|
||||
RemovedVirtualBenchSequences.Add(virtualBenchSeq);
|
||||
VirtualBenchSequences.Remove(virtualBenchSeq);
|
||||
tabControl.TabPages.Remove(tabPage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void RetrieveData()
|
||||
{
|
||||
if (seqStepsCtrls.Count > slctdTab) seqStepsCtrls[slctdTab].OkBtnClicked();
|
||||
}
|
||||
|
||||
string GetWarningsBeforeSaving(ref Dictionary<string, string> renmInfo)
|
||||
{
|
||||
string warnings = string.Empty;
|
||||
renmInfo = new Dictionary<string, string>();
|
||||
|
||||
foreach (var seq in RemovedTransitionSequences)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(seq.OriName))
|
||||
{
|
||||
int occurances = 0;
|
||||
foreach (var test in tests)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(test.RelTransBefore) && test.RelTransBefore == seq.OriName) occurances++;
|
||||
if (!string.IsNullOrEmpty(test.TransitionAfter) && test.TransitionAfter == seq.OriName) occurances++;
|
||||
}
|
||||
foreach (var proc in procedures)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(proc.TransitionStart) && proc.TransitionStart == seq.OriName) occurances++;
|
||||
if (!string.IsNullOrEmpty(proc.TransitionEnd) && proc.TransitionEnd == seq.OriName) occurances++;
|
||||
}
|
||||
if (occurances > 0)
|
||||
{
|
||||
warnings += string.Format("Deleting transition sequence {0} used in {1} tests and procedures{2}", seq.OriName, occurances, Environment.NewLine);
|
||||
renmInfo.Add(seq.OriName, string.Empty);
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach (var seq in RemovedVirtualBenchSequences)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(seq.OriName))
|
||||
{
|
||||
int occurances = 0;
|
||||
foreach (var test in tests)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(test.RelTransBefore) && test.RelTransBefore == seq.OriName) occurances++;
|
||||
if (!string.IsNullOrEmpty(test.TransitionAfter) && test.TransitionAfter == seq.OriName) occurances++;
|
||||
}
|
||||
foreach (var proc in procedures)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(proc.TransitionStart) && proc.TransitionStart == seq.OriName) occurances++;
|
||||
if (!string.IsNullOrEmpty(proc.TransitionEnd) && proc.TransitionEnd == seq.OriName) occurances++;
|
||||
}
|
||||
if (occurances > 0)
|
||||
{
|
||||
warnings += string.Format("Deleting virtual bench sequence {0} used in {1} tests and procedures{2}", seq.OriName, occurances, Environment.NewLine);
|
||||
renmInfo.Add(seq.OriName, string.Empty);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var seq in TransitionSequences)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(seq.OriName) && seq.OriName != seq.Name)
|
||||
{
|
||||
int occurances = 0;
|
||||
foreach (var test in tests)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(test.RelTransBefore) && test.RelTransBefore == seq.OriName) occurances++;
|
||||
if (!string.IsNullOrEmpty(test.TransitionAfter) && test.TransitionAfter == seq.OriName) occurances++;
|
||||
}
|
||||
foreach (var proc in procedures)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(proc.TransitionStart) && proc.TransitionStart == seq.OriName) occurances++;
|
||||
if (!string.IsNullOrEmpty(proc.TransitionEnd) && proc.TransitionEnd == seq.OriName) occurances++;
|
||||
}
|
||||
if (occurances > 0)
|
||||
{
|
||||
warnings += string.Format("Renaming transition sequence {0} used in {1} tests and procedures{2}", seq.OriName, occurances, Environment.NewLine);
|
||||
renmInfo.Add(seq.OriName, seq.Name);
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach (var seq in VirtualBenchSequences)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(seq.OriName) && seq.OriName != seq.Name)
|
||||
{
|
||||
int occurances = 0;
|
||||
foreach (var test in tests)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(test.RelTransBefore) && test.RelTransBefore == seq.OriName) occurances++;
|
||||
if (!string.IsNullOrEmpty(test.TransitionAfter) && test.TransitionAfter == seq.OriName) occurances++;
|
||||
}
|
||||
foreach (var proc in procedures)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(proc.TransitionStart) && proc.TransitionStart == seq.OriName) occurances++;
|
||||
if (!string.IsNullOrEmpty(proc.TransitionEnd) && proc.TransitionEnd == seq.OriName) occurances++;
|
||||
}
|
||||
if (occurances > 0)
|
||||
{
|
||||
warnings += string.Format("Renaming virtual bench sequence {0} used in {1} tests and procedures{2}", seq.OriName, occurances, Environment.NewLine);
|
||||
renmInfo.Add(seq.OriName, seq.Name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return warnings;
|
||||
}
|
||||
|
||||
private void okButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
RetrieveData();
|
||||
|
||||
string warnings = GetWarningsBeforeSaving(ref renameInfo);
|
||||
|
||||
bool updateRelatedItems = false;
|
||||
if (!string.IsNullOrEmpty(warnings))
|
||||
{
|
||||
string message = string.Format("{0}{1}{2}", warnings, Environment.NewLine,
|
||||
Strings.Do_you_want_to_update_related_tests_and_procedures);
|
||||
DialogResult dr = MessageBox.Show(message, Strings.Warning, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Exclamation);
|
||||
if (dr == DialogResult.Cancel)
|
||||
{
|
||||
DialogResult = DialogResult.Cancel;
|
||||
return;
|
||||
}
|
||||
else if (dr == DialogResult.Yes)
|
||||
{
|
||||
updateRelatedItems = true;
|
||||
}
|
||||
}
|
||||
|
||||
Cursor.Current = Cursors.WaitCursor;
|
||||
|
||||
using (var transaction = Session.BeginTransaction())
|
||||
{
|
||||
try
|
||||
{
|
||||
if (updateRelatedItems)
|
||||
{
|
||||
foreach (var ri in renameInfo)
|
||||
{
|
||||
var tests = Session.QueryOver<Config.Entities.Test>()
|
||||
.Where(x => (x.RelTransBefore == ri.Key))
|
||||
.List();
|
||||
foreach (var t in tests)
|
||||
{
|
||||
t.RelTransBefore = ri.Value;
|
||||
Session.Update(t);
|
||||
}
|
||||
|
||||
tests = Session.QueryOver<Config.Entities.Test>()
|
||||
.Where(x => (x.TransitionAfter == ri.Key))
|
||||
.List();
|
||||
foreach (var t in tests)
|
||||
{
|
||||
t.TransitionAfter = ri.Value;
|
||||
Session.Update(t);
|
||||
}
|
||||
|
||||
var procedures = Session.QueryOver<Config.Entities.Procedure>()
|
||||
.Where(x => (x.TransitionStart == ri.Key))
|
||||
.List();
|
||||
foreach (var p in procedures)
|
||||
{
|
||||
p.TransitionStart = ri.Value;
|
||||
Session.Update(p);
|
||||
}
|
||||
|
||||
procedures = Session.QueryOver<Config.Entities.Procedure>()
|
||||
.Where(x => (x.TransitionEnd == ri.Key))
|
||||
.List();
|
||||
foreach (var p in procedures)
|
||||
{
|
||||
p.TransitionEnd = ri.Value;
|
||||
Session.Update(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var transSeq in RemovedTransitionSequences)
|
||||
{
|
||||
foreach (var step in transSeq.TransitionSteps) Session.Delete(step);
|
||||
Session.Delete(transSeq);
|
||||
}
|
||||
foreach (var vBnchSeq in RemovedVirtualBenchSequences)
|
||||
{
|
||||
foreach (var step in vBnchSeq.VirtualBenchSteps) Session.Delete(step);
|
||||
Session.Delete(vBnchSeq);
|
||||
}
|
||||
|
||||
int itemNr = 0;
|
||||
foreach (var transSeq in TransitionSequences)
|
||||
{
|
||||
transSeq.ItemNr = itemNr++;
|
||||
Session.SaveOrUpdate(transSeq);
|
||||
}
|
||||
itemNr = 0;
|
||||
foreach (var vBnchSeq in VirtualBenchSequences)
|
||||
{
|
||||
vBnchSeq.ItemNr = itemNr++;
|
||||
Session.SaveOrUpdate(vBnchSeq);
|
||||
}
|
||||
|
||||
transaction.Commit();
|
||||
}
|
||||
catch (Exception e2)
|
||||
{
|
||||
transaction.Rollback();
|
||||
Cursor.Current = Cursors.Default;
|
||||
|
||||
MessageBox.Show(Strings.Cannot_save_changes, Strings.Error, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
|
||||
log.ErrorFormat("Update of sequences in the database failed: {0}", e2.Message);
|
||||
}
|
||||
}
|
||||
|
||||
Cursor.Current = Cursors.Default;
|
||||
|
||||
Program.LocalSettings.TransitionsDlgLeft = Location.X;
|
||||
Program.LocalSettings.TransitionsDlgTop = Location.Y;
|
||||
Program.LocalSettings.TransitionsDlgWidth = Size.Width;
|
||||
Program.LocalSettings.TransitionsDlgHeight = Size.Height;
|
||||
Program.LocalSettings.Save();
|
||||
|
||||
DialogResult = DialogResult.OK;
|
||||
Close();
|
||||
return;
|
||||
}
|
||||
|
||||
private void cancelButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
Program.LocalSettings.TransitionsDlgLeft = Location.X;
|
||||
Program.LocalSettings.TransitionsDlgTop = Location.Y;
|
||||
Program.LocalSettings.TransitionsDlgWidth = Size.Width;
|
||||
Program.LocalSettings.TransitionsDlgHeight = Size.Height;
|
||||
Program.LocalSettings.Save();
|
||||
|
||||
DialogResult = DialogResult.Cancel;
|
||||
Close();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int slctdTab;
|
||||
|
||||
private void tabControl_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
if (seqStepsCtrls.Count > slctdTab)
|
||||
{
|
||||
seqStepsCtrls[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 (seqStepsCtrls.Count > slctdTab) seqStepsCtrls[slctdTab].AddOne();
|
||||
}
|
||||
|
||||
private void removeButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (seqStepsCtrls.Count > slctdTab) seqStepsCtrls[slctdTab].RemoveSelected();
|
||||
}
|
||||
|
||||
private void upButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (seqStepsCtrls.Count > slctdTab) seqStepsCtrls[slctdTab].MoveUpSelected();
|
||||
}
|
||||
|
||||
private void downButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (seqStepsCtrls.Count > slctdTab) seqStepsCtrls[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)
|
||||
{
|
||||
Results.Forms.ListViewEx listViewEx = sender as Results.Forms.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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user