Exemple #1
0
        public UserAdd(UserAPIs userAPIs)
        {
            InitializeComponent();

            try
            {
                List <DomainUser> allUsers = new List <DomainUser>();
                PrincipalContext  ctx      = new PrincipalContext(ContextType.Domain, "chevronvn.com"); //, "OU=SomeOU,dc=YourCompany,dc=com"// create your domain context and define the OU container to search in
                UserPrincipal     qbeUser  = new UserPrincipal(ctx);                                    // define a "query-by-example" principal - here, we search for a UserPrincipal (user)
                PrincipalSearcher srch     = new PrincipalSearcher(qbeUser);                            // create your principal searcher passing in the QBE principal

                foreach (var found in srch.FindAll())                                                   // find all matches
                {                                                                                       // do whatever here - "found" is of type "Principal" - it could be user, group, computer.....
                    allUsers.Add(new DomainUser()
                    {
                        FirstName = found.DisplayName, LastName = found.Name, UserName = this.GetWindowsIdentityName(found.DistinguishedName), SecurityIdentifier = found.Sid.Value
                    });
                }

                this.combexUserID.DataSource    = allUsers;
                this.combexUserID.DisplayMember = CommonExpressions.PropertyName <DomainUser>(p => p.UserName);
                this.combexUserID.ValueMember   = CommonExpressions.PropertyName <DomainUser>(p => p.UserName);
                this.bindingUserName            = this.combexUserID.DataBindings.Add("SelectedValue", this, CommonExpressions.PropertyName <DomainUser>(p => p.UserName), true, DataSourceUpdateMode.OnPropertyChanged);

                this.userAPIs = userAPIs;
                this.combexOrganizationalUnitID.DataSource    = this.userAPIs.GetOrganizationalUnitIndexes();
                this.combexOrganizationalUnitID.DisplayMember = CommonExpressions.PropertyName <OrganizationalUnitIndex>(p => p.LocationOrganizationalUnitName);
                this.combexOrganizationalUnitID.ValueMember   = CommonExpressions.PropertyName <OrganizationalUnitIndex>(p => p.OrganizationalUnitID);
                this.bindingOrganizationalUnitID = this.combexOrganizationalUnitID.DataBindings.Add("SelectedValue", this, CommonExpressions.PropertyName <OrganizationalUnitIndex>(p => p.OrganizationalUnitID), true, DataSourceUpdateMode.OnPropertyChanged);
            }
            catch (Exception exception)
            {
                ExceptionHandlers.ShowExceptionMessageBox(this, exception);
            }
        }
Exemple #2
0
        public UserReferences()
        {
            InitializeComponent();
            try
            {
                this.UserID = ContextAttributes.User.UserID;

                ModuleAPIs moduleAPIs = new ModuleAPIs(CommonNinject.Kernel.Get <IModuleAPIRepository>());

                this.fastNMVNTasks.ShowGroups           = true;
                this.fastNMVNTasks.AboutToCreateGroups += fastNMVNTasks_AboutToCreateGroups;
                this.fastNMVNTasks.SetObjects(moduleAPIs.GetModuleDetailIndexes());
                this.fastNMVNTasks.Sort(this.olvModuleName, SortOrder.Ascending);

                this.userAPIs = new UserAPIs(CommonNinject.Kernel.Get <IUserAPIRepository>());
                this.comboUserID.ComboBox.DataSource    = this.userAPIs.GetUserIndexes();
                this.comboUserID.ComboBox.DisplayMember = CommonExpressions.PropertyName <UserIndex>(p => p.FullyQualifiedUserName);
                this.comboUserID.ComboBox.ValueMember   = CommonExpressions.PropertyName <UserIndex>(p => p.UserID);
                this.bindingUserID = this.comboUserID.ComboBox.DataBindings.Add("SelectedValue", this, CommonExpressions.PropertyName <UserIndex>(p => p.UserID), true, DataSourceUpdateMode.OnPropertyChanged);


                this.gridexUserAccessControl.AutoGenerateColumns = false;
                this.gridexUserAccessControl.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;

                this.bindingListUserAccessControls              = new BindingList <UserAccessControlDTO>();
                this.gridexUserAccessControl.DataSource         = this.bindingListUserAccessControls;
                this.bindingListUserAccessControls.ListChanged += bindingListUserAccessControls_ListChanged;

                StackedHeaderDecorator stackedHeaderDecorator = new StackedHeaderDecorator(this.gridexUserAccessControl);
            }
            catch (Exception exception)
            {
                ExceptionHandlers.ShowExceptionMessageBox(this, exception);
            }
        }
Exemple #3
0
        private void buttonChange_Click(object sender, EventArgs e)
        {
            try
            {
                if (this.textBoxCurrentPassword.Visible)
                {
                    this.textBoxCurrentPassword.Visible = false;
                    this.textBoxNewPassword.Visible     = true;
                    this.textBoxConfirmPassword.Visible = true;
                    this.labelCurrentPassword.Visible   = false;
                    this.labelNewPassword.Visible       = true;
                    this.labelConfirmPassword.Visible   = true;
                    this.SetButtonEnabled();
                    this.DialogResult = DialogResult.None;
                }
                else
                {
                    string passwordHash = this.textBoxNewPassword.Text;
                    if (passwordHash != "")
                    {
                        passwordHash = SecurePassword.Encrypt(passwordHash);
                    }

                    UserAPIs userAPIs = new UserAPIs(CommonNinject.Kernel.Get <IUserAPIRepository>());
                    if (userAPIs.SetPasswordHash(ContextAttributes.User.UserID, passwordHash) == 1)
                    {
                        this.DialogResult = DialogResult.Yes;
                    }
                }
            }
            catch (Exception exception)
            {
                ExceptionHandlers.ShowExceptionMessageBox(this, exception);
            }
        }
Exemple #4
0
        private void PublicAuthenticationPassword_Load(object sender, EventArgs e)
        {
            try
            {
                UserAPIs userAPIs     = new UserAPIs(CommonNinject.Kernel.Get <IUserAPIRepository>());
                string   passwordHash = userAPIs.GetPasswordHash(ContextAttributes.User.UserID);
                if (passwordHash != "")
                {
                    passwordHash = SecurePassword.Decrypt(passwordHash);
                }

                this.textBoxCurrentPassword.Tag = passwordHash;

                this.SetButtonEnabled();
            }
            catch (Exception exception)
            {
                ExceptionHandlers.ShowExceptionMessageBox(this, exception);
            }
        }
Exemple #5
0
        //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);
            }
        }
Exemple #6
0
        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;
            }
        }
Exemple #7
0
        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);
            }
        }
        public UserRegister(UserAPIs userAPIs, OrganizationalUnitAPIs organizationalUnitAPIs)
        {
            InitializeComponent();

            try
            {
                List <DomainUser> allUsers = new List <DomainUser>();

                //userAPIs.UpdateUserName("S-1-5-21-3775195119-1044016383-3360809325-1001", "NMVN\vendor");

                if (true)
                {
                    PrincipalContext  ctx     = new PrincipalContext(ContextType.Domain, "chevronvn.com"); //, "OU=SomeOU,dc=YourCompany,dc=com"// create your domain context and define the OU container to search in
                    UserPrincipal     qbeUser = new UserPrincipal(ctx);                                    // define a "query-by-example" principal - here, we search for a UserPrincipal (user)
                    PrincipalSearcher srch    = new PrincipalSearcher(qbeUser);                            // create your principal searcher passing in the QBE principal

                    foreach (var found in srch.FindAll())                                                  // find all matches
                    {                                                                                      // do whatever here - "found" is of type "Principal" - it could be user, group, computer.....
                        if (found.Sid.Value != null && found.Sid.Value != "" && found.SamAccountName != null && found.SamAccountName != "")
                        {
                            userAPIs.UpdateUserName(found.Sid.Value, found.SamAccountName);
                        }

                        allUsers.Add(new DomainUser()
                        {
                            FirstName = "", LastName = "", UserName = found.SamAccountName, SecurityIdentifier = found.Sid.Value
                        });                                                                                                                                      //found.UserPrincipalName: the same as SamAccountName, but with @chevron.com
                    }
                }
                else
                {
                    for (int i = 1; i <= 5; i++)
                    {
                        allUsers.Add(new DomainUser()
                        {
                            FirstName = "FIST NAME" + i.ToString(), LastName = "FIST NAME" + i.ToString(), UserName = "******", SecurityIdentifier = "S-1-5-21-2907738014-1953812902-1740135539-2131"
                        });
                    }
                }

                this.combexUserID.DataSource          = allUsers;
                this.combexUserID.DisplayMember       = CommonExpressions.PropertyName <DomainUser>(p => p.UserName);
                this.combexUserID.ValueMember         = CommonExpressions.PropertyName <DomainUser>(p => p.UserName);
                this.bindingUserName                  = this.combexUserID.DataBindings.Add("SelectedValue", this, CommonExpressions.PropertyName <DomainUser>(p => p.UserName), true, DataSourceUpdateMode.OnPropertyChanged);
                this.bindingUserName.BindingComplete += binding_BindingComplete;

                this.userAPIs = userAPIs;
                this.organizationalUnitAPIs = organizationalUnitAPIs;

                this.combexOrganizationalUnitID.DataSource    = this.organizationalUnitAPIs.GetOrganizationalUnitIndexes();
                this.combexOrganizationalUnitID.DisplayMember = CommonExpressions.PropertyName <OrganizationalUnitIndex>(p => p.LocationOrganizationalUnitName);
                this.combexOrganizationalUnitID.ValueMember   = CommonExpressions.PropertyName <OrganizationalUnitIndex>(p => p.OrganizationalUnitID);
                this.bindingOrganizationalUnitID = this.combexOrganizationalUnitID.DataBindings.Add("SelectedValue", this, CommonExpressions.PropertyName <OrganizationalUnitIndex>(p => p.OrganizationalUnitID), true, DataSourceUpdateMode.OnPropertyChanged);
                this.bindingOrganizationalUnitID.BindingComplete += binding_BindingComplete;

                this.SameOUAccessLevel = GlobalEnums.AccessLevel.NoAccess;
                this.combexSameOUAccessLevels.DataSource = new List <ACL>()
                {
                    new ACL()
                    {
                        AccessLevelID = GlobalEnums.AccessLevel.NoAccess
                    }, new ACL()
                    {
                        AccessLevelID = GlobalEnums.AccessLevel.Readable
                    }, new ACL()
                    {
                        AccessLevelID = GlobalEnums.AccessLevel.Editable
                    }
                };
                this.combexSameOUAccessLevels.DisplayMember = CommonExpressions.PropertyName <ACL>(p => p.AccessLevelName);
                this.combexSameOUAccessLevels.ValueMember   = CommonExpressions.PropertyName <ACL>(p => p.AccessLevelID);
                this.combexSameOUAccessLevels.DataBindings.Add("SelectedValue", this, "SameOUAccessLevel", true, DataSourceUpdateMode.OnPropertyChanged);

                this.SameLocationAccessLevel = GlobalEnums.AccessLevel.NoAccess;
                this.combexSameLocationAccessLevels.DataSource = new List <ACL>()
                {
                    new ACL()
                    {
                        AccessLevelID = GlobalEnums.AccessLevel.NoAccess
                    }, new ACL()
                    {
                        AccessLevelID = GlobalEnums.AccessLevel.Readable
                    }, new ACL()
                    {
                        AccessLevelID = GlobalEnums.AccessLevel.Editable
                    }
                };
                this.combexSameLocationAccessLevels.DisplayMember = CommonExpressions.PropertyName <ACL>(p => p.AccessLevelName);
                this.combexSameLocationAccessLevels.ValueMember   = CommonExpressions.PropertyName <ACL>(p => p.AccessLevelID);
                this.combexSameLocationAccessLevels.DataBindings.Add("SelectedValue", this, "SameLocationAccessLevel", true, DataSourceUpdateMode.OnPropertyChanged);

                this.OtherOUAccessLevel = GlobalEnums.AccessLevel.NoAccess;
                this.combexOtherOUAccessLevels.DataSource = new List <ACL>()
                {
                    new ACL()
                    {
                        AccessLevelID = GlobalEnums.AccessLevel.NoAccess
                    }, new ACL()
                    {
                        AccessLevelID = GlobalEnums.AccessLevel.Readable
                    }
                };
                this.combexOtherOUAccessLevels.DisplayMember = CommonExpressions.PropertyName <ACL>(p => p.AccessLevelName);
                this.combexOtherOUAccessLevels.ValueMember   = CommonExpressions.PropertyName <ACL>(p => p.AccessLevelID);
                this.combexOtherOUAccessLevels.DataBindings.Add("SelectedValue", this, "OtherOUAccessLevel", true, DataSourceUpdateMode.OnPropertyChanged);
            }
            catch (Exception exception)
            {
                ExceptionHandlers.ShowExceptionMessageBox(this, exception);
            }
        }