package com.view.dataoption { import com.vo.FlowModel; import com.vo.FmNodes; import com.vo.FmXian; import flash.data.sqlConnection; import flash.data.sqlResult; import flash.data.sqlStatement; import flash.errors.sqlError; import flash.filesystem.File; import flash.net.FileReference; import mx.collections.ArrayCollection; import mx.controls.Alert; public class Conn { private var conn:sqlConnection; public function Conn() { } public function openConn():void{ var filee : FileReference = new FileReference(); conn = new sqlConnection(); var file : File = File.applicationStorageDirectory.resolvePath("flowmodel.db"); try{ conn.open(file); }catch(error:sqlError){ Alert.show(error.message); Alert.show(error.details); } } public function excutesql(sqlstr:String):void{ openConn(); var stmt:sqlStatement = new sqlStatement(); try{ stmt.sqlConnection = conn; stmt.text = sqlstr; stmt.execute(); }catch(error:sqlError){ Alert.show(error.message); Alert.show(error.details); } } public function findFlowModel(fmId : Number) : FlowModel{ openConn(); var stmt:sqlStatement = new sqlStatement(); var sqlstr : String ="select * from flowmodel where fm_id = "+fmId; var flowModel : FlowModel = null; try{ stmt.sqlConnection = conn; stmt.text = sqlstr; stmt.execute(); var result:sqlResult = stmt.getResult(); if(result.data !=null){ flowModel = new FlowModel(result.data[0]); Alert.show(flowModel.fmName); } }catch(error:sqlError){ Alert.show(error.message); Alert.show(error.details); } return flowModel; } public function findFlowXian(fmId : Number) : ArrayCollection{ openConn(); var stmt:sqlStatement = new sqlStatement(); var sqlstr : String ="select * from fmxian where fm_id = "+fmId; var arrXian : ArrayCollection; try{ stmt.sqlConnection = conn; stmt.text = sqlstr; stmt.execute(); var result:sqlResult = stmt.getResult(); if(result.data!=null){ arrXian = new ArrayCollection(); var numResults:int = result.data.length; for(var i:int = 0;i<numResults; i++){ var obj:Object = result.data[i]; var xian : FmXian = new FmXian(obj); arrXian.addItem(xian); } } }catch(error:sqlError){ Alert.show(error.message); Alert.show(error.details); } return arrXian; } public function findFlowNode(fmId : Number) : ArrayCollection{ openConn(); var stmt:sqlStatement = new sqlStatement(); var sqlstr : String ="select * from fmnodes where fm_id = "+fmId; var arrNode : ArrayCollection ; try{ stmt.sqlConnection = conn; stmt.text = sqlstr; stmt.execute(); var result:sqlResult = stmt.getResult(); if(result.data !=null){ arrNode = new ArrayCollection(); var numResults:int = result.data.length; for(var i:int = 0;i<numResults; i++){ var obj:Object = result.data[i]; var node : FmNodes = new FmNodes(obj); arrNode.addItem(node); } } }catch(error:sqlError){ Alert.show(error.message); Alert.show(error.details); } return arrNode; } public function insertsql(sqlstr:String) : Number{ openConn(); var stmt:sqlStatement = new sqlStatement(); try{ stmt.sqlConnection = conn; stmt.text = sqlstr; stmt.execute(); var result : sqlResult = stmt.getResult(); var primaryKey:Number = result.lastInsertRowID; closeConn(); return primaryKey; }catch(error:sqlError){ Alert.show(error.message); Alert.show(error.details); } return 0 ; } public function closeConn():void{ conn.close(); } } }