Exemple #1
0
    protected void btnDelete_Click(object sender, EventArgs e)
    {
        //是否已经存在
        LinQDBDataContext linqDB = new LinQDBDataContext();
        int i = linqDB.User.Where(p => this.txtName.Text == p.UserName).Count();

        if (i > 0)
        {
            User u = linqDB.User.Where(p => p.UserName == this.txtName.Text).Single();
            linqDB.User.DeleteOnSubmit(u);
            //更新对象
            linqDB.SubmitChanges();
        }
        else
        {
            Response.Write("<script language=javascript>window.alert('该用户已经存在')</script>");
            return;
        }
    }
Exemple #2
0
    protected void btnUpdate_Click(object sender, EventArgs e)
    {
        //是否已经存在
        LinQDBDataContext linqDB = new LinQDBDataContext();
        int i = linqDB.User.Where(p => this.txtName.Text == p.UserName).Count();

        if (i > 0)
        {
            User u = linqDB.User.Where(p => p.UserName == this.txtName.Text).Single();
            u.UserPassword = this.txtPwd.Text;
            u.RoleID       = int.Parse(this.rdlRole.SelectedValue.ToString());
            //更新对象
            linqDB.SubmitChanges();
        }
        else
        {
            Response.Write("<script language=javascript>window.alert('该用户已经存在')</script>");
            return;
        }
    }
Exemple #3
0
    protected void btnRegister_Click(object sender, EventArgs e)
    {
        //是否已经存在
        LinQDBDataContext linqDB = new LinQDBDataContext();
        int i = linqDB.User.Where(p => this.txtName.Text == p.UserName).Count();

        if (i > 0)
        {
            Response.Write("<script language=javascript>window.alert('该用户已经存在')</script>");
            return;
        }
        //注册用户
        //OR映射实现注册
        //将需要保存的信息封装在对象内部,然后OR映射将对象转化为SQL语句
        User u = new User();

        u.UserName     = this.txtName.Text;
        u.UserPassword = this.txtPwd.Text;
        u.RoleID       = int.Parse(this.rdlRole.SelectedValue.ToString());
        //在容器中添加一个新对象
        linqDB.User.InsertOnSubmit(u);
        //更新到数据库
        linqDB.SubmitChanges();
    }