分类:
2009-11-24 15:17:01
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
gt_kind(DropDownList1, "xitong");
st_query_style();
gt_kind(DropDownList1,"sort");
}
}
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 st_query_style()
{
string IDSort = DropDownList1.SelectedValue;
gt_docum_iso(DropDownList1.SelectedValue);
}
protected void gt_docum_iso(string kind_id)
{
string iduse = Session["UserName"].ToString();
}
protected void Button1_Click(object sender, EventArgs e)
{
searchfordate();
}
protected void searchfordate()
{
HiddenField1.Value = Session["UserName"].ToString();
string time1 = CodefanCalendar1.Text;
string time2 = CodefanCalendar2.Text;
string IDUSE = HiddenField1.Value;
myco = new MySqlConnection(strconn);
myco.Open();
mycomm = new MySqlCommand("RizhiSearchForDate", myco);
mycomm.CommandType = CommandType.StoredProcedure;
MySqlParameter[] para = new MySqlParameter[]{
new MySqlParameter("@time1_",MySqlDbType.DateTime),
new MySqlParameter("@time2_",MySqlDbType.DateTime),
new MySqlParameter("@IDUSE_",MySqlDbType.VarChar,10)
};
para[0].Value = time1;
para[1].Value = time2;
para[2].Value = IDUSE;
mycomm.Parameters.AddRange(para);
MySqlDataAdapter myda = new MySqlDataAdapter();
myda.SelectCommand = mycomm;
DataSet myset = new DataSet();
myda.Fill(myset);
DataList1.DataSource = myset.Tables[0];
DataList1.DataBind();
myda.Dispose();
mycomm.Dispose();
myco.Close();
}
protected void RizhiSearchForTitle()
{
string title = "%"+TextBox1.Text+"%";
HiddenField1.Value = Session["UserName"].ToString();
string IDUSE = HiddenField1.Value;
myco = new MySqlConnection(strconn);
myco.Open();
mycomm = new MySqlCommand("RizhiShowbeaTitle", myco);
mycomm.CommandType = CommandType.StoredProcedure;
//MySqlParameter para = new MySqlParameter("@title_", MySqlDbType.VarChar, 52);
//para.Value = title_;
//mycomm.Parameters.Add(para);
MySqlParameter[] para = new MySqlParameter[]{
new MySqlParameter("@title_",MySqlDbType.VarChar ,52),
new MySqlParameter("@IDUSE_",MySqlDbType.VarChar,10)
};
para[0].Value = title;
para[1].Value = IDUSE;
mycomm.Parameters.AddRange(para);
MySqlDataAdapter myda =new MySqlDataAdapter();
myda.SelectCommand =mycomm;
DataSet myset=new DataSet();
myda.Fill(myset);
DataList1.DataSource =myset.Tables[0];
DataList1.DataBind();
myda.Dispose();
mycomm.Dispose();
myco.Close();
}
protected void Button2_Click(object sender, EventArgs e)
{
RizhiSearchForTitle();
}
protected void getdata()
{
myco = new MySqlConnection(strconn);
myco.Open();
string IDUSE_ = HiddenField1.Value;
string sql = "select * from logtable where IDUSE= '" + IDUSE_ + "'";
MySqlDataAdapter myAdapter = new MySqlDataAdapter(sql, myco);
DataSet ds = new DataSet();
myAdapter.Fill(ds);
DataList1.DataSource = ds.Tables[0];
DataList1.DataKeyField = "IDRizhi";
DataList1.DataBind();
ds.Dispose();
myAdapter.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();
getdata();
}
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 Button3_Click(object sender, EventArgs e)
{
Get_RiZhi();
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
}
protected void Get_RiZhi()
{
string iduse = Session["UserName"].ToString();
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].DefaultView;
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;
}
}
}