Transition sequences can be renamed and deleted.

This commit is contained in:
Milan Hanajik
2016-10-13 18:06:13 +02:00
parent 0fb3a74879
commit 790364832d
5 changed files with 161 additions and 78 deletions
+16
View File
@@ -22,6 +22,22 @@ namespace TBF.Forms
IsVirtualBenchSeq = false; IsVirtualBenchSeq = false;
} }
public TabNameDlg(bool nameOnly)
{
InitializeComponent();
TabNameLabel = string.Empty;
TabName = string.Empty;
IsVirtualBenchSeq = false;
if (nameOnly == true)
{
radioButton1.Visible = false;
radioButton2.Visible = false;
Height -= 50;
}
}
private void TabNameDlg_Load(object sender, EventArgs e) private void TabNameDlg_Load(object sender, EventArgs e)
{ {
Text = TabNameLabel; Text = TabNameLabel;
+1 -1
View File
@@ -360,7 +360,7 @@ namespace TBF
private void benchComponentsTSMItem_Click(object s, EventArgs e) { new ComponentsManagerDlg().ShowDialog(); } private void benchComponentsTSMItem_Click(object s, EventArgs e) { new ComponentsManagerDlg().ShowDialog(); }
private void benchPathsTSMItem_Click(object s, EventArgs e) { new PathsDlg().ShowDialog(); } private void benchPathsTSMItem_Click(object s, EventArgs e) { new PathsDlg().ShowDialog(); }
private void benchTransitionsTSMItem_Click(object s, EventArgs e) { new TransitionsDlg().ShowDialog(); } private void benchTransitionsTSMItem_Click(object s, EventArgs e) { Cursor = Cursors.WaitCursor; new TransitionsDlg().ShowDialog(); Cursor = Cursors.Default; }
private void benchMetrologyTSMItem_Click(object s, EventArgs e) { new MetrologyDlg().ShowDialog(); } private void benchMetrologyTSMItem_Click(object s, EventArgs e) { new MetrologyDlg().ShowDialog(); }
private void proceduresTSMItem_Click(object s, EventArgs e) { new ProceduresDlg().ShowDialog(); } private void proceduresTSMItem_Click(object s, EventArgs e) { new ProceduresDlg().ShowDialog(); }
private void localSettingsTSMItem_Click(object s, EventArgs e) { new PreferencesDlg().ShowDialog(); } private void localSettingsTSMItem_Click(object s, EventArgs e) { new PreferencesDlg().ShowDialog(); }
+9
View File
@@ -987,6 +987,15 @@ namespace TBF.Resources {
} }
} }
/// <summary>
/// Looks up a localized string similar to Do you really want to delete sequence &apos;{0}&apos; ?.
/// </summary>
internal static string Do_you_really_want_to_delete_sequence_0 {
get {
return ResourceManager.GetString("Do_you_really_want_to_delete_sequence_0", resourceCulture);
}
}
/// <summary> /// <summary>
/// Looks up a localized string similar to Do you want to copy this value to all cells below this cell?. /// Looks up a localized string similar to Do you want to copy this value to all cells below this cell?.
/// </summary> /// </summary>
@@ -1591,4 +1591,7 @@
<data name="Evaluate_volume" xml:space="preserve"> <data name="Evaluate_volume" xml:space="preserve">
<value>Evaluate volume</value> <value>Evaluate volume</value>
</data> </data>
<data name="Do_you_really_want_to_delete_sequence_0" xml:space="preserve">
<value>Do you really want to delete sequence '{0}' ?</value>
</data>
</root> </root>
+132 -77
View File
@@ -33,12 +33,14 @@ namespace TBF
/// Set by the constructor or updated by the parent after creation and before loading. /// Set by the constructor or updated by the parent after creation and before loading.
/// </summary> /// </summary>
public IList<TransitionSequence> TransitionSequences; public IList<TransitionSequence> TransitionSequences;
public IList<TransitionSequence> RemovedTransitionSequences;
/// <summary> /// <summary>
/// Virtual bench sequences to be updated by this dialog. /// Virtual bench sequences to be updated by this dialog.
/// Set by the constructor or updated by the parent after creation and before loading. /// Set by the constructor or updated by the parent after creation and before loading.
/// </summary> /// </summary>
public IList<VirtualBenchSequence> VirtualBenchSequences; public IList<VirtualBenchSequence> VirtualBenchSequences;
public IList<VirtualBenchSequence> RemovedVirtualBenchSequences;
/// Auxiliary public lists used also by user controls in tab pages /// Auxiliary public lists used also by user controls in tab pages
@@ -75,27 +77,8 @@ namespace TBF
seqStepsCtrls = new List<ITabWithListViewEx>(); seqStepsCtrls = new List<ITabWithListViewEx>();
TransitionSequences = new List<TransitionSequence>();
VirtualBenchSequences = new List<VirtualBenchSequence>();
}
void Localize()
{
Text = Strings.Transitions;
}
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;
/// Open the database /// Open the database
Session = Config.FluentCommon.CreateSession(Config.Entities.DBKind.Config); Session = Config.FluentCommon.CreateSession(Config.Entities.DBKind.Config);
/// Prepare a list of components and a list of all valves in the test bench /// Prepare a list of components and a list of all valves in the test bench
TbfComponents = BenchControl.TbfComponents.LoadComponentsFromDB(Session); TbfComponents = BenchControl.TbfComponents.LoadComponentsFromDB(Session);
@@ -104,69 +87,66 @@ namespace TBF
foreach (var cmpnt in TbfComponents) foreach (var cmpnt in TbfComponents)
{ {
if ((cmpnt is IRegulValve) && !(cmpnt is BenchControl.Elde.RegulValveTandem.RegulValveTandem)) if ((cmpnt is IRegulValve) && !(cmpnt is BenchControl.Elde.RegulValveTandem.RegulValveTandem))
{ {
RegulValves.Add(cmpnt as IRegulValve); RegulValves.Add(cmpnt as IRegulValve);
} }
} }
/// Load the sequences /// Load the sequences
TransitionSequences = Session.CreateQuery("FROM TransitionSequence ORDER BY ItemNr")
.List<TransitionSequence>();
VirtualBenchSequences = Session.CreateQuery("FROM VirtualBenchSequence ORDER BY ItemNr")
.List<VirtualBenchSequence>();
/// Create a tab with sequence steps for each sequence ordered by ItemNr.
/// Note: Each sequence (in both sequences together) has a unique ItemNr (0 .. N-1) /// Note: Each sequence (in both sequences together) has a unique ItemNr (0 .. N-1)
for (int i = 0; i < TransitionSequences.Count + VirtualBenchSequences.Count; i++) TransitionSequences = Session.QueryOver<TransitionSequence>().OrderBy(x => x.ItemNr).Asc.List();
{ VirtualBenchSequences = Session.QueryOver<VirtualBenchSequence>().OrderBy(x => x.ItemNr).Asc.List();
bool skip = false;
foreach (var transSeq in TransitionSequences) RemovedTransitionSequences = new List<TransitionSequence>();
{ RemovedVirtualBenchSequences = new List<VirtualBenchSequence>();
if (transSeq.ItemNr == i)
{ /// Create a tab with sequence steps for each sequence ordered by ItemNr.
AddTransitionSeqTab(transSeq); foreach (var transSeq in TransitionSequences) AddTransitionSeqTab(transSeq);
skip = true; foreach (var vBenchSeq in VirtualBenchSequences) AddVirtualBenchSeqTab(vBenchSeq);
continue; }
}
} void AddTransitionSeqTab(TransitionSequence sequence)
if (skip) continue; {
foreach (var vBenchSeq in VirtualBenchSequences) TabPage nwTab = new TabPage(sequence.Name);
{ nwTab.Tag = sequence;
if (vBenchSeq.ItemNr == i) TransitionStepsCtrl newCtrl = new TransitionStepsCtrl();
{ seqStepsCtrls.Add(newCtrl);
AddVirtualBenchSeqTab(vBenchSeq); nwTab.Controls.Add(newCtrl);
continue; 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 /// Now refresh the content of the dialog
RefreshAllTabs(); RefreshAllTabs();
} }
void AddTransitionSeqTab(TransitionSequence sequence) void Localize()
{
TabPage nwTab = new TabPage(sequence.Name);
TransitionStepsCtrl newCtrl = new TransitionStepsCtrl();
seqStepsCtrls.Add(newCtrl);
nwTab.Controls.Add(newCtrl);
this.tabControl.TabPages.Add(nwTab);
newCtrl.Initialize(sequence, this, this.tabControl.TabPages[this.tabControl.TabPages.Count - 1]);
newCtrl.SelectedIndexChanged += new System.EventHandler(this.SelectedIndexChanged);
}
void AddVirtualBenchSeqTab(VirtualBenchSequence sequence)
{ {
TabPage nwTab = new TabPage(sequence.Name); Text = Strings.Transitions;
VirtualBenchStepsCtrl newCtrl = new VirtualBenchStepsCtrl(); }
seqStepsCtrls.Add(newCtrl);
nwTab.Controls.Add(newCtrl);
this.tabControl.TabPages.Add(nwTab);
newCtrl.Initialize(sequence, this, this.tabControl.TabPages[this.tabControl.TabPages.Count - 1]);
newCtrl.SelectedIndexChanged += new System.EventHandler(this.SelectedIndexChanged);
}
void RefreshAllTabs() void RefreshAllTabs()
{ {
@@ -229,10 +209,66 @@ namespace TBF
private void renameTabButton_Click(object sender, EventArgs e) 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) 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);
}
}
} }
private void okButton_Click(object sender, EventArgs e) private void okButton_Click(object sender, EventArgs e)
@@ -243,10 +279,29 @@ namespace TBF
{ {
try try
{ {
foreach (var transSeq in TransitionSequences) foreach (var transSeq in RemovedTransitionSequences)
Session.SaveOrUpdate(transSeq); {
foreach (var vBnchSeq in VirtualBenchSequences) foreach (var step in transSeq.TransitionSteps) Session.Delete(step);
Session.SaveOrUpdate(vBnchSeq); 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(); transaction.Commit();
} }