实现Flex数据分页查询的几种处理方法

开发 后端
这段时间空闲的时候都在用Flex结合自己开发的框架做一些应用,在这里介绍一下如何进行Flex数据分页查询,顺便介绍一下Flex结合框架进行应用开发。

首先看下Flex数据分页查询需要的应用效果<!--[if !vml]-->

Flex数据分页查询效果

<!--[endif]-->

实际功能包括对Customer进行条件和Flex数据分页查询,客户相关国家数据查询。

  1. <!--[if !supportLists]-->l        <!--[endif]-->服务端功能处理  
  2. <!--[if !supportLists]-->u     <!--[endif]-->根据逻辑定义相关数据操作实体类  
  3.     [Table("Customers")]  
  4.     interface ICustomer  
  5.     {  
  6.         [ID]  
  7.         string CustomerID { get; set; }  
  8.         [Column]  
  9.         string CompanyName { get; set; }  
  10.         [Column]  
  11.        string ContactName { get; set; }  
  12.         [Column]  
  13.         string ContactTitle { get; set; }  
  14.         [Column]  
  15.         string Address { get; set; }  
  16.         [Column]  
  17.         string City { get; set; }  
  18.        [Column]  
  19.         string Region { get; set; }  
  20.         [Column]  
  21.        string PostalCode { get; set; }  
  22.         [Column]  
  23.         string Country { get; set; }  
  24.         [Column]  
  25.         string Phone { get; set; }  
  26.        [Column]  
  27.         string Fax { get; set; }  
  28.     }  
  29.     [Table("Customers",DISTINCT=true)]  
  30.     interface ICountry  
  31.     {  
  32.         [Column("Country")]  
  33.         string Name { get; set; }  
  34. }  
  35. <!--[if !supportLists]-->u     <!--[endif]-->定义逻辑方法  
  36.    [Service]  
  37.     public class CustomerService  
  38.     {  
  39.         public IList<Customer> List(string matchCompanyName,string country, [Output]DataPage datapage)  
  40.         {  
  41.             Expression exp = new Expression();  
  42.             if (!string.IsNullOrEmpty(matchCompanyName))  
  43.                 exp &= Customer.contactName.Match(matchCompanyName);  
  44.             if (!string.IsNullOrEmpty(country))  
  45.                 exp &= Customer.country == country;  
  46.             datapage.RecordCount = exp.Count<Customer>();  
  47.             return exp.List<Customer>(new Region(datapage.PageIndex,datapage.PageSize));  
  48.         }  
  49.         public IList<Country> ListCountry()  
  50.         {  
  51.             Expression exp = new Expression();  
  52.             return exp.List<Country>();  
  53.         }  
  54. }  
  55. <!--[if !supportLists]-->l        <!--[endif]-->Flex功能处理  
  56. <!--[if !supportLists]-->u     <!--[endif]-->定义AS逻辑代理方法  
  57.     import Core.Utility;  
  58.     /**  
  59.     * Action Script调用方法生成工具1.0  生成时间:2009-7-27 21:39:39  
  60.     */  
  61.    public dynamic class CustomerService_List  
  62.     {  
  63.        public var Callback:Function;  
  64.        public var matchCompanyName:Object;  
  65.        public var country:Object;  
  66.       public var PageIndex:Object;  
  67.        public var PageSize:Object;  
  68.       public var RecordCount:Object;  
  69.        public var PageCount:Object;  
  70.        public var OrderField:Object;  
  71.        public function Execute(method:String="get"):void  
  72.        {  
  73.            this._TimeSlice = new Date();  
  74.            Utility.CallMethod("CustomerService_List",this,Callback,method);  
  75.        }  
  76.     }  
  77.     import Core.Utility;  
  78.     /**  
  79.     * Action Script调用方法生成工具1.0  生成时间:2009-7-27 21:39:43  
  80.     */  
  81.     public dynamic class CustomerService_ListCountry  
  82.     {  
  83.        public var Callback:Function;  
  84.        public function Execute(method:String="get"):void  
  85.        {  
  86.           this._TimeSlice = new Date();  
  87.            Utility.CallMethod("CustomerService_ListCountry",this,Callback,method);  
  88.        }  
  89.     }  
  90. <!--[if !supportLists]-->u     <!--[endif]-->在界面定义逻辑操作对象  
  91.    <mx:Script> 
  92.         
  93.            [Bindable]  
  94.            private var Customers:Object = new ArrayCollection();  
  95.            [Bindable]  
  96.            private var Countrys:Object = new ArrayCollection();  
  97.            private var getCustomer = new CustomerService_List();  
  98.            private var getCountry = new CustomerService_ListCountry();  
  99.        ]]> 
  100.     mx:Script> 
  101. <!--[if !supportLists]-->u     <!--[endif]-->设置国家Combox数据源绑定  
  102. <mx:ComboBox id="txtCountry"  dataProvider="{Countrys}"    
  103. labelField="Name" editable="true" width="135"   
  104. color="#000000">mx:ComboBox> 
  105. <!--[if !supportLists]-->u     <!--[endif]-->设置客户查询数据源绑定  
  106.     <mx:DataGrid dataProvider="{Customers}" width="100%" height="100%"> 
  107.        <mx:columns> 
  108.            <mx:DataGridColumn headerText="CustomerID" dataField="CustomerID"/> 
  109.            <mx:DataGridColumn headerText="CompanyName" dataField="CompanyName"/> 
  110.            <mx:DataGridColumn headerText="ContactName" dataField="ContactName"/> 
  111.            <mx:DataGridColumn headerText="ContactTitle" dataField="ContactTitle"/> 
  112.            <mx:DataGridColumn headerText="Address" dataField="Address"/> 
  113.            <mx:DataGridColumn headerText="City" dataField="City"/> 
  114.            <mx:DataGridColumn headerText="Region" dataField="Region"/> 
  115.            <mx:DataGridColumn headerText="PostalCode" dataField="PostalCode"/> 
  116.            <mx:DataGridColumn headerText="Country" dataField="Country"/> 
  117.            <mx:DataGridColumn headerText="Phone" dataField="Phone"/> 
  118.            <mx:DataGridColumn headerText="Fax" dataField="Fax"/> 
  119.        mx:columns> 
  120.     mx:DataGrid> 
  121. <!--[if !supportLists]-->u     <!--[endif]-->在界面初始化事件中定义相关方法加调处理  
  122.     <mx:initialize> 
  123.         
  124.            getCountry.Callback= function(result:XML,err:Boolean){  
  125.                 Countrys= result.Data.Country;  
  126.            };  
  127.                  getCustomer.Callback = function(result:XML,err:Boolean){  
  128.               Customers = result.Data.Customer;  
  129.               if(getCustomer.FristSearch)  
  130.              {  
  131.                   dp.Open(getCustomer.PageSize ,result.Properties.datapage.RecordCount)  
  132.               }  
  133.            };  
  134.            getCustomer.PageSize=10;  
  135.            getCustomer.FristSearch = true;  
  136.            getCountry.Execute();  
  137.           getCustomer.Execute();  
  138.        ]]> 
  139.     mx:initialize> 
  140. <!--[if !supportLists]-->u     <!--[endif]-->查询按钮相关功能处理  
  141.        <mx:Button label="Search" icon="@Embed(source='Search.png')"> 
  142.            <mx:click> 
  143.               
  144.                  getCustomer.FristSearch = true;  
  145.                   getCustomer.matchCompanyName = txtCompanyName.text;  
  146.                   getCustomer.country = txtCountry.text;  
  147.                   getCustomer.PageIndex =0;  
  148.                   getCustomer.Execute();  
  149.               ]]> 
  150.            mx:click> 
  151.     mx:Button> 

其实Flex做应用开发效率还是挺高的,特别当你熟了MXML后基于不用在UI设计器和MXML间切换所带来的麻烦。由于Flex直接支持CSS文件来描述,所以在开发过程基本不用管样式,到***把设计人员搞好的CSS直接引用到Application里即可。顺便推荐一个Flex的样式主题站http://www.scalenine.com/gallery/ 提供一些免费的主题。Flex数据分页查询最终实现。

【编辑推荐】

  1. Flex教程 Flex程序开发初步
  2. Flex垃圾回收和性能优化的一些总结
  3. Flex和Jsp之间中文参数的传递
  4. Flex编程中需要注意的Namespace用法
  5. Flex SDK 4:Gumbo的主题 极其快速的RIA开发
责任编辑:彭凡 来源: cnblogs
相关推荐

2011-08-15 10:22:19

分页查询数据库

2009-04-09 13:14:09

Oracle分页查询CBO

2010-08-05 09:39:17

Flex页面跳转

2010-08-11 16:10:27

Flex DataGr

2010-07-30 09:16:24

Flex数据绑定

2010-08-12 13:34:13

Flex验证组件

2009-08-04 14:23:36

ASP.NET查询分页

2011-03-21 13:44:38

SQL ServerSQL Server2分页

2010-08-12 10:43:19

Flex数据绑定

2010-07-29 15:09:19

Flex全屏

2009-09-21 13:42:47

Hibernate查询

2010-11-10 15:29:40

SQL SERVER

2010-08-05 15:06:19

Flex数据绑定

2019-11-15 10:01:07

MySQL数据库数据

2010-11-09 13:09:58

SQL Server分

2018-09-06 16:46:33

数据库MySQL分页查询

2009-09-18 12:29:55

2010-07-28 09:29:36

Flex DataGr

2009-08-07 09:57:20

Ajax分页功能

2009-12-23 09:04:41

LINQ通用分页
点赞
收藏

51CTO技术栈公众号