예제 #1
0
        private void btnLogin_Click(object sender, EventArgs e)
        {
            string userName = textBoxUserName.Text.Trim();
            string userPwd  = textBoxPassword.Text;

            bool valid = false;

            if (userName == "admin" && userPwd == "qaz123")
            {
                IsAdmin    = true;
                Privileges = Privilege.ALL;
                valid      = true;
            }
            else
            {
                // 需要数据库验证
                IsAdmin = false;
                UserPrivilege privilege = privilegeManager.GetUser(userName, UserPrivilege.CreateMD5Hash(userPwd));
                if (privilege != null)
                {
                    valid      = true;
                    Privileges = privilege.Privileges;
                }
            }

            if (valid)
            {
                privilegeManager.LoggedUser  = userName;
                this.ParentForm.DialogResult = DialogResult.OK;
            }
            else
            {
                MessageBox.Show(@"账号密码错误,请重新输入");
            }
        }
예제 #2
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            AddAccountPanel addPanel = new AddAccountPanel(privilegeManager);

            addPanel.Dock = System.Windows.Forms.DockStyle.Fill;

            TemplateForm addForm = new TemplateForm(@"添加账户", addPanel.Size);

            addForm.AddContent(addPanel);
            addForm.MaximizeBox   = false;
            addForm.MinimizeBox   = false;
            addForm.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
            DialogResult result = addForm.ShowDialog();

            if (result == DialogResult.OK)
            {
                UserPrivilege privilege = new UserPrivilege();
                privilege.UserName   = addPanel.UserName;
                privilege.UserPwd    = UserPrivilege.CreateMD5Hash(addPanel.UserPwd);
                privilege.Privileges = Privilege.ALL;
                if (privilegeManager.AddUser(privilege))
                {
                    ListViewItem item = listBoxUsers.Items.Add(privilege.UserName);
                    item.Tag = privilege;
                }
            }
        }