Sql Server2000 存储过程
--用户管理分页
--参数@NewsTypeID 新闻类型
--参数@NewsStatus 新闻状态
--参数@KeyWord 关键字
--参数@Promulgator 发布者
--参数@InTime 发布时间
-- @docount=1 返回记录统计
Alter procedure PR_GetNews
(
@KeyWord varchar(100),
@NewsTypeID varchar(8),
@NewsStatus int,
@Promulgator varchar(50),
@InTime datetime,
@pagesize int,
@pageindex int,
@docount bit
)
as
set nocount on
declare @where nvarchar(400)
set @where='where 1=1'
if @KeyWord <> '' set @where = @where+' and (Content like ''%'+@KeyWord+'%'' or Title like ''%'+@KeyWord+'%'')'
if @NewsTypeID <>'' set @where=@where+' and NewsTypeID like ''%'+@NewsTypeID+'%''' --使用模糊查询因为一条新闻可能是多个类型
if @NewsStatus >= 0 set @where=@where+' and NewsStatus= '+str(@NewsStatus,1) + ''
if @Promulgator <> '' set @where = @where+' and Promulgator like ''%' + @Promulgator + '%'''
if @InTime is not null set @where = @where + ' and (NewsCheckInTime between '''+convert(varchar(10),@InTime,120)+''' and '''+convert(varchar(10),GetDate()+1,120)+''')'
declare @RecordCount int
declare @TempSql nvarchar(1000)
print @where
set @TempSql='select @RecordCount=count(NewsID) from TB_News '+ @where
exec sp_executesql @TempSql,N'@RecordCount int output',@RecordCount output
if(@docount=1)
select @RecordCount
else
begin
if(@pageindex=1)
exec('select top '+@pagesize+' * from TB_News '+@where+' order by NewsID desc')
else
begin
declare @PageUpperBound int
declare @endrecords int
set @PageUpperBound=@pageindex*@pagesize
if(@PageUpperBound-@pagesize)>=@RecordCount
select ''
else if(@RecordCount-(@PageUpperBound-@pagesize)<=@pagesize)
begin
set @endrecords=@RecordCount-(@PageUpperBound-@pagesize)
exec('select * from (select top '+@endrecords+' * from TB_News '+@where+' order by NewsID )A order by NewsID desc')
end
else
exec('select * from (select top '+@pagesize+'* from (select top '+@PageUpperBound+' * from TB_News '+@where+' order by NewsID desc)A order by NewsID )B order by NewsID desc')
end
end
set nocount off
--select @where
GO
管理分页代码
//绑定 DataGrid 及 AspNetPage控件
private void GridDataBind(string KeyWord,string NewsTypeID,int NewsStatus,string Promulgator,string InTime)
{
DataSet ds=null;
//获取总记录总数
MyPage.RecordCount = Pad.BS.Facade.System.FNews.PR_GetNews_ByPageCount(KeyWord,NewsTypeID,NewsStatus,Promulgator,InTime);
ds = Pad.BS.Facade.System.FNews.PR_GetNews_ByPage(KeyWord,NewsTypeID,NewsStatus,Promulgator,InTime,MyPage.PageSize,MyPage.CurrentPageIndex);
this.gridNews.DataSource = ds;
this.gridNews.DataBind();
MyPage.CustomInfoText="记录总数:<font color="red"><b>"+MyPage.RecordCount.ToString()+"</b></font>";
MyPage.CustomInfoText+=" 总页数:<font color="red"><b>"+MyPage.PageCount.ToString()+"</b></font>";
MyPage.CustomInfoText+=" 当前页:<font color="red"><b>"+MyPage.CurrentPageIndex.ToString()+"</b></font>";
}
//AspNetPage的 PageChanged 事件
private void MyPage_PageChanged(object src, Pad.WControl.PageChangedEventArgs e)
{
MyPage.CurrentPageIndex = e.NewPageIndex;
GridDataBind(this.txtKeyWord.Text.ToString(),this.listNewsType.SelectedValue.ToString(),
Convert.ToInt32(this.ListStatus.SelectedValue.ToString()),this.txtAuthor.Text.ToString(),
this.txtDate.Text.ToString());
}

838

被折叠的 条评论
为什么被折叠?



