标签:
using System;
using System.Web.UI;
using System.Data;
using System.Text;
using BLL = SmartWaterSys.BLL;
namespace Web
{
public partial class DoingOrder : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
this.txtStartTime.Text = DateTime.Now.AddMonths(-1).ToString("yyyy-MM-dd");
this.txtEndTime.Text = DateTime.Now.ToString("yyyy-MM-dd");
if (Cache["StrWhere_DoingOrder"] != null)
Cache.Remove("StrWhere_DoingOrder");//清除缓存
LoadDDLOrderType();
QueryData(SetInitQueryString());
}
}
private void LoadDDLOrderType()
{
BLL.EN_OrderType ordertype = new BLL.EN_OrderType();
DataSet ds = ordertype.GetAllList();
this.OrderTypeLst.DataSource = ds;
this.OrderTypeLst.DataTextField = "EN_OrderType_Name";
this.OrderTypeLst.DataValueField = "EN_OrderType_ID";
this.OrderTypeLst.DataBind();
this.OrderTypeLst.Items.Insert(0, "全部");
}
private string SetInitQueryString()
{
StringBuilder sbSql = new StringBuilder();
if (OrderTypeLst.SelectedItem != null && OrderTypeLst.SelectedItem.Text != "全部")
{
sbSql.Append(string.Format(" and EN_OrderType_Name = ‘{0}‘ ", OrderTypeLst.SelectedItem.Text));
}
if (StatusDDL != null && StatusDDL.SelectedItem.Text != "全部")
{
sbSql.Append(string.Format(" and [Status] = ‘{0}‘ ", StatusDDL.SelectedItem.Text));
}
if (txtOrderNum.Text.Length != 0)
{
sbSql.Append(string.Format(" and EN_OrderInfo_Num like ‘%{0}%‘", txtOrderNum.Text));
}
if (txtStartTime.Text.Length != 0)
{
sbSql.Append(string.Format(" and DL_OrderProcess_ReceiveDate >= ‘{0}‘", txtStartTime.Text));
}
if (txtEndTime.Text.Length != 0)
{
sbSql.Append(string.Format(" and DL_OrderProcess_AdvanceDate <= ‘{0}‘", txtEndTime.Text));
}
Cache["StrWhere_DoingOrder"] = sbSql.ToString();
//首次加载完页面(分页)或者重置按钮后保存至缓存 return sbSql.ToString();
}
protected void lnkRefresh_Click(object sender, EventArgs e)
{
lnkQuery_Click(null,null);
}
protected void lnkQuery_Click(object sender, EventArgs e)
{
this.AspNetPager1.CurrentPageIndex = 0;
BLL.View_Operate view = new BLL.View_Operate();
StringBuilder sbSql = new StringBuilder();
if (OrderTypeLst.SelectedItem != null && OrderTypeLst.SelectedItem.Text !="全部")
{
sbSql.Append(string.Format(" and EN_OrderType_Name = ‘{0}‘ ", OrderTypeLst.SelectedItem.Text));
}
if (StatusDDL !=null && StatusDDL.SelectedItem.Text!="全部")
{
sbSql.Append(string.Format(" and [Status] = ‘{0}‘ ",StatusDDL.SelectedItem.Text));
}
//sbSql.Append(string.Format(" and EN_OrderType_Name = ‘{0}‘ and [Status] = ‘{1}‘ ", OrderTypeLst.SelectedItem.Text, StatusDDL.SelectedItem.Text));
if (txtOrderNum.Text.Length != 0)
sbSql.Append(string.Format(" and EN_OrderInfo_Num like ‘%{0}%‘", txtOrderNum.Text));
if (txtStartTime.Text.Length != 0)
sbSql.Append(string.Format(" and DL_OrderProcess_ReceiveDate >= ‘{0}‘", txtStartTime.Text));
if (txtEndTime.Text.Length != 0)
sbSql.Append(string.Format(" and DL_OrderProcess_AdvanceDate <= ‘{0}‘", txtEndTime.Text));
Cache["StrWhere_DoingOrder"] = sbSql.ToString();
//根据查询条件查询数据后保存至缓存 QueryData(sbSql.ToString());
}
protected void lnkReset_Click(object sender, EventArgs e)
{
this.txtStartTime.Text = DateTime.Now.AddMonths(-1).ToString("yyyy-MM-dd");
this.txtEndTime.Text = DateTime.Now.ToString("yyyy-MM-dd");
this.txtOrderNum.Text = "";
if (Cache["StrWhere_DoingOrder"] != null)//重置时清除缓存
Cache.Remove("StrWhere_DoingOrder");
LoadDDLOrderType();
QueryData(SetInitQueryString());
}
private void QueryData(string strWhere)
{
StringBuilder sb = new StringBuilder();
if (!string.IsNullOrEmpty(strWhere))
{
sb.Append(strWhere);
}
BLL.View_Operate bll = new BLL.View_Operate();
int page = this.AspNetPager1.CurrentPageIndex, pageSize = this.AspNetPager1.PageSize, pageCount = 0, counts = 0;
DataSet ds = bll.GetListByPage("View_CheckOrderDoing", sb.ToString(), "[EN_OrderInfo_ID]", ref pageCount, ref counts, pageSize, page, "EN_OrderInfo_ID", "*", 1);
this.dgrdOrder.DataSource = ds;
this.dgrdOrder.DataBind();
this.AspNetPager1.RecordCount = counts;
}
protected void AspNetPager1_PageChanged(object sender, EventArgs e)
{
if (Cache["StrWhere_DoingOrder"] == null)
QueryData("");
else
QueryData(Cache["StrWhere_DoingOrder"].ToString());
//当缓存不为空时使用 }
}
}
标签:
原文地址:http://www.cnblogs.com/sherlockholmes/p/5286984.html