Ejemplo n.º 1
0
        /// <summary>
        /// 添加按钮事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Button1_Click(object sender, EventArgs e)
        {
            string    username = this.txtUserName.Text.Trim();
            string    realName = this.txtRealName.Text.Trim();
            string    pass     = this.txtPass.Text.Trim();
            string    md5Pass  = encrypt.EncryptMd5(pass);
            int       roleId   = Convert.ToInt32(this.ddlRole.SelectedValue);
            AdminUser item     = new AdminUser();

            item.username = username;
            item.realName = realName;
            item.password = pass;
            item.md5Pass  = md5Pass;
            item.roleId   = roleId;
            item.status   = 1;
            item.remark   = "";
            if (this.hidAdminId.Value != "")      //编辑
            {
                item.id = Convert.ToInt32(this.hidAdminId.Value);
                int num = AdminUserService.Update(item);
                if (num > 0)
                {
                    ScriptManager.RegisterStartupScript(this.UpdatePanel1, this.GetType(), "", "alert('更新成功!');location.href='manager.aspx'", true);
                }
                else
                {
                    ScriptManager.RegisterStartupScript(this.UpdatePanel1, this.GetType(), "", "alert('更新失败!');location.href='manager.aspx'", true);
                }
            }
            else
            {
                if (AdminUserService.Exists(item))
                {
                    ScriptManager.RegisterStartupScript(this.UpdatePanel1, this.GetType(), "", "alert('用户已经存在,请更换!');location.href='manager.aspx'", true);
                    return;
                }
                int num = AdminUserService.Add(item);
                if (num > 0)
                {
                    this.txtPass.Text      = "";
                    this.txtPassAgain.Text = "";
                    this.txtRealName.Text  = "";
                    this.txtUserName.Text  = "";

                    ScriptManager.RegisterStartupScript(this.UpdatePanel1, this.GetType(), "", "alert('添加成功!');location.href='manager.aspx'", true);
                }
            }
        }