`
cuixuelei
  • 浏览: 49340 次
  • 性别: Icon_minigender_1
  • 来自: 济南
社区版块
存档分类
最新评论

flex的dataGrid:用checkbook和弹出窗口修改,返回修改本行

阅读更多

弹出窗口类:CusterEdit.mxml

<?xml version="1.0" encoding="utf-8"?>  
<mx:TitleWindow xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" width="400" height="300"  
      creationComplete="initComponent()"  
      showCloseButton="true"  
      close="closeWindow()">  
       
    <mx:Script>  
  
        <![CDATA[  
            
        /* 数据xml格式如下:   
            <items>  
                <item label="Tom" data="num001"/>  
                <item label="Lucy" data="num002"/>  
            </items>    
        */   
           
         import mx.managers.PopUpManager;   
         import mx.rpc.events.ResultEvent;   
         import mx.controls.Alert;   
         import mx.collections.ArrayCollection;
            
         [Bindable]public var mainApp:Object = null;     
         [Bindable]public var headTitle:String;           
         [Bindable]public var url:String;   
         [Bindable]public var selectedItem:Object;   
         [Bindable]public var callbackFunction:Function;  //回调函数   
        
         [Bindable]public var customer_codeS:String;//客户编码
         [Bindable]public var customer_nameS:String;//客户名称
         [Bindable]public var coordinatexS:String;//x坐标
         [Bindable]public var coordinateyS:String;//y坐标
         [Bindable]public var lineArr:ArrayCollection;//线路计划
         [Bindable]public var ship_periodS:String;//配送周期
        
         [Bindable]
         public var cards:ArrayCollection = new ArrayCollection(
                [ {label:"Visa",data:1}, //这样的数组分配方式也是第一次见:) 经过分析才学习到:这里的"data"似乎是自定义的变量名,label是组件"label"
                  {label:"MasterCard", data:2},
                  {label:"American Express", data:3} ]);

            
         private function initComponent():void {   
            //listDataService.url = url;   
            listDataService.send();   
         }   
            
        //closeWindow   
         private function closeWindow():void {   
               PopUpManager.removePopUp(this);   
         }   
            
         private function submit():void {   
             PopUpManager.removePopUp(this);
             if (coordinatex.text != null && coordinatey.text != null) {  
                 //调用父窗体的方法并以参数形式返回选择结果   
                 callbackFunction.call(mainApp, coordinatex.text,coordinatey.text,ship_period.text,line.selectedItem["data"],line.selectedItem["label"]);    
             } else{
              Alert.show("怎么走了这");
             }  
            
            
         }   
            
         private function mySelection(oEvent:Event):void {   
             selectedItem = oEvent.target.selectedItem;   
         }      
           
        private function initListData(event:ResultEvent):void {   
            //使用HTTPService返回的xml数据,初始化List数据   
            //dataList.dataProvider = event.result.items.item;   
        }   
  
       ]]>  
    </mx:Script>  
  
    <mx:HTTPService id="listDataService" url="{url}" showBusyCursor="true"  result="initListData(event)" />  
  
    <mx:Label text="{headTitle}"/>  
       
     
    <mx:FormItem label="客户编码:" width="237">
     <mx:Text id="customer_code" width="124"  height="31"/>
    </mx:FormItem>
    <mx:FormItem label="客户名称:" width="237">
     <mx:Text id="customer_name" width="124"/>
    </mx:FormItem>
    <mx:FormItem label="经度坐标:" width="237">
     <mx:TextInput id="coordinatex" width="124"/>
    </mx:FormItem>
    <mx:FormItem label="纬度坐标:" width="237">
     <mx:TextInput id="coordinatey" width="124"/>
    </mx:FormItem>
    <mx:FormItem label="配送周期:" width="237">
     <mx:TextInput id="ship_period" width="145"/>
    </mx:FormItem>
    <mx:FormItem label="线    路:" width="237">
     <mx:ComboBox id="line"  width="147"/>
    </mx:FormItem>
    <mx:VBox width="100%">  
        <mx:Button label="保存" click="submit();"/>  
    </mx:VBox>  
       
</mx:TitleWindow> 

父窗体:CustomerList.mxml里面用的是DataGrid 修改、地图定位

<?xml version="1.0" encoding="utf-8"?>

<mx:TitleWindow xmlns:mx="http://www.adobe.com/2006/mxml"
                width="990"
                height="304"
                showCloseButton="true"
                creationComplete="init()"
                close="{PopUpManager.removePopUp(this)}"
                title="零售户信息"
                fontSize="12"
                xmlns:components="com.bluesword.cargps.components.*">

    <mx:Script source="utils.as"/>

    <mx:Script>
        <![CDATA[
         import com.bluesword.cargps.socket.CustomerMap;
            import com.bluesword.cargps.utils.Global;
            import mx.controls.Alert;
            import mx.controls.dataGridClasses.DataGridColumn;
            import com.bluesword.cargps.socket.ChengWeiData;
            import mx.collections.ArrayCollection;
            import mx.rpc.events.ResultEvent;
            import mx.rpc.remoting.RemoteObject;
            import mx.managers.PopUpManager;
            import mx.events.ListEvent;
            import mx.rpc.events.ResultEvent;
            import mx.events.DataGridEvent;
            import com.esri.ags.Map;
            import com.bluesword.cargps.AcceptUserInfo
            import mx.collections.ArrayCollection;
            import mx.rpc.events.FaultEvent;
            import com.bluesword.cargps.frame.report.CusterEdit; 
            import mx.containers.TitleWindow;  
      import mx.managers.PopUpManager;  
           
   private static var flexSession:RemoteObject = null;
           
            private var customerService:RemoteObject;

            public var userInfo:Object;

            [Bindable]
            private var array_qy:ArrayCollection;

            [Bindable]
            private var array_start:ArrayCollection;

            [Bindable]
            private var array_info:ArrayCollection;
           
            [Bindable] public var array_line:ArrayCollection;

   [Bindable]
   public var map:Map;
   
   public var acceptUserInfo:AcceptUserInfo;
   
   public var checkBox_info:String = new String();
   
   
            private function init():void
            {
              
                customerService = new RemoteObject();
                customerService.destination = "story.customerService";
               
    flexSession = new RemoteObject();
            flexSession.addEventListener(FaultEvent.FAULT,faultHandler);
            flexSession.destination="flexSession";
               
                //根据所选情况进行查询
                customerService.getCustomerInfo.addEventListener(ResultEvent.RESULT, getCarMonthOilUseInfoHandler);
               
                customerService.getCustomerType.addEventListener(ResultEvent.RESULT,addCustType);
                customerService.getCustomerType("CUSTOMER_STATUS");
               
                customerService.onSubmit.addEventListener(ResultEvent.RESULT,getSubmit);
               
                //初始化客户类型
    addCustStart();
    
    flexSession.getLoginUser.addEventListener(ResultEvent.RESULT,getFlexSession);//获得角色
    flexSession.getLoginUser();
    
    //获得线路
    customerService.getLine.addEventListener(ResultEvent.RESULT,getLine);
    customerService.getLine();
    
            }
           
            //获得线路
            public function getLine(event:ResultEvent):void{
             array_line = event.result as ArrayCollection;
            }
           
            //获得权限
            public  function getFlexSession(event:ResultEvent):void{
               var tmp:Object = event.result;
               userInfo = String(tmp.role_id);
      }
   
   
   //绑定客户类型
   private function addCustType(event:ResultEvent):void
   {
    
    array_qy = event.result as ArrayCollection;
    var def:Object = {
                        type_code: "0",
                        type_name: "全部"
                    };
                array_qy.addItemAt(def, 0);
                custType.selectedIndex = 0;
               
   }
   
   //绑定状态
   private function addCustStart():void
   {
    array_start = new ArrayCollection;
    var str1:Object = {start_code:"1",start_name:"提交"};
                array_start.addItemAt(str1,0);
                var str2:Object = {start_code:"2",start_name:"未提交"};
                array_start.addItemAt(str2,1);
                startM.selectedIndex = 0;
   }
          

          
            /**
             *  获取车辆日里程油耗统计信息
             */
            private function getCarMonthOilUseInfoHandler(event:ResultEvent):void
            {
                array_info = event.result as ArrayCollection;
//                gc.refresh();
    var item:Object = (myDG.dataProvider as ArrayCollection).getItemAt(1);  
                if (array_info.length > 0)
                    Alert.show("查询完毕");
                else
                    Alert.show("查询完毕,无信息");
            }

           
            /**
             *  根据指定的条件查询
             */
            private function onQuery():void
            {
             
                customerService.getCustomerInfo(customer_code.text,customer_name.text,startTime.text,endTime.text,custType.selectedItem.type_code,startM.selectedItem.start_code);
               
            }

            /**
             *  导出为Excel文件
             */
            private function onCreate():void
            {
                loadDGInExcel(myDG, Global.EXCEL_JSP, "零售户信息表");
            }
           
            /**
             *  双击车辆树型列表, 居中定位该车
             */
            public function onDoubleClick(event:ListEvent):void
            {
               var datagrid:DataGrid = event.target as DataGrid;
               var cols:DataGridColumn = myDG.columns[event.columnIndex];
               var customer_no = datagrid.selectedItem["customer_no"];
             
               var customer:CustomerMap = new CustomerMap(map);
               customer.showCustomerOnMap(customer_no);
            }
           
            //保存
            private function update(e:ListEvent)
            {
               
             /*var colIndex:Number = e.columnIndex;
             var datagrid:DataGrid = e.target as DataGrid;
             var col:DataGridColumn = datagrid.columns[colIndex];
             var x:Number = datagrid.selectedItem["coordinatex"];
             var y:Number = datagrid.selectedItem["coordinatey"];*/
             //acceptUserInfo
             myDG.invalidateList();
            }
           
            public  function onEditEnd(event:DataGridEvent):void
            {
             
    /*if(event.reason == DataGridEventReason.NEW_ROW || event.reason == DataGridEventReason.OTHER){
     
     
     acItemsSelected = dg.selectedItem;
     var code:String = acItemsSelected.customer_code;
     var x:Number = acItemsSelected.coordinatex;
     var y:Number =  acItemsSelected.coordinatey;
     customerService.update(code,x,y);
    }*/
    if(event.dataField=="coordinatex"){
     var datagrid:DataGrid = event.target as DataGrid;
         var cols:DataGridColumn = myDG.columns[event.columnIndex];
     //编辑后新的值
         var x:Number = myDG.itemEditorInstance[cols.editorDataField];
         var code:String = datagrid.selectedItem["customer_code"];
         var y:Number = datagrid.selectedItem["coordinatey"];
         customerService.update(code,x,y);
       }
       if(event.dataField == "coordinatey"){
        var datagrid:DataGrid = event.target as DataGrid;
        var cols:DataGridColumn = myDG.columns[event.columnIndex];
        var y:Number = myDG.itemEditorInstance[cols.editorDataField];
        var code:String = datagrid.selectedItem["customer_code"];
         var x:Number = datagrid.selectedItem["coordinatex"];
         customerService.update(code,x,y);
       }
            }
           
            //修改方法
            public function onEdit():void
            {
             var x:Number = myDG.selectedItem["coordinatex"];
             var code:String = myDG.selectedItem["customer_code"];
             var name:String = myDG.selectedItem["customer_name"];
             var y:Number = myDG.selectedItem["coordinatey"];
             var ship_period = myDG.selectedItem["ship_period"];
             
             //customerService.update(code,x,y);
             
              var titleWindowInstance:CusterEdit =  CusterEdit(PopUpManager.createPopUp(this, CusterEdit, false));
            titleWindowInstance.title = "零售户资料修改";
            titleWindowInstance.width = 400;
           titleWindowInstance.height = 300;   
           titleWindowInstance.mainApp = this;  
           titleWindowInstance.customer_code.text = code;//客户code
           titleWindowInstance.customer_name.text = name;//客户名称
           titleWindowInstance.coordinatex.text = x.toString();//x坐标
           titleWindowInstance.coordinatey.text = y.toString();//y坐标
           titleWindowInstance.ship_period.text = ship_period;//配送周期
           titleWindowInstance.line.dataProvider = array_line;//线路
           titleWindowInstance.url="http://localhost:9090/index.mxml";
           titleWindowInstance.callbackFunction = this.myFunction;
          
           PopUpManager.centerPopUp(titleWindowInstance);
    
             
            }
            public function myFunction(x:String,y:String,ship_periodS:String,lineCode:String,lineName:String):void {  
          Alert.show("x:"+x+"y:"+y+"配送周期"+ship_periodS+lineCode+lineName);
          //array_info.getItemAt(myDG.selectedIndex).coordinatex = x; 
          //array_info.setItemAt(x,);
          var customer_code:String = myDG.selectedItem["customer_code"];//客户编号
          var customer_name:String = myDG.selectedItem["customer_name"];//客户名称
          var manager_code:String = myDG.selectedItem["manager_code"];//客户经理CODE
          var manager_name:String = myDG.selectedItem["manager_name"];//客户经理名称
          var customer_no:String = myDG.selectedItem["customer_no"];//专卖证号
          var customer_status:String = myDG.selectedItem["customer_status"];//客户类型
          var customer_status_code:String = myDG.selectedItem["customer_status_code"];//客户类型编码
          var customer_type_name:String = myDG.selectedItem["customer_type_name"];//状态
          var customer_start_type:String = myDG.selectedItem["customer_start_type"];//状态编码
         
          var temp:Object = {customer_code:customer_code,
                   customer_name:customer_name,
                   manager_code:manager_code,
                   manager_name:manager_name,
                   coordinatex:x,
                   coordinatey:y,
                   ship_period:ship_periodS,
                   ship_line_id:lineCode,
                   ship_line_name:lineName,
                   customer_no:customer_no,
                   customer_status:customer_status,
                   customer_status_code:customer_status_code,
                   customer_type_name:customer_type_name,
                   customer_start_type:customer_start_type
                  };
        
          array_info.setItemAt(temp,myDG.selectedIndex);//修改
            }
           
             //定位方法
            public function onLocation():void
            {
             
               var customer_no = myDG.selectedItem["customer_no"];
               var customer:CustomerMap = new CustomerMap(map);
               customer.showCustomerOnMap(customer_no);
            }
           
            
      //查询后台错误处理
      public  function faultHandler(evt:FaultEvent):void{
          trace(evt.fault.message);
         }
        
         //提交        
         public function onSubmit():void
         {
          
          if(checkBox_info!="" && checkBox_info.split(";").length>0){
                 customerService.onSubmit(checkBox_info);
          }else{
           Alert.show("请选择要提交的客户!");
          }
          
         }
        
         public function getSubmit(event:ResultEvent):void
         {
          var outs:String = String(event.result);
          if(outs=="提交成功") onQuery();
           
          Alert.show(outs);
         }
        
   public function clickHanlder(obj:Object):void{
    if(obj.chxBox.selected){
     
     checkBox_info += array_info.getItemAt(myDG.selectedIndex).customer_code+";";
     Alert.show(checkBox_info);
    }else{
     var code:String = array_info.getItemAt(myDG.selectedIndex).customer_code;
     var newArr:String = new String();
     
     if(checkBox_info!=null && checkBox_info.length>0){
      var arr:Array = checkBox_info.split(";");
      for(var i:Number=0;i<arr.length;i++){
       
       var s:String = String(arr[i]);
       
       if(s!=code){
        newArr += s+";";
       }
      }
     }
     checkBox_info = newArr ;
    }
    
   }
        
        ]]>
    </mx:Script>

    <mx:Canvas width="100%"
               height="100%">
        <mx:FormItem x="231.5"
                     y="10"
                     label="客户编号:"
                     width="71">
                    
           
        </mx:FormItem>
        <mx:FormItem x="6"
                     y="10"
                     label="客户名称:">
        </mx:FormItem>

        <mx:TextArea id="customer_code"   x="310.5" y="11" width="94.5" leading="10"  height="22">
         
        </mx:TextArea>
        <mx:FormItem x="7"
                     y="43"
                     label="新增用户日期:"
                     width="183"
                     horizontalAlign="left">
            <components:CusDateField id="startTime"
                                     width="104"
                                     height="24"
                                     defFormatString="YYYY-MM-DD"/>
        </mx:FormItem>
        <mx:FormItem x="191"
                     y="43"
                     label="-"
                     width="174"
                     horizontalAlign="left">
            <components:CusDateField id="endTime"
                                     width="104"
                                     height="24"
                                     defFormatString="YYYY-MM-DD"/>
        </mx:FormItem>
        <mx:FormItem label="客户类型:" y="41" x="367">
         <mx:ComboBox id="custType"
                         width="89"
                         labelField="type_name"
                         dataProvider="{array_qy}">
            </mx:ComboBox>
        </mx:FormItem>
       
        <mx:FormItem label="状态" y="41" x="534" width="114">
         <mx:ComboBox id="startM"
             labelField="start_name"
             dataProvider="{array_start}" width="68">
         </mx:ComboBox>
        </mx:FormItem>

        <mx:Button x="413"
                   y="9"
                   label="查询"
                   click="onQuery()"
                   width="69"/>
        <mx:Button x="509"
                   y="9"
                   label="提交"
                   click="onSubmit()"
                   width="69"/>
        <mx:TabNavigator x="0"
                         y="76"
                         width="100%"
                         height="80%">
            <mx:Canvas label="零售户信息"
                       id="carsta"
                       width="100%"
                       height="100%"
                       horizontalScrollPolicy="off"
                       verticalScrollPolicy="off">

               
                <mx:DataGrid id="myDG"
                             x="0"
                             y="0"
                             width="{carsta.width}"
                             height="{carsta.height}"
                             dataProvider="{array_info}" editable="true"
                            
                             >
                    <mx:columns>
      <mx:DataGridColumn headerText="选择" editable="false">
       <mx:itemRenderer>  
                         <mx:Component>  
                          <mx:HBox>
                              <mx:CheckBox id="chxBox" label="{data.name}" name="custCheck" click="outerDocument.clickHanlder(this)"/>  
                          </mx:HBox>
                         </mx:Component>  
                      </mx:itemRenderer>
      </mx:DataGridColumn>
      <mx:DataGridColumn dataField="customer_code"   headerText="客户编号" editable="false"/>
      <mx:DataGridColumn dataField="customer_name"   headerText="客户名称" editable="false"/>
      <mx:DataGridColumn dataField="manager_code"    headerText="客户经理编号" editable="false"/>
      <mx:DataGridColumn dataField="manager_name"    headerText="客户经理名称" editable="false"/>
      <mx:DataGridColumn dataField="coordinatex"     headerText="经度坐标" editable="true"/>
      <mx:DataGridColumn dataField="coordinatey"     headerText="纬度坐标" editable="true"/> 
      <mx:DataGridColumn dataField="ship_period"     headerText="配送周期" editable="false"/>
      <mx:DataGridColumn dataField="ship_line_id"    headerText="线路ID" visible="false"/>
      <mx:DataGridColumn dataField="ship_line_name"  headerText="线路名称" editable="false"/>
      <mx:DataGridColumn dataField="customer_no"    headerText="专卖证号" visible="false"/>
      <mx:DataGridColumn dataField="customer_status" headerText="客户类型" editable="false"/>
      <mx:DataGridColumn dataField="customer_status_code" headerText="客户类型编码" visible="false"/>
      <mx:DataGridColumn dataField="customer_type_name" headerText="状态" editable="false"/>
      <mx:DataGridColumn dataField="customer_start_type" headerText="状态编码" visible="false"/>
      <mx:DataGridColumn headerText="操作1" editable="false">
       <mx:itemRenderer>
        <mx:Component>
         <mx:Button label="修改" click="outerDocument.onEdit()"/>
        </mx:Component>
       </mx:itemRenderer>
      </mx:DataGridColumn>
      <mx:DataGridColumn headerText="操作2" editable="false">
       <mx:itemRenderer>
        <mx:Component>
         <mx:Button label="定位" click="outerDocument.onLocation()"/>
        </mx:Component>
       </mx:itemRenderer>
      </mx:DataGridColumn>
      
     </mx:columns>
                </mx:DataGrid>
            </mx:Canvas>
        </mx:TabNavigator>
        <mx:TextArea id="customer_name"
                     width="99"
                      x="93" y="11" height="20">
        </mx:TextArea>
    </mx:Canvas>

</mx:TitleWindow>
 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics