public FillingLines() : base() { InitializeComponent(); this.toolstripChild = this.toolStripChildForm; this.fastListIndex = this.fastFillingLineIndex; this.fillingLineAPIs = new FillingLineAPIs(CommonNinject.Kernel.Get <IFillingLineAPIRepository>()); this.fillingLineViewModel = CommonNinject.Kernel.Get <FillingLineViewModel>(); this.fillingLineViewModel.PropertyChanged += new PropertyChangedEventHandler(ModelDTO_PropertyChanged); this.baseDTO = this.fillingLineViewModel; }
private void WizardMaster_Load(object sender, EventArgs e) { try { this.pickupViewModel.PropertyChanged += pickupDetailDTO_PropertyChanged; WarehouseAPIs warehouseAPIs = new WarehouseAPIs(CommonNinject.Kernel.Get <IWarehouseAPIRepository>()); this.combexWarehouseID.DataSource = warehouseAPIs.GetWarehouseBases(); this.combexWarehouseID.DisplayMember = CommonExpressions.PropertyName <WarehouseBase>(p => p.Name); this.combexWarehouseID.ValueMember = CommonExpressions.PropertyName <WarehouseBase>(p => p.WarehouseID); this.bindingWarehouseID = this.combexWarehouseID.DataBindings.Add("SelectedValue", this.pickupViewModel, CommonExpressions.PropertyName <PickupViewModel>(p => p.WarehouseID), true, DataSourceUpdateMode.OnPropertyChanged); FillingLineAPIs fillingLineAPIs = new FillingLineAPIs(CommonNinject.Kernel.Get <IFillingLineAPIRepository>()); this.combexFillingLineID.DataSource = fillingLineAPIs.GetFillingLineBases(); this.combexFillingLineID.DisplayMember = CommonExpressions.PropertyName <FillingLineBase>(p => p.NickName); this.combexFillingLineID.ValueMember = CommonExpressions.PropertyName <FillingLineBase>(p => p.FillingLineID); this.bindingFillingLineID = this.combexFillingLineID.DataBindings.Add("SelectedValue", this.pickupViewModel, CommonExpressions.PropertyName <PickupViewModel>(p => p.FillingLineID), true, DataSourceUpdateMode.OnPropertyChanged); EmployeeAPIs employeeAPIs = new EmployeeAPIs(CommonNinject.Kernel.Get <IEmployeeAPIRepository>()); this.combexForkliftDriverID.DataSource = employeeAPIs.GetEmployeeBases(ContextAttributes.User.UserID, (int)this.pickupViewModel.NMVNTaskID, (int)GlobalEnums.RoleID.Production); this.combexForkliftDriverID.DisplayMember = CommonExpressions.PropertyName <EmployeeBase>(p => p.Name); this.combexForkliftDriverID.ValueMember = CommonExpressions.PropertyName <EmployeeBase>(p => p.EmployeeID); this.bindingForkliftDriverID = this.combexForkliftDriverID.DataBindings.Add("SelectedValue", this.pickupViewModel, CommonExpressions.PropertyName <PickupViewModel>(p => p.ForkliftDriverID), true, DataSourceUpdateMode.OnPropertyChanged); this.combexStorekeeperID.DataSource = employeeAPIs.GetEmployeeBases(ContextAttributes.User.UserID, (int)this.pickupViewModel.NMVNTaskID, (int)GlobalEnums.RoleID.Logistic); this.combexStorekeeperID.DisplayMember = CommonExpressions.PropertyName <EmployeeBase>(p => p.Name); this.combexStorekeeperID.ValueMember = CommonExpressions.PropertyName <EmployeeBase>(p => p.EmployeeID); this.bindingStorekeeperID = this.combexStorekeeperID.DataBindings.Add("SelectedValue", this.pickupViewModel, CommonExpressions.PropertyName <PickupViewModel>(p => p.StorekeeperID), true, DataSourceUpdateMode.OnPropertyChanged); this.bindingRemarks = this.textexRemarks.DataBindings.Add("Text", this.pickupViewModel, "Remarks", true, DataSourceUpdateMode.OnPropertyChanged); this.bindingWarehouseID.BindingComplete += new BindingCompleteEventHandler(CommonControl_BindingComplete); this.bindingFillingLineID.BindingComplete += new BindingCompleteEventHandler(CommonControl_BindingComplete); this.bindingForkliftDriverID.BindingComplete += new BindingCompleteEventHandler(CommonControl_BindingComplete); this.bindingStorekeeperID.BindingComplete += new BindingCompleteEventHandler(CommonControl_BindingComplete); this.bindingRemarks.BindingComplete += new BindingCompleteEventHandler(CommonControl_BindingComplete); this.errorProviderMaster.DataSource = this.pickupViewModel; } catch (Exception exception) { ExceptionHandlers.ShowExceptionMessageBox(this, exception); } }
//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 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); } }