示例#1
0
        private void btn_saveRole_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(this.tb_roleName.Text.Trim()))
            {
                this.SetError(tb_username, "角色名不能为空!");
                tb_username.Focus();
                return;
            }


            Roles role;

            if (isRoleModify)
            {
                role = new Roles(int.Parse(this.lb_roleId.Text), tb_roleName.Text.Trim(), GetRoleValue(), int.Parse(cb_adminFlag.CheckValue.ToString()));

                if (roleBll.UpdateRole(role))
                {
                    MessageBoxEx.Show("修改成功!", "修改角色");
                    this.DisableRoleForm();
                    InitRoleDropdownList();
                    InitRolenameList();
                }
                else
                {
                    MessageBoxEx.Show("修改失败!", "修改角色");
                }
            }
            else
            {
                role = new Roles(tb_roleName.Text.Trim(), GetRoleValue(), int.Parse(cb_adminFlag.CheckValue.ToString()));
                if (roleBll.Check(role.RoleName))
                {
                    if (roleBll.AddRole(role))
                    {
                        MessageBoxEx.Show("添加成功!", "添加角色");
                        this.DisableRoleForm();
                        this.ClearForm();
                        InitRolenameList();
                        InitRoleDropdownList();
                    }
                    else
                    {
                        MessageBoxEx.Show("添加失败!", "添加角色");
                    }
                }
            }
        }