
<?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;
private var step:int=10;
private var count:int=0;
private var k:int=10;
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
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
protected function remoteobject1_faulthandler3(event:faultevent):void
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));
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.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();
}
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) {
// todo: handle exception
return r;
}
public int deleteitem(int i){
int result=0;
string sql="update user set visible=0 where num = "+i+";";
s.execute(sql);
result=1;
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){
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);
pr.execute();
return result;
public static int getmax(){
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;";
resultset rs=ss.executequery(sql);
result=rs.getint("max");
result=result+1;
}
}
<?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>