flex 多级窗口互调连接oracle动态管理生成动态datagrid
发布时间:2020-12-15 04:58:09 所属栏目:百科 来源:网络整理
导读:废话不多说,直接上代码讲解: 首先是对datagrid的管理界面 ,里面有增加,删除,修改,界面如下: 然后主页面名字 :EditeBusPdGo.xml,代码如下: ?xml version="1.0" encoding="utf-8"?s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="libr
废话不多说,直接上代码讲解:
首先是对datagrid的管理界面,里面有增加,删除,修改,界面如下: 然后主页面名字:EditeBusPdGo.xml,代码如下: <?xml version="1.0" encoding="utf-8"?> <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" creationComplete="init()"> <fx:Declarations> <!-- 将非可视元素(例如服务、值对象)放在此处 --> </fx:Declarations> <fx:Script> <![CDATA[ import mx.collections.ArrayCollection; import mx.collections.ArrayList; import mx.controls.Alert; import mx.controls.DataGrid; import mx.controls.dataGridClasses.DataGridColumn; import mx.events.CloseEvent; import mx.events.ListEvent; import mx.formatters.DateFormatter; import mx.managers.PopUpManager; import mx.rpc.events.ResultEvent; import mx.rpc.soap.WebService; public var dgDataArr:Array; private static var dateFormatter:DateFormatter = new DateFormatter(); // private var formatString:String="YYYY-MM-DD"; [Bindable] private var notes:ArrayCollection ; private var addNoteScreen:AddBusLineRunTime; private var UpdateNoteScreen:UpdateBusLineRunTm; private var WebServiceUrl:String="http://localhost:10635/AnalysisRdBl/AnalysisBL.asmx?wsdl"; private var setBusName:String="99路"; private var setTime:String="2012-12-02"; private function init():void{ runTimeTable.text=setBusName+"行车计划时刻表"; doTime.text="实施日期: "+setTime; getdata(); addNoteScreen = new AddBusLineRunTime(); addNoteScreen.addEventListener("SaveNote",saveNote); UpdateNoteScreen=new UpdateBusLineRunTm(); UpdateNoteScreen.addEventListener("SaveNote",update); } private function update(e:Event):void { var ob:Object=new Object(); ob.线路名=setBusName; ob.路牌名=UpdateNoteScreen.lupai.text; ob.圈=UpdateNoteScreen.quan.text; ob.实施时间=setTime; ob.报到=UpdateNoteScreen.baodao.text; ob.工时=UpdateNoteScreen.gongshi.text; ob.出场=UpdateNoteScreen.chuchang.text; ob.离场=UpdateNoteScreen.lichang.text; var updatenotes:ArrayCollection= new ArrayCollection(); updatenotes.addItem(ob); var temparr:ArrayCollection=new ArrayCollection(); temparr=UpdateNoteScreen.notes; var xx:XML=TWOarrToXml(updatenotes,temparr); var xxString:String=xx.toXMLString(); //trace(xx.toXMLString()); var ws1:WebService = new WebService(); ws1.loadWSDL(WebServiceUrl); ws1.updateTable.addEventListener(ResultEvent.RESULT,resultUpdateData); ws1.updateTable.send(updateO,xxString); PopUpManager.removePopUp(UpdateNoteScreen); } private function resultUpdateData(e:ResultEvent):void { getdata(); if(e.result as String=="success") { Alert.show("更新成功!"); } else { Alert.show("更新失败!"); } } private function getdata():void { var ws1:WebService = new WebService(); ws1.loadWSDL(WebServiceUrl); ws1.GetBusRunTimeList.addEventListener(ResultEvent.RESULT,resultGetData); ws1.GetBusRunTimeList.send(setBusName,setTime); } public var ObObArr:Array; private function refreshObOb():void { ObObArr=new Array(); for(var i:int=0;i<dgDataArr.length;i++) { var LuLU:String=dgDataArr[i]["路牌名"].toString(); ObObArr.push(LuLU); } } private function resultGetData(e:ResultEvent):void{ if(e.result as String=="noData") { Alert.show("您好,本线路下面还没有具体线路信息,请添加","没有信息!") } else{ var returnValue:XMLList=XML(e.result).children(); //ShowRunTimeTable.dataProvider=xmlListToArray(returnValue); dgDataArr=new Array(); dgDataArr=xmlListToArray(returnValue); refreshObOb(); // for(var i:int=0;i<dgDataArr.length;i++) // { // var LuLU:String=dgDataArr[i]["路牌名"].toString(); // trace(LuLU); // ObObArr.push(LuLU); // // // } //deleteArr=xmlListToArray(returnValue); showTableInit(); } } private function xmlListToArray(results:XMLList):Array { var array:Array=new Array(); for each(var child:XML in results) { var obj:Object=new Object(); //obj[child.nodeKind()]=child[child.nodeKind()]; for each(var ite:XML in child.children()) { obj[ite.name().toString()]=child[ite.name().toString()]; } //array.addItem(obj); array.push(obj); } return array; } private function getArraylistFromXMLList(data:XMLList):Array { var al:Array=new Array(); for(var i:int=0;i<data.length();i++) { var obj:Object=new Object(); for(var j:int=0;j<data[i].children().length();j++) { var dataColoum:String=data[i].children()[j].localName(); obj[dataColoum]=data[i].children()[j].toString(); } al.addItem(obj); } return al; } //public var deleteArr:Array=new Array(); //public var xxfc:Function; private function showCol():Array { var arr:Array=new Array(); var dataNum:int=dgDataArr[0]["站长"]; //trace(dataNum.toString()); //trace(dgDataArr[0]["OBJECTID"]); var shouzhan:String="首站"; var mozhan:String="末站"; for(var i:int=1;i<=dataNum;i++) { var temp1:String=shouzhan+i.toString(); var temp2:String=mozhan+i.toString(); arr.push(temp1); arr.push(temp2); } return arr; } // private function upArray(ii:int):void // { // var dataNum:int=dgDataArr[ii]["此长"]; // //trace(dataNum.toString()); // // // //trace(dgDataArr[0]["OBJECTID"]); // var shouzhan:String="首站"; // var mozhan:String="末站"; // // for(var i:int=1;i<=dataNum;i++) // { // var temp1:String=shouzhan+i.toString(); // var temp2:String=mozhan+i.toString(); // arr.push(temp1); // arr.push(temp2); // // } // // // // } //public var upArr:Array=new Array(); public var dataGrid:DataGrid; private var busNam:String="99路"; private function showTableInit():void { var dgData:ArrayCollection = new ArrayCollection(dgDataArr); dataGrid = new DataGrid(); dataGrid.horizontalScrollPolicy = "on"; dataGrid.x = 10; dataGrid.y = 20; //dataGrid.editable = true; dataGrid.percentWidth = 100; dataGrid.percentHeight=90; dataGrid.setStyle("fontSize",14); dataGrid.styleName dataGrid.dataProvider = dgData; //dataGrid.addEventListener(ListEvent.ITEM_CLICK,itemClickHandler); showDT.removeAllElements(); showDT.addElement(dataGrid); var columns:Array = new Array(); var col:DataGridColumn; var buslineName1:String=dgDataArr[0]["线路名"]; //busNam=buslineName1; var time:String=dgDataArr[0]["实施时间"]; var lupaicol:DataGridColumn=new DataGridColumn(); lupaicol.headerText="路牌"; lupaicol.dataField="路牌名"; columns.push(lupaicol); var baodaocol:DataGridColumn=new DataGridColumn(); baodaocol.headerText="报到"; baodaocol.dataField="报到"; columns.push(baodaocol); var chuchangcol:DataGridColumn=new DataGridColumn(); chuchangcol.headerText="出场"; chuchangcol.dataField="出场"; columns.push(chuchangcol); var arr:Array= showCol(); for(var i:int=1;i<=arr.length;i++) { var d:String=arr[i-1]; if(i%2==0) { col = new DataGridColumn(d); col.headerText="末站"; columns.push(col); } else{ col = new DataGridColumn(d); col.headerText="首站"; columns.push(col); } } var lichangcol:DataGridColumn=new DataGridColumn(); lichangcol.headerText="离场"; lichangcol.dataField="离场"; columns.push(lichangcol); var gongshicol:DataGridColumn=new DataGridColumn(); gongshicol.headerText="工时"; gongshicol.dataField="工时"; columns.push(gongshicol); var quancol:DataGridColumn=new DataGridColumn(); quancol.headerText="圈"; quancol.dataField="圈"; columns.push(quancol); dataGrid.columns=columns; } private function itemClickHandler(e:ListEvent):void { trace(e.target); } private function addNote():void { PopUpManager.addPopUp(addNoteScreen,this,true); PopUpManager.centerPopUp(addNoteScreen); addNoteScreen.ObObArr=ObObArr; //addNoteScreen.author.text = ""; //addNoteScreen.topic.text = ""; //addNoteScreen.description.text = ""; } private function close():void { PopUpManager.removePopUp(this); } private function arrToXml(arr:ArrayCollection):XML{ var root:XML = new XML("<result/>"); for(var i:int = 0;i<arr.length;i++){ var node:XML = new XML("<item/>"); node.线路名=arr[i].线路名; node.路牌名=arr[i].路牌名; node.圈=arr[i].圈; node.实施时间=arr[i].实施时间; node.报到=arr[i].报到; node.工时=arr[i].工时; node.出场=arr[i].出场; node.离场=arr[i].离场; root.appendChild(node); } return root; } private function TWOarrToXml(arr:ArrayCollection,arr2:ArrayCollection):XML{ var root:XML = new XML("<result/>"); for(var i:int = 0;i<arr.length;i++){ var node:XML = new XML("<item/>"); node.线路名=arr[i].线路名; node.路牌名=arr[i].路牌名; node.圈=arr[i].圈; node.实施时间=arr[i].实施时间; node.报到=arr[i].报到; node.工时=arr[i].工时; node.出场=arr[i].出场; node.离场=arr[i].离场; for(var j:int=0;j<arr2.length;j++) { var shou:String="首站"+(j+1); var mo:String="末站"+(j+1); node[shou]=arr2[j].首站; node[mo]=arr2[j].末站; } root.appendChild(node); } return root; } public var xxString:String; private function saveNote(e:Event):void { var ob:Object=new Object(); ob.线路名=setBusName; ob.路牌名=addNoteScreen.lupai.text; ob.圈=addNoteScreen.quan.text; ob.实施时间=setTime; ob.报到=addNoteScreen.baodao.text; ob.工时=addNoteScreen.gongshi.text; ob.出场=addNoteScreen.chuchang.text; ob.离场=addNoteScreen.lichang.text; notes= new ArrayCollection(); notes.addItem(ob); var temparr:ArrayCollection=new ArrayCollection(); temparr=addNoteScreen.notes; var xx:XML=TWOarrToXml(notes,temparr); var ws1:WebService = new WebService(); ws1.loadWSDL(WebServiceUrl); ws1.insertTable.addEventListener(ResultEvent.RESULT,resultInsert); //ws1.insertTable.send(xxString); //xxString="<result><item><线路名>640路</线路名><路牌名>88</路牌名><圈>88</圈> <实施时间>2012-06-10</实施时间><报到>88</报到><工时>88</工时> <出场>88</出场> <离场>88</离场> <首站1>765</首站1><末站1>654</末站1> <首站2>543</首站2><末站2>432</末站2><首站3>321</首站3><末站3>210</末站3></item></result>"; //ws.GetBusRunTimeList.send(); xxString=xx.toXMLString(); //trace(xxString); ws1.insertTable.send(xxString); //trace(xxString); // trace(notes.toString()); //trace(arr1.toString()); //trace(arr2.toString()); PopUpManager.removePopUp(addNoteScreen); //var upadteString:String= } private function resultInsert(e:ResultEvent):void{ var sh:String=String(e.result); getdata(); if(sh=="success") { Alert.show("插入成功!","成功"); } else { Alert.show("插入失败!","失败"); } } private function deletePiece(event:CloseEvent):void{ if (event.detail==Alert.YES){ if (dataGrid.selectedItems == null) return; var index:int=0; var seledIndexs:int=dataGrid.selectedIndex; //for (var i:int=0; i < seledIndexs.length; i++) //{ //index=seledIndexs[i]; //dgDataArr[0]["线路名"] //var id:Number=xxfc(seledIndexs) as Number; //trace(xxfc(seledIndexs)); var s:String=(dgDataArr[seledIndexs]["OBJECTID"].toString()); //delete(dgDataArr[seledIndexs]); //notes.removeItemAt(seledIndexs); var deletewsl:WebService=new WebService(); deletewsl.loadWSDL(WebServiceUrl); deletewsl.deleteData.addEventListener(ResultEvent.RESULT,resultDelete); deletewsl.deleteData.send(s); delete(dgDataArr[seledIndexs]); //ObObArr.splice(0,ObObArr.length); //refreshObOb(); //delete(ObObArr[seledIndexs]); } } private function resultDelete(e:ResultEvent):void { var sh:String=String(e.result); getdata(); if(sh=="success") { Alert.show("删除成功!","成功"); } else { Alert.show("删除失败!","失败"); } } private var updateO:String; private function updatePiece():void{ UpdateNoteScreen.ObObArr=ObObArr; UpdateNoteScreen.oldLupai=dgDataArr[seledIndexs]["路牌名"].toString(); updateO=dgDataArr[seledIndexs]["OBJECTID"].toString(); PopUpManager.addPopUp(UpdateNoteScreen,true); PopUpManager.centerPopUp(UpdateNoteScreen); if (dataGrid.selectedItems == null) return; var index:int=0; var seledIndexs:int=dataGrid.selectedIndex; UpdateNoteScreen.lupai.text=dgDataArr[seledIndexs]["路牌名"].toString(); UpdateNoteScreen.baodao.text=dgDataArr[seledIndexs]["报到"].toString(); UpdateNoteScreen.chuchang.text=dgDataArr[seledIndexs]["出场"].toString(); UpdateNoteScreen.lichang.text=dgDataArr[seledIndexs]["离场"].toString(); UpdateNoteScreen.gongshi.text=dgDataArr[seledIndexs]["工时"].toString(); UpdateNoteScreen.quan.text=dgDataArr[seledIndexs]["圈"].toString(); //UpdateNoteScreen.time.text=dgDataArr[seledIndexs]["实施时间"].toString(); var notes:ArrayCollection=new ArrayCollection(); //trace(dgDataArr[seledIndexs]["此长"].toString()); var len:int=int(dgDataArr[seledIndexs]["此长"].toString()); //trace(len.toString()); for(var i:int=1;i<=len;i++) { var sh:String="首站"+i; var mo:String="末站"+i; var ob:Object=new Object(); //trace(sh); //trace(dgDataArr[seledIndexs][sh].toString()); ob.首站=dgDataArr[seledIndexs][sh].toString(); ob.末站=dgDataArr[seledIndexs][mo].toString(); //note.author = addNoteScreen.author.text; //note.topic = addNoteScreen.topic.text; //note.description = addNoteScreen.description.text; notes.addItem(ob); //trace(notes.length.toString()); //UpdateNoteScreen.shoumo.dataProvider=notes; UpdateNoteScreen.notes=notes; UpdateNoteScreen.shoumo.dataProvider=UpdateNoteScreen.notes; } } private function deleteAsk():void { Alert.show("确定删除?","系统提示",(1|2),deletePiece); } ]]> </fx:Script> <!-- <s:Button x="156" y="114" label="显示数据" click="getdata()"/> <s:DataGrid id="showData" x="525" y="128" requestedRowCount="4"> </s:DataGrid> <s:DataGrid id="xx" x="301" y="114" requestedRowCount="4"> <s:columns> <s:ArrayList> <s:GridColumn dataField="OBJECTID" headerText="列 1"></s:GridColumn> </s:ArrayList> </s:columns> </s:DataGrid> --> <s:Panel title="公交时刻行车计划表" width="100%" height="100%"> <s:VGroup x="0" y="0" width="100%" height="100%" gap="0" horizontalAlign="left" verticalAlign="top"> <s:HGroup width="100%" height="29"> <s:Group width="100%" height="30"> <s:Label id="companyName" x="19" y="10" text="公司名称:杨高公交"/> <s:Label id="runTimeTable" x="374" y="10" text="行车时刻计划表"/> <s:Label id="doTime" x="739" y="11" text="实施日期:"/> <!--<s:Button x="159" y="10" label="按钮" click="getdata()"/>--> </s:Group> </s:HGroup> <s:HGroup width="100%" height="27"> <s:Button label="增加" click="addNote()"/> <s:Button label="删除" click="deleteAsk()"/> <s:Button label="修改" click="updatePiece()"/> </s:HGroup> <s:VGroup width="100%" id="showDT" height="90%"> </s:VGroup> </s:VGroup> </s:Panel> </s:Application> 点击增加,弹出AddBusLineRunTime.mxml,界面如下: 代码如下: <?xml version="1.0" encoding="utf-8"?> <mx:TitleWindow xmlns:mx="library://ns.adobe.com/flex/mx" xmlns:fx="http://ns.adobe.com/mxml/2009" layout="absolute" width="498" height="598" title="增加一条数据" xmlns:s="library://ns.adobe.com/flex/spark" creationComplete="init()"> <fx:Script> <![CDATA[ import mx.collections.ArrayCollection; import mx.controls.Alert; import mx.managers.PopUpManager; // [Bindable] public var notes:ArrayCollection=new ArrayCollection(); public var ObObArr:Array=new Array(); private var addNoteScreen:AddShouMo; private var WebServiceUrl:String="http://localhost:8081/AnalysisBL.asmx?wsdl"; private function close():void { PopUpManager.removePopUp(this); } private function save():void{ // for(var i:int=0;i<ObObArr.length;i++) // { // // trace(ObObArr[i].toString()); // } if(ObObArr.indexOf(lupai.text.toString())==-1) { this.dispatchEvent(new Event("SaveNote")); } else { Alert.show("已经存在该路牌名!请重新输入!"); } } private function init():void{ addNoteScreen = new AddShouMo(); addNoteScreen.addEventListener("SaveShouMo",SaveShouMo); } private function add():void{ PopUpManager.addPopUp(addNoteScreen,true); PopUpManager.centerPopUp(addNoteScreen); //addNoteScreen.author.text = ""; //addNoteScreen.topic.text = ""; //addNoteScreen.description.text = ""; } private function SaveShouMo(e:Event):void { // notes= // if(notes.length!=0) // { // notes.removeAll(); // } //var note:Note = new Note(); var ob:Object=new Object(); ob.首站=addNoteScreen.shouzhan.text; ob.末站=addNoteScreen.mozhan.text; //note.author = addNoteScreen.author.text; //note.topic = addNoteScreen.topic.text; //note.description = addNoteScreen.description.text; notes.addItem(ob); PopUpManager.removePopUp(addNoteScreen); shoumo.dataProvider=notes; } private function shanchu():void{ if (shoumo.selectedItems == null) return; var index:int=0; var seledIndexs:int=shoumo.selectedIndex; //for (var i:int=0; i < seledIndexs.length; i++) //{ //index=seledIndexs[i]; notes.removeItemAt(seledIndexs); //} } ]]> </fx:Script> <fx:Metadata> [Event(name="SaveNote")] </fx:Metadata> <mx:Label x="35" y="10" text="路牌"/> <mx:TextInput id="lupai" width="150" x="84" y="8"/> <mx:Label text="报到" y="36" x="35"/> <mx:TextInput id="baodao" width="150" x="84" y="34"/> <mx:Button label="取消" x="233" y="490" click="close()"/> <mx:Button label="保存" x="344" y="490" click="save()"/> <s:Label x="37" y="75" text="出场"/> <s:TextInput id="chuchang" x="84" y="65" width="150"/> <s:Label x="37" y="110" text="离场"/> <s:Label x="37" y="147" text="工时"/> <s:Label x="43" y="185" text="圈"/> <s:TextInput id="lichang" x="84" y="100" width="150"/> <s:TextInput id="gongshi" x="84" y="137" width="150"/> <s:TextInput id="quan" x="84" y="175" width="150"/> <s:DataGrid x="84" y="234" width="148" height="234" requestedRowCount="4" id="shoumo"> <s:columns> <s:ArrayList> <s:GridColumn dataField="首站" headerText="首站"></s:GridColumn> <s:GridColumn dataField="末站" headerText="末站"></s:GridColumn> </s:ArrayList> </s:columns> </s:DataGrid> <s:Button x="84" y="205" label="增加" click="add()"/> <s:Button x="162" y="205" label="删除" click="shanchu()"/> </mx:TitleWindow> 此页面又弹出添加AddShouMo.mxml,添加任意组首末站的界面: 代码如下: <?xml version="1.0" encoding="utf-8"?> <mx:TitleWindow xmlns:mx="library://ns.adobe.com/flex/mx" xmlns:fx="http://ns.adobe.com/mxml/2009" layout="absolute" width="348" height="138" title="增加首末站"> <fx:Script> <![CDATA[ import mx.managers.PopUpManager; private function close():void { PopUpManager.removePopUp(this); } private function save():void{ this.dispatchEvent(new Event("SaveShouMo")); } ]]> </fx:Script> <fx:Metadata> [Event(name="SaveShouMo")] </fx:Metadata> <mx:Label text="首站" x="35" y="10"/> <mx:TextInput id="shouzhan" width="150" x="84" y="8"/> <mx:Label text="末站" y="36" x="35"/> <mx:TextInput id="mozhan" width="150" x="84" y="34"/> <mx:Button label="取消" x="154" y="69" click="close()"/> <mx:Button label="保存" x="257" y="68" click="save()"/> </mx:TitleWindow> 再然后就是一个修改的页面:UpdateBusLineRunTm.mxml界面如下: 代码如下: <?xml version="1.0" encoding="utf-8"?> <mx:TitleWindow xmlns:mx="library://ns.adobe.com/flex/mx" xmlns:fx="http://ns.adobe.com/mxml/2009" layout="absolute" width="498" height="598" title="增加一条数据" xmlns:s="library://ns.adobe.com/flex/spark" creationComplete="init()"> <fx:Script> <![CDATA[ import mx.collections.ArrayCollection; import mx.controls.Alert; import mx.managers.PopUpManager; [Bindable] public var notes:ArrayCollection=new ArrayCollection(); public var ObObArr:Array=new Array(); private var addNoteScreen:AddShouMo; public var oldLupai:String; private function close():void { PopUpManager.removePopUp(this); } private function save():void{ if(lupai.text.toString()==oldLupai) { this.dispatchEvent(new Event("SaveNote")); } if(ObObArr.indexOf(lupai.text.toString())==-1) { this.dispatchEvent(new Event("SaveNote")); } else { Alert.show("已经存在该路牌名!请重新输入!"); } } private function init():void{ addNoteScreen = new AddShouMo(); addNoteScreen.addEventListener("SaveShouMo",SaveShouMo); //shoumo.dataProvider=notes; } private function add():void{ PopUpManager.addPopUp(addNoteScreen,true); PopUpManager.centerPopUp(addNoteScreen); //addNoteScreen.author.text = ""; //addNoteScreen.topic.text = ""; //addNoteScreen.description.text = ""; } private function SaveShouMo(e:Event):void { // notes= // if(notes.length!=0) // { // notes.removeAll(); // } //var note:Note = new Note(); var ob:Object=new Object(); ob.首站=addNoteScreen.shouzhan.text; ob.末站=addNoteScreen.mozhan.text; //note.author = addNoteScreen.author.text; //note.topic = addNoteScreen.topic.text; //note.description = addNoteScreen.description.text; notes.addItem(ob); PopUpManager.removePopUp(addNoteScreen); // shoumo.dataProvider=notes; } private function shanchu():void{ if (shoumo.selectedItems == null) return; var index:int=0; var seledIndexs:int=shoumo.selectedIndex; //for (var i:int=0; i < seledIndexs.length; i++) //{ //index=seledIndexs[i]; notes.removeItemAt(seledIndexs); //} } ]]> </fx:Script> <fx:Metadata> [Event(name="SaveNote")] </fx:Metadata> <mx:Label x="35" y="10" text="路牌"/> <mx:TextInput id="lupai" width="150" x="84" y="8"/> <mx:Label text="报到" y="36" x="35"/> <mx:TextInput id="baodao" width="150" x="84" y="34"/> <mx:Button label="取消" x="209" y="539" click="close()"/> <mx:Button label="保存" x="291" y="539" click="save()"/> <s:Label x="37" y="75" text="出场"/> <s:TextInput id="chuchang" x="84" y="65" width="150"/> <s:Label x="37" y="110" text="离场"/> <s:Label x="37" y="147" text="工时"/> <s:Label x="43" y="185" text="圈"/> <s:TextInput id="lichang" x="84" y="100" width="150"/> <s:TextInput id="gongshi" x="84" y="137" width="150"/> <s:TextInput id="quan" x="84" y="175" width="150"/> <s:DataGrid x="81" y="258" width="148" height="234" requestedRowCount="4" id="shoumo" > <s:columns> <s:ArrayList> <s:GridColumn dataField="首站" headerText="首站"></s:GridColumn> <s:GridColumn dataField="末站" headerText="末站"></s:GridColumn> </s:ArrayList> </s:columns> </s:DataGrid> <s:Button x="81" y="215" label="增加" click="add()"/> <s:Button x="164" y="215" label="删除" click="shanchu()"/> </mx:TitleWindow> 下面说下这其中的难点: 源代码,和后台webservice以及数据库文件在附件中,其中涉及到一个数据传输的问题,webservice可以传输可以序列化的数据类型,本demo中,是以xml的方式传输的,webservice,我用c#写的,首先就是连接数据库,这里使用的OLEDB连接的数据库:首先在web.config中加入如下字段: <appSettings> <add key="oracleconnection" value="Provider=MSDAORA;Persist Security Info=true;User ID=pdjt;password=pdjt;Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=xxxxxxxxxxxxxxxxxxooooooooooooooooooo)(PORT=1521))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)))"/> <add key="SDEServer" value="xxxxxxxxxxxxxxxxxxooooooooooooooooooo"/> <add key="SDEInstance" value="5151"/> <add key="SDEUser" value="pdjt"/> <add key="SDEPwd" value="pdjt"/> <add key="SDEDatabase" value="ORCL"/> <add key="SDEVersion" value="SDE.DEFAULT"/> <add key="bufferDistance" value="5"/> <add key="filterDistance" value="10"/> </appSettings> 然后连接数据库 //连接并打开数据库 string connString = System.Configuration.ConfigurationManager.AppSettings["oracleconnection"]; OleDbConnection conn = new OleDbConnection(connString); conn.Open(); 由于是同时操作一对多的两张表,增删改,我们如何保证数据的一致性和完整性呢 先建立一个序列 CREATE SEQUENCE "PDJT"."NewSequence" INCREMENT BY 1 MINVALUE 1 MAXVALUE 2147483647 START WITH 161 CACHE 20; GRANT SELECT,ALTER ON "PDJT"."NewSequence" TO PUBLIC; ????? 每次插入,先从序列拿到值: string sql = "Select YZN001.nextval from dual"; OleDbCommand commsql = new OleDbCommand(sql,conn); double OBJECTID=Convert.ToDouble(commsql.ExecuteScalar()) ; 同时插入主表和附表就保证了主键的唯一性以及主表附表的数据的完整性 取得收据,后要生成xml,传给前台 XmlDocument doc = new XmlDocument(); doc.AppendChild(doc.CreateElement("result")); XmlElement item = doc.CreateElement("item"); XmlElement nodeZhanZhang = doc.CreateElement("站长"); nodeZhanZhang.InnerText = maxIN.ToString(); item.AppendChild(nodeZhanZhang); XmlElement nodeCiChang = doc.CreateElement("此长"); nodeCiChang.InnerText = tbl.Rows.Count.ToString(); item.AppendChild(nodeCiChang); .........doc.LastChild.AppendChild(item); return doc.InnerXml; 前台到后台的xml的遍历: XmlDocument doc = new XmlDocument(); doc.LoadXml(xmlString); ArrayList headersubList = new ArrayList(); //获取当前XML文档的根 一级 XmlNode oNode = doc.DocumentElement; //获取根节点的所有子节点列表 XmlNodeList oList = oNode.ChildNodes; //标记当前节点 XmlNode oCurrentNode; //遍历所有二级节点 for (int i = 0; i < oList.Count; i++) { //二级 oCurrentNode = oList[i]; // 线路名 = oList[i].Value; //检测当前节点的名称,节点的值是否与已知匹配 if (oCurrentNode.Name.ToLower().Equals("item")) { //检测是否有子节点 三级 if (oCurrentNode.HasChildNodes) { //Console.WriteLine(oCurrentNode.ChildNodes.Count); //遍历当前节点的所有子节点 for (int n = 0; n < oCurrentNode.ChildNodes.Count; n++) {, oracle时间类型的处理: public string 实施时间 = "2012-06-05"; to_date('" + 实施时间 + "','yyyy-mm-dd')); 关于oracle时间处理的详解: ORACLE/JSP技术涉及日期、时间问题的处理 (1)在英文版本的ORACLE中默认日期格式为'DD-MON-YY',例如'01-JAN-98' ? 在汉化的中文版本中ORACLE默认日期格式为'日-月-年',例如'21-8月-2003'或'21-8月-03' (2)转换字符串为日期 使用ORACLE内部函数to_date() to_date()函数的参数是to_char()函数参数的反转。 to_date(string_value,date_format) 变量定义如下: string_value :为字符串直接值(字符串本身)、字符串列(数据库中定义的某个表的某列)或某字符串内部函数的返回值。 date_format为合法的Oracle日期格式。 下列更新语句均符合ORACLE的日期格式,更新成功: create table student (name varchar2(10) not null primary key,enrolldate date not null);//创建student表 insert into student values('mark',to_date('08-21-2003','MM-DD-YYYY')); insert into student values('mark1',to_date('21-08-2003','DD-MM-YYYY')); insert into student values('mark2','21-8月-2003'); insert into xiongxiaomin.student values('mark3','21-8月-03'); (3)转换日期为字符串 使用ORACLE内部函数to_char() to_char(date_value,date_format) 变量定义如下: date_value :为日期型直接值(日期本身)、日期型列值(数据库中定义的某个表的某列)或某内部函数的返回的日期型值。 date_format为合法的Oracle日期格式。 选择enrolldate字段的时间部分: select (to_char(enrolldate,'HH24:MI:SS'))enrolldate from? student; (4)注意:ORACLE中的date数据类型定义的列包含日期和时间。 1、系统当前日期为2003年8月21日,之后执行下列语句 insert into student values('mark5',to_date('09:28:03','HH:MI:SS'));//注意此种在一条记录的date类型字段中插入时间的方法,系统默认的日期为系统当前日期所在月份的第一天,因此得到的记录为 Name??????????? enrolldate mark5??? 01-八月 -2003 09:28:03 AM 2、修改系统当前日期为2003年7月21日,之后执行下列语句 insert into student values('mark6','HH:MI:SS')); 得到的记录为 Name??????????? enrolldate mark6???? 01-七月 -2003 09:28:03 AM insert into student values('mark8',to_date('20:28:03','HH24:MI:SS')); 3、同时在一条记录中插入日期和时间的方法 insert into student values('mark9',to_date('21-08-2003 20:28:03','DD-MM-YYYY HH24:MI:SS'));//同时在一条记录中插入日期和时间的方法 insert into student values('mark',to_date('21-08-2003 09:52:03','DD-MM-YYYY HH:MI:SS'));//同时在一条记录中插入日期和时间的方法 注意不能使用下列方法同时插入日期和时间 insert into student values('mark2','21-8月-2003'+to_date(' 09:52:03','HH:MI:SS'));//无效插入记录方法 4、在SQL*Plus Worksheet中执行下列SQL语句 select * from student; 得到的记录结果如下:注意date类型字段中只显示了日期,时间并未显示 NAME???????????????? ENROLLDATE mark?????????????? 18-8月 -03 mark1????????????? 21-8月 -03 mark2????????????? 21-8月 -03 已选择3行。 5、但在JSP程序中同样执行select * from student order by enrolldate 显示结果见下图(既显示了日期,又显示了时间) ???????????????????????? JSP页面中的显示结果 6、在SQL*Plus Worksheet中执行下列SQL语句 select name,to_char(enrolldate,'DD-MM-YYYY HH:MI:SS') from student; 得到的记录结果如下:注意date类型字段中显示了日期和时间 NAME???????????????? TO_CHAR(ENROLLDATE,'DD-MM-YYYYHH:MI:SS mark?????????????? 21-08-2003 12:00:00 mark1????????????? 21-08-2003 12:00:00 已选择2行 注意:5和6中的不同,时间到秒时,JSP页面中显示时多出了". 0" 7、在SQL*Plus Worksheet中执行下列SQL语句 select name,'DD-MM-YYYY HH24:MI:SS') from student; 得到的记录结果如下:注意date类型字段中显示了日期,时间 NAME???????????????? TO_CHAR(ENROLLDATE,'DD-MM-YYYYHH24:MI: mark?????????????? 18-08-2003 17:40:20 mark1????????????? 21-08-2003 00:00:00 mark2????????????? 21-08-2003 00:00:00 已选择3行。 注意:6和7中的SELECT中的"HH:MI:SS"和"HH24:MI:SS"两者的不同是"HH"为小时制,值的范围为0-12;"HH24"为24小时制,值的范围为0-23。 ?? 看下列例子: ①insert into student values('南太里',to_date('08-19-2003 13:54:05','MM-DD-YYYY HH24:MI:SS')); ORACLE中的记录结果为: NAME?????????????????? enrolldate 南太里??????????????? 19-八月 -2003 01:54:05 PM ②insert into student values('南太里2','MM-DD-YYYY HH:MI:SS'));//插入错误 错误提示为: insert into student values('南太里2',to_date('08-19-2003 13:54:05','MM-DD ????????????????????????????????????????????????????????? * ERROR 位于第 1 行: ORA-01849: 小时值必须介于 1 和 12 之间 即应用"HH"时,不能应用"13:54:05",而应改为"01:54:05" 正确语句如下: insert into student values('南太里2',to_date('08-19-2003 01:54:05','MM-DD-YYYY HH:MI:SS')); ORACLE中的记录结果为: NAME?????????????????? enrolldate 南太里2????????????? 19-八月 -2003 01:54:05 AM 注意上述两种方式得出的结果一种为PM,另一种为AM。 为了提高正确性,建议都是用地一种方式"HH24" 8、但在JSP程序中同样执行select name,'DD-MM-YYYY HH:MI:SS') from student 显示结果见下图。(其结果与在SQL*Plus Worksheet中执行下列SQL语句 select name,'DD-MM-YYYY HH:MI:SS') from student;相同) 9、在SQL*Plus Worksheet中执行下列SQL语句 select name,'month dd,yyyy HH24:MI:SS') from student; 得到的记录结果如下:注意date类型字段中显示了日期,时间 NAME???????????????? TO_CHAR(ENROLLDATE,'MONTHDD,YYYYHH24:MI:SS') mark?????????????? 8月? 18,2003 17:40:20 mark1????????????? 8月? 21,2003 00:00:00 mark2????????????? 8月? 21,2003 00:00:00 已选择3行。 10、to_char()函数,'DD-MM-YYYY'格式及'MM-DD-YYYY'格式和'month dd,yyyy'格式的不同 'DD-MM-YYYY'格式:21-08-2003 'month dd,yyyy'格式:8月? 21,2003 11、注意:在日期和时间格式中非常容易混淆的是月份和秒的格式(即MM和MI) 在SQLPlus*Worksheet中执行下列语句,不报错。 insert into student values('王嘉',to_date('08:05','HH24:MM'));//08被认为是小时,05被认为是月份。 commit; 在表编辑器中查看:实际插入值为 NAME???????????????? ENROLLDATE 王嘉??? 01-五月 -2003 08:00:00 AM select name,'DD-MM-YYYY HH24:MI:SS')enrolldate from student where name='王嘉'; NAME???????????????? ENROLLDATE 王嘉???????????????? 01-05-2003 08:00:00 已选择 1 行。 insert into student values('汪嘉2','MM-DD-YYYY HH24:MI:SS')); 12、使用Oracle的date数据类型的另一个优点是:它支持日期的运算。可以对已经存在的 日期加上或减去若干天,例如: insert into student values('熊',sysdate+7); 还有一个问题就是附表主键自增长问题,写一个序列和触发器: 序列: CREATE SEQUENCE "PDJT"."NewSequence" INCREMENT BY 1 MINVALUE 1 MAXVALUE 2147483647 START WITH 281 CACHE 20; GRANT SELECT,ALTER ON "PDJT"."NewSequence" TO PUBLIC; 触发器: CREATE OR REPLACE TRIGGER "PDJT"."NewTrigger" BEFORE INSERT ON "PDJT"."公交线路行车时刻计划表附表" REFERENCING OLD AS "OLD" NEW AS "NEW" FOR EACH ROW BEGIN SELECT YZN002.NEXTVAL INTO :NEW.OBJECTID FROM DUAL; END; ; ALTER TRIGGER "PDJT"."NewTrigger" ENABLE; flex前端,xml转array: private function xmlListToArray(results:XMLList):Array { var array:Array=new Array(); for each(var child:XML in results) { var obj:Object=new Object(); //obj[child.nodeKind()]=child[child.nodeKind()]; for each(var ite:XML in child.children()) { obj[ite.name().toString()]=child[ite.name().toString()]; } //array.addItem(obj); array.push(obj); } return array; } array转xml private function arrToXml(arr:ArrayCollection):XML{ var root:XML = new XML("<result/>"); for(var i:int = 0;i<arr.length;i++){ var node:XML = new XML("<item/>"); node.线路名=arr[i].线路名; node.路牌名=arr[i].路牌名; node.圈=arr[i].圈; node.实施时间=arr[i].实施时间; node.报到=arr[i].报到; node.工时=arr[i].工时; node.出场=arr[i].出场; node.离场=arr[i].离场; root.appendChild(node); } return root; } 其他见附件 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |