Chinaunix首页 | 论坛 | 博客
  • 博客访问: 72251
  • 博文数量: 42
  • 博客积分: 2025
  • 博客等级: 大尉
  • 技术积分: 437
  • 用 户 组: 普通用户
  • 注册时间: 2009-05-03 12:17
文章分类

全部博文(42)

文章存档

2010年(12)

2009年(30)

我的朋友

分类:

2009-11-25 15:44:14

写文章
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 MySql.Data.MySqlClient;
public partial class User_UserLogAdd : System.Web.UI.Page
{
    MySqlCommand mycomm;
    //MySqlDataReader dr;
    string strconn = ConfigurationManager.AppSettings["Mysqlstudb"];
    MySqlConnection myco;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            string IDUSE = Session["UserName"].ToString();
            HiddenField1.Value = IDUSE;
            Label3.Visible = false;
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        string Title_ = TextBox1.Text;
       
        string Sort_ = DropDownList1.SelectedValue;
        string WriteTime_ = System.DateTime.Now.ToString();
        string Content_ = Editor1.Text;
        string IDUSE_ = HiddenField1.Value;
      
        if (Title == "")
        {           
          
                   TextBox1.Focus();
                   Label3.Visible = true;
              Label3.Text = "标题不能为空";
        }
           
  
        else
        {
            if (CheckBox1.Checked == true && CheckBox2.Checked == true)
            {
                  myco = new MySqlConnection(strconn);
                  myco.Open();
                 
                  string sql = "insert into logtable(Title,Sort,WriteTime,Content,IDUSE,IsISO,IsPopup) values";
                  sql += "('" + Title_ + "','" + Sort_ + "','" + WriteTime_ + "','" + Content_ + "','" + IDUSE_ + "',true,true)";
                  mycomm = new MySqlCommand(sql, myco);
                  mycomm.CommandType = CommandType.Text;
                 mycomm.ExecuteNonQuery();
                 myco.Dispose();
                 myco.Close();
                 Response.Redirect("UserLogAddOK.aspx");
            }
            else if(CheckBox1.Checked == true && CheckBox2.Checked == false)
            {
                myco = new MySqlConnection(strconn);
                myco.Open();
                string sql = "insert into logtable(Title,Sort,WriteTime,Content,IDUSE,IsISO,IsPopup) values";
                sql += "('" + Title_ + "','" + Sort_ + "','" + WriteTime_ + "','" + Content_ + "','" + IDUSE_ + "',true,false)";
                mycomm = new MySqlCommand(sql, myco);
                mycomm.CommandType = CommandType.Text;
                mycomm.ExecuteNonQuery();
                myco.Dispose();
                myco.Close();
                Response.Redirect("UserLogAddOK.aspx");
            }
            else if (CheckBox1.Checked == false && CheckBox2.Checked == true)
            {
                myco = new MySqlConnection(strconn);
                myco.Open();
                string sql = "insert into logtable(Title,Sort,WriteTime,Content,IDUSE,IsISO,IsPopup) values";
                sql += "('" + Title_ + "','" + Sort_ + "','" + WriteTime_ + "','" + Content_ + "','" + IDUSE_ + "',false,true)";
                mycomm = new MySqlCommand(sql, myco);
                mycomm.CommandType = CommandType.Text;
                mycomm.ExecuteNonQuery();
                myco.Dispose();
                myco.Close();
                Response.Redirect("UserLogAddOK.aspx");
            }
            else if (CheckBox1.Checked == false && CheckBox2.Checked == false)
            {
                myco = new MySqlConnection(strconn);
                myco.Open();
                string sql = "insert into logtable(Title,Sort,WriteTime,Content,IDUSE,IsISO,IsPopup) values";
                sql += "('" + Title_ + "','" + Sort_ + "','" + WriteTime_ + "','" + Content_ + "','" + IDUSE_ + "',false,false)";
                mycomm = new MySqlCommand(sql, myco);
                mycomm.CommandType = CommandType.Text;
                mycomm.ExecuteNonQuery();
                myco.Dispose();
                myco.Close();
                Response.Redirect("UserLogAddOK.aspx");
            }
    }
}
    protected void Button2_Click(object sender, EventArgs e)
    {
        Response.Redirect("UserLogMan.aspx");
    }
}
 
更新文章
 
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 MySql.Data.MySqlClient;
public partial class User_UserLogUpdate : System.Web.UI.Page
{
    private MySqlCommand mycomm;
    private MySqlDataReader dr;
    private string strconn = ConfigurationManager.AppSettings["Mysqlstudb"];
    private MySqlConnection myco;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            myco = new MySqlConnection(strconn);
            myco.Open();
            string IDUSE_ = Session["UserName"].ToString();
            HiddenField1.Value = IDUSE_;
            string IDRizhi_ = Request.QueryString["IDRizhi"];
            HiddenField2.Value = IDRizhi_;
            string sql = "select * from logtable where IDRizhi='" + IDRizhi_ + "'";
            mycomm = new MySqlCommand(sql, myco);
            dr = mycomm.ExecuteReader();
            while (dr.Read())
            {
                TextBox1.Text = dr["Title"].ToString();
                Editor1.Text = dr["Content"].ToString();
            }
            mycomm.Dispose();
            myco.Close();
            Label3.Visible = false;
        }

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        string Title_ = TextBox1.Text;
        string Sort_ = DropDownList1.SelectedValue;
        string WriteTime_ = System.DateTime.Now.ToString();
        string Content_ = Editor1.Text;
        string IDUSE_ = HiddenField1.Value;
        string IDRizhi_ = HiddenField2.Value;
        if (Title_ == "")
        {
            TextBox1.Focus();
            Label3.Visible = true;
            Label3.Text = "标题不能为空";
        }
        else
        {
            if (CheckBox1.Checked == true && CheckBox2.Checked == true)
            {

                myco = new MySqlConnection(strconn);
                myco.Open();
                string sql1="update logtable set ";
                sql1 +="Title='"+ Title_ + "',Sort='"+ Sort_ +"' ,Content='"+ Content_ +"',";
                sql1 += "IDUSE ='" + IDUSE_ + "',IsISO=true ,IsPopup=true ";
                sql1 += "where IDRizhi=" + IDRizhi_ + "";
                mycomm = new MySqlCommand(sql1, myco);
                mycomm.CommandType = CommandType.Text;
                mycomm.ExecuteReader();
                myco.Dispose();
                myco.Close();
                Response.Redirect("UserLogUpdateOK.aspx");
            }
            else if (CheckBox1.Checked == true && CheckBox2.Checked == false)
            {
                myco = new MySqlConnection(strconn);
                myco.Open();
                string sql1 = "update logtable set ";
                sql1 += "Title='" + Title_ + "',Sort='" + Sort_ + "' ,Content='" + Content_ + "',";
                sql1 += "IDUSE ='" + IDUSE_ + "',IsISO=true ,IsPopup=false ";
                sql1 += "where IDRizhi=" + IDRizhi_ + "";
                mycomm = new MySqlCommand(sql1, myco);
                mycomm.CommandType = CommandType.Text;
                mycomm.ExecuteReader();
                myco.Dispose();
                myco.Close();
                Response.Redirect("UserLogUpdateOK.aspx");
            }
            else if (CheckBox1.Checked == false && CheckBox2.Checked == true)
            {
                myco = new MySqlConnection(strconn);
                myco.Open();
                string sql1 = "update logtable set ";
                sql1 += "Title='" + Title_ + "',Sort='" + Sort_ + "' ,Content='" + Content_ + "',";
                sql1 += "IDUSE ='" + IDUSE_ + "',IsISO=false ,IsPopup=false ";
                sql1 += "where IDRizhi=" + IDRizhi_ + "";
                mycomm = new MySqlCommand(sql1, myco);
                mycomm.CommandType = CommandType.Text;
                mycomm.ExecuteReader();
                myco.Dispose();
                myco.Close();
                Response.Redirect("UserLogUpdateOK.aspx");
            }
            else if (CheckBox1.Checked == false && CheckBox2.Checked == false)
            {
                myco = new MySqlConnection(strconn);
                myco.Open();
                string sql1 = "update logtable set ";
                sql1 += "Title='" + Title_ + "',Sort='" + Sort_ + "' ,Content='" + Content_ + "',";
                sql1 += "IDUSE ='" + IDUSE_ + "',IsISO=false ,IsPopup=false ";
                sql1 += "where IDRizhi=" + IDRizhi_ + "";
                mycomm = new MySqlCommand(sql1, myco);
                mycomm.CommandType = CommandType.Text;
                mycomm.ExecuteReader();
                myco.Dispose();
                myco.Close();
                Response.Redirect("UserLogUpdateOK.aspx");
            }

        }
//        string Title = TextBox1.Text;
//        string Sort = DropDownList1.Text;
//        string content = Editor1.Text;
//        int IDRizhi = System.Convert.ToInt32(HiddenField1.Value);
//        myco = new MySqlConnection(strconn);
//        myco.Open();
//        mycomm = new MySqlCommand("RizhiUpdate", myco);
//        mycomm.CommandType = CommandType.StoredProcedure;
//        MySqlParameter[] para = new MySqlParameter[]{
//               new MySqlParameter("@Title_",MySqlDbType.VarChar ,50),
//               new MySqlParameter("@Sort_",MySqlDbType.VarChar ,20),
//               new MySqlParameter("@Content_",MySqlDbType.MediumText),
//               new MySqlParameter("@IDRizhi_",MySqlDbType.Int32,11)
//};
//        para[0].Value = Title;
//        para[1].Value = Sort;
       
//        para[2].Value = content;
//        para[3].Value = IDRizhi;
//        mycomm.Parameters.AddRange(para);
//        mycomm.ExecuteNonQuery();
//        mycomm.Dispose();
//        myco.Close();
//        Response.Redirect("UserLogUpdateOK.aspx");
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        Response.Redirect("UserLogMan.aspx");
    }
}
 
管理页面
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 MySql.Data.MySqlClient;
public partial class User_UserLogMan : System.Web.UI.Page
{
    private MySqlCommand mycomm;
        private string strconn = ConfigurationManager.AppSettings["Mysqlstudb"];
    private MySqlConnection myco;
    private MySqlDataReader dr;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            HiddenField1.Value = Session["UserName"].ToString();
            Label1.Text = HiddenField1.Value;
           
            Get_RiZhi();
 
        }
       
    }
    protected void gt_kind(DropDownList ddl, string kindtype)   //获取查询分类情况
    {
        myco = new MySqlConnection(strconn);
        myco.Open();
        mycomm = new MySqlCommand("kind_pro", myco);
        mycomm.CommandType = CommandType.StoredProcedure;
        MySqlParameter para = new MySqlParameter("@kindtype", MySqlDbType.VarChar, 10);
        para.Value = kindtype;
        mycomm.Parameters.Add(para);
        dr = mycomm.ExecuteReader();
 
        while (dr.Read())
        {
            ddl.Items.Add(new ListItem(dr["kind_name"].ToString(), dr["kind_id"].ToString()));
        }
 
        dr.Close();
        mycomm.Dispose();
        myco.Close();
    }
    protected void Button_IndexFirst_Click(object sender, EventArgs e)
    {
        pageIndexLab.Text = "1";
        if (pageCountLab.Text.Equals("0"))
        {
            pageIndexLab.Text = "0";
        }
        Get_RiZhi();
    }

    protected void Button_IndexPrevious_Click(object sender, EventArgs e)
    {
        int pageIndex = System.Convert.ToInt32(pageIndexLab.Text.ToString());
        pageIndex--;
        if (pageIndex < 0)
        {
            pageIndex = 0;
        }
        pageIndexLab.Text = pageIndex.ToString();
        Get_RiZhi();
    }
    protected void Button_IndexNext_Click(object sender, EventArgs e)
    {
        int pageIndex = System.Convert.ToInt32(pageIndexLab.Text.ToString());
        int pageCount = System.Convert.ToInt32(pageCountLab.Text.ToString());
        pageIndex++;
        if (pageIndex > pageCount)
        {
            pageIndex = pageCount;
        }
        pageIndexLab.Text = pageIndex.ToString();
        Get_RiZhi();
    }
    protected void Button_IndexLast_Click(object sender, EventArgs e)
    {
        int pageIndex = System.Convert.ToInt32(pageIndexLab.Text.ToString());
        int pageCount = System.Convert.ToInt32(pageCountLab.Text.ToString());
        pageIndex = pageCount;
        pageIndexLab.Text = pageIndex.ToString();
        Get_RiZhi();
    }
    protected void DropDownpage_SelectedIndexChanged(object sender, EventArgs e)  //下拉转到第几页
    {
        pageIndexLab.Text = DropDownpage.SelectedValue;
        Get_RiZhi();
    }
 
 
    protected void Get_RiZhi()
    {
        string iduse = Session["UserName"].ToString();
        string IDRizhi_ = Request.QueryString["IDRizhi"];
        int pageSize = 5;
        int pageCount = 1;
        int pageCountMod = 0;
        int doCount = 0;
        int pageIndex = System.Convert.ToInt32(pageIndexLab.Text.ToString());
        string strWhere = "";
        string fldName = "";
        string tbName = "";
        fldName = " * ";
        tbName = " logtable ";
     
       strWhere = "where iduse='" + iduse + "'";
  
     
        myco = new MySqlConnection(strconn);
        myco.Open();
        mycomm = new MySqlCommand("GetRecordCount", myco);
        mycomm.CommandType = CommandType.StoredProcedure;
        MySqlParameter[] para = new MySqlParameter[]{
            new MySqlParameter("@tbName",MySqlDbType.VarChar,800),
            new MySqlParameter("@strWhere",MySqlDbType.VarChar,500)};
        para[0].Value = tbName;
        para[1].Value = strWhere;
        mycomm.Parameters.AddRange(para);
        dr = mycomm.ExecuteReader();
        while (dr.Read())
        {
            pageCount = System.Convert.ToInt32(dr["countStr"].ToString());
            recordLab.Text = pageCount.ToString();
            pageCountMod = pageCount % pageSize;
            pageCount = pageCount / pageSize;
            if (pageCount == 0)
            {
                pageCount++;
            }
            else
            {
                if (pageCountMod != 0)
                {
                    pageCount++;
                }
            }
            pageCountLab.Text = pageCount.ToString();
        }
        if (pageIndex == 0)
        {
            pageIndex++;
        }
        dr.Close();
        mycomm.Dispose();
        mycomm = new MySqlCommand("GetRecordAsPage", myco);
        mycomm.CommandType = CommandType.StoredProcedure;
        para.Initialize();
        para = new MySqlParameter[]{
            new MySqlParameter("@tbName",MySqlDbType.VarChar,800),
            new MySqlParameter("@fldName",MySqlDbType.VarChar,1000),
            new MySqlParameter("@strWhere",MySqlDbType.VarChar,500),
            new MySqlParameter("@pageIndex",MySqlDbType.Int32),
            new MySqlParameter("@pageSize",MySqlDbType.Int32),
            new MySqlParameter("@orderType",MySqlDbType.Int16),
            new MySqlParameter("@sortName",MySqlDbType.VarChar,50)};
        para[0].Value = tbName;
        para[1].Value = fldName;
        para[2].Value = strWhere;
        para[3].Value = pageIndex;
        para[4].Value = pageSize;
        para[5].Value = 1;                             //0:asc 1:desc降序
        para[6].Value = "WriteTime";
        mycomm.Parameters.AddRange(para);

        MySqlDataAdapter myadap = new MySqlDataAdapter(mycomm);
        DataSet ds = new DataSet();
        myadap.Fill(ds);
        DataList1.DataSource = ds.Tables[0];
        DataList1.DataKeyField = "IDRizhi";
        DataList1.DataBind();
        myadap.Dispose();
        mycomm.Dispose();
        myco.Close();
        DropDownpage.Items.Clear();
        if (pageCount != 0)
        {
            doCount = 0;
            while (doCount < pageCount)
            {
                doCount++;
                DropDownpage.Items.Add(new ListItem(doCount.ToString() + "页", doCount.ToString()));
            }
        }
        if (pageIndex == 1)
        {
            Button_IndexFirst.Enabled = false;
            Button_IndexPrevious.Enabled = false;
            Button_IndexNext.Enabled = true;
            Button_IndexLast.Enabled = true;
        }
        else if (pageIndex == pageCount)
        {
            Button_IndexFirst.Enabled = true;
            Button_IndexPrevious.Enabled = true;
            Button_IndexNext.Enabled = false;
            Button_IndexLast.Enabled = false;
        }
        else
        {
            Button_IndexFirst.Enabled = true;
            Button_IndexPrevious.Enabled = true;
            Button_IndexNext.Enabled = true;
            Button_IndexLast.Enabled = true;
        }
        if (pageCount == 0 || pageCount == 1)
        {
            pageIndex = pageCount;
            Button_IndexFirst.Enabled = false;
            Button_IndexPrevious.Enabled = false;
            Button_IndexNext.Enabled = false;
            Button_IndexLast.Enabled = false;
            DropDownpage.Enabled = false;
        }
        else
        {
            DropDownpage.Enabled = true;
        }
        pageIndexLab.Text = pageIndex.ToString();
        if (pageIndex != 0)
        {
            DropDownpage.SelectedItem.Selected = false;
            DropDownpage.Items.FindByValue(pageIndex.ToString()).Selected = true;
        }
    }

    protected void DataList1_ItemDataBound(object source, DataListItemEventArgs e)
    {
        ((LinkButton)e.Item.Controls[0].FindControl("LinkButton1")).Attributes.Add("onclick", "return confirm('您确定要删除吗?')");
    }
    protected void DataList1_DeleteCommand(object source, DataListCommandEventArgs e)
    {
        int IDRizhi_ = Int32.Parse(DataList1.DataKeys[e.Item.ItemIndex].ToString());
        myco = new MySqlConnection(strconn);
        myco.Open();
        string sql = "delete  from logtable where IDRizhi=" + IDRizhi_ + "";
        mycomm = new MySqlCommand(sql, myco);
        dr = mycomm.ExecuteReader();
        mycomm.Dispose();
        Get_RiZhi();
    }

}
查询页面
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 MySql.Data.MySqlClient;
public partial class User_UserLogQue : System.Web.UI.Page
{
    private MySqlCommand mycomm;
    private MySqlDataReader dr;
    private string strconn = ConfigurationManager.AppSettings["Mysqlstudb"];
    private MySqlConnection myco;
    protected void Page_Load(object sender, EventArgs e)
    {  
        //Button_IndexFirst.Visible = false;
        //Button_IndexPrevious.Visible = false;
        //Button_IndexNext.Visible = false;
        //Label11.Visible = false;
        //recordLab.Visible = false;
        //Label4.Visible = false;
        //pageIndexLab.Visible = false;
        //Label6.Visible = false;
        //pageCountLab.Visible = false;
        //Label10.Visible = false;
        //DropDownpage.Visible = false;
        //Button_IndexLast.Visible = false;
        //DataList1.Visible = false;

        if (!IsPostBack)
        {
            gt_kind(DropDownList1, "rizhi");
            start();
        }

    }
    protected void start()
    {
        string kind_id = DropDownList1.SelectedValue;
       
        if (kind_id.Equals("A7"))  // 按标题查询
        {
            TextBox1.Visible = true;
            CodefanCalendar1.Visible = false;
            CodefanCalendar2.Visible = false;
            Label1.Visible = false;
           
        }
        else if (kind_id.Equals("A8")) //按日期查询
        {
            TextBox1.Visible = false;
            CodefanCalendar1.Visible = true;
            CodefanCalendar2.Visible = true;
            Label1.Visible = true;
        }
    }
    protected void gt_kind(DropDownList ddl, string kindtype)   //获取查询分类情况
    {
        myco = new MySqlConnection(strconn);
        myco.Open();
        mycomm = new MySqlCommand("kind_pro", myco);
        mycomm.CommandType = CommandType.StoredProcedure;
        MySqlParameter para = new MySqlParameter("@kindtype", MySqlDbType.VarChar, 10);
        para.Value = kindtype;
        mycomm.Parameters.Add(para);
        dr = mycomm.ExecuteReader();

       
        while (dr.Read())
        {
            ddl.Items.Add(new ListItem(dr["kind_name"].ToString(), dr["kind_id"].ToString()));
        }
 
        dr.Close();
        mycomm.Dispose();
        myco.Close();
    }
 
    protected void DataList1_ItemDataBound(object source, DataListItemEventArgs e)
    {
        ((LinkButton)e.Item.Controls[0].FindControl("LinkButton1")).Attributes.Add("onclick", "return confirm('您确定要删除吗?')");
    }
    protected void DataList1_DeleteCommand(object source, DataListCommandEventArgs e)
    {
        int IDRizhi_ = Int32.Parse(DataList1.DataKeys[e.Item.ItemIndex].ToString());
        myco = new MySqlConnection(strconn);
        myco.Open();
        string sql = "delete  from logtable where IDRizhi=" + IDRizhi_ + "";
        mycomm = new MySqlCommand(sql, myco);
        dr = mycomm.ExecuteReader();
        mycomm.Dispose();
        Get_RiZhi();
      
    }
   
    protected void Button_IndexFirst_Click(object sender, EventArgs e)
    {
        pageIndexLab.Text = "1";
        if (pageCountLab.Text.Equals("0"))
        {
            pageIndexLab.Text = "0";
        }
        Get_RiZhi();
    }

    protected void Button_IndexPrevious_Click(object sender, EventArgs e)
    {
        int pageIndex = System.Convert.ToInt32(pageIndexLab.Text.ToString());
        pageIndex--;
        if (pageIndex < 0)
        {
            pageIndex = 0;
        }
        pageIndexLab.Text = pageIndex.ToString();
        Get_RiZhi();
    }
    protected void Button_IndexNext_Click(object sender, EventArgs e)
    {
        int pageIndex = System.Convert.ToInt32(pageIndexLab.Text.ToString());
        int pageCount = System.Convert.ToInt32(pageCountLab.Text.ToString());
        pageIndex++;
        if (pageIndex > pageCount)
        {
            pageIndex = pageCount;
        }
        pageIndexLab.Text = pageIndex.ToString();
        Get_RiZhi();
    }
    protected void Button_IndexLast_Click(object sender, EventArgs e)
    {
        int pageIndex = System.Convert.ToInt32(pageIndexLab.Text.ToString());
        int pageCount = System.Convert.ToInt32(pageCountLab.Text.ToString());
        pageIndex = pageCount;
        pageIndexLab.Text = pageIndex.ToString();
        Get_RiZhi();
    }
    protected void DropDownpage_SelectedIndexChanged(object sender, EventArgs e)  //下拉转到第几页
    {
        pageIndexLab.Text = DropDownpage.SelectedValue;
        Get_RiZhi();
    }
 
 
    protected void Get_RiZhi()
    {
        string iduse = Session["UserName"].ToString();
        string kind_id = DropDownList1.SelectedValue;
        string time1 = CodefanCalendar1.Text;
        string time2 = CodefanCalendar2.Text;
        int pageSize = 5;
        int pageCount = 1;
        int pageCountMod = 0;
        int doCount = 0;
        int pageIndex = System.Convert.ToInt32(pageIndexLab.Text.ToString());
        string strWhere = "";
        string fldName = "";
        string tbName = "";
        string title = "%" + TextBox1.Text + "%";
       
 
        fldName = " * ";
        tbName = " logtable ";
       
        if (kind_id.Equals("A7"))
        {  
            strWhere = " where iduse='" + iduse + "'";
            strWhere += " and Title like '" + title + "'";
        }
        else if (kind_id.Equals("A8"))
        {
            if (CodefanCalendar1.Text.ToString().Equals(CodefanCalendar2.Text.ToString()))
            {
                strWhere = " where iduse='" + iduse + "'";
                string sametime = "%" + CodefanCalendar1.Text + "%";
                strWhere += " and WriteTime like '" + sametime + "'";
               
            }

        //   strWhere = " where iduse='" + iduse + "'";
        //strWhere+=" and WriteTime between '" + time1 + "' and  '" + time2 + "'";

        }
        myco = new MySqlConnection(strconn);
        myco.Open();
        mycomm = new MySqlCommand("GetRecordCount", myco);
        mycomm.CommandType = CommandType.StoredProcedure;
        MySqlParameter[] para = new MySqlParameter[]{
            new MySqlParameter("@tbName",MySqlDbType.VarChar,800),
            new MySqlParameter("@strWhere",MySqlDbType.VarChar,500)};
        para[0].Value = tbName;
        para[1].Value = strWhere;
        mycomm.Parameters.AddRange(para);
        dr = mycomm.ExecuteReader();
       
        while (dr.Read())
        {
           
            pageCount = System.Convert.ToInt32(dr["countStr"].ToString());
            recordLab.Text = pageCount.ToString();
            pageCountMod = pageCount % pageSize;
            pageCount = pageCount / pageSize;
            if (pageCount == 0)
            {
                pageCount++;
            }
            else
            {
                if (pageCountMod != 0)
                {
                    pageCount++;
                }
            }
            pageCountLab.Text = pageCount.ToString();
        }
        if (pageIndex == 0)
        {
            pageIndex++;
        }
        dr.Close();
        mycomm.Dispose();
        mycomm = new MySqlCommand("GetRecordAsPage", myco);
        mycomm.CommandType = CommandType.StoredProcedure;
        para.Initialize();
        para = new MySqlParameter[]{
            new MySqlParameter("@tbName",MySqlDbType.VarChar,800),
            new MySqlParameter("@fldName",MySqlDbType.VarChar,1000),
            new MySqlParameter("@strWhere",MySqlDbType.VarChar,500),
            new MySqlParameter("@pageIndex",MySqlDbType.Int32),
            new MySqlParameter("@pageSize",MySqlDbType.Int32),
            new MySqlParameter("@orderType",MySqlDbType.Int16),
            new MySqlParameter("@sortName",MySqlDbType.VarChar,50)};
        para[0].Value = tbName;
        para[1].Value = fldName;
        para[2].Value = strWhere;
        para[3].Value = pageIndex;
        para[4].Value = pageSize;
        para[5].Value = 1;                             //0:asc 1:desc降序
        para[6].Value = "WriteTime";
        mycomm.Parameters.AddRange(para);

        MySqlDataAdapter myadap = new MySqlDataAdapter(mycomm);
        DataSet ds = new DataSet();
        myadap.Fill(ds);
        DataList1.DataSource = ds.Tables[0].DefaultView;
        DataList1.DataKeyField = "IDRizhi";
        DataList1.DataBind();
        myadap.Dispose();
        mycomm.Dispose();
        myco.Close();
        DropDownpage.Items.Clear();
        if (pageCount != 0)
        {
            doCount = 0;
            while (doCount < pageCount)
            {
                doCount++;
                DropDownpage.Items.Add(new ListItem(doCount.ToString() + "页", doCount.ToString()));
            }
        }
        if (pageIndex == 1)
        {
            Button_IndexFirst.Enabled = false;
            Button_IndexPrevious.Enabled = false;
            Button_IndexNext.Enabled = true;
            Button_IndexLast.Enabled = true;
        }
        else if (pageIndex == pageCount)
        {
            Button_IndexFirst.Enabled = true;
            Button_IndexPrevious.Enabled = true;
            Button_IndexNext.Enabled = false;
            Button_IndexLast.Enabled = false;
        }
        else
        {
            Button_IndexFirst.Enabled = true;
            Button_IndexPrevious.Enabled = true;
            Button_IndexNext.Enabled = true;
            Button_IndexLast.Enabled = true;
        }
        if (pageCount == 0 || pageCount == 1)
        {
            pageIndex = pageCount;
            Button_IndexFirst.Enabled = false;
            Button_IndexPrevious.Enabled = false;
            Button_IndexNext.Enabled = false;
            Button_IndexLast.Enabled = false;
            DropDownpage.Enabled = false;
        }
        else
        {
            DropDownpage.Enabled = true;
        }
        pageIndexLab.Text = pageIndex.ToString();
        if (pageIndex != 0)
        {
            DropDownpage.SelectedItem.Selected = false;
            DropDownpage.Items.FindByValue(pageIndex.ToString()).Selected = true;
        }
    }
    protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
    {
        string kind_id = DropDownList1.SelectedValue;
        if (kind_id.Equals("A7"))  // 按标题查询
        {
         
            if (TextBox1.Text == "")
            {
                Label2.Text = "请输入文件标题";
            }
            else
            {
                Get_RiZhi();
            }
        }
        else if (kind_id.Equals("A8")) //按日期查询
        {
            if (CodefanCalendar1.Text == "" || CodefanCalendar2.Text == "")
            {
                Label2.Text = "请输入创建时间范围";
            }
            else
            {
                Get_RiZhi();
            }

        }
    }
    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        start();
    }
}
阅读(302) | 评论(0) | 转发(0) |
0

上一篇:查询数据091124

下一篇:编辑器路径

给主人留下些什么吧!~~