diff --git a/ResultsBrowser/Program.cs b/ResultsBrowser/Program.cs index ad51abeff..b2b617dac 100644 --- a/ResultsBrowser/Program.cs +++ b/ResultsBrowser/Program.cs @@ -246,7 +246,7 @@ namespace ResultsBrowser if (LocalSettings.LastProcedureName != null) { IList listOfProcedures = FluentCommon.CreateSession(Database.Procedures) - .CreateQuery("FROM Procedure WHERE Name = :procName") + .CreateQuery("FROM Procedure WHERE ProcedureState = 'Active' AND Name = :procName") .SetParameter("procName", LocalSettings.LastProcedureName) .List(); diff --git a/TODO.txt b/TODO.txt index dbc046702..0848c8ddc 100644 --- a/TODO.txt +++ b/TODO.txt @@ -1,10 +1,12 @@ iPerl: +- menej logovania vah MettlerToledo +- naukaldat process data pre UnknownPcbNr... vodomery +- vyuzit sirku obrazovky na Activity, Progress bar, Drop down menu + - log pre pevny start, podobne (zarazky) ako pre letmy - 'Q2 corrected from ...' Evaluate a Publish parametre - STOP nefunguje vzdy (alebo pomaly) - zlepsit uzivatelsky dojem -- zapamatat si sirku stlpcov v okne Procedures -- vyuzit sirku obrazovky na Activity, Progress bar, Drop down menu - v iPerlCommunication ponukat stringy v drop-down menu - na Process obrazovke posunut stupacku a rezervoar uplne doprava diff --git a/TestBenchFramework/BenchControl/StateMachine.cs b/TestBenchFramework/BenchControl/StateMachine.cs index d2538080d..91f476b3b 100644 --- a/TestBenchFramework/BenchControl/StateMachine.cs +++ b/TestBenchFramework/BenchControl/StateMachine.cs @@ -338,7 +338,7 @@ namespace TBF.BenchControl if (loadPathsOnly) return; IList selectedProcs = session - .CreateQuery("FROM Procedure WHERE Name = :name") + .CreateQuery("FROM Procedure WHERE ProcedureState = 'Active' AND Name = :name") .SetParameter("name", TBF.UiBridge.Bridge.SelectedProcedureName) .List(); diff --git a/TestBenchFramework/Entities/Enums.cs b/TestBenchFramework/Entities/Enums.cs index 5e06f95f9..b699d37ee 100644 --- a/TestBenchFramework/Entities/Enums.cs +++ b/TestBenchFramework/Entities/Enums.cs @@ -6,6 +6,14 @@ using System.Collections.Generic; namespace TBF.Entities { + public enum ProcedureState + { + Active, + History, + Template, + Count, + } + /// /// Kind of meters for the procedure / test /// diff --git a/TestBenchFramework/Entities/Procedure.cs b/TestBenchFramework/Entities/Procedure.cs index 800fd4b1e..e476405e9 100644 --- a/TestBenchFramework/Entities/Procedure.cs +++ b/TestBenchFramework/Entities/Procedure.cs @@ -15,13 +15,20 @@ namespace TBF.Entities public virtual int Id { get; protected set; } public virtual int ItemNr { get; set; } public virtual string Name { get; set; } - public virtual MetersKind MetersKind { get; set; } + public virtual string Description { get; set; } /// Short description public virtual string CreationUser { get; set; } /// Name of the user who has created or changed this procedure public virtual DateTime CreationTime { get; set; } /// Date and time of the creation or change public virtual string LastChgUser { get; set; } /// Name of the user who has created or changed this procedure public virtual DateTime LastChgTime { get; set; } /// Date and time of the creation or change public virtual string LongDescription { get; set; } /// Long description (notes) + + public virtual ProcedureState ProcedureState { get; set; } + public virtual int Revision { get; set; } + public virtual int PredecessorId { get; set; } + public virtual bool ObtainedByCopy { get; set; } + /// + public virtual MetersKind MetersKind { get; set; } public virtual string Watermeters { get; set; } /// Water meter name or Id public virtual string ProtocolTitle { get; set; } /// Title of the printed and saved protocol @@ -74,6 +81,10 @@ namespace TBF.Entities result.LastChgUser = LastChgUser; result.LastChgTime = LastChgTime; result.LongDescription = LongDescription; + + result.ProcedureState = ProcedureState.Active; + result.PredecessorId = Id; + result.Watermeters = Watermeters; result.DataEntry = DataEntry; result.ResultsPrinter = ResultsPrinter; diff --git a/TestBenchFramework/LocalSettings.cs b/TestBenchFramework/LocalSettings.cs index eccc2b66c..965ec2a0e 100644 --- a/TestBenchFramework/LocalSettings.cs +++ b/TestBenchFramework/LocalSettings.cs @@ -115,6 +115,7 @@ namespace TBF public int MetrologyDlgWidth; public int MetrologyDlgHeight; + /// Procedures public int ProceduresDlgLeft; public int ProceduresDlgTop; @@ -132,10 +133,15 @@ namespace TBF public int OneProcedureDlgWidth; public int OneProcedureDlgHeight; - /// OneProcedure public int PrintOrderLeft; public int PrintOrderTop; + [XmlArrayAttribute("HistoryColumnWidths")] + public int[] HistoryColumnWidths; + [XmlIgnore] + public int HistoryColumnCount { get { return (HistoryColumnWidths != null) ? HistoryColumnWidths.Length : 0; } } + + /// Serial numbers public string[] LastSNTexts; [XmlIgnore] diff --git a/TestBenchFramework/MainWnd.cs b/TestBenchFramework/MainWnd.cs index ee2da2e02..5be744fde 100644 --- a/TestBenchFramework/MainWnd.cs +++ b/TestBenchFramework/MainWnd.cs @@ -349,7 +349,7 @@ namespace TBF string oriProcName = procedureComboBox.Text; IList procedures = FluentCommon.CreateSession(Database.Procedures) - .CreateQuery("FROM Procedure ORDER BY ItemNr") + .CreateQuery("FROM Procedure WHERE ProcedureState = 'Active' ORDER BY ItemNr") .List(); procedureComboBox.Items.Clear(); @@ -526,7 +526,7 @@ namespace TBF } IList procedure = session - .CreateQuery("FROM Procedure WHERE Name = :procedureName") + .CreateQuery("FROM Procedure WHERE ProcedureState = 'Active' AND Name = :procedureName") .SetParameter("procedureName", testResults[0].ProcedureName) .List(); diff --git a/TestBenchFramework/Mappings/ProcedureMap.cs b/TestBenchFramework/Mappings/ProcedureMap.cs index 2f6c6c511..e3720d738 100644 --- a/TestBenchFramework/Mappings/ProcedureMap.cs +++ b/TestBenchFramework/Mappings/ProcedureMap.cs @@ -13,13 +13,20 @@ namespace TBF.Mappings Id(x => x.Id); Map(x => x.ItemNr); Map(x => x.Name); - Map(x => x.MetersKind); + Map(x => x.Description); Map(x => x.CreationUser); Map(x => x.CreationTime); Map(x => x.LastChgUser); Map(x => x.LastChgTime); Map(x => x.LongDescription); + + Map(x => x.ProcedureState); + Map(x => x.Revision); + Map(x => x.PredecessorId); + Map(x => x.ObtainedByCopy); + + Map(x => x.MetersKind); Map(x => x.Watermeters); Map(x => x.ProtocolTitle); Map(x => x.DataEntry); diff --git a/TestBenchFramework/ProcedureDlg.Designer.cs b/TestBenchFramework/ProcedureDlg.Designer.cs index 307a1b725..14cca9ada 100644 --- a/TestBenchFramework/ProcedureDlg.Designer.cs +++ b/TestBenchFramework/ProcedureDlg.Designer.cs @@ -35,6 +35,8 @@ namespace TBF this.mainSplitContainer = new System.Windows.Forms.SplitContainer(); this.tabControl = new System.Windows.Forms.TabControl(); this.generalTabPage = new System.Windows.Forms.TabPage(); + this.protocolTitleTextBox = new System.Windows.Forms.TextBox(); + this.protocolTitleLabel = new System.Windows.Forms.Label(); this.metersKindRadioButton2 = new System.Windows.Forms.RadioButton(); this.metersKindRadioButton1 = new System.Windows.Forms.RadioButton(); this.transitionEndComboBox = new System.Windows.Forms.ComboBox(); @@ -65,9 +67,6 @@ namespace TBF this.label1 = new System.Windows.Forms.Label(); this.historyTabPage = new System.Windows.Forms.TabPage(); this.historyListViewEx = new TBF.UiControls.ListViewEx(); - this.changedByClmnHdr = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); - this.dateClmnHdr = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); - this.descriptionClmnHdr = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.metrology1TabPage = new System.Windows.Forms.TabPage(); this.metrology1ListViewEx = new TBF.UiControls.ListViewEx(); this.metrology2TabPage = new System.Windows.Forms.TabPage(); @@ -77,8 +76,6 @@ namespace TBF this.parametersTabPage = new System.Windows.Forms.TabPage(); this.parametersListViewEx = new TBF.UiControls.ListViewEx(); this.sharedButtons = new TBF.UiControls.SharedButtons(); - this.protocolTitleTextBox = new System.Windows.Forms.TextBox(); - this.protocolTitleLabel = new System.Windows.Forms.Label(); ((System.ComponentModel.ISupportInitialize)(this.mainSplitContainer)).BeginInit(); this.mainSplitContainer.Panel1.SuspendLayout(); this.mainSplitContainer.Panel2.SuspendLayout(); @@ -156,6 +153,17 @@ namespace TBF this.generalTabPage.ToolTipText = global::TBF.Resources.Strings.String1; this.generalTabPage.UseVisualStyleBackColor = true; // + // protocolTitleTextBox + // + resources.ApplyResources(this.protocolTitleTextBox, "protocolTitleTextBox"); + this.protocolTitleTextBox.Name = "protocolTitleTextBox"; + // + // protocolTitleLabel + // + resources.ApplyResources(this.protocolTitleLabel, "protocolTitleLabel"); + this.protocolTitleLabel.ImageKey = global::TBF.Resources.Strings.String1; + this.protocolTitleLabel.Name = "protocolTitleLabel"; + // // metersKindRadioButton2 // resources.ApplyResources(this.metersKindRadioButton2, "metersKindRadioButton2"); @@ -329,10 +337,6 @@ namespace TBF // historyListViewEx // this.historyListViewEx.AllowColumnReorder = true; - this.historyListViewEx.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] { - this.changedByClmnHdr, - this.dateClmnHdr, - this.descriptionClmnHdr}); resources.ApplyResources(this.historyListViewEx, "historyListViewEx"); this.historyListViewEx.DoubleClickActivation = false; this.historyListViewEx.FullRowSelect = true; @@ -341,18 +345,6 @@ namespace TBF this.historyListViewEx.UseCompatibleStateImageBehavior = false; this.historyListViewEx.View = System.Windows.Forms.View.Details; // - // changedByClmnHdr - // - resources.ApplyResources(this.changedByClmnHdr, "changedByClmnHdr"); - // - // dateClmnHdr - // - resources.ApplyResources(this.dateClmnHdr, "dateClmnHdr"); - // - // descriptionClmnHdr - // - resources.ApplyResources(this.descriptionClmnHdr, "descriptionClmnHdr"); - // // metrology1TabPage // this.metrology1TabPage.Controls.Add(this.metrology1ListViewEx); @@ -435,17 +427,6 @@ namespace TBF resources.ApplyResources(this.sharedButtons, "sharedButtons"); this.sharedButtons.Name = "sharedButtons"; // - // protocolTitleTextBox - // - resources.ApplyResources(this.protocolTitleTextBox, "protocolTitleTextBox"); - this.protocolTitleTextBox.Name = "protocolTitleTextBox"; - // - // protocolTitleLabel - // - resources.ApplyResources(this.protocolTitleLabel, "protocolTitleLabel"); - this.protocolTitleLabel.ImageKey = global::TBF.Resources.Strings.String1; - this.protocolTitleLabel.Name = "protocolTitleLabel"; - // // ProcedureDlg // resources.ApplyResources(this, "$this"); @@ -475,9 +456,6 @@ namespace TBF private System.Windows.Forms.TabControl tabControl; private System.Windows.Forms.TabPage historyTabPage; private UiControls.ListViewEx historyListViewEx; - private System.Windows.Forms.ColumnHeader changedByClmnHdr; - private System.Windows.Forms.ColumnHeader dateClmnHdr; - private System.Windows.Forms.ColumnHeader descriptionClmnHdr; private System.Windows.Forms.TabPage metrology1TabPage; private UiControls.ListViewEx metrology1ListViewEx; private System.Windows.Forms.TabPage metrology2TabPage; @@ -518,6 +496,5 @@ namespace TBF private UiControls.ListViewEx parametersListViewEx; private System.Windows.Forms.TextBox protocolTitleTextBox; private System.Windows.Forms.Label protocolTitleLabel; - } } \ No newline at end of file diff --git a/TestBenchFramework/ProcedureDlg.cs b/TestBenchFramework/ProcedureDlg.cs index a00d9e084..18cfe206b 100644 --- a/TestBenchFramework/ProcedureDlg.cs +++ b/TestBenchFramework/ProcedureDlg.cs @@ -258,6 +258,8 @@ namespace TBF Left = (ls.OneProcedureDlgLeft != 0) ? ls.OneProcedureDlgLeft : 150; Top = (ls.OneProcedureDlgTop != 0) ? ls.OneProcedureDlgTop : 150; + InitializeHistoryTab(); /// Create ListViewEx columns for 'History of changes' + /// Create LisViewEx columns and edit controls for 'Metrology1', 'Metrology2' and 'Process' tabs PrepareMetrology12AndProcessTabs(); @@ -290,6 +292,7 @@ namespace TBF { ctrl.Initialize(); } + RefreshAllTabs(); } @@ -371,7 +374,74 @@ namespace TBF #endregion - #region Metrology1, Metrology2, Process, and Parameters + #region History + + void InitializeHistoryTab() + { + TBF.LocalSettings ls = Program.LocalSettings; + + historyListViewEx.Columns.Add(Strings.Name, (ls.HistoryColumnCount > 0) ? ls.HistoryColumnWidths[0] : 80); + historyListViewEx.Columns.Add(Strings.Revision, (ls.HistoryColumnCount > 0) ? ls.HistoryColumnWidths[0] : 80); + historyListViewEx.Columns.Add(Strings.Date_and_time_, (ls.HistoryColumnCount > 1) ? ls.HistoryColumnWidths[1] : 120); + historyListViewEx.Columns.Add(Strings.User_, (ls.HistoryColumnCount > 2) ? ls.HistoryColumnWidths[2] : 55); + historyListViewEx.Columns.Add(Strings.DescriptionColHdr, (ls.HistoryColumnCount > 3) ? ls.HistoryColumnWidths[3] : 300); + + RefreshHistoryTab(); + } + + void RefreshHistoryTab() + { + NHibernate.ISession session = FluentCommon.CreateSession(Database.Procedures); + IList procedures = session + .CreateQuery("FROM Procedure WHERE ProcedureState = 'History'") + .List(); + + int predecessorId = LoadedProcedure.PredecessorId; + + IList oneProcedure = session + .CreateQuery(string.Format("FROM Procedure WHERE ProcedureState = 'Active' AND Id = {0}", predecessorId)) + .List(); + + if (oneProcedure.Count == 1) + { + predecessorId = oneProcedure[0].PredecessorId; + } + else + { + return; + } + + while (predecessorId != 0) + { + bool found = false; + foreach (var p in procedures) + { + if (p.Id == predecessorId) + { + found = true; + ListViewItem item = new ListViewItem(p.Name); + item.SubItems.Add(p.Revision.ToString()); + item.SubItems.Add(p.LastChgTime.ToShortDateString()); + item.SubItems.Add(p.LastChgUser.ToString()); + item.SubItems.Add(p.Description); + historyListViewEx.Items.Add(item); + + predecessorId = p.PredecessorId; /// Iterate + break; + } + } + if (!found) break; + } + } + + void UpdateFromHistoryTab() + { + // Do nothing + } + + #endregion + + #region Metrology1, Metrology2, Process, and Parameters void PrepareMetrology12AndProcessTabs() { diff --git a/TestBenchFramework/ProcedureDlg.resx b/TestBenchFramework/ProcedureDlg.resx index 21280e561..bc0f17202 100644 --- a/TestBenchFramework/ProcedureDlg.resx +++ b/TestBenchFramework/ProcedureDlg.resx @@ -930,21 +930,6 @@ 0 - - Changed by - - - 80 - - - Date - - - Description - - - 400 - Fill @@ -961,7 +946,7 @@ historyListViewEx - TBF.UiControls.ListViewEx, TBF, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null + TBF.UiControls.ListViewEx, TBF, Version=1.5.146.1, Culture=neutral, PublicKeyToken=null historyTabPage @@ -1012,7 +997,7 @@ metrology1ListViewEx - TBF.UiControls.ListViewEx, TBF, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null + TBF.UiControls.ListViewEx, TBF, Version=1.5.146.1, Culture=neutral, PublicKeyToken=null metrology1TabPage @@ -1063,7 +1048,7 @@ metrology2ListViewEx - TBF.UiControls.ListViewEx, TBF, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null + TBF.UiControls.ListViewEx, TBF, Version=1.5.146.1, Culture=neutral, PublicKeyToken=null metrology2TabPage @@ -1114,7 +1099,7 @@ processListViewEx - TBF.UiControls.ListViewEx, TBF, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null + TBF.UiControls.ListViewEx, TBF, Version=1.5.146.1, Culture=neutral, PublicKeyToken=null processTabPage @@ -1165,7 +1150,7 @@ parametersListViewEx - TBF.UiControls.ListViewEx, TBF, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null + TBF.UiControls.ListViewEx, TBF, Version=1.5.146.1, Culture=neutral, PublicKeyToken=null parametersTabPage @@ -1249,7 +1234,7 @@ sharedButtons - TBF.UiControls.SharedButtons, TBF, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null + TBF.UiControls.SharedButtons, TBF, Version=1.5.146.1, Culture=neutral, PublicKeyToken=null mainSplitContainer.Panel2 @@ -1305,24 +1290,6 @@ Procedure - - changedByClmnHdr - - - System.Windows.Forms.ColumnHeader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - dateClmnHdr - - - System.Windows.Forms.ColumnHeader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - descriptionClmnHdr - - - System.Windows.Forms.ColumnHeader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - ProcedureDlg diff --git a/TestBenchFramework/Program.cs b/TestBenchFramework/Program.cs index df540f856..acf23d0b4 100644 --- a/TestBenchFramework/Program.cs +++ b/TestBenchFramework/Program.cs @@ -294,7 +294,7 @@ namespace TBF if (LocalSettings.LastProcedureName != null) { IList listOfProcedures = FluentCommon.CreateSession(Database.Procedures) - .CreateQuery("FROM Procedure WHERE Name = :procName") + .CreateQuery("FROM Procedure WHERE ProcedureState = 'Active' AND Name = :procName") .SetParameter("procName", LocalSettings.LastProcedureName) .List(); diff --git a/TestBenchFramework/Properties/AssemblyInfo.cs b/TestBenchFramework/Properties/AssemblyInfo.cs index b851ba120..22098d145 100644 --- a/TestBenchFramework/Properties/AssemblyInfo.cs +++ b/TestBenchFramework/Properties/AssemblyInfo.cs @@ -29,5 +29,5 @@ using System.Runtime.InteropServices; // Build Number // Revision // -[assembly: AssemblyVersion("1.5.145.1")] -[assembly: AssemblyFileVersion("1.5.145.1")] +[assembly: AssemblyVersion("1.6.146.1")] +[assembly: AssemblyFileVersion("1.6.146.1")] diff --git a/TestBenchFramework/Resources/Strings.Designer.cs b/TestBenchFramework/Resources/Strings.Designer.cs index a792d22be..44ae5b88f 100644 --- a/TestBenchFramework/Resources/Strings.Designer.cs +++ b/TestBenchFramework/Resources/Strings.Designer.cs @@ -1851,6 +1851,24 @@ namespace TBF.Resources { } } + /// + /// Looks up a localized string similar to Procedure {0} added.. + /// + internal static string Procedure_0_added { + get { + return ResourceManager.GetString("Procedure_0_added", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Procedure {0} modified.. + /// + internal static string Procedure_0_modified { + get { + return ResourceManager.GetString("Procedure_0_modified", resourceCulture); + } + } + /// /// Looks up a localized string similar to Procedures. /// @@ -2247,6 +2265,15 @@ namespace TBF.Resources { } } + /// + /// Looks up a localized string similar to Revision. + /// + internal static string Revision { + get { + return ResourceManager.GetString("Revision", resourceCulture); + } + } + /// /// Looks up a localized string similar to ROI Detection in Progress. /// diff --git a/TestBenchFramework/Resources/Strings.resx b/TestBenchFramework/Resources/Strings.resx index a4b637a5e..4fdd1da18 100644 --- a/TestBenchFramework/Resources/Strings.resx +++ b/TestBenchFramework/Resources/Strings.resx @@ -1153,4 +1153,13 @@ Retry + + Procedure {0} added. + + + Procedure {0} modified. + + + Revision + \ No newline at end of file diff --git a/TestBenchFramework/UiControls/BenchControlPanel.cs b/TestBenchFramework/UiControls/BenchControlPanel.cs index 6c00020e6..fdb8d9439 100644 --- a/TestBenchFramework/UiControls/BenchControlPanel.cs +++ b/TestBenchFramework/UiControls/BenchControlPanel.cs @@ -114,7 +114,7 @@ namespace TBF.UiControls string oriTestName = testComboBox.Text; IList procedures = FluentCommon.CreateSession(Database.Procedures) - .CreateQuery("FROM Procedure WHERE Name = :name") + .CreateQuery("FROM Procedure WHERE ProcedureState = 'Active' AND Name = :name") .SetParameter("name", Program.MainWnd.ProcedureName) .List(); diff --git a/TestBenchFramework/UiControls/ProceduresCtrl.cs b/TestBenchFramework/UiControls/ProceduresCtrl.cs index 50c708f8b..00efea2ed 100644 --- a/TestBenchFramework/UiControls/ProceduresCtrl.cs +++ b/TestBenchFramework/UiControls/ProceduresCtrl.cs @@ -67,7 +67,7 @@ namespace TBF.UiControls { /// Load the procedures session = FluentCommon.CreateSession(Database.Procedures); - MyItems = session.CreateQuery("FROM Procedure ORDER BY ItemNr") + MyItems = session.CreateQuery("FROM Procedure WHERE ProcedureState = 'Active' ORDER BY ItemNr") .List(); base.RedrawAll(); @@ -110,8 +110,10 @@ namespace TBF.UiControls { FluentCommon.DeleteFromDb(session, entity); } + int itemNr = 0; foreach (var entity in MyItems) { + (entity as Entities.Procedure).ItemNr = itemNr++; FluentCommon.SaveToDb(session, entity); } @@ -138,7 +140,42 @@ namespace TBF.UiControls if (notUsed) break; } - base.AddOne(new Entities.Procedure(newName, MyItems.Count + 1)); + Entities.Procedure newProcedure = new Entities.Procedure(newName, MyItems.Count); + newProcedure.ProcedureState = Entities.ProcedureState.Active; + newProcedure.Revision = 1; + newProcedure.PredecessorId = 0; + newProcedure.ObtainedByCopy = false; + newProcedure.CreationUser = Entities.User.CurrentUser.Name; + newProcedure.CreationTime = DateTime.Now; + + if (new ProcedureDlg(newProcedure).ShowDialog() == DialogResult.OK) + { + /// TODO: Make name uniqueness test + parent.Unlock(); + + using(var transaction = session.BeginTransaction()) + { + try + { + newProcedure.LastChgUser = Entities.User.CurrentUser.Name; + newProcedure.LastChgTime = DateTime.Now; + + base.AddOne(newProcedure); + session.SaveOrUpdate(newProcedure); + transaction.Commit(); + + MessageBox.Show(string.Format(Strings.Procedure_0_added, newProcedure.Name), + Strings.Confirmation, + MessageBoxButtons.OK, + MessageBoxIcon.Information); + } + catch (Exception exc) + { + transaction.Rollback(); + } + } + session.Flush(); + } } public new void RemoveSelected() @@ -153,38 +190,43 @@ namespace TBF.UiControls public void editButton_Click(object sender, EventArgs e) { if (SelectedItems.Count != 1) return; - int dbId = (SelectedItems[0].Tag as Entities.Procedure).Id; - if (dbId == 0) + Entities.Procedure originalProcedure = SelectedItems[0].Tag as Entities.Procedure; + Entities.Procedure modifiedProcedure = originalProcedure.Clone(); + + modifiedProcedure.ItemNr = originalProcedure.ItemNr; + modifiedProcedure.Revision = originalProcedure.Revision + 1; + modifiedProcedure.ObtainedByCopy = false; + + if (new ProcedureDlg(modifiedProcedure).ShowDialog() == DialogResult.OK) { - session.SaveOrUpdate(SelectedItems[0].Tag as Entities.Procedure); - } + /// TODO: Make name uniqueness test + parent.Unlock(); - dbId = (SelectedItems[0].Tag as Entities.Procedure).Id; - - /// - /// Entities.Procedure has to be loaded in a different session otherwise - /// the database would be updated in case the dialog was closed with 'Cancel' button. - /// - using (ISession editSession = FluentCommon.CreateSession(Database.Procedures)) - { - IList procedure = editSession - .CreateQuery("FROM Procedure WHERE Id = :id") - .SetParameter("id", dbId) - .List(); - if (procedure.Count != 1) return; - - ProcedureDlg dlg = new ProcedureDlg(procedure[0]); - if (dlg.ShowDialog() == DialogResult.OK) + using (var transaction = session.BeginTransaction()) { - parent.Unlock(); - using (var transaction = editSession.BeginTransaction()) + try { - editSession.SaveOrUpdate(procedure[0]); + originalProcedure.ProcedureState = Entities.ProcedureState.History; + modifiedProcedure.LastChgUser = Entities.User.CurrentUser.Name; + modifiedProcedure.LastChgTime = DateTime.Now; + + session.SaveOrUpdate(originalProcedure); + session.SaveOrUpdate(modifiedProcedure); transaction.Commit(); + + SelectedItems[0].Tag = modifiedProcedure; + MessageBox.Show(string.Format(Strings.Procedure_0_modified, modifiedProcedure.Name), + Strings.Confirmation, + MessageBoxButtons.OK, + MessageBoxIcon.Information); + } + catch (Exception exc) + { + transaction.Rollback(); } - } + session.Flush(); } ReloadAndRedrawAll(); @@ -198,17 +240,34 @@ namespace TBF.UiControls /// Make a copy of the selected procedure Entities.Procedure newProcedure = selectedProcedure.Clone(); + newProcedure.Name = selectedProcedure.Name + Strings.New_name_copy; - newProcedure.ItemNr = MyItems.Count; - newProcedure.CreationUser = Entities.User.CurrentUser.Name; + newProcedure.ItemNr = MyItems.Count; + newProcedure.ProcedureState = Entities.ProcedureState.Active; + newProcedure.Revision = 1; + newProcedure.PredecessorId = selectedProcedure.Id; + newProcedure.ObtainedByCopy = true; + newProcedure.CreationUser = Entities.User.CurrentUser.Name; newProcedure.CreationTime = DateTime.Now; if ((new ProcedureDlg(newProcedure)).ShowDialog() == DialogResult.OK) { + /// TODO: Make name uniqueness test + parent.Unlock(); + using (var transaction = session.BeginTransaction()) { + newProcedure.LastChgUser = Entities.User.CurrentUser.Name; + newProcedure.LastChgTime = DateTime.Now; + + base.AddOne(newProcedure); session.SaveOrUpdate(newProcedure); transaction.Commit(); + + MessageBox.Show(string.Format(Strings.Procedure_0_added, newProcedure.Name), + Strings.Confirmation, + MessageBoxButtons.OK, + MessageBoxIcon.Information); } base.AddOne(newProcedure); }