public
string sel = "" ;
//当前页
public
int _CurrentPage;
//共页
public
int _PageCount;
//首页
public
int _FirstPage;
//上一页
public
int _PrevPage;
//下一页
public
int _NextPage;
//尾页
public
int _LastPage;
//跳转页
public
int _GO = 1;
protected
void Page_Load( object
sender, EventArgs e)
{
if
(!IsPostBack)
{
sel = "sel" ;
loadhtml();
}
}
private
void loadhtml()
{
DataTable dt = new
DataTable();
//查询
if
(sel == "sel" )
{
int
count = 0;
dt = mor_dal.GetOrderDataTablePageList(SqlWhere.ToString(), "order_id" , "asc" , _GO, 20, ref
count);
if
(count % 20 > 0)
{
_PageCount = count / 20 + 1;
}
else
{
_PageCount = count / 20;
}
//给分页赋值
CurrentPage.Text = _GO.ToString();
PageCount.Text = _PageCount.ToString();
CountSum.Text = count.ToString();
if
(_GO == 1)
{
PrevPageText.Enabled = false ;
}
else
{
PrevPageText.Enabled = true ;
}
if
(Convert.ToInt32(PageCount.Text.Trim()) == _GO)
{
NextPageText.Enabled = false ;
}
else
{
NextPageText.Enabled = true ;
}
}
else
{
int
count = 0;
dt = mor_dal.GetOrderDataTablePageList(SqlWhere.ToString(), "order_id" , "asc" , _GO, 20, ref
count);
CurrentPage.Text = _GO.ToString();
}
}
/// <summary>
/// 首页
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected
void FirstPageText_Click( object
sender, EventArgs e)
{
_GO = 1;
PrevPageText.Enabled = false ;
if
(Convert.ToInt32(PageCount.Text.Trim()) == _GO)
{
NextPageText.Enabled = false ;
}
else
{
NextPageText.Enabled = true ;
}
loadhtml();
}
/// <summary>
/// 上一页
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected
void PrevPageText_Click( object
sender, EventArgs e)
{
_GO = Convert.ToInt32(CurrentPage.Text.Trim()) - 1;
if
(_GO == 1)
{
PrevPageText.Enabled = false ;
}
else
{
PrevPageText.Enabled = true ;
}
if
(Convert.ToInt32(PageCount.Text.Trim()) == _GO)
{
NextPageText.Enabled = false ;
}
else
{
NextPageText.Enabled = true ;
}
loadhtml();
}
/// <summary>
/// 下一页
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected
void NextPageText_Click( object
sender, EventArgs e)
{
_GO = Convert.ToInt32(CurrentPage.Text.Trim()) + 1;
if
(_GO == 1)
{
PrevPageText.Enabled = false ;
}
else
{
PrevPageText.Enabled = true ;
}
if
(Convert.ToInt32(PageCount.Text.Trim()) == _GO)
{
NextPageText.Enabled = false ;
}
else
{
NextPageText.Enabled = true ;
}
loadhtml();
}
/// <summary>
/// 尾页
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>NextPageTextLastPage
protected
void LastPageText_Click( object
sender, EventArgs e)
{
_GO = Convert.ToInt32(PageCount.Text.Trim());
NextPageText.Enabled = false ;
if
(_GO == 1)
{
PrevPageText.Enabled = false ;
}
else
{
PrevPageText.Enabled = true ;
}
loadhtml();
}
/// <summary>
/// G O
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected
void Btn_PageIndex_Click( object
sender, EventArgs e)
{
try
{
if
(Convert.ToInt32(PageIndex.Value.Trim()) <= Convert.ToInt32(PageCount.Text.Trim()) && PageIndex.Value.Trim() != "0" )
{
_GO = Convert.ToInt32(PageIndex.Value.Trim());
if
(_GO == 1)
{
PrevPageText.Enabled = false ;
}
else
{
PrevPageText.Enabled = true ;
}
if
(Convert.ToInt32(PageCount.Text.Trim()) == _GO)
{
NextPageText.Enabled = false ;
}
else
{
NextPageText.Enabled = true ;
}
loadhtml();
}
else
{
Page.Response.Write( "<script type=\"text/javascript\">alert(‘已超出索引!‘);</script>" );
}
}
catch
(Exception)
{
Page.Response.Write( "<script type=\"text/javascript\">alert(‘输入有误!‘);</script>" );
}
}
//执行SQL
/// <summary>
/// 销售订单明细--分页
/// </summary>
/// <param name="sqlwhere">条件</param>
/// <param name="orderField">排序字段</param>
/// <param name="orderType">排序类型</param>
/// <param name="pageIndex">当前页</param>
/// <param name="pageSize">页大小</param>
/// <param name="count">返回查询条数</param>
/// <returns></returns>
public
System.Data.DataTable GetOrderDataTablePageList( string
sqlwhere, string
orderField, string
orderType, int
pageIndex, int
pageSize, ref
int count)
{
StringBuilder strSql = new
StringBuilder();
strSql.Append( @"SELECT
E.order_id,
E.order_no,
E.cust_no,
E.cust_name,
E.or_currency_Name,
E.or_ask_money,
E.or_sale_uname,
E.or_date,
E.touching_uname,
E.touching_date,
E.or_check,
E.or_check_date,
E.or_status,
E.or_remark,
Q.op_id,
Q.op_matno,
Q.op_matname,
Q.op_matStandard,
Q.op_unit,
Q.op_unit_id,
Q.op_quantity,
Q.op_price,
Q.op_money,
Q.op_delivery_date,
Q.IsStockNum,
Q.NotStockNum,
Q.op_remark,
Q.pro_code,
D.dep_type,
D.amount
FROM YZOrder as E LEFT JOIN
YZOrder_product as Q on e.order_no = Q.order_no LEFT JOIN
YZ_Depot as D on q.op_matno= D.mat_no WHERE 1=1" );
strSql.Append(sqlwhere);
return
DataFactory.SqlDataBase().GetPageList(strSql.ToString(), orderField, orderType, pageIndex, pageSize, ref
count);
}
/// <summary>
/// 摘要:
/// 数据分页
/// 参数:
/// sql:传入要执行sql语句
/// param:参数化
/// orderField:排序字段
/// orderType:排序类型
/// pageIndex:当前页
/// pageSize:页大小
/// count:返回查询条数
/// </summary>
public
DataTable GetPageList( string
sql, SqlParam[] param, string
orderField, string
orderType, int
pageIndex, int
pageSize, ref
int count)
{
StringBuilder sb = new
StringBuilder();
try
{
int
num = (pageIndex - 1) * pageSize;
int
num1 = (pageIndex) * pageSize;
sb.Append( "Select * From (Select ROW_NUMBER() Over (Order By "
+ orderField + " "
+ orderType + "" );
sb.Append( ") As rowNum, * From ("
+ sql + ") As T ) As N Where rowNum > "
+ num + " And rowNum <= "
+ num1 + "" );
count = Convert.ToInt32( this .GetObjectValue( new
StringBuilder( "Select Count(1) From ("
+ sql + ") As t" ), param));
return
this .GetDataTableBySQL(sb, param);
}
catch
(Exception e)
{
DbLog.WriteException(e);
return
null ; ;
}
}
|