我的net分页方法(三层架构、适用于所有数据控件)

     我是新手刚学net不久,这个是我在asp里面经常用的,速度还可,可以应付百万级的数据量,适用于任何复杂的SQL语句,现在把它转成net三层架构,我对net研究不多用的不多,不知道这样效率怎么样,贴出来让大家看看这样做行不行?

 

所使用的存储过程

Code

 

SQLHelper

Code

 

Model层

Code

 

DAL层

    /// <summary>
    
/// 分页数据获取类
    
/// </summary>

    public class PageDAO
    
{
        
private SQLHelper sqlhelper = null;

        
public PageDAO()
        
{
            sqlhelper 
= new SQLHelper();
        }


        
/// <summary>
        
/// 分页方法
        
/// </summary>
        
/// <param name="p">分页实体</param>
        
/// <param name="outCount">数据总数</param>
        
/// <returns></returns>

        public DataTable Page(PageInfo p, out int outCount)
        
{
            DataTable dt 
= new DataTable();
            dt 
= sqlhelper.ExecutePage(p.IPage, p.IPageSize, p.StrTable, p.StrText, p.StrWhere, p.StrIndex, p.StrOrder, out outCount);
            
return dt;
        }

    }

 

BLL层

    public class PageBll
    
{
        
private PageDAO pDao = null;

        
public PageBll()
        
{
            pDao 
= new PageDAO();
        }


        
/// <summary>
        
/// 分页方法
        
/// </summary>
        
/// <param name="p">分页实体</param>
        
/// <param name="outCount">数据总数</param>
        
/// <returns></returns>

        public DataTable Page(PageInfo p, out int outCount)
        
{
            
return pDao.Page(p, out outCount);
        }

    }

 

页面调用

    private PageBll pBll = new PageBll();

    
protected void Page_Load(object sender, EventArgs e)
    {
        
if (!Page.IsPostBack)
        {
            
//原SQL语句
            
//select l.id,l.inDate,l.outDate,u.[name],u.worderNumber,c.[name] from live l
            
//inner join [user] u on l.userId=u.id
            
//inner join card c on c.id=u.cardId
            
//where u.[name] like '杜毛' or u.worderNumber='dl0010'
            
//order by l.id desc

            
//加入分页实体
            PageInfo p = new PageInfo();
            p.IPage 
= 1;
            p.IPageSize 
= 10;
            p.StrTable 
= "live l inner join [user] u on l.userId=u.id inner join card c on c.id=u.cardId";
            p.StrText 
= "l.id,l.inDate,l.outDate,u.[name],u.worderNumber,c.[name]";
            p.StrWhere 
= "and u.[name] like '杜毛' or u.worderNumber='dl0010'";
            p.StrIndex 
= "l.id";
            p.StrOrder 
= "l.id desc";
            
int outCount;

            GridView1.DataSource 
= pBll.Page(p, out outCount).DefaultView;
            GridView1.DataBind();
            Response.Write(outCount);
        }
    }

 

 

posted @ 2009-03-13 11:42  ╰⑥月の雨╮  阅读(2863)  评论(8编辑  收藏  举报