實現(xiàn)Flex數(shù)據(jù)分頁查詢的幾種處理方法
首先看下Flex數(shù)據(jù)分頁查詢需要的應(yīng)用效果<!--[if !vml]-->
<!--[endif]-->
實際功能包括對Customer進(jìn)行條件和Flex數(shù)據(jù)分頁查詢,客戶相關(guān)國家數(shù)據(jù)查詢。
- <!--[if !supportLists]-->l <!--[endif]-->服務(wù)端功能處理
- <!--[if !supportLists]-->u <!--[endif]-->根據(jù)邏輯定義相關(guān)數(shù)據(jù)操作實體類
- [Table("Customers")]
- interface ICustomer
- {
- [ID]
- string CustomerID { get; set; }
- [Column]
- string CompanyName { get; set; }
- [Column]
- string ContactName { get; set; }
- [Column]
- string ContactTitle { get; set; }
- [Column]
- string Address { get; set; }
- [Column]
- string City { get; set; }
- [Column]
- string Region { get; set; }
- [Column]
- string PostalCode { get; set; }
- [Column]
- string Country { get; set; }
- [Column]
- string Phone { get; set; }
- [Column]
- string Fax { get; set; }
- }
- [Table("Customers",DISTINCT=true)]
- interface ICountry
- {
- [Column("Country")]
- string Name { get; set; }
- }
- <!--[if !supportLists]-->u <!--[endif]-->定義邏輯方法
- [Service]
- public class CustomerService
- {
- public IList<Customer> List(string matchCompanyName,string country, [Output]DataPage datapage)
- {
- Expression exp = new Expression();
- if (!string.IsNullOrEmpty(matchCompanyName))
- exp &= Customer.contactName.Match(matchCompanyName);
- if (!string.IsNullOrEmpty(country))
- exp &= Customer.country == country;
- datapage.RecordCount = exp.Count<Customer>();
- return exp.List<Customer>(new Region(datapage.PageIndex,datapage.PageSize));
- }
- public IList<Country> ListCountry()
- {
- Expression exp = new Expression();
- return exp.List<Country>();
- }
- }
- <!--[if !supportLists]-->l <!--[endif]-->Flex功能處理
- <!--[if !supportLists]-->u <!--[endif]-->定義AS邏輯代理方法
- import Core.Utility;
- /**
- * Action Script調(diào)用方法生成工具1.0 生成時間:2009-7-27 21:39:39
- */
- public dynamic class CustomerService_List
- {
- public var Callback:Function;
- public var matchCompanyName:Object;
- public var country:Object;
- public var PageIndex:Object;
- public var PageSize:Object;
- public var RecordCount:Object;
- public var PageCount:Object;
- public var OrderField:Object;
- public function Execute(method:String="get"):void
- {
- this._TimeSlice = new Date();
- Utility.CallMethod("CustomerService_List",this,Callback,method);
- }
- }
- import Core.Utility;
- /**
- * Action Script調(diào)用方法生成工具1.0 生成時間:2009-7-27 21:39:43
- */
- public dynamic class CustomerService_ListCountry
- {
- public var Callback:Function;
- public function Execute(method:String="get"):void
- {
- this._TimeSlice = new Date();
- Utility.CallMethod("CustomerService_ListCountry",this,Callback,method);
- }
- }
- <!--[if !supportLists]-->u <!--[endif]-->在界面定義邏輯操作對象
- <mx:Script>
- [Bindable]
- private var Customers:Object = new ArrayCollection();
- [Bindable]
- private var Countrys:Object = new ArrayCollection();
- private var getCustomer = new CustomerService_List();
- private var getCountry = new CustomerService_ListCountry();
- ]]>
- < SPAN>mx:Script>
- <!--[if !supportLists]-->u <!--[endif]-->設(shè)置國家Combox數(shù)據(jù)源綁定
- <mx:ComboBox id="txtCountry" dataProvider="{Countrys}"
- labelField="Name" editable="true" width="135"
- color="#000000">< SPAN>mx:ComboBox>
- <!--[if !supportLists]-->u <!--[endif]-->設(shè)置客戶查詢數(shù)據(jù)源綁定
- <mx:DataGrid dataProvider="{Customers}" width="100%" height="100%">
- <mx:columns>
- <mx:DataGridColumn headerText="CustomerID" dataField="CustomerID"/>
- <mx:DataGridColumn headerText="CompanyName" dataField="CompanyName"/>
- <mx:DataGridColumn headerText="ContactName" dataField="ContactName"/>
- <mx:DataGridColumn headerText="ContactTitle" dataField="ContactTitle"/>
- <mx:DataGridColumn headerText="Address" dataField="Address"/>
- <mx:DataGridColumn headerText="City" dataField="City"/>
- <mx:DataGridColumn headerText="Region" dataField="Region"/>
- <mx:DataGridColumn headerText="PostalCode" dataField="PostalCode"/>
- <mx:DataGridColumn headerText="Country" dataField="Country"/>
- <mx:DataGridColumn headerText="Phone" dataField="Phone"/>
- <mx:DataGridColumn headerText="Fax" dataField="Fax"/>
- < SPAN>mx:columns>
- < SPAN>mx:DataGrid>
- <!--[if !supportLists]-->u <!--[endif]-->在界面初始化事件中定義相關(guān)方法加調(diào)處理
- <mx:initialize>
- getCountry.Callback= function(result:XML,err:Boolean){
- Countrys= result.Data.Country;
- };
- getCustomer.Callback = function(result:XML,err:Boolean){
- Customers = result.Data.Customer;
- if(getCustomer.FristSearch)
- {
- dp.Open(getCustomer.PageSize ,result.Properties.datapage.RecordCount)
- }
- };
- getCustomer.PageSize=10;
- getCustomer.FristSearch = true;
- getCountry.Execute();
- getCustomer.Execute();
- ]]>
- < SPAN>mx:initialize>
- <!--[if !supportLists]-->u <!--[endif]-->查詢按鈕相關(guān)功能處理
- <mx:Button label="Search" icon="@Embed(source='Search.png')">
- <mx:click>
- getCustomer.FristSearch = true;
- getCustomer.matchCompanyName = txtCompanyName.text;
- getCustomer.country = txtCountry.text;
- getCustomer.PageIndex =0;
- getCustomer.Execute();
- ]]>
- < SPAN>mx:click>
- < SPAN>mx:Button>
其實Flex做應(yīng)用開發(fā)效率還是挺高的,特別當(dāng)你熟了MXML后基于不用在UI設(shè)計器和MXML間切換所帶來的麻煩。由于Flex直接支持CSS文件來描述,所以在開發(fā)過程基本不用管樣式,到***把設(shè)計人員搞好的CSS直接引用到Application里即可。順便推薦一個Flex的樣式主題站http://www.scalenine.com/gallery/ 提供一些免費(fèi)的主題。Flex數(shù)據(jù)分頁查詢最終實現(xiàn)。
【編輯推薦】