コード例 #1
0
 private void AddUserAuthority(UserAuthority userAuthority, int rowIndex)
 {
     usrGrid.Rows[rowIndex].Cells[0].Value = userAuthority.Name.ToString();
     usrGrid.Rows[rowIndex].Cells[1].Value = userAuthority.Password;
     usrGrid.Rows[rowIndex].Cells[2].Value = userAuthority.UserType.Equals(UserType.Administrator) ? "管理员" : "操作员";
     usrGrid.Rows[rowIndex].Cells[3].Value = userAuthority.Remark;
 }
コード例 #2
0
ファイル: FormUser.cs プロジェクト: qum640/Code-Detection
        private void btnConfirm_Click(object sender, EventArgs e)
        {
            mIsInvalidClose = false;
            try
            {
                //this.DialogResult = DialogResult.Cancel;
                string userName = txtUserName.Text.Trim();
                if (string.IsNullOrEmpty(userName))
                {
                    txtUserName.Focus();
                    txtUserName.SelectAll();

                    MessageBox.Show("用户名不能为空!", "错误");
                    return;
                }
                string password = txtPassword.Text.Trim();
                if (password.Length != 6)
                {
                    txtPassword.Focus();
                    txtPassword.SelectAll();

                    MessageBox.Show("密码长度为6位!", "错误");
                    return;
                }
                if (UserConfiguration.GetInstance().User.ContainsKey(userName))
                {
                    mUserAuthority = UserConfiguration.GetInstance().User[userName];
                    if (password.Equals(mUserAuthority.Password))
                    {
                        MessageBox.Show("登录成功!", "提示");
                        this.DialogResult = DialogResult.OK;
                        this.Close();
                    }
                    else
                    {
                        txtPassword.Focus();
                        txtPassword.SelectAll();
                        MessageBox.Show("密码错误!", "错误");
                    }
                }
                else
                {
                    txtUserName.Focus();
                    txtUserName.SelectAll();
                    MessageBox.Show("无效用户名!", "错误");
                    return;
                }
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.ToString(), "错误");
            }
            finally
            {
                mIsInvalidClose = true;
            }
        }
コード例 #3
0
        private void UserLogin(bool isReset)
        {
            FormUser formUser = new FormUser(isReset);

            if (formUser.ShowDialog() == DialogResult.OK)
            {
                mUserAuthority = formUser.GetUserAuthority();
                RefreshUserAuthorityMenu();
            }
        }
コード例 #4
0
        private void InitializeGrid()
        {
            IDictionaryEnumerator enumerator = UserConfiguration.GetInstance().User.GetEnumerator();

            while (enumerator.MoveNext())
            {
                UserAuthority userAuthority = (UserAuthority)enumerator.Value;
                int           index         = this.usrGrid.Rows.Add();
                AddUserAuthority(userAuthority, index);
            }
            usrGrid.Update();
        }
コード例 #5
0
        public void CreateDefualtUserConfigurationFile()
        {
            UserAuthority administratorUser = new UserAuthority("admin", "111111", UserType.Administrator);
            //UserAuthority managerUser = new UserAuthority("manager", "02468", UserType.Manager);
            UserAuthority operatorUser = new UserAuthority("operator", "123456", UserType.Operator);

            mUser = new Dictionary <string, UserAuthority>();
            mUser.Add(administratorUser.Name, administratorUser);
            //mUser.Add(managerUser.Name, managerUser);
            mUser.Add(operatorUser.Name, operatorUser);
            SaveConfigurationFile();
        }
コード例 #6
0
 private void btnAdd_Click(object sender, EventArgs e)
 {
     try
     {
         FormAddUser formAddUser = new FormAddUser();
         if (formAddUser.ShowDialog() == DialogResult.OK)
         {
             UserAuthority userAuthority = formAddUser.UserAuthority;
             int           index         = this.usrGrid.Rows.Add();
             AddUserAuthority(userAuthority, index);
             MessageBox.Show("添加用户成功!", "提示");
         }
     }
     catch (System.Exception ex)
     {
         MessageBox.Show(ex.ToString(), "错误");
     }
 }
コード例 #7
0
        private void btnConfirm_Click(object sender, EventArgs e)
        {
            try
            {
                //this.DialogResult = DialogResult.Cancel;
                string userName = txtUserName.Text.Trim();
                if (string.IsNullOrEmpty(userName))
                {
                    txtUserName.Focus();
                    txtUserName.SelectAll();

                    MessageBox.Show("用户名不能为空!", "错误");
                    return;
                }
                //string oldPassword = txtOldPassword.Text.Trim();
                string newPassword = txtNewPassword.Text.Trim();

                //if (oldPassword.Length!=6)
                //{
                //    txtOldPassword.Focus();
                //    txtOldPassword.SelectAll();
                //    MessageBox.Show(mResources.GetString("txtPasswordLengthError"), mResources.GetString("error"));
                //    return;
                //}
                if (newPassword.Length != 6)
                {
                    txtNewPassword.Focus();
                    txtNewPassword.SelectAll();
                    MessageBox.Show("密码长度应为6位!", "错误");
                    return;
                }
                if (!UserConfiguration.GetInstance().User.ContainsKey(userName))
                {
                    mUserAuthority = new UserAuthority(userName, newPassword, (UserType)cmbUserType.SelectedIndex);
                    UserConfiguration.GetInstance().User.Add(mUserAuthority.Name, mUserAuthority);
                    //if (oldPassword.Equals(userAuthority.Password))
                    {
                        //userAuthority.Set(userName,newPassword,userAuthority.UserType);
                        //mUserConfiguration.SaveConfigurationFile();
                        //MessageBox.Show(mResources.GetString("txtChangePasswordSuccess"), mResources.GetString("hint"));
                        this.DialogResult = DialogResult.OK;
                        this.Close();
                    }

                    //else
                    //{
                    //    txtOldPassword.Focus();
                    //    txtOldPassword.SelectAll();

                    //    MessageBox.Show(mResources.GetString("txtWrongPassword"), mResources.GetString("error"));

                    //}
                }
                else
                {
                    txtUserName.Focus();
                    txtUserName.SelectAll();
                    MessageBox.Show("用户名错误!", "错误");
                    return;
                }
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.ToString(), "错误");
            }
        }
コード例 #8
0
        private void btnConfirm_Click(object sender, EventArgs e)
        {
            try
            {
                int myrow;
                for (int row = 0; row < usrGrid.Rows.Count - 1; row++)
                {
                    if (usrGrid.Rows[row].Cells[0].Value == null)
                    {
                        myrow = row + 1;
                        MessageBox.Show("第" + myrow.ToString() + "行输入的用户名为空,请重新输入!", "错误");
                        usrGrid.Rows[row].Selected = true;
                        return;
                    }
                    if (usrGrid.Rows[row].Cells[1].Value == null)
                    {
                        myrow = row + 1;
                        MessageBox.Show("第" + myrow.ToString() + "行输入的密码为空,请重新输入!", "错误");
                        usrGrid.Rows[row].Selected = true;
                        return;
                    }
                    if (usrGrid.Rows[row].Cells[2].Value == null)
                    {
                        myrow = row + 1;
                        MessageBox.Show("第" + myrow.ToString() + "行用户类型为空,请重新输入!", "错误");
                        usrGrid.Rows[row].Selected = true;
                        return;
                    }

                    string password = usrGrid.Rows[row].Cells[1].Value.ToString();
                    if (password.Length != 6)
                    {
                        myrow = row + 1;
                        MessageBox.Show("第" + myrow.ToString() + "行输入的密码长度必须会6位,请重新输入!", "错误");
                        usrGrid.Rows[row].Selected = true;
                        return;
                    }
                    string strusrname = usrGrid.Rows[row].Cells[0].Value.ToString();
                    strusrname.Trim();

                    for (int i = 0; i < row; i++)
                    {
                        string prename = usrGrid.Rows[i].Cells[0].Value.ToString();
                        if (prename.Trim().Equals(strusrname))
                        {
                            myrow = row + 1;
                            MessageBox.Show("第" + myrow.ToString() + "行输入的用户名已存在,请重新输入!", "错误");
                            usrGrid.Rows[row].Selected = true;
                            return;
                        }
                    }
                }

                UserConfiguration.GetInstance().User.Clear();
                for (int row = 0; row < usrGrid.Rows.Count - 1; row++)
                {
                    string        name     = usrGrid.Rows[row].Cells[0].Value.ToString();
                    string        password = usrGrid.Rows[row].Cells[1].Value.ToString();
                    UserType      type     = usrGrid.Rows[row].Cells[2].Value.ToString().Equals("管理员") ? UserType.Administrator : UserType.Operator;
                    UserAuthority user     = new UserAuthority(name, password, type);
                    user.Remark = "";
                    if (usrGrid.Rows[row].Cells[3].Value != null)
                    {
                        user.Remark = usrGrid.Rows[row].Cells[3].Value.ToString();
                    }
                    UserConfiguration.GetInstance().User.Add(user.Name, user);
                }
                UserConfiguration.GetInstance().SaveConfigurationFile();
                MessageBox.Show("保存用户权限成功!", "提示");
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.ToString(), "错误");
            }
        }