Flex分页显示实例

Flex mxml代码   收藏代码
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"  creationComplete="application1_creationCompleteHandler(event)"  
  3.                xmlns:s="library://ns.adobe.com/flex/spark"   
  4.                xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">  
  5.     <s:layout>  
  6.         <s:VerticalLayout verticalAlign="middle" horizontalAlign="center"/>  
  7.     </s:layout>  
  8.   
  9.     <fx:Script>  
  10.         <![CDATA[  
  11.             import comp.add;  
  12.             import comp.infoWindow;  
  13.               
  14.             import mx.collections.ArrayCollection;  
  15.             import mx.controls.Alert;  
  16.             import mx.events.CloseEvent;  
  17.             import mx.events.FlexEvent;  
  18.             import mx.managers.PopUpManager;  
  19.             import mx.rpc.events.ResultEvent;  
  20.             [Bindable]  
  21.             private var all:int=0;  
  22.             [Bindable]  
  23.             private var step:int=10;  
  24.             [Bindable]  
  25.             private var count:int=0;  
  26.             private var k:int=10;  
  27.             [Bindable]  
  28.             private var dp:ArrayCollection=new ArrayCollection();;  
  29.             protected function remoteobject1_resultHandler2(event:ResultEvent):void  
  30.             {  
  31.                 if(int(event.result)==1){  
  32.                     remote1.getInfo(0,10);  
  33.                 }  
  34.             }  
  35.             protected function remoteobject1_resultHandler3(event:ResultEvent):void  
  36.             {  
  37.                 if(int(event.result)==1){  
  38.                     remote1.getInfo(0,10);  
  39.                 }  
  40.             }  
  41.             protected function remoteobject1_resultHandler(event:ResultEvent):void  
  42.             {  
  43.                 var arr:ArrayCollection=event.result as ArrayCollection;  
  44.                 dp.removeAll();  
  45.                 all=int(arr[arr.length-1]);  
  46.                 if(arr.length<=11){  
  47.                     k=arr.length-1;  
  48.                 }  
  49.                 for(var i:int=0;i<k;i++){  
  50.                     var o:Object=new Object();  
  51.                     o.num=arr[i][0];  
  52.                     o.pic=arr[i][1];  
  53.                     o.name=arr[i][2];  
  54.                     o.sex=arr[i][3];  
  55.                     o.age=arr[i][4];  
  56.                     o.department=arr[i][5];  
  57.                     o.job=arr[i][6];  
  58.                     o.birthday=arr[i][7];  
  59.                     o.comeday=arr[i][8];  
  60.                     o.education=arr[i][9];  
  61.                     o.workage=arr[i][10];  
  62.                     o.id=arr[i][11];  
  63.                     o.tel=arr[i][12];  
  64.                     o.home=arr[i][13];  
  65.                     o.edu=arr[i][14];  
  66.                     o.hobby=arr[i][15];  
  67.                     o.etc=arr[i][16];  
  68.                     dp.addItem(o);  
  69.                 }  
  70.             }  
  71.             protected function remoteobject1_faultHandler(event:FaultEvent):void  
  72.             {  
  73.                 // TODO Auto-generated method stub  
  74.             }  
  75.             protected function remoteobject1_faultHandler2(event:FaultEvent):void  
  76.             {  
  77.                 // TODO Auto-generated method stub  
  78.             }  
  79.             protected function remoteobject1_faultHandler3(event:FaultEvent):void  
  80.             {  
  81.                 // TODO Auto-generated method stub  
  82.             }  
  83.             import mx.rpc.events.FaultEvent;  
  84.   
  85.             protected function application1_creationCompleteHandler(event:FlexEvent):void  
  86.             {  
  87.                 remote1.getInfo(0,10);  
  88.             }  
  89.   
  90.   
  91.             protected function button1_clickHandler(event:MouseEvent):void  
  92.             {  
  93.                 var a:add=new add();  
  94.                 PopUpManager.addPopUp(a,this);  
  95.                 PopUpManager.centerPopUp(a);  
  96.             }  
  97.             private function qetInfomation (s:int,e:int):void{  
  98.                 remote1.getInfo(s,e);  
  99.             }  
  100.   
  101.             protected function button2_clickHandler(event:MouseEvent):void  
  102.             {  
  103.                 qetInfomation((count-1)*step,step);  
  104.                 count=count-1;  
  105.             }  
  106.   
  107.   
  108.             protected function button3_clickHandler(event:MouseEvent):void  
  109.             {  
  110.                 qetInfomation((count+1)*step,step);  
  111.                 count=count+1;  
  112.             }  
  113.   
  114.   
  115.             protected function button4_clickHandler(event:MouseEvent):void  
  116.             {  
  117.                 if(dg.selectedItem==null){  
  118.                     return ;  
  119.                 }else{  
  120.                     Alert.show("确定删除该记录吗?","提示",1|2,this,CHandler);  
  121.                 }  
  122.             }  
  123.             private function CHandler(e:CloseEvent):void{  
  124.                 if(e.detail==Alert.YES){  
  125.                     var o:Object=dg.selectedItem;  
  126.                     remote2.deleteItem(int(o.num));  
  127.                 }else{  
  128.                     return ;  
  129.                 }  
  130.             }  
  131.             public function saveItem(names:String,age:int,sex:String,tel:String,dept:String,job:String,birthday:String,comeday:String,workage:int,ids:String,home:String,edu:String,hobby:String,etc:String):void{  
  132.                 remote3.saveItem(names,age,sex,tel,dept,job,birthday,comeday,workage,ids,home,edu,hobby,etc);  
  133.             }  
  134.             public function open(o:Object):void{  
  135.                 var w:infoWindow=new infoWindow();  
  136.                 PopUpManager.addPopUp(w,this);  
  137.                 PopUpManager.centerPopUp(w);  
  138.                 w.data=o;  
  139.             }  
  140.               
  141.             private function toFirstPage(event:MouseEvent):void{  
  142.                 qetInfomation(0,step);  
  143.                 count=0;  
  144.             }  
  145.               
  146.             private function toLastePage(event:MouseEvent):void{  
  147.                 count=(all+(10-all%step))/step-1;  
  148.                 qetInfomation(count*step,count*step+all%step);  
  149.               
  150.             }  
  151.   
  152.         ]]>  
  153.     </fx:Script>  
  154.     <fx:Declarations>  
  155.         <s:RemoteObject destination="main" fault="remoteobject1_faultHandler(event)"  
  156.          result="remoteobject1_resultHandler(event)" id="remote1"/>  
  157.         <s:RemoteObject destination="main" fault="remoteobject1_faultHandler2(event)"  
  158.                         result="remoteobject1_resultHandler2(event)" id="remote2"/>  
  159.         <s:RemoteObject destination="main" fault="remoteobject1_faultHandler3(event)"  
  160.                         result="remoteobject1_resultHandler3(event)" id="remote3"/>  
  161.     </fx:Declarations>  
  162.     <mx:DataGrid width="100%" height="280" id="dg" dataProvider="{dp}">  
  163.         <mx:columns>  
  164.             <mx:DataGridColumn headerText="编号" dataField="num"/>  
  165.             <mx:DataGridColumn headerText="姓名" dataField="name">  
  166.                 <mx:itemRenderer>  
  167.                     <fx:Component>  
  168.                         <mx:LinkButton label="{data.name}" click="this.outerDocument.open(data);" >  
  169.                         </mx:LinkButton>  
  170.                     </fx:Component>  
  171.                 </mx:itemRenderer>  
  172.             </mx:DataGridColumn>  
  173.             <mx:DataGridColumn headerText="性别" dataField="sex"/>  
  174.             <mx:DataGridColumn headerText="年龄" dataField="age"/>  
  175.             <mx:DataGridColumn headerText="所在部门" dataField="department"/>  
  176.             <mx:DataGridColumn headerText="职务" dataField="job"/>  
  177.         </mx:columns>  
  178.     </mx:DataGrid>  
  179.     <mx:HBox verticalAlign="middle" horizontalAlign="center" height="30" width="100%">  
  180.         <s:Label text="共有:"/>  
  181.         <s:Label text="{all}"/>  
  182.         <s:Label text="条记录"/>  
  183.         <s:Label text="当前第:"/>  
  184.         <s:Label text="{count+1}"/>  
  185.         <s:Label text="页"/>  
  186.         <s:Button label="增加" click="button1_clickHandler(event)"/>  
  187.         <s:Button label="第一页" enabled="{count>0?true:false}" click="toFirstPage(event)"/>  
  188.         <s:Button label="上一页" enabled="{count>0?true:false}" click="button2_clickHandler(event)"/>  
  189.         <s:Button label="下一页" enabled="{(count+1)*step>all?false:true}" click="button3_clickHandler(event)"/>  
  190.         <s:Button label="最后页" enabled="{(count+1)*step>all?false:true}" click="toLastePage(event)"/>  
  191.         <s:Button label="删除" click="button4_clickHandler(event)"/>  
  192.           
  193.     </mx:HBox>  
  194. </s:Application>  

 import Java.sql.*;

Java代码   收藏代码
  1. import java.util.ArrayList;  
  2. import java.util.List;  
  3.   
  4. import javax.swing.text.html.HTMLDocument.HTMLReader.PreAction;  
  5. public class HR {  
  6.     Connection c=null;  
  7.     Statement s=null;  
  8.     String url="jdbc:mysql://localhost:3306/company?user=root&password=rootcode";  
  9.     public List getInfo(int start,int end){  
  10.         List r=new ArrayList<Array>();  
  11.         String temp [];  
  12.         try{  
  13.             Class.forName("com.mysql.jdbc.Driver");  
  14.         }catch (ClassNotFoundException e) {  
  15.             e.printStackTrace();  
  16.         }  
  17.         try{  
  18.             c=DriverManager.getConnection(url);  
  19.             s=c.createStatement();  
  20.             String sql="select * from user where visible=1 order by num limit "+start+","+end+";";  
  21.             System.out.print(sql);  
  22.             ResultSet rs=s.executeQuery(sql);  
  23.             while(rs.next()){  
  24.                 temp=new String[17];  
  25.                 temp[0]=rs.getString("num");  
  26.                 temp[1]=rs.getString("pic");  
  27.                 temp[2]=rs.getString("name");  
  28.                 temp[3]=rs.getString("sex");  
  29.                 temp[4]=rs.getString("age");  
  30.                 temp[5]=rs.getString("department");  
  31.                 temp[6]=rs.getString("job");  
  32.                 temp[7]=rs.getString("birthday");  
  33.                 temp[8]=rs.getString("comeday");  
  34.                 temp[9]=rs.getString("education");  
  35.                 temp[10]=rs.getString("workage");  
  36.                 temp[11]=rs.getString("id");  
  37.                 temp[12]=rs.getString("tel");  
  38.                 temp[13]=rs.getString("home");  
  39.                 temp[14]=rs.getString("edu");  
  40.                 temp[15]=rs.getString("hobby");  
  41.                 temp[16]=rs.getString("etc");  
  42.                 r.add(temp);  
  43.             }  
  44.             Statement ss=c.createStatement();  
  45. //          c.prepareStatement(sql)  
  46.             String sql2="select count(*) as 'all' from user where visible=1;";  
  47.             ResultSet rs2=ss.executeQuery(sql2);  
  48.             while(rs2.next()){  
  49.                 r.add(rs2.getInt("all"));  
  50.             }  
  51.               
  52.         }catch (SQLException e) {  
  53.             e.printStackTrace();  
  54.             // TODO: handle exception  
  55.         }  
  56.         return r;  
  57.     }  
  58.     public int deleteItem(int i){  
  59.         int result=0;  
  60.         try{  
  61.             Class.forName("com.mysql.jdbc.Driver");  
  62.         }catch (ClassNotFoundException e) {  
  63.             e.printStackTrace();  
  64.         }  
  65.         try{  
  66.             c=DriverManager.getConnection(url);  
  67.             s=c.createStatement();  
  68.             String sql="update user set visible=0 where num = "+i+";";  
  69.             System.out.print(sql);  
  70.             s.execute(sql);  
  71.             result=1;  
  72.               
  73.         }catch (SQLException e) {  
  74.             e.printStackTrace();  
  75.             // TODO: handle exception  
  76.         }  
  77.         return result;  
  78.     }  
  79.     public int saveItem(String names,int age,String sex,String tel,String dept,String job,String birthday,String comeday,int workage,String ids,String home,String edu,String hobby,String etc){  
  80.         int result=0;  
  81.         try{  
  82.             Class.forName("com.mysql.jdbc.Driver");  
  83.         }catch (ClassNotFoundException e) {  
  84.             e.printStackTrace();  
  85.         }  
  86.         try{  
  87.             c=DriverManager.getConnection(url);  
  88.             String pic=getMax()+".jpg";  
  89.             System.out.print(pic);  
  90.             String sql="insert into user values (null,?,?,?,?,?,?,?,?,null,?,?,?,?,?,?,?,1);";  
  91.             PreparedStatement pr=c.prepareStatement(sql);  
  92.             System.out.println(sql);  
  93.             pr.setString(1,pic);  
  94.             pr.setString(2,names);  
  95.             pr.setString(3, sex);  
  96.             pr.setInt(4, age);  
  97.             pr.setString(5, dept);  
  98.             pr.setString(6, job);  
  99.             pr.setString(7, birthday);  
  100.             pr.setString(8, comeday);  
  101.             pr.setInt(9, workage);  
  102.             pr.setString(10, ids);  
  103.             pr.setString(11, tel);  
  104.             pr.setString(12, home);  
  105.             pr.setString(13, edu);  
  106.             pr.setString(14, hobby);  
  107.             pr.setString(15, etc);  
  108.             System.out.println(sql);  
  109.             pr.execute();  
  110.             result=1;  
  111.               
  112.         }catch (SQLException e) {  
  113.             e.printStackTrace();  
  114.             // TODO: handle exception  
  115.         }  
  116.         return result;        
  117.     }  
  118.     public static int getMax(){  
  119.         int result=0;  
  120.         try{  
  121.             Class.forName("com.mysql.jdbc.Driver");  
  122.         }catch (ClassNotFoundException e) {  
  123.             e.printStackTrace();  
  124.         }  
  125.         try{  
  126.             String url1="jdbc:mysql://localhost:3306/company?user=root&password=rootcode";  
  127.             Connection cc=DriverManager.getConnection(url1);  
  128.             Statement ss=cc.createStatement();  
  129.             String sql="select MAX(num) as 'max' from user;";  
  130.             System.out.print(sql);  
  131.             ResultSet rs=ss.executeQuery(sql);  
  132.             while(rs.next()){  
  133.                 result=rs.getInt("max");  
  134.                 result=result+1;  
  135.             }     
  136.         }catch (SQLException e) {  
  137.             e.printStackTrace();  
  138.             // TODO: handle exception  
  139.         }  
  140.         return result;  
  141.     }  
  142.   
  143. }  

 <?xml version="1.0" encoding="UTF-8"?>

Xml代码   收藏代码
  1. <service id="remoting-service"   
  2.     class="flex.messaging.services.RemotingService">  
  3.   
  4.     <adapters>  
  5.         <adapter-definition id="java-object" class="flex.messaging.services.remoting.adapters.JavaAdapter" default="true"/>  
  6.     </adapters>  
  7.   
  8.     <default-channels>  
  9.         <channel ref="my-amf"/>  
  10.     </default-channels>  
  11.     <destination id="main">  
  12.     <properties>  
  13.     <source>HR</source>  
  14.     </properties>  
  15.     </destination>  
  16. </service>  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值