//private CommonMetaList commonMetaList; private void PublicApplicationLogon_Load(object sender, EventArgs e) { #region TEST //// List of strings for your names //List<string> allUsers = new List<string>(); //// create your domain context and define the OU container to search in //PrincipalContext ctx = new PrincipalContext(ContextType.Domain, "DOMAINNAME", // "OU=SomeOU,dc=YourCompany,dc=com"); //// define a "query-by-example" principal - here, we search for a UserPrincipal (user) //UserPrincipal qbeUser = new UserPrincipal(ctx); //// create your principal searcher passing in the QBE principal //PrincipalSearcher srch = new PrincipalSearcher(qbeUser); //// find all matches //foreach (var found in srch.FindAll()) //{ // // do whatever here - "found" is of type "Principal" - it could be user, group, computer..... // allUsers.Add(found.DisplayName); //} //using (var context = new PrincipalContext(ContextType.Domain, "yourdomain.com")) //{ // using (var searcher = new PrincipalSearcher(new UserPrincipal(context))) // { // foreach (var result in searcher.FindAll()) // { // DirectoryEntry de = result.GetUnderlyingObject() as DirectoryEntry; // Console.WriteLine("First Name: " + de.Properties["givenName"].Value); // Console.WriteLine("Last Name : " + de.Properties["sn"].Value); // Console.WriteLine("SAM account name : " + de.Properties["samAccountName"].Value); // Console.WriteLine("User principal name: " + de.Properties["userPrincipalName"].Value); // Console.WriteLine(); // } // } //} //Console.ReadLine(); ////////string plainText = "Lê Minh Hiệp"; ////////// Convert the plain string pwd into bytes //////////byte[] plainTextBytes = UnicodeEncoding.Unicode.GetBytes(plainText); //////////System.Security.Cryptography.HashAlgorithm hashAlgo = new System.Security.Cryptography.SHA256Managed(); //////////byte[] hash = hashAlgo.ComputeHash(plainTextBytes); ////////byte[] data = UnicodeEncoding.Unicode.GetBytes(plainText); ////////data = new System.Security.Cryptography.SHA256Managed().ComputeHash(data); ////////String hash = UnicodeEncoding.Unicode.GetString(data); //////////CustomMsgBox.Show(hash); #endregion TEST try { int.TryParse(CommonConfigs.ReadSetting("ConfigID"), out GlobalVariables.ConfigID); UserPrincipal currentUserPrincipal = UserPrincipal.Current; if (currentUserPrincipal == null || currentUserPrincipal.Sid == null) { throw new Exception("Sorry, can not get current user principal!"); } this.baseRepository = CommonNinject.Kernel.Get <IBaseRepository>(); UserAPIs userAPIs = new UserAPIs(CommonNinject.Kernel.Get <IUserAPIRepository>()); IList <ActiveUser> activeUsers = userAPIs.GetActiveUsers(GlobalVariables.ConfigID == (int)GlobalVariables.FillingLine.Smallpack || GlobalVariables.ConfigID == (int)GlobalVariables.FillingLine.Pail ? "S-1-5-21-705987929-4194781227-356911358-1001" : "S-1-5-21-2907738014-1953812902-1740135539-2132-NTF"); //currentUserPrincipal.Sid.Value //throw new Exception(currentUserPrincipal.Sid.Value); if (activeUsers.Count > 0) { this.comboBoxEmployeeID.DataSource = activeUsers; this.comboBoxEmployeeID.DisplayMember = CommonExpressions.PropertyName <ActiveUser>(p => p.FullyQualifiedUserName); this.comboBoxEmployeeID.ValueMember = CommonExpressions.PropertyName <ActiveUser>(p => p.UserID); FillingLineAPIs fillingLineAPIs = new FillingLineAPIs(CommonNinject.Kernel.Get <IFillingLineAPIRepository>()); this.comboFillingLineID.DataSource = fillingLineAPIs.GetFillingLineBases(); this.comboFillingLineID.DisplayMember = CommonExpressions.PropertyName <FillingLineBase>(p => p.Name); this.comboFillingLineID.ValueMember = CommonExpressions.PropertyName <FillingLineBase>(p => p.FillingLineID); if (GlobalVariables.ConfigID == (int)GlobalVariables.FillingLine.Smallpack || GlobalVariables.ConfigID == (int)GlobalVariables.FillingLine.Pail || GlobalVariables.ConfigID == (int)GlobalVariables.FillingLine.Drum) { this.comboFillingLineID.SelectedValue = GlobalVariables.ConfigID; } if (!(GlobalVariables.ConfigID == (int)GlobalVariables.FillingLine.Smallpack || GlobalVariables.ConfigID == (int)GlobalVariables.FillingLine.Pail || GlobalVariables.ConfigID == (int)GlobalVariables.FillingLine.Drum)) { this.lbProductionLineID.Visible = false; this.comboFillingLineID.Visible = false; this.labelPassword.Top = this.lbEmployeeID.Top; this.textPassword.Top = this.comboBoxEmployeeID.Top; this.lbEmployeeID.Top = this.lbProductionLineID.Top; this.comboBoxEmployeeID.Top = this.comboFillingLineID.Top; } this.comboBoxAutonicsPortName.DataSource = System.IO.Ports.SerialPort.GetPortNames(); if (this.comboBoxAutonicsPortName.Items.Count == 0) { this.comboBoxAutonicsPortName.DataSource = null; this.comboBoxAutonicsPortName.Items.Add("COM0"); } string comportName = CommonConfigs.ReadSetting("ComportName"); if (this.comboBoxAutonicsPortName.Items.IndexOf(comportName) >= 0) { this.comboBoxAutonicsPortName.SelectedIndex = this.comboBoxAutonicsPortName.Items.IndexOf(comportName); } this.buttonDownload.Visible = true; this.buttonLoginRestore.Visible = activeUsers[0].IsDatabaseAdmin; } else { this.comboFillingLineID.Visible = false; this.comboBoxEmployeeID.Visible = false; this.lbEmployeeID.Visible = false; this.lbProductionLineID.Text = "\r\n" + "Sorry, user: "******"\r\n" + "Don't have permission to run this program." + "\r\n" + "\r\n" + "Contact your admin for more information. Thank you!" + "\r\n" + "\r\n" + "\r\n" + "Xin lỗi, bạn chưa được cấp quyền sử dụng phần mềm này."; this.buttonLogin.Visible = false; } } catch (Exception exception) { ExceptionHandlers.ShowExceptionMessageBox(this, exception); } }
private void buttonLoginExit_Click(object sender, EventArgs e) { try { if (!(GlobalVariables.ConfigID == (int)GlobalEnums.NmvnTaskID.Lavie || GlobalVariables.ConfigID == (int)GlobalVariables.FillingLine.Smallpack || GlobalVariables.ConfigID == (int)GlobalVariables.FillingLine.Pail || GlobalVariables.ConfigID == (int)GlobalVariables.FillingLine.BatchMaster)) { CustomMsgBox.Show(this, "Sorry, can not open this application." + "\r\n" + "\r\n" + "Call 0919 878 329 for more information. Thanks!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Stop); this.DialogResult = DialogResult.Cancel; return; } if (sender.Equals(this.buttonExit)) { this.DialogResult = DialogResult.Cancel; return; } if (this.comboBoxEmployeeID.SelectedIndex >= 0) { ActiveUser activeUser = this.comboBoxEmployeeID.SelectedItem as ActiveUser; if (activeUser != null) { UserAPIs userAPIs = new UserAPIs(CommonNinject.Kernel.Get <IUserAPIRepository>()); string passwordHash = userAPIs.GetPasswordHash(activeUser.UserID); if (passwordHash != "") { passwordHash = SecurePassword.Decrypt(passwordHash); } if (this.textPassword.Text != passwordHash) { throw new Exception("Sai mật khẩu. Vui lòng nhập lại mật khẩu trước khi tiếp tục."); } ContextAttributes.User = new UserInformation(activeUser.UserID, activeUser.OrganizationalUnitID, activeUser.LocationID, activeUser.LocationName, activeUser.UserName, activeUser.SecurityIdentifier, activeUser.FullyQualifiedUserName, activeUser.IsDatabaseAdmin, new DateTime()); if (this.comboFillingLineID.Visible && (this.comboFillingLineID.SelectedIndex < 0 || this.comboBoxAutonicsPortName.SelectedIndex < 0)) { throw new System.ArgumentException("Vui lòng chọn chuyền sản xuất (NOF1, NOF2, NOF...), và chọn đúng cổng COM để chạy phần mềm"); // || (this.comboFillingLineID.Enabled && (GlobalVariables.ProductionLine)this.comboFillingLineID.SelectedValue == GlobalVariables.ProductionLine.SERVER) } if (this.comboFillingLineID.Visible) { GlobalVariables.FillingLineID = (GlobalVariables.FillingLine) this.comboFillingLineID.SelectedValue; GlobalVariables.FillingLineCode = ((FillingLineBase)this.comboFillingLineID.SelectedItem).Code; GlobalVariables.FillingLineName = ((FillingLineBase)this.comboFillingLineID.SelectedItem).Name; GlobalVariables.FillingLineFactoryCode = ((FillingLineBase)this.comboFillingLineID.SelectedItem).FactoryCode; } else { GlobalVariables.FillingLineID = GlobalVariables.FillingLine.None; } GlobalVariables.ComportName = (string)this.comboBoxAutonicsPortName.SelectedValue; CommonConfigs.AddUpdateAppSetting("ConfigID", (GlobalVariables.ConfigID).ToString()); CommonConfigs.AddUpdateAppSetting("ComportName", GlobalVariables.ComportName); //CommonConfigs.AddUpdateAppSetting("ReportServerUrl", GlobalVariables.ReportServerUrl); //WILL BE REMOVE THIS LINE GlobalVariables.ReportServerUrl = CommonConfigs.ReadSetting("ReportServerUrl"); this.VersionValidate(); #region EMPTY DATABASE if (false && this.checkEmptyData.Checked) { this.baseRepository.ExecuteStoreCommand("UPDATE GoodsReceipts SET PickupID = NULL, GoodsIssueID = NULL, WarehouseAdjustmentID = NULL", new ObjectParameter[] { }); this.baseRepository.ExecuteStoreCommand("UPDATE GoodsReceiptDetails SET PickupDetailID = NULL, PickupID = NULL, GoodsIssueTransferDetailID = NULL, GoodsIssueID = NULL, WarehouseAdjustmentDetailID = NULL, WarehouseAdjustmentID = NULL", new ObjectParameter[] { }); this.baseRepository.ExecuteStoreCommand("DELETE FROM WarehouseAdjustmentDetails", new ObjectParameter[] { }); this.baseRepository.ExecuteStoreCommand("DBCC CHECKIDENT ('WarehouseAdjustmentDetails', RESEED, 0)", new ObjectParameter[] { }); this.baseRepository.ExecuteStoreCommand("DELETE FROM WarehouseAdjustments", new ObjectParameter[] { }); this.baseRepository.ExecuteStoreCommand("DBCC CHECKIDENT ('WarehouseAdjustments', RESEED, 0)", new ObjectParameter[] { }); this.baseRepository.ExecuteStoreCommand("DELETE FROM GoodsIssueTransferDetails", new ObjectParameter[] { }); this.baseRepository.ExecuteStoreCommand("DBCC CHECKIDENT ('GoodsIssueTransferDetails', RESEED, 0)", new ObjectParameter[] { }); this.baseRepository.ExecuteStoreCommand("DELETE FROM GoodsIssueDetails", new ObjectParameter[] { }); this.baseRepository.ExecuteStoreCommand("DBCC CHECKIDENT ('GoodsIssueDetails', RESEED, 0)", new ObjectParameter[] { }); this.baseRepository.ExecuteStoreCommand("DELETE FROM GoodsIssues", new ObjectParameter[] { }); this.baseRepository.ExecuteStoreCommand("DBCC CHECKIDENT ('GoodsIssues', RESEED, 0)", new ObjectParameter[] { }); this.baseRepository.ExecuteStoreCommand("DELETE FROM TransferOrderDetails", new ObjectParameter[] { }); this.baseRepository.ExecuteStoreCommand("DBCC CHECKIDENT ('TransferOrderDetails', RESEED, 0)", new ObjectParameter[] { }); this.baseRepository.ExecuteStoreCommand("DELETE FROM TransferOrders", new ObjectParameter[] { }); this.baseRepository.ExecuteStoreCommand("DBCC CHECKIDENT ('TransferOrders', RESEED, 0)", new ObjectParameter[] { }); this.baseRepository.ExecuteStoreCommand("DELETE FROM DeliveryAdviceDetails", new ObjectParameter[] { }); this.baseRepository.ExecuteStoreCommand("DBCC CHECKIDENT ('DeliveryAdviceDetails', RESEED, 0)", new ObjectParameter[] { }); this.baseRepository.ExecuteStoreCommand("DELETE FROM DeliveryAdvices", new ObjectParameter[] { }); this.baseRepository.ExecuteStoreCommand("DBCC CHECKIDENT ('DeliveryAdvices', RESEED, 0)", new ObjectParameter[] { }); this.baseRepository.ExecuteStoreCommand("DELETE FROM SalesOrderDetails", new ObjectParameter[] { }); this.baseRepository.ExecuteStoreCommand("DBCC CHECKIDENT ('SalesOrderDetails', RESEED, 0)", new ObjectParameter[] { }); this.baseRepository.ExecuteStoreCommand("DELETE FROM SalesOrders", new ObjectParameter[] { }); this.baseRepository.ExecuteStoreCommand("DBCC CHECKIDENT ('SalesOrders', RESEED, 0)", new ObjectParameter[] { }); this.baseRepository.ExecuteStoreCommand("DELETE FROM GoodsReceiptDetails", new ObjectParameter[] { }); this.baseRepository.ExecuteStoreCommand("DBCC CHECKIDENT ('GoodsReceiptDetails', RESEED, 0)", new ObjectParameter[] { }); this.baseRepository.ExecuteStoreCommand("DELETE FROM GoodsReceipts", new ObjectParameter[] { }); this.baseRepository.ExecuteStoreCommand("DBCC CHECKIDENT ('GoodsReceipts', RESEED, 0)", new ObjectParameter[] { }); this.baseRepository.ExecuteStoreCommand("DELETE FROM PickupDetails", new ObjectParameter[] { }); this.baseRepository.ExecuteStoreCommand("DBCC CHECKIDENT ('PickupDetails', RESEED, 0)", new ObjectParameter[] { }); this.baseRepository.ExecuteStoreCommand("DELETE FROM Pickups", new ObjectParameter[] { }); this.baseRepository.ExecuteStoreCommand("DBCC CHECKIDENT ('Pickups', RESEED, 0)", new ObjectParameter[] { }); this.baseRepository.ExecuteStoreCommand("DELETE FROM Packs", new ObjectParameter[] { }); this.baseRepository.ExecuteStoreCommand("DBCC CHECKIDENT ('Packs', RESEED, 0)", new ObjectParameter[] { }); this.baseRepository.ExecuteStoreCommand("DELETE FROM Cartons", new ObjectParameter[] { }); this.baseRepository.ExecuteStoreCommand("DBCC CHECKIDENT ('Cartons', RESEED, 0)", new ObjectParameter[] { }); this.baseRepository.ExecuteStoreCommand("DELETE FROM Pallets", new ObjectParameter[] { }); this.baseRepository.ExecuteStoreCommand("DBCC CHECKIDENT ('Pallets', RESEED, 0)", new ObjectParameter[] { }); this.baseRepository.ExecuteStoreCommand("DELETE FROM Batches", new ObjectParameter[] { }); this.baseRepository.ExecuteStoreCommand("DBCC CHECKIDENT ('Batches', RESEED, 0)", new ObjectParameter[] { }); this.baseRepository.ExecuteStoreCommand("DELETE FROM Lots", new ObjectParameter[] { }); this.baseRepository.ExecuteStoreCommand("DBCC CHECKIDENT ('Lots', RESEED, 0)", new ObjectParameter[] { }); this.baseRepository.ExecuteStoreCommand("DELETE FROM BatchMasters", new ObjectParameter[] { }); this.baseRepository.ExecuteStoreCommand("DBCC CHECKIDENT ('BatchMasters', RESEED, 0)", new ObjectParameter[] { }); this.baseRepository.ExecuteStoreCommand("DELETE FROM Commodities", new ObjectParameter[] { }); this.baseRepository.ExecuteStoreCommand("DBCC CHECKIDENT ('Commodities', RESEED, 0)", new ObjectParameter[] { }); } #endregion if (this.baseRepository.AutoUpdates(sender.Equals(this.buttonLoginRestore))) { this.DialogResult = DialogResult.OK; } else { CustomMsgBox.Show(this, "The program on this computer must be updated to the latest version." + "\r\n" + "\r\n" + "Contact your administrator for more information.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Stop); this.buttonDownload_Click(this.buttonDownload, new EventArgs()); } } } } catch (Exception exception) { ExceptionHandlers.ShowExceptionMessageBox(this, exception); this.DialogResult = DialogResult.None; } }
private void PublicApplicationLogon_Load(object sender, EventArgs e) { #region TEST //// List of strings for your names //List<string> allUsers = new List<string>(); //// create your domain context and define the OU container to search in //PrincipalContext ctx = new PrincipalContext(ContextType.Domain, "DOMAINNAME", // "OU=SomeOU,dc=YourCompany,dc=com"); //// define a "query-by-example" principal - here, we search for a UserPrincipal (user) //UserPrincipal qbeUser = new UserPrincipal(ctx); //// create your principal searcher passing in the QBE principal //PrincipalSearcher srch = new PrincipalSearcher(qbeUser); //// find all matches //foreach (var found in srch.FindAll()) //{ // // do whatever here - "found" is of type "Principal" - it could be user, group, computer..... // allUsers.Add(found.DisplayName); //} //using (var context = new PrincipalContext(ContextType.Domain, "yourdomain.com")) //{ // using (var searcher = new PrincipalSearcher(new UserPrincipal(context))) // { // foreach (var result in searcher.FindAll()) // { // DirectoryEntry de = result.GetUnderlyingObject() as DirectoryEntry; // Console.WriteLine("First Name: " + de.Properties["givenName"].Value); // Console.WriteLine("Last Name : " + de.Properties["sn"].Value); // Console.WriteLine("SAM account name : " + de.Properties["samAccountName"].Value); // Console.WriteLine("User principal name: " + de.Properties["userPrincipalName"].Value); // Console.WriteLine(); // } // } //} //Console.ReadLine(); ////string plainText = "Lê Minh Hiệp"; ////// Convert the plain string pwd into bytes //////byte[] plainTextBytes = UnicodeEncoding.Unicode.GetBytes(plainText); //////System.Security.Cryptography.HashAlgorithm hashAlgo = new System.Security.Cryptography.SHA256Managed(); //////byte[] hash = hashAlgo.ComputeHash(plainTextBytes); ////byte[] data = UnicodeEncoding.Unicode.GetBytes(plainText); ////data = new System.Security.Cryptography.SHA256Managed().ComputeHash(data); ////String hash = UnicodeEncoding.Unicode.GetString(data); //////CustomMsgBox.Show(hash); #endregion TEST ////JUST FOR 4L FillingLine ONLY. SHOULD REMOVE NEXT TIME //CommonConfigs.AddUpdateAppSetting("ConfigID", ((int)GlobalVariables.FillingLine.Import).ToString()); try { if (!(int.TryParse(CommonConfigs.ReadSetting("ConfigID"), out GlobalVariables.ConfigID))) { throw new Exception("Please check ConfigID value in config file."); } UserPrincipal currentUserPrincipal = UserPrincipal.Current; if (currentUserPrincipal == null || currentUserPrincipal.Sid == null) { throw new Exception("Sorry, can not get current user principal!"); } this.baseRepository = CommonNinject.Kernel.Get <IBaseRepository>(); UserAPIs userAPIs = new UserAPIs(CommonNinject.Kernel.Get <IUserAPIRepository>()); IList <ActiveUser> activeUsers = userAPIs.GetActiveUsers(GlobalEnums.CBPP ? "S-1-5-21-2058209122-1687518253-2045704780-1001" : currentUserPrincipal.Sid.Value); if (activeUsers.Count > 0) { if (GlobalVariables.ConfigID == (int)GlobalVariables.FillingLine.Smallpack || GlobalVariables.ConfigID == (int)GlobalVariables.FillingLine.Pail || GlobalVariables.ConfigID == (int)GlobalVariables.FillingLine.Medium4L || GlobalVariables.ConfigID == (int)GlobalVariables.FillingLine.Import || GlobalVariables.ConfigID == (int)GlobalVariables.FillingLine.Drum) { int?accessLevel = this.baseRepository.TotalSmartCodingEntities.GetAccessLevel(activeUsers[0].UserID, (int)TotalBase.Enums.GlobalEnums.NmvnTaskID.SmartCoding + (int)GlobalVariables.ConfigID, 0).Single(); if (accessLevel != (int)TotalBase.Enums.GlobalEnums.AccessLevel.Editable) { activeUsers = new List <ActiveUser>(); } this.comboUserID.Enabled = false; } else { this.Height = this.Height - 80; } } if (activeUsers.Count > 0) { this.comboSecurityIdentifier.Items.Add(activeUsers[0].UserName); this.comboSecurityIdentifier.SelectedIndex = 0; this.comboUserID.DataSource = activeUsers; this.comboUserID.DisplayMember = CommonExpressions.PropertyName <ActiveUser>(p => p.FullyQualifiedOrganizationalUnitName); this.comboUserID.ValueMember = CommonExpressions.PropertyName <ActiveUser>(p => p.UserID); FillingLineAPIs fillingLineAPIs = new FillingLineAPIs(CommonNinject.Kernel.Get <IFillingLineAPIRepository>()); this.comboFillingLineID.DataSource = fillingLineAPIs.GetFillingLineBases(); this.comboFillingLineID.DisplayMember = CommonExpressions.PropertyName <FillingLineBase>(p => p.Name); this.comboFillingLineID.ValueMember = CommonExpressions.PropertyName <FillingLineBase>(p => p.FillingLineID); if (GlobalVariables.ConfigID == (int)GlobalVariables.FillingLine.Smallpack || GlobalVariables.ConfigID == (int)GlobalVariables.FillingLine.Pail || GlobalVariables.ConfigID == (int)GlobalVariables.FillingLine.Medium4L || GlobalVariables.ConfigID == (int)GlobalVariables.FillingLine.Import || GlobalVariables.ConfigID == (int)GlobalVariables.FillingLine.Drum) { this.comboFillingLineID.SelectedValue = GlobalVariables.ConfigID; } if (!(GlobalVariables.ConfigID == (int)GlobalVariables.FillingLine.Smallpack || GlobalVariables.ConfigID == (int)GlobalVariables.FillingLine.Pail || GlobalVariables.ConfigID == (int)GlobalVariables.FillingLine.Medium4L || GlobalVariables.ConfigID == (int)GlobalVariables.FillingLine.Import || GlobalVariables.ConfigID == (int)GlobalVariables.FillingLine.Drum)) { this.labelFillingLineID.Visible = false; this.comboFillingLineID.Visible = false; } if (GlobalVariables.ConfigID == (int)GlobalVariables.FillingLine.Drum) { this.checkGlobalDrumWithDigit.Visible = true; } this.comboComportName.DataSource = System.IO.Ports.SerialPort.GetPortNames(); if (this.comboComportName.Items.Count == 0) { this.comboComportName.DataSource = null; this.comboComportName.Items.Add("COM0"); } string comportName = CommonConfigs.ReadSetting("ComportName"); if (this.comboComportName.Items.IndexOf(comportName) >= 0) { this.comboComportName.SelectedIndex = this.comboComportName.Items.IndexOf(comportName); } this.buttonDownload.Visible = true; this.buttonLoginRestore.Visible = activeUsers[0].IsDatabaseAdmin; this.buttonConnectServer.Visible = activeUsers[0].IsDatabaseAdmin; this.buttonWebapi.Visible = activeUsers[0].IsDatabaseAdmin; this.buttonApplicationRoleIgnored.Visible = activeUsers[0].IsDatabaseAdmin; this.separatorResetApplicationRole.Visible = activeUsers[0].IsDatabaseAdmin; } else { this.comboSecurityIdentifier.Visible = false; this.comboUserID.Visible = false; this.comboFillingLineID.Visible = false; this.labelUserID.Visible = false; this.labelFillingLineID.Visible = false; this.labelSecurityIdentifier.Text = "\r\n" + "Sorry, user: "******"\r\n" + "Don't have permission to run this program." + "\r\n" + "\r\n" + "Contact your admin for more information. Thank you!" + "\r\n" + "\r\n" + "\r\n" + "Xin lỗi, bạn chưa được cấp quyền sử dụng phần mềm này."; this.buttonLogin.Visible = false; } if (ApplicationRoles.ExceptionMessage != null && ApplicationRoles.ExceptionMessage != "") { CustomMsgBox.Show(this, ApplicationRoles.ExceptionMessage, "Warning", MessageBoxButtons.OK); } this.buttonApplicationRoleRequired.Visible = !ApplicationRoles.Required; this.buttonApplicationRoleIgnored.Visible = ApplicationRoles.Required; } catch (Exception exception) { ExceptionHandlers.ShowExceptionMessageBox(this, exception); } }
static void Main() { const string applicationName = "TotalSmartCodingSolution"; bool createdNew; mutex = new Mutex(true, applicationName, out createdNew); if (!createdNew) { return; } //app is already running! Exiting the application Registries.ProductName = Application.ProductName.ToUpper(); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); AutoMapperConfig.SetupMappings(); //string ApplicationRoleRequired = "false"; //COMMENT ON 11-JUL-2018: NOT USE ApplicationRoleRequired. JUST REMOVE THIS COMMENT ONLY -> TO USE ApplicationRoleRequired (GET ApplicationRoleRequired OPTION FROM CONFIG SETTING BY THE FOLLOWING CommonConfigs.ReadSetting("ApplicationRoleRequired")). string ApplicationRoleRequired = CommonConfigs.ReadSetting("ApplicationRoleRequired"); ApplicationRoles.Required = true; ApplicationRoles.Name = ""; ApplicationRoles.Password = ""; bool applicationRoleRequired = false; if (bool.TryParse(ApplicationRoleRequired, out applicationRoleRequired)) { ApplicationRoles.Required = applicationRoleRequired; } TrialConnects trialConnects = new TrialConnects(); DialogResult trialConnectResult = trialConnects.Connected(); if (trialConnectResult == DialogResult.Yes) { Logon logon = new Logon(); if (logon.ShowDialog() == DialogResult.OK) { if (!GlobalEnums.CBPP) { LegalNotice legalNotice = new LegalNotice(); legalNotice.ShowDialog(); legalNotice.Dispose(); } if (GlobalVariables.FillingLineID == GlobalVariables.FillingLine.Smallpack || GlobalVariables.FillingLineID == GlobalVariables.FillingLine.Pail || GlobalVariables.FillingLineID == GlobalVariables.FillingLine.Medium4L || GlobalVariables.FillingLineID == GlobalVariables.FillingLine.Import || GlobalVariables.FillingLineID == GlobalVariables.FillingLine.Drum) { Application.Run(new MasterMDI(GlobalEnums.NmvnTaskID.SmartCoding, new SmartCoding())); } else { if (GlobalVariables.ConfigID == (int)GlobalVariables.FillingLine.Pickup) { Application.Run(new MasterMDI(GlobalEnums.NmvnTaskID.Pickups, new Pickups())); } else if (GlobalVariables.ConfigID == (int)GlobalVariables.FillingLine.GoodsIssue) { Application.Run(new MasterMDI(GlobalEnums.NmvnTaskID.GoodsIssues, new GoodsIssues())); } else { Application.Run(new MasterMDI()); } } } logon.Dispose(); } else if (trialConnectResult == DialogResult.No) { if (ApplicationRoles.Required) { ConnectServer connectServer = new ConnectServer(false); connectServer.ShowDialog(); connectServer.Dispose(); } else if (CustomMsgBox.Show(new Form(), "Do you want to specify new application role and password?", "Warning", MessageBoxButtons.YesNoCancel) == DialogResult.Yes) { ConnectServer connectServer = new ConnectServer(true); connectServer.ShowDialog(); connectServer.Dispose(); } } }
private void buttonLoginExit_Click(object sender, EventArgs e) { try { if (sender.Equals(this.buttonExit)) { this.DialogResult = DialogResult.Cancel; return; } if (this.comboUserID.SelectedIndex >= 0) { ActiveUser activeUser = this.comboUserID.SelectedItem as ActiveUser; if (activeUser != null) { ContextAttributes.LocalIPAddress = this.GetLocalIPAddress(); ContextAttributes.User = new UserInformation(activeUser.UserID, activeUser.OrganizationalUnitID, activeUser.LocationID, activeUser.LocationName, activeUser.UserName, activeUser.SecurityIdentifier, activeUser.FullyQualifiedUserName, activeUser.IsDatabaseAdmin, new DateTime()); if (this.comboFillingLineID.Visible && (this.comboFillingLineID.SelectedIndex < 0 || this.comboComportName.SelectedIndex < 0)) { throw new System.ArgumentException("Vui lòng chọn chuyền sản xuất (NOF1, NOF2, NOF...), và chọn đúng cổng COM để chạy phần mềm"); // || (this.comboFillingLineID.Enabled && (GlobalVariables.ProductionLine)this.comboFillingLineID.SelectedValue == GlobalVariables.ProductionLine.SERVER) } if (this.comboFillingLineID.Visible) { GlobalVariables.FillingLineID = (GlobalVariables.FillingLine) this.comboFillingLineID.SelectedValue; GlobalVariables.FillingLineCode = ((FillingLineBase)this.comboFillingLineID.SelectedItem).Code; GlobalVariables.FillingLineName = ((FillingLineBase)this.comboFillingLineID.SelectedItem).Name; } else { GlobalVariables.FillingLineID = GlobalVariables.FillingLine.None; } if (GlobalVariables.FillingLineID == GlobalVariables.FillingLine.Drum) { TotalBase.Enums.GlobalEnums.GlobalDrumWithDigit = this.checkGlobalDrumWithDigit.Checked; } GlobalVariables.ComportName = (string)this.comboComportName.SelectedValue; CommonConfigs.AddUpdateAppSetting("ConfigID", (GlobalVariables.ConfigID).ToString()); CommonConfigs.AddUpdateAppSetting("ComportName", GlobalVariables.ComportName); if (CommonConfigs.ReadSetting("ReportServerUrl") == "") { CommonConfigs.AddUpdateAppSetting("ReportServerUrl", GlobalVariables.ReportServerUrl); //INIT NEW Setting IN CONFIG FILE } GlobalVariables.ReportServerUrl = CommonConfigs.ReadSetting("ReportServerUrl"); this.VersionValidate(); #region EMPTY DATABASE if (false && this.checkEmptyData.Checked) { this.baseRepository.ExecuteStoreCommand("DELETE FROM WarehouseAdjustmentDetails", new ObjectParameter[] { }); this.baseRepository.ExecuteStoreCommand("DBCC CHECKIDENT ('WarehouseAdjustmentDetails', RESEED, 0)", new ObjectParameter[] { }); this.baseRepository.ExecuteStoreCommand("DELETE FROM WarehouseAdjustments", new ObjectParameter[] { }); this.baseRepository.ExecuteStoreCommand("DBCC CHECKIDENT ('WarehouseAdjustments', RESEED, 0)", new ObjectParameter[] { }); this.baseRepository.ExecuteStoreCommand("DELETE FROM GoodsIssueTransferDetails", new ObjectParameter[] { }); this.baseRepository.ExecuteStoreCommand("DBCC CHECKIDENT ('GoodsIssueTransferDetails', RESEED, 0)", new ObjectParameter[] { }); this.baseRepository.ExecuteStoreCommand("DELETE FROM GoodsIssueDetails", new ObjectParameter[] { }); this.baseRepository.ExecuteStoreCommand("DBCC CHECKIDENT ('GoodsIssueDetails', RESEED, 0)", new ObjectParameter[] { }); this.baseRepository.ExecuteStoreCommand("DELETE FROM GoodsIssues", new ObjectParameter[] { }); this.baseRepository.ExecuteStoreCommand("DBCC CHECKIDENT ('GoodsIssues', RESEED, 0)", new ObjectParameter[] { }); this.baseRepository.ExecuteStoreCommand("DELETE FROM TransferOrderDetails", new ObjectParameter[] { }); this.baseRepository.ExecuteStoreCommand("DBCC CHECKIDENT ('TransferOrderDetails', RESEED, 0)", new ObjectParameter[] { }); this.baseRepository.ExecuteStoreCommand("DELETE FROM TransferOrders", new ObjectParameter[] { }); this.baseRepository.ExecuteStoreCommand("DBCC CHECKIDENT ('TransferOrders', RESEED, 0)", new ObjectParameter[] { }); this.baseRepository.ExecuteStoreCommand("DELETE FROM DeliveryAdviceDetails", new ObjectParameter[] { }); this.baseRepository.ExecuteStoreCommand("DBCC CHECKIDENT ('DeliveryAdviceDetails', RESEED, 0)", new ObjectParameter[] { }); this.baseRepository.ExecuteStoreCommand("DELETE FROM DeliveryAdvices", new ObjectParameter[] { }); this.baseRepository.ExecuteStoreCommand("DBCC CHECKIDENT ('DeliveryAdvices', RESEED, 0)", new ObjectParameter[] { }); this.baseRepository.ExecuteStoreCommand("DELETE FROM SalesOrderDetails", new ObjectParameter[] { }); this.baseRepository.ExecuteStoreCommand("DBCC CHECKIDENT ('SalesOrderDetails', RESEED, 0)", new ObjectParameter[] { }); this.baseRepository.ExecuteStoreCommand("DELETE FROM SalesOrders", new ObjectParameter[] { }); this.baseRepository.ExecuteStoreCommand("DBCC CHECKIDENT ('SalesOrders', RESEED, 0)", new ObjectParameter[] { }); this.baseRepository.ExecuteStoreCommand("DELETE FROM GoodsReceiptDetails", new ObjectParameter[] { }); this.baseRepository.ExecuteStoreCommand("DBCC CHECKIDENT ('GoodsReceiptDetails', RESEED, 0)", new ObjectParameter[] { }); this.baseRepository.ExecuteStoreCommand("DELETE FROM GoodsReceipts", new ObjectParameter[] { }); this.baseRepository.ExecuteStoreCommand("DBCC CHECKIDENT ('GoodsReceipts', RESEED, 0)", new ObjectParameter[] { }); this.baseRepository.ExecuteStoreCommand("DELETE FROM PickupDetails", new ObjectParameter[] { }); this.baseRepository.ExecuteStoreCommand("DBCC CHECKIDENT ('PickupDetails', RESEED, 0)", new ObjectParameter[] { }); this.baseRepository.ExecuteStoreCommand("DELETE FROM Pickups", new ObjectParameter[] { }); this.baseRepository.ExecuteStoreCommand("DBCC CHECKIDENT ('Pickups', RESEED, 0)", new ObjectParameter[] { }); this.baseRepository.ExecuteStoreCommand("DELETE FROM Packs", new ObjectParameter[] { }); this.baseRepository.ExecuteStoreCommand("DBCC CHECKIDENT ('Packs', RESEED, 0)", new ObjectParameter[] { }); this.baseRepository.ExecuteStoreCommand("DELETE FROM Cartons", new ObjectParameter[] { }); this.baseRepository.ExecuteStoreCommand("DBCC CHECKIDENT ('Cartons', RESEED, 0)", new ObjectParameter[] { }); this.baseRepository.ExecuteStoreCommand("DELETE FROM Pallets", new ObjectParameter[] { }); this.baseRepository.ExecuteStoreCommand("DBCC CHECKIDENT ('Pallets', RESEED, 0)", new ObjectParameter[] { }); //this.baseRepository.ExecuteStoreCommand("DELETE FROM Batches", new ObjectParameter[] { }); //this.baseRepository.ExecuteStoreCommand("DBCC CHECKIDENT ('Batches', RESEED, 0)", new ObjectParameter[] { }); //this.baseRepository.ExecuteStoreCommand("DELETE FROM Commodities", new ObjectParameter[] { }); //this.baseRepository.ExecuteStoreCommand("DBCC CHECKIDENT ('Commodities', RESEED, 0)", new ObjectParameter[] { }); } #endregion if (this.baseRepository.AutoUpdates(sender.Equals(this.buttonLoginRestore))) { this.DialogResult = DialogResult.OK; } else { CustomMsgBox.Show(this, "The program on this computer must be updated to the latest version." + "\r\n" + "\r\n" + "Contact your administrator for more information.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Stop); this.buttonDownload_Click(this.buttonDownload, new EventArgs()); } SmartLogDTO.Init(); } } } catch (Exception exception) { ExceptionHandlers.ShowExceptionMessageBox(this, exception); this.DialogResult = DialogResult.None; } }