示例#1
0
        //下拉框选择逻辑
        private void cmbRole_SelectedIndexChanged(object sender, EventArgs e)
        {
            int              roleId   = cmbRole.SelectedIndex + 2;
            string           roleName = cmbRole.Text;
            string           oldName  = string.Empty;
            DataGridViewCell cell     = dgvAuth.CurrentCell;

            if (cell != null)
            {
                try
                {
                    oldName    = cell.Value.ToString();
                    cell.Value = roleName;
                    int row = cell.RowIndex;
                    dgvAuth.Rows[row].Cells[2].Value = roleId;
                    Db.Authority auth = new Db.Authority();
                    auth.Id   = Convert.ToInt32(dtAuth.Rows[row]["id"]);
                    auth.Name = dtAuth.Rows[row]["name"].ToString();
                    Role role = new Role(roleId, roleName);
                    auth.Role = role;
                    if (auth.Update())
                    {
                        LogMan.Log2Sqlite(new Log(LogLevel.Info, EventType.权限管理, "修改权限:" + dtAuth.Rows[row]["name"].ToString() + "(" + oldName + "->" + roleName + ")", DateTime.Now));
                    }
                }
                catch (Exception ex)
                {
                    LogMan.Log2File(null, ex);
                }
            }
        }
 /// <summary>
 /// Handles the Click event of the mrbAdd control.
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
 private void mrbAdd_Click(object sender, EventArgs e)
 {
     try
     {
         string name    = this.msltUser.Text.Trim();
         string pwd     = this.msltPwd.Text.Trim();
         string confirm = this.msltConfirm.Text.Trim();
         int    roleId  = cmbRole.SelectedIndex + 2;
         if (string.IsNullOrEmpty(name))
         {
             MessageBox.Show("用户名不能为空!", ConstMsg.Msg00, MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
         }
         else if (string.IsNullOrEmpty(pwd) || string.IsNullOrEmpty(confirm))
         {
             MessageBox.Show("密码不能为空!", ConstMsg.Msg00, MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
         }
         else if (pwd != confirm)
         {
             MessageBox.Show("两次输入密码不一致!", ConstMsg.Msg00, MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
         }
         else
         {
             User user = User.Find(name);
             if (user != null)
             {
                 MessageBox.Show("用户已存在!", ConstMsg.Msg00, MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
             }
             else
             {
                 user          = new User();
                 user.UserName = name;
                 user.Password = SunGolden.Encryption.DEncrypt.Encrypt(pwd);
                 user.RoleId   = roleId;
                 if (!user.Insert())
                 {
                     MessageBox.Show("添加用户失败!", ConstMsg.Msg00, MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                 }
                 else
                 {
                     MessageBox.Show("添加用户成功!", ConstMsg.Msg00, MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                     LogMan.Log2Sqlite(new Log(LogLevel.Info, EventType.用户管理, "添加用户:" + name, DateTime.Now));
                     this.DialogResult = DialogResult.OK;
                 }
             }
         }
     }
     catch (Exception ex)
     {
         LogMan.Log2File(null, ex);
     }
 }
        private void mrbOK_Click(object sender, EventArgs e)
        {
            int newRoleId = cmbRole.SelectedIndex + 2;

            try
            {
                if (newRoleId != selectedUser.RoleId)
                {
                    selectedUser.RoleId = newRoleId;
                    selectedUser.Update(true);
                    LogMan.Log2Sqlite(new Log(LogLevel.Info, EventType.用户管理, "修改用户角色:" + selectedUser.UserName + "(" + selectedUser.Role.Name + "->" + cmbRole.Text + ")", DateTime.Now));
                    this.DialogResult = DialogResult.OK;
                }
            }
            catch (Exception ex)
            {
                LogMan.Log2File(null, ex);
            }
        }
示例#4
0
 private void mrbLogin_Click(object sender, EventArgs e)
 {
     if (!Login())
     {
         return;
     }
     if (this.mcbRember.Checked)
     {
         //打开配置文件
         Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
         config.AppSettings.Settings["User"].Value     = this.msltUser.Text;
         config.AppSettings.Settings["Password"].Value = SunGolden.Encryption.DEncrypt.Encrypt(this.msltPwd.Text);
         //保存配置
         config.Save();
         ConfigurationManager.RefreshSection("AppSettings");
     }
     LogMan.Log2Sqlite(new Log(LogLevel.Info, EventType.用户管理, "用户登陆:" + this.msltUser.Text, DateTime.Now));
     this.DialogResult = DialogResult.OK;
 }
 private void mrbAdd_Click(object sender, EventArgs e)
 {
     if (DialogResult.OK == MessageBox.Show("确定要修改密码吗?", ConstMsg.Msg00, MessageBoxButtons.OKCancel, MessageBoxIcon.Question))
     {
         string oldPwd    = this.msltOldPwd.Text;
         string newPwd    = this.msltNewPwd.Text;
         string confimPwd = this.msltConfimPwd.Text;
         if (string.IsNullOrEmpty(oldPwd) || SunGolden.Encryption.DEncrypt.Encrypt(oldPwd) != ConstDef.curUser.Password)
         {
             MessageBox.Show("原密码错误,请重新输入!", ConstMsg.Msg00, MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
         }
         else if (string.IsNullOrEmpty(newPwd) || string.IsNullOrEmpty(confimPwd) || newPwd != confimPwd)
         {
             MessageBox.Show("新密码为空或不一致,请重新输入!", ConstMsg.Msg00, MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
         }
         else
         {
             ConstDef.curUser.Password = SunGolden.Encryption.DEncrypt.Encrypt(newPwd);
             try
             {
                 if (ConstDef.curUser.Update(true))
                 {
                     //消息提示
                     MessageBox.Show("修改成功,下次登陆请使用新密码。", ConstMsg.Msg00, MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                     //记录操作日志
                     LogMan.Log2Sqlite(new Log(LogLevel.Info, EventType.用户管理, "修改密码", DateTime.Now));
                 }
             }
             catch (Exception ex)
             {
                 //提示错误信息
                 MessageBox.Show("修改失败:" + ex.Message, ConstMsg.Msg00, MessageBoxButtons.OK, MessageBoxIcon.Error);
                 //记录错误日志
                 Db.LogMan.Log2File(null, ex);
             }
         }
     }
 }
 private void EditUser(User user, string opration)
 {
     if (opration == "删除")
     {
         if (user.RoleId == 1)
         {
             MessageBox.Show("不能删除超级管理员账户", ConstMsg.Msg00, MessageBoxButtons.OK, MessageBoxIcon.Warning);
         }
         else if (user.RoleId == 2)
         {
             if (ConstDef.curUser.RoleId == 1)
             {
                 if (DialogResult.OK == MessageBox.Show(string.Format("删除账户:{0} ?", user.UserName), ConstMsg.Msg00, MessageBoxButtons.OKCancel, MessageBoxIcon.Question))
                 {
                     user.Delete();
                     LogMan.Log2Sqlite(new Log(LogLevel.Info, EventType.用户管理, "删除用户:" + user.UserName, DateTime.Now));
                     LoadUsers("");
                 }
             }
             else
             {
                 if (user.UserName != ConstDef.curUser.UserName)
                 {
                     MessageBox.Show("权限不足:删除其他管理员账户请使用超级管理员登陆!", ConstMsg.Msg00, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                 }
                 else
                 {
                     if (DialogResult.OK == MessageBox.Show("已使用所选账户登陆,是否删除?", ConstMsg.Msg00, MessageBoxButtons.OKCancel, MessageBoxIcon.Question))
                     {
                         ConstDef.curUser.Delete();
                         LogMan.Log2Sqlite(new Log(LogLevel.Info, EventType.用户管理, "删除用户:" + user.UserName, DateTime.Now));
                         Application.Restart();
                     }
                 }
             }
         }
         else
         {
             if (DialogResult.OK == MessageBox.Show(string.Format("删除账户:{0} ?", user.UserName), ConstMsg.Msg00, MessageBoxButtons.OKCancel, MessageBoxIcon.Question))
             {
                 user.Delete();
                 LogMan.Log2Sqlite(new Log(LogLevel.Info, EventType.用户管理, "删除用户:" + user.UserName, DateTime.Now));
                 LoadUsers("");
             }
         }
     }
     else if (opration == "编辑")
     {
         if (user.RoleId == 1)
         {
             MessageBox.Show("不能编辑超级管理员账户", ConstMsg.Msg00, MessageBoxButtons.OK, MessageBoxIcon.Warning);
         }
         else if (user.RoleId == 2)
         {
             if (ConstDef.curUser.RoleId == 1)
             {
                 //su编辑管理员角色
                 if (DialogResult.OK == new frmEditUser(user).ShowDialog())
                 {
                     LoadUsers("");
                 }
             }
             else
             {
                 if (user.UserName != ConstDef.curUser.UserName)
                 {
                     MessageBox.Show("权限不足:编辑其他管理员账户请使用超级管理员登陆!", ConstMsg.Msg00, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                 }
                 else
                 {
                     //管理员用户编辑自己角色
                     if (DialogResult.OK == new frmEditUser(user).ShowDialog())
                     {
                         if (user.UserName == ConstDef.curUser.UserName)
                         {
                             ConstDef.curUser = User.Find(user.UserName);
                         }
                         if (ConstDef.curUser.RoleId > 2)
                         {
                             this.Close();
                         }
                         else
                         {
                             LoadUsers("");
                         }
                     }
                 }
             }
         }
         //管理员编辑普通用户
         else
         {
             if (DialogResult.OK == new frmEditUser(user).ShowDialog())
             {
                 LoadUsers("");
             }
         }
     }
 }