最新更新 sitemap 网站制作设计本站搜索
网页设计
国外网站 韩国网站 个人主页 手提袋设计 CSS 网页特效 平面设计 网站设计 Flash CMS技巧 服装网站 php教程 photoshop 画册 服务器选用 数据库 Office
虚拟主机 域名注册 云主机 网页设计 客服QQ:8208442
当前位置:首页 > 编程开发 > asp教程

ASP中Flex分页控件技巧

日期:08-02    来源:中国设计秀    作者:cnwebshow.com

提到分页大家应该都很熟悉了,几乎所有的应用中都会用到。因而完成一个分页组件在不同的应用中进行复用是必须的,刚写完了一个flex分页的组件,拿来分享一下。如果有什么建议、问题欢迎大家提出。希望可以为flex的开发者们提供一个可靠的分页组件。csw中国设计秀
csw中国设计秀
                                                                                                    csw中国设计秀
csw中国设计秀
package utils.pagecsw中国设计秀
csw中国设计秀
{csw中国设计秀
csw中国设计秀
    import Flash.events.MouseEvent;csw中国设计秀
csw中国设计秀
    csw中国设计秀
csw中国设计秀
    import mx.controls.Button;csw中国设计秀
csw中国设计秀
    import mx.controls.Label;csw中国设计秀
csw中国设计秀
    csw中国设计秀
csw中国设计秀
    //分页组件类csw中国设计秀
csw中国设计秀
    //作者:孙镜涛csw中国设计秀
csw中国设计秀
    //日期:2010-01-12csw中国设计秀
csw中国设计秀
    //描述:本类主要负责对分页相关的按钮以及信息显示的标签进行管理;对数据显示内容进行控制csw中国设计秀
csw中国设计秀
    public class PageComponentcsw中国设计秀
csw中国设计秀
    {csw中国设计秀
csw中国设计秀
       //首页按钮csw中国设计秀
csw中国设计秀
       PRivate var firstButton:Button;csw中国设计秀
csw中国设计秀
       //下一页按钮csw中国设计秀
csw中国设计秀
       private var nextButton:Button;csw中国设计秀
csw中国设计秀
       //前一页按钮csw中国设计秀
csw中国设计秀
       private var previousButton:Button;csw中国设计秀
csw中国设计秀
       //最后页按钮csw中国设计秀
csw中国设计秀
       private var lastButton:Button;csw中国设计秀
csw中国设计秀
       //当前页信息显示csw中国设计秀
csw中国设计秀
       private var curPageInfoLbl:Label;csw中国设计秀
csw中国设计秀
       //所有页信息显示csw中国设计秀
csw中国设计秀
       private var totalPageInfoLbl:Label;csw中国设计秀
csw中国设计秀
       //当前页改变时数据处理方法csw中国设计秀
csw中国设计秀
       private var handleDataFun:Function;csw中国设计秀
csw中国设计秀
       //分页数据的处理类csw中国设计秀
csw中国设计秀
       private var page:PageUtils;csw中国设计秀
csw中国设计秀
       csw中国设计秀
csw中国设计秀
       //first,next,previous,last:第一页,下一页,上一页,最后页的buttoncsw中国设计秀
csw中国设计秀
       //curPageInfoLbl,totalPageInfoLbl:当前页,所有页信息显示的labelcsw中国设计秀
csw中国设计秀
       //handleDataFun:分页的页码改变后数据的处理函数,该函数符合的签名为:(data:Array):voidcsw中国设计秀
csw中国设计秀
       //exeFun:查询数据的sql,该函数的签名为:(sql:String):Arraycsw中国设计秀
csw中国设计秀
       //pageNum:每页显示数据条数csw中国设计秀
csw中国设计秀
       public function PageComponent(first:Button,next:Button,previous:Button,last:Button,curPageInfoLbl:Label,csw中国设计秀
csw中国设计秀
                                     totalPageInfoLbl:Label,handleDataFun:Function,exeFun:Function,pageNum:int)csw中国设计秀
csw中国设计秀
       {csw中国设计秀
csw中国设计秀
           //分页按钮初始化csw中国设计秀
csw中国设计秀
           this.firstButton=first;csw中国设计秀
csw中国设计秀
           this.nextButton=next;csw中国设计秀
csw中国设计秀
           this.previousButton=previous;csw中国设计秀
csw中国设计秀
           this.lastButton=last;csw中国设计秀
csw中国设计秀
           csw中国设计秀
csw中国设计秀
           //分页信息显示控件初始化csw中国设计秀
csw中国设计秀
           this.curPageInfoLbl=curPageInfoLbl;csw中国设计秀
csw中国设计秀
           this.totalPageInfoLbl=totalPageInfoLbl;csw中国设计秀
csw中国设计秀
           csw中国设计秀
csw中国设计秀
           //页面改变后数据处理函数csw中国设计秀
csw中国设计秀
           this.handleDataFun=handleDataFun;csw中国设计秀
csw中国设计秀
           csw中国设计秀
csw中国设计秀
           //分页数据类初始化csw中国设计秀
csw中国设计秀
           this.page=new PageUtils(exeFun,pageNum);csw中国设计秀
csw中国设计秀
           csw中国设计秀
csw中国设计秀
           //为分页按钮增加相应的事件处理函数csw中国设计秀
csw中国设计秀
           this.firstButton.addEventListener(MouseEvent.CLICK,firstButtonClicked);csw中国设计秀
csw中国设计秀
           this.nextButton.addEventListener(MouseEvent.CLICK,nextButtonClicked);csw中国设计秀
csw中国设计秀
           this.previousButton.addEventListener(MouseEvent.CLICK,previousButtonClicked);csw中国设计秀
csw中国设计秀
           this.lastButton.addEventListener(MouseEvent.CLICK,lastButtonClicked);csw中国设计秀
csw中国设计秀
       }csw中国设计秀
csw中国设计秀
       csw中国设计秀
csw中国设计秀
       //需要分页查询的的sqlcsw中国设计秀
csw中国设计秀
       public function initSql(sql:String):voidcsw中国设计秀
csw中国设计秀
       {csw中国设计秀
csw中国设计秀
           this.page.initSqlAndInitDataIfNecessary(sql);        csw中国设计秀
csw中国设计秀
           setButtonStatus();csw中国设计秀
csw中国设计秀
           setLabelInfo();csw中国设计秀
csw中国设计秀
           this.handleDataFun(page.getPageData());csw中国设计秀
csw中国设计秀
       }csw中国设计秀
csw中国设计秀
csw中国设计秀
csw中国设计秀
       //分页按钮被点击时的处理逻辑为:csw中国设计秀
csw中国设计秀
       //1.设置当前数据的页数csw中国设计秀
csw中国设计秀
       //2.设置分页控件按钮的状态csw中国设计秀
csw中国设计秀
       //3.设置分页控件信息显示label的内容csw中国设计秀
csw中国设计秀
       //4.查询该页数据并执行数据处理函数csw中国设计秀
csw中国设计秀
       csw中国设计秀
csw中国设计秀
       //点击第一页时触发的事件csw中国设计秀
csw中国设计秀
       public function firstButtonClicked(event:MouseEvent):voidcsw中国设计秀
csw中国设计秀
       {csw中国设计秀
csw中国设计秀
           page.setCurrentPage(1);csw中国设计秀
csw中国设计秀
           setButtonStatus();csw中国设计秀
csw中国设计秀
           setLabelInfo();csw中国设计秀
csw中国设计秀
           this.handleDataFun(page.getPageData());csw中国设计秀
csw中国设计秀
       }csw中国设计秀
csw中国设计秀
       csw中国设计秀
csw中国设计秀
       //点击下一页时触发的事件csw中国设计秀
csw中国设计秀
       public function nextButtonClicked(event:MouseEvent):voidcsw中国设计秀
csw中国设计秀
       {csw中国设计秀
csw中国设计秀
           if(page.getCurrentPage()<page.getPageCount())csw中国设计秀
csw中国设计秀
           {csw中国设计秀
csw中国设计秀
              page.setCurrentPage(page.getCurrentPage()+1);csw中国设计秀
csw中国设计秀
           }csw中国设计秀
csw中国设计秀
           setButtonStatus();csw中国设计秀
csw中国设计秀
           setLabelInfo();csw中国设计秀
csw中国设计秀
           this.handleDataFun(page.getPageData());csw中国设计秀
csw中国设计秀
       }csw中国设计秀
csw中国设计秀
       csw中国设计秀
csw中国设计秀
       //点击上一页时触发的事件csw中国设计秀
csw中国设计秀
       public function previousButtonClicked(event:MouseEvent):voidcsw中国设计秀
csw中国设计秀
       {csw中国设计秀
csw中国设计秀
           if(page.getCurrentPage()>1)csw中国设计秀
csw中国设计秀
           {csw中国设计秀
csw中国设计秀
              page.setCurrentPage(page.getCurrentPage()-1);csw中国设计秀
csw中国设计秀
           }csw中国设计秀
csw中国设计秀
           setButtonStatus();csw中国设计秀
csw中国设计秀
           setLabelInfo();csw中国设计秀
csw中国设计秀
           this.handleDataFun(page.getPageData());csw中国设计秀
csw中国设计秀
       }csw中国设计秀
csw中国设计秀
       csw中国设计秀
csw中国设计秀
       //点击最后页时触发的事件csw中国设计秀
csw中国设计秀
       public function lastButtonClicked(event:MouseEvent):voidcsw中国设计秀
csw中国设计秀
       {csw中国设计秀
csw中国设计秀
           page.setCurrentPage(page.getPageCount());csw中国设计秀
csw中国设计秀
           setButtonStatus();csw中国设计秀
csw中国设计秀
           setLabelInfo();csw中国设计秀
csw中国设计秀
           this.handleDataFun(page.getPageData());csw中国设计秀
csw中国设计秀
       }csw中国设计秀
csw中国设计秀
       csw中国设计秀
csw中国设计秀
       //设置所有分页按钮的状态为不可用csw中国设计秀
csw中国设计秀
       private function setAllButtonStatusDisabled():voidcsw中国设计秀
csw中国设计秀
       {csw中国设计秀
csw中国设计秀
           this.firstButton.enabled=false;csw中国设计秀
csw中国设计秀
           this.previousButton.enabled=false;csw中国设计秀
csw中国设计秀
           this.nextButton.enabled=false;csw中国设计秀
csw中国设计秀
           this.lastButton.enabled=false;csw中国设计秀
csw中国设计秀
       }csw中国设计秀
csw中国设计秀
       csw中国设计秀
csw中国设计秀
       //设置分页按钮的状态csw中国设计秀
csw中国设计秀
       //步骤为:csw中国设计秀
csw中国设计秀
       //     1.首先设置所有分页按钮的状态为不可用csw中国设计秀
csw中国设计秀
       //     2.判断是否需要启用某些分页按钮(仅当查询有数据并且数据页数大于一的时候才有必要)csw中国设计秀
csw中国设计秀
       //         2.1如果需要启用某些按钮分为三种情况:csw中国设计秀
csw中国设计秀
       //            2.1.1位于第一页那么下一页和最后页的按钮可用csw中国设计秀
csw中国设计秀
       //            2.1.2位于中间页那么所有按钮可用csw中国设计秀
csw中国设计秀
       //            2.1.3位于最后也那么上一页和第一页的按钮可用csw中国设计秀
csw中国设计秀
       private function setButtonStatus():voidcsw中国设计秀
csw中国设计秀
       {csw中国设计秀
csw中国设计秀
           setAllButtonStatusDisabled();csw中国设计秀
csw中国设计秀
           if(page.getTotalCount()>0&&page.getPageCount()>1)csw中国设计秀
csw中国设计秀
           {csw中国设计秀
csw中国设计秀
              if(page.getCurrentPage()==1)csw中国设计秀
csw中国设计秀
              {csw中国设计秀
csw中国设计秀
                  this.nextButton.enabled=true;csw中国设计秀
csw中国设计秀
                  this.lastButton.enabled=true;csw中国设计秀
csw中国设计秀
              }csw中国设计秀
csw中国设计秀
              else if(page.getCurrentPage()<page.getPageCount()&&page.getCurrentPage()>1)csw中国设计秀
csw中国设计秀
              {csw中国设计秀
csw中国设计秀
                  this.nextButton.enabled=true;csw中国设计秀
csw中国设计秀
                  this.firstButton.enabled=true;csw中国设计秀
csw中国设计秀
                  this.previousButton.enabled=true;csw中国设计秀
csw中国设计秀
                  this.lastButton.enabled=true;csw中国设计秀
csw中国设计秀
              }csw中国设计秀
csw中国设计秀
              else if(page.getCurrentPage()==page.getPageCount())csw中国设计秀
csw中国设计秀
              {csw中国设计秀
csw中国设计秀
                  this.firstButton.enabled=true;csw中国设计秀
csw中国设计秀
                  this.previousButton.enabled=true;csw中国设计秀
csw中国设计秀
              }             csw中国设计秀
csw中国设计秀
           }csw中国设计秀
csw中国设计秀
       }   csw中国设计秀
csw中国设计秀
       csw中国设计秀
csw中国设计秀
       //设置查询结果分页信息的label内容csw中国设计秀
csw中国设计秀
       private function setLabelInfo():voidcsw中国设计秀
csw中国设计秀
       {csw中国设计秀
csw中国设计秀
           this.totalPageInfoLbl.text="共"+page.getPageCount()+"页";csw中国设计秀
csw中国设计秀
           this.curPageInfoLbl.text="当前第"+page.getCurrentPage()+"页";csw中国设计秀
csw中国设计秀
       }csw中国设计秀
csw中国设计秀
       csw中国设计秀
csw中国设计秀
    }csw中国设计秀
csw中国设计秀
}csw中国设计秀
csw中国设计秀
csw中国设计秀
csw中国设计秀
csw中国设计秀
csw中国设计秀
csw中国设计秀
csw中国设计秀
package utils.pagecsw中国设计秀
csw中国设计秀
{csw中国设计秀
csw中国设计秀
    import entity.ConsumptionRecord;csw中国设计秀
csw中国设计秀
    csw中国设计秀
csw中国设计秀
    //分页数据组件类csw中国设计秀
csw中国设计秀
    //作者:孙镜涛csw中国设计秀
csw中国设计秀
    //日期:2010-01-12csw中国设计秀
csw中国设计秀
    //描述:本类主要负责对分页数据的状态进行控制,以及进行查询数据csw中国设计秀
csw中国设计秀
    public class PageUtilscsw中国设计秀
csw中国设计秀
    {csw中国设计秀
csw中国设计秀
       //查询数据的函数csw中国设计秀
csw中国设计秀
       private var exeFun:Function;csw中国设计秀
csw中国设计秀
       csw中国设计秀
csw中国设计秀
       //分页查询的sqlcsw中国设计秀
csw中国设计秀
       private var sql:String;csw中国设计秀
csw中国设计秀
       //每页显示的记录条数csw中国设计秀
csw中国设计秀
       private var pageNumber:int=0;csw中国设计秀
csw中国设计秀
       //当前查询的记录总数csw中国设计秀
csw中国设计秀
       private var totalCount:int=0;csw中国设计秀
csw中国设计秀
       //当前所处的页数csw中国设计秀
csw中国设计秀
       private var currentPage:int=0;csw中国设计秀
csw中国设计秀
       //当前查询的记录总页数csw中国设计秀
csw中国设计秀
       private var totalPage:int=0;csw中国设计秀
csw中国设计秀
       csw中国设计秀
csw中国设计秀
       public function getPageCount():intcsw中国设计秀
csw中国设计秀
       {csw中国设计秀
csw中国设计秀
           return this.totalPage;csw中国设计秀
csw中国设计秀
       }csw中国设计秀
csw中国设计秀
       csw中国设计秀
csw中国设计秀
       public function getTotalCount():intcsw中国设计秀
csw中国设计秀
       {csw中国设计秀
csw中国设计秀
           return this.totalCount;csw中国设计秀
csw中国设计秀
       }csw中国设计秀
csw中国设计秀
       csw中国设计秀
csw中国设计秀
       public function getCurrentPage():intcsw中国设计秀
csw中国设计秀
       {csw中国设计秀
csw中国设计秀
           return this.currentPage;csw中国设计秀
csw中国设计秀
       }csw中国设计秀
csw中国设计秀
       csw中国设计秀
csw中国设计秀
       public function setCurrentPage(pageNum:int):voidcsw中国设计秀
csw中国设计秀
       {csw中国设计秀
csw中国设计秀
           this.currentPage=pageNum;csw中国设计秀
csw中国设计秀
       }csw中国设计秀
csw中国设计秀
       csw中国设计秀
csw中国设计秀
       //构造函数, exeFun为查询数据的函数,签名需要符合:(sql:String):Arraycsw中国设计秀
csw中国设计秀
       //         pageNum为每页显示记录数,默认为10csw中国设计秀
csw中国设计秀
       public function PageUtils(exeFun:Function,pageNum:int=10)csw中国设计秀
csw中国设计秀
       {csw中国设计秀
csw中国设计秀
           this.exeFun=exeFun;csw中国设计秀
csw中国设计秀
           this.pageNumber=pageNum;csw中国设计秀
csw中国设计秀
       }csw中国设计秀
csw中国设计秀
       csw中国设计秀
csw中国设计秀
       //初始化查询sql,如果必要那么进行分页数据的初始化csw中国设计秀
csw中国设计秀
       //具体步骤为:csw中国设计秀
csw中国设计秀
       //         1.如果本次查询和上次查询的sql不一样,那么进行分页数据初始化csw中国设计秀
csw中国设计秀
       //         2.构造查询记录总数的sqlcsw中国设计秀
csw中国设计秀
       //         3.根据查询记录总数的结果初始化本类的相关变量,如果没有返回结果那么使用默认值:0csw中国设计秀
csw中国设计秀
       public function initSqlAndInitDataIfNecessary(sql:String):voidcsw中国设计秀
csw中国设计秀
       {csw中国设计秀
csw中国设计秀
           if(this.sql!=sql)csw中国设计秀
csw中国设计秀
           {csw中国设计秀
csw中国设计秀
              this.sql=sql;csw中国设计秀
csw中国设计秀
              var countSql:String="SELECT COUNT(*) COUNT_NUMBER "+sql.substring(sql.indexOf("FROM"));csw中国设计秀
csw中国设计秀
              var data:Array=exeFun(countSql);csw中国设计秀
csw中国设计秀
              if(data!=null)csw中国设计秀
csw中国设计秀
              {   csw中国设计秀
csw中国设计秀
                  //设置总条数csw中国设计秀
csw中国设计秀
                  this.totalCount=data[0].COUNT_NUMBER;csw中国设计秀
csw中国设计秀
                  //设置总页数csw中国设计秀
csw中国设计秀
                  this.totalPage=this.totalCount%this.pageNumber==0?this.totalCount/this.pageNumber:this.totalCount/this.pageNumber+1;csw中国设计秀
csw中国设计秀
                  //设置当前页csw中国设计秀
csw中国设计秀
                  this.currentPage=1;csw中国设计秀
csw中国设计秀
              }   csw中国设计秀
csw中国设计秀
           }csw中国设计秀
csw中国设计秀
       }csw中国设计秀
csw中国设计秀
       csw中国设计秀
csw中国设计秀
       //获取分页数据的方法csw中国设计秀
csw中国设计秀
       public function getPageData():Arraycsw中国设计秀
csw中国设计秀
       {csw中国设计秀
csw中国设计秀
           var tempSql:String=this.sql+getLimitOffsetSuffix(this.pageNumber,(this.currentPage-1)*this.pageNumber);csw中国设计秀
csw中国设计秀
           return exeFun(tempSql);            csw中国设计秀
csw中国设计秀
       }csw中国设计秀
csw中国设计秀
       csw中国设计秀
csw中国设计秀
       //为查询sql增加分页条件csw中国设计秀
csw中国设计秀
       private function getLimitOffsetSuffix(limit:int,offset:int):Stringcsw中国设计秀
csw中国设计秀
       {csw中国设计秀
csw中国设计秀
           return " LIMIT "+limit+" OFFSET "+offset;csw中国设计秀
csw中国设计秀
       }csw中国设计秀
csw中国设计秀
csw中国设计秀
csw中国设计秀
    }csw中国设计秀
csw中国设计秀
}csw中国设计秀
csw中国设计秀
csw中国设计秀
csw中国设计秀
csw中国设计秀
csw中国设计秀
csw中国设计秀
csw中国设计秀
使用该代码你需要做什么:csw中国设计秀
csw中国设计秀
           //处理分页数据的方法csw中国设计秀
csw中国设计秀
           private function bindDataToGrid(data:Array):voidcsw中国设计秀
csw中国设计秀
           {csw中国设计秀
csw中国设计秀
              //将数据绑定到DataGrid上csw中国设计秀
csw中国设计秀
              dataGrid.dataProvider=data;csw中国设计秀
csw中国设计秀
           }csw中国设计秀
csw中国设计秀
           //执行数据查询的方法csw中国设计秀
csw中国设计秀
            public static function execute(sql:String):Arraycsw中国设计秀
csw中国设计秀
           {      csw中国设计秀
csw中国设计秀
               sqlStatement.text=sql;csw中国设计秀
csw中国设计秀
               sqlStatement.execute();csw中国设计秀
csw中国设计秀
               return sqlStatement.getResult().data;csw中国设计秀
csw中国设计秀
           }csw中国设计秀
csw中国设计秀
           //查询条件改变时执行的方法csw中国设计秀
csw中国设计秀
           private function searchConditionChanged():voidcsw中国设计秀
csw中国设计秀
           {csw中国设计秀
csw中国设计秀
//初始化分页组件csw中国设计秀
csw中国设计秀
var pageComponent:PageComponent=new csw中国设计秀
csw中国设计秀
PageComponent(firstBtn,nextBtn,previousBtn,lastBtn,lblCurrentPage,lblTotalPage,bindDataToGrid,execute,20);       csw中国设计秀
csw中国设计秀
var sql:String=”select name id from users”;csw中国设计秀
csw中国设计秀
//初始化查询sqlcsw中国设计秀
csw中国设计秀
              pageComponent.initSql(sql);            csw中国设计秀
csw中国设计秀
           }csw中国设计秀
csw中国设计秀
 csw中国设计秀

本文引用地址:/bc/article_46136.html
网站地图 | 关于我们 | 联系我们 | 网站建设 | 广告服务 | 版权声明 | 免责声明