62,268
社区成员
发帖
与我相关
我的任务
分享/// <summary>
/// 存储过程
/// </summary>
/// <param name="webcons">WebControl绑定控件</param>
/// <param name="dbtable">表名</param>
/// <param name="pagesize">每页显示记录数</param>
/// <param name="showsize">每页显示分页数</param>
/// <param name="thispage">当前页索引</param>
/// <returns>分页字串</returns>
public string GetPorc(WebControl webcons,string dbtable,int pagesize,int showsize,int thispage)
{
MAYI.Mpage Mypage = new MAYI.Mpage();
Open();
SqlCommand cmd = new SqlCommand("Mypage", Connection);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@metabname", SqlDbType.VarChar, 50);
cmd.Parameters.Add("@mepagesize", SqlDbType.Int);
cmd.Parameters.Add("@mepageint", SqlDbType.Int);
cmd.Parameters.Add("@thispage", SqlDbType.Int);
cmd.Parameters["@metabname"].Value = "news";
cmd.Parameters["@mepagesize"].Value = pagesize;
cmd.Parameters["@mepageint"].Value = showsize;
cmd.Parameters["@thispage"].Value = thispage;
cmd.Parameters.Add("@msrsall", SqlDbType.Int);
cmd.Parameters.Add("@mspagecount", SqlDbType.Int);
cmd.Parameters["@msrsall"].Direction = ParameterDirection.Output;
cmd.Parameters["@mspagecount"].Direction = ParameterDirection.Output;
cmd.ExecuteNonQuery();
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
sda.Fill(ds);
if (webcons is GridView)
{
(webcons as GridView).DataSource= ds.Tables[0].DefaultView;
(webcons as GridView).DataBind();
}
if (webcons is DataList)
{
(webcons as DataList).DataSource = ds.Tables[0].DefaultView;
(webcons as DataList).DataBind();
}
string pagestr = Mypage.MyPage(Convert.ToInt32(cmd.Parameters["@msrsall"].Value), pagesize, showsize, null, null, "pp", null, null, null);
return pagestr;
Close();
}
CREATE PROCEDURE Mypage
(
@metabname varchar(200), --表名
@mepagesize int, --每页显示记录数
@mepageint int, --分页条显示个数
@thispage int, --当前页编号
@msrsall int output, --总记录数
@mspagecount int output --总页数
)
AS
declare @tabsql nvarchar(200)
declare @pagecount int --分页总数
declare @rsall int --总记录数
declare @top int --提当前段数据
declare @sql varchar(200)
------------------------------------------------------------------------------------
set @tabsql='select @rsall =count(*) from '+ @metabname
exec sp_executesql @tabsql,N'@rsall int output',@rsall output
------------------------------------------------------------------------------------
if @rsall >0 --有数据
begin
set @top=@mepagesize*(@thispage-1)
set @sql='select top ' + str(@mepagesize) + ' * from '+@metabname+' where id not in(select top '+ str(@top) +' id from '+@metabname+') order by id asc'
exec(@sql)
if @rsall % @mepagesize=0
begin
set @pagecount=@rsall / @mepagesize
end
else
begin
set @pagecount=@rsall / @mepagesize+1
end
end
else --没数据
begin
set @msrsall=0
set @mspagecount=0
end
set @msrsall=@rsall --总信息数
set @mspagecount=@pagecount --分页总数
GO
public string Mepage(int Mcount, int pagesize, string Mepostbackurl, string Meurlstr, string Meurlpage)
{
int num;
int num2;
StringBuilder builder = new StringBuilder();
string str = Meurlstr + Meurlpage;
if ((HttpContext.Current.Request.QueryString[Meurlpage] != null) && int.TryParse(HttpContext.Current.Request.QueryString[Meurlpage], out num))
{
num2 = Convert.ToInt32(HttpContext.Current.Request.QueryString[Meurlpage]);
}
else
{
num2 = 1;
}
int num3 = Mcount / pagesize;
if (num3 == 0)
{
num3 = 1;
}
else if ((Mcount % pagesize) > 0)
{
num3++;
}
builder.Append("<table><tr>");
builder.Append("<td>");
builder.Append("共有条" + Mcount.ToString() + "记录 ");
builder.Append(string.Concat(new object[] { "当前是第", num2, "/", num3, "页 " }));
if (num3 == 1)
{
builder.Append("首页 ");
builder.Append("上一页 ");
builder.Append("下一页 ");
builder.Append("最后一页");
}
else if (num2 == 1)
{
builder.Append("首页 ");
builder.Append("上一页 ");
builder.Append(string.Concat(new object[] { "<a href=", Mepostbackurl, "?", str, "=", num2 + 1, ">下一页</a> " }));
builder.Append(string.Concat(new object[] { "<a href=", Mepostbackurl, "?", str, "=", num3, ">最后一页</a>" }));
}
else if (num2 >= num3)
{
builder.Append("<a href=" + Mepostbackurl + "?" + str + "=1>首页</a> ");
builder.Append(string.Concat(new object[] { "<a href=", Mepostbackurl, "?", str, "=", num2 - 1, ">上一页</a> " }));
builder.Append("下一页 ");
builder.Append("最后一页");
}
else
{
builder.Append("<a href=" + Mepostbackurl + "?" + str + "=1>首页</a> ");
builder.Append(string.Concat(new object[] { "<a href=", Mepostbackurl, "?", str, "=", num2 - 1, ">上一页</a> " }));
builder.Append(string.Concat(new object[] { "<a href=", Mepostbackurl, "?", str, "=", num2 + 1, ">下一页</a> " }));
builder.Append(string.Concat(new object[] { "<a href=", Mepostbackurl, "?", str, "=", num3, ">最后一页</a>" }));
}
builder.Append("</td>");
builder.Append("<td><select id=\"MeSelectPage\" onchange=\"window.location='" + Mepostbackurl + "?" + str + "='+this.options[this.selectedIndex].value\">\r\n");
for (int i = 1; i < (num3 + 1); i++)
{
if ((HttpContext.Current.Request.QueryString[Meurlpage] != null) && (HttpContext.Current.Request.QueryString[Meurlpage].ToString() == i.ToString()))
{
builder.Append(string.Concat(new object[] { "<option value=", i, " selected>", i, "页</option>\r\n" }));
}
else
{
builder.Append(string.Concat(new object[] { "<option value=", i, ">", i, "页</option>\r\n" }));
}
}
builder.Append("</select></td>\r\n");
builder.Append("</tr></table>");
return builder.ToString();
}
public string MyPage(int Myallcount, int Mypagesize, int Mypageshowsize, string Mypostbackurl, string Myurlstr, string Myurlpage, string Mycolor, string Myfontcolor, string Mybordercolor)
{
StringBuilder builder = new StringBuilder();
StringBuilder builder2 = new StringBuilder();
string str = Myurlstr + Myurlpage;
int num = Myallcount / Mypagesize;
if (num == 0)
{
num = 1;
}
else if ((Myallcount % Mypagesize) > 0)
{
num++;
}
int num3 = 0;
if (Myallcount > 0)
{
int num2;
int num4;
int num5;
builder.Append("<td class=pagefalse><a href=#>共有" + Myallcount + "条记录</a></td>\r\n");
builder.Append("<td class=pagefalse><a href=" + Mypostbackurl + "?" + str + "=1 title=首页>首页</a></td>\r\n");
if (!(((HttpContext.Current.Request.QueryString[Myurlpage] != null) && (HttpContext.Current.Request.QueryString[Myurlpage].ToString() != null)) && int.TryParse(HttpContext.Current.Request.QueryString[Myurlpage], out num4)))
{
num2 = 1;
}
else
{
num2 = Convert.ToInt32(HttpContext.Current.Request.QueryString[Myurlpage]);
}
if (num < Mypageshowsize)
{
for (num5 = (num2 / Mypageshowsize) + 1; num5 <= num; num5++)
{
if (num2 == num5)
{
builder.Append("<td class=pagetrue><a href=" + Mypostbackurl + "?" + str + "=" + num5.ToString() + " title=第" + num5.ToString() + "页>" + num5.ToString() + "</a></td>\r\n");
}
else
{
builder.Append("<td class=pagefalse><a href=" + Mypostbackurl + "?" + str + "=" + num5.ToString() + " title=第" + num5.ToString() + "页>" + num5.ToString() + "</a></td>\r\n");
}
}
}
else if ((num2 / Mypageshowsize) > 0)
{
builder.Append(string.Concat(new object[] { "<td class=pagefalse><a href=", Mypostbackurl, "?", str, "=", Convert.ToInt32((int) (((num2 / Mypageshowsize) * Mypageshowsize) - 1)), " title=上一组>.....</a></td>\r\n" }));
if ((num2 / Mypageshowsize) < (num / Mypageshowsize))
{
for (num5 = (num2 / Mypageshowsize) * Mypageshowsize; num5 <= (((num2 / Mypageshowsize) + 1) * Mypageshowsize); num5++)
{
if (num2 == num5)
{
builder.Append("<td class=pagetrue><a href=" + Mypostbackurl + "?" + str + "=" + num5.ToString() + " title=第" + num5.ToString() + "页>" + num5.ToString() + "</a></td>\r\n");
}
else
{
builder.Append("<td class=pagefalse><a href=" + Mypostbackurl + "?" + str + "=" + num5.ToString() + " title=第" + num5.ToString() + "页>" + num5.ToString() + "</a></td>\r\n");
}
}
num3 = ((num2 / Mypageshowsize) + 1) * Mypageshowsize;
builder.Append("<td class=pagefalse><a href=" + Mypostbackurl + "?" + str + "=" + num3.ToString() + " title=下一组>.....</a></td>\r\n");
}
else
{
for (num5 = (num2 / Mypageshowsize) * Mypageshowsize; num5 <= num; num5++)
{
if (num2 == num5)
{
builder.Append("<td class=pagetrue><a href=" + Mypostbackurl + "?" + str + "=" + num5.ToString() + " title=第" + num5.ToString() + "页>" + num5.ToString() + "</a></td>\r\n");
}
else
{
builder.Append("<td class=pagefalse><a href=" + Mypostbackurl + "?" + str + "=" + num5.ToString() + " title=第" + num5.ToString() + "页>" + num5.ToString() + "</a></td>\r\n");
}
}
num3 = num;
}
}
else
{
for (num5 = (num2 / Mypageshowsize) + 1; num5 <= Mypageshowsize; num5++)
{
if (num2 == num5)
{
builder.Append("<td class=pagetrue><a href=" + Mypostbackurl + "?" + str + "=" + num5.ToString() + " title=第" + num5.ToString() + "页>" + num5.ToString() + "</a></td>\r\n");
}
else
{
builder.Append("<td class=pagefalse><a href=" + Mypostbackurl + "?" + str + "=" + num5.ToString() + " title=第" + num5.ToString() + "页>" + num5.ToString() + "</a></td>\r\n");
}
}
num3 = ((num2 / Mypageshowsize) + 1) * Mypageshowsize;
builder.Append("<td class=pagefalse><a href=" + Mypostbackurl + "?" + str + "=" + num3.ToString() + " title=下一组>.....</a></td>\r\n");
}
builder.Append("<td><select id=\"MySelectPage\" onchange=\"window.location='" + Mypostbackurl + "?" + str + "='+this.options[this.selectedIndex].value\">\r\n");
for (int i = 1; i < (num + 1); i++)
{
if ((HttpContext.Current.Request.QueryString[Myurlpage] != null) && (HttpContext.Current.Request.QueryString[Myurlpage].ToString() == i.ToString()))
{
builder.Append(string.Concat(new object[] { "<option value=", i, " selected>", i, "页</option>\r\n" }));
}
else
{
builder.Append(string.Concat(new object[] { "<option value=", i, ">", i, "页</option>\r\n" }));
}
}
builder.Append("</select></td>\r\n");
builder.Append(string.Concat(new object[] { "<td class=pagefalse><a href=", Mypostbackurl, "?", str, "=", num, " title=最后一页>最后一页</a></td>\r\n" }));
}
else
{
builder.Append("<td>抱歉没有数据</td>");
}
builder2.Append("<style>\r\n");
builder2.Append(".pageborder A:active,.pageborder A:hover,.pageborder A:visited,.pageborder A:link {\r\n");
builder2.Append("DISPLAY: block;COLOR: #686868;TEXT-DECORATION: none;font-size:14px;text-align:center;\r\n");
builder2.Append("border: 1px solid " + Mybordercolor + ";}\r\n");
builder2.Append(".pagefalse A:link,.pagefalse A:visited,.pagefalse A:active,.pagefalse A:hover {padding:3px;}\r\n");
builder2.Append(".pagetrue A:link,.pagetrue A:visited,.pagetrue A:active,.pagetrue A:hover {\r\n");
builder2.Append("padding:5px;background-color:" + Mycolor + ";color:" + Myfontcolor + ";}\r\n");
builder2.Append("</style>\r\n");
builder2.Append("<table cellspacing=0 class=pageborder>\r\n");
builder2.Append("<tr>\r\n");
builder2.Append(builder.ToString() + "\r\n");
builder2.Append("</tr>\r\n");
builder2.Append("</table>\r\n");
return builder2.ToString();
}
public SqlDataReader getBatchSale(Int32 id, int iSize, int iIndex, bool bDocount, string strCondition)
{
SqlDataReader dataReader = null;
database data = new database();
SqlParameter[] prams = {
data.MakeInParam("@id",SqlDbType.BigInt,8,id), //用作条件,用户id(可选)
data.MakeInParam("@pagesize",SqlDbType.Int,4,iSize),//每页显示条数
data.MakeInParam("@pageindex",SqlDbType.Int,4,iIndex),//第几页
data.MakeInParam("@docount",SqlDbType.Bit,1,bDocount),//是否统计数据
data.MakeInParam("@condition",SqlDbType.VarChar,800,strCondition) //其他条件(可选)
};
try
{
data.RunProc("sp_member_BatchSale", prams, out dataReader);
return (dataReader);
}
catch (Exception ex)
{
Error.Log(ex.ToString());
return null;
}
finally
{
data = null;
}
}
CREATE PROCEDURE sp_member_BatchSale
@id bigint,
@pagesize int,
@pageindex int,
@docount bit,
@condition varchar(800)
AS
set nocount on
if(@docount=1)
exec('select count(*) FROM web_C_BatchSale C_BatchSale inner join web_C_Customer c on c.CustomerID = C_BatchSale.CustomerID
left join Common_DCode on Common_DCode.DCode=c.AreaCode where C_BatchSale.UpUserID='+@id+@condition)
else
begin
declare @PageLowerBound int
set @PageLowerBound=(@pageindex-1)*@pagesize
if(@PageLowerBound=0)
exec('SELECT top 20 C_BatchSale.CustomerID as "C_BatchSale.CustomerID",
c.CustomerName as "C_BatchSale.CustomerName",
Common_DCode.DName,
C_BatchSale.BatchSaleNumber as "C_BatchSale.BatchSaleNumber",
Convert(varchar(10),C_BatchSale.SaleDate,120) as "C_BatchSale.SaleDate",
C_BatchSale.BSTypesCode as "C_BatchSale.BSTypesCode",
C_BatchSale.CarryModeCode as "C_BatchSale.CarryModeCode",
C_BatchSale.ReceiveModeCode as "C_BatchSale.ReceiveModeCode",
C_BatchSale.ReceiveStateCode as "C_BatchSale.ReceiveStateCode",
C_BatchSale.Operator as "C_BatchSale.Operator",
C_BatchSale.AddDate as "C_BatchSale.AddDate",
convert(numeric(8,2),round(C_BatchSale.TotalFixedPrice,2)) as "C_BatchSale.TotalFixedPrice",
convert(numeric(8,2),round(C_BatchSale.TotalDiscountedPrice,2)) as "C_BatchSale.TotalDiscountedPrice",
convert(numeric(8,2),round(C_BatchSale.AverageRebate,2)) as "C_BatchSale.AverageRebate",
C_BatchSale.AllowSendBackCode as "C_BatchSale.AllowSendBackCode",
C_BatchSale.StateCode as "C_BatchSale.StateCode",
C_BatchSale.TotalCount as "C_BatchSale.TotalCount",
C_BatchSale.Remark as "C_BatchSale.Remark"
FROM web_C_BatchSale C_BatchSale inner join web_C_Customer c on c.CustomerID = C_BatchSale.CustomerID
left join Common_DCode on Common_DCode.DCode=c.AreaCode
where C_BatchSale.UpUserID='+@id+@condition+'
ORDER BY C_BatchSale.OrderID')
else
begin
exec('SELECT top 20 C_BatchSale.CustomerID as "C_BatchSale.CustomerID",
c.CustomerName as "C_BatchSale.CustomerName",
Common_DCode.DName,
C_BatchSale.BatchSaleNumber as "C_BatchSale.BatchSaleNumber",
Convert(varchar(10),C_BatchSale.SaleDate,120) as "C_BatchSale.SaleDate",
C_BatchSale.BSTypesCode as "C_BatchSale.BSTypesCode",
C_BatchSale.CarryModeCode as "C_BatchSale.CarryModeCode",
C_BatchSale.ReceiveModeCode as "C_BatchSale.ReceiveModeCode",
C_BatchSale.ReceiveStateCode as "C_BatchSale.ReceiveStateCode",
C_BatchSale.Operator as "C_BatchSale.Operator",
C_BatchSale.AddDate as "C_BatchSale.AddDate",
convert(numeric(8,2),round(C_BatchSale.TotalFixedPrice,2)) as "C_BatchSale.TotalFixedPrice",
convert(numeric(8,2),round(C_BatchSale.TotalDiscountedPrice,2)) as "C_BatchSale.TotalDiscountedPrice",
convert(numeric(8,2),round(C_BatchSale.AverageRebate,2)) as "C_BatchSale.AverageRebate",
C_BatchSale.AllowSendBackCode as "C_BatchSale.AllowSendBackCode",
C_BatchSale.StateCode as "C_BatchSale.StateCode",
C_BatchSale.TotalCount as "C_BatchSale.TotalCount",
C_BatchSale.Remark as "C_BatchSale.Remark"
FROM web_C_BatchSale C_BatchSale inner join web_C_Customer c on c.CustomerID = C_BatchSale.CustomerID
left join Common_DCode on Common_DCode.DCode=c.AreaCode
where C_BatchSale.UpUserID='+@id+@condition+'
and C_BatchSale.orderID>(select max(OrderID) From
(Select top '+@PageLowerBound+' C_BatchSale.OrderID FROM web_C_BatchSale C_BatchSale inner join web_C_Customer c
on c.CustomerID = C_BatchSale.CustomerID left join Common_DCode on Common_DCode.DCode=c.AreaCode
where C_BatchSale.UpUserID='+@id+@condition+'
ORDER BY C_BatchSale.orderID
) As ENGINE_CHILDQUERY_TEMPTABLE)
ORDER BY C_BatchSale.orderID')
end
end
set nocount off
GO
CREATE PROCEDURE sp_memberCenter_BookStock
@id int,
@pagesize int,
@pageindex int,
@docount bit,
@condition varchar(800)
AS
set nocount on
if(@docount=1)
exec('select count(*) from web_publish_Books_Storage a inner join web_publish_books b
on a.booknumber=b.booknumber where b.upuserid='+@id+@condition)
else
begin --select * from common_code where codeid=7
declare @PageLowerBound int
declare @PageUpperBound int
set @PageLowerBound=(@pageindex-1)*@pagesize
set @PageUpperBound=@PageLowerBound+@pagesize
set rowcount @PageUpperBound
set @PageLowerBound=@PageLowerBound+1
exec('declare @indextable table(id int identity(1,1),nid int)
insert into @indextable(nid) select a.BookNumber from web_publish_Books_Storage a inner join web_publish_books b
on a.booknumber=b.booknumber where b.upuserid='+@id+@condition+' order by a.adddate desc
SELECT a.booknumber,storagevalues,instoragetotal,a.adddate,bookname,
(SELECT typesname FROM web_B_BookTypes z where b.BookTypeCode=z.typesid)as booktypecode,author,
(select codename from common_code c where c.codeid=7 and a.SaleState=c.code) as SaleState,
Convert(numeric(10,2),price) as price
FROM web_publish_Books_Storage a inner join web_publish_books b
on a.booknumber=b.booknumber,@indextable t
where b.upuserid='+@id+@condition+' and a.BookNumber=t.nid
and t.id between '+@PageLowerBound+' and '+@PageUpperBound+'
order by t.id ')
end
set nocount off
GO
/// <summary>
/// 分页绑定
/// </summary>
/// <param name="strTCondition"></param>
private void GridTotal(string strTCondition)
{
SqlDataReader drStorage = member.getBatchSale(Convert.ToInt32(Session["user_id"]), 1, 1, true, strTCondition);
while (drStorage.Read())
{
Pager.RecordCount = Convert.ToInt32(drStorage[0].ToString());
}
drStorage.Close();
}
/// <summary>
/// gridview绑定
/// </summary>
/// <param name="strGCondition"></param>
private void BindGrid(string strGCondition)
{
SqlDataReader drStorage = member.getBatchSale(Convert.ToInt32(Session["user_id"]), Pager.PageSize, Pager.CurrentPageIndex, false, strGCondition);
DataTable dtStorage = tools.ConvertDataReaderToDataTable(drStorage);
dtStorage.TableName = "BatchSale";
grid_List.DataSource = dtStorage.DefaultView;
grid_List.DataBind();
lblNum.Text = Pager.RecordCount.ToString();
}
/// <summary>
/// 分页控件分页事件
/// </summary>
/// <param name="src"></param>
/// <param name="e"></param>
protected void Pager_PageChanged(object src, Wuqi.Webdiyer.PageChangedEventArgs e)
{
Pager.CurrentPageIndex = e.NewPageIndex;
BindGrid(strCondition);
}
<div class="content" style="width: 776px; text-align: left">
<div style="overflow-x: scroll; overflow-y: hidden;width: 776px; ">
<asp:GridView ID="grid_List" runat="server" AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="C_BatchSale.BatchSaleNumber"
CellPadding="4" OnDataBound="grid_List_DataBound" PageSize="20" Width="1400px" OnRowDeleting="grid_List_RowDeleting" OnRowDataBound="grid_List_RowDataBound" BorderColor="#93BEE2" BorderStyle="Solid">
<Columns>
<asp:HyperLinkField DataNavigateUrlFields="C_BatchSale.CustomerID" DataNavigateUrlFormatString="CustomerInfo.aspx?id={0}"
DataTextField="C_BatchSale.CustomerName" HeaderText="客户名称">
<ItemStyle Width="150px" />
</asp:HyperLinkField>
<asp:BoundField DataField="DName" HeaderText="所属区域">
<ItemStyle Width="140px" />
</asp:BoundField>
<asp:BoundField DataField="C_BatchSale.BatchSaleNumber" HeaderText="批销单号">
<ItemStyle Width="90px" />
</asp:BoundField>
<asp:BoundField DataField="C_BatchSale.SaleDate" DataFormatString="{0:d}" HeaderText="批销日期">
<ItemStyle Width="70px" />
</asp:BoundField>
<asp:BoundField DataField="C_BatchSale.BSTypesCode" HeaderText="批销类型">
<ItemStyle Width="53px" />
</asp:BoundField>
<asp:BoundField DataField="C_BatchSale.CarryModeCode" HeaderText="发货方式">
<ItemStyle Width="53px" />
</asp:BoundField>
<asp:BoundField DataField="C_BatchSale.ReceiveStateCode" HeaderText="收款情况">
<ItemStyle Width="53px" />
</asp:BoundField>
<asp:BoundField DataField="C_BatchSale.Operator" HeaderText="操作员">
<ItemStyle Width="53px" />
</asp:BoundField>
<asp:BoundField DataField="C_BatchSale.TotalFixedPrice" HeaderText="总码洋">
<ItemStyle Width="60px" />
</asp:BoundField>
<asp:BoundField DataField="C_BatchSale.TotalDiscountedPrice" HeaderText="总实洋">
<ItemStyle Width="60px" />
</asp:BoundField>
<asp:BoundField DataField="C_BatchSale.AverageRebate" HeaderText="平均折扣">
<ItemStyle Width="53px" />
</asp:BoundField>
<asp:BoundField DataField="C_BatchSale.AllowSendBackCode" HeaderText="允许退货">
<ItemStyle Width="53px" />
</asp:BoundField>
<asp:BoundField DataField="C_BatchSale.StateCode" HeaderText="单据状态">
<ItemStyle Width="53px" />
</asp:BoundField>
<asp:BoundField DataField="C_BatchSale.TotalCount" HeaderText="本单数量">
<ItemStyle Width="53px" />
</asp:BoundField>
<asp:BoundField DataField="C_BatchSale.AddDate" HeaderText="添加日期">
<ItemStyle Width="120px" />
</asp:BoundField>
<asp:BoundField DataField="C_BatchSale.Remark" Visible="False" HeaderText="备注"/>
<asp:HyperLinkField DataNavigateUrlFields="C_BatchSale.BatchSaleNumber" DataNavigateUrlFormatString="AddBatchSale.aspx?bid={0}&type=upd"
HeaderText="修改" Text="修改">
<ItemStyle Width="30px" />
</asp:HyperLinkField>
<asp:TemplateField HeaderText="删除">
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandName="Delete"
OnClientClick='return confirm("您确定要删除这条记录吗?")' Text="删除"></asp:LinkButton>
</ItemTemplate>
<ItemStyle Width="30px" />
</asp:TemplateField>
</Columns>
<HeaderStyle BackColor="#859FD4" Font-Bold="False" ForeColor="White" />
</asp:GridView>
</div>
<div style="margin-top: 0px; font-size: 12px; letter-spacing: 2px; text-align: right;
text-decoration: none">
<webdiyer:aspnetpager id="Pager" runat="server" alwaysshow="True" cssclass="" custominfosectionwidth="10%"
custominfotext="" custominfotextalign="Justify" imagepath="/" inputboxclass="txtnav" NumericButtonTextFormatString="[{0}]"
inputboxstyle="txtnav" onpagechanged="Pager_PageChanged" pagesize="20" pagingbuttonspacing="80px"
showcustominfosection="Left" showinputbox="Always" submitbuttonclass="btn1nav"
submitbuttonstyle="btn1nav" textafterinputbox="页 " textbeforeinputbox="第">
</webdiyer:aspnetpager>
</div>
</div>
/// <summary>
/// 分页函数
/// </summary>
/// <param name="pageSize">每页记录记录数</param>
/// <param name="navNum">数字页码显示个数</param>
/// <param name="firstPage">首页</param>
/// <param name="prevPage">上页</param>
/// <param name="nextPage">下页</param>
/// <param name="lastPage">末页</param>
/// <param name="leftHtml">页码左边内容</param>
/// <param name="rightHtml">页码右边内容</param>
/// <param name="outerSpace">首上下末间空格</param>
/// <param name="innerSpace">数字页码间空格</param>
/// <param name="urlParam">要转向的URL地址,须加?号</param>
/// <param name="tableKey">表的主键</param>
/// <param name="tableName">表的名称</param>
/// <param name="theField">表的字段</param>
/// <param name="theWhere">以where开头,不能为空</param>
/// <param name="theOrder">排序语句,可为空</param>
/// <param name="currentPage">当前页,从1开始</param>
/// <param name="cmdParam">含参数的Command对象</param>
/// <param name="objs">参数列表</param>
public static Hashtable ExecutePage(int pageSize, int navNum, string firstPage, string prevPage, string nextPage, string lastPage, string leftHtml, string rightHtml, string outerSpace, string innerSpace, string urlParam, string tableKey, string tableName, string theField, string theWhere, string theOrder, int currentPage, SqlCommand cmdParam, params object[] objs)
{
int num = 0;
Hashtable ha = new Hashtable();
if (navNum % 2 == 0) navNum++;
if (firstPage == "0")
{
firstPage = "<font face=webdings>9</font>";
prevPage = "<font face=webdings>7</font>";
nextPage = "<font face=webdings>8</font>";
lastPage = "<font face=webdings>:</font>";
}
if (prevPage == "0")
{
firstPage = "";
prevPage = "<font face=webdings>7</font>";
nextPage = "<font face=webdings>8</font>";
lastPage = "";
}
SqlCommand cmd = cmdParam;
if (cmd == null) cmd = new SqlCommand();
try
{
cmd.Connection = new SqlConnection(ConnectionString);
cmd.CommandText = "select count(*) from " + tableName + " " + theWhere;
for (int i = 0; i < objs.Length; i += 2) cmd.Parameters.Add(objs[i].ToString(), objs[i + 1]);
cmd.Connection.Open();
num = Convert.ToInt32(cmd.ExecuteScalar());
}
catch (SqlException ex)
{
ErrorMessage = ex.Message;
}
finally
{
cmd.Connection.Close();
}
int total = (num - 1) / pageSize + 1;
if (currentPage < 1 || currentPage > num || num < 1) return null;
string sql = "select top " + pageSize + " " + theField + " from " + tableName + " " + theWhere + " " + theOrder;
if (currentPage != 1) sql = "select top " + pageSize + " " + theField + " from " + tableName + " " + theWhere + " and " + tableKey + " not in (select top " + pageSize * (currentPage - 1) + " " + tableKey + " from " + tableName + " " + theWhere + " " + theOrder + ") " + theOrder;
cmd.CommandText = sql;
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
string span = "<span>";
if (currentPage != 1)
{
span += "<a title='首页' href='" + urlParam + "&page=1'>" + firstPage + "</a>" + outerSpace;
span += "<a title='上一页' href='" + urlParam + "&page=" + (currentPage - 1) + "'>" + prevPage + "</a>" + outerSpace;
}
else
{
span += "<a disabled=disabled>" + firstPage + "</a>" + outerSpace;
span += "<a disabled=disabled>" + prevPage + "</a>" + outerSpace;
}
if (navNum > 0)
{
int start = 1, end = total, len = navNum / 2;
if (navNum < total)
{
start = currentPage - len;
end = currentPage + len;
if (start < 1)
{
start = 1;
end = navNum;
}
if (end > total)
{
start = total - navNum + 1;
end = total;
}
}
for (int i = start; i <= end; i++)
{
if (i == currentPage)
{
//span += "<font color=red>" + leftHtml + i + rightHtml + "</font>" + innerSpace;
span += i + innerSpace;
}
else
{
if (i != end)
{
span += "<a title='第" + i + "页' href='" + urlParam + "&page=" + i + "'>" + leftHtml + i + rightHtml + "</a>" + innerSpace;
}
else
{
span += "<a title='第" + i + "页' href='" + urlParam + "&page=" + i + "'>" + leftHtml + i + rightHtml + "</a>";
}
}
}
span = span.Trim(' ');
span += outerSpace;
}
if (currentPage != total)
{
span += "<a title='下一页' href='" + urlParam + "&page=" + (currentPage + 1) + "'>" + nextPage + "</a>" + outerSpace;
span += "<a title='尾页' href='" + urlParam + "&page=" + ((num - 1) / pageSize + 1) + "'>" + lastPage + "</a>";
}
else
{
span += "<a disabled=disabled>" + nextPage + "</a>" + outerSpace;
span += "<a disabled=disabled>" + lastPage + "</a>";
}
ha.Add("MainPage", span);
span = "<table cellpadding=0 cellspacing=0 width=100% style='margin-top:10px'><tr><td style='padding-left:10px;padding-top:2px'>第<font color=red>" + currentPage + "</font>页 共<font color=red>" + total + "</font>页 每页<font color=red>" + pageSize + "</font>条记录 共<font color=red>" + num + "</font>条记录</td><td align=right>" + span + "</td></tr></table>";
ha.Add("AutoPage", span);
span = "\n<input id=goto size=1 value=" + currentPage + " onchange=\"location.href='" + urlParam + "&page='+document.getElementById('goto').value\">\n<input type=button size=1 value=GO onclick=\"location.href='" + urlParam + "&page='+document.getElementById('goto').value\">";
ha.Add("GotoPage", span);
span = "\n<select onchange=\"location.href='" + urlParam + "&page='+this.value\">\n";
for (int i = 1; i <= total; i++) span += "\t<option value=" + i + (i == currentPage ? " selected" : "") + ">第" + i + "页</option>\n";
span += "</select>\n";
ha.Add("SelectPage", span);
ha.Add("CurrentPage", currentPage);
ha.Add("TotalPage", total);
ha.Add("PageSize", pageSize);
ha.Add("TotalRecords", num);
ha.Add("DataSet", ds);
return ha;
}