From be6240bf2815936beeca755d73baf734c81738b3 Mon Sep 17 00:00:00 2001 From: Milan Hanajik Date: Thu, 25 May 2017 16:33:44 +0200 Subject: [PATCH] Automated renaming of paths and transitions, parts 2,3,4. --- Config/Entities/TransitionSequence.cs | 3 +- Config/Entities/VirtualBenchSequence.cs | 3 +- .../TestMethods/Endurance/CycleStepsCtrl.cs | 4 +- TestBenchFramework/PathsDlg.cs | 9 +- .../Resources/Strings.Designer.cs | 18 +- TestBenchFramework/Resources/Strings.resx | 4 +- TestBenchFramework/TransitionsDlg.cs | 191 +++++++++++++++++- .../UiControls/ITabWithListViewEx.cs | 6 +- .../UiControls/MetrologyDlgBalanceTab.cs | 4 +- .../UiControls/MetrologyDlgDensityTab.cs | 4 +- .../UiControls/MetrologyDlgFlowMeterTab.cs | 4 +- ...MetrologyDlgPlatinumResistanceTMeterTab.cs | 4 +- .../UiControls/MetrologyDlgPressMeterTab.cs | 4 +- .../UiControls/PathsBenchCtrl.cs | 19 +- .../UiControls/PathsFeedingCtrl.cs | 35 ++-- .../UiControls/PathsHeatMetersCtrl.cs | 21 +- .../UiControls/PathsMetersCtrl.cs | 29 ++- .../UiControls/PathsOutputCtrl.cs | 30 ++- .../UiControls/ProceduresCtrl.cs | 4 +- .../UiControls/TransitionStepsCtrl.cs | 4 +- .../UiControls/VirtualBenchStepsCtrl.cs | 4 +- 21 files changed, 285 insertions(+), 119 deletions(-) diff --git a/Config/Entities/TransitionSequence.cs b/Config/Entities/TransitionSequence.cs index 8bb47d18d..b71f3da8f 100644 --- a/Config/Entities/TransitionSequence.cs +++ b/Config/Entities/TransitionSequence.cs @@ -13,7 +13,8 @@ namespace Config.Entities public virtual int Id { get; protected set; } public virtual int ItemNr { get; set; } public virtual string Name { get; set; } - public virtual string Description { get; set; } /// Short description + public virtual string OriName { get; set; } /// Not mapped to database + public virtual string Description { get; set; } /// Short description public virtual IList TransitionSteps { get; set; } public TransitionSequence() diff --git a/Config/Entities/VirtualBenchSequence.cs b/Config/Entities/VirtualBenchSequence.cs index ef8278555..857dc8fbd 100644 --- a/Config/Entities/VirtualBenchSequence.cs +++ b/Config/Entities/VirtualBenchSequence.cs @@ -11,7 +11,8 @@ namespace Config.Entities public virtual int Id { get; protected set; } public virtual int ItemNr { get; set; } public virtual string Name { get; set; } - public virtual string Description { get; set; } /// Short description + public virtual string OriName { get; set; } /// Not mapped to database + public virtual string Description { get; set; } /// Short description public virtual IList VirtualBenchSteps { get; set; } public VirtualBenchSequence() diff --git a/TestBenchFramework/BenchControl/TestMethods/Endurance/CycleStepsCtrl.cs b/TestBenchFramework/BenchControl/TestMethods/Endurance/CycleStepsCtrl.cs index 32bb704e9..68f5bfc19 100644 --- a/TestBenchFramework/BenchControl/TestMethods/Endurance/CycleStepsCtrl.cs +++ b/TestBenchFramework/BenchControl/TestMethods/Endurance/CycleStepsCtrl.cs @@ -260,12 +260,12 @@ namespace TBF.BenchControl.TestMethods.Endurance } } - public string GetWarningsBeforeSaving() + public string GetWarningsBeforeSaving(ref Dictionary renmInfo) { return string.Empty; } - public void UpdateRelatedItems() + public void UpdateRelatedItems(Dictionary renameInfo) { } } diff --git a/TestBenchFramework/PathsDlg.cs b/TestBenchFramework/PathsDlg.cs index c170e98f4..789a49062 100644 --- a/TestBenchFramework/PathsDlg.cs +++ b/TestBenchFramework/PathsDlg.cs @@ -164,17 +164,20 @@ namespace TBF private void okButton_Click(object sender, EventArgs e) { string warnings = string.Empty; + Dictionary renameInfo = new Dictionary(); + foreach (TabPage tab in pathsTabControl.TabPages) { if (tab.Tag is ITabWithListViewEx) { - warnings += (tab.Tag as ITabWithListViewEx).GetWarningsBeforeSaving(); + warnings += (tab.Tag as ITabWithListViewEx).GetWarningsBeforeSaving(ref renameInfo); } } if (!string.IsNullOrEmpty(warnings)) { - string message = string.Format("{0}{1}{2}", warnings, Environment.NewLine, Strings.Do_you_want_to_rename_related_tests); + 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) { @@ -186,7 +189,7 @@ namespace TBF Cursor.Current = Cursors.WaitCursor; foreach (TabPage tab in pathsTabControl.TabPages) { - if (tab.Tag is ITabWithListViewEx) (tab.Tag as ITabWithListViewEx).UpdateRelatedItems(); + if (tab.Tag is ITabWithListViewEx) (tab.Tag as ITabWithListViewEx).UpdateRelatedItems(renameInfo); } } } diff --git a/TestBenchFramework/Resources/Strings.Designer.cs b/TestBenchFramework/Resources/Strings.Designer.cs index d8c5aafe9..be83f13da 100644 --- a/TestBenchFramework/Resources/Strings.Designer.cs +++ b/TestBenchFramework/Resources/Strings.Designer.cs @@ -1176,15 +1176,6 @@ namespace TBF.Resources { } } - /// - /// Looks up a localized string similar to Do you want to rename related tests?. - /// - internal static string Do_you_want_to_rename_related_tests { - get { - return ResourceManager.GetString("Do_you_want_to_rename_related_tests", resourceCulture); - } - } - /// /// Looks up a localized string similar to Do you want to save changes?. /// @@ -1203,6 +1194,15 @@ namespace TBF.Resources { } } + /// + /// Looks up a localized string similar to Do you want to update related tests and procedures?. + /// + internal static string Do_you_want_to_update_related_tests_and_procedures { + get { + return ResourceManager.GetString("Do_you_want_to_update_related_tests_and_procedures", resourceCulture); + } + } + /// /// Looks up a localized string similar to Down. /// diff --git a/TestBenchFramework/Resources/Strings.resx b/TestBenchFramework/Resources/Strings.resx index cdc6e8bbc..15b3273fb 100644 --- a/TestBenchFramework/Resources/Strings.resx +++ b/TestBenchFramework/Resources/Strings.resx @@ -1774,7 +1774,7 @@ {0} path '{1}' used by {2} tests will be renamed.{3} - - Do you want to rename related tests? + + Do you want to update related tests and procedures? \ No newline at end of file diff --git a/TestBenchFramework/TransitionsDlg.cs b/TestBenchFramework/TransitionsDlg.cs index 22c37931c..abf62acd8 100644 --- a/TestBenchFramework/TransitionsDlg.cs +++ b/TestBenchFramework/TransitionsDlg.cs @@ -1,5 +1,5 @@ /// -/// Copyright (c) 2013-2015 Sensus Metering Systems +/// Copyright (c) 2013-2017 Sensus Metering Systems /// using System; using System.Collections.Generic; @@ -28,6 +28,12 @@ namespace TBF /// public ISession Session; + IList procedures; + IList tests; + + Dictionary renameInfo; /// Pairs original name / new name + + /// /// Transition sequences to be updated by this dialog. /// Set by the constructor or updated by the parent after creation and before loading. @@ -96,13 +102,24 @@ namespace TBF /// Note: Each sequence (in both sequences together) has a unique ItemNr (0 .. N-1) TransitionSequences = Session.QueryOver().OrderBy(x => x.ItemNr).Asc.List(); VirtualBenchSequences = Session.QueryOver().OrderBy(x => x.ItemNr).Asc.List(); + procedures = Session.QueryOver().List(); + tests = Session.QueryOver().List(); RemovedTransitionSequences = new List(); RemovedVirtualBenchSequences = new List(); /// Create a tab with sequence steps for each sequence ordered by ItemNr. - foreach (var transSeq in TransitionSequences) AddTransitionSeqTab(transSeq); - foreach (var vBenchSeq in VirtualBenchSequences) AddVirtualBenchSeqTab(vBenchSeq); + 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) @@ -271,14 +288,175 @@ namespace TBF } } + void RetrieveData() + { + if (seqStepsCtrls.Count > slctdTab) seqStepsCtrls[slctdTab].OkBtnClicked(); + } + + string GetWarningsBeforeSaving(ref Dictionary renmInfo) + { + string warnings = string.Empty; + renmInfo = new Dictionary(); + + 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) { - if (seqStepsCtrls.Count > slctdTab) seqStepsCtrls[slctdTab].OkBtnClicked(); + 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 item in tests) + { + bool updated = false; + string newSeqName; + if (!string.IsNullOrEmpty(item.RelTransBefore) && renameInfo.TryGetValue(item.RelTransBefore, out newSeqName)) + { + item.RelTransBefore = newSeqName; + updated = true; + } + if (!string.IsNullOrEmpty(item.TransitionAfter) && renameInfo.TryGetValue(item.TransitionAfter, out newSeqName)) + { + item.TransitionAfter = newSeqName; + updated = true; + } + if (updated) Session.SaveOrUpdate(item); + } + + foreach (var item in procedures) + { + bool updated = false; + string newSeqName; + if (!string.IsNullOrEmpty(item.TransitionStart) && renameInfo.TryGetValue(item.TransitionStart, out newSeqName)) + { + item.TransitionStart = newSeqName; + updated = true; + } + if (!string.IsNullOrEmpty(item.TransitionEnd) && renameInfo.TryGetValue(item.TransitionEnd, out newSeqName)) + { + item.TransitionEnd = newSeqName; + updated = true; + } + if (updated) Session.SaveOrUpdate(item); + } + } + foreach (var transSeq in RemovedTransitionSequences) { foreach (var step in transSeq.TransitionSteps) Session.Delete(step); @@ -307,11 +485,14 @@ namespace TBF } catch (Exception e2) { + 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; @@ -336,6 +517,8 @@ namespace TBF return; } + + int slctdTab; private void tabControl_SelectedIndexChanged(object sender, EventArgs e) diff --git a/TestBenchFramework/UiControls/ITabWithListViewEx.cs b/TestBenchFramework/UiControls/ITabWithListViewEx.cs index 179a2b914..500e97949 100644 --- a/TestBenchFramework/UiControls/ITabWithListViewEx.cs +++ b/TestBenchFramework/UiControls/ITabWithListViewEx.cs @@ -1,5 +1,5 @@ /// -/// Copyright (c) 2013-2015 Sensus Metering Systems +/// Copyright (c) 2013-2017 Sensus Metering Systems /// using System; using System.Collections.Generic; @@ -17,7 +17,7 @@ namespace TBF.UiControls void RemoveSelected(); void MoveUpSelected(); void MoveDownSelected(); - string GetWarningsBeforeSaving(); - void UpdateRelatedItems(); + string GetWarningsBeforeSaving(ref Dictionary renameInfo); + void UpdateRelatedItems(Dictionary renameInfo); } } diff --git a/TestBenchFramework/UiControls/MetrologyDlgBalanceTab.cs b/TestBenchFramework/UiControls/MetrologyDlgBalanceTab.cs index 9b16e25f7..a870c9b12 100644 --- a/TestBenchFramework/UiControls/MetrologyDlgBalanceTab.cs +++ b/TestBenchFramework/UiControls/MetrologyDlgBalanceTab.cs @@ -347,12 +347,12 @@ namespace TBF.UiControls } } - public string GetWarningsBeforeSaving() + public string GetWarningsBeforeSaving(ref Dictionary renmInfo) { return string.Empty; } - public void UpdateRelatedItems() + public void UpdateRelatedItems(Dictionary renameInfo) { } } diff --git a/TestBenchFramework/UiControls/MetrologyDlgDensityTab.cs b/TestBenchFramework/UiControls/MetrologyDlgDensityTab.cs index 36c706ca1..8f2d0eed2 100644 --- a/TestBenchFramework/UiControls/MetrologyDlgDensityTab.cs +++ b/TestBenchFramework/UiControls/MetrologyDlgDensityTab.cs @@ -106,12 +106,12 @@ namespace TBF.UiControls { } - public string GetWarningsBeforeSaving() + public string GetWarningsBeforeSaving(ref Dictionary renmInfo) { return string.Empty; } - public void UpdateRelatedItems() + public void UpdateRelatedItems(Dictionary renameInfo) { } } diff --git a/TestBenchFramework/UiControls/MetrologyDlgFlowMeterTab.cs b/TestBenchFramework/UiControls/MetrologyDlgFlowMeterTab.cs index abe65a32a..0ca0443e4 100644 --- a/TestBenchFramework/UiControls/MetrologyDlgFlowMeterTab.cs +++ b/TestBenchFramework/UiControls/MetrologyDlgFlowMeterTab.cs @@ -328,12 +328,12 @@ namespace TBF.UiControls } } - public string GetWarningsBeforeSaving() + public string GetWarningsBeforeSaving(ref Dictionary renmInfo) { return string.Empty; } - public void UpdateRelatedItems() + public void UpdateRelatedItems(Dictionary renameInfo) { } } diff --git a/TestBenchFramework/UiControls/MetrologyDlgPlatinumResistanceTMeterTab.cs b/TestBenchFramework/UiControls/MetrologyDlgPlatinumResistanceTMeterTab.cs index 2c7ddb926..40866aad1 100644 --- a/TestBenchFramework/UiControls/MetrologyDlgPlatinumResistanceTMeterTab.cs +++ b/TestBenchFramework/UiControls/MetrologyDlgPlatinumResistanceTMeterTab.cs @@ -219,12 +219,12 @@ namespace TBF.UiControls { } - public string GetWarningsBeforeSaving() + public string GetWarningsBeforeSaving(ref Dictionary renmInfo) { return string.Empty; } - public void UpdateRelatedItems() + public void UpdateRelatedItems(Dictionary renameInfo) { } } diff --git a/TestBenchFramework/UiControls/MetrologyDlgPressMeterTab.cs b/TestBenchFramework/UiControls/MetrologyDlgPressMeterTab.cs index 87ada7a4f..806babf23 100644 --- a/TestBenchFramework/UiControls/MetrologyDlgPressMeterTab.cs +++ b/TestBenchFramework/UiControls/MetrologyDlgPressMeterTab.cs @@ -278,12 +278,12 @@ namespace TBF.UiControls } } - public string GetWarningsBeforeSaving() + public string GetWarningsBeforeSaving(ref Dictionary renmInfo) { return string.Empty; } - public void UpdateRelatedItems() + public void UpdateRelatedItems(Dictionary renameInfo) { } } diff --git a/TestBenchFramework/UiControls/PathsBenchCtrl.cs b/TestBenchFramework/UiControls/PathsBenchCtrl.cs index ecf0cbeea..88afe86d5 100644 --- a/TestBenchFramework/UiControls/PathsBenchCtrl.cs +++ b/TestBenchFramework/UiControls/PathsBenchCtrl.cs @@ -310,7 +310,7 @@ namespace TBF.UiControls } } - public string GetWarningsBeforeSaving() + public string GetWarningsBeforeSaving(ref Dictionary renmInfo) { base.OkBtnClicked(); /// = UpdateAll() @@ -347,20 +347,15 @@ namespace TBF.UiControls return warnings; } - public void UpdateRelatedItems() + public void UpdateRelatedItems(Dictionary renameInfo) { - foreach (var entity in MyItems) + foreach (var tst in parent.Tests) { - if (!string.IsNullOrEmpty(entity.OriName) && entity.OriName != entity.Name) + string newPathName; + if (!string.IsNullOrEmpty(tst.BenchPath) && renameInfo.TryGetValue(tst.BenchPath, out newPathName)) { - foreach (var tst in parent.Tests) - { - if (!string.IsNullOrEmpty(tst.BenchPath) && tst.BenchPath.Equals(entity.OriName)) - { - tst.BenchPath = entity.Name; - Config.FluentCommon.SaveToDb(parent.Session, tst); - } - } + tst.BenchPath = newPathName; + Config.FluentCommon.SaveToDb(parent.Session, tst); } } } diff --git a/TestBenchFramework/UiControls/PathsFeedingCtrl.cs b/TestBenchFramework/UiControls/PathsFeedingCtrl.cs index 43306522d..329c56da2 100644 --- a/TestBenchFramework/UiControls/PathsFeedingCtrl.cs +++ b/TestBenchFramework/UiControls/PathsFeedingCtrl.cs @@ -318,7 +318,7 @@ namespace TBF.UiControls } } - public string GetWarningsBeforeSaving() + public string GetWarningsBeforeSaving(ref Dictionary renmInfo) { base.OkBtnClicked(); /// = UpdateAll() @@ -334,7 +334,8 @@ namespace TBF.UiControls if (occurances > 0) { warnings += string.Format(Strings._0_path_1_used_by_2_tests_will_be_removed_3, Strings.FeedingTabPageTitle, entity.Name, occurances, Environment.NewLine); - } + renmInfo.Add(entity.OriName, string.Empty); + } } } @@ -348,30 +349,26 @@ namespace TBF.UiControls if (occurances > 0) { warnings += string.Format(Strings._0_path_1_used_by_2_tests_will_be_renamed_3, Strings.FeedingTabPageTitle, entity.Name, occurances, Environment.NewLine); - } + renmInfo.Add(entity.OriName, entity.Name); + } } } return warnings; } - public void UpdateRelatedItems() + public void UpdateRelatedItems(Dictionary renameInfo) { - foreach (var entity in MyItems) - { - if (!string.IsNullOrEmpty(entity.OriName) && entity.OriName != entity.Name) - { - foreach (var tst in parent.Tests) - { - if (!string.IsNullOrEmpty(tst.FeedingPath) && tst.FeedingPath.Equals(entity.OriName)) - { - tst.FeedingPath = entity.Name; - Config.FluentCommon.SaveToDb(parent.Session, tst); - } - } - } - } - } + foreach (var tst in parent.Tests) + { + string newPathName; + if (!string.IsNullOrEmpty(tst.FeedingPath) && renameInfo.TryGetValue(tst.FeedingPath, out newPathName)) + { + tst.FeedingPath = newPathName; + Config.FluentCommon.SaveToDb(parent.Session, tst); + } + } + } /// /// Update the entities and save them to the database diff --git a/TestBenchFramework/UiControls/PathsHeatMetersCtrl.cs b/TestBenchFramework/UiControls/PathsHeatMetersCtrl.cs index ea12c09d1..5afdbafe8 100644 --- a/TestBenchFramework/UiControls/PathsHeatMetersCtrl.cs +++ b/TestBenchFramework/UiControls/PathsHeatMetersCtrl.cs @@ -249,7 +249,7 @@ namespace TBF.UiControls } } - public string GetWarningsBeforeSaving() + public string GetWarningsBeforeSaving(ref Dictionary renmInfo) { base.OkBtnClicked(); /// = UpdateAll() @@ -287,25 +287,20 @@ namespace TBF.UiControls return warnings; } - public void UpdateRelatedItems() + public void UpdateRelatedItems(Dictionary renameInfo) { #if HEAT_METERS - foreach (var entity in MyItems) + foreach (var tst in parent.Tests) { - if (!string.IsNullOrEmpty(entity.OriName) && entity.OriName != entity.Name) + string newPathName; + if (!string.IsNullOrEmpty(tst.HeatMetersPath) && renameInfo.TryGetValue(tst.HeatMetersPath, out newPathName)) { - foreach (var tst in parent.Tests) - { - if (!string.IsNullOrEmpty(tst.HeatMetersPath) && tst.HeatMetersPath.Equals(entity.OriName)) - { - tst.HeatMetersPath = entity.Name; - Config.FluentCommon.SaveToDb(parent.Session, tst); - } - } + tst.HeatMetersPath = newPathName; + Config.FluentCommon.SaveToDb(parent.Session, tst); } } #endif - } + } /// /// Update the entities and save them to the database diff --git a/TestBenchFramework/UiControls/PathsMetersCtrl.cs b/TestBenchFramework/UiControls/PathsMetersCtrl.cs index c32b252df..20a98f69c 100644 --- a/TestBenchFramework/UiControls/PathsMetersCtrl.cs +++ b/TestBenchFramework/UiControls/PathsMetersCtrl.cs @@ -186,7 +186,7 @@ namespace TBF.UiControls } } - public string GetWarningsBeforeSaving() + public string GetWarningsBeforeSaving(ref Dictionary renmInfo) { base.OkBtnClicked(); /// = UpdateAll() @@ -223,23 +223,18 @@ namespace TBF.UiControls return warnings; } - public void UpdateRelatedItems() + public void UpdateRelatedItems(Dictionary renameInfo) { - foreach (var entity in MyItems) - { - if (!string.IsNullOrEmpty(entity.OriName) && entity.OriName != entity.Name) - { - foreach (var tst in parent.Tests) - { - if (!string.IsNullOrEmpty(tst.MetersPath) && tst.MetersPath.Equals(entity.OriName)) - { - tst.MetersPath = entity.Name; - Config.FluentCommon.SaveToDb(parent.Session, tst); - } - } - } - } - } + foreach (var tst in parent.Tests) + { + string newPathName; + if (!string.IsNullOrEmpty(tst.MetersPath) && renameInfo.TryGetValue(tst.MetersPath, out newPathName)) + { + tst.MetersPath = newPathName; + Config.FluentCommon.SaveToDb(parent.Session, tst); + } + } + } /// /// Update the entities and save them to the database diff --git a/TestBenchFramework/UiControls/PathsOutputCtrl.cs b/TestBenchFramework/UiControls/PathsOutputCtrl.cs index a0ae4fc0d..9647db4b7 100644 --- a/TestBenchFramework/UiControls/PathsOutputCtrl.cs +++ b/TestBenchFramework/UiControls/PathsOutputCtrl.cs @@ -9,6 +9,7 @@ using Config.Entities; using TBF.BenchControl; using TBF.BenchControl.GenericDevices; using TBF.Resources; +using System.Collections.Generic; namespace TBF.UiControls { @@ -316,7 +317,7 @@ namespace TBF.UiControls } } - public string GetWarningsBeforeSaving() + public string GetWarningsBeforeSaving(ref Dictionary renmInfo) { base.OkBtnClicked(); /// = UpdateAll() @@ -353,23 +354,18 @@ namespace TBF.UiControls return warnings; } - public void UpdateRelatedItems() + public void UpdateRelatedItems(Dictionary renameInfo) { - foreach (var entity in MyItems) - { - if (!string.IsNullOrEmpty(entity.OriName) && entity.OriName != entity.Name) - { - foreach (var tst in parent.Tests) - { - if (!string.IsNullOrEmpty(tst.OutputPath) && tst.OutputPath.Equals(entity.OriName)) - { - tst.OutputPath = entity.Name; - Config.FluentCommon.SaveToDb(parent.Session, tst); - } - } - } - } - } + foreach (var tst in parent.Tests) + { + string newPathName; + if (!string.IsNullOrEmpty(tst.OutputPath) && renameInfo.TryGetValue(tst.OutputPath, out newPathName)) + { + tst.OutputPath = newPathName; + Config.FluentCommon.SaveToDb(parent.Session, tst); + } + } + } /// /// Update the entities and save them to the database diff --git a/TestBenchFramework/UiControls/ProceduresCtrl.cs b/TestBenchFramework/UiControls/ProceduresCtrl.cs index a362b5258..c56740c46 100644 --- a/TestBenchFramework/UiControls/ProceduresCtrl.cs +++ b/TestBenchFramework/UiControls/ProceduresCtrl.cs @@ -360,12 +360,12 @@ namespace TBF.UiControls } } - public string GetWarningsBeforeSaving() + public string GetWarningsBeforeSaving(ref Dictionary renmInfo) { return string.Empty; } - public void UpdateRelatedItems() + public void UpdateRelatedItems(Dictionary renameInfo) { } } diff --git a/TestBenchFramework/UiControls/TransitionStepsCtrl.cs b/TestBenchFramework/UiControls/TransitionStepsCtrl.cs index e4c8fa3d7..85b218774 100644 --- a/TestBenchFramework/UiControls/TransitionStepsCtrl.cs +++ b/TestBenchFramework/UiControls/TransitionStepsCtrl.cs @@ -504,12 +504,12 @@ namespace TBF.UiControls } } - public string GetWarningsBeforeSaving() + public string GetWarningsBeforeSaving(ref Dictionary renmInfo) { return string.Empty; } - public void UpdateRelatedItems() + public void UpdateRelatedItems(Dictionary renameInfo) { } } diff --git a/TestBenchFramework/UiControls/VirtualBenchStepsCtrl.cs b/TestBenchFramework/UiControls/VirtualBenchStepsCtrl.cs index 131f78d9f..a846af34b 100644 --- a/TestBenchFramework/UiControls/VirtualBenchStepsCtrl.cs +++ b/TestBenchFramework/UiControls/VirtualBenchStepsCtrl.cs @@ -259,12 +259,12 @@ namespace TBF.UiControls } } - public string GetWarningsBeforeSaving() + public string GetWarningsBeforeSaving(ref Dictionary renmInfo) { return string.Empty; } - public void UpdateRelatedItems() + public void UpdateRelatedItems(Dictionary renameInfo) { } }