Example #1
0
    public void LeaveWordfillgv()            //用户自定义的方法
    {
        string        SqlStr = "select * from tb_LeaveWord order by lTime desc";
        SqlConnection con    = new SqlConnection(EP.GetConStr());

        con.Open();                         //打开数据库连接
        SqlDataAdapter sda = new SqlDataAdapter(SqlStr, con);
        DataSet        ds  = new DataSet(); //声明一个DataSet的对象,并将该对象ds实例化

        sda.Fill(ds, "tb_LeaveWord");       //将tb_LeaveWord填充到数据库中
        this.GvLeaveWord.DataSource = ds;
        this.GvLeaveWord.DataBind();        //将数据绑定到GridView控件中
        for (int i = 0; i <= this.GvLeaveWord.Rows.Count - 1; i++)
        {
            DataRowView mydrv;  //声明一个DataRowView的对象
            string      gintro;

            if (this.GvLeaveWord.PageIndex == 0)
            {
                EP.GetConStr();

                mydrv  = ds.Tables["tb_LeaveWord"].DefaultView[i];
                gintro = Convert.ToString(mydrv["Title"]);
                this.GvLeaveWord.Rows[i].Cells[1].Text = ep.SubStr(gintro, 10);
            }
        }
        con.Close();
    }
    public void GongGaofillgv()            //用户自定义的方法
    {
        string        SqlStr = "select * from tb_GongGao order by GTime desc";
        SqlConnection con    = new SqlConnection(EP.GetConStr());

        con.Open();                         //打开数据库连接
        SqlDataAdapter sda = new SqlDataAdapter(SqlStr, con);
        DataSet        ds  = new DataSet(); //声明一个DataSet的对象,并将该对象ds实例化

        sda.Fill(ds, "tb_GongGao");         //将tb_GongGao填充到数据库中
        this.GvGongGao.DataSource = ds;
        this.GvGongGao.DataBind();          //将数据绑定到GridView控件中
        for (int i = 0; i <= this.GvGongGao.Rows.Count - 1; i++)
        {
            DataRowView mydrv;  //声明一个DataRowView的对象
            string      gintro; //声明一个字符串变量
            if (this.GvGongGao.PageIndex == 0)
            {
                EP.GetConStr();//调用EP类中的GetConStr()方法
                mydrv  = ds.Tables["tb_GongGao"].DefaultView[i];
                gintro = Convert.ToString(mydrv["content"]);
                this.GvGongGao.Rows[i].Cells[1].Text = ep.SubStr(gintro, 10);
            }
        }
        con.Close();//关闭数据库链接
    }
Example #3
0
    protected void dlContent_DeleteCommand(object source, DataListCommandEventArgs e)
    {
        string        ID     = this.dlContent.DataKeys[e.Item.ItemIndex].ToString(); //获取当前DataList控件列
        string        sqlstr = "delete from tb_tools where ID='" + Convert.ToInt32(ID) + "'";
        SqlConnection con    = new SqlConnection(EP.GetConStr());
        SqlCommand    com    = new SqlCommand(sqlstr, con);

        con.Open();
        com.ExecuteNonQuery();
        con.Close();
        this.bindDataList();
    }
    /// <summary>
    /// 该方法用于判断管理员输入的文本框的内容是否和数据库中的数据一致
    /// </summary>
    /// <param name="loginName">传递用户名</param>
    /// <param name="loginPwd">传递用户密码</param>
    /// <param name="loginrole">传递用户权限</param>
    /// <returns></returns>
    public int checkLogin(string loginName, string loginPwd, string loginrole)
    {
        SqlConnection con       = new SqlConnection(EP.GetConStr());
        SqlCommand    myCommand = new SqlCommand("select count(*) from tb_UserLogin where UserName=@loginName and UserPwd=@loginPwd and role=@loginrole", con);

        myCommand.Parameters.Add(new SqlParameter("@loginName", SqlDbType.VarChar, 50));
        myCommand.Parameters["@loginName"].Value = loginName;
        myCommand.Parameters.Add(new SqlParameter("@loginPwd", SqlDbType.VarChar, 50));
        myCommand.Parameters["@loginPwd"].Value = loginPwd;
        myCommand.Parameters.Add(new SqlParameter("@loginrole", SqlDbType.VarChar, 20));
        myCommand.Parameters["@loginrole"].Value = loginrole;
        myCommand.Connection.Open();            //打开数据库连接
        int i = (int)myCommand.ExecuteScalar(); //执行SQL语句

        myCommand.Connection.Close();           //关闭数据库连接
        return(i);
    }
Example #5
0
    /// <summary>
    /// 该方法在DataList控件中实现分页功能
    /// </summary>
    public void bindDataList()
    {
        //将labPage控件显示的页数赋值给整型变量curpage中
        int             curpage = Convert.ToInt32(this.labPage.Text);
        PagedDataSource ps      = new PagedDataSource();             //实例化一个PagedDataSource类对象
        SqlConnection   con     = new SqlConnection(EP.GetConStr()); //连接数据库

        con.Open();                                                  //打开数据库连接
        string         sqlstr    = "select * from tb_tools";
        SqlDataAdapter MyAdapter = new SqlDataAdapter(sqlstr, con);
        DataSet        ds        = new DataSet();//实例化一个对象

        MyAdapter.Fill(ds, "tb_tools");
        ps.DataSource           = ds.Tables["tb_tools"].DefaultView;
        ps.AllowPaging          = true;        //是否可以分页
        ps.PageSize             = 2;           //显示的数量
        ps.CurrentPageIndex     = curpage - 1; //取得当前页的页码
        this.lnkbtnUp.Enabled   = true;        //显示上一页按钮
        this.lnkbtnNext.Enabled = true;        //显示下一页按钮
        this.lnkbtnBack.Enabled = true;        //显示最后一页按钮
        this.lnkbtnOne.Enabled  = true;        //显示第一页按钮
        if (curpage == 1)
        {
            this.lnkbtnOne.Enabled = false; //不显示第一页按钮
            this.lnkbtnUp.Enabled  = false; //不显示上一页按钮
        }
        if (curpage == ps.PageCount)
        {
            this.lnkbtnNext.Enabled = false;                          //不显示下一页按钮
            this.lnkbtnBack.Enabled = false;                          //不显示最后一页按钮
        }
        this.labBackPage.Text       = Convert.ToString(ps.PageCount); //将分页的总页数赋值给labBackPage控件中
        this.dlContent.DataSource   = ps;                             //在dlContent控件中绑定ps分页数据源
        this.dlContent.DataKeyField = "ID";                           //将主键传递给dlContent控件中
        this.dlContent.DataBind();                                    //将数据源绑定到dbContent控件中
        con.Close();                                                  //关闭数据库连接
    }
Example #6
0
    public void bindDataList()
    {
        int             curpage = Convert.ToInt32(this.labPage.Text);
        PagedDataSource ps      = new PagedDataSource();
        SqlConnection   con     = new SqlConnection(EP.GetConStr());

        con.Open();
        string         sqlstr    = "select * from tb_tools";
        SqlDataAdapter MyAdapter = new SqlDataAdapter(sqlstr, con);
        DataSet        ds        = new DataSet();

        MyAdapter.Fill(ds, "tb_tools");
        ps.DataSource           = ds.Tables["tb_tools"].DefaultView;
        ps.AllowPaging          = true;        //是否可以分页
        ps.PageSize             = 2;           //显示的数量
        ps.CurrentPageIndex     = curpage - 1; //取得当前页的页码
        this.lnkbtnUp.Enabled   = true;
        this.lnkbtnNext.Enabled = true;
        this.lnkbtnBack.Enabled = true;
        this.lnkbtnOne.Enabled  = true;
        if (curpage == 1)
        {
            this.lnkbtnOne.Enabled = false; //不显示第一页按钮
            this.lnkbtnUp.Enabled  = false; //不显示上一页按钮
        }
        if (curpage == ps.PageCount)
        {
            this.lnkbtnNext.Enabled = false; //不显示下一页
            this.lnkbtnBack.Enabled = false; //不显示最后一页
        }
        this.labBackPage.Text       = Convert.ToString(ps.PageCount);
        this.dlContent.DataSource   = ps;
        this.dlContent.DataKeyField = "ID";
        this.dlContent.DataBind();
        con.Close();
    }