Example #1
0
    /// <summary>
    /// 添加,修改
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnUpdate_Click(object sender, EventArgs e)
    {
        if (btnUpdate.Text == "添加")
        {
            Users model = new Users();
            model.U_Name     = txtName.Value.Trim();
            model.U_Pwd      = txtPwd.Value.Trim();
            model.U_RealName = txtRealName.Value.Trim();
            model.U_Sex      = ddlSex.SelectedValue;
            model.U_Type     = ddlType.SelectedValue;

            if (!UsersBLL.IsTrue(model.U_Name))
            {
                if (UsersBLL.AddUsers(model) > 0)
                {
                    this.Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('添加成功!');window.location.replace('UsersManage.aspx');</script>");
                    return;
                }
                else
                {
                    this.Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('添加失败!');</script>");
                    return;
                }
            }
            else
            {
                this.Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('该账号已存在!');</script>");
                return;
            }
        }
        else
        {
            Users model = UsersBLL.GetIdByUsers(Convert.ToInt32(Request.QueryString["id"]));
            model.U_Name     = txtName.Value.Trim();
            model.U_Pwd      = txtPwd.Value.Trim();
            model.U_RealName = txtRealName.Value.Trim();
            model.U_Sex      = ddlSex.SelectedValue;
            model.U_Type     = ddlType.SelectedValue;

            if (!UsersBLL.IsTrue(model.U_Name, model.U_Id))
            {
                if (UsersBLL.UpdateUsers(model) > 0)
                {
                    this.Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('修改成功!');window.location.replace('UsersManage.aspx');</script>");
                    return;
                }
                else
                {
                    this.Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('修改失败!');</script>");
                    return;
                }
            }
            else
            {
                this.Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('该账号已存在!');</script>");
                return;
            }
        }
    }
Example #2
0
    protected void btnUpdate_Click(object sender, EventArgs e)
    {
        if (btnUpdate.Text == "添加")
        {
            Users model = new Users();
            model.DeptId   = Convert.ToInt32(ddlDeptId.SelectedValue.Trim());
            model.Email    = txtEmail.Value.Trim();
            model.Phone    = txtPhone.Value.Trim();
            model.Pwd      = txtPwd.Value.Trim();
            model.RealName = txtRealName.Value.Trim();
            model.Remark   = txtRemark.Value.Trim();
            model.RoleId   = Convert.ToInt32(ddlRoleId.SelectedValue);
            model.UserName = txtUserName.Value.Trim();

            if (UsersBLL.AddUsers(model) > 0)
            {
                this.Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('添加成功!');window.location.replace('UsersManage.aspx');</script>");
                return;
            }
            else
            {
                this.Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('添加失败!');</script>");
                return;
            }
        }
        else
        {
            Users model = UsersBLL.GetIdByUsers(Convert.ToInt32(Request.QueryString["id"]));

            model.DeptId   = Convert.ToInt32(ddlDeptId.SelectedValue.Trim());
            model.Email    = txtEmail.Value.Trim();
            model.Phone    = txtPhone.Value.Trim();
            model.Pwd      = txtPwd.Value.Trim();
            model.RealName = txtRealName.Value.Trim();
            model.Remark   = txtRemark.Value.Trim();
            model.RoleId   = Convert.ToInt32(ddlRoleId.SelectedValue);
            model.UserName = txtUserName.Value.Trim();


            if (UsersBLL.UpdateUsers(model) > 0)
            {
                this.Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('修改成功!');window.location.replace('UsersManage.aspx');</script>");
                return;
            }
            else
            {
                this.Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('修改失败!');</script>");
                return;
            }
        }
    }