⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 useradd.aspx.cs

📁 基于C#语言的一个企业客户管理数据库系统开发案例的源代码 ,很实用
💻 CS
字号:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Security.Cryptography;
public partial class UserAdd : System.Web.UI.Page
{
    public int Type; //定义变量TypeValues来保存代表用户身份的值(0代表管理员,1代表工程师,2代表普通用户)
    protected void Page_Load(object sender, EventArgs e)
    {

        if (Session["flag"] == null)
        {
            Response.Redirect("../Login.aspx");
        }
        if (!IsPostBack)
        {
            this.Panel1.Visible = true;
            this.Panel2.Visible = false;
            //使用代码添加DropDownList控件的项
            this.ddlRole.Items.Add(new ListItem("选择角色"));
            this.ddlRole.Items.Add(new ListItem("管理员"));
            this.ddlRole.Items.Add(new ListItem("工程师"));
            this.ddlRole.Items.Add(new ListItem("普通员工"));
            this.Bindgv();//绑定Bindgv()方法
        }
        if (Operation.userName != "")
        {
            this.txtUserName.Text = Operation.userName;
            Operation.userName = "";
        }

    }
    public void Bindgv()
    {
        DataSet ds = Operation.ReDataSet("BindUsersInfo");
        this.gvUsersInfo.DataSource = ds;
        this.gvUsersInfo.DataKeyNames = new string[] { "ID" };
        this.gvUsersInfo.DataBind();
    }
    protected void gvUsersInfo_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            if (e.Row.Cells[2].Text == "0")
            {
                e.Row.Cells[2].Text = "男";
            }
            else
            {
                e.Row.Cells[2].Text = "女";
            }
            if (e.Row.Cells[4].Text == "0")
            {
                e.Row.Cells[4].Text = "管理员";
            }
            if (e.Row.Cells[4].Text == "1")
            {
                e.Row.Cells[4].Text = "工程师";
            }
            if(e.Row.Cells[4].Text == "2")
            {
                e.Row.Cells[4].Text = "普通员工";
            }
            ((LinkButton)(e.Row.Cells[5].Controls[0])).Attributes.Add("onclick", "return comfirm('你确定要删除吗?')"); //确定删除提示信息
        }
    }
    protected void gvUsersInfo_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        int ID = Convert.ToInt32(this.gvUsersInfo.DataKeys[e.RowIndex].Value.ToString());//取得在GridWiew中选中行的ID
        Operation.ExSql("DelUsersInfo", ID);
        this.Bindgv();
    }
    protected void btnClickOk_Click(object sender, EventArgs e)
    {
        string UserName = this.txtUserName.Text.Trim();
        string Password = this.txtPassword.Text.Trim();
        string Telephone = this.txtPhone.Text.Trim();
        int Sex;
        if (this.radButtonMan.Checked)//使用单选按钮选择性别
        {
            Sex = '0';//选择“男”的时候把性别状态值设为0
        }
        else
        {
            Sex = '1';//选择“女”的时候把性别状态值设为1
        }
        if (this.ddlRole.SelectedValue == "管理员")
        {
            Type = 0;
        }
        if (this.ddlRole.SelectedValue == "工程师")
        {
            Type = 1;
        }
        if (this.ddlRole.SelectedValue == "普通员工")
        {
            Type = 2;
        }
        if (this.ddlRole.SelectedValue == "选择角色")
        {
            Response.Write("<script>alert('请选择添加用户的身份!')</script>");
        }

        if (Operation.InsertUserInfo(UserName, Password, Sex, Telephone, Type))//调用InsertUserInfo方法来插入用户信息
        {
            Response.Write("<script>alert('插入成功!');location='UserAdd.aspx'</script>");
            this.clear();//清空编辑框
        }
        else
        {
            Response.Write("<script>alert('插入失败!';location='UserAdd.aspx')</script>");
        }

    }

    //清空编辑框
    public void clear()
    {
        this.txtUserName.Text = "";
        this.txtPassword.Text = "";
        this.txtPhone.Text = "";
        this.txtPasswordAgain.Text = "";
        this.radButtonMan.Checked = true;
        this.ddlRole.SelectedIndex = -1;
    }
  
   
    protected void lnkbtnUserName_Click(object sender, EventArgs e)
    {
        Operation.userName = this.txtUserName.Text.Trim();
        Operation oper = new Operation();
        if (oper.CheckUserName(Operation.userName))
        {
            Response.Write("<script>alert('该用户名没有被使用');location='UserAdd.aspx'</script>");
        }
        else
        {
            Response.Write("<script>alert('该用户名已经被使用');location='UserAdd.aspx'</script>");
            this.txtUserName.Text = "";//清空文本内容
        }
    }


    protected void lnkbtnBianji_Click(object sender, EventArgs e)
    {
        this.Panel2.Visible = true;
        this.Panel1.Visible = false;
    }
    protected void gvUsersInfo_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        this.gvUsersInfo.PageIndex = e.NewPageIndex;
        this.Bindgv();
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -