Ejemplo n.º 1
0
 protected void BtnAdd_Click(object sender, EventArgs e)
 {
     //验证必填信息
     if (this.ddlRoles.Text.Trim() == "")
     {
         ScriptHelper.SetAlert((Control)sender, GetTran("001113", "角色信息不能为空"));
     }
     else
     {
         if (this.ddlDepts.Text.Trim() == "")
         {
             ScriptHelper.SetAlert((Control)sender, GetTran("001114", "部门信息不能为空"));
         }
         else
         {
             if (this.txtName.Text.Trim() == "")
             {
                 ScriptHelper.SetAlert((Control)sender, GetTran("001116", "管理员姓名不能为空"));
             }
             else
             {
                 if (this.txtNumber.Text.Trim() == "")
                 {
                     ScriptHelper.SetAlert((Control)sender, GetTran("001117", "管理员编号不能为空"));
                 }
                 else if (this.txtNumber.Text.Trim().Length < 6)
                 {
                     ScriptHelper.SetAlert((Control)sender, GetTran("001163", "管理员编号必须6个字符以上"));
                 }
                 else
                 {
                     //取出当前登录管理员的编号
                     string number   = Session["Company"].ToString();
                     string manageId = BLL.CommonClass.CommonDataBLL.getManageID(1);
                     if (number != manageId)
                     {
                         if (!DeptRoleBLL.CheckAllot(number, int.Parse(this.ddlRoles.SelectedValue)))
                         {
                             ScriptHelper.SetAlert((Control)sender, GetTran("000975", "不能对该角色进行操作,没有权限!"));
                             return;
                         }
                     }
                     //根据输入信息构建管理员
                     ManageModel manager = new ManageModel();
                     if (!ManagerBLL.CheckNumber(txtNumber.Text.Trim()))
                     {
                         ScriptHelper.SetAlert((Control)sender, GetTran("001166", "该编号已经存在"));
                     }
                     else
                     {
                         manager.Number            = this.txtNumber.Text.Trim();
                         manager.Name              = txtName.Text.Trim();
                         manager.PermissionMan     = number.Trim();
                         manager.Post              = this.ddlRoles.SelectedItem.Text.Trim();
                         manager.Branch            = this.ddlDepts.SelectedItem.Text.Trim();
                         manager.RoleID            = int.Parse(this.ddlRoles.SelectedValue);
                         manager.BeginDate         = DateTime.UtcNow;
                         manager.Status            = 1;
                         manager.LastLoginDate     = DateTime.UtcNow;
                         manager.IsViewPermissions = int.Parse(this.RadioButtonList1.SelectedValue);
                         manager.IsRecommended     = int.Parse(this.RadioButtonList2.SelectedValue);
                         //获取管理员的默认密码
                         string password = ManagerBLL.GetPassword(this.txtNumber.Text.Trim());
                         //加密存储管理员的密码
                         manager.LoginPass = Encryption.Encryption.GetEncryptionPwd(this.txtNumber.Text.Trim(), this.txtNumber.Text.Trim());
                         //存储管理员信息到数据库
                         if (ManagerBLL.AddManage(manager, number) > 0)
                         {
                             //存储成功,给出提示
                             ScriptHelper.SetAlert((Control)sender, GetTran("001167", "添加管理员成功!"), "ManagerManage.aspx");
                         }
                         else
                         {
                             //存储失败,给出提示
                             ScriptHelper.SetAlert((Control)sender, GetTran("001169", "添加管理员失败!"));
                         }
                     }
                 }
             }
         }
     }
 }