当状态切换时,触发alarm事件,在事件里调用数据库的操作函数,取得数据绑定在新状态下的datagrid组件上
新的stste
<mx:State name="alarm" activate="alarm()" >
<mx:RemoveChild target="{image1}"/>
<mx:AddChild relativeTo="{canvas1}" position="lastChild">
<mx:DataGrid x="0" y="0" width="100%" height="100%" id="db1" dataProvider="{myarray}" >
<mx:columns>
<mx:DataGridColumn headerText="id" dataField="alarmId"/>
<mx:DataGridColumn headerText="报警设备" dataField="deviceId"/>
<mx:DataGridColumn headerText="报警时间" dataField="alarmDate"/>
<mx:DataGridColumn headerText="报警信息" dataField="alarmNote"/>
<mx:DataGridColumn headerText="报警进程" dataField="alarmProcess"/>
<mx:DataGridColumn headerText="报警次数" dataField="alarmTimes"/>
</mx:columns>
</mx:DataGrid>
</mx:AddChild>
</mx:State>
script里的函数
public function alarm() :void {
remoteControl.getData();
remoteControl.addEventListener(ResultEvent.RESULT,onResult);
setintervalID=setInterval(alarm,600000);//刷新60分钟
}
public function onResult(event:ResultEvent) :void{
myarray=ArrayCollection(event.result);
//db1.dataProvider = myarray;
}
组件
<mx:RemoteObject destination="Control" id="remoteControl"/>
<mx:Button label="网络故障管理" fontFamily="Verdana" fontSize="15" color="#105FE1" icon="@Embed(source='../img/wlgz.png')" textRollOverColor="#3171F4" textSelectedColor="#3171F4" click="currentState='alarm'" />
java程序
alarmbean:
package data;
public class AlarmBean {
private int alarmId;
private String deviceId;
private String alarmData;
private int alarmType;
private String alarmNote;
private int alarmState;
private int alarmTimes;
private String alarmProcess;
//alarmId
public void setalarmId(int alarmId){
this.alarmId = alarmId;
}
public int getalarmId(){
return alarmId;
}
//deviceId
public void setdeviceId(String deviceId){
this.deviceId = deviceId;
}
public String getdeviceId(){
return deviceId;
}
//alarmData
public void setalarmData(String alarmData){
this.alarmData = alarmData;
}
public String getalarmData(){
return alarmData;
}
//alarmType
public void setalarmType(int alarmType){
this.alarmType = alarmType;
}
public int getalarmType(){
return alarmType;
}
//alarmNote
public void setalarmNote(String alarmNote){
this.alarmNote = alarmNote;
}
public String getalarmNote(){
return alarmNote;
}
//alarmState
public void setalarmState(int alarmState){
this.alarmState = alarmState;
}
public int getalarmState(){
return alarmState;
}
//alarmTimes
public void setalarmTimes(int alarmTimes){
this.alarmTimes = alarmTimes;
}
public int getalarmTimes(){
return alarmTimes;
}
//alarmProcess
public void setalarmProcess(String alarmProcess){
this.alarmProcess= alarmProcess;
}
public String getalarmProcess(){
return alarmProcess;
}
}
控制函数
package data;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import data.TestDao;
import data.AlarmBean;
import data.DeviceBean;
public class Control {
TestDao test=new TestDao();
public List getData(){
System.out.println("list");
ArrayList list=new ArrayList();
String sql="select * from t_alarm";
ResultSet rs=test.selectSql(sql);
System.out.println(rs.toString());
try {
while(rs.next()){
AlarmBean db=new AlarmBean();
db.setalarmId(rs.getInt("alarmId"));
db.setdeviceId(rs.getString("deviceId"));
db.setalarmData(rs.getString("alarmDate"));
db.setalarmNote(rs.getString("alarmNote"));
db.setalarmProcess(rs.getString("alarmProcess"));
db.setalarmTimes(rs.getInt("alarmTimes"));
if(db.getalarmState()==0&&db.getalarmTimes()>=2)
list.add(db);
System.out.println("hello");
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println(list.toString());
return list;
}}