📄 gatequeryresult.aspx.cs
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using WebMonitor;
using System.IO;
using System.Net;
namespace SAMPLE.DLWLJK.QUERY
{
/// <summary>
/// WebForm3 的摘要说明。
/// </summary>
public class GateQueryResultForm : System.Web.UI.Page
{
protected System.Web.UI.WebControls.ImageButton btnFirstPage;
protected System.Web.UI.WebControls.DataGrid Grid;
protected System.Web.UI.WebControls.Label lblCurPagePrompt;
protected System.Web.UI.WebControls.ImageButton btnPrintCurPage;
protected Microsoft.Web.UI.WebControls.Toolbar Toolbar;
protected System.Web.UI.WebControls.ImageButton btnPrePage;
protected System.Web.UI.WebControls.ImageButton btnNextPage;
protected System.Web.UI.WebControls.ImageButton btnLastPage;
protected System.Web.UI.WebControls.ImageButton btnGo;
protected System.Web.UI.WebControls.TextBox txtPageNum;
protected System.Web.UI.WebControls.ImageButton ImageButton1;
protected System.Web.UI.WebControls.ImageButton btnBack;
protected System.Web.UI.WebControls.ImageButton btnSaveToExcel;
protected static QueryCondition m_oQueryCondition;//用户指定地查询条件
protected static AllQuery m_AllQuery;//查询并得到结果
protected static int iPageIndex;//当前页数(缓冲区中第几页)
private static int nCurPage; //当前页数(实际)
private static int nTotalPageNum;
protected static int iRecCount; //查询结果的记录总数
private static DataTable m_dt;//datagrid 显示的数据
private void InitializeComponent()
{
this.Grid.SelectedIndexChanged += new System.EventHandler(this.Grid_SelectedIndexChanged);
this.btnFirstPage.Click += new System.Web.UI.ImageClickEventHandler(this.btnFirstPage_Click);
this.btnPrePage.Click += new System.Web.UI.ImageClickEventHandler(this.btnPrePage_Click);
this.btnNextPage.Click += new System.Web.UI.ImageClickEventHandler(this.btnNextPage_Click);
this.btnLastPage.Click += new System.Web.UI.ImageClickEventHandler(this.btnLastPage_Click);
this.btnGo.Click += new System.Web.UI.ImageClickEventHandler(this.btnGo_Click);
this.btnBack.Click += new System.Web.UI.ImageClickEventHandler(this.btnBack_Click);
this.btnSaveToExcel.Click += new System.Web.UI.ImageClickEventHandler(this.btnSaveToExcel_Click);
}
protected bool LoadDataFromSession()
{
try
{
int iResult=Int32.Parse(Server.HtmlEncode(Request.Cookies["QueryInfo"]["GateCrossState"]));
if(iResult==-1)
{
Response.Redirect("AllQuery.aspx");
}
else
{
m_oQueryCondition.SetGateCrossState(iResult);
}
int nCrossState=m_oQueryCondition.GetGateCrossState();
if(nCrossState==0)
{
m_oQueryCondition.SetBeginDateTime(Request.Cookies["QueryInfo"]["BeginDateTime"].ToString());//经过卡口起始时间
m_oQueryCondition.SetEndDateTime(Request.Cookies["QueryInfo"]["EndDateTime"].ToString());//经过卡口结束时间
m_oQueryCondition.SetCarryContaBegintime(Request.Cookies["QueryInfo"]["CarryContaBegintime"].ToString());//提箱起始时间
m_oQueryCondition.SetCarryContaEndtime(Request.Cookies["QueryInfo"]["CarryContaEndtime"].ToString());//提箱结束时间
m_oQueryCondition.SetEntryWeightErrorStart(float.Parse(Request.Cookies["QueryInfo"]["EntryWeightErrorStart"].ToString()));//报关误差起始
m_oQueryCondition.SetEntryWeightErrorEnd(float.Parse(Request.Cookies["QueryInfo"]["EntryWeightErrorEnd"].ToString()));////报关误差结束
m_oQueryCondition.SetBillWeightErrorStart(float.Parse(Request.Cookies["QueryInfo"]["BillWeightErrorStart"].ToString()));//舱单误差起始
m_oQueryCondition.SetBillWeightErrorEnd(float.Parse(Request.Cookies["QueryInfo"]["BillWeightErrorEnd"].ToString()));//舱单误差结束
m_oQueryCondition.SetPlaceID_DB(int.Parse(Request.Cookies["QueryInfo"]["PlaceID"].ToString()));//卡口号
m_oQueryCondition.SetUserID_DB(int.Parse(Request.Cookies["QueryInfo"]["CheckUserID"].ToString()));//检查人员
m_oQueryCondition.SetGoodsType_DB(Request.Cookies["QueryInfo"]["GoodsType"].ToString());//货物类型
m_oQueryCondition.SetCheckType_DB(int.Parse(Request.Cookies["QueryInfo"]["CheckType"].ToString()));//检查方式
m_oQueryCondition.SetCheckFlag_DB(int.Parse(Request.Cookies["QueryInfo"]["GoType"].ToString()));//放行方式
m_oQueryCondition.SetGoodsBillRelation_DB(Request.Cookies["QueryInfo"]["GoodsBillRelation"].ToString());//货单关系
m_oQueryCondition.SetVehiNo(Request.Cookies["QueryInfo"]["VehiNo"].ToString());
}
m_oQueryCondition.SetShipName(Request.Cookies["QueryInfo"]["ShipName"].ToString());
m_oQueryCondition.SetVoyageNo(Request.Cookies["QueryInfo"]["VoyageNo"].ToString());
m_oQueryCondition.SetBillNo(Request.Cookies["QueryInfo"]["BillNo"].ToString());
m_oQueryCondition.SetContaNo(Request.Cookies["QueryInfo"]["ContaNo"].ToString());
m_oQueryCondition.SetEntryID(Request.Cookies["QueryInfo"]["EntryID"].ToString());
m_oQueryCondition.SetOutEntryID(Request.Cookies["QueryInfo"]["OutEntryID"].ToString());
}
catch(Exception )
{
Response.Redirect("AllQuery.aspx");
}
return true;
}
public void SavePageRalationVar()
{
HttpCookie bCookie=new HttpCookie("QueryInfo_DateSelect");
bCookie.Values["TotalPageNum"]=nTotalPageNum.ToString();
bCookie.Values["CurPageNum"]=nCurPage.ToString();
bCookie.Values["iPageIndex"]=iPageIndex.ToString();
bCookie.Values["iRecCount"]=iRecCount.ToString();
bCookie.Values["CurrentPage"]="QueryResult.aspx";
bCookie.Expires = DateTime.Now.AddDays(1);
Response.Cookies.Add(bCookie);
}
//event handler for load event
private void Page_Load(object sender, System.EventArgs e)
{
InitializeComponent();
try
{
if(!IsPostBack)
{
iPageIndex=0;
iRecCount=0;
m_oQueryCondition=new QueryCondition();
m_AllQuery=new AllQuery();
LoadDataFromSession();
Session["m_oQueryCondition"]=m_oQueryCondition;
Session["m_AllQuery"]=m_AllQuery;
int nGateCrossState=m_oQueryCondition.GetGateCrossState();
nCurPage=1;
iRecCount=m_AllQuery.GetTotalRecNum(ref m_oQueryCondition);
nTotalPageNum=m_AllQuery.GetTotalPage(ref m_oQueryCondition);
m_dt=m_AllQuery.GetQueryResultView(ref m_oQueryCondition ,nCurPage ,ref iPageIndex);
Grid.DataSource=m_dt.DefaultView;
Grid.CurrentPageIndex=iPageIndex;
Grid.DataBind();
ShowPageFoot();
SavePageRalationVar();
}
else
{
nTotalPageNum=Int32.Parse(Server.HtmlEncode(Request.Cookies["QueryInfo_DateSelect"]["TotalPageNum"]));
nCurPage=Int32.Parse(Server.HtmlEncode(Request.Cookies["QueryInfo_DateSelect"]["CurPageNum"]));
iPageIndex=Int32.Parse(Server.HtmlEncode(Request.Cookies["QueryInfo_DateSelect"]["iPageIndex"]));
iRecCount=Int32.Parse(Server.HtmlEncode(Request.Cookies["QueryInfo_DateSelect"]["iRecCount"]));
}
m_oQueryCondition=(QueryCondition)Session["m_oQueryCondition"];
m_AllQuery=(AllQuery)Session["m_AllQuery"];
ShowPageFoot();
}
catch(Exception)
{
nTotalPageNum=0;
iRecCount=0;
Grid.DataSource=null;
Grid.CurrentPageIndex=0;
Grid.DataBind();
ShowPageFoot();
}
// btnSaveToExcel.Attributes.Add("onclick","window.open('SelectPage.aspx','综合查询数据下载','menubar=yes,resizable=no',width=268,height=260,left=200,top=200)");
// btnSaveToExcel.Attributes.Add("onclick","window.open('SelectPage.aspx','综合查询数据下载','menubar=no,resizable=no,width=420,height=320')");
}
public void ShowPageFoot()
{
int iCurPageIndex=Grid.CurrentPageIndex+1;
lblCurPagePrompt.Text="总记录数为 "+ iRecCount.ToString()+"条,当前为 "+nCurPage.ToString() + "/"+ nTotalPageNum.ToString()+ "页";
SavePageRalationVar();
}
private void btnFirstPage_Click(object sender, System.Web.UI.ImageClickEventArgs e)
{
if(nTotalPageNum>0)
nCurPage=1;
else
nCurPage=0;
m_dt=m_AllQuery.GetQueryResultView(ref m_oQueryCondition ,1 ,ref iPageIndex);
Grid.DataSource=m_dt.DefaultView;
Grid.CurrentPageIndex=iPageIndex;
Grid.DataBind();
ShowPageFoot();
}
private void Grid_SelectedIndexChanged(object sender, System.EventArgs e)
{
}
private void Toolbar_ButtonClick(object sender, System.EventArgs e)
{
Microsoft.Web.UI.WebControls.ToolbarButton tb=(Microsoft.Web.UI.WebControls.ToolbarButton)( sender);
string str=tb.Text.ToString();
int iResult;
iResult=str.CompareTo("查询");
if(iResult==0)
{
Response.Redirect("AllQuery.aspx");
}
iResult=str.CompareTo("统计");
if(iResult==0)
{
Response.Redirect("AllQuery.aspx");
}
}
private void btnNextPage_Click(object sender, System.Web.UI.ImageClickEventArgs e)
{
if(nCurPage<nTotalPageNum)
{
nCurPage++;
m_dt=m_AllQuery.GetQueryResultView(ref m_oQueryCondition ,nCurPage ,ref iPageIndex);
Grid.DataSource=m_dt.DefaultView;
Grid.CurrentPageIndex=iPageIndex;
Grid.DataBind();
ShowPageFoot();
}
}
private void btnPrePage_Click(object sender, System.Web.UI.ImageClickEventArgs e)
{
if(nCurPage>1)
{
nCurPage--;
m_dt=m_AllQuery.GetQueryResultView(ref m_oQueryCondition ,nCurPage ,ref iPageIndex);
Grid.DataSource=m_dt.DefaultView;
Grid.CurrentPageIndex=iPageIndex;
Grid.DataBind();
ShowPageFoot();
}
}
private void btnLastPage_Click(object sender, System.Web.UI.ImageClickEventArgs e)
{
nCurPage=nTotalPageNum;
m_dt=m_AllQuery.GetQueryResultView(ref m_oQueryCondition ,nCurPage ,ref iPageIndex);
Grid.DataSource=m_dt.DefaultView;
Grid.CurrentPageIndex=iPageIndex;
Grid.DataBind();
ShowPageFoot();
}
private void btnGo_Click(object sender, System.Web.UI.ImageClickEventArgs e)
{
string str=txtPageNum.Text.Trim();
int iPageNum;
int iValue;
if(str.Length==0)
{
return ;
}
try
{
iValue=int.Parse(txtPageNum.Text);
}
catch(Exception )
{
return;
}
if(iValue<=0)
{
return ;
}
else if(iValue>nTotalPageNum)
iValue=nTotalPageNum;
nCurPage=iValue;
m_dt=m_AllQuery.GetQueryResultView(ref m_oQueryCondition ,nCurPage ,ref iPageIndex);
Grid.DataSource=m_dt.DefaultView;
Grid.CurrentPageIndex=iPageIndex;
Grid.DataBind();
ShowPageFoot();
}
private void btnBack_Click(object sender, System.Web.UI.ImageClickEventArgs e)
{
Response.Redirect("AllQuery.aspx");
}
private void StateSavetoCookie()
{
int iResult;
try
{
iResult=Int32.Parse(Server.HtmlEncode(Request.Cookies["QueryInfo"]["GateCrossState"]));
}
catch
{
int iCrossState=m_oQueryCondition.GetGateCrossState();
HttpCookie bCookie=new HttpCookie("QueryInfo");
if(iCrossState==0)
{
bCookie.Values["BeginDateTime"]=m_oQueryCondition.GetBeginDateTime();//经过卡口起始时间
bCookie.Values["EndDateTime"]=m_oQueryCondition.GetEndDateTime();//经过卡口结束时间
bCookie.Values["CarryContaBegintime"]=m_oQueryCondition.GetCarryContaBegintime();//提箱起始时间
bCookie.Values["CarryContaEndtime"]=m_oQueryCondition.GetCarryContaEndtime();//提箱结束时间
bCookie.Values["EntryWeightErrorStart"]=m_oQueryCondition.GetEntryWeightErrorStart().ToString();//报关误差起始
bCookie.Values["EntryWeightErrorEnd"]=m_oQueryCondition.GetEntryWeightErrorEnd().ToString();//报关误差结束
bCookie.Values["BillWeightErrorStart"]=m_oQueryCondition.GetBillWeightErrorStart().ToString();//舱单误差起始
bCookie.Values["BillWeightErrorEnd"]=m_oQueryCondition.GetBillWeightErrorEnd().ToString();//舱单误差结束
bCookie.Values["CheckType"]=m_oQueryCondition.GetCheckType().ToString();//检查方式
bCookie.Values["GoodsType"]=m_oQueryCondition.GetGoodsType().ToString();//货物类型
bCookie.Values["GoType"]=m_oQueryCondition.GetCheckFlag().ToString();//放行方式
bCookie.Values["VehiNo"]=m_oQueryCondition.GetVehiNo().ToString();//车牌号
bCookie.Values["GoodsBillRelation"]=m_oQueryCondition.GetGoodsBillRelation().ToString();//货单关系
}
bCookie.Values["GateCrossState"]=m_oQueryCondition.GetGateCrossState().ToString();//经过卡口信息
bCookie.Values["ShipName"]=m_oQueryCondition.GetShipName();//船名
bCookie.Values["VoyageNo"]=m_oQueryCondition.GetVoyageNo();//航次
bCookie.Values["BillNo"]=m_oQueryCondition.GetBillNo();//提单
bCookie.Values["ContaNo"]=m_oQueryCondition.GetContaNo();//箱号
bCookie.Values["EntryID"]=m_oQueryCondition.GetEntryID();//报关单
bCookie.Values["OutEntryID"]=m_oQueryCondition.GetOutEntryID();//转关单
bCookie.Expires = DateTime.Now.AddDays(1);
Response.Cookies.Add(bCookie);
}
}
private void btnSaveToExcel_Click(object sender, System.Web.UI.ImageClickEventArgs e)
{
Response.Redirect("SelectPageDlg.aspx");
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -