日期:2014-05-18 浏览次数:20396 次
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; public partial class gwc : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (Session["temp"] == null) { Random rnd = new Random(); int n = rnd.Next(1000, 9999); string newname = DateTime.Now.Year.ToString().Trim() + DateTime.Now.Month.ToString().Trim() + DateTime.Now.Day.ToString().Trim() + DateTime.Now.Hour.ToString().Trim() + DateTime.Now.Minute.ToString().Trim() + DateTime.Now.Second.ToString().Trim() + n.ToString().Trim(); Session["temp"] = newname; } if (!IsPostBack) { string sql; sql = "select * from goumaijilu where goumairen ='" + Session["temp"].ToString().Trim() + "' order by id desc"; getdata(sql); } } private void getdata(string sql) { DataSet result = new DataSet(); result = new Class1().hsggetdata(sql); if (result != null) { if (result.Tables[0].Rows.Count > 0) { DataGrid1.DataSource = result.Tables[0]; DataGrid1.DataBind(); Label1.Text = "以上数据中共" + result.Tables[0].Rows.Count + "条"; } else { DataGrid1.DataSource = null; DataGrid1.DataBind(); Label1.Text = "暂无任何数据"; } } } protected void Button1_Click(object sender, EventArgs e) { string sql; sql = "select * from goumaijilu where goumairen ='" + Session["temp"].ToString().Trim() + "'"; if (bianhao.Text.ToString().Trim() != "") { sql = sql + " and bianhao like '%" + bianhao.Text.ToString().Trim() + "%'"; } if (mingcheng.Text.ToString().Trim() != "") { sql = sql + " and mingcheng like '%" + mingcheng.Text.ToString().Trim() + "%'"; } sql = sql + " order by id desc"; getdata(sql); } protected void DataGrid1_PageIndexChanged(object source, DataGridPageChangedEventArgs e) { string sql; sql = "select * from goumaijilu where goumairen ='" + Session["temp"].ToString().Trim() + "' order by id desc"; getdata(sql); DataGrid1.CurrentPageIndex = e.NewPageIndex; DataGrid1.DataBind(); } public string riqigeshi(object str) { string strTmp = str.ToString(); DateTime dt = Convert.ToDateTime(strTmp); string ss = dt.ToShortDateString(); return ss; } }