- <?xml version="1.0" encoding="utf-8"?>
- <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" creationComplete="application1_creationCompleteHandler(event)"
- xmlns:s="library://ns.adobe.com/flex/spark"
- xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">
- <s:layout>
- <s:VerticalLayout verticalAlign="middle" horizontalAlign="center"/>
- </s:layout>
- <fx:Script>
- <![CDATA[
- import comp.add;
- import comp.infoWindow;
- import mx.collections.ArrayCollection;
- import mx.controls.Alert;
- import mx.events.CloseEvent;
- import mx.events.FlexEvent;
- import mx.managers.PopUpManager;
- import mx.rpc.events.ResultEvent;
- [Bindable]
- private var all:int=0;
- [Bindable]
- private var step:int=10;
- [Bindable]
- private var count:int=0;
- private var k:int=10;
- [Bindable]
- private var dp:ArrayCollection=new ArrayCollection();;
- protected function remoteobject1_resultHandler2(event:ResultEvent):void
- {
- if(int(event.result)==1){
- remote1.getInfo(0,10);
- }
- }
- protected function remoteobject1_resultHandler3(event:ResultEvent):void
- {
- if(int(event.result)==1){
- remote1.getInfo(0,10);
- }
- }
- protected function remoteobject1_resultHandler(event:ResultEvent):void
- {
- var arr:ArrayCollection=event.result as ArrayCollection;
- dp.removeAll();
- all=int(arr[arr.length-1]);
- if(arr.length<=11){
- k=arr.length-1;
- }
- for(var i:int=0;i<k;i++){
- var o:Object=new Object();
- o.num=arr[i][0];
- o.pic=arr[i][1];
- o.name=arr[i][2];
- o.sex=arr[i][3];
- o.age=arr[i][4];
- o.department=arr[i][5];
- o.job=arr[i][6];
- o.birthday=arr[i][7];
- o.comeday=arr[i][8];
- o.education=arr[i][9];
- o.workage=arr[i][10];
- o.id=arr[i][11];
- o.tel=arr[i][12];
- o.home=arr[i][13];
- o.edu=arr[i][14];
- o.hobby=arr[i][15];
- o.etc=arr[i][16];
- dp.addItem(o);
- }
- }
- protected function remoteobject1_faultHandler(event:FaultEvent):void
- {
- // TODO Auto-generated method stub
- }
- protected function remoteobject1_faultHandler2(event:FaultEvent):void
- {
- // TODO Auto-generated method stub
- }
- protected function remoteobject1_faultHandler3(event:FaultEvent):void
- {
- // TODO Auto-generated method stub
- }
- import mx.rpc.events.FaultEvent;
- protected function application1_creationCompleteHandler(event:FlexEvent):void
- {
- remote1.getInfo(0,10);
- }
- protected function button1_clickHandler(event:MouseEvent):void
- {
- var a:add=new add();
- PopUpManager.addPopUp(a,this);
- PopUpManager.centerPopUp(a);
- }
- private function qetInfomation (s:int,e:int):void{
- remote1.getInfo(s,e);
- }
- protected function button2_clickHandler(event:MouseEvent):void
- {
- qetInfomation((count-1)*step,step);
- count=count-1;
- }
- protected function button3_clickHandler(event:MouseEvent):void
- {
- qetInfomation((count+1)*step,step);
- count=count+1;
- }
- protected function button4_clickHandler(event:MouseEvent):void
- {
- if(dg.selectedItem==null){
- return ;
- }else{
- Alert.show("确定删除该记录吗?","提示",1|2,this,CHandler);
- }
- }
- private function CHandler(e:CloseEvent):void{
- if(e.detail==Alert.YES){
- var o:Object=dg.selectedItem;
- remote2.deleteItem(int(o.num));
- }else{
- return ;
- }
- }
- 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{
- remote3.saveItem(names,age,sex,tel,dept,job,birthday,comeday,workage,ids,home,edu,hobby,etc);
- }
- public function open(o:Object):void{
- var w:infoWindow=new infoWindow();
- PopUpManager.addPopUp(w,this);
- PopUpManager.centerPopUp(w);
- w.data=o;
- }
- private function toFirstPage(event:MouseEvent):void{
- qetInfomation(0,step);
- count=0;
- }
- private function toLastePage(event:MouseEvent):void{
- count=(all+(10-all%step))/step-1;
- qetInfomation(count*step,count*step+all%step);
- }
- ]]>
- </fx:Script>
- <fx:Declarations>
- <s:RemoteObject destination="main" fault="remoteobject1_faultHandler(event)"
- result="remoteobject1_resultHandler(event)" id="remote1"/>
- <s:RemoteObject destination="main" fault="remoteobject1_faultHandler2(event)"
- result="remoteobject1_resultHandler2(event)" id="remote2"/>
- <s:RemoteObject destination="main" fault="remoteobject1_faultHandler3(event)"
- result="remoteobject1_resultHandler3(event)" id="remote3"/>
- </fx:Declarations>
- <mx:DataGrid width="100%" height="280" id="dg" dataProvider="{dp}">
- <mx:columns>
- <mx:DataGridColumn headerText="编号" dataField="num"/>
- <mx:DataGridColumn headerText="姓名" dataField="name">
- <mx:itemRenderer>
- <fx:Component>
- <mx:LinkButton label="{data.name}" click="this.outerDocument.open(data);" >
- </mx:LinkButton>
- </fx:Component>
- </mx:itemRenderer>
- </mx:DataGridColumn>
- <mx:DataGridColumn headerText="性别" dataField="sex"/>
- <mx:DataGridColumn headerText="年龄" dataField="age"/>
- <mx:DataGridColumn headerText="所在部门" dataField="department"/>
- <mx:DataGridColumn headerText="职务" dataField="job"/>
- </mx:columns>
- </mx:DataGrid>
- <mx:HBox verticalAlign="middle" horizontalAlign="center" height="30" width="100%">
- <s:Label text="共有:"/>
- <s:Label text="{all}"/>
- <s:Label text="条记录"/>
- <s:Label text="当前第:"/>
- <s:Label text="{count+1}"/>
- <s:Label text="页"/>
- <s:Button label="增加" click="button1_clickHandler(event)"/>
- <s:Button label="第一页" enabled="{count>0?true:false}" click="toFirstPage(event)"/>
- <s:Button label="上一页" enabled="{count>0?true:false}" click="button2_clickHandler(event)"/>
- <s:Button label="下一页" enabled="{(count+1)*step>all?false:true}" click="button3_clickHandler(event)"/>
- <s:Button label="最后页" enabled="{(count+1)*step>all?false:true}" click="toLastePage(event)"/>
- <s:Button label="删除" click="button4_clickHandler(event)"/>
- </mx:HBox>
- </s:Application>
import Java.sql.*;
- import java.util.ArrayList;
- import java.util.List;
- import javax.swing.text.html.HTMLDocument.HTMLReader.PreAction;
- public class HR {
- Connection c=null;
- Statement s=null;
- String url="jdbc:mysql://localhost:3306/company?user=root&password=rootcode";
- public List getInfo(int start,int end){
- List r=new ArrayList<Array>();
- String temp [];
- try{
- Class.forName("com.mysql.jdbc.Driver");
- }catch (ClassNotFoundException e) {
- e.printStackTrace();
- }
- try{
- c=DriverManager.getConnection(url);
- s=c.createStatement();
- String sql="select * from user where visible=1 order by num limit "+start+","+end+";";
- System.out.print(sql);
- ResultSet rs=s.executeQuery(sql);
- while(rs.next()){
- temp=new String[17];
- temp[0]=rs.getString("num");
- temp[1]=rs.getString("pic");
- temp[2]=rs.getString("name");
- temp[3]=rs.getString("sex");
- temp[4]=rs.getString("age");
- temp[5]=rs.getString("department");
- temp[6]=rs.getString("job");
- temp[7]=rs.getString("birthday");
- temp[8]=rs.getString("comeday");
- temp[9]=rs.getString("education");
- temp[10]=rs.getString("workage");
- temp[11]=rs.getString("id");
- temp[12]=rs.getString("tel");
- temp[13]=rs.getString("home");
- temp[14]=rs.getString("edu");
- temp[15]=rs.getString("hobby");
- temp[16]=rs.getString("etc");
- r.add(temp);
- }
- Statement ss=c.createStatement();
- // c.prepareStatement(sql)
- String sql2="select count(*) as 'all' from user where visible=1;";
- ResultSet rs2=ss.executeQuery(sql2);
- while(rs2.next()){
- r.add(rs2.getInt("all"));
- }
- }catch (SQLException e) {
- e.printStackTrace();
- // TODO: handle exception
- }
- return r;
- }
- public int deleteItem(int i){
- int result=0;
- try{
- Class.forName("com.mysql.jdbc.Driver");
- }catch (ClassNotFoundException e) {
- e.printStackTrace();
- }
- try{
- c=DriverManager.getConnection(url);
- s=c.createStatement();
- String sql="update user set visible=0 where num = "+i+";";
- System.out.print(sql);
- s.execute(sql);
- result=1;
- }catch (SQLException e) {
- e.printStackTrace();
- // TODO: handle exception
- }
- return result;
- }
- 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){
- int result=0;
- try{
- Class.forName("com.mysql.jdbc.Driver");
- }catch (ClassNotFoundException e) {
- e.printStackTrace();
- }
- try{
- c=DriverManager.getConnection(url);
- String pic=getMax()+".jpg";
- System.out.print(pic);
- String sql="insert into user values (null,?,?,?,?,?,?,?,?,null,?,?,?,?,?,?,?,1);";
- PreparedStatement pr=c.prepareStatement(sql);
- System.out.println(sql);
- pr.setString(1,pic);
- pr.setString(2,names);
- pr.setString(3, sex);
- pr.setInt(4, age);
- pr.setString(5, dept);
- pr.setString(6, job);
- pr.setString(7, birthday);
- pr.setString(8, comeday);
- pr.setInt(9, workage);
- pr.setString(10, ids);
- pr.setString(11, tel);
- pr.setString(12, home);
- pr.setString(13, edu);
- pr.setString(14, hobby);
- pr.setString(15, etc);
- System.out.println(sql);
- pr.execute();
- result=1;
- }catch (SQLException e) {
- e.printStackTrace();
- // TODO: handle exception
- }
- return result;
- }
- public static int getMax(){
- int result=0;
- try{
- Class.forName("com.mysql.jdbc.Driver");
- }catch (ClassNotFoundException e) {
- e.printStackTrace();
- }
- try{
- String url1="jdbc:mysql://localhost:3306/company?user=root&password=rootcode";
- Connection cc=DriverManager.getConnection(url1);
- Statement ss=cc.createStatement();
- String sql="select MAX(num) as 'max' from user;";
- System.out.print(sql);
- ResultSet rs=ss.executeQuery(sql);
- while(rs.next()){
- result=rs.getInt("max");
- result=result+1;
- }
- }catch (SQLException e) {
- e.printStackTrace();
- // TODO: handle exception
- }
- return result;
- }
- }
<?xml version="1.0" encoding="UTF-8"?>
- <service id="remoting-service"
- class="flex.messaging.services.RemotingService">
- <adapters>
- <adapter-definition id="java-object" class="flex.messaging.services.remoting.adapters.JavaAdapter" default="true"/>
- </adapters>
- <default-channels>
- <channel ref="my-amf"/>
- </default-channels>
- <destination id="main">
- <properties>
- <source>HR</source>
- </properties>
- </destination>
- </service>