2 Replies Latest reply on Dec 9, 2010 9:08 AM by ScottJ2727

    itemEditEnd hell - event fires gazillion times

    ScottJ2727

      Well I was making great progress with my first major flex app when I hit a wall. The last element I put in place was to enable user to edit one column in a datagrid. Before I send the changes back to a web service I thought I would confirm that it is firing correctly and passing correct values. To my surprise the event fires over and over again. I believe its something to do with the use of the accordian and multiple canvases. Sorry but this is happening on both flex 3 and 4 platforms (its worse in 4 for some reason). I have not had a chance to scale down the project and simply it so apologies if the code is lenghty.

       

      Any ideas how to solve this?

       

      <?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"
                     creationPolicy= "all">
          <fx:Declarations>
             
                  <mx:WebService
                  id="nwCL2"
                  wsdl="http://finance-web/BannerWebServices/BannerService.asmx?WSDL">
                  <mx:operation name="FetchRequestAsTableToArray"
                                resultFormat="object"
                                showBusyCursor="true"
                                result="resultHandler(event)"
                                fault="onFault(event)">
                      <mx:request>
                          <IncRecItems>{IncRecItems}</IncRecItems>
                          <PmyGUID>{myGUID}</PmyGUID>
                          <AgeItems>{AgeItems}</AgeItems>
                      </mx:request>
                  </mx:operation>
              </mx:WebService>
             
              <mx:WebService
                  id="nwCL3"
                  wsdl="http://finance-web/BannerWebServices/BannerService.asmx?WSDL">
                  <mx:operation name="FetchDirectPOAsTableToArray"
                                resultFormat="object"
                                showBusyCursor="true"
                                result="resultHandler3(event)"
                                fault="onFault(event)">
                      <mx:request>
                          <IncRecItems>{IncRecItems}</IncRecItems>
                          <AgeItems>{AgeItems2}</AgeItems>
                          <PmyGUID>{myGUID}</PmyGUID>
                      </mx:request>
                  </mx:operation>
              </mx:WebService>
             
              <mx:WebService
                  id="nwCL4"
                  wsdl="http://finance-web/BannerWebServices/BannerService.asmx?WSDL">
                  <mx:operation name="FetchDirectPODELAsTableToArray"
                                resultFormat="object"
                                showBusyCursor="true"
                                result="resultHandler4(event)"
                                fault="onFault(event)">
                      <mx:request>
                          <PmyGUID>{myGUID}</PmyGUID>
                      </mx:request>
                  </mx:operation>
              </mx:WebService>
             
              <mx:WebService
                  id="nwCL5"
                  wsdl="http://finance-web/BannerWebServices/BannerService.asmx?WSDL">
                  <mx:operation name="SendMailMessage"
                                resultFormat="object"
                                showBusyCursor="true"
                                result="resultHandler5(event)"
                                fault="onFault(event)">
                      <mx:request>
                          <PmyGUID>{myGUID}</PmyGUID>
                          <from>
                              {from}
                          </from>
                          <recepient>
                              {recepient}
                          </recepient>
                          <bcc>
                              {bcc}
                          </bcc>
                          <cc>
                              {cc}
                          </cc>
                          <subject>
                              {subject}
                          </subject>
                          <body>
                              {myEmailBody}
                          </body>
                          <CallProc>
                              {CallProc}
                          </CallProc>
                      </mx:request>
                  </mx:operation>
              </mx:WebService>
             
              <mx:WebService
                  id="nwCL6"
                  wsdl="http://finance-web/BannerWebServices/BannerService.asmx?WSDL">
                  <mx:operation name="InsRecordFYPOAUD"
                                resultFormat="object"
                                showBusyCursor="true"
                                result="resultHandler6(event)"
                                fault="onFault(event)">
                      <mx:request>
                          <PmyGUID>{myGUID}</PmyGUID>
                          <myuserID>{myuserID}</myuserID>
                          <DocCode>{DocCode}</DocCode>
                      </mx:request>
                  </mx:operation>
                  <mx:operation name="DelRecordFYPOAUD"
                                resultFormat="object"
                                showBusyCursor="true"
                                result="resultHandler6(event)"
                                fault="onFault(event)">
                      <mx:request>
                          <PmyGUID>{myGUID}</PmyGUID>
                          <DocCode>{DocCode}</DocCode>
                      </mx:request>
                  </mx:operation>
                 
                  <mx:operation name="FetchUserID"
                                resultFormat="object"
                                showBusyCursor="true"
                                result="resultHandler7(event)"
                                fault="onFault(event)">
                      <mx:request>
                          <PmyGUID>{myGUID}</PmyGUID>
                      </mx:request>
                  </mx:operation>
                 
                  <mx:operation name="InsGUIDAudit"
                                resultFormat="object"
                                showBusyCursor="true"
                                result="resultHandler8(event)"
                                fault="onFault(event)">
                      <mx:request>
                          <PmyGUID>{myGUID}</PmyGUID>
                      </mx:request>
                  </mx:operation>
                 
              </mx:WebService>
              </fx:Declarations>
          <fx:Script>
              <![CDATA[
                  import mx.collections.ArrayCollection;
                  import mx.collections.IViewCursor;
                  import mx.controls.Alert;
                  import mx.controls.ToolTip;
                  import mx.controls.dataGridClasses.DataGridColumn;
                  import mx.controls.dataGridClasses.DataGridItemRenderer;
                  import mx.core.mx_internal;
                  import mx.events.DataGridEvent;
                  import mx.events.ListEvent;
                  import mx.rpc.events.FaultEvent;
                  import mx.rpc.events.ResultEvent;

       

                  //added after upgrading to flex 4
                  import mx.core.FlexGlobals;
                  import mx.controls.RichTextEditor
                 
                  //import flash.events.Event;
                  [Bindable] public var IncRecItems:String;
                  [Bindable] public var myGUID:String;
                  [Bindable] public var myData:ArrayCollection;
                  [Bindable]public var serverData:ArrayCollection; 
                  [Bindable]public var serverData3:ArrayCollection;
                  [Bindable]public var serverData4:ArrayCollection;
                  [Bindable]public var serverData5:ArrayCollection;    
                  [Bindable] public var IncRecItems3:String;
                 
                  [Bindable] public var from:String;
                  [Bindable] public var recepient:String;
                  [Bindable] public var bcc:String;
                  [Bindable] public var cc:String;
                  [Bindable] public var subject:String;
                  [Bindable] public var body:String;
                  [Bindable] public var CallProc:String;
                 
                  [Bindable] public var myEmailBody:String;
                 
                  [Bindable] public var myuserID:String;
                  [Bindable] public var DocCode:String;
                 
                  [Bindable] public var AgeItems:String;
                  [Bindable] public var AgeItems2:String;

       

                  [Bindable] public var DocItem:Number;
                  [Bindable] public var DocText:String;

       

                  //this adds event listener for mouse over event so I can display descriptive text about various columns values
                  //POFromRequest.addEventListener(ListEvent.ITEM_ROLL_OVER, declarePosition);
                  //USE ROLLOVER VERSUS MOUSEOVER EVENT AS THE LATTER CAUSES BLINKING
                 
                  private function createToolTip(event:ListEvent):void {
                 
                  //var col:DataGridColumn = POFromRequest.columns[event.columnIndex];
                  //var newValue:String = ArrayCollection(POFromRequest.dataProvider).getItemAt(event.rowIndex)[col.dataField];
                  //Alert.show("You are hovering over:" +newValue);
                 
                 
                  if (event.columnIndex==13)
                  {
                 
                 
                  var str:String =  "P-Y=Paid and Completed" + "\r"  + "O-Y=Open and Completed" + "\r"  + "O-R=Open and Unmatched" ;
                 
                  //this code works and will fetch active mouse over datagrid values!           
                  var col:DataGridColumn = POFromRequest.columns[event.columnIndex];
                  var newValue:String = ArrayCollection(POFromRequest.dataProvider).getItemAt(event.rowIndex)[col.dataField];
                  //Alert.show("You are hovering over:" +newValue);
                 
                 
                  }
                 
                  else if (event.columnIndex==21||event.columnIndex==22)
                 
                  {
                  var col21:DataGridColumn = POFromRequest.columns[21];
                  var col22:DataGridColumn = POFromRequest.columns[22];
                 
                  var Value21:Number = ArrayCollection(POFromRequest.dataProvider).getItemAt(event.rowIndex)[col21.dataField];
                  var Value22:Number = ArrayCollection(POFromRequest.dataProvider).getItemAt(event.rowIndex)[col22.dataField];
                 
                  //21=Bal not Rec(BNR);22=Bal not Inv(BNI)
                  //evaluate BNR/BNI and give approp message which represents
                  //action required by end user (ie they don't have to think!)
                  var str:String
                 
                  if (Value21>0 && Value22<=0)
                  {
                  str = "Case1:All invoices sent to AP but we are missing a receiving. Please contact receiving.";
                  }
                  else if(Value21>0 && Value22>0)
                  {
                  str = "Case2:We are missing invoices and receiving. Please contact both departments ASAP.";
                  }   
                  else if(Value21<=0 && Value22>0)
                  {
                  str = "Case3:All receiving completed but we are missing invoices. Please contact AP and forward any invoices to them ASAP.";
                  }
                  else if(Value21==0 && Value22==0)
                  {
                  str = "Case4:All documents received. No action required. You can hide these items by clicking/turning off the box:Include Balance of 0 Items? ";
                  }
                 
                  //var str:String = Value21.toString()+Value22.toString()
                 
                  }
                 
                  else
                  {
                  //var str:String = "Row :"  +event.rowIndex + "Column : " +event.columnIndex;
                  }   
                 
                 
                  POFromRequest.toolTip = str;
                  }
                 
                  private function deleteToolTip(obj:Object):void {
                  POFromRequest.toolTip = null;
                  }
                 
                  //start mouse over code for directPO datagrid
                 
                  private function createToolTip2(event:ListEvent):void {
                 
                  //var col:DataGridColumn = DirectPOGrid.columns[event.columnIndex];
                  //var newValue:String = ArrayCollection(DirectPOGrid.dataProvider).getItemAt(event.rowIndex)[col.dataField];
                  //Alert.show("You are hovering over:" +newValue);
                 
                  if (event.columnIndex==1)
                  {
                  var str:String =  "If you know for sure that this item is not yours then highlight item by left clicking, then hit the delete button below. Hold the ctrl key to select multiple items." ;               
                  }
                 
                 
                 
                  if (event.columnIndex==12)
                  {
                 
                 
                  var str:String =  "P-Y=Paid and Completed" + "\r"  + "O-Y=Open and Completed" + "\r"  + "O-R=Open and Unmatched" ;
                 
                  //this code works and will fetch active mouse over datagrid values!           
                  var col:DataGridColumn = DirectPOGrid.columns[event.columnIndex];
                  var newValue:String = ArrayCollection(DirectPOGrid.dataProvider).getItemAt(event.rowIndex)[col.dataField];
                  //Alert.show("You are hovering over:" +newValue);
                 
                  }
                 
                  else if (event.columnIndex==20||event.columnIndex==21)
                 
                  {
                  var col20:DataGridColumn = DirectPOGrid.columns[20];
                  var col21:DataGridColumn = DirectPOGrid.columns[21];
                 
                  var Value20:Number = ArrayCollection(DirectPOGrid.dataProvider).getItemAt(event.rowIndex)[col20.dataField];
                  var Value21:Number = ArrayCollection(DirectPOGrid.dataProvider).getItemAt(event.rowIndex)[col21.dataField];
                 
                  //21=Bal not Rec(BNR);22=Bal not Inv(BNI)
                  //evaluate BNR/BNI and give approp message which represents
                  //action required by end user (ie they don't have to think!)
                  var str:String
                 
                  if (Value20>0 && Value21<=0)
                  {
                  str = "Case1:All invoices sent to AP but we are missing a receiving. Please contact receiving.";
                  }
                  else if(Value20>0 && Value21>0)
                  {
                  str = "Case2:We are missing invoices and receiving. Please contact both departments ASAP.";
                  }   
                  else if(Value20<=0 && Value21>0)
                  {
                  str = "Case3:All receiving completed but we are missing invoices. Please contact AP and forward any invoices to them ASAP.";
                  }
                  else if(Value20==0 && Value21==0)
                  {
                  str = "Case4:All documents received. No action required. You can hide these items by clicking/turning off the box:Include Balance of 0 Items? ";
                  }
                 
                  //var str:String = Value21.toString()+Value22.toString()
                 
                  }
                 
                  else
                  {
                  //var str:String = "Row :"  +event.rowIndex + "Column : " +event.columnIndex;
                  }   
                 
                 
                  DirectPOGrid.toolTip = str;
                  }
                 
                  private function deleteToolTip2(obj:Object):void {
                  DirectPOGrid.toolTip = null;
                  }
                 
                 
                  //end tool tip code
             
                 
                  private function GetData():void
                  {
                  //IncRecItems = "Y"
                  //IncRecItems = "Y"
                  //myGUID = "d5ef405a-d64a-489f-8583-38dd087de502"
                  //var MyurlParams:Dictionary = new Dictionary();
                  //MyurlParams = getUrlParamaters();
                 
                  //myGUID = MyurlParams['myGUID'];
                 
                  nwCL2.FetchRequestAsTableToArray.send();
                  }
                 
                  private function GetData3():void
                  {
                  //IncRecItems = "Y"
                  //IncRecItems = "Y"
                  //myGUID = "d5ef405a-d64a-489f-8583-38dd087de502"
                  var MyurlParams:Dictionary = new Dictionary();
                  MyurlParams = getUrlParamaters();
                 
                  myGUID = MyurlParams['myGUID'];
                 
                  nwCL3.FetchDirectPOAsTableToArray.send();
                  NotifyDel();
                  }
                 
                  private function GetData4():void
                  {
                  //IncRecItems = "Y"
                  //IncRecItems = "Y"
                  //myGUID = "d5ef405a-d64a-489f-8583-38dd087de502"
                  var MyurlParams:Dictionary = new Dictionary();
                  MyurlParams = getUrlParamaters();
                 
                  myGUID = MyurlParams['myGUID'];
                 
                  nwCL4.FetchDirectPODELAsTableToArray.send();
                  NotifyStatus();
                  }
                 
                  public function resultHandler(event:ResultEvent):void {
                 
                  serverData = new ArrayCollection(event.result.source);
                 
                 
                  //             Alert.show("getdata fired");
                 
                  }    
                 
                  public function resultHandler3(event:ResultEvent):void {
                 
                  serverData3 = new ArrayCollection(event.result.source);
                 
                 
                  //             Alert.show("getdata fired");
                 
                  }
                 
                  public function resultHandler4(event:ResultEvent):void {
                 
                  serverData4 = new ArrayCollection(event.result.source);
                 
                 
                  //             Alert.show("getdata fired");
                 
                  }        
                 
                  public function resultHandler5(event:ResultEvent):void {
                 
                  var FunctionResult:String=event.result.toString();
                  var Response:String;
                 
                  if(FunctionResult != "Success")
                  {
                  Alert.show("A problem has occurred. " + FunctionResult);
                 
                  }
                  else
                  {
                  Alert.show("The email was sent successfully.");
                  }
                 
                 
                  //             Alert.show("getdata fired");
                 
                  }        
                 
                  public function resultHandler6(event:ResultEvent):void {
                 
                  var FunctionResult:String=event.result.toString();
                  var Response:String;
                 
                  if(FunctionResult != "Success")
                  {
                  Alert.show("A problem has occurred. " + FunctionResult);
                 
                  }
                  else
                  {
                  Alert.show("Item moved.");
                  //refresh both datagrids for deleted/ins records
                  //need to call diff proc which does the same but does not show the initial message box
                  ReloadTables()
                 
                  }
                 
                  }        
                 
                  public function resultHandler7(event:ResultEvent):void {
                 
                  var FunctionResult:String=event.result.toString();
                 
                  if(FunctionResult == "Invalid GUID")
                  {
                  Alert.show("A problem has occurred. " + FunctionResult);
                 
                  }
                  else
                  {
                 
                  myuserID = FunctionResult;
                  myGlobVar.globMyUserID = FunctionResult;
                 
                  }
                 
                  }        
                 
                  public function resultHandler8(event:ResultEvent):void {
                 
                  //we don't really care about handling this event
                 
                  var FunctionResult:String=event.result.toString();
                 
                  if(FunctionResult == "Invalid GUID")
                  {
                  Alert.show("A problem has occurred. " + FunctionResult);
                 
                  }
                  else
                  {
                 
                  //myuserID = FunctionResult;
                 
                  }
                 
                  }        
                 
                 
                  private function initApp():void
                  {
                 
                  //code for grabing guid passed from .net ldap authentication page
                  //this file is located on finance-web box along with guid database.
                  //the web service is also located on finance-web
                  //and flex source code is on box fin-selement3 but is saved to U and published to finance-web
                  //(this is because flex is installed on fin-selement3 only
                 
                 
                 
                  //GurfeedTbl = nwCL.FetchFTVACCTAsTable();
                  flash.system.Security.allowDomain("*");flash.system.Security.allowInsecureDomain("*");
                  //siteData.send();
                 
                  //trace("Hello from Flex Debugging!");
                  //Alert.show("Init app fired");
                 
                  //first get focus of email tab (if we don't then a bug exists;error on object creation)
                  //I have tried various techniques for some reason I can't load back to base 0
                  //ac.selectedIndex = 3;
                  //Alert.show("Please remember to audit documents on all tabssss!");
                  //ac.selectedIndex = 1;
                 
                  Alert.show("HardCoded GUID in place. Remove after testing")
                  myGUID = "c25ef14a-bff4-4e07-bfa5-f9c0725c3fd0";

       

                  //need to set initial value
                  AgeItems = "N";
                  AgeItems2 = "N";
                 
                 
                  myBody.text = "Body";
                  //myGUID = "d5ef405a-d64a-489f-8583-38dd087de502"
                 
                  //var MyurlParams:Dictionary = new Dictionary();
                  //MyurlParams = getUrlParamaters();
                 
                  //myGUID = MyurlParams['myGUID'];
                 
                  //Alert.show("HardCoded GUID in place. Remove after testing")
                  //myGUID = "c25ef14a-bff4-4e07-bfa5-f9c0725c3fd0";

       

                  //insert audit trail record
                 
                  nwCL6.InsGUIDAudit.send();
                 
                  nwCL6.FetchUserID.send(); //for some reason when this was located inside the proc it was called from it would not
                  //set the global variable until after it was required resulting in null error
                 
                  //myGlobVar.globMyUserID = myUserID ;
                 
                 
                  }   
                  //Alert.show
                  private function checkBoxZero_change(evt:Event):void {
                 
                  if(checkBoxZero.selected == true) IncRecItems = "Y" else IncRecItems ="N";
                  //Alert.show(IncRecItems.toString())
                  GetData() ;
                 
                  }
                  private function checkBoxAge_change(evt:Event):void {
                 
                  //if(checkBoxAge.selected == true) AgeItems = "Y" else AgeItems ="N";
                  if(checkBoxAge.selected == true) AgeItems = "N" else AgeItems ="Y";
                 
                  GetData() ;
                 
                  }
                 
                  private function checkBoxAge2_change(evt:Event):void {
                 
                  //if(checkBoxAge.selected == true) AgeItems = "Y" else AgeItems ="N";
                  if(checkBoxAge2.selected == true) AgeItems2 = "N" else AgeItems2 ="Y";
                 
                  GetData3() ;
                 
                  }
                 
                  private function checkBoxZero3_change(evt:Event):void {
                 
                  if(checkBoxZero3.selected == true) IncRecItems3 = "Y" else IncRecItems3 ="N";
                  //Alert.show(IncRecItems.toString())
                  GetData3() ;
                 
                  }
                  private function onFault(event:FaultEvent):void {
                  Alert.show(event.fault.toString());
                  }
                 
                 
                  private function RemoveItems():void {
                  var selectedItems:Array = DirectPOGrid.selectedItems;
                  var listItem:Object;
                 
                 
                 
                  if (selectedItems.length < 1)
                  {
                  Alert.show("You did not highlight any items. Highlight items by left clicking the mouse. To select multiple items, hold the ctrl key down while left clicking.");
                  }
                 
                  //nwCL6.FetchUserID.send();
                 
                  for (var i:int = 0; i < selectedItems.length; i++)
                  {
                  listItem = selectedItems[i];
                  //DirectPOGrid.removeItem(listItem);
                  //TargetList.addItem(listItem);
                 
                  //var newValue:String = ArrayCollection("selectedItems").getItemAt(i)["PO"];
                  var newValue:String = listItem["PO"].toString()
                  //Alert.show(newValue);
                  DocCode = listItem["PO"].toString()
                 
                  //call proc to set userid was not working here as it was getting fired after so I moved it to initapp
                  //nwCL6.FetchUserID.send();
                  myuserID = myGlobVar.globMyUserID;
                  //myUserID = 'testuser';
                  nwCL6.InsRecordFYPOAUD.send();
                 
                 
                  //Alert.show("doc:"+DocCode+" guid:"+myGUID+"user:"+myGlobVar.globMyUserID);
                 
                  //Alert.show(selectedItems[i][PO].toString());
                  }
                 
                  }
                 
                  private function RemoveItems4():void {
                  var selectedItems:Array = DirectPOGridNotMine.selectedItems;
                  var listItem:Object;
                 
                  if (selectedItems.length < 1)
                  {
                  Alert.show("You did not highlight any items. Highlight items by left clicking the mouse. To select multiple items, hold the ctrl key down while left clicking.");
                  }
                 
                  for (var i:int = 0; i < selectedItems.length; i++)
                  {
                  listItem = selectedItems[i];
                  //DirectPOGrid.removeItem(listItem);
                  //TargetList.addItem(listItem);
                 
                  //var newValue:String = ArrayCollection("selectedItems").getItemAt(i)["PO"];
                  var newValue:String = listItem["PO"].toString()
                  //Alert.show(newValue);
                  //Alert.show(selectedItems[i][PO].toString());
                 
                  DocCode = listItem["PO"].toString()
                 
                  //myGUID = "d5ef405a-d64a-489f-8583-38dd087de502"
                  nwCL6.DelRecordFYPOAUD.send();
                 
                  }
                 
                  }
                 
                  private function NotifyDel():void {
                  Alert.show("These PO's were not created from requests and we are only guessing that they might belong to you. If you don't want to see specific PO's then you can remove them. This is done by highlighting items (left clicking on row), then clicking the delete button below. Hold the ctrl key to select multiple items.") ;   
                  }
                 
                  private function NotifyStatus():void {
                  Alert.show("These PO's were not created from requests and are displayed here because you have marked them as not belonging to you. If you have accidentally deleted these and they really belong to you then hit the delete button below to reactivate them.") ;   
                  }
                 
                  private function POSendEmailAP():void {
                 
                  var selectedItems:Array = POFromRequest.selectedItems;
                  var listItem:Object;
                  var newValue:String;
                  var ValEmailTO:String = "MSAJI@aus.edu,NALZOUBI@aus.edu";
                  var myString:String;
                  var txtBody:String;
                  var num:int;
                 
                  if (selectedItems.length < 1)
                  {
                  Alert.show("You did not highlight any items. Highlight items by left clicking the mouse. To select multiple items, hold the ctrl key down while left clicking.");
                  }
                 
                  // emailTO.text = ValEmailTO ;
                  txtBody = myBody.text.toString()
                 
                  for (var i:int = 0; i < selectedItems.length; i++)
                  {
                  listItem = selectedItems[i];
                  //DirectPOGrid.removeItem(listItem);
                  //TargetList.addItem(listItem);
                 
                  //var newValue:String = ArrayCollection("selectedItems").getItemAt(i)["PO"];
                  newValue = listItem["PO"].toString();
                  //Alert.show(newValue);
                 
                  emailTO.text = ValEmailTO;
                 
                  if (emailSUBJECT.text.toString()=="subject")
                  {
                  emailSUBJECT.text = newValue ;   
                  }
                  else
                  {
                 
                  if (emailSUBJECT.text.indexOf(newValue,0)<0)//this ensures that we only show distinct PO values
                  {
                  emailSUBJECT.text = emailSUBJECT.text.toString()+"/"+newValue ;   
                  }
                 
                  }
                 
                 
                  //code for email body
                 
                  if (txtBody=="Body")
                  {
                  txtBody = "Dear AP/Receiving:" + "\r" + "\r" + "Please note that I have received the following items directly from the vendor(s): " + "\r" + "\r" + listItem["PO"].toString() + " POItem:" + listItem["POItem"].toString() + " " + listItem["CMDDESC"].toString()  + " " + "QTYRCVD:" + listItem["BALNOTRECD"].toString() + " ";
                 
                  }
                  else
                  {
                  txtBody = txtBody + "\r" + listItem["PO"].toString() + " POItem:" + listItem["POItem"].toString() + " " + listItem["CMDDESC"].toString()  + " " + "QTYRCVD:" + listItem["BALNOTRECD"].toString() + " ";   
                  }
                 
                 
                  }   
                  myBody.text = txtBody;
                  //public variable for sending body text to email service in correct format
                  //body = txtBody;
                 
                  Alert.show("Items copied to email tab.");
                 
                  POFromRequest.selectedIndex=-1;
                 
                  }
                 
                  private function POSendEmailAPDirectStuff():void {
                 
                  var selectedItems:Array = DirectPOGrid.selectedItems;
                  var listItem:Object;
                  var newValue:String;
                  var ValEmailTO:String = "MSAJI@aus.edu,NALZOUBI@aus.edu";
                  var myString:String;
                  var txtBody:String;
                 
                 
                  if (selectedItems.length < 1)
                  {
                  Alert.show("You did not highlight any items. Highlight items by left clicking the mouse. To select multiple items, hold the ctrl key down while left clicking.");
                  }
                 
                  // emailTO.text = ValEmailTO ;
                  txtBody = myBody.text.toString()
                 
                  for (var i:int = 0; i < selectedItems.length; i++)
                  {
                  listItem = selectedItems[i];
                  //DirectPOGrid.removeItem(listItem);
                  //TargetList.addItem(listItem);
                 
                  //var newValue:String = ArrayCollection("selectedItems").getItemAt(i)["PO"];
                  newValue = listItem["PO"].toString();
                  //Alert.show(newValue);
                 
                  emailTO.text = ValEmailTO;
                 
                  if (emailSUBJECT.text.toString()=="subject")
                  {
                  emailSUBJECT.text = newValue ;   
                  }
                  else
                  {
                  if (emailSUBJECT.text.indexOf(newValue,0)<0)//this ensures that we only show distinct PO values
                  {
                  emailSUBJECT.text = emailSUBJECT.text.toString()+"/"+newValue ;   
                  }
                  }
                 
                 
                  //code for email body
                 
                  if (txtBody=="Body")
                  {
                  txtBody = "Dear AP/Receiving:" + "\r" + "\r" + "Please note that I have received the following items directly from the vendor(s): " + "\r" + "\r" + listItem["PO"].toString() + " POItem:" + listItem["POItem"].toString() + " " + listItem["CMDDESC"].toString()  + " " + "QTYRCVD:" + listItem["BALNOTRECD"].toString() + " ";
                 
                  }
                  else
                  {
                  txtBody = txtBody + "\r" + listItem["PO"].toString() + " POItem:" + listItem["POItem"].toString() + " " + listItem["CMDDESC"].toString()  + " " + "QTYRCVD:" + listItem["BALNOTRECD"].toString() + " ";   
                  }
                 
                 
                  }   
                  myBody.text = txtBody;
                  Alert.show("Items copied to email tab.");
                  DirectPOGrid.selectedIndex=-1;
                  }
                 
                  private function ClearEmail():void {
                 
                 
                  myBody.text = "Body";
                  emailSUBJECT.text = "Subject";
                 
                  }
                 
                  private function SEmail():void {
                 
                  //hardcode until we fetch via guid
                  //Alert.show("Insert code to fetch username from guid. For now its hard coded.");
                 
                  CallProc = "FLEX"; //This notifies web service so it parses out \r to <p>
                  //from = "selement@aus.edu"
                 
                  var MyurlParams:Dictionary = new Dictionary();
                  MyurlParams = getUrlParamaters();
                 
                  myGUID = MyurlParams['myGUID'];
                  //myGUID = "c25ef14a-bff4-4e07-bfa5-f9c0725c3fd0";
                 
                 
                  //from = myuserID+"@aus.edu";
                  from = myGlobVar.globMyUserID+"@aus.edu";
                 
                 
                 
                  recepient =  emailTO.text.toString();
                  cc = emailCC.text.toString();
                  bcc = "selement@aus.edu"
                  subject = emailSUBJECT.text.toString();   
                 
                  //var stuffToReplace:RegExp = /\r\n|\n\r/g;
                  //the key to this function is the /g means global and means to replace ALL instances of search variable!!!
                  var stuffToReplace:RegExp = /\r/g;
                 
                 
                 
                  //myEmailBody = myEmailBody.replace("\r","*123");
                  myEmailBody = myBody.text.replace(stuffToReplace,"*123*");
                 
                  //myEmailBody = myBody.text.replace("\r","*\r").toString();
                  //myEmailBody = myBody.text ;
                 
                  //myEmailBody.replace("\r","*\r");
                 
                  //myGUID = "d5ef405a-d64a-489f-8583-38dd087de502"
                  nwCL5.SendMailMessage.send();
                 
                  }
                 
                  private function ReloadTables():void
                  {
                 
                  //myGUID = "d5ef405a-d64a-489f-8583-38dd087de502"
                  nwCL4.FetchDirectPODELAsTableToArray.send();
                  nwCL3.FetchDirectPOAsTableToArray.send();    
                 
                  }
                 
                  private function getUrlParamaters():Dictionary
                  {
                  var urlParams:Dictionary = new Dictionary();
                 
                  if (ExternalInterface.available)
                  {
                  var fullUrl:String = ExternalInterface.call('eval', 'document.location.href');
                  var paramStr:String = fullUrl.split('?')[1];
                  if (paramStr != null)
                  {
                  var params:Array = paramStr.split('&');
                  for (var i:int=0; i < params.length; i++)
                  {
                  var kv:Array = params[i].split('=');
                  urlParams[kv[0]] = kv[1];
                  }
                  }
                  }
                  else
                  {
                      urlParams = FlexGlobals.topLevelApplication.parameters;
                  //urlParams = Application.application.parameters;
                      //urlParams = sparks.components.application.parameters;
                  }
                 
                  return urlParams;
                  }
                 
                  private function RefData(event:DataGridEvent):void {
                      var dataGrid:DataGrid = event.target as DataGrid;
                      var dsColumnIndex:Number = event.columnIndex;
                      var col:DataGridColumn = dataGrid.columns[dsColumnIndex];
                      var colPO:DataGridColumn = dataGrid.columns[1];
                      var colPOItem:DataGridColumn = dataGrid.columns[5];
                      var colNotes:DataGridColumn = dataGrid.columns[23];
                      var newValue:String = dataGrid.itemEditorInstance[col.editorDataField];
                      var newValue2:String = dataGrid.itemEditorInstance[colNotes.editorDataField];   
                     
                      var dbval:String;
                      var dbvalLen:Number;
                     
                      DocCode = ArrayCollection(POFromRequest.dataProvider).getItemAt(event.rowIndex)[colPO.dataField];
                      DocItem = ArrayCollection(POFromRequest.dataProvider).getItemAt(event.rowIndex)[colPOItem.dataField ];
                      dbval = ArrayCollection(POFromRequest.dataProvider).getItemAt(event.rowIndex)[col.dataField];
                      /*
                      if (dbval.length != null)
                      {
                      dbvalLen = dbval.length;
                      }               
                      else
                      {
                      dbvalLen = 0;
                     
                      }
                      */
                     
                     
                     
                      //Alert.show("key=" +myGlobVar.KeyPress)
                     
                      if (newValue2.substr(0,3)!='P00') //this is silly code that is necessary until I sort the whole problem of audit note Dec 2010
                          //When the user hits the tab key the cursor goes to the next line and for some reason assigns PO field value to notes field value
                          //this line of code ignores in that case       
                      {
                          //if (dbval==null && newValue2!=null && newValue2!='')
                          //if (newValue2!=null || newValue2!='')
                          //if (newValue2!=null || dbvalLen>=1)
                          //{
                          Alert.show("grid value" +DocCode+":"+DocItem+"Notes:"+newValue+"colNotes:"+newValue2+"dbvnotes:"+dbval);                
                          //}
                         
                         
                      }
                      //nwCL6.UpdateFYPOAUD.send();
                     
                     
                      //tempCnt
                     
                      //if datagrid edit is true then this will fire       
                      //all the code below is checking if value from datagrid has changed
                      //as compared to value stored in source data so we don't need this in this project
                     
                      //var dsFieldName:String = event.dataField;
                      //var author:VOAuthor = event.itemRenderer.data as VOAuthor;
                      //if (newValue == author[dsFieldName])
                      //    return;
                      //get the new value for the first name or last name
                      //author[dsFieldName] = newValue;
                      //myRemote.saveData(author);
                  }

       


              ]]>
          </fx:Script>

       

          <mx:Panel title="Auditing of Purchase Order Delivery and Invoicing Status by User:" height="100%" width="100%"
                    creationComplete="initApp()" paddingTop="5" paddingBottom="5" paddingLeft="5" paddingRight="5" fontSize="15" horizontalAlign="left" color="#701193">
             
             
              <mx:Accordion id="ac"
                            width="100%"
                            height="100%"
                            selectedIndex="0"
                            historyManagementEnabled="false"  >
                 
                  <mx:Canvas width="100%" height="400"  label="Detailed Data for which a PO was issued from a Request" id="POfromReq" backgroundColor="#D2E9DA" color="#A60831">
                      <mx:Button click="GetData()" label="Press to load Data" width="305"></mx:Button>
                      <mx:FormItem label="HeaderWordWrap:" x="335">
                          <mx:CheckBox id="checkBox" selected="true" />
                      </mx:FormItem>
                      <mx:FormItem label="Include Balance of 0 Items?:" x="550">
                          <mx:CheckBox id="checkBoxZero" selected="false" change="checkBoxZero_change(event);"  />
                      </mx:FormItem>
                      <mx:FormItem label="Only Show Items > 30 Days?:" x="850">
                          <mx:CheckBox id="checkBoxAge" selected="true" change="checkBoxAge_change(event);"  />
                      </mx:FormItem>
                     
                      <mx:DataGrid id="POFromRequest"  allowMultipleSelection="true" doubleClickEnabled="true" editable="True" horizontalScrollPolicy="auto" width="3500" height="300" dataProvider="{serverData}" y="36" itemRollOut="deleteToolTip(event)" itemRollOver="createToolTip(event)" itemEditEnd="RefData(event)">
                          <mx:columns>
                              <fx:Array>
                                  <mx:DataGridColumn headerText="UserName"  editable="false" dataField="SOURCEREQUESTUSERID" width="100"/>
                                  <mx:DataGridColumn headerText="PO" dataField="PO" width="100"/>
                                  <mx:DataGridColumn headerText="Vendor" dataField="VENDOR" width="270"/>
                                  <mx:DataGridColumn headerText="Po Date" dataField="PO_Date" width="120"/>
                                  <mx:DataGridColumn headerText="Ordered QTY (A)" headerWordWrap="{checkBox.selected}" dataField="Ord_Qty" width="120" />
                                  <mx:DataGridColumn headerText="PO Item" dataField="POItem" width="100" />
                                  <mx:DataGridColumn headerText="Commodity Description" dataField="CMDDESC" width="300"/>
                                  <mx:DataGridColumn headerText="PO Unit Price" dataField="POUNITPRICE" width="120"/>
                                  <mx:DataGridColumn headerText="Org code" dataField="ACTGORG" width="100"/>
                                  <mx:DataGridColumn headerText="Receiving Document" dataField="RECEIVE_DOC_NUM" headerWordWrap="{checkBox.selected}" width="120"/>
                                  <mx:DataGridColumn headerText="Received Qty (B)" dataField="RECQTY" width="150"/>
                                  <mx:DataGridColumn headerText="Inv Document #" dataField="INVCODE" width="150"/>
                                  <mx:DataGridColumn headerText="Vendor Invoice #" dataField="VENDINV" width="150"/>
                                  <mx:DataGridColumn headerText="Invoice Status" dataField="INVSTATUS" width="150"/>
                                  <mx:DataGridColumn headerText="Invoice Due Date" dataField="DUEDATE" width="150"/>
                                  <mx:DataGridColumn headerText="Invoice Date" dataField="VENDORINVDATE" width="120"/>
                                  <mx:DataGridColumn headerText="Fund" dataField="FUNDCODE" width="80"/>
                                  <mx:DataGridColumn headerText="Account" dataField="ACCT" width="80"/>
                                  <mx:DataGridColumn headerText="Org" dataField="ORG" width="80"/>
                                  <mx:DataGridColumn headerText="Prg" dataField="PROG" width="80"/>
                                  <mx:DataGridColumn headerText="Net Invoiced (C)" headerWordWrap="{checkBox.selected}" dataField="NETINVD" width="130"/>
                                  <mx:DataGridColumn headerText="Balance not Received (A-B)" headerWordWrap="{checkBox.selected}" dataField="BALNOTRECD" width="175"/>
                                  <mx:DataGridColumn headerText="Balance not Invoiced (B-C)" headerWordWrap="{checkBox.selected}" dataField="BALNOTINVD" width="175"/>
                                  <mx:DataGridColumn headerText="Notes" headerWordWrap="{checkBox.selected}" dataField="NOTES" width="300"/>
                              </fx:Array>
                          </mx:columns>
                      </mx:DataGrid>
                      <mx:List id="square"  visible="false" x="298" y="266"></mx:List>
                      <mx:Button click="POSendEmailAP()" label="Press to copy selected items to body of email template" width="478" y="344"></mx:Button>
                     
                     
                  </mx:Canvas>
                  <mx:Canvas width="100%" height="400"  label="Direct PO Details: PO not created from request" id="DirectPO" backgroundColor="#D2E9DA" color="#A60831">
                      <mx:Button click="GetData3()" label="Press to load Data" width="305"></mx:Button>
                      <mx:FormItem label="HeaderWordWrap:" x="335">
                          <mx:CheckBox id="checkBox3" selected="true" />
                      </mx:FormItem>
                      <mx:FormItem label="Include Balance of 0 Items?:" x="550">
                          <mx:CheckBox id="checkBoxZero3" selected="false" change="checkBoxZero3_change(event);"  />
                      </mx:FormItem>
                      <mx:FormItem label="Only Show Items > 30 Days?:" x="850">
                          <mx:CheckBox id="checkBoxAge2" selected="true" change="checkBoxAge2_change(event);"  />
                      </mx:FormItem>
                     
                      <mx:DataGrid id="DirectPOGrid"  allowMultipleSelection="true" horizontalScrollPolicy="auto" width="3500" height="300" dataProvider="{serverData3}" y="36" itemRollOut="deleteToolTip2(event)" itemRollOver="createToolTip2(event)" itemEditEnd="RefData(event)">
                          <mx:columns>
                              <fx:Array>
                                  <mx:DataGridColumn  headerText="PossibleUserName" dataField="PossibleSourceUserid" width="160"/>
                                  <mx:DataGridColumn headerText="PO" dataField="PO" width="100"/>
                                  <mx:DataGridColumn headerText="Vendor" dataField="VENDOR" width="270"/>
                                  <mx:DataGridColumn headerText="Po Date" dataField="PO_Date" width="120"/>
                                  <mx:DataGridColumn headerText="Ordered QTY (A)" headerWordWrap="{checkBox3.selected}" dataField="Ord_Qty" width="120" />
                                  <mx:DataGridColumn headerText="PO Item" dataField="POItem" width="100" />
                                  <mx:DataGridColumn headerText="Commodity Description" dataField="CMDDESC" width="300"/>
                                  <mx:DataGridColumn headerText="PO Unit Price" dataField="POUNITPRICE" width="120"/>
                                  <mx:DataGridColumn headerText="Org code" dataField="ACTGORG" width="100"/>
                                  <mx:DataGridColumn headerText="Received Qty (B)" dataField="RECQTY" width="150"/>
                                  <mx:DataGridColumn headerText="Inv Document #" dataField="INVCODE" width="150"/>
                                  <mx:DataGridColumn headerText="Vendor Invoice #" dataField="VENDINV" width="150"/>
                                  <mx:DataGridColumn headerText="Invoice Status" dataField="INVSTATUS" width="150"/>
                                  <mx:DataGridColumn headerText="Invoice Due Date" dataField="DUEDATE" width="150"/>
                                  <mx:DataGridColumn headerText="Invoice Date" dataField="VENDORINVDATE" width="120"/>
                                  <mx:DataGridColumn headerText="Fund" dataField="FUNDCODE" width="80"/>
                                  <mx:DataGridColumn headerText="Account" dataField="ACCT" width="80"/>
                                  <mx:DataGridColumn headerText="Org" dataField="ORG" width="80"/>
                                  <mx:DataGridColumn headerText="Prg" dataField="PROG" width="80"/>
                                  <mx:DataGridColumn headerText="Net Invoiced (C)" headerWordWrap="{checkBox3.selected}" dataField="NETINVD" width="130"/>
                                  <mx:DataGridColumn headerText="Balance not Received (A-B)" headerWordWrap="{checkBox3.selected}" dataField="BALNOTRECD" width="175"/>
                                  <mx:DataGridColumn headerText="Balance not Invoiced (B-C)" headerWordWrap="{checkBox3.selected}" dataField="BALNOTINVD" width="175"/>
                                  <mx:DataGridColumn headerText="Notes" headerWordWrap="{checkBox.selected}" dataField="NOTES" width="300"/>
                              </fx:Array>
                          </mx:columns>
                      </mx:DataGrid>
                      <mx:Button id="RemoveB1" click="RemoveItems()" label="Press to Delete Highlighted Items" width="305" y="344"></mx:Button>
                      <mx:Button id="SemailB1" click="POSendEmailAPDirectStuff()" label="Press to copy selected items to body of email template" width="478" y="344" x="313"></mx:Button>
                  </mx:Canvas>
                  <mx:Canvas width="100%" height="400"  label="Direct PO Details(not yours): Items you have flagged as not belonging to you." id="DirectPONotYours" backgroundColor="#D2E9DA" color="#A60831">
                      <mx:Button click="GetData4()" label="Press to load Data" width="305"></mx:Button>
                      <mx:FormItem label="HeaderWordWrap:" x="335">
                          <mx:CheckBox id="checkBox4" selected="true" />
                      </mx:FormItem>
                     
                      <mx:DataGrid id="DirectPOGridNotMine"  allowMultipleSelection="true" horizontalScrollPolicy="auto" width="3200" height="300" dataProvider="{serverData4}" y="36" >
                          <mx:columns>
                              <fx:Array>
                                  <mx:DataGridColumn  headerText="DelUserName" dataField="DELUSERID" width="160"/>
                                  <mx:DataGridColumn headerText="PO" dataField="PO" width="100"/>
                                  <mx:DataGridColumn headerText="Vendor" dataField="VENDOR" width="270"/>
                                  <mx:DataGridColumn headerText="Po Date" dataField="PO_Date" width="120"/>
                                  <mx:DataGridColumn headerText="Ordered QTY (A)" headerWordWrap="{checkBox4.selected}" dataField="Ord_Qty" width="120" />
                                  <mx:DataGridColumn headerText="PO Item" dataField="POItem" width="100" />
                                  <mx:DataGridColumn headerText="Commodity Description" dataField="CMDDESC" width="300"/>
                                  <mx:DataGridColumn headerText="PO Unit Price" dataField="POUNITPRICE" width="120"/>
                                  <mx:DataGridColumn headerText="Org code" dataField="ACTGORG" width="100"/>
                                  <mx:DataGridColumn headerText="Received Qty (B)" dataField="RECQTY" width="150"/>
                                  <mx:DataGridColumn headerText="Inv Document #" dataField="INVCODE" width="150"/>
                                  <mx:DataGridColumn headerText="Vendor Invoice #" dataField="VENDINV" width="150"/>
                                  <mx:DataGridColumn headerText="Invoice Status" dataField="INVSTATUS" width="150"/>
                                  <mx:DataGridColumn headerText="Invoice Due Date" dataField="DUEDATE" width="150"/>
                                  <mx:DataGridColumn headerText="Invoice Date" dataField="VENDORINVDATE" width="120"/>
                                  <mx:DataGridColumn headerText="Fund" dataField="FUNDCODE" width="80"/>
                                  <mx:DataGridColumn headerText="Account" dataField="ACCT" width="80"/>
                                  <mx:DataGridColumn headerText="Org" dataField="ORG" width="80"/>
                                  <mx:DataGridColumn headerText="Prg" dataField="PROG" width="80"/>
                                  <mx:DataGridColumn headerText="Net Invoiced (C)" headerWordWrap="{checkBox4.selected}" dataField="NETINVD" width="130"/>
                                  <mx:DataGridColumn headerText="Balance not Received (A-B)" headerWordWrap="{checkBox4.selected}" dataField="BALNOTRECD" width="175"/>
                                  <mx:DataGridColumn headerText="Balance not Invoiced (B-C)" headerWordWrap="{checkBox4.selected}" dataField="BALNOTINVD" width="175"/>
                              </fx:Array>
                          </mx:columns>
                      </mx:DataGrid>
                      <mx:Button id="RemoveB2" click="RemoveItems4()" label="Press to Delete Highlighted Items" width="305" y="344"></mx:Button>
                  </mx:Canvas>
                  <mx:Canvas width="100%" height="400"  label="Email" id="EmailAP" backgroundColor="#D2E9DA" color="#A60831">
                      <mx:Label x="21" y="20" text="TO:" width="91"/>
                      <mx:TextInput  id="emailTO" text="emailTO" x="58" y="18" width="290"/>
                      <mx:Label x="356" y="20" text="CC:" width="91"/>
                      <mx:TextInput  id="emailCC" x="393" y="18" width="290"/>
                      <mx:Label x="21" y="54" text="SUBJECT:" width="91"/>
                      <mx:TextInput  id="emailSUBJECT"  text="subject" x="110" y="52" width="455"/>
                      <mx:Button click="ClearEmail()" x="790" y="52" label="Start Over"/>
                      <mx:Button click="SEmail()" x="790" y="152" label="Send Email"/>
                      <s:RichEditableText x="21" y="104" text="Body" height="244" width="566" id="myBody"/>
                  </mx:Canvas>
              </mx:Accordion>
             
          </mx:Panel>
         
      </s:Application>