HTML
=======================================
@model wafrooBL.Models.GetMyDealList
@if (Model.pager.EndPage > 1)
{
<ul class="pagination">
@if (Model.pager.CurrentPage > 1)
{
<li>
<a href="/customer/MyDeals/Index">First</a>
</li>
<li>
<a href="/customer/MyDeals/Index?pageno=@(Model.pager.CurrentPage - 1)">Previous</a>
</li>
}
@for (var page = Model.pager.StartPage; page <= Model.pager.EndPage; page++)
{
<li class="@(page == Model.pager.CurrentPage ? "active" : "")">
<a href="/customer/MyDeals/Index?pageno=@page">@page</a>
</li>
}
@if (Model.pager.CurrentPage < Model.pager.TotalPages)
{
<li>
<a href="/customer/MyDeals/Index?pageno=@(Model.pager.CurrentPage + 1)">Next</a>
</li>
<li>
<a href="/customer/MyDeals/Index?pageno=@(Model.pager.TotalPages)">Last</a>
</li>
}
</ul>
}
================================================================
Controller
===========================================================
public ActionResult Index(long? CustomerId = null, int? pageno=1)
{
GetMyDealList obj = null;
int Pagesize = 5;
int totalrecord = 0;
if (CustomerId != null)
{
obj = new GetMyDealList(CustomerId, pageno, Pagesize);
if(obj.list.Count>0)
{
totalrecord = obj.list[0].TotalCount;
}
var pager = new Pager(totalrecord,pageno, Pagesize);
obj.pager = pager;
}
return View(obj);
}
==========================================================
Bl and property
=========================================================
public class GetMyDealList
{
public List<Deal> list { get; set; }
public Pager pager { get; set; }
BusinessLogic bl = new BusinessLogic();
public GetMyDealList(long? CustomerId = null, int ? pageno =null, int ? Pagesize=null)
{
this.list = bl.GetMyDeal(CustomerId, pageno, Pagesize);
}
}
public class Pager
{
public Pager(int totalItems, int? page, int pageSize)
{
// calculate total, start and end pages
var totalPages = (int)Math.Ceiling((decimal)totalItems / (decimal)pageSize);
var currentPage = page != null ? (int)page : 1;
var startPage = currentPage - 5;
var endPage = currentPage + 4;
if (startPage <= 0)
{
endPage -= (startPage - 1);
startPage = 1;
}
if (endPage > totalPages)
{
endPage = totalPages;
if (endPage > 10)
{
startPage = endPage - 9;
}
}
TotalItems = totalItems;
CurrentPage = currentPage;
PageSize = pageSize;
TotalPages = totalPages;
StartPage = startPage;
EndPage = endPage;
}
public int TotalItems { get; private set; }
public int CurrentPage { get; private set; }
public int PageSize { get; private set; }
public int TotalPages { get; private set; }
public int StartPage { get; private set; }
public int EndPage { get; private set; }
}
=======================================================
Dll get info using Stored Proceduer
============================================
ALTER procedure [dbo].[getMyDealsGk] --@CustomerId=2, @pageno=1 ,@Pagesize=40
(
@CustomerId bigint = 0,
@Result int =0 OUT,
@Message nvarchar(100)=null OUT,
@pageno int=0,
@Pagesize int=0
)
AS
BEGIN
if(@CustomerId!=0)
begin
declare @RowSkip int
declare @TotalRecord int
set @RowSkip =(@pageno - 1) * @Pagesize
select @TotalRecord=count(1) from [Deals-Master] DM
where DM.[IsDelete] = 0 and DM.CustomerId = @CustomerId
SELECT DISTINCT DM.[DealID]
,DM.[VendorID]
,@TotalRecord as totalrecord
FROM [Deals-Master] DM
where DM.[IsDelete] = 0 and DM .CustomerId = @CustomerId order by DM .CustomerId
OFFSET @RowSkip ROWS FETCH NEXT @Pagesize ROWS ONLY
end
END
--select @@version
--select * from [MyDeals] where
=======================================
@model wafrooBL.Models.GetMyDealList
@if (Model.pager.EndPage > 1)
{
<ul class="pagination">
@if (Model.pager.CurrentPage > 1)
{
<li>
<a href="/customer/MyDeals/Index">First</a>
</li>
<li>
<a href="/customer/MyDeals/Index?pageno=@(Model.pager.CurrentPage - 1)">Previous</a>
</li>
}
@for (var page = Model.pager.StartPage; page <= Model.pager.EndPage; page++)
{
<li class="@(page == Model.pager.CurrentPage ? "active" : "")">
<a href="/customer/MyDeals/Index?pageno=@page">@page</a>
</li>
}
@if (Model.pager.CurrentPage < Model.pager.TotalPages)
{
<li>
<a href="/customer/MyDeals/Index?pageno=@(Model.pager.CurrentPage + 1)">Next</a>
</li>
<li>
<a href="/customer/MyDeals/Index?pageno=@(Model.pager.TotalPages)">Last</a>
</li>
}
</ul>
}
================================================================
Controller
===========================================================
public ActionResult Index(long? CustomerId = null, int? pageno=1)
{
GetMyDealList obj = null;
int Pagesize = 5;
int totalrecord = 0;
if (CustomerId != null)
{
obj = new GetMyDealList(CustomerId, pageno, Pagesize);
if(obj.list.Count>0)
{
totalrecord = obj.list[0].TotalCount;
}
var pager = new Pager(totalrecord,pageno, Pagesize);
obj.pager = pager;
}
return View(obj);
}
==========================================================
Bl and property
=========================================================
public class GetMyDealList
{
public List<Deal> list { get; set; }
public Pager pager { get; set; }
BusinessLogic bl = new BusinessLogic();
public GetMyDealList(long? CustomerId = null, int ? pageno =null, int ? Pagesize=null)
{
this.list = bl.GetMyDeal(CustomerId, pageno, Pagesize);
}
}
public class Pager
{
public Pager(int totalItems, int? page, int pageSize)
{
// calculate total, start and end pages
var totalPages = (int)Math.Ceiling((decimal)totalItems / (decimal)pageSize);
var currentPage = page != null ? (int)page : 1;
var startPage = currentPage - 5;
var endPage = currentPage + 4;
if (startPage <= 0)
{
endPage -= (startPage - 1);
startPage = 1;
}
if (endPage > totalPages)
{
endPage = totalPages;
if (endPage > 10)
{
startPage = endPage - 9;
}
}
TotalItems = totalItems;
CurrentPage = currentPage;
PageSize = pageSize;
TotalPages = totalPages;
StartPage = startPage;
EndPage = endPage;
}
public int TotalItems { get; private set; }
public int CurrentPage { get; private set; }
public int PageSize { get; private set; }
public int TotalPages { get; private set; }
public int StartPage { get; private set; }
public int EndPage { get; private set; }
}
=======================================================
Dll get info using Stored Proceduer
============================================
ALTER procedure [dbo].[getMyDealsGk] --@CustomerId=2, @pageno=1 ,@Pagesize=40
(
@CustomerId bigint = 0,
@Result int =0 OUT,
@Message nvarchar(100)=null OUT,
@pageno int=0,
@Pagesize int=0
)
AS
BEGIN
if(@CustomerId!=0)
begin
declare @RowSkip int
declare @TotalRecord int
set @RowSkip =(@pageno - 1) * @Pagesize
select @TotalRecord=count(1) from [Deals-Master] DM
where DM.[IsDelete] = 0 and DM.CustomerId = @CustomerId
SELECT DISTINCT DM.[DealID]
,DM.[VendorID]
,@TotalRecord as totalrecord
FROM [Deals-Master] DM
where DM.[IsDelete] = 0 and DM .CustomerId = @CustomerId order by DM .CustomerId
OFFSET @RowSkip ROWS FETCH NEXT @Pagesize ROWS ONLY
end
END
--select @@version
--select * from [MyDeals] where
No comments:
Post a Comment