Ejemplo n.º 1
0
    private void GetRoles()
    {
        LinQDBDataContext linqDB = new LinQDBDataContext();

        this.rdlRole.DataSource     = linqDB.Role.ToList <Role>().Distinct();
        this.rdlRole.DataTextField  = "RoleName";
        this.rdlRole.DataValueField = "RoleID";
        this.rdlRole.DataBind();
        this.rdlRole.Items[0].Selected = true;
    }
Ejemplo n.º 2
0
    private void BinderToGridView()
    {
        //获取DataContext--获取映射文件--当我们对DB进行对象操作的时候,自动生成相对应的SQL语句
        LinQDBDataContext linqDB = new LinQDBDataContext();

        var result = linqDB.User;

        //要实现分页处理
        this.GridView1.DataSource = result;
        this.GridView1.DataBind();
    }
Ejemplo n.º 3
0
    private void BinderToGridView(int pageIndex, int pageSize)
    {
        //获取DataContext--获取映射文件--当我们对DB进行对象操作的时候,自动生成相对应的SQL语句
        LinQDBDataContext linqDB = new LinQDBDataContext();
        var result = linqDB.User;

        int pageTotal = (result.Count() + pageSize - 1) / pageSize;

        this.DropDownList1.DataSource = (System.Linq.Enumerable.Range(1, pageTotal)).ToList <int>();
        this.DropDownList1.DataBind();

        //要实现分页处理--跳过(pageIndex-1)*pageSize条记录,然后提取pageSize条记录
        this.GridView1.DataSource = result.Skip((pageIndex - 1) * pageSize).Take(pageSize);

        this.GridView1.DataBind();
    }
Ejemplo n.º 4
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;
        }
    }
Ejemplo n.º 5
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;
        }
    }
Ejemplo n.º 6
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();
    }