From f1f662a419dc20819e83bc0477e7674474185b71 Mon Sep 17 00:00:00 2001 From: Milan Hanajik Date: Mon, 23 May 2022 11:53:48 +0200 Subject: [PATCH] Common..CurrentUser static class with Stack userStack, Change( ) and Restore( ). --- Common/Common.csproj | 1 + Common/CurrentUser.cs | 122 ++++++++++++++++++ Common/GlobalData.cs | 30 +---- Common/IUser.cs | 1 + Common/Utils.cs | 4 +- Config/Entities/Procedure.cs | 2 +- Config/Entities/Profile.cs | 2 +- Config/Entities/User.cs | 4 +- Config/FluentCommon.cs | 4 +- DeviceTest/DeviceTestDlg.cs | 10 +- EventViewer/EventViewerWnd.cs | 2 +- GenericTest/GenericTestDlg.cs | 14 +- GenericTest/Program.cs | 2 +- OrderManagement/OrderManagementDlg.cs | 2 +- OrderManagement/Program.cs | 2 +- ProductionTracing/Program.cs | 2 +- .../Forms/PrinterConfigDlg.Designer.cs | 1 + ResultsBrowser/Forms/PrinterConfigDlg.cs | 7 +- SharedDatabase/Entities/User.cs | 49 +++---- SharedDatabase/Forms/DoubleLoginDlg.cs | 34 ++--- SharedDatabase/Forms/LoginDlg.cs | 32 +++-- SharedDatabase/Forms/PasswordChangeDlg.cs | 2 +- SharedDatabase/Forms/TripleLoginDlg.cs | 38 +++--- SharedDatabase/Forms/UserManagementDlg.cs | 12 +- SharedDatabase/Properties/AssemblyInfo.cs | 4 +- TBF/Program.cs | 20 +-- .../BackupAndSecurityOptions/Component.cs | 4 +- .../Output/DB/ProductionTracing/Tracing.cs | 2 +- TBF/Rig/Sequences/MainSeq.cs | 10 +- TBF/Rig/Sequences/MainSeqUtils.cs | 4 +- TBF/Rig/TestMethods/Endurance/CycleDlg.cs | 10 +- .../Endurance/CycleDlg.designer.cs | 97 +++++++------- TBF/Rig/TestMethods/Endurance/CycleDlg.resx | 2 +- TBF/Rig/Various/CoverTest/CoverTestForm.cs | 20 +-- .../CoverTest/CoverTestForm.designer.cs | 1 + .../Components/ComponentParametersDlg.cs | 26 ++-- .../Bench/Components/ComponentsManagerDlg.cs | 11 +- .../EditSchDrawingDlg.Designer.cs | 31 +++-- .../Bench/EditSchDrawing/EditSchDrawingDlg.cs | 11 +- .../Bench/Metrology/MetrologyDlg.Designer.cs | 121 ++++++++--------- TBF/UI/Bench/Metrology/MetrologyDlg.cs | 8 +- TBF/UI/Bench/Paths/PathsDlg.Designer.cs | 1 + TBF/UI/Bench/Paths/PathsDlg.cs | 10 +- TBF/UI/Bench/Paths/PathsDlg.resx | 58 +-------- TBF/UI/Bench/TestProfiles/TestProfileDlg.cs | 52 ++++---- TBF/UI/Bench/TestProfiles/TestProfileDlg.resx | 8 +- TBF/UI/Bench/TestProfiles/TestProfilesCtrl.cs | 22 ++-- TBF/UI/Bench/TestProfiles/TestProfilesDlg.cs | 9 +- .../TestProfiles/TestProfilesDlg.designer.cs | 1 + .../Transitions/TransitionsDlg.Designer.cs | 97 +++++++------- TBF/UI/Bench/Transitions/TransitionsDlg.cs | 10 +- TBF/UI/Bench/Transitions/TransitionsDlg.resx | 5 +- .../Bench/Uncertainties/UncertaintiesDlg.cs | 6 + .../UncertaintiesDlg.designer.cs | 1 + TBF/UI/MainWnd.cs | 29 ++--- TBF/UI/Procedures/ProcedureDlg.cs | 68 +++++----- TBF/UI/Procedures/ProceduresCtrl.cs | 34 ++--- TBF/UI/Procedures/ProceduresDlg.Designer.cs | 5 +- TBF/UI/Procedures/ProceduresDlg.cs | 6 + .../DeleteFromOracleForm.Designer.cs | 19 +-- TBF/UI/ResultsMI/DeleteFromOracleForm.cs | 5 + .../ResultsArrangementDlg.Designer.cs | 1 + TBF/UI/ResultsMI/ResultsArrangementDlg.cs | 19 ++- TBF/UI/ResultsMI/ResultsTabPageCtrl.cs | 23 ++-- TBF/UI/Shared/BenchControlPanel.cs | 6 +- TBF/UI/Shared/SharedButtons.cs | 17 +-- WorkflowConfigurator/MainWnd.cs | 4 +- .../UserControls/EditProcessCtrl.cs | 12 +- .../UserControls/OverviewOfProcessesCtrl.cs | 14 +- Workplace/Program.cs | 9 +- Workplace/WorkplaceDlg.cs | 19 +-- 71 files changed, 738 insertions(+), 593 deletions(-) create mode 100644 Common/CurrentUser.cs diff --git a/Common/Common.csproj b/Common/Common.csproj index c18b5b1b7..1be056c82 100644 --- a/Common/Common.csproj +++ b/Common/Common.csproj @@ -64,6 +64,7 @@ ModelessForm.cs + diff --git a/Common/CurrentUser.cs b/Common/CurrentUser.cs new file mode 100644 index 000000000..27bfb4df1 --- /dev/null +++ b/Common/CurrentUser.cs @@ -0,0 +1,122 @@ +/// +/// Copyright (c) 2021-2022 Sensus Slovensko a.s. +/// +using System; +using System.Collections.Generic; +using System.Windows.Forms; + +namespace Common +{ + class UserAndForm + { + public readonly IUser User; + public readonly Form Form; + + public UserAndForm(IUser user, Form form) + { + User = user; + Form = form; + } + } + + public static class CurrentUser + { + public const string AdminUsername = "admin"; + public const string AdminPassword = "staratura"; + + public static int MinPasswdLength = 0; + public static int PasswdExpirationPeriodDays = 0; + + public static DBSettings RemoteUsersDB = null; + public static DBSettings LocalUsersDB = null; + + + static readonly Stack userStack = new Stack(); + + public static Common.AuthorizedAs AuthorizedAs; + public static DateTime LastAuthorization = DateTime.Now; + + + /// + /// Push a new user into the stack of users and form references. + /// Prevent double user stack entry for the same Windows form. + /// + /// New user + /// Reference to the current form + public static void Change(IUser newUser, Form currentForm) + { + if (userStack.Count > 0 && userStack.Peek().Form == currentForm) + { + userStack.Pop(); + } + + userStack.Push(new UserAndForm(newUser, currentForm)); + } + + /// + /// Restore an original user from the stack of users - remove user at the top of the stack. + /// Prevent restoring when there is no entry for the form currently being closed. + /// + /// Reference to the form currently being closed + /// true = current user was restored, false = no current user change + public static bool Restore(Form formBeingClosed) + { + if (userStack.Count > 0 && userStack.Peek().Form == formBeingClosed) + { + userStack.Pop(); + return true; + } + + return false; + } + + /// + /// Return the user currenty at the top of the stack of users. + /// + public static IUser User() + { + return (userStack.Count > 0) ? userStack.Peek().User : null; /// TODO: Return default user when stack is empty + } + + public static IUser User2; + public static IUser User3; + + /// + /// Return the current user name or an empty string + /// + public static string UserName() + { + if (User() == null || User().UserName == null) + return string.Empty; + else if (User2 == null || User2.UserName == null) + return User().UserName; + else if (User3 == null || User3.UserName == null) + return string.Format("{0},{1}", User().UserName, User2.UserName); + else + return string.Format("{0},{1},{2}", User().UserName, User2.UserName, User3.UserName); + } + + /// + /// Return the current user number or 0 + /// + public static int Number() + { + return (User() != null) ? User().Number : 0; + } + + public static bool IsPowerUser() + { + return (User() != null) ? User().IsPowerUser() : false; + } + + public static bool IsMemberOf(GID groupId) + { + return (User() != null) ? User().IsMemberOf(groupId) : false; + } + + public static bool IsMemberOf(GID[] groupIds) + { + return (User() != null) ? User().IsMemberOf(groupIds) : (groupIds == null); + } + } +} diff --git a/Common/GlobalData.cs b/Common/GlobalData.cs index 44b7e9260..da15f5a6d 100644 --- a/Common/GlobalData.cs +++ b/Common/GlobalData.cs @@ -5,38 +5,10 @@ using System; namespace Common { - public class GlobalData + public static class GlobalData { public static double SampleDensity = 0; /// sample water density measured in an accredited labo [kg/m3] public static double SampleTemp = 0; /// sample temperature when density measured in an accredited labo [°C] public static double Buoyancy = 0; - - public const string AdminUsername = "admin"; - public const string AdminPassword = "staratura"; - - public static DBSettings RemoteUsersDB = null; - public static DBSettings LocalUsersDB = null; - - public static IUser CurrentUser; - public static IUser CurrentUser2; - public static IUser CurrentUser3; - - public static Common.AuthorizedAs AuthorizedAs; - public static DateTime LastAuthorization = DateTime.Now; - - public static int MinPasswdLength = 0; - public static int PasswdExpirationPeriodDays = 0; - - public static string GetCurrentUserName() - { - if (CurrentUser == null || CurrentUser.UserName == null) - return string.Empty; - else if (CurrentUser2 == null || CurrentUser2.UserName == null) - return CurrentUser.UserName; - else if (CurrentUser3 == null || CurrentUser3.UserName == null) - return string.Format("{0},{1}", CurrentUser.UserName, CurrentUser2.UserName); - else - return string.Format("{0},{1},{2}", CurrentUser.UserName, CurrentUser2.UserName, CurrentUser3.UserName); - } } } diff --git a/Common/IUser.cs b/Common/IUser.cs index e127c2f6b..c401bae4e 100644 --- a/Common/IUser.cs +++ b/Common/IUser.cs @@ -10,6 +10,7 @@ namespace Common int Number { get; } /// Access rights + bool IsPowerUser(); bool IsMemberOf(GID group); bool IsMemberOf(GID[] groups); bool IsCorrectPassword(string password); diff --git a/Common/Utils.cs b/Common/Utils.cs index a1c1173ac..a187b3099 100644 --- a/Common/Utils.cs +++ b/Common/Utils.cs @@ -212,9 +212,9 @@ namespace Common int length = string.IsNullOrEmpty(password) ? 0 : password.Length; /// Password length must be at least 6 - if (length < GlobalData.MinPasswdLength) + if (length < CurrentUser.MinPasswdLength) { - explanation = string.Format("Password must have at least {0} characters", GlobalData.MinPasswdLength); + explanation = string.Format("Password must have at least {0} characters", CurrentUser.MinPasswdLength); return false; } else diff --git a/Config/Entities/Procedure.cs b/Config/Entities/Procedure.cs index 42df5ab9a..db97e7856 100644 --- a/Config/Entities/Procedure.cs +++ b/Config/Entities/Procedure.cs @@ -75,7 +75,7 @@ namespace Config.Entities /// /// Default values /// - CreationUser = Common.GlobalData.GetCurrentUserName(); + CreationUser = Common.CurrentUser.UserName(); CreationTime = DateTime.Now; LastChgUser = CreationUser; LastChgTime = CreationTime; diff --git a/Config/Entities/Profile.cs b/Config/Entities/Profile.cs index 40cbc7cfe..cc7839886 100644 --- a/Config/Entities/Profile.cs +++ b/Config/Entities/Profile.cs @@ -36,7 +36,7 @@ namespace Config.Entities /// /// Default values /// - CreationUser = GlobalData.GetCurrentUserName(); + CreationUser = CurrentUser.UserName(); CreationTime = DateTime.Now; LastChgUser = CreationUser; LastChgTime = CreationTime; diff --git a/Config/Entities/User.cs b/Config/Entities/User.cs index 94cb3c12e..6a521d3a3 100644 --- a/Config/Entities/User.cs +++ b/Config/Entities/User.cs @@ -157,14 +157,14 @@ namespace Config.Entities /// public virtual bool IsPasswordExpired() { - if (IsPowerUser() || IsMemberOf(GID.Administrators) || GlobalData.PasswdExpirationPeriodDays == 0) + if (IsPowerUser() || IsMemberOf(GID.Administrators) || CurrentUser.PasswdExpirationPeriodDays == 0) { /// Password cannot expirate for this user or this feature is disabled in Backup and Security options return false; } /// Password expiration time is 3 months - return (DateTime.Now - LastPwChange > new TimeSpan(GlobalData.PasswdExpirationPeriodDays, 0, 0, 0)); + return (DateTime.Now - LastPwChange > new TimeSpan(CurrentUser.PasswdExpirationPeriodDays, 0, 0, 0)); } /// diff --git a/Config/FluentCommon.cs b/Config/FluentCommon.cs index afdc2470e..9336ab5a3 100644 --- a/Config/FluentCommon.cs +++ b/Config/FluentCommon.cs @@ -105,11 +105,11 @@ namespace Config /// var admin = new Config.Entities.User { - UserName = GlobalData.AdminUsername, + UserName = CurrentUser.AdminUsername, FullName = Strings.Administrator, LastPwChange = DateTime.Now }; - admin.SetPassword(GlobalData.AdminPassword); + admin.SetPassword(CurrentUser.AdminPassword); /// /// Prepare all groups, add some of them to admin diff --git a/DeviceTest/DeviceTestDlg.cs b/DeviceTest/DeviceTestDlg.cs index 3e71e95bd..4016aecd2 100644 --- a/DeviceTest/DeviceTestDlg.cs +++ b/DeviceTest/DeviceTestDlg.cs @@ -423,7 +423,7 @@ namespace DeviceTest { parentCfg = parentFactory.DefaultConfig(); } - ComponentParametersDlg cfgForm = new ComponentParametersDlg(); + ComponentParametersDlg cfgForm = new ComponentParametersDlg(this); cfgForm.CmpntEntities = new List(); IComponentCfgCtrl cfgControl = parentCfg.GetControl(cfgForm.CmpntEntities); @@ -452,7 +452,7 @@ namespace DeviceTest { component1Cfg = component1Factory.DefaultConfig(); } - ComponentParametersDlg cfgForm = new ComponentParametersDlg(); + ComponentParametersDlg cfgForm = new ComponentParametersDlg(this); /// var compEntities = new List(); if (parentFactory != null && parentCfg != null) compEntities.Add(parentCfg.CreateDbEntity()); @@ -486,7 +486,7 @@ namespace DeviceTest { component2Cfg = component2Factory.DefaultConfig(); } - ComponentParametersDlg cfgForm = new ComponentParametersDlg(); + ComponentParametersDlg cfgForm = new ComponentParametersDlg(this); /// var compEntities = new List(); if (parentFactory != null && parentCfg != null) compEntities.Add(parentCfg.CreateDbEntity()); @@ -521,7 +521,7 @@ namespace DeviceTest { component3Cfg = component3Factory.DefaultConfig(); } - ComponentParametersDlg cfgForm = new ComponentParametersDlg(); + ComponentParametersDlg cfgForm = new ComponentParametersDlg(this); /// var compEntities = new List(); if (parentFactory != null && parentCfg != null) compEntities.Add(parentCfg.CreateDbEntity()); @@ -899,6 +899,8 @@ namespace DeviceTest { Cursor = Cursors.WaitCursor; + CurrentUser.Restore(this); + if (workerThread != null) { workerThreadRunning = false; diff --git a/EventViewer/EventViewerWnd.cs b/EventViewer/EventViewerWnd.cs index 19a7a322e..a661b4f3c 100644 --- a/EventViewer/EventViewerWnd.cs +++ b/EventViewer/EventViewerWnd.cs @@ -291,7 +291,7 @@ namespace EventViewer { try { - GlobalData.RemoteUsersDB = new DBSettings(DBType.MySql, Program.LocalSettings.UsersDBConnString); + CurrentUser.RemoteUsersDB = new DBSettings(DBType.MySql, Program.LocalSettings.UsersDBConnString); SharedDatabase.Forms.LoginDlg dlg = new SharedDatabase.Forms.LoginDlg(); if (dlg.ShowDialog() == DialogResult.OK) { diff --git a/GenericTest/GenericTestDlg.cs b/GenericTest/GenericTestDlg.cs index 28fab8daa..ab552e36f 100644 --- a/GenericTest/GenericTestDlg.cs +++ b/GenericTest/GenericTestDlg.cs @@ -176,13 +176,11 @@ namespace GenericTest private void settingsButton_Click(object sender, EventArgs e) { - IUser oriUser = GlobalData.CurrentUser; /// Save the original user (= tester) - - if (new LoginDlg(Program.SettingsAccessLevel).ShowDialog() == DialogResult.OK) + if (new LoginDlg(Program.SettingsAccessLevel, this).ShowDialog() == DialogResult.OK) { /// Logged in at 'TraceabilityManagement' level - GlobalData.CurrentUser = oriUser; /// Restore the original user (= tester) + CurrentUser.Restore(this); /// Restore the original user (= tester) string oriWorkplace = Program.LocalSettings.Workplace; /// @@ -195,7 +193,7 @@ namespace GenericTest TracingDB.UnregisterWorkplaceObsolete(dbSession, oriWorkplace); TracingDB.RegisterWorkplaceObsolete(dbSession, Program.LocalSettings.Workplace, - GlobalData.GetCurrentUserName(), + CurrentUser.UserName(), "1.2.3.4", "", WorkflowStep, @@ -714,14 +712,14 @@ namespace GenericTest if (!string.IsNullOrEmpty(Program.LocalSettings.UsersDBConnString)) { - GlobalData.LocalUsersDB = new DBSettings(DBType.MySql, Program.LocalSettings.UsersDBConnString); + CurrentUser.LocalUsersDB = new DBSettings(DBType.MySql, Program.LocalSettings.UsersDBConnString); } UpdateTitle(); TracingDB.RegisterWorkplaceObsolete(dbSession, Program.LocalSettings.Workplace, - GlobalData.GetCurrentUserName(), + CurrentUser.UserName(), "1.2.3.4", "", WorkflowStep, @@ -1037,7 +1035,7 @@ namespace GenericTest void UpdateTitle() { - Text = string.Format("{0} v.{1} ({2}, {3})", DfltWorkplaceName, Program.Version, Program.LocalSettings.Workplace, GlobalData.GetCurrentUserName()); + Text = string.Format("{0} v.{1} ({2}, {3})", DfltWorkplaceName, Program.Version, Program.LocalSettings.Workplace, CurrentUser.UserName()); } } } diff --git a/GenericTest/Program.cs b/GenericTest/Program.cs index eb4fc9780..e4e0e4b71 100644 --- a/GenericTest/Program.cs +++ b/GenericTest/Program.cs @@ -153,7 +153,7 @@ namespace GenericTest { try { - GlobalData.LocalUsersDB = new DBSettings(DBType.MySql, LocalSettings.UsersDBConnString); + CurrentUser.LocalUsersDB = new DBSettings(DBType.MySql, LocalSettings.UsersDBConnString); if (new SharedDatabase.Forms.LoginDlg().ShowDialog() != DialogResult.OK) return; } diff --git a/OrderManagement/OrderManagementDlg.cs b/OrderManagement/OrderManagementDlg.cs index 2ae38324c..9f51ce8b2 100644 --- a/OrderManagement/OrderManagementDlg.cs +++ b/OrderManagement/OrderManagementDlg.cs @@ -192,7 +192,7 @@ namespace OrderManagement { try { - Common.GlobalData.RemoteUsersDB = new Common.DBSettings(Common.DBType.MySql, Program.LocalSettings.UsersDBConnString); + Common.CurrentUser.RemoteUsersDB = new Common.DBSettings(Common.DBType.MySql, Program.LocalSettings.UsersDBConnString); DialogResult dr = new SharedDatabase.Forms.LoginDlg().ShowDialog(); if (dr != DialogResult.OK) return; diff --git a/OrderManagement/Program.cs b/OrderManagement/Program.cs index 86dbf7e33..94ce7c1fd 100644 --- a/OrderManagement/Program.cs +++ b/OrderManagement/Program.cs @@ -160,7 +160,7 @@ namespace OrderManagement { try { - Common.GlobalData.RemoteUsersDB = new DBSettings(Common.DBType.MySql, LocalSettings.UsersDBConnString); + Common.CurrentUser.RemoteUsersDB = new DBSettings(Common.DBType.MySql, LocalSettings.UsersDBConnString); DialogResult dr = new SharedDatabase.Forms.LoginDlg().ShowDialog(); if (dr != DialogResult.OK) return; diff --git a/ProductionTracing/Program.cs b/ProductionTracing/Program.cs index 51a04b3c8..b56bfa511 100644 --- a/ProductionTracing/Program.cs +++ b/ProductionTracing/Program.cs @@ -158,7 +158,7 @@ namespace ProductionTracing { try { - Common.GlobalData.RemoteUsersDB = new DBSettings(Common.DBType.MySql, LocalSettings.UsersDBConnString); + Common.CurrentUser.RemoteUsersDB = new DBSettings(Common.DBType.MySql, LocalSettings.UsersDBConnString); DialogResult dr = new SharedDatabase.Forms.LoginDlg().ShowDialog(); if (dr != DialogResult.OK) return; diff --git a/ResultsBrowser/Forms/PrinterConfigDlg.Designer.cs b/ResultsBrowser/Forms/PrinterConfigDlg.Designer.cs index 439835110..30c795977 100644 --- a/ResultsBrowser/Forms/PrinterConfigDlg.Designer.cs +++ b/ResultsBrowser/Forms/PrinterConfigDlg.Designer.cs @@ -107,6 +107,7 @@ this.Controls.Add(this.printerClassComboBox); this.Name = "PrinterConfigDlg"; this.Text = "Printer configuration"; + this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.PrinterConfigDlg_FormClosing); this.Load += new System.EventHandler(this.PrinterClassDlg_Load); this.ResumeLayout(false); this.PerformLayout(); diff --git a/ResultsBrowser/Forms/PrinterConfigDlg.cs b/ResultsBrowser/Forms/PrinterConfigDlg.cs index 9434fbc62..b7beb015f 100644 --- a/ResultsBrowser/Forms/PrinterConfigDlg.cs +++ b/ResultsBrowser/Forms/PrinterConfigDlg.cs @@ -88,7 +88,7 @@ namespace ResultsBrowser.Forms printerCfg = printerFactory.CmpntCfgFromCmpntEntity(cmpnt); } - ComponentParametersDlg cfgForm = new ComponentParametersDlg(); + ComponentParametersDlg cfgForm = new ComponentParametersDlg(this); cfgForm.CmpntEntities = new List(); IComponentCfgCtrl cfgControl = printerCfg.GetControl(cfgForm.CmpntEntities); @@ -167,5 +167,10 @@ namespace ResultsBrowser.Forms return null; } + + private void PrinterConfigDlg_FormClosing(object sender, FormClosingEventArgs e) + { + Common.CurrentUser.Restore(this); + } } } diff --git a/SharedDatabase/Entities/User.cs b/SharedDatabase/Entities/User.cs index 261e215e0..d999a3a07 100644 --- a/SharedDatabase/Entities/User.cs +++ b/SharedDatabase/Entities/User.cs @@ -1,5 +1,5 @@ /// -/// Copyright (c) 2016-2021 Sensus Slovensko a.s. +/// Copyright (c) 2016-2022 Sensus Slovensko a.s. /// using System; using System.Collections.Generic; @@ -30,7 +30,7 @@ namespace SharedDatabase.Entities private bool powerUser; /// true for built-in users, power users have full access even with empty Groups list public virtual bool IsPowerUser() { return powerUser; } - + private string legalizator; /// Not mapped to a database !!!, 2nd user entered in a logging dialog public virtual void SetLegalizator(string value) { legalizator = value; } public virtual string GetLegalizator() { return legalizator; } @@ -160,14 +160,14 @@ namespace SharedDatabase.Entities /// public virtual bool IsPasswordExpired() { - if (IsPowerUser() || IsMemberOf(GID.Administrators) || GlobalData.PasswdExpirationPeriodDays == 0) + if (IsPowerUser() || IsMemberOf(GID.Administrators) || CurrentUser.PasswdExpirationPeriodDays == 0) { /// Password cannot expirate for this user or this feature is disabled in Backup and Security options return false; } /// Password expiration time is 3 months - return (DateTime.Now - LastPwChange > new TimeSpan(GlobalData.PasswdExpirationPeriodDays, 0, 0, 0)); + return (DateTime.Now - LastPwChange > new TimeSpan(CurrentUser.PasswdExpirationPeriodDays, 0, 0, 0)); } /// @@ -216,13 +216,13 @@ namespace SharedDatabase.Entities /// Password /// /// true = authorized - public virtual bool Authorize(string userName, string password, GID[] requiredGroupMembership) + public virtual bool Authorize(string userName, string password, GID[] requiredGroupMembership, System.Windows.Forms.Form currentForm ) { if (Common.Utils.IsPowerUser(userName, password)) { /// User is a power user => authorize - GlobalData.CurrentUser = this; - GlobalData.LastAuthorization = DateTime.Now; + CurrentUser.Change(this, currentForm); + CurrentUser.LastAuthorization = DateTime.Now; log.FatalFormat("Power user '{0}' authorized @level '{1}'", userName, requiredGroupMembership); return true; } @@ -233,7 +233,7 @@ namespace SharedDatabase.Entities return false; } - return CompleteAuthorization(password, requiredGroupMembership); + return CompleteAuthorization(password, requiredGroupMembership, currentForm); } /// @@ -247,7 +247,7 @@ namespace SharedDatabase.Entities /// Password /// /// true = authorized - public virtual bool AuthorizeNumber(int number, string password, GID[] requiredGroupMembership) + public virtual bool AuthorizeNumber(int number, string password, GID[] requiredGroupMembership, System.Windows.Forms.Form currentForm) { if (Number != number) { @@ -255,7 +255,7 @@ namespace SharedDatabase.Entities return false; } - return CompleteAuthorization(password, requiredGroupMembership); + return CompleteAuthorization(password, requiredGroupMembership, currentForm); } /// @@ -269,7 +269,7 @@ namespace SharedDatabase.Entities /// /// /// true = authorized - public virtual bool AuthorizeFullName(string fullName, string password, GID[] requiredGroupMembership) + public virtual bool AuthorizeFullName(string fullName, string password, GID[] requiredGroupMembership, System.Windows.Forms.Form currentForm) { if (FullName.ToLower() != fullName.ToLower()) { @@ -277,7 +277,7 @@ namespace SharedDatabase.Entities return false; } - return CompleteAuthorization(password, requiredGroupMembership); + return CompleteAuthorization(password, requiredGroupMembership, currentForm); } /// @@ -286,7 +286,7 @@ namespace SharedDatabase.Entities /// Password /// Required group membership /// true = authorized - bool CompleteAuthorization(string password, GID[] requiredGroupMembership) + bool CompleteAuthorization(string password, GID[] requiredGroupMembership, System.Windows.Forms.Form currentForm) { if (!IsMemberOf(requiredGroupMembership) || !IsCorrectPassword(password)) { @@ -305,8 +305,8 @@ namespace SharedDatabase.Entities } /// All OK => complete authorization - GlobalData.CurrentUser = this; - GlobalData.LastAuthorization = DateTime.Now; + CurrentUser.Change(this, currentForm); + CurrentUser.LastAuthorization = DateTime.Now; log.FatalFormat("User '{0}' authorized @level '{1}'", UserName, requiredGroupMembership); return true; } @@ -321,7 +321,7 @@ namespace SharedDatabase.Entities /// Tag (RFID, NFC, ... s/n) /// /// true = authorized - public virtual bool AuthorizeTag(string tag, GID[] requiredGroupMembership) + public virtual bool AuthorizeTag(string tag, GID[] requiredGroupMembership, System.Windows.Forms.Form currentForm) { if (Tag != tag) { @@ -332,8 +332,8 @@ namespace SharedDatabase.Entities if (IsMemberOf(requiredGroupMembership)) { /// Group membersip is OK _and_ password is OK => authorize - GlobalData.CurrentUser = this; - GlobalData.LastAuthorization = DateTime.Now; + CurrentUser.Change(this, currentForm); + CurrentUser.LastAuthorization = DateTime.Now; log.FatalFormat("User with Tag={0} authorized @level '{1}'", tag, requiredGroupMembership); return true; } @@ -349,12 +349,13 @@ namespace SharedDatabase.Entities /// /// User name for the query /// reference to a 'User' (if it exists) or null - public static User AuthorizeDummyUser(string username) + public static User AuthorizeDummyUser(string username, System.Windows.Forms.Form currentForm) { User user = new User(); user.UserName = username; - GlobalData.CurrentUser = user; - return user; + CurrentUser.Change(user, currentForm); + CurrentUser.LastAuthorization = DateTime.Now; + return user; } @@ -490,10 +491,10 @@ namespace SharedDatabase.Entities /// /// Unauthorize, abandon current users authorization. /// - public static void Unauthorize() + public static void Unauthorize(System.Windows.Forms.Form currentForm) { - GlobalData.CurrentUser = null; - GlobalData.LastAuthorization = DateTime.Now; + CurrentUser.Restore(currentForm); + CurrentUser.LastAuthorization = DateTime.Now; } public virtual string ToEncodedStr() diff --git a/SharedDatabase/Forms/DoubleLoginDlg.cs b/SharedDatabase/Forms/DoubleLoginDlg.cs index 907ef3793..2c74a8a20 100644 --- a/SharedDatabase/Forms/DoubleLoginDlg.cs +++ b/SharedDatabase/Forms/DoubleLoginDlg.cs @@ -20,7 +20,8 @@ namespace SharedDatabase.Forms // Private fields string predefinedUser; GID[] requiredGroupMembership; - bool noDatabase; + Form parentForm; + bool noDatabase; Color oriBackColor; /// Smart card support, card S/N is used as user.Tag @@ -54,10 +55,11 @@ namespace SharedDatabase.Forms /// /// Constructor with a predefined user. /// - public DoubleLoginDlg(string predefinedUser) + public DoubleLoginDlg(string predefinedUser, Form parentForm) : this() { this.predefinedUser = predefinedUser; + this.parentForm = parentForm; userNameTextBox1.Text = predefinedUser; } @@ -66,11 +68,12 @@ namespace SharedDatabase.Forms /// /// Name of workplace A /// Name of workplace B - public DoubleLoginDlg(string workplace1, string workplace2) + public DoubleLoginDlg(string workplace1, string workplace2, Form parentForm) : this() { workplaceGroupBox1.Text = workplace1; workplaceGroupBox2.Text = workplace2; + this.parentForm = parentForm; } /// @@ -85,21 +88,23 @@ namespace SharedDatabase.Forms /// /// Constructor when a specific group membership is required. /// - public DoubleLoginDlg(GID[] requiredGroupMembership) + public DoubleLoginDlg(GID[] requiredGroupMembership, Form parentForm) : this() { this.requiredGroupMembership = requiredGroupMembership; + this.parentForm = parentForm; } /// /// Constructor with a predefined user when a specific group membership is required. /// - public DoubleLoginDlg(string predefinedUser, GID[] requiredGroupMembership) + public DoubleLoginDlg(string predefinedUser, GID[] requiredGroupMembership, Form parentForm) : this() { this.predefinedUser = predefinedUser; userNameTextBox1.Text = predefinedUser; this.requiredGroupMembership = requiredGroupMembership; + this.parentForm = parentForm; } private void LoginDlg_Load(object sender, EventArgs e) @@ -249,7 +254,7 @@ namespace SharedDatabase.Forms bool authorized = false; if (!noDatabase) { - DBSettings db = GlobalData.LocalUsersDB; + DBSettings db = CurrentUser.LocalUsersDB; loadedUser = User.LoadUserByName(user, db); if (loadedUser != null) @@ -258,15 +263,15 @@ namespace SharedDatabase.Forms { default: case LoginMethod.UserName: - authorized = loadedUser.Authorize(user, password, requiredGroupMembership); + authorized = loadedUser.Authorize(user, password, requiredGroupMembership, parentForm); break; case LoginMethod.FullName: - authorized = loadedUser.AuthorizeFullName(user, password, requiredGroupMembership); + authorized = loadedUser.AuthorizeFullName(user, password, requiredGroupMembership, parentForm); break; case LoginMethod.Number: int number; if (!int.TryParse(user, out number)) break; - authorized = loadedUser.AuthorizeNumber(number, password, requiredGroupMembership); + authorized = loadedUser.AuthorizeNumber(number, password, requiredGroupMembership, parentForm); break; } } @@ -283,7 +288,7 @@ namespace SharedDatabase.Forms { if (requiredGroupMembership == null) { - Entities.User.Unauthorize(); + Entities.User.Unauthorize(parentForm); } DialogResult = DialogResult.Cancel; @@ -316,13 +321,12 @@ namespace SharedDatabase.Forms bool authorized = false; - DBSettings db = GlobalData.LocalUsersDB; - IUser oriUser = GlobalData.CurrentUser; + DBSettings db = CurrentUser.LocalUsersDB; User loadedUser = User.LoadUserByTag(tag, db); if (loadedUser != null) { - authorized = loadedUser.AuthorizeTag(tag, requiredGroupMembership); + authorized = loadedUser.AuthorizeTag(tag, requiredGroupMembership, parentForm); } @@ -515,8 +519,8 @@ namespace SharedDatabase.Forms /// void PrepareClosingDlg() { - GlobalData.CurrentUser = authorizedUser1; - GlobalData.CurrentUser2 = authorizedUser2; + CurrentUser.Change(authorizedUser1, parentForm); + CurrentUser.User2 = authorizedUser2; DialogResult = DialogResult.OK; Close(); diff --git a/SharedDatabase/Forms/LoginDlg.cs b/SharedDatabase/Forms/LoginDlg.cs index 684854fe6..4a9ecf86f 100644 --- a/SharedDatabase/Forms/LoginDlg.cs +++ b/SharedDatabase/Forms/LoginDlg.cs @@ -27,7 +27,8 @@ namespace SharedDatabase.Forms string user; string password; GID[] requiredGroupMembership; - bool noDatabase; + Form parentForm; + bool noDatabase; Color oriBackColor; /// Smart card support, card S/N is used as user.Tag @@ -50,11 +51,12 @@ namespace SharedDatabase.Forms /// /// Constructor with a predefined user. /// - public LoginDlg(string predefinedUser) + public LoginDlg(string predefinedUser, Form parentForm) : this() { user = predefinedUser; userNameTextBox.Text = predefinedUser; + this.parentForm = parentForm; } /// @@ -69,10 +71,11 @@ namespace SharedDatabase.Forms /// /// Constructor when a specific group membership is required. /// - public LoginDlg(GID[] requiredGroupMembership) + public LoginDlg(GID[] requiredGroupMembership, Form parentForm) : this() { this.requiredGroupMembership = requiredGroupMembership; + this.parentForm = parentForm; #if DEBUG user = "milan"; userNameTextBox.Text = "milan"; @@ -83,12 +86,13 @@ namespace SharedDatabase.Forms /// /// Constructor with a predefined user when a specific group membership is required. /// - public LoginDlg(string predefinedUser, GID[] requiredGroupMembership) + public LoginDlg(string predefinedUser, GID[] requiredGroupMembership, Form parentForm) : this() { user = predefinedUser; userNameTextBox.Text = predefinedUser; this.requiredGroupMembership = requiredGroupMembership; + this.parentForm = parentForm; } private void LoginDlg_Load(object sender, EventArgs e) @@ -191,12 +195,12 @@ namespace SharedDatabase.Forms bool authorized = Common.Utils.IsPowerUser(user, password); if (authorized) { - GlobalData.CurrentUser = new Entities.User(user, 6, true); + CurrentUser.Change(new Entities.User(user, 6, true), parentForm); } if (!authorized && !noDatabase) { - DBSettings[] dbs = new DBSettings[] { GlobalData.RemoteUsersDB, GlobalData.LocalUsersDB }; + DBSettings[] dbs = new DBSettings[] { CurrentUser.RemoteUsersDB, CurrentUser.LocalUsersDB }; authorizedAs = AuthorizedAs.RemoteUser; foreach (var db in dbs) @@ -208,12 +212,12 @@ namespace SharedDatabase.Forms case LoginMethod.UserName: default: var usr1 = Entities.User.LoadUserByName(user, db); - if (usr1 != null) { authorized = usr1.Authorize(user, password, requiredGroupMembership); } + if (usr1 != null) { authorized = usr1.Authorize(user, password, requiredGroupMembership, parentForm); } break; case LoginMethod.FullName: var usr2 = Entities.User.LoadUserByFullName(user, db); - if (usr2 != null) { authorized = usr2.AuthorizeFullName(user, password, requiredGroupMembership); } + if (usr2 != null) { authorized = usr2.AuthorizeFullName(user, password, requiredGroupMembership, parentForm); } if (authorized) { user = usr2.UserName; } break; @@ -221,7 +225,7 @@ namespace SharedDatabase.Forms int number; if (!int.TryParse(user, out number)) break; var usr3 = Entities.User.LoadUserByNumber(number, db); - if (usr3 != null) { authorized = usr3.AuthorizeNumber(number, password, requiredGroupMembership); } + if (usr3 != null) { authorized = usr3.AuthorizeNumber(number, password, requiredGroupMembership, parentForm); } if (authorized) { user = usr3.UserName; } break; } @@ -236,7 +240,7 @@ namespace SharedDatabase.Forms if (authorized) { - GlobalData.AuthorizedAs = authorizedAs; + CurrentUser.AuthorizedAs = authorizedAs; DialogResult = DialogResult.OK; Close(); return; @@ -254,7 +258,7 @@ namespace SharedDatabase.Forms { if (requiredGroupMembership == null) { - Entities.User.Unauthorize(); + Entities.User.Unauthorize(parentForm); } DialogResult = DialogResult.Cancel; @@ -297,7 +301,7 @@ namespace SharedDatabase.Forms card.Disconnect(DISCONNECT.Leave); - DBSettings[] dbs = new DBSettings[] { GlobalData.RemoteUsersDB, GlobalData.LocalUsersDB }; + DBSettings[] dbs = new DBSettings[] { CurrentUser.RemoteUsersDB, CurrentUser.LocalUsersDB }; bool authorized = false; AuthorizedAs authorizedAs = AuthorizedAs.RemoteUser; /// @@ -308,7 +312,7 @@ namespace SharedDatabase.Forms Entities.User loadedUser = Entities.User.LoadUserByTag(tag, db); if (loadedUser != null) { - authorized = loadedUser.AuthorizeTag(tag, requiredGroupMembership); + authorized = loadedUser.AuthorizeTag(tag, requiredGroupMembership, parentForm); if (authorized) { @@ -324,7 +328,7 @@ namespace SharedDatabase.Forms if (authorized) { - GlobalData.AuthorizedAs = authorizedAs; + CurrentUser.AuthorizedAs = authorizedAs; DialogResult = DialogResult.OK; Close(); return; diff --git a/SharedDatabase/Forms/PasswordChangeDlg.cs b/SharedDatabase/Forms/PasswordChangeDlg.cs index 05644cc26..e7d586868 100644 --- a/SharedDatabase/Forms/PasswordChangeDlg.cs +++ b/SharedDatabase/Forms/PasswordChangeDlg.cs @@ -97,7 +97,7 @@ namespace SharedDatabase.Forms bool oldPasswdOK = false; if (!oldPasswdOK) { - DBSettings[] dbs = new DBSettings[] { GlobalData.RemoteUsersDB, GlobalData.LocalUsersDB }; + DBSettings[] dbs = new DBSettings[] { CurrentUser.RemoteUsersDB, CurrentUser.LocalUsersDB }; foreach (var db in dbs) { diff --git a/SharedDatabase/Forms/TripleLoginDlg.cs b/SharedDatabase/Forms/TripleLoginDlg.cs index 1471d35fe..1388ab6cb 100644 --- a/SharedDatabase/Forms/TripleLoginDlg.cs +++ b/SharedDatabase/Forms/TripleLoginDlg.cs @@ -20,7 +20,8 @@ namespace SharedDatabase.Forms // Private fields string predefinedUser; GID[] requiredGroupMembership; - bool noDatabase; + Form parentForm; + bool noDatabase; Color oriBackColor; /// Smart card support, card S/N is used as user.Tag @@ -58,10 +59,11 @@ namespace SharedDatabase.Forms /// /// Constructor with a predefined user. /// - public TripleLoginDlg(string predefinedUser) + public TripleLoginDlg(string predefinedUser, Form parentForm) : this() { this.predefinedUser = predefinedUser; + this.parentForm = parentForm; userNameTextBox1.Text = predefinedUser; } @@ -70,9 +72,10 @@ namespace SharedDatabase.Forms /// /// Name of workplace A /// Name of workplace B - public TripleLoginDlg(string workplace1, string workplace2, string workplace3) + public TripleLoginDlg(string workplace1, string workplace2, string workplace3, Form parentForm) : this() { + this.parentForm = parentForm; workplaceGroupBox1.Text = workplace1; workplaceGroupBox2.Text = workplace2; workplaceGroupBox3.Text = workplace3; @@ -90,21 +93,23 @@ namespace SharedDatabase.Forms /// /// Constructor when a specific group membership is required. /// - public TripleLoginDlg(GID[] requiredGroupMembership) + public TripleLoginDlg(GID[] requiredGroupMembership, Form parentForm) : this() { this.requiredGroupMembership = requiredGroupMembership; + this.parentForm = parentForm; } /// /// Constructor with a predefined user when a specific group membership is required. /// - public TripleLoginDlg(string predefinedUser, GID[] requiredGroupMembership) + public TripleLoginDlg(string predefinedUser, GID[] requiredGroupMembership, Form parentForm) : this() { this.predefinedUser = predefinedUser; - userNameTextBox1.Text = predefinedUser; this.requiredGroupMembership = requiredGroupMembership; + this.parentForm = parentForm; + userNameTextBox1.Text = predefinedUser; } private void LoginDlg_Load(object sender, EventArgs e) @@ -274,7 +279,7 @@ namespace SharedDatabase.Forms bool authorized = false; if (!noDatabase) { - DBSettings db = GlobalData.LocalUsersDB; + DBSettings db = CurrentUser.LocalUsersDB; loadedUser = User.LoadUserByName(user, db); if (loadedUser != null) @@ -283,15 +288,15 @@ namespace SharedDatabase.Forms { default: case LoginMethod.UserName: - authorized = loadedUser.Authorize(user, password, requiredGroupMembership); + authorized = loadedUser.Authorize(user, password, requiredGroupMembership, parentForm); break; case LoginMethod.FullName: - authorized = loadedUser.AuthorizeFullName(user, password, requiredGroupMembership); + authorized = loadedUser.AuthorizeFullName(user, password, requiredGroupMembership, parentForm); break; case LoginMethod.Number: int number; if (!int.TryParse(user, out number)) break; - authorized = loadedUser.AuthorizeNumber(number, password, requiredGroupMembership); + authorized = loadedUser.AuthorizeNumber(number, password, requiredGroupMembership, parentForm); break; } } @@ -308,7 +313,7 @@ namespace SharedDatabase.Forms { if (requiredGroupMembership == null) { - Entities.User.Unauthorize(); + Entities.User.Unauthorize(parentForm); } DialogResult = DialogResult.Cancel; @@ -347,13 +352,12 @@ namespace SharedDatabase.Forms bool authorized = false; - DBSettings db = GlobalData.LocalUsersDB; - IUser oriUser = GlobalData.CurrentUser; + DBSettings db = CurrentUser.LocalUsersDB; User loadedUser = User.LoadUserByTag(tag, db); if (loadedUser != null) { - authorized = loadedUser.AuthorizeTag(tag, requiredGroupMembership); + authorized = loadedUser.AuthorizeTag(tag, requiredGroupMembership, parentForm); } @@ -622,9 +626,9 @@ namespace SharedDatabase.Forms /// void PrepareClosingDlg() { - GlobalData.CurrentUser = authorizedUser1; - GlobalData.CurrentUser2 = authorizedUser2; - GlobalData.CurrentUser3 = authorizedUser3; + CurrentUser.Change(authorizedUser1, parentForm); + CurrentUser.User2 = authorizedUser2; + CurrentUser.User3 = authorizedUser3; DialogResult = DialogResult.OK; Close(); diff --git a/SharedDatabase/Forms/UserManagementDlg.cs b/SharedDatabase/Forms/UserManagementDlg.cs index 037fad31e..9696eefcd 100644 --- a/SharedDatabase/Forms/UserManagementDlg.cs +++ b/SharedDatabase/Forms/UserManagementDlg.cs @@ -223,8 +223,8 @@ namespace SharedDatabase.Forms private void copyFromRemoteButton_Click(object sender, EventArgs e) { - if (GlobalData.RemoteUsersDB == null || string.IsNullOrEmpty(GlobalData.RemoteUsersDB.ConnectionString) || - GlobalData.LocalUsersDB == null || string.IsNullOrEmpty(GlobalData.LocalUsersDB.ConnectionString)) + if (CurrentUser.RemoteUsersDB == null || string.IsNullOrEmpty(CurrentUser.RemoteUsersDB.ConnectionString) || + CurrentUser.LocalUsersDB == null || string.IsNullOrEmpty(CurrentUser.LocalUsersDB.ConnectionString)) { MessageBox.Show(Strings.No_remote_database_of_users, Strings.Error, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; @@ -244,8 +244,8 @@ namespace SharedDatabase.Forms /// /// Create remote DB session and read remote users /// - UsersDB.DbType = GlobalData.RemoteUsersDB.DbType; - UsersDB.ConnectionString = GlobalData.RemoteUsersDB.ConnectionString; + UsersDB.DbType = CurrentUser.RemoteUsersDB.DbType; + UsersDB.ConnectionString = CurrentUser.RemoteUsersDB.ConnectionString; ISession remoteSession = UsersDB.CreateSession(); remoteUsers = remoteSession.QueryOver().List(); remoteGroups = remoteSession.QueryOver().List(); @@ -253,8 +253,8 @@ namespace SharedDatabase.Forms /// /// Prepare local DB session /// - UsersDB.DbType = GlobalData.LocalUsersDB.DbType; - UsersDB.ConnectionString = GlobalData.LocalUsersDB.ConnectionString; + UsersDB.DbType = CurrentUser.LocalUsersDB.DbType; + UsersDB.ConnectionString = CurrentUser.LocalUsersDB.ConnectionString; ISession localSession = UsersDB.CreateSession(); transaction = localSession.BeginTransaction(); diff --git a/SharedDatabase/Properties/AssemblyInfo.cs b/SharedDatabase/Properties/AssemblyInfo.cs index 7bf1424d4..29f960c7d 100644 --- a/SharedDatabase/Properties/AssemblyInfo.cs +++ b/SharedDatabase/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ using System.Runtime.InteropServices; // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("3.0.1.0")] -[assembly: AssemblyFileVersion("3.0.1.0")] +[assembly: AssemblyVersion("3.2.0.0")] +[assembly: AssemblyFileVersion("3.2.0.0")] diff --git a/TBF/Program.cs b/TBF/Program.cs index 544179ed3..bb94e222a 100644 --- a/TBF/Program.cs +++ b/TBF/Program.cs @@ -252,8 +252,8 @@ namespace TBF { log.FatalFormat("Test bench name: {0}", loginDlgBench.BenchName); - GlobalData.RemoteUsersDB = LocalSettings.TestBenches[i].UsersDBSettings; - GlobalData.LocalUsersDB = LocalSettings.TestBenches[i].ProceduresDBSettings; + CurrentUser.RemoteUsersDB = LocalSettings.TestBenches[i].UsersDBSettings; + CurrentUser.LocalUsersDB = LocalSettings.TestBenches[i].ProceduresDBSettings; SharedDatabase.Entities.User loadedUser = null; try @@ -269,10 +269,10 @@ namespace TBF if (Common.Utils.IsPowerUser(loginDlgBench.Alias, loginDlgBench.Password)) { loadedUser = new SharedDatabase.Entities.User(loginDlgBench.Alias, 6, true); - authorized = loadedUser.Authorize(loginDlgBench.Alias, loginDlgBench.Password, reqGrpMembership); + authorized = loadedUser.Authorize(loginDlgBench.Alias, loginDlgBench.Password, reqGrpMembership, null); if (authorized) { - GlobalData.AuthorizedAs = AuthorizedAs.PowerUser; + CurrentUser.AuthorizedAs = AuthorizedAs.PowerUser; } } @@ -281,7 +281,7 @@ namespace TBF /// if (!authorized) { - DBSettings[] dbs = new DBSettings[] { GlobalData.RemoteUsersDB, GlobalData.LocalUsersDB }; + DBSettings[] dbs = new DBSettings[] { CurrentUser.RemoteUsersDB, CurrentUser.LocalUsersDB }; authorizedAs = AuthorizedAs.RemoteUser; /// Try remote DB first @@ -293,7 +293,7 @@ namespace TBF if (loginDlgBench.Password == LoginDlgWithBenchSelection.UseTheTagPassword) { loadedUser = SharedDatabase.Entities.User.LoadUserByTag(loginDlgBench.Alias, db); - if (loadedUser != null) authorized = loadedUser.AuthorizeTag(loginDlgBench.Alias, reqGrpMembership); + if (loadedUser != null) authorized = loadedUser.AuthorizeTag(loginDlgBench.Alias, reqGrpMembership, null); } else { @@ -302,17 +302,17 @@ namespace TBF default: case LoginMethod.UserName: loadedUser = SharedDatabase.Entities.User.LoadUserByName(loginDlgBench.Alias, db); - if (loadedUser != null) authorized = loadedUser.Authorize(loginDlgBench.Alias, loginDlgBench.Password, reqGrpMembership); + if (loadedUser != null) authorized = loadedUser.Authorize(loginDlgBench.Alias, loginDlgBench.Password, reqGrpMembership, null); break; case LoginMethod.FullName: loadedUser = SharedDatabase.Entities.User.LoadUserByFullName(loginDlgBench.Alias, db); - if (loadedUser != null) authorized = loadedUser.AuthorizeFullName(loginDlgBench.Alias, loginDlgBench.Password, reqGrpMembership); + if (loadedUser != null) authorized = loadedUser.AuthorizeFullName(loginDlgBench.Alias, loginDlgBench.Password, reqGrpMembership, null); break; case LoginMethod.Number: int number; if (!int.TryParse(loginDlgBench.Alias, out number)) break; loadedUser = SharedDatabase.Entities.User.LoadUserByNumber(number, db); - if (loadedUser != null) authorized = loadedUser.AuthorizeNumber(number, loginDlgBench.Password, reqGrpMembership); + if (loadedUser != null) authorized = loadedUser.AuthorizeNumber(number, loginDlgBench.Password, reqGrpMembership, null); break; } } @@ -331,7 +331,7 @@ namespace TBF if (authorized) { loadedUser.SetLegalizator(loginDlgBench.Legalizator); - GlobalData.AuthorizedAs = authorizedAs; + CurrentUser.AuthorizedAs = authorizedAs; LocalSettings.LoginMethod = loginDlgBench.Method; /// Save the login method actually used diff --git a/TBF/Rig/DataContainer/BackupAndSecurityOptions/Component.cs b/TBF/Rig/DataContainer/BackupAndSecurityOptions/Component.cs index a025ff2f2..9e02217a3 100644 --- a/TBF/Rig/DataContainer/BackupAndSecurityOptions/Component.cs +++ b/TBF/Rig/DataContainer/BackupAndSecurityOptions/Component.cs @@ -32,8 +32,8 @@ namespace TBF.Rig.DataContainer.BackupAndSecurityOptions public override void Initialize() { - GlobalData.MinPasswdLength = myCfg.MinPasswdLength; - GlobalData.PasswdExpirationPeriodDays = myCfg.PasswdExpirationPeriodDays; + CurrentUser.MinPasswdLength = myCfg.MinPasswdLength; + CurrentUser.PasswdExpirationPeriodDays = myCfg.PasswdExpirationPeriodDays; } } } diff --git a/TBF/Rig/Output/DB/ProductionTracing/Tracing.cs b/TBF/Rig/Output/DB/ProductionTracing/Tracing.cs index d688e5e19..733808068 100644 --- a/TBF/Rig/Output/DB/ProductionTracing/Tracing.cs +++ b/TBF/Rig/Output/DB/ProductionTracing/Tracing.cs @@ -599,7 +599,7 @@ namespace TBF.Rig.Output.DB.ProductionTracing StepRecord stepRecord = new StepRecord(refRecord, wflowSummary.WorkstepName, workplace, - Common.GlobalData.GetCurrentUserName(), + Common.CurrentUser.UserName(), wm.PassedFromTests() ? 0 : 1); if (refRecord.StepRecords == null) { diff --git a/TBF/Rig/Sequences/MainSeq.cs b/TBF/Rig/Sequences/MainSeq.cs index 275972ef8..30de211cc 100644 --- a/TBF/Rig/Sequences/MainSeq.cs +++ b/TBF/Rig/Sequences/MainSeq.cs @@ -430,10 +430,10 @@ namespace TBF.Rig.Sequences /// Water meter failed but the failure is not an assembly error wm.Disabled = true; } - else if (!wm.Disabled && (GlobalData.GetCurrentUserName() == "milan" || - GlobalData.GetCurrentUserName() == "augustin" || - GlobalData.GetCurrentUserName() == "michal" || - GlobalData.GetCurrentUserName() == "michal2")) + else if (!wm.Disabled && (CurrentUser.UserName() == "milan" || + CurrentUser.UserName() == "augustin" || + CurrentUser.UserName() == "michal" || + CurrentUser.UserName() == "michal2")) { /// Water meter failed, is not disabled, there is an assembly error and user is one of above /// ... => reset flag E28 @@ -641,7 +641,7 @@ namespace TBF.Rig.Sequences log.ErrorFormat("StartInfoReader failed to read data from the database"); /// TODO: Message for an operator? Error? } - else if ((selection == Selection.RestoreAndFixBatch) && (GlobalData.GetCurrentUserName() != "milan")) + else if ((selection == Selection.RestoreAndFixBatch) && (CurrentUser.UserName() != "milan")) { /// Restore and fix a batch - part 2 for (int i = 0; i < BatchRslts.Batch.WaterMeters.Count; i++) diff --git a/TBF/Rig/Sequences/MainSeqUtils.cs b/TBF/Rig/Sequences/MainSeqUtils.cs index 16d542d5c..04b4cb97f 100644 --- a/TBF/Rig/Sequences/MainSeqUtils.cs +++ b/TBF/Rig/Sequences/MainSeqUtils.cs @@ -614,8 +614,8 @@ namespace TBF.Rig.Sequences (BenchInfo != null) ? BenchInfo.Address3 : string.Empty, (BenchInfo != null) ? BenchInfo.Address4 : string.Empty, (BenchInfo != null) ? BenchInfo.Address5 : string.Empty, - GlobalData.GetCurrentUserName(), - (GlobalData.CurrentUser != null) ? GlobalData.CurrentUser.Number : 0, + CurrentUser.UserName(), + CurrentUser.Number(), Program.Version, StateMachine.Procedure, waterMeterData, diff --git a/TBF/Rig/TestMethods/Endurance/CycleDlg.cs b/TBF/Rig/TestMethods/Endurance/CycleDlg.cs index 99803ae0e..08b15c2e1 100644 --- a/TBF/Rig/TestMethods/Endurance/CycleDlg.cs +++ b/TBF/Rig/TestMethods/Endurance/CycleDlg.cs @@ -34,9 +34,9 @@ namespace TBF.Rig.TestMethods.Endurance ITabWithListViewEx seqStepsCtrl; - public CycleDlg() - : this(new List()) + CycleDlg() { + EnduranceCycle = new List(); } public CycleDlg(IList cycle) @@ -47,6 +47,7 @@ namespace TBF.Rig.TestMethods.Endurance InitializeComponent(); /// SharedDlgButtons configuration + sharedButtons.ParentForm = this; sharedButtons.RequiredGroupMembership = new Common.GID[] { Common.GID.Metrologists }; sharedButtons.OptionalButtons = SharedButtons.Buttons.Add | SharedButtons.Buttons.Remove | @@ -264,5 +265,10 @@ namespace TBF.Rig.TestMethods.Endurance UpdateButtonStates(SharedButtons.SelectedItemPos.Middle); } } + + private void CycleDlg_FormClosing(object sender, FormClosingEventArgs e) + { + if (CurrentUser.Restore(this)) Program.MainWnd.UpdateUser(); + } } } diff --git a/TBF/Rig/TestMethods/Endurance/CycleDlg.designer.cs b/TBF/Rig/TestMethods/Endurance/CycleDlg.designer.cs index a89e77b15..f2b0a1693 100644 --- a/TBF/Rig/TestMethods/Endurance/CycleDlg.designer.cs +++ b/TBF/Rig/TestMethods/Endurance/CycleDlg.designer.cs @@ -31,54 +31,55 @@ namespace TBF.Rig.TestMethods.Endurance /// private void InitializeComponent() { - System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(CycleDlg)); - this.mainSplitContainer = new System.Windows.Forms.SplitContainer(); - this.tabControl = new System.Windows.Forms.TabControl(); - this.sharedButtons = new TBF.UI.Shared.SharedButtons(); - ((System.ComponentModel.ISupportInitialize)(this.mainSplitContainer)).BeginInit(); - this.mainSplitContainer.Panel1.SuspendLayout(); - this.mainSplitContainer.Panel2.SuspendLayout(); - this.mainSplitContainer.SuspendLayout(); - this.SuspendLayout(); - // - // mainSplitContainer - // - resources.ApplyResources(this.mainSplitContainer, "mainSplitContainer"); - this.mainSplitContainer.FixedPanel = System.Windows.Forms.FixedPanel.Panel2; - this.mainSplitContainer.Name = "mainSplitContainer"; - // - // mainSplitContainer.Panel1 - // - this.mainSplitContainer.Panel1.Controls.Add(this.tabControl); - // - // mainSplitContainer.Panel2 - // - this.mainSplitContainer.Panel2.Controls.Add(this.sharedButtons); - // - // tabControl - // - resources.ApplyResources(this.tabControl, "tabControl"); - this.tabControl.Name = "tabControl"; - this.tabControl.SelectedIndex = 0; - this.tabControl.SelectedIndexChanged += new System.EventHandler(this.tabControl_SelectedIndexChanged); - // - // sharedButtons - // - resources.ApplyResources(this.sharedButtons, "sharedButtons"); - this.sharedButtons.Name = "sharedButtons"; - // - // CycleDlg - // - resources.ApplyResources(this, "$this"); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.Controls.Add(this.mainSplitContainer); - this.Name = "CycleDlg"; - this.Load += new System.EventHandler(this.CycleDlg_Load); - this.mainSplitContainer.Panel1.ResumeLayout(false); - this.mainSplitContainer.Panel2.ResumeLayout(false); - ((System.ComponentModel.ISupportInitialize)(this.mainSplitContainer)).EndInit(); - this.mainSplitContainer.ResumeLayout(false); - this.ResumeLayout(false); + System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(CycleDlg)); + this.mainSplitContainer = new System.Windows.Forms.SplitContainer(); + this.tabControl = new System.Windows.Forms.TabControl(); + this.sharedButtons = new TBF.UI.Shared.SharedButtons(); + ((System.ComponentModel.ISupportInitialize)(this.mainSplitContainer)).BeginInit(); + this.mainSplitContainer.Panel1.SuspendLayout(); + this.mainSplitContainer.Panel2.SuspendLayout(); + this.mainSplitContainer.SuspendLayout(); + this.SuspendLayout(); + // + // mainSplitContainer + // + resources.ApplyResources(this.mainSplitContainer, "mainSplitContainer"); + this.mainSplitContainer.FixedPanel = System.Windows.Forms.FixedPanel.Panel2; + this.mainSplitContainer.Name = "mainSplitContainer"; + // + // mainSplitContainer.Panel1 + // + this.mainSplitContainer.Panel1.Controls.Add(this.tabControl); + // + // mainSplitContainer.Panel2 + // + this.mainSplitContainer.Panel2.Controls.Add(this.sharedButtons); + // + // tabControl + // + resources.ApplyResources(this.tabControl, "tabControl"); + this.tabControl.Name = "tabControl"; + this.tabControl.SelectedIndex = 0; + this.tabControl.SelectedIndexChanged += new System.EventHandler(this.tabControl_SelectedIndexChanged); + // + // sharedButtons + // + resources.ApplyResources(this.sharedButtons, "sharedButtons"); + this.sharedButtons.Name = "sharedButtons"; + // + // CycleDlg + // + resources.ApplyResources(this, "$this"); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.mainSplitContainer); + this.Name = "CycleDlg"; + this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.CycleDlg_FormClosing); + this.Load += new System.EventHandler(this.CycleDlg_Load); + this.mainSplitContainer.Panel1.ResumeLayout(false); + this.mainSplitContainer.Panel2.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.mainSplitContainer)).EndInit(); + this.mainSplitContainer.ResumeLayout(false); + this.ResumeLayout(false); } diff --git a/TBF/Rig/TestMethods/Endurance/CycleDlg.resx b/TBF/Rig/TestMethods/Endurance/CycleDlg.resx index cd69c302b..a3fdfa228 100644 --- a/TBF/Rig/TestMethods/Endurance/CycleDlg.resx +++ b/TBF/Rig/TestMethods/Endurance/CycleDlg.resx @@ -181,7 +181,7 @@ sharedButtons - TBF.UiControls.SharedButtons, TBF, Version=2.12.404.1, Culture=neutral, PublicKeyToken=null + TBF.UI.Shared.SharedButtons, TBF, Version=3.2.1913.0, Culture=neutral, PublicKeyToken=null mainSplitContainer.Panel2 diff --git a/TBF/Rig/Various/CoverTest/CoverTestForm.cs b/TBF/Rig/Various/CoverTest/CoverTestForm.cs index 02a81ac65..95e3f25e2 100644 --- a/TBF/Rig/Various/CoverTest/CoverTestForm.cs +++ b/TBF/Rig/Various/CoverTest/CoverTestForm.cs @@ -1,5 +1,5 @@ /// -/// Copyright (c) 2017 Sensus Slovensko a.s. +/// Copyright (c) 2017-2022 Sensus Slovensko a.s. /// using System; using System.Drawing; @@ -55,20 +55,17 @@ namespace TBF.Rig.Various.CoverTest private void bypassButton_Click(object sender, EventArgs e) { - if (!(GlobalData.CurrentUser is SharedDatabase.Entities.User) || - !(GlobalData.CurrentUser as SharedDatabase.Entities.User).IsMemberOf(bypassLevel)) + if (!CurrentUser.IsMemberOf(bypassLevel)) { - if ((new SharedDatabase.Forms.LoginDlg(bypassLevel)).ShowDialog() != DialogResult.OK) + if ((new SharedDatabase.Forms.LoginDlg(bypassLevel, this)).ShowDialog() != DialogResult.OK) { return; } - else - { - if (Program.MainWnd != null) Program.MainWnd.UpdateUser(); - } + + Program.MainWnd.UpdateUser(); } - bypassLog.InfoFormat("{0} bypassed by {1}", message, GlobalData.GetCurrentUserName()); + bypassLog.InfoFormat("{0} bypassed by {1}", message, CurrentUser.UserName()); completed = true; Close(); @@ -111,5 +108,10 @@ namespace TBF.Rig.Various.CoverTest } #endregion + + private void CoverTestForm_FormClosing(object sender, FormClosingEventArgs e) + { + if (CurrentUser.Restore(this)) Program.MainWnd.UpdateUser(); + } } } diff --git a/TBF/Rig/Various/CoverTest/CoverTestForm.designer.cs b/TBF/Rig/Various/CoverTest/CoverTestForm.designer.cs index 99416f5ed..11ad435ea 100644 --- a/TBF/Rig/Various/CoverTest/CoverTestForm.designer.cs +++ b/TBF/Rig/Various/CoverTest/CoverTestForm.designer.cs @@ -68,6 +68,7 @@ namespace TBF.Rig.Various.CoverTest this.Name = "CoverTestForm"; this.Text = "Message"; this.TopMost = true; + this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.CoverTestForm_FormClosing); this.ResumeLayout(false); this.PerformLayout(); diff --git a/TBF/UI/Bench/Components/ComponentParametersDlg.cs b/TBF/UI/Bench/Components/ComponentParametersDlg.cs index d710a76ef..3a4ec2856 100644 --- a/TBF/UI/Bench/Components/ComponentParametersDlg.cs +++ b/TBF/UI/Bench/Components/ComponentParametersDlg.cs @@ -37,25 +37,31 @@ namespace TBF.UI.Bench.Components int cmpntEntityId; + ComponentParametersDlg() + { + InitializeComponent(); + } + /// /// Create a window to edit component configuration /// /// Config.Entities.Component.Id or 0 when this is a new/copied/immported component - public ComponentParametersDlg(int cmpntEntityId = 0) + public ComponentParametersDlg(Form parentForm, int cmpntEntityId = 0) + : this() { - InitializeComponent(); - this.cmpntEntityId = cmpntEntityId; - Flags = CfgUpdateFlags.None; - /// SharedDlgButtons configuration - sharedButtons.RequiredGroupMembership = new GID[] { GID.Metrologists }; + /// SharedDlgButtons configuration + sharedButtons.ParentForm = parentForm; + sharedButtons.RequiredGroupMembership = new GID[] { GID.Metrologists }; sharedButtons.MoreButtonTop = ComponentCfgCtrlHeight - 45; sharedButtons.OptionalButtons = SharedButtons.Buttons.None; - sharedButtons.Unlocked += Unlock; - sharedButtons.OKClicked += okButton_Click; - sharedButtons.CancelClicked += cancelButton_Click; - sharedButtons.MoreClicked += moreButton_Click; + sharedButtons.Unlocked += Unlock; + sharedButtons.OKClicked += okButton_Click; + sharedButtons.CancelClicked += cancelButton_Click; + sharedButtons.MoreClicked += moreButton_Click; + + Flags = CfgUpdateFlags.None; } private void ComponentCfgForm_Load(object sender, EventArgs e) diff --git a/TBF/UI/Bench/Components/ComponentsManagerDlg.cs b/TBF/UI/Bench/Components/ComponentsManagerDlg.cs index 16efe7db9..dd3e18c54 100644 --- a/TBF/UI/Bench/Components/ComponentsManagerDlg.cs +++ b/TBF/UI/Bench/Components/ComponentsManagerDlg.cs @@ -69,6 +69,7 @@ namespace TBF.UI.Bench.Components selectComponentTypeDlg = new SelectComponentClassDlg(); /// SharedDlgButtons configuration + sharedButtons.ParentForm = this; sharedButtons.RequiredGroupMembership = new GID[] { GID.Metrologists }; sharedButtons.OptionalButtons = SharedButtons.Buttons.Add | @@ -421,7 +422,7 @@ namespace TBF.UI.Bench.Components cfgControl.Config = cfg; cfgControl.Config.ItemNr = (cmpntEntities.Count > 0) ? (cmpntEntities[cmpntEntities.Count - 1].ItemNr + 1) : 1; - ComponentParametersDlg cfgForm = new ComponentParametersDlg(); + ComponentParametersDlg cfgForm = new ComponentParametersDlg(this); cfgForm.CmpntEntities = cmpntEntities; cfgForm.ComponentCfgCtrl = cfgControl; cfgForm.UnlockAfterStart = true; @@ -502,7 +503,7 @@ namespace TBF.UI.Bench.Components IComponentCfg cfg = TbfComponents.CmpntCfgFromCmpntEntity(component); if (cfg != null) { - ComponentParametersDlg cfgForm = new ComponentParametersDlg(component.Id); + ComponentParametersDlg cfgForm = new ComponentParametersDlg(this, component.Id); cfgForm.CmpntEntities = cmpntEntities; cfgForm.ComponentCfgCtrl = cfg.GetControl(cmpntEntities); cfgForm.ComponentCfgCtrl.Config = cfg; @@ -544,7 +545,7 @@ namespace TBF.UI.Bench.Components cfgControl.Config = cfg; cfgControl.Config.ItemNr = (cmpntEntities.Count > 0) ? (cmpntEntities[cmpntEntities.Count - 1].ItemNr + 1) : 1; - ComponentParametersDlg cfgForm = new ComponentParametersDlg(); + ComponentParametersDlg cfgForm = new ComponentParametersDlg(this); cfgForm.CmpntEntities = cmpntEntities; cfgForm.ComponentCfgCtrl = cfgControl; cfgForm.UnlockAfterStart = true; @@ -589,7 +590,7 @@ namespace TBF.UI.Bench.Components cfgControl.Config.Name = cfgControl.Config.Name + " imported"; cfgControl.Config.ItemNr = (cmpntEntities.Count > 0) ? (cmpntEntities[cmpntEntities.Count - 1].ItemNr + 1) : 1; - ComponentParametersDlg cfgForm = new ComponentParametersDlg(); + ComponentParametersDlg cfgForm = new ComponentParametersDlg(this); cfgForm.CmpntEntities = cmpntEntities; cfgForm.ComponentCfgCtrl = cfgControl; cfgForm.UnlockAfterStart = true; @@ -698,6 +699,8 @@ namespace TBF.UI.Bench.Components SaveDBChanges(session); } } + + if (CurrentUser.Restore(this)) Program.MainWnd.UpdateUser(); } diff --git a/TBF/UI/Bench/EditSchDrawing/EditSchDrawingDlg.Designer.cs b/TBF/UI/Bench/EditSchDrawing/EditSchDrawingDlg.Designer.cs index 708a717f4..b2ce9e3cf 100644 --- a/TBF/UI/Bench/EditSchDrawing/EditSchDrawingDlg.Designer.cs +++ b/TBF/UI/Bench/EditSchDrawing/EditSchDrawingDlg.Designer.cs @@ -33,6 +33,7 @@ this.splitContainer2 = new System.Windows.Forms.SplitContainer(); this.sharedButtons = new TBF.UI.Shared.SharedButtons(); this.splitContainer3 = new System.Windows.Forms.SplitContainer(); + this.isLargeStepLabel = new System.Windows.Forms.Label(); this.radioButton9 = new System.Windows.Forms.RadioButton(); this.radioButton8 = new System.Windows.Forms.RadioButton(); this.deletePipeButton = new System.Windows.Forms.Button(); @@ -52,7 +53,6 @@ this.downButton = new System.Windows.Forms.Button(); this.upButton = new System.Windows.Forms.Button(); this.itemsListBox = new System.Windows.Forms.ListBox(); - this.isLargeStepLabel = new System.Windows.Forms.Label(); ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit(); this.splitContainer1.Panel1.SuspendLayout(); this.splitContainer1.Panel2.SuspendLayout(); @@ -90,11 +90,13 @@ // this.drawingCtrl.AltStrings = null; this.drawingCtrl.BenchControlMode = false; + this.drawingCtrl.CustomBitmaps = null; this.drawingCtrl.Dock = System.Windows.Forms.DockStyle.Fill; this.drawingCtrl.EditMode = false; this.drawingCtrl.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(238))); this.drawingCtrl.Location = new System.Drawing.Point(0, 0); this.drawingCtrl.MeasuredValues = null; + this.drawingCtrl.MsrmntAvailableFlags = null; this.drawingCtrl.Name = "drawingCtrl"; this.drawingCtrl.PipesL = new string[0]; this.drawingCtrl.PipesM = new string[0]; @@ -175,6 +177,19 @@ this.splitContainer3.SplitterDistance = 138; this.splitContainer3.TabIndex = 0; // + // isLargeStepLabel + // + this.isLargeStepLabel.AutoSize = true; + this.isLargeStepLabel.BackColor = System.Drawing.Color.DarkOrchid; + this.isLargeStepLabel.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(238))); + this.isLargeStepLabel.ForeColor = System.Drawing.Color.Snow; + this.isLargeStepLabel.Location = new System.Drawing.Point(33, 29); + this.isLargeStepLabel.Name = "isLargeStepLabel"; + this.isLargeStepLabel.Size = new System.Drawing.Size(14, 13); + this.isLargeStepLabel.TabIndex = 17; + this.isLargeStepLabel.Text = "L"; + this.isLargeStepLabel.Visible = false; + // // radioButton9 // this.radioButton9.AutoSize = true; @@ -396,19 +411,6 @@ this.itemsListBox.TabIndex = 0; this.itemsListBox.SelectedIndexChanged += new System.EventHandler(this.itemsListBox_SelectedIndexChanged); // - // isLargeStepLabel - // - this.isLargeStepLabel.AutoSize = true; - this.isLargeStepLabel.BackColor = System.Drawing.Color.DarkOrchid; - this.isLargeStepLabel.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(238))); - this.isLargeStepLabel.ForeColor = System.Drawing.Color.Snow; - this.isLargeStepLabel.Location = new System.Drawing.Point(33, 29); - this.isLargeStepLabel.Name = "isLargeStepLabel"; - this.isLargeStepLabel.Size = new System.Drawing.Size(14, 13); - this.isLargeStepLabel.TabIndex = 17; - this.isLargeStepLabel.Text = "L"; - this.isLargeStepLabel.Visible = false; - // // EditSchDrawingDlg // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); @@ -419,6 +421,7 @@ this.Name = "EditSchDrawingDlg"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; this.Text = "Schematic drawing"; + this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.EditSchDrawingDlg_FormClosing); this.Load += new System.EventHandler(this.EditSchDrawingDlg_Load); this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.drawingCtrl_MouseDown); this.splitContainer1.Panel1.ResumeLayout(false); diff --git a/TBF/UI/Bench/EditSchDrawing/EditSchDrawingDlg.cs b/TBF/UI/Bench/EditSchDrawing/EditSchDrawingDlg.cs index b71ffe113..fb0216730 100644 --- a/TBF/UI/Bench/EditSchDrawing/EditSchDrawingDlg.cs +++ b/TBF/UI/Bench/EditSchDrawing/EditSchDrawingDlg.cs @@ -49,12 +49,16 @@ namespace TBF.UI.Bench.EditSchDrawing InitializeComponent(); Controls.Add(new TextBox() { Visible = false }); selectComponentTypeDlg = new SelectComponentClassDlg("Various.Drawing."); + + /// SharedDlgButtons configuration + sharedButtons.ParentForm = this; sharedButtons.RequiredGroupMembership = new Common.GID[] { Common.GID.Administrators }; sharedButtons.OptionalButtons = SharedButtons.Buttons.Add; sharedButtons.Unlocked += Unlocked; sharedButtons.OKClicked += okButton_Click; sharedButtons.CancelClicked += cancelButton_Click; sharedButtons.AddClicked += addButton_Click; + radioButton1.Checked = true; /// Auto selection mode UpdateTitle(); } @@ -264,7 +268,7 @@ namespace TBF.UI.Bench.EditSchDrawing cfgControl.Config = cfg; cfgControl.Config.ItemNr = (cmpntEntities.Count > 0) ? (cmpntEntities[cmpntEntities.Count - 1].ItemNr + 1) : 1; - ComponentParametersDlg cfgForm = new ComponentParametersDlg(); + ComponentParametersDlg cfgForm = new ComponentParametersDlg(this); cfgForm.CmpntEntities = cmpntEntities; cfgForm.ComponentCfgCtrl = cfgControl; cfgForm.UnlockAfterStart = true; @@ -1003,5 +1007,10 @@ namespace TBF.UI.Bench.EditSchDrawing } } } + + private void EditSchDrawingDlg_FormClosing(object sender, FormClosingEventArgs e) + { + if (CurrentUser.Restore(this)) Program.MainWnd.UpdateUser(); + } } } diff --git a/TBF/UI/Bench/Metrology/MetrologyDlg.Designer.cs b/TBF/UI/Bench/Metrology/MetrologyDlg.Designer.cs index b4cc7be62..03a1aa15b 100644 --- a/TBF/UI/Bench/Metrology/MetrologyDlg.Designer.cs +++ b/TBF/UI/Bench/Metrology/MetrologyDlg.Designer.cs @@ -31,66 +31,67 @@ namespace TBF.UI.Bench.Metrology /// private void InitializeComponent() { - this.splitContainer = new System.Windows.Forms.SplitContainer(); - this.metrologyTabControl = new System.Windows.Forms.TabControl(); - this.sharedButtons = new TBF.UI.Shared.SharedButtons(); - ((System.ComponentModel.ISupportInitialize)(this.splitContainer)).BeginInit(); - this.splitContainer.Panel1.SuspendLayout(); - this.splitContainer.Panel2.SuspendLayout(); - this.splitContainer.SuspendLayout(); - this.SuspendLayout(); - // - // splitContainer - // - this.splitContainer.Dock = System.Windows.Forms.DockStyle.Fill; - this.splitContainer.FixedPanel = System.Windows.Forms.FixedPanel.Panel2; - this.splitContainer.Location = new System.Drawing.Point(0, 0); - this.splitContainer.Name = "splitContainer"; - // - // splitContainer.Panel1 - // - this.splitContainer.Panel1.Controls.Add(this.metrologyTabControl); - // - // splitContainer.Panel2 - // - this.splitContainer.Panel2.Controls.Add(this.sharedButtons); - this.splitContainer.Size = new System.Drawing.Size(965, 344); - this.splitContainer.SplitterDistance = 863; - this.splitContainer.TabIndex = 0; - // - // metrologyTabControl - // - this.metrologyTabControl.Dock = System.Windows.Forms.DockStyle.Fill; - this.metrologyTabControl.ItemSize = new System.Drawing.Size(60, 30); - this.metrologyTabControl.Location = new System.Drawing.Point(0, 0); - this.metrologyTabControl.Name = "metrologyTabControl"; - this.metrologyTabControl.SelectedIndex = 0; - this.metrologyTabControl.Size = new System.Drawing.Size(863, 344); - this.metrologyTabControl.TabIndex = 0; - this.metrologyTabControl.SelectedIndexChanged += new System.EventHandler(this.metrologyTabControl_SelectedIndexChanged); - // - // sharedButtons - // - this.sharedButtons.Location = new System.Drawing.Point(-2, 0); - this.sharedButtons.Name = "sharedButtons"; - this.sharedButtons.Size = new System.Drawing.Size(100, 400); - this.sharedButtons.TabIndex = 0; - // - // MetrologyDlg - // - this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(965, 344); - this.Controls.Add(this.splitContainer); - this.Name = "MetrologyDlg"; - this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; - this.Text = "Metrology"; - this.Load += new System.EventHandler(this.MetrologyDlg_Load); - this.splitContainer.Panel1.ResumeLayout(false); - this.splitContainer.Panel2.ResumeLayout(false); - ((System.ComponentModel.ISupportInitialize)(this.splitContainer)).EndInit(); - this.splitContainer.ResumeLayout(false); - this.ResumeLayout(false); + this.splitContainer = new System.Windows.Forms.SplitContainer(); + this.metrologyTabControl = new System.Windows.Forms.TabControl(); + this.sharedButtons = new TBF.UI.Shared.SharedButtons(); + ((System.ComponentModel.ISupportInitialize)(this.splitContainer)).BeginInit(); + this.splitContainer.Panel1.SuspendLayout(); + this.splitContainer.Panel2.SuspendLayout(); + this.splitContainer.SuspendLayout(); + this.SuspendLayout(); + // + // splitContainer + // + this.splitContainer.Dock = System.Windows.Forms.DockStyle.Fill; + this.splitContainer.FixedPanel = System.Windows.Forms.FixedPanel.Panel2; + this.splitContainer.Location = new System.Drawing.Point(0, 0); + this.splitContainer.Name = "splitContainer"; + // + // splitContainer.Panel1 + // + this.splitContainer.Panel1.Controls.Add(this.metrologyTabControl); + // + // splitContainer.Panel2 + // + this.splitContainer.Panel2.Controls.Add(this.sharedButtons); + this.splitContainer.Size = new System.Drawing.Size(965, 344); + this.splitContainer.SplitterDistance = 863; + this.splitContainer.TabIndex = 0; + // + // metrologyTabControl + // + this.metrologyTabControl.Dock = System.Windows.Forms.DockStyle.Fill; + this.metrologyTabControl.ItemSize = new System.Drawing.Size(60, 30); + this.metrologyTabControl.Location = new System.Drawing.Point(0, 0); + this.metrologyTabControl.Name = "metrologyTabControl"; + this.metrologyTabControl.SelectedIndex = 0; + this.metrologyTabControl.Size = new System.Drawing.Size(863, 344); + this.metrologyTabControl.TabIndex = 0; + this.metrologyTabControl.SelectedIndexChanged += new System.EventHandler(this.metrologyTabControl_SelectedIndexChanged); + // + // sharedButtons + // + this.sharedButtons.Location = new System.Drawing.Point(-2, 0); + this.sharedButtons.Name = "sharedButtons"; + this.sharedButtons.Size = new System.Drawing.Size(100, 400); + this.sharedButtons.TabIndex = 0; + // + // MetrologyDlg + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(965, 344); + this.Controls.Add(this.splitContainer); + this.Name = "MetrologyDlg"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; + this.Text = "Metrology"; + this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.MetrologyDlg_FormClosing); + this.Load += new System.EventHandler(this.MetrologyDlg_Load); + this.splitContainer.Panel1.ResumeLayout(false); + this.splitContainer.Panel2.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.splitContainer)).EndInit(); + this.splitContainer.ResumeLayout(false); + this.ResumeLayout(false); } diff --git a/TBF/UI/Bench/Metrology/MetrologyDlg.cs b/TBF/UI/Bench/Metrology/MetrologyDlg.cs index 2dc036724..fe1ffb022 100644 --- a/TBF/UI/Bench/Metrology/MetrologyDlg.cs +++ b/TBF/UI/Bench/Metrology/MetrologyDlg.cs @@ -1,5 +1,5 @@ /// -/// Copyright (c) 2013-2019 Sensus Slovensko a.s. +/// Copyright (c) 2013-2022 Sensus Slovensko a.s. /// using System; using System.Collections.Generic; @@ -27,6 +27,7 @@ namespace TBF.UI.Bench.Metrology InitializeComponent(); /// SharedDlgButtons configuration + sharedButtons.ParentForm = this; sharedButtons.RequiredGroupMembership = new Common.GID[] { Common.GID.Metrologists, Common.GID.MetrologicalAuthority }; sharedButtons.OptionalButtons = SharedButtons.Buttons.Add | SharedButtons.Buttons.Remove; sharedButtons.Unlocked += unlockButton_Click; @@ -342,5 +343,10 @@ namespace TBF.UI.Bench.Metrology { sharedButtons.DisableButtons(SharedButtons.Buttons.Remove); } + + private void MetrologyDlg_FormClosing(object sender, FormClosingEventArgs e) + { + if (CurrentUser.Restore(this)) Program.MainWnd.UpdateUser(); + } } } diff --git a/TBF/UI/Bench/Paths/PathsDlg.Designer.cs b/TBF/UI/Bench/Paths/PathsDlg.Designer.cs index 6b862410f..f59ad339a 100644 --- a/TBF/UI/Bench/Paths/PathsDlg.Designer.cs +++ b/TBF/UI/Bench/Paths/PathsDlg.Designer.cs @@ -162,6 +162,7 @@ namespace TBF.UI.Bench.Paths this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.Controls.Add(this.splitContainer); this.Name = "PathsDlg"; + this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.PathsDlg_FormClosing); this.Load += new System.EventHandler(this.PathsDlg_Load); this.splitContainer.Panel1.ResumeLayout(false); this.splitContainer.Panel2.ResumeLayout(false); diff --git a/TBF/UI/Bench/Paths/PathsDlg.cs b/TBF/UI/Bench/Paths/PathsDlg.cs index 471efbc4d..524ab8f8d 100644 --- a/TBF/UI/Bench/Paths/PathsDlg.cs +++ b/TBF/UI/Bench/Paths/PathsDlg.cs @@ -1,5 +1,5 @@ /// -/// Copyright (c) 2013-2017 Sensus Metering Systems +/// Copyright (c) 2013-2022 Sensus Slovensko a.s. /// using System; using System.Collections.Generic; @@ -51,7 +51,8 @@ namespace TBF.UI.Bench.Paths InitializeComponent(); /// SharedDlgButtons configuration - sharedButtons.RequiredGroupMembership = new Common.GID[] { Common.GID.Metrologists }; + sharedButtons.ParentForm = this; + sharedButtons.RequiredGroupMembership = new GID[] { GID.Metrologists }; sharedButtons.OptionalButtons = SharedButtons.Buttons.Add | SharedButtons.Buttons.Remove | SharedButtons.Buttons.Up | SharedButtons.Buttons.Down; sharedButtons.Unlocked += Unlocked; @@ -350,5 +351,10 @@ namespace TBF.UI.Bench.Paths sharedButtons.DisableButtons(SharedButtons.Buttons.Remove | SharedButtons.Buttons.Up | SharedButtons.Buttons.Down); } } + + private void PathsDlg_FormClosing(object sender, FormClosingEventArgs e) + { + if (CurrentUser.Restore(this)) Program.MainWnd.UpdateUser(); + } } } diff --git a/TBF/UI/Bench/Paths/PathsDlg.resx b/TBF/UI/Bench/Paths/PathsDlg.resx index 5aaef6997..a28ee6006 100644 --- a/TBF/UI/Bench/Paths/PathsDlg.resx +++ b/TBF/UI/Bench/Paths/PathsDlg.resx @@ -145,7 +145,7 @@ pathsFeedingCtrl - TBF.UiControls.PathsFeedingCtrl, TBF, Version=2.8.315.1, Culture=neutral, PublicKeyToken=null + TBF.UI.Bench.Paths.PathsFeedingCtrl, TBF, Version=3.2.1913.0, Culture=neutral, PublicKeyToken=null feedingTabPage @@ -196,7 +196,7 @@ pathsBenchCtrl - TBF.UiControls.PathsBenchCtrl, TBF, Version=2.8.315.1, Culture=neutral, PublicKeyToken=null + TBF.UI.Bench.Paths.PathsBenchCtrl, TBF, Version=3.2.1913.0, Culture=neutral, PublicKeyToken=null benchTabPage @@ -247,7 +247,7 @@ pathsOutputCtrl - TBF.UiControls.PathsOutputCtrl, TBF, Version=2.8.315.1, Culture=neutral, PublicKeyToken=null + TBF.UI.Bench.Paths.PathsOutputCtrl, TBF, Version=3.2.1913.0, Culture=neutral, PublicKeyToken=null outputTabPage @@ -298,7 +298,7 @@ pathsMetersCtrl - TBF.UiControls.PathsMetersCtrl, TBF, Version=2.8.315.1, Culture=neutral, PublicKeyToken=null + TBF.UI.Bench.Paths.PathsMetersCtrl, TBF, Version=3.2.1913.0, Culture=neutral, PublicKeyToken=null metersTabPage @@ -330,54 +330,6 @@ 3 - - Fill - - - 0, 0 - - - 831, 277 - - - 0 - - - pathsHeatMetersCtrl - - - TBF.UiControls.PathsHeatMetersCtrl, TBF, Version=2.8.315.1, Culture=neutral, PublicKeyToken=null - - - heatMetersTabPage - - - 0 - - - 4, 34 - - - 831, 277 - - - 4 - - - Heat meter sensors - - - heatMetersTabPage - - - System.Windows.Forms.TabPage, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - pathsTabControl - - - 4 - Fill @@ -430,7 +382,7 @@ sharedButtons - TBF.UiControls.SharedButtons, TBF, Version=2.8.315.1, Culture=neutral, PublicKeyToken=null + TBF.UI.Shared.SharedButtons, TBF, Version=3.2.1913.0, Culture=neutral, PublicKeyToken=null splitContainer.Panel2 diff --git a/TBF/UI/Bench/TestProfiles/TestProfileDlg.cs b/TBF/UI/Bench/TestProfiles/TestProfileDlg.cs index 206cc7326..6e4d6c20d 100644 --- a/TBF/UI/Bench/TestProfiles/TestProfileDlg.cs +++ b/TBF/UI/Bench/TestProfiles/TestProfileDlg.cs @@ -36,28 +36,40 @@ namespace TBF.UI.Bench.TestProfiles bool unlocked; - public TestProfileDlg() + TestProfileDlg() { - /// Detect display setting: 100% = 96dpi, 125% = 120dpi, 150% = 144dpi. + InitializeComponent(); + + /// Detect display setting: 100% = 96dpi, 125% = 120dpi, 150% = 144dpi. Dpi = (int)this.CreateGraphics().DpiX; openUnlocked = false; + } - InitializeComponent(); + public TestProfileDlg(Profile profile, IList usedNames, bool openUnlocked, Form parentForm) + : this() + { + if (profile == null) throw new ArgumentNullException("profile"); + + LoadedProfile = profile; + this.usedNames = usedNames; + this.openUnlocked = openUnlocked; /// SharedDlgButtons configuration + sharedButtons.ParentForm = parentForm; sharedButtons.RequiredGroupMembership = new GID[] { GID.MetrologicalAuthority }; - - sharedButtons.OptionalButtons = SharedButtons.Buttons.Add | SharedButtons.Buttons.Remove | - SharedButtons.Buttons.Up | SharedButtons.Buttons.Down; + sharedButtons.OptionalButtons = SharedButtons.Buttons.Add | + SharedButtons.Buttons.Remove | + SharedButtons.Buttons.Up | + SharedButtons.Buttons.Down; 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.OKClicked += okButton_Click; + sharedButtons.CancelClicked += cancelButton_Click; + sharedButtons.AddClicked += addButton_Click; + sharedButtons.RemoveClicked += removeButton_Click; + sharedButtons.UpClicked += upButton_Click; + sharedButtons.DownClicked += downButton_Click; - /// ListViewEx-es configuration + /// ListViewEx-es configuration metrologyListViewEx.SubItemClicked += new SubItemEventHandler(metrologyListViewEx_SubItemClicked); metrologyListViewEx.SubItemRightClicked += new SubItemEventHandler(metrologyListViewEx_SubItemRightClicked); metrologyListViewEx.SubItemEndEditing += new SubItemEndEditingEventHandler(metrologyListViewEx_SubItemEndEditing); @@ -71,19 +83,7 @@ namespace TBF.UI.Bench.TestProfiles errorFlags2ListViewEx.SubItemEndEditing += new SubItemEndEditingEventHandler(errorFlags2ListViewEx_SubItemEndEditing); SelectedTestIx = -1; - } - - public TestProfileDlg(Config.Entities.Profile profile, IList usedNames, bool openUnlocked = false) - : this() - { - if (profile == null) throw new ArgumentNullException("profile"); - - LoadedProfile = profile; - this.usedNames = usedNames; - this.openUnlocked = openUnlocked; - - sharedButtons.RequiredGroupMembership = new GID[] { GID.MetrologicalAuthority }; - } + } private void TestProfileDlg_Load(object sender, EventArgs e) { diff --git a/TBF/UI/Bench/TestProfiles/TestProfileDlg.resx b/TBF/UI/Bench/TestProfiles/TestProfileDlg.resx index 97a2dab88..159701f68 100644 --- a/TBF/UI/Bench/TestProfiles/TestProfileDlg.resx +++ b/TBF/UI/Bench/TestProfiles/TestProfileDlg.resx @@ -745,7 +745,7 @@ metrologyListViewEx - Common.Forms.ListViewEx, Results, Version=2.24.1369.0, Culture=neutral, PublicKeyToken=null + Common.Forms.ListViewEx, Common, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null metrologyTabPage @@ -796,7 +796,7 @@ errorFlagsListViewEx - Common.Forms.ListViewEx, Results, Version=2.24.1369.0, Culture=neutral, PublicKeyToken=null + Common.Forms.ListViewEx, Common, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null errorFlagsTabPage @@ -844,7 +844,7 @@ errorFlags2ListViewEx - Common.Forms.ListViewEx, Results, Version=2.24.1369.0, Culture=neutral, PublicKeyToken=null + Common.Forms.ListViewEx, Common, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null errorFlags2TabPage @@ -928,7 +928,7 @@ sharedButtons - TBF.UI.Shared.SharedButtons, TBF, Version=2.24.1372.0, Culture=neutral, PublicKeyToken=null + TBF.UI.Shared.SharedButtons, TBF, Version=3.2.1913.0, Culture=neutral, PublicKeyToken=null mainSplitContainer.Panel2 diff --git a/TBF/UI/Bench/TestProfiles/TestProfilesCtrl.cs b/TBF/UI/Bench/TestProfiles/TestProfilesCtrl.cs index f9da8deaf..c30ce460a 100644 --- a/TBF/UI/Bench/TestProfiles/TestProfilesCtrl.cs +++ b/TBF/UI/Bench/TestProfiles/TestProfilesCtrl.cs @@ -212,10 +212,10 @@ namespace TBF.UI.Bench.TestProfiles } Profile newProfile = new Profile(newName, MyItems.Count); - newProfile.CreationUser = GlobalData.CurrentUser.UserName; + newProfile.CreationUser = CurrentUser.UserName(); newProfile.CreationTime = DateTime.Now; - if (new TestProfileDlg(newProfile, GetUsedNames(false), true).ShowDialog() == DialogResult.OK) + if (new TestProfileDlg(newProfile, GetUsedNames(false), true, parent).ShowDialog() == DialogResult.OK) { /// TODO: Make name uniqueness test parent.Unlock(); @@ -224,7 +224,7 @@ namespace TBF.UI.Bench.TestProfiles { try { - newProfile.LastChgUser = GlobalData.GetCurrentUserName(); + newProfile.LastChgUser = CurrentUser.UserName(); newProfile.LastChgTime = DateTime.Now; base.AddOne(newProfile); @@ -295,7 +295,7 @@ namespace TBF.UI.Bench.TestProfiles IList usedNames = GetUsedNames(false); usedNames.Remove(editedProfile.Name.ToLower()); /// Allow original procedure name /// - if (new TestProfileDlg(editedProfile, usedNames).ShowDialog() == DialogResult.OK) + if (new TestProfileDlg(editedProfile, usedNames, false, parent).ShowDialog() == DialogResult.OK) { parent.Unlock(); @@ -303,7 +303,7 @@ namespace TBF.UI.Bench.TestProfiles { try { - editedProfile.LastChgUser = GlobalData.GetCurrentUserName(); + editedProfile.LastChgUser = CurrentUser.UserName(); editedProfile.LastChgTime = DateTime.Now; session.SaveOrUpdate(editedProfile); @@ -337,17 +337,17 @@ namespace TBF.UI.Bench.TestProfiles newProfile.Name = selectedProfile.Name + Strings.New_name_copy; newProfile.ItemNr = MyItems.Count; - newProfile.CreationUser = GlobalData.GetCurrentUserName(); + newProfile.CreationUser = CurrentUser.UserName(); newProfile.CreationTime = DateTime.Now; - if ((new TestProfileDlg(newProfile, GetUsedNames(false), true)).ShowDialog() == DialogResult.OK) + if ((new TestProfileDlg(newProfile, GetUsedNames(false), true, parent)).ShowDialog() == DialogResult.OK) { /// TODO: Make name uniqueness test parent.Unlock(); using (var transaction = session.BeginTransaction()) { - newProfile.LastChgUser = GlobalData.GetCurrentUserName(); + newProfile.LastChgUser = CurrentUser.UserName(); newProfile.LastChgTime = DateTime.Now; base.AddOne(newProfile); @@ -386,17 +386,17 @@ namespace TBF.UI.Bench.TestProfiles newProfile.Name = newProfile.Name + " imported"; newProfile.ItemNr = MyItems.Count; - newProfile.CreationUser = GlobalData.GetCurrentUserName(); + newProfile.CreationUser = CurrentUser.UserName(); newProfile.CreationTime = DateTime.Now; - if ((new TestProfileDlg(newProfile, GetUsedNames(false), true)).ShowDialog() == DialogResult.OK) + if ((new TestProfileDlg(newProfile, GetUsedNames(false), true, parent)).ShowDialog() == DialogResult.OK) { /// TODO: Make name uniqueness test parent.Unlock(); using (var transaction = session.BeginTransaction()) { - newProfile.LastChgUser = GlobalData.GetCurrentUserName(); + newProfile.LastChgUser = CurrentUser.UserName(); newProfile.LastChgTime = DateTime.Now; base.AddOne(newProfile); diff --git a/TBF/UI/Bench/TestProfiles/TestProfilesDlg.cs b/TBF/UI/Bench/TestProfiles/TestProfilesDlg.cs index 79312c13b..72e02656b 100644 --- a/TBF/UI/Bench/TestProfiles/TestProfilesDlg.cs +++ b/TBF/UI/Bench/TestProfiles/TestProfilesDlg.cs @@ -5,6 +5,7 @@ using System; using System.Collections.Generic; using System.Windows.Forms; using log4net; +using Common; using TBF.Resources; using TBF.UI.Shared; @@ -25,7 +26,8 @@ namespace TBF.UI.Bench.TestProfiles InitializeComponent(); /// SharedDlgButtons configuration - sharedButtons.RequiredGroupMembership = new Common.GID[] { Common.GID.MetrologicalAuthority }; + sharedButtons.ParentForm = this; + sharedButtons.RequiredGroupMembership = new GID[] { GID.MetrologicalAuthority }; sharedButtons.OptionalButtons = SharedButtons.Buttons.Add | SharedButtons.Buttons.Remove | SharedButtons.Buttons.Up | SharedButtons.Buttons.Down | @@ -217,5 +219,10 @@ namespace TBF.UI.Bench.TestProfiles sharedButtons.DisableButtons(SharedButtons.Buttons.Remove | SharedButtons.Buttons.Up | SharedButtons.Buttons.Down); } } + + private void TestProfilesDlg_FormClosing(object sender, FormClosingEventArgs e) + { + if (CurrentUser.Restore(this)) Program.MainWnd.UpdateUser(); + } } } diff --git a/TBF/UI/Bench/TestProfiles/TestProfilesDlg.designer.cs b/TBF/UI/Bench/TestProfiles/TestProfilesDlg.designer.cs index ed349e73e..ad56aad2b 100644 --- a/TBF/UI/Bench/TestProfiles/TestProfilesDlg.designer.cs +++ b/TBF/UI/Bench/TestProfiles/TestProfilesDlg.designer.cs @@ -88,6 +88,7 @@ namespace TBF.UI.Bench.TestProfiles this.Name = "TestProfilesDlg"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; this.Text = "TestProfilesDlg"; + this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.TestProfilesDlg_FormClosing); this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.ProceduresDlg_FormClosed); this.Load += new System.EventHandler(this.TestProfilesDlg_Load); this.splitContainer.Panel1.ResumeLayout(false); diff --git a/TBF/UI/Bench/Transitions/TransitionsDlg.Designer.cs b/TBF/UI/Bench/Transitions/TransitionsDlg.Designer.cs index 8bd3acd5d..e837f3d73 100644 --- a/TBF/UI/Bench/Transitions/TransitionsDlg.Designer.cs +++ b/TBF/UI/Bench/Transitions/TransitionsDlg.Designer.cs @@ -31,54 +31,55 @@ namespace TBF.UI.Bench.Transitions /// private void InitializeComponent() { - System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(TransitionsDlg)); - this.mainSplitContainer = new System.Windows.Forms.SplitContainer(); - this.tabControl = new System.Windows.Forms.TabControl(); - this.sharedButtons = new TBF.UI.Shared.SharedButtons(); - ((System.ComponentModel.ISupportInitialize)(this.mainSplitContainer)).BeginInit(); - this.mainSplitContainer.Panel1.SuspendLayout(); - this.mainSplitContainer.Panel2.SuspendLayout(); - this.mainSplitContainer.SuspendLayout(); - this.SuspendLayout(); - // - // mainSplitContainer - // - resources.ApplyResources(this.mainSplitContainer, "mainSplitContainer"); - this.mainSplitContainer.FixedPanel = System.Windows.Forms.FixedPanel.Panel2; - this.mainSplitContainer.Name = "mainSplitContainer"; - // - // mainSplitContainer.Panel1 - // - this.mainSplitContainer.Panel1.Controls.Add(this.tabControl); - // - // mainSplitContainer.Panel2 - // - this.mainSplitContainer.Panel2.Controls.Add(this.sharedButtons); - // - // tabControl - // - resources.ApplyResources(this.tabControl, "tabControl"); - this.tabControl.Name = "tabControl"; - this.tabControl.SelectedIndex = 0; - this.tabControl.SelectedIndexChanged += new System.EventHandler(this.tabControl_SelectedIndexChanged); - // - // sharedButtons - // - resources.ApplyResources(this.sharedButtons, "sharedButtons"); - this.sharedButtons.Name = "sharedButtons"; - // - // TransitionsDlg - // - resources.ApplyResources(this, "$this"); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.Controls.Add(this.mainSplitContainer); - this.Name = "TransitionsDlg"; - this.Load += new System.EventHandler(this.TransitionsDlg_Load); - this.mainSplitContainer.Panel1.ResumeLayout(false); - this.mainSplitContainer.Panel2.ResumeLayout(false); - ((System.ComponentModel.ISupportInitialize)(this.mainSplitContainer)).EndInit(); - this.mainSplitContainer.ResumeLayout(false); - this.ResumeLayout(false); + System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(TransitionsDlg)); + this.mainSplitContainer = new System.Windows.Forms.SplitContainer(); + this.tabControl = new System.Windows.Forms.TabControl(); + this.sharedButtons = new TBF.UI.Shared.SharedButtons(); + ((System.ComponentModel.ISupportInitialize)(this.mainSplitContainer)).BeginInit(); + this.mainSplitContainer.Panel1.SuspendLayout(); + this.mainSplitContainer.Panel2.SuspendLayout(); + this.mainSplitContainer.SuspendLayout(); + this.SuspendLayout(); + // + // mainSplitContainer + // + resources.ApplyResources(this.mainSplitContainer, "mainSplitContainer"); + this.mainSplitContainer.FixedPanel = System.Windows.Forms.FixedPanel.Panel2; + this.mainSplitContainer.Name = "mainSplitContainer"; + // + // mainSplitContainer.Panel1 + // + this.mainSplitContainer.Panel1.Controls.Add(this.tabControl); + // + // mainSplitContainer.Panel2 + // + this.mainSplitContainer.Panel2.Controls.Add(this.sharedButtons); + // + // tabControl + // + resources.ApplyResources(this.tabControl, "tabControl"); + this.tabControl.Name = "tabControl"; + this.tabControl.SelectedIndex = 0; + this.tabControl.SelectedIndexChanged += new System.EventHandler(this.tabControl_SelectedIndexChanged); + // + // sharedButtons + // + resources.ApplyResources(this.sharedButtons, "sharedButtons"); + this.sharedButtons.Name = "sharedButtons"; + // + // TransitionsDlg + // + resources.ApplyResources(this, "$this"); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.mainSplitContainer); + this.Name = "TransitionsDlg"; + this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.TransitionsDlg_FormClosing); + this.Load += new System.EventHandler(this.TransitionsDlg_Load); + this.mainSplitContainer.Panel1.ResumeLayout(false); + this.mainSplitContainer.Panel2.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.mainSplitContainer)).EndInit(); + this.mainSplitContainer.ResumeLayout(false); + this.ResumeLayout(false); } diff --git a/TBF/UI/Bench/Transitions/TransitionsDlg.cs b/TBF/UI/Bench/Transitions/TransitionsDlg.cs index 686c3719b..bd4421c8d 100644 --- a/TBF/UI/Bench/Transitions/TransitionsDlg.cs +++ b/TBF/UI/Bench/Transitions/TransitionsDlg.cs @@ -1,5 +1,5 @@ /// -/// Copyright (c) 2013-2017 Sensus Metering Systems +/// Copyright (c) 2013-2022 Sensus Slovensko a.s. /// using System; using System.Collections.Generic; @@ -66,7 +66,8 @@ namespace TBF.UI.Bench.Transitions InitializeComponent(); /// SharedDlgButtons configuration - sharedButtons.RequiredGroupMembership = new Common.GID[] { Common.GID.Metrologists }; + sharedButtons.ParentForm = this; + sharedButtons.RequiredGroupMembership = new GID[] { GID.Metrologists }; sharedButtons.OptionalButtons = SharedButtons.Buttons.Add | SharedButtons.Buttons.Remove | SharedButtons.Buttons.Up | SharedButtons.Buttons.Down | SharedButtons.Buttons.Export | SharedButtons.Buttons.Import | @@ -703,5 +704,10 @@ namespace TBF.UI.Bench.Transitions { MessageBox.Show("Comparing sequences in not implemented yet"); } + + private void TransitionsDlg_FormClosing(object sender, FormClosingEventArgs e) + { + if (CurrentUser.Restore(this)) Program.MainWnd.UpdateUser(); + } } } diff --git a/TBF/UI/Bench/Transitions/TransitionsDlg.resx b/TBF/UI/Bench/Transitions/TransitionsDlg.resx index f2190cf21..ceeffcb23 100644 --- a/TBF/UI/Bench/Transitions/TransitionsDlg.resx +++ b/TBF/UI/Bench/Transitions/TransitionsDlg.resx @@ -181,7 +181,7 @@ sharedButtons - TBF.UiControls.SharedButtons, TBF, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null + TBF.UI.Shared.SharedButtons, TBF, Version=3.2.1913.0, Culture=neutral, PublicKeyToken=null mainSplitContainer.Panel2 @@ -231,9 +231,6 @@ 863, 366 - - NoControl - CenterParent diff --git a/TBF/UI/Bench/Uncertainties/UncertaintiesDlg.cs b/TBF/UI/Bench/Uncertainties/UncertaintiesDlg.cs index b99dd2649..5a10877d3 100644 --- a/TBF/UI/Bench/Uncertainties/UncertaintiesDlg.cs +++ b/TBF/UI/Bench/Uncertainties/UncertaintiesDlg.cs @@ -27,6 +27,7 @@ namespace TBF.UI.Bench.Uncertainties InitializeComponent(); /// SharedDlgButtons configuration + sharedButtons.ParentForm = this; #if KEMPNO_50 sharedButtons.RequiredGroupMembership = new Common.GID[] { Common.GID.MetrologicalAuthority }; #else @@ -304,5 +305,10 @@ namespace TBF.UI.Bench.Uncertainties { sharedButtons.DisableButtons(SharedButtons.Buttons.Remove); } + + private void UncertaintiesDlg_FormClosing(object sender, FormClosingEventArgs e) + { + if (CurrentUser.Restore(this)) Program.MainWnd.UpdateUser(); + } } } diff --git a/TBF/UI/Bench/Uncertainties/UncertaintiesDlg.designer.cs b/TBF/UI/Bench/Uncertainties/UncertaintiesDlg.designer.cs index 5271641a5..0d94ae562 100644 --- a/TBF/UI/Bench/Uncertainties/UncertaintiesDlg.designer.cs +++ b/TBF/UI/Bench/Uncertainties/UncertaintiesDlg.designer.cs @@ -85,6 +85,7 @@ namespace TBF.UI.Bench.Uncertainties this.Name = "UncertaintiesDlg"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; this.Text = "Uncertainty"; + this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.UncertaintiesDlg_FormClosing); this.Load += new System.EventHandler(this.UncertaintiesDlg_Load); this.splitContainer.Panel1.ResumeLayout(false); this.splitContainer.Panel2.ResumeLayout(false); diff --git a/TBF/UI/MainWnd.cs b/TBF/UI/MainWnd.cs index a7f0e67c2..469383fe7 100644 --- a/TBF/UI/MainWnd.cs +++ b/TBF/UI/MainWnd.cs @@ -1,5 +1,5 @@ /// -/// Copyright (c) 2013-2021 Sensus Slovensko a.s. +/// Copyright (c) 2013-2022 Sensus Slovensko a.s. /// using System; using System.Collections.Generic; @@ -13,6 +13,7 @@ using Common; using Config.Entities; using Dirichlet.Numerics; using SchematicDrawing; +using SharedDatabase; using TBF.Resources; using TBF.UiBridge; using TBF.UI.Shared; @@ -628,24 +629,22 @@ namespace TBF.UI public void UpdateUser() { - userInfoStatusLabel.Text = string.Format("{0}: {1}{2}, ", Strings.User, GlobalData.CurrentUser.UserName, - (GlobalData.AuthorizedAs == AuthorizedAs.PowerUser) ? "(S)" : - (GlobalData.AuthorizedAs == AuthorizedAs.LocalUser) ? "(L)" : "(R)"); + userInfoStatusLabel.Text = string.Format("{0}: {1}{2}, ", Strings.User, CurrentUser.UserName(), + (CurrentUser.AuthorizedAs == AuthorizedAs.PowerUser) ? "(S)" : + (CurrentUser.AuthorizedAs == AuthorizedAs.LocalUser) ? "(L)" : "(R)"); UpdateMenuItemsVisibility(); } void UpdateMenuItemsVisibility() { - SharedDatabase.Entities.User cu = GlobalData.CurrentUser as SharedDatabase.Entities.User; - - usersTSMenuItem.Visible = cu != null && (cu.IsMemberOf(GID.Administrators) || cu.IsMemberOf(GID.HeadOfLab)); - databaseSettingsTSMenuItem.Visible = cu != null && cu.IsMemberOf(GID.Administrators) && cu.IsPowerUser(); - upgradeTSMenuItem.Visible = cu != null && cu.IsMemberOf(GID.Administrators) && cu.IsPowerUser(); - clearCountersToolStripMenuItem.Visible = cu != null && (cu.IsMemberOf(GID.Administrators) || - cu.IsMemberOf(GID.HeadOfLab) || - cu.IsMemberOf(GID.TestingSpecialists) || - cu.IsMemberOf(GID.Metrologists)); + usersTSMenuItem.Visible = CurrentUser.IsMemberOf(GID.Administrators) || CurrentUser.IsMemberOf(GID.HeadOfLab); + databaseSettingsTSMenuItem.Visible = CurrentUser.IsMemberOf(GID.Administrators) && CurrentUser.IsPowerUser(); + upgradeTSMenuItem.Visible = CurrentUser.IsMemberOf(GID.Administrators) && CurrentUser.IsPowerUser(); + clearCountersToolStripMenuItem.Visible = CurrentUser.IsMemberOf(GID.Administrators) || + CurrentUser.IsMemberOf(GID.HeadOfLab) || + CurrentUser.IsMemberOf(GID.TestingSpecialists) || + CurrentUser.IsMemberOf(GID.Metrologists); } public void UpdateStatusP(string statusPStr) @@ -714,7 +713,7 @@ namespace TBF.UI } private void backUpConfigTSMItem_Click(object s, EventArgs e) { BackupConfiguration(); } private void backUpResultsTSMItem_Click(object s, EventArgs e) { BackupResults(); } - private void passwdTSMItem_Click(object s, EventArgs e) { new SharedDatabase.Forms.PasswordChangeDlg(GlobalData.GetCurrentUserName()).ShowDialog(); } + private void passwdTSMItem_Click(object s, EventArgs e) { new SharedDatabase.Forms.PasswordChangeDlg(CurrentUser.UserName()).ShowDialog(); } private void aboutTSMItem_Click(object s, EventArgs e) { new TBF.UI.Help.AboutDlg().ShowDialog(); } /// @@ -1107,7 +1106,7 @@ namespace TBF.UI GID[] reqGrpMembership = null; #endif - if (new SharedDatabase.Forms.LoginDlg(reqGrpMembership).ShowDialog() == DialogResult.OK) + if (new SharedDatabase.Forms.LoginDlg(reqGrpMembership, this).ShowDialog() == DialogResult.OK) { UpdateUser(); } diff --git a/TBF/UI/Procedures/ProcedureDlg.cs b/TBF/UI/Procedures/ProcedureDlg.cs index 5b75f27f7..f6f7bd1b7 100644 --- a/TBF/UI/Procedures/ProcedureDlg.cs +++ b/TBF/UI/Procedures/ProcedureDlg.cs @@ -65,26 +65,38 @@ namespace TBF.UI.Procedures bool unlocked; - public ProcedureDlg() + ProcedureDlg() { - /// Detect display setting: 100% = 96dpi, 125% = 120dpi, 150% = 144dpi. - Dpi = (int)this.CreateGraphics().DpiX; - initialMode = Mode.Locked; + InitializeComponent(); - InitializeComponent(); + /// Detect display setting: 100% = 96dpi, 125% = 120dpi, 150% = 144dpi. + Dpi = (int)this.CreateGraphics().DpiX; + } + + public ProcedureDlg(Procedure procedure, IList usedNames, Mode initialMode, Form parentForm) + : this() + { + if (procedure == null) throw new ArgumentNullException("procedure"); + + LoadedProcedure = procedure; + this.usedNames = usedNames; + this.initialMode = initialMode; /// SharedDlgButtons configuration + sharedButtons.ParentForm = parentForm; #if KEMPNO_50 || KRAKOW_50 - sharedButtons.RequiredGroupMembership = new GID[] { GID.TestingSpecialists, GID.WaterMeterAuthority }; + sharedButtons.RequiredGroupMembership = procedure.Protected ? new GID[] { GID.WaterMeterAuthority } + : new GID[] { GID.TestingSpecialists, GID.WaterMeterAuthority }; #else - sharedButtons.RequiredGroupMembership = new GID[] { GID.TestingSpecialists, GID.Metrologists }; + sharedButtons.RequiredGroupMembership = procedure.Protected ? new GID[] { GID.Metrologists } + : new GID[] { GID.TestingSpecialists, GID.Metrologists }; #endif - sharedButtons.OptionalButtons = SharedButtons.Buttons.Add | SharedButtons.Buttons.Remove | SharedButtons.Buttons.Up | SharedButtons.Buttons.Down | SharedButtons.Buttons.Copy; + #if TURA_SPECIAL || TURA_IPERL || TURA_IPERL_NEW /// Custom button 'Načítaj testy iPerl z Oracle' sharedButtons.OptionalButtons |= SharedButtons.Buttons.Custom1; @@ -92,15 +104,16 @@ namespace TBF.UI.Procedures sharedButtons.Custom1Clicked += iPerlWizardButton_Click; #endif 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.OKClicked += okButton_Click; + sharedButtons.CancelClicked += cancelButton_Click; + sharedButtons.AddClicked += addButton_Click; + sharedButtons.RemoveClicked += removeButton_Click; + sharedButtons.UpClicked += upButton_Click; + sharedButtons.DownClicked += downButton_Click; sharedButtons.CopyClicked += copyButton_Click; + if (initialMode == Mode.PermanentlyLocked) sharedButtons.DisableUnlock(); - /// ListViewEx-es configuration + /// ListViewEx-es configuration metrology1ListViewEx.SubItemClicked += new SubItemEventHandler(metrology1ListViewEx_SubItemClicked); metrology1ListViewEx.SubItemRightClicked += new SubItemEventHandler(metrology1ListViewEx_SubItemRightClicked); metrology1ListViewEx.SubItemEndEditing += new SubItemEndEditingEventHandler(metrology1ListViewEx_SubItemEndEditing); @@ -118,25 +131,6 @@ namespace TBF.UI.Procedures parametersListViewEx.SubItemEndEditing += new SubItemEndEditingEventHandler(parametersListViewEx_SubItemEndEditing); SelectedTestIx = -1; - } - - public ProcedureDlg(Config.Entities.Procedure procedure, IList usedNames, Mode initialMode) - : this() - { - if (procedure == null) throw new ArgumentNullException("procedure"); - - LoadedProcedure = procedure; - this.usedNames = usedNames; - this.initialMode = initialMode; - -#if KEMPNO_50 || KRAKOW_50 - sharedButtons.RequiredGroupMembership = procedure.Protected ? new GID[] { GID.WaterMeterAuthority } - : new GID[] { GID.TestingSpecialists, GID.WaterMeterAuthority }; -#else - sharedButtons.RequiredGroupMembership = procedure.Protected ? new GID[] { GID.Metrologists } - : new GID[] { GID.TestingSpecialists, GID.Metrologists }; -#endif - if (initialMode == Mode.PermanentlyLocked) sharedButtons.DisableUnlock(); using (NHibernate.ISession session = TBF.DB.CreateSession(DBKind.Config)) { @@ -2117,7 +2111,7 @@ namespace TBF.UI.Procedures procNameTextBox.Enabled = true; descriptionTextBox.Enabled = true; variantTextBox.Enabled = true; - protectedCheckBox.Enabled = GlobalData.CurrentUser.IsMemberOf(GID.Metrologists); + protectedCheckBox.Enabled = CurrentUser.IsMemberOf(GID.Metrologists); mustBeCompleteCheckBox.Enabled = true; manualControlDisabledCheckBox.Enabled = true; dataEntryComboBox.Enabled = true; @@ -2857,7 +2851,7 @@ namespace TBF.UI.Procedures /// Loaded procedure /// Selected sensors path /// ROI data - void AddProcedureParamsToRoiComponents(Config.Entities.Procedure procedure, string sensorsPathName, TestWizard.RoiData roiData) + void AddProcedureParamsToRoiComponents(Procedure procedure, string sensorsPathName, TestWizard.RoiData roiData) { IList cmpntsInSensPath = new List(); @@ -3087,7 +3081,7 @@ namespace TBF.UI.Procedures if (lvi.Tag is Procedure) { - (new ProcedureDlg(lvi.Tag as Procedure, new List(), ProcedureDlg.Mode.PermanentlyLocked)).ShowDialog(); + (new ProcedureDlg(lvi.Tag as Procedure, new List(), ProcedureDlg.Mode.PermanentlyLocked, sharedButtons.ParentForm)).ShowDialog(); } } diff --git a/TBF/UI/Procedures/ProceduresCtrl.cs b/TBF/UI/Procedures/ProceduresCtrl.cs index ed4cf0b8c..670bd4e19 100644 --- a/TBF/UI/Procedures/ProceduresCtrl.cs +++ b/TBF/UI/Procedures/ProceduresCtrl.cs @@ -1,5 +1,5 @@ /// -/// Copyright (c) 2020 Sensus Slovensko a.s. +/// Copyright (c) 2020-2022 Sensus Slovensko a.s. /// using System; using System.Collections.Generic; @@ -304,10 +304,10 @@ namespace TBF.UI.Procedures newProcedure.Revision = 1; newProcedure.PredecessorId = 0; newProcedure.ObtainedByCopy = false; - newProcedure.CreationUser = GlobalData.GetCurrentUserName(); + newProcedure.CreationUser = CurrentUser.UserName(); newProcedure.CreationTime = DateTime.Now; - if (new ProcedureDlg(newProcedure, GetUsedNames(false), ProcedureDlg.Mode.Unlocked).ShowDialog() == DialogResult.OK) + if (new ProcedureDlg(newProcedure, GetUsedNames(false), ProcedureDlg.Mode.Unlocked, parent).ShowDialog() == DialogResult.OK) { /// TODO: Make name uniqueness test parent.Unlock(); @@ -316,7 +316,7 @@ namespace TBF.UI.Procedures { try { - newProcedure.LastChgUser = GlobalData.GetCurrentUserName(); + newProcedure.LastChgUser = CurrentUser.UserName(); newProcedure.LastChgTime = DateTime.Now; DoAddOne(newProcedure); @@ -542,7 +542,7 @@ namespace TBF.UI.Procedures IList usedNames = GetUsedNames(false); usedNames.Remove(originalProcedure.Name.ToLower()); /// Allow original procedure name /// - if (new ProcedureDlg(modifiedProcedure, usedNames, ProcedureDlg.Mode.Locked).ShowDialog() == DialogResult.OK) + if (new ProcedureDlg(modifiedProcedure, usedNames, ProcedureDlg.Mode.Locked, parent).ShowDialog() == DialogResult.OK) { parent.Unlock(); @@ -551,7 +551,7 @@ namespace TBF.UI.Procedures try { originalProcedure.ProcedureState = ProcedureState.History; - modifiedProcedure.LastChgUser = GlobalData.GetCurrentUserName(); + modifiedProcedure.LastChgUser = CurrentUser.UserName(); modifiedProcedure.LastChgTime = DateTime.Now; session.SaveOrUpdate(originalProcedure); @@ -591,18 +591,18 @@ namespace TBF.UI.Procedures newProcedure.Revision = 1; newProcedure.PredecessorId = selectedProcedure.Id; newProcedure.ObtainedByCopy = true; - newProcedure.CreationUser = GlobalData.GetCurrentUserName(); + newProcedure.CreationUser = CurrentUser.UserName(); newProcedure.CreationTime = DateTime.Now; newProcedure.Protected = false; - if ((new ProcedureDlg(newProcedure, GetUsedNames(false), ProcedureDlg.Mode.Unlocked)).ShowDialog() == DialogResult.OK) + if ((new ProcedureDlg(newProcedure, GetUsedNames(false), ProcedureDlg.Mode.Unlocked, parent)).ShowDialog() == DialogResult.OK) { /// TODO: Make name uniqueness test parent.Unlock(); using (var transaction = session.BeginTransaction()) { - newProcedure.LastChgUser = GlobalData.GetCurrentUserName(); + newProcedure.LastChgUser = CurrentUser.UserName(); newProcedure.LastChgTime = DateTime.Now; DoAddOne(newProcedure); @@ -645,17 +645,17 @@ namespace TBF.UI.Procedures newProcedure.Revision = 1; newProcedure.PredecessorId = 0; newProcedure.ObtainedByCopy = false; - newProcedure.CreationUser = GlobalData.GetCurrentUserName(); + newProcedure.CreationUser = CurrentUser.UserName(); newProcedure.CreationTime = DateTime.Now; - if ((new ProcedureDlg(newProcedure, GetUsedNames(false), ProcedureDlg.Mode.Unlocked)).ShowDialog() == DialogResult.OK) + if ((new ProcedureDlg(newProcedure, GetUsedNames(false), ProcedureDlg.Mode.Unlocked, parent)).ShowDialog() == DialogResult.OK) { /// TODO: Make name uniqueness test parent.Unlock(); using (var transaction = session.BeginTransaction()) { - newProcedure.LastChgUser = GlobalData.GetCurrentUserName(); + newProcedure.LastChgUser = CurrentUser.UserName(); newProcedure.LastChgTime = DateTime.Now; DoAddOne(newProcedure); @@ -726,7 +726,9 @@ namespace TBF.UI.Procedures IList errorFlagsParamsOfCreatedTests = new List(); IList waterMeterParamsOfNewProcedure = new List(); - var cmpntEntities = session.QueryOver().OrderBy(x => x.ItemNr).Asc.List(); + var cmpntEntities = session.QueryOver() + .OrderBy(x => x.ItemNr).Asc + .List(); IList components = Rig.TbfComponents.LoadComponentsFromDB(cmpntEntities); foreach (var cmptn in components) { @@ -860,10 +862,10 @@ namespace TBF.UI.Procedures newProcedure.Revision = 1; newProcedure.PredecessorId = 0; newProcedure.ObtainedByCopy = false; - newProcedure.CreationUser = GlobalData.GetCurrentUserName(); + newProcedure.CreationUser = CurrentUser.UserName(); newProcedure.CreationTime = DateTime.Now; - if (new ProcedureDlg(newProcedure, GetUsedNames(false), ProcedureDlg.Mode.Unlocked).ShowDialog() == DialogResult.OK) + if (new ProcedureDlg(newProcedure, GetUsedNames(false), ProcedureDlg.Mode.Unlocked, parent).ShowDialog() == DialogResult.OK) { /// TODO: Make name uniqueness test parent.Unlock(); @@ -872,7 +874,7 @@ namespace TBF.UI.Procedures { try { - newProcedure.LastChgUser = GlobalData.GetCurrentUserName(); + newProcedure.LastChgUser = CurrentUser.UserName(); newProcedure.LastChgTime = DateTime.Now; DoAddOne(newProcedure); diff --git a/TBF/UI/Procedures/ProceduresDlg.Designer.cs b/TBF/UI/Procedures/ProceduresDlg.Designer.cs index 3f12e0835..9f6d2e43c 100644 --- a/TBF/UI/Procedures/ProceduresDlg.Designer.cs +++ b/TBF/UI/Procedures/ProceduresDlg.Designer.cs @@ -32,7 +32,7 @@ namespace TBF.UI.Procedures private void InitializeComponent() { this.splitContainer = new System.Windows.Forms.SplitContainer(); - this.proceduresCtrl = new ProceduresCtrl(); + this.proceduresCtrl = new TBF.UI.Procedures.ProceduresCtrl(); this.sharedButtons = new TBF.UI.Shared.SharedButtons(); ((System.ComponentModel.ISupportInitialize)(this.splitContainer)).BeginInit(); this.splitContainer.Panel1.SuspendLayout(); @@ -63,7 +63,7 @@ namespace TBF.UI.Procedures this.proceduresCtrl.Dock = System.Windows.Forms.DockStyle.Fill; this.proceduresCtrl.Location = new System.Drawing.Point(0, 0); this.proceduresCtrl.Name = "proceduresCtrl"; - this.proceduresCtrl.Size = new System.Drawing.Size(412, 402); + this.proceduresCtrl.Size = new System.Drawing.Size(606, 402); this.proceduresCtrl.TabIndex = 0; // // sharedButtons @@ -82,6 +82,7 @@ namespace TBF.UI.Procedures this.Name = "ProceduresDlg"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; this.Text = "ProceduresDlg"; + this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.ProceduresDlg_FormClosing); this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.ProceduresDlg_FormClosed); this.Load += new System.EventHandler(this.ProceduresDlg_Load); this.splitContainer.Panel1.ResumeLayout(false); diff --git a/TBF/UI/Procedures/ProceduresDlg.cs b/TBF/UI/Procedures/ProceduresDlg.cs index 7a23c5e3f..1d6206577 100644 --- a/TBF/UI/Procedures/ProceduresDlg.cs +++ b/TBF/UI/Procedures/ProceduresDlg.cs @@ -25,6 +25,7 @@ namespace TBF.UI.Procedures InitializeComponent(); /// SharedDlgButtons configuration + sharedButtons.ParentForm = this; sharedButtons.RequiredGroupMembership = new GID[] { GID.TestingSpecialists, GID.Metrologists }; #if TEST_PROFILES @@ -252,5 +253,10 @@ namespace TBF.UI.Procedures sharedButtons.DisableButtons(SharedButtons.Buttons.Remove | SharedButtons.Buttons.Up | SharedButtons.Buttons.Down); } } + + private void ProceduresDlg_FormClosing(object sender, FormClosingEventArgs e) + { + if (CurrentUser.Restore(this)) Program.MainWnd.UpdateUser(); + } } } diff --git a/TBF/UI/ResultsMI/DeleteFromOracleForm.Designer.cs b/TBF/UI/ResultsMI/DeleteFromOracleForm.Designer.cs index 18204e733..d22178782 100644 --- a/TBF/UI/ResultsMI/DeleteFromOracleForm.Designer.cs +++ b/TBF/UI/ResultsMI/DeleteFromOracleForm.Designer.cs @@ -29,9 +29,9 @@ private void InitializeComponent() { this.selectWhatToDeleteGroupBox = new System.Windows.Forms.GroupBox(); - this.waterMetersTextBox = new System.Windows.Forms.TextBox(); this.waterMetersRadioButton = new System.Windows.Forms.RadioButton(); this.batchRadioButton = new System.Windows.Forms.RadioButton(); + this.waterMetersTextBox = new System.Windows.Forms.TextBox(); this.startButton = new System.Windows.Forms.Button(); this.activityGroupBox = new System.Windows.Forms.GroupBox(); this.activityTextBox = new System.Windows.Forms.TextBox(); @@ -61,14 +61,6 @@ this.selectWhatToDeleteGroupBox.TabStop = false; this.selectWhatToDeleteGroupBox.Text = "Select what to delete"; // - // waterMetersTextBox - // - this.waterMetersTextBox.Location = new System.Drawing.Point(267, 70); - this.waterMetersTextBox.Multiline = true; - this.waterMetersTextBox.Name = "waterMetersTextBox"; - this.waterMetersTextBox.Size = new System.Drawing.Size(211, 56); - this.waterMetersTextBox.TabIndex = 2; - // // waterMetersRadioButton // this.waterMetersRadioButton.AutoSize = true; @@ -91,6 +83,14 @@ this.batchRadioButton.Text = "Batch"; this.batchRadioButton.UseVisualStyleBackColor = true; // + // waterMetersTextBox + // + this.waterMetersTextBox.Location = new System.Drawing.Point(267, 70); + this.waterMetersTextBox.Multiline = true; + this.waterMetersTextBox.Name = "waterMetersTextBox"; + this.waterMetersTextBox.Size = new System.Drawing.Size(211, 56); + this.waterMetersTextBox.TabIndex = 2; + // // startButton // this.startButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); @@ -209,6 +209,7 @@ this.MinimumSize = new System.Drawing.Size(600, 500); this.Name = "DeleteFromOracleForm"; this.Text = "Delete Data From Oracle"; + this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.DeleteFromOracleForm_FormClosing); this.selectWhatToDeleteGroupBox.ResumeLayout(false); this.selectWhatToDeleteGroupBox.PerformLayout(); this.activityGroupBox.ResumeLayout(false); diff --git a/TBF/UI/ResultsMI/DeleteFromOracleForm.cs b/TBF/UI/ResultsMI/DeleteFromOracleForm.cs index 9a60d5910..fd90276c9 100644 --- a/TBF/UI/ResultsMI/DeleteFromOracleForm.cs +++ b/TBF/UI/ResultsMI/DeleteFromOracleForm.cs @@ -383,5 +383,10 @@ namespace TBF.UI.ResultsMI return false; } } + + private void DeleteFromOracleForm_FormClosing(object sender, FormClosingEventArgs e) + { + if (CurrentUser.Restore(this)) Program.MainWnd.UpdateUser(); + } } } diff --git a/TBF/UI/ResultsMI/ResultsArrangementDlg.Designer.cs b/TBF/UI/ResultsMI/ResultsArrangementDlg.Designer.cs index 3fbd9d0aa..a52e53864 100644 --- a/TBF/UI/ResultsMI/ResultsArrangementDlg.Designer.cs +++ b/TBF/UI/ResultsMI/ResultsArrangementDlg.Designer.cs @@ -249,6 +249,7 @@ namespace TBF.UI.ResultsMI this.Name = "ResultsArrangementDlg"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; this.Text = "ResultsConfig"; + this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.ResultsArrangementDlg_FormClosing); this.Load += new System.EventHandler(this.ResultsConfig_Load); this.testsArangementGroupBox.ResumeLayout(false); this.testsArangementGroupBox.PerformLayout(); diff --git a/TBF/UI/ResultsMI/ResultsArrangementDlg.cs b/TBF/UI/ResultsMI/ResultsArrangementDlg.cs index fd9205946..38b3ba428 100644 --- a/TBF/UI/ResultsMI/ResultsArrangementDlg.cs +++ b/TBF/UI/ResultsMI/ResultsArrangementDlg.cs @@ -1,5 +1,5 @@ /// -/// Copyright (c) 2013-2017 Sensus Slovensko a.s. +/// Copyright (c) 2013-2022 Sensus Slovensko a.s. /// using System; using System.Collections.Generic; @@ -91,19 +91,17 @@ namespace TBF.UI.ResultsMI { if (!Unlocked) { - if (!GlobalData.CurrentUser.IsMemberOf(RequiredGroupMembership)) + if (!CurrentUser.IsMemberOf(RequiredGroupMembership)) { - if ((new SharedDatabase.Forms.LoginDlg(RequiredGroupMembership)).ShowDialog() != DialogResult.OK) + if ((new SharedDatabase.Forms.LoginDlg(RequiredGroupMembership, this)).ShowDialog() != DialogResult.OK) return; } else if (Program.LocalSettings.AlwaysAskPasswdWhenUnlocking) { - if ((new SharedDatabase.Forms.LoginDlg(GlobalData.GetCurrentUserName(), RequiredGroupMembership)).ShowDialog() != DialogResult.OK) + if ((new SharedDatabase.Forms.LoginDlg(CurrentUser.UserName(), RequiredGroupMembership, this)).ShowDialog() != DialogResult.OK) return; } - if (Program.MainWnd != null) Program.MainWnd.UpdateUser(); - Unlocked = true; /// @@ -121,7 +119,9 @@ namespace TBF.UI.ResultsMI minWidthTextBox.Enabled = true; minHeightTextBox.Enabled = true; resultsConfigCtrl.Unlocked = true; - } + + if (Program.MainWnd != null) Program.MainWnd.UpdateUser(); + } } void okButton_Click(object sender, EventArgs e) @@ -138,5 +138,10 @@ namespace TBF.UI.ResultsMI DialogResult = DialogResult.OK; Close(); } + + private void ResultsArrangementDlg_FormClosing(object sender, FormClosingEventArgs e) + { + if (CurrentUser.Restore(this)) Program.MainWnd.UpdateUser(); + } } } diff --git a/TBF/UI/ResultsMI/ResultsTabPageCtrl.cs b/TBF/UI/ResultsMI/ResultsTabPageCtrl.cs index 2db25e351..b5d774d00 100644 --- a/TBF/UI/ResultsMI/ResultsTabPageCtrl.cs +++ b/TBF/UI/ResultsMI/ResultsTabPageCtrl.cs @@ -1,5 +1,5 @@ /// -/// Copyright (c) 2013-2021 Sensus Slovensko a.s. +/// Copyright (c) 2013-2022 Sensus Slovensko a.s. /// using System; using System.Collections.Generic; @@ -218,16 +218,17 @@ namespace TBF.UI.ResultsMI /// private void configureButton_Click(object sender, EventArgs e) { - ResultsArrangementDlg dlg = new ResultsArrangementDlg(); - - dlg.MetersKind = metersKind; - dlg.TestsArrangement = TestsArrangement; - dlg.MetersArrangement = MetersArrangement; - dlg.NrMetersInOneGroup = NrMetersInOneGroup; - dlg.ShowDisabledPositions = ShowDisabledPositions; - dlg.MinWidth = MinWidth; - dlg.MinHeight = MinHeight; - dlg.SelectedItems = GetRsltItems(metersKind); + ResultsArrangementDlg dlg = new ResultsArrangementDlg() + { + MetersKind = metersKind, + TestsArrangement = TestsArrangement, + MetersArrangement = MetersArrangement, + NrMetersInOneGroup = NrMetersInOneGroup, + ShowDisabledPositions = ShowDisabledPositions, + MinWidth = MinWidth, + MinHeight = MinHeight, + SelectedItems = GetRsltItems(metersKind) + }; DialogResult dr = dlg.ShowDialog(); if (dr == DialogResult.OK && dlg.Unlocked) diff --git a/TBF/UI/Shared/BenchControlPanel.cs b/TBF/UI/Shared/BenchControlPanel.cs index 9e8bea3d5..1885769c2 100644 --- a/TBF/UI/Shared/BenchControlPanel.cs +++ b/TBF/UI/Shared/BenchControlPanel.cs @@ -283,7 +283,7 @@ namespace TBF.UI.Shared { #if TURA_IPERL || TURA_IPERL_NEW /// Prevent 'Stop draining' by password - if (drain1Highlighted && !GlobalData.CurrentUser.IsMemberOf(GID.TestingSpecialists)) + if (drain1Highlighted && !GlobalData.IsMemberOf(GID.TestingSpecialists)) { if ((new SharedDatabase.Forms.LoginDlg(new GID[] { GID.TestingSpecialists })).ShowDialog() != DialogResult.OK) return; @@ -300,7 +300,7 @@ namespace TBF.UI.Shared { #if TURA_IPERL || TURA_IPERL_NEW /// Prevent 'Stop draining' by password - if (drain1Highlighted && !GlobalData.CurrentUser.IsMemberOf(GID.TestingSpecialists)) + if (drain1Highlighted && !GlobalData.IsMemberOf(GID.TestingSpecialists)) { if ((new SharedDatabase.Forms.LoginDlg(new GID[] { GID.TestingSpecialists })).ShowDialog() != DialogResult.OK) return; @@ -317,7 +317,7 @@ namespace TBF.UI.Shared { #if TURA_IPERL || TURA_IPERL_NEW /// Prevent 'Stop draining' by password - if (drain1Highlighted && !GlobalData.CurrentUser.IsMemberOf(GID.TestingSpecialists)) + if (drain1Highlighted && !GlobalData.IsMemberOf(GID.TestingSpecialists)) { if ((new SharedDatabase.Forms.LoginDlg(new GID[] { GID.TestingSpecialists })).ShowDialog() != DialogResult.OK) return; diff --git a/TBF/UI/Shared/SharedButtons.cs b/TBF/UI/Shared/SharedButtons.cs index 6b110e106..3162a513d 100644 --- a/TBF/UI/Shared/SharedButtons.cs +++ b/TBF/UI/Shared/SharedButtons.cs @@ -72,9 +72,9 @@ namespace TBF.UI.Shared Middle, } - public GID[] RequiredGroupMembership; + public Form ParentForm; /// Used as a current form reference when changing and restoring a user - IUser originalUser; + public GID[] RequiredGroupMembership; /// /// Default constructor @@ -82,7 +82,6 @@ namespace TBF.UI.Shared public SharedButtons() { InitializeComponent(); - originalUser = GlobalData.CurrentUser; lockState = LockState.Locked; MoreActive = false; RequiredGroupMembership = null; @@ -199,12 +198,6 @@ namespace TBF.UI.Shared EnableOrDisableButtons(selectedButtons, false); } - void RestoreUser() - { - GlobalData.CurrentUser = originalUser; - Program.MainWnd.UpdateUser(); - } - /// /// Events invoked when buttons are clicked (and in case of Unlock kbutton also accepted) /// @@ -237,14 +230,14 @@ namespace TBF.UI.Shared { if (lockState == LockState.Locked) { - if (!GlobalData.CurrentUser.IsMemberOf(RequiredGroupMembership)) + if (!CurrentUser.IsMemberOf(RequiredGroupMembership)) { - if ((new SharedDatabase.Forms.LoginDlg(RequiredGroupMembership)).ShowDialog() != DialogResult.OK) + if ((new SharedDatabase.Forms.LoginDlg(RequiredGroupMembership, ParentForm)).ShowDialog() != DialogResult.OK) return; } else if (Program.LocalSettings.AlwaysAskPasswdWhenUnlocking) { - if ((new SharedDatabase.Forms.LoginDlg(GlobalData.CurrentUser.UserName, RequiredGroupMembership)).ShowDialog() != DialogResult.OK) + if ((new SharedDatabase.Forms.LoginDlg(CurrentUser.UserName(), RequiredGroupMembership, ParentForm)).ShowDialog() != DialogResult.OK) return; } diff --git a/WorkflowConfigurator/MainWnd.cs b/WorkflowConfigurator/MainWnd.cs index ed64e4c38..ae4026db3 100644 --- a/WorkflowConfigurator/MainWnd.cs +++ b/WorkflowConfigurator/MainWnd.cs @@ -65,7 +65,7 @@ namespace WorkflowConfigurator if (!string.IsNullOrEmpty(Program.LocalSettings.UsersDBConnString)) { - GlobalData.LocalUsersDB = new DBSettings(Common.DBType.MySql, Program.LocalSettings.UsersDBConnString); + CurrentUser.LocalUsersDB = new DBSettings(Common.DBType.MySql, Program.LocalSettings.UsersDBConnString); } } @@ -89,7 +89,7 @@ namespace WorkflowConfigurator public static void PrintTitle(bool busy) { - string user = GlobalData.GetCurrentUserName(); + string user = CurrentUser.UserName(); if (!string.IsNullOrEmpty(user)) user = string.Format(" ({0})", user); Program.MainWnd.Text = string.Format(busy ? "{0} v.{1}{2} ... reading database" : "{0} v.{1}{2}", diff --git a/WorkflowConfigurator/UserControls/EditProcessCtrl.cs b/WorkflowConfigurator/UserControls/EditProcessCtrl.cs index 0167a668b..11649884d 100644 --- a/WorkflowConfigurator/UserControls/EditProcessCtrl.cs +++ b/WorkflowConfigurator/UserControls/EditProcessCtrl.cs @@ -555,8 +555,8 @@ namespace WorkflowConfigurator.UserControls /// Unlock button pressed if (unlocked) return; /// Already unlocked - if ((GlobalData.CurrentUser!= null && GlobalData.CurrentUser.IsMemberOf(UnlockAccessLevel)) || - new SharedDatabase.Forms.LoginDlg(UnlockAccessLevel).ShowDialog() == DialogResult.OK) + if (CurrentUser.IsMemberOf(UnlockAccessLevel) || + new SharedDatabase.Forms.LoginDlg(UnlockAccessLevel, null).ShowDialog() == DialogResult.OK) { MainWnd.PrintTitle(false); UpdateLockState(true, (Process.ReleaseStatus == ReleaseStatus.In_preparation)); @@ -594,7 +594,7 @@ namespace WorkflowConfigurator.UserControls if (!GetAccessToStateChange(true)) return; /// Obligatory login when releasing a process to production UpdateLockState(false, false); Process.ReleaseStatus = ReleaseStatus.Released; - Process.ApprovedBy = GlobalData.GetCurrentUserName(); + Process.ApprovedBy = CurrentUser.UserName(); Process.TimeStamp2 = DateTime.Now; break; @@ -716,12 +716,12 @@ namespace WorkflowConfigurator.UserControls GID[] rqrdMmbrshp = ChangeReleaseState; if (forceLogin) { - return new LoginDlg(rqrdMmbrshp).ShowDialog() == DialogResult.OK; + return new LoginDlg(rqrdMmbrshp, null).ShowDialog() == DialogResult.OK; } else { - return (GlobalData.CurrentUser != null && GlobalData.CurrentUser.IsMemberOf(rqrdMmbrshp)) || - new LoginDlg(rqrdMmbrshp).ShowDialog() == DialogResult.OK; + return CurrentUser.IsMemberOf(rqrdMmbrshp) || + new LoginDlg(rqrdMmbrshp, null).ShowDialog() == DialogResult.OK; } } diff --git a/WorkflowConfigurator/UserControls/OverviewOfProcessesCtrl.cs b/WorkflowConfigurator/UserControls/OverviewOfProcessesCtrl.cs index ab9eb03a0..819abe7b3 100644 --- a/WorkflowConfigurator/UserControls/OverviewOfProcessesCtrl.cs +++ b/WorkflowConfigurator/UserControls/OverviewOfProcessesCtrl.cs @@ -61,8 +61,8 @@ namespace WorkflowConfigurator.UserControls { GID[] rqrdMmbrshp = Program.SettingsAccessLevel; /// - if ((GlobalData.CurrentUser != null && GlobalData.CurrentUser.IsMemberOf(rqrdMmbrshp)) || - new LoginDlg(rqrdMmbrshp).ShowDialog() == DialogResult.OK) + if (CurrentUser.IsMemberOf(rqrdMmbrshp) || + new LoginDlg(rqrdMmbrshp, null).ShowDialog() == DialogResult.OK) { MainWnd.PrintTitle(false); new Forms.SettingsDlg().ShowDialog(); /// Logged in => Show settings dialog @@ -279,15 +279,15 @@ namespace WorkflowConfigurator.UserControls { GID[] rqrdMmbrshp = EditProcessCtrl.UnlockAccessLevel; /// - if ((GlobalData.CurrentUser != null && GlobalData.CurrentUser.IsMemberOf(rqrdMmbrshp)) || - new LoginDlg(rqrdMmbrshp).ShowDialog() == DialogResult.OK) + if (CurrentUser.IsMemberOf(rqrdMmbrshp) || + new LoginDlg(rqrdMmbrshp, null).ShowDialog() == DialogResult.OK) { MainWnd.PrintTitle(false); if (editProcessCtrl.FinishEditing() == EditFinishedInfo.Cancel) return; Process newProcess = new Process(NewProcessName(Strings.Workflow)); - newProcess.CreatedBy = GlobalData.GetCurrentUserName(); + newProcess.CreatedBy = CurrentUser.UserName(); allProcesses.Add(newProcess); editProcessCtrl.UpdateProcess(newProcess, Reason.NewProcess, allProcesses); RedrawLeftPane(RedrawType.FromScratch, newProcess); /// By this the new process will be selected @@ -300,7 +300,7 @@ namespace WorkflowConfigurator.UserControls if ((editProcessCtrl.Process == null) || (editProcessCtrl.FinishEditing() == EditFinishedInfo.Cancel)) return; - Process processCopy = editProcessCtrl.Process.Clone(NewProcessName(string.Format("{0} - {1}", editProcessCtrl.Process.Name, Strings.copy)), GlobalData.GetCurrentUserName()); + Process processCopy = editProcessCtrl.Process.Clone(NewProcessName(string.Format("{0} - {1}", editProcessCtrl.Process.Name, Strings.copy)), CurrentUser.UserName()); allProcesses.Add(processCopy); editProcessCtrl.UpdateProcess(processCopy, Reason.CopyProcess, allProcesses); RedrawLeftPane(RedrawType.FromScratch, processCopy); /// By this the copied process will be selected @@ -312,7 +312,7 @@ namespace WorkflowConfigurator.UserControls if ((editProcessCtrl.Process == null) || (editProcessCtrl.FinishEditing() == EditFinishedInfo.Cancel)) return; - Process processFromTemplate = editProcessCtrl.Process.Clone(NewProcessName(string.Format(Strings.Workflow_from_template_0, editProcessCtrl.Process.Name)), GlobalData.GetCurrentUserName()); + Process processFromTemplate = editProcessCtrl.Process.Clone(NewProcessName(string.Format(Strings.Workflow_from_template_0, editProcessCtrl.Process.Name)), CurrentUser.UserName()); allProcesses.Add(processFromTemplate); editProcessCtrl.UpdateProcess(processFromTemplate, Reason.CopyProcess, allProcesses); RedrawLeftPane(RedrawType.FromScratch, processFromTemplate); /// By this the process created from a template will be selected diff --git a/Workplace/Program.cs b/Workplace/Program.cs index 9c0ecbe9e..f61e7b6af 100644 --- a/Workplace/Program.cs +++ b/Workplace/Program.cs @@ -148,7 +148,7 @@ namespace Workplace /// /// User login /// - Common.GlobalData.LocalUsersDB = new DBSettings(DBType.MySql, LocalSettings.UsersDBConnString); + Common.CurrentUser.LocalUsersDB = new DBSettings(DBType.MySql, LocalSettings.UsersDBConnString); DialogResult dr; switch (LocalSettings.LocalWorkplacesCount) @@ -159,11 +159,14 @@ namespace Workplace break; case 2: - dr = new DoubleLoginDlg(Program.LocalSettings.LocalWorkplace1, Program.LocalSettings.LocalWorkplace2).ShowDialog(); + dr = new DoubleLoginDlg(Program.LocalSettings.LocalWorkplace1, + Program.LocalSettings.LocalWorkplace2, null).ShowDialog(); break; case 3: - dr = new TripleLoginDlg(Program.LocalSettings.LocalWorkplace1, Program.LocalSettings.LocalWorkplace2, Program.LocalSettings.LocalWorkplace3).ShowDialog(); + dr = new TripleLoginDlg(Program.LocalSettings.LocalWorkplace1, + Program.LocalSettings.LocalWorkplace2, + Program.LocalSettings.LocalWorkplace3, null).ShowDialog(); break; } diff --git a/Workplace/WorkplaceDlg.cs b/Workplace/WorkplaceDlg.cs index 4a76cd443..5cbdfb34e 100644 --- a/Workplace/WorkplaceDlg.cs +++ b/Workplace/WorkplaceDlg.cs @@ -181,7 +181,7 @@ namespace Workplace workplaceTextBox.Text = Program.LocalSettings.WorkplaceId; - workerTextBox.Text = Common.GlobalData.GetCurrentUserName(); + workerTextBox.Text = Common.CurrentUser.UserName(); lastLoginTime = DateTime.Now; isLoggedOut = false; @@ -622,7 +622,7 @@ namespace Workplace UpdateTitle(); /// Show acrive verification wplaceRegistration.UpdateRegistration(dbSession, Program.LocalSettings.WorkplaceId, - Common.GlobalData.CurrentUser.UserName, + Common.CurrentUser.UserName(), "1.2.3.4", (CurrentWorkflow != null) ? CurrentWorkflow.Name : string.Empty, (CurrentWorkstep != null) ? CurrentWorkstep.Name : string.Empty, @@ -1693,7 +1693,7 @@ namespace Workplace { ResetIdleTime(); - if (new LoginDlg(Program.SettingsAccessLevel).ShowDialog() == DialogResult.OK) + if (new LoginDlg(Program.SettingsAccessLevel, null).ShowDialog() == DialogResult.OK) { string oriWorkplace = Program.LocalSettings.WorkplaceId; if (Configure() == DialogResult.OK) @@ -1706,7 +1706,7 @@ namespace Workplace wplaceRegistration.UpdateRegistration(dbSession, Program.LocalSettings.WorkplaceId, - Common.GlobalData.CurrentUser.UserName, + Common.CurrentUser.UserName(), "1.2.3.4", (CurrentWorkflow != null) ? CurrentWorkflow.Name : string.Empty, (CurrentWorkstep != null) ? CurrentWorkstep.Name : string.Empty, @@ -1813,23 +1813,26 @@ namespace Workplace dr = new LoginDlg().ShowDialog(); break; case 2: - dr = new DoubleLoginDlg(Program.LocalSettings.LocalWorkplace1, Program.LocalSettings.LocalWorkplace2).ShowDialog(); + dr = new DoubleLoginDlg(Program.LocalSettings.LocalWorkplace1, + Program.LocalSettings.LocalWorkplace2, this).ShowDialog(); break; case 3: - dr = new TripleLoginDlg(Program.LocalSettings.LocalWorkplace1, Program.LocalSettings.LocalWorkplace2, Program.LocalSettings.LocalWorkplace3).ShowDialog(); + dr = new TripleLoginDlg(Program.LocalSettings.LocalWorkplace1, + Program.LocalSettings.LocalWorkplace2, + Program.LocalSettings.LocalWorkplace3, this).ShowDialog(); break; } if (dr == DialogResult.OK) break; } - workerTextBox.Text = Common.GlobalData.GetCurrentUserName(); + workerTextBox.Text = Common.CurrentUser.UserName(); lastLoginTime = DateTime.Now; isLoggedOut = false; ClearBatchNumbers(); wplaceRegistration.UpdateRegistration(dbSession, Program.LocalSettings.WorkplaceId, - Common.GlobalData.CurrentUser.UserName, + Common.CurrentUser.UserName(), "1.2.3.4", (CurrentWorkflow != null) ? CurrentWorkflow.Name : string.Empty, (CurrentWorkstep != null) ? CurrentWorkstep.Name : string.Empty,