Tuesday, March 22, 2011

Dynamic Create XML and Chart..Passing Data


<?xml version="1.0" encoding="utf-8"?>
<mx:Application creationComplete="bar.visible=false;" xmlns:mx="http://www.adobe.com/2006/mxml"  backgroundColor="#ffffff" layout="absolute" width="1345" xmlns:ns1="com.flexer.*">
<mx:Script>
<![CDATA[
import mx.utils.ObjectUtil;
import mx.controls.Label;
import mx.managers.PopUpManager;
import mx.controls.Alert;
[Bindable]
public var dataxml:XML;
[Bindable]
public var datalist:XML=new XML(<data/>); 
[Bindable]
public var xxx:XMLList;

private var data2xml:XML;
private var data2list:XML=new XML(<data/>);
private var xxx2:XMLList;
    [Bindable]
public var labstring:String;
    public function add():void
    { 
   
dataxml=new XML(<employee/>);
dataxml.@id=tex1.text;
dataxml.@age=tex2.text;
dataxml.@add=tex3.text;
dataxml.@city=tex4.text;
dataxml.@state=tex5.text;
                    trace(dataxml);
datalist.appendChild(dataxml);
xxx=new XMLList(datalist.children());

data.dataProvider=xxx;
   Alert.show("DATAS SEND SUCCESSFULLY");

    }
    public function clr():void
    {
    tex1.text=''
    tex2.text=''
    tex3.text=''
    tex4.text=''
    tex5.text=''
   
    }
    var re1:Report1;
    public var nameStr:String;
    public function search(event:MouseEvent):void
{
vb.removeAllChildren();
if(datalist.employee.length()<1)
{
Alert.show("List Empty");
}
  
for(var j:int=0;j<datalist.employee.length();j++)
{
if(searchT.text==datalist.employee[j].@id)
{

/* tex1.text=datalist.employee[j].@id;
   tex2.text=datalist.employee[j].@age;
tex3.text=datalist.employee[j].@add;
tex4.text=datalist.employee[j].@city;
tex5.text=datalist.employee[j].@state; */

re1=new Report1();
re1.str1=datalist.employee[j].@id;
re1.str2=datalist.employee[j].@age;
re1.str3=datalist.employee[j].@add;
re1.str4=datalist.employee[j].@city;
re1.str5=datalist.employee[j].@state;
vb.addChild(re1);
}

else
{
//Alert.show("Nothing Found");
}
    
  }
 
  }
  public function add2():void
    { 
   
data2xml=new XML(<employee/>);
data2xml.@ip=tex11.text;
data2xml.@sys=tex12.text;
data2xml.@pass=tex13.text;
data2xml.@repas=tex14.text;

data2list.appendChild(data2xml);
xxx2=new XMLList(data2list.children());

data1.dataProvider=xxx2;
Alert.show("DATAS SEND SUCCESSFULLY");

    }
     public function clr2():void
    {
    tex11.text=''
    tex12.text=''
    tex13.text=''
    tex14.text=''
       
    }
    var re2:Report2;
     public function search2():void
{
vb.removeAllChildren();
if(data2list.employee.length()<1)
{
Alert.show("List Empty");
}
  
for(var j:int=0;j<data2list.employee.length();j++)
{
if(searchTT.text==data2list.employee[j].@ip)
{
/* tex11.text=data2list.employee[j].@ip;
   tex12.text=data2list.employee[j].@sys;
tex13.text=data2list.employee[j].@pass;
tex14.text=data2list.employee[j].@repas; */

re2=new Report2();
re2.str11=data2list.employee[j].@ip;
re2.str12=data2list.employee[j].@sys;
re2.str13=data2list.employee[j].@pass;
re2.str14=data2list.employee[j].@repas;

vb.addChild(re2);
}
else
{
//Alert.show("Nothing Found");
}
    
  }
 
  }
  public function show():void
  {
  can1.visible=false;
  can2.visible=true;
  }
  public function show2():void
  {
  can1.visible=true;
  can2.visible=false;
  }
  public function login():void
  {
   
  if(usern.text=='demo'&&passw.text=='demo')
  {
   
   can1.visible=true;
   pan.removeChild(log);
   bar.visible=true;
  }
  }
  public function remo():void
  {
  vb.removeAllChildren();
  }
  
  public function allr():void
  {
  vb2.removeAllChildren();
  //Alert.show('test');
 
    for(var k:int=0;k<datalist.children().length();k++)
   {
    var re1:Report1=new Report1();
    re1.str1=datalist.children()[k].@id;
    re1.str2=datalist.children()[k].@age;
    re1.str3=datalist.children()[k].@add;
    re1.str4=datalist.children()[k].@city;
    re1.str5=datalist.children()[k].@state;
    vb2.addChild(re1);
   
   
   } 
  
    }
     var k:int=0;
     var m:int=0;
     var Count:int=0;
     var chkStr:String;
     public var info:information;
     public function slidNext():void
{
  if(k==datalist.children().length()-0) 
   {
    k=0;
    trace('This is for Next');
       info=new information();
    HB.addChild(info);
   }
   else
   {
    re1=new Report1();
    re1.str1=datalist.children()[k].@id;
    re1.str2=datalist.children()[k].@age;
    re1.str3=datalist.children()[k].@add;
    re1.str4=datalist.children()[k].@city;
    re1.str5=datalist.children()[k].@state;
    HB.addChild(re1);
    k=k+1;
   } 
}
   var all:Allrepo;
   public function AdmNext():void
   {
   if(m==data2list.children().length()-0) 
   {
    m=0;
    all=new Allrepo();
    HB.addChild(all);
    trace('test');
   }  
   else
   {
       re2=new Report2();
    re2.str11=data2list.children()[m].@ip;
    re2.str12=data2list.children()[m].@sys;
    re2.str13=data2list.children()[m].@pass;
    re2.str14=data2list.children()[m].@repas;
    HB.addChild(re2);
    m=m+1;
     }    
   }
   public function AdmPrve():void
     {
   m=m-1;
   if(m==data2list.children().length()-0) 
   {
   
    trace('test');
   }  
   else
   {
       re2=new Report2();
    re2.str11=data2list.children()[m].@ip;
    re2.str12=data2list.children()[m].@sys;
    re2.str13=data2list.children()[m].@pass;
    re2.str14=data2list.children()[m].@repas;
    HB.addChild(re2);
   
     }    
      }    
    
     public function slidPrev():void
  {
  k=k-1;
  if(k==datalist.children().length()-0) 
   {
   
    trace('This is for Prev');   
   }
   else
   {
    re1=new Report1();
    re1.str1=datalist.children()[k].@id;
    re1.str2=datalist.children()[k].@age;
    re1.str3=datalist.children()[k].@add;
    re1.str4=datalist.children()[k].@city;
    re1.str5=datalist.children()[k].@state;
    HB.addChild(re1);
   
   }      
    }
      
      
     public function delt():void
{
for(var j:int=0;j<datalist.employee.length();j++)
{
    if(searchT.text==datalist.employee[j].@id)
   {
   
   delete datalist.children()[j];
   xxx=new XMLList(datalist.children());
   data.dataProvider=xxx;
   vb.removeAllChildren();
   } 
 }
   
}
public function delt2():void
{
for(var j:int=0;j<data2list.employee.length();j++)
{
    if(searchTT.text==data2list.employee[j].@ip)
   {
   
   delete data2list.children()[j];
   xxx2=new XMLList(data2list.children());
       data.dataProvider=xxx;
   vb.removeAllChildren();  
   } 
 }
   
}
   public function tes():void
   {
   Alert.show(xxx);
   } 
   public var cha:PopupChart=new PopupChart();
    public function tes1():void
   {
   
   PopUpManager.addPopUp(cha,this,true);
   PopUpManager.centerPopUp(cha);
   /* cha.pie.dataProvider=xxx;
   cha.PS.xField=xxx.@age;
   cha.PS.yField=xxx.@id;
   cha.PS.labelField=xxx.@city;
   trace(cha.pie.dataProvider); */
   } 
]]>
</mx:Script>






<mx:Iris id="irisOut" duration="1000" showTarget="true"/>
    <mx:Iris id="irisIn" duration="1000" showTarget="false"/>


   <mx:Panel id="pan"  x="406" y="207" width="579" height="446" layout="absolute" horizontalScrollPolicy="auto" includeInLayout="true" paddingBottom="30" borderThickness="5"  cornerRadius="15" >
   <mx:Canvas id="can1" visible="false" backgroundColor="#ffffff" height="100%" width="100%">
   <mx:Label text="User Account" textDecoration="underline" fontSize="14" fontWeight="bold" x="195" y="30"/>
  
      <mx:Form visible="true" x="95" y="84" height="184" width="410.5" fontWeight="bold">
      <mx:FormItem label="ID" fontWeight="bold" fontSize="12">
      <mx:TextInput id="tex1"/>
      </mx:FormItem>
      <mx:FormItem label="Age" fontWeight="bold" width="290" fontSize="12">
      <mx:TextInput id="tex2" width="163"/>
      </mx:FormItem>
      
      <mx:FormItem label="Address" fontWeight="bold" fontSize="12">
      <mx:TextInput id="tex3"/>
      </mx:FormItem>
      <mx:FormItem label="City" fontWeight="bold" fontSize="12">
      <mx:TextInput id="tex4"/>
      </mx:FormItem>
      <mx:FormItem label="State" fontWeight="bold" fontSize="12">
      <mx:TextInput id="tex5"/>
      </mx:FormItem>
      </mx:Form>
   
      
      
      <mx:HBox x="60" y="368" width="480" height="28">
         <mx:Button id="but1" click="add()" label="Save"/>
         <mx:Button label="Delete" click="delt()"/>
         <mx:Button id="but2" click="clr()" label="Clear"/>
         <mx:TextInput id="searchT" width="137"/>
         <mx:Button click="search(event)" label="Search"/>
         <mx:Label text="*ID only."/>
      </mx:HBox>
      <mx:DataGrid   id="data"  width="559" height="396" visible="{cb1.selected}"
            showEffect="{irisIn}" hideEffect="{irisOut}" borderStyle="outset"  alpha="1.0" dropShadowColor="black" dropShadowEnabled="true" shadowDirection="right" shadowDistance="5" editable="true" fontWeight="bold" x="0" y="10">
         <mx:columns>
            <mx:DataGridColumn headerText="ID" dataField="@id"/>
            <mx:DataGridColumn headerText="Age" dataField="@age"/>
            <mx:DataGridColumn headerText="Address" dataField="@add"/>
            <mx:DataGridColumn headerText="City" dataField="@city"/>
            <mx:DataGridColumn headerText="State" dataField="@state"/>
         </mx:columns>
      </mx:DataGrid>
       </mx:Canvas>
       
       
       
       
       
      <mx:Canvas id="can2" visible="false" backgroundColor="#ffffff" height="100%" width="100%">
   <mx:Label text="Admin Account" textDecoration="underline" fontSize="14" fontWeight="bold" x="195" y="30"/>
      <mx:Form visible="true" x="69" y="84" height="184" width="410.5" fontWeight="bold">
      <mx:FormItem label="IP" fontWeight="bold" fontSize="12">
      <mx:TextInput id="tex11"/>
      </mx:FormItem>
      <mx:FormItem label="Sys no" fontWeight="bold" width="290" fontSize="12">
      <mx:TextInput id="tex12" width="163"/>
      </mx:FormItem>
      
      <mx:FormItem label="Password" fontWeight="bold" fontSize="12">
      <mx:TextInput id="tex13"/>
      </mx:FormItem>
      <mx:FormItem label="Repassword" fontWeight="bold" fontSize="12">
      <mx:TextInput id="tex14"/>
      </mx:FormItem>
      </mx:Form>
   
      
      
      <mx:HBox  x="60" y="368" width="480" height="28">
         <mx:Button id="but11" click="add2()" label="Save"/>
         <mx:Button label="Delete" click="delt2()"/>
         <mx:Button id="but12" click="clr2()" label="Clear"/>
         <mx:TextInput id="searchTT" width="137"/>
         <mx:Button click="search2()" label="Search"/>
         <mx:Label text="*IP only."/>
      </mx:HBox>
      <mx:DataGrid   id="data1"  width="559" height="396" visible="{cb1.selected}"
            showEffect="{irisIn}" hideEffect="{irisOut}" borderStyle="outset"  alpha="1.0" dropShadowColor="black" dropShadowEnabled="true" shadowDirection="right" shadowDistance="5" editable="true" fontWeight="bold" x="0" y="10">
         <mx:columns>
            <mx:DataGridColumn headerText="IP" dataField="@ip"/>
            <mx:DataGridColumn headerText="Sys no" dataField="@sys"/>
            <mx:DataGridColumn headerText="Password" dataField="@pass"/>
            <mx:DataGridColumn headerText="Repassword" dataField="@repas"/>
         </mx:columns>
      </mx:DataGrid>
       </mx:Canvas>
      <mx:Canvas id="log" x="0" y="1" width="100%" height="100%" borderStyle="solid" backgroundColor="#FFFFFF">
         <mx:Form x="159" y="113" width="333" height="100">
         <mx:FormItem label="User name" fontWeight="bold" fontSize="13">
         <mx:TextInput id="usern"/>
         </mx:FormItem>
         <mx:FormItem  label="Password" fontWeight="bold" fontSize="13">
         <mx:TextInput id="passw"/>
         </mx:FormItem>
         </mx:Form>
         <mx:Button click="login()" x="275" y="221" label="Submit"/>
      </mx:Canvas>
   </mx:Panel>
   <mx:ApplicationControlBar id="bar" width="579" height="31" cornerRadius="15" fillColors="black" barColor="black" fillAlphas="[0.55, 0.54]" alpha="1.0" color="black" x="406" y="207">
      <mx:Button click="show2()" label="User"/>
      <mx:Button click="show()" label="Admin"/>
      <mx:HRule shadowColor="gray" strokeColor="gray" alpha="0.0" width="43" height="2"/>
      <mx:CheckBox  id="cb1" label="View Full Details" selected="false" color="#080808" fontWeight="bold"/>
     
   </mx:ApplicationControlBar>
   <mx:VBox horizontalScrollPolicy="off" id="vb" x="134" y="221" height="142" width="260" backgroundColor="#E0DCDC">
   </mx:VBox>
   <mx:Button click="remo()" x="134" y="191" label="Remove All"/>
   <mx:Button click="allr()" x="134" y="371" label="View All"/>
   <mx:VBox horizontalScrollPolicy="off" id="vb2" height="432" width="260" backgroundColor="#E0DCDC" x="134" y="397">
   </mx:VBox>

  <mx:Canvas id="main" x="993" y="221" width="288" height="200">
    <mx:Canvas id="HB" verticalScrollPolicy="off" horizontalScrollPolicy="off" x="10" y="45" width="260" height="145" backgroundColor="#D6D3D3" borderStyle="solid">
       <mx:Label x="37.5" y="91" text="Click the Button for User Details" height="18"/>
       <!--<mx:Button click="slidPrev()" x="103" y="61" label="Click"/>-->
    </mx:Canvas>
    <mx:HBox id="H1" x="10" y="14" width="94" height="23">
       <mx:Button id="prev" click="slidPrev()" label="&lt;"/>
       <mx:Button id="next" click="slidNext()" label="&gt;"/>
    </mx:HBox>
    <mx:HBox id="H2" visible="false" x="10" y="14" width="94" height="23">
       <mx:Button id="Aprev" click="AdmPrve()"  label="&lt;"/>
       <mx:Button id="Anext" click="AdmNext()" label="&gt;"/>
    </mx:HBox>
  </mx:Canvas>
  <mx:Button click="tes()" x="640" y="93" label="Button"/>
  <mx:Button click="tes1()" x="736" y="93" label="Chart"/>


</mx:Application>








DEMO HERE :(user Name:demo,Password:demo)