<?xml version="1.0" encoding="utf-8"?>
xmlns:ios="com.pialabs.eskimo.skins.mobile.ios.*"
initialize="initdb()" title="Agregar Gasto">
<fx:Declarations>
<fx:Component className="AlertMsg">
<s:SkinnablePopUpContainer x="70" y="300">
<s:TitleWindow title="" close="close()">
<s:VGroup horizontalAlign="center" width="100%" >
<s:Label text="Datos agregados con éxito"/>
<s:Button label="OK" click="close()"/>
</s:VGroup>
</s:TitleWindow>
</s:SkinnablePopUpContainer>
</fx:Component>
<fx:Component className="AlertMsg2">
<s:SkinnablePopUpContainer x="70" y="300">
<s:TitleWindow title="" close="close()">
<s:VGroup horizontalAlign="center" width="100%" >
<s:Label text="Sincronizaión realizada con éxito"/>
<s:Button label="OK" click="close()"/>
</s:VGroup>
</s:TitleWindow>
</s:SkinnablePopUpContainer>
</fx:Component>
<fx:Component className="AlertMsg3">
<s:SkinnablePopUpContainer x="70" y="300">
<s:TitleWindow title="" close="close()">
<s:VGroup horizontalAlign="center" width="100%" >
<s:Label text="Guardado de datos realizado con exito"/>
<s:Button label="OK" click="close()"/>
</s:VGroup>
</s:TitleWindow>
</s:SkinnablePopUpContainer>
</fx:Component>
<s:ArrayCollection id="suppliesAC">
<fx:Object name="Alimentos"/>
<fx:Object name="Transporte" />
<fx:Object name="Hotel" />
<fx:Object name="Entretenimiento" />
<fx:Object name="Telefono" />
<fx:Object name="Internet"/>
<fx:Object name="Herramientas"/>
<fx:Object name="Equipo"/>
<fx:Object name="Propinas"/>
<fx:Object name="Otros"/>
</s:ArrayCollection>
</fx:Declarations>
<fx:Script>
<![CDATA[
import org.osmf.media.URLResource;
import spark.components.calendarClasses.DateSelectorDisplayMode;
private var loader:URLLoader = new URLLoader();
private var dayArray:Array = new Array(
"Sunday","Monday","Tuesday",
"Wednesday","Thursday","Friday","Saturday");
import mx.collections.ArrayCollection;
import mx.rpc.http.mxml.HTTPService;
public var conecta:SQLConnection=new SQLConnection();
public function initdb():void{
var lugar_origen:File= File.applicationDirectory.resolvePath("assets/autosfin.db");//funcion para poner nuestra db dentro de donde lo guarda el SO
var lugar_destino:File=File.applicationStorageDirectory.resolvePath("assets/autosfin.db");
// var lugar_origen2:File= File.applicationDirectory.resolvePath("assets/employees.xml");//funcion para poner nuestra db dentro de donde lo guarda el SO
// var lugar_destino2:File=File.applicationStorageDirectory.resolvePath("assets/employees.xml");
var d2:Date = new Date();
fecha.text = d2.fullYear + "-" + int(d2.month + 1) + "-" + d2.date;
loader.dataFormat = URLLoaderDataFormat.BINARY;
loader.addEventListener(Event.COMPLETE, onLoad);
//concepto.text=File.applicationStorageDirectory.nativePath;
if(!lugar_destino.exists){
lugar_origen.copyTo(lugar_destino);
}
var autosfin:File=lugar_destino;
conecta.open(autosfin);
//inserta_gasto();
// if(!lugar_destino2.exists){
// lugar_origen2.copyTo(lugar_destino2);
//}
//var xmlfile:File=lugar_destino2;
//inserta_gasto();
}
protected function button1_activateHandler(event:Event):void
{
supplyList.visible=true;// TODO Auto-generated method stub
contenedor.visible=true;
}
private function onLoad(event:Event):void {
saveLocally(fileName, loader.data);//call the saveLocally function; loader.data has the bytes of the loaded resource
}
private function saveLocally(fileName:String, data:ByteArray):void {
//create a file under the application storage directory using the filename argument
var file:File = File.applicationStorageDirectory.resolvePath("assets/"+fileName);
if (file.exists)
file.deleteFile(); //delete it if exists
//create a file stream to be able to write the content of the file
var fileStream:FileStream = new FileStream();
//open the file stream and set for Write
fileStream.open(file, FileMode.WRITE);
//writes the bytes
fileStream.writeBytes(data, 0, data.length);
//close the stream
fileStream.close();
//display the path of the saved resources
}
private function saveResource():void {
new AlertMsg3().open(this, false);
guardar_local.enabled=false;
pruebita.text=File.applicationStorageDirectory.nativePath;
//var lugar_origenxml:File=File.applicationStorageDirectory.resolvePath("assets/employees.xml");
//var lugar_destinoxml:File=File.applicationDirectory.resolvePath("assets/employees.xml");
//lugar_origenxml.copyTo(lugar_destinoxml);
}
public function inserta_gasto():void{
var inserta_gasto:SQLStatement =new SQLStatement();
inserta_gasto.sqlConnection=conecta;
inserta_gasto.text= "INSERT INTO gastos (idgasto, concepto, fecha, monto, observaciones,recurso) values (NULL,'" + concepto.text + "','" + fecha.text + "','" + monto.text + "','" + observaciones.text + "','" + recurso.text + "')";
inserta_gasto.execute ();
new AlertMsg().open(this, false);
boton_agregar.enabled=false;
concepto.enabled=false;
fecha.enabled=false;
monto.enabled=false;
observaciones.enabled=false;
//var resultado_gasto:Array =inserta_gasto.getResult().data;
//texto_gasto.dataProvider=resultado_gasto[0];
}
public function regresar():void
{
navigator.pushView(views.gastos_autosmapHomeView);
}
protected function button1_clickHandler(event:MouseEvent):void
{
var inserta_datos : HTTPService = new HTTPService();
inserta_datos.method = "POST";
var parameters : Object = new Object();
parameters ["concepto"] = concepto.text;
parameters ["from"] = fecha.text;
parameters ["monto"] = monto.text;
parameters ["observaciones"] = observaciones.text;
parameters ["recurso"] = recurso.text;
inserta_datos.send(parameters) ;
new AlertMsg2().open(this, false);
boton_sincronizar.enabled=false;
concepto.enabled=false;
fecha.enabled=false;
monto.enabled=false;
observaciones.enabled=false;
//saveResource();
//var fr:FileReference= new FileReference();
//fr.download(lugar_origen3,"employees.xml");
//var lugar_origen4:File=File.applicationStorageDirectory.resolvePath("assets/employees.xml");
//var lugar_destino3:File=File.applicationDirectory.resolvePath("assets/employees.xml");
//lugar_origen4.copyTo(lugar_destino3);
// TODO Auto-generated method stub
}
protected function ds1_changeHandler(e:Event):void
{
// TODO Auto-generated method stub
var d:Date = new Date(e.currentTarget.selectedDate);
fecha.text = d.fullYear + "-" + int(d.month + 1) + "-" + d.date;
}
public function cambia_vista_gasto():void{
navigator.pushView(views.agregar_gastoHomeView);
}
]]>
</fx:Script>
<s:actionContent>
<s:Button label="Regresar" click="regresar()"/>
<s:Button label="+" click="cambia_vista_gasto()" fontSize="19"/>
</s:actionContent>
<s:Label x="117" y="403" fontSize="20" text="Observaciones:"/>
<s:Label x="117" y="317" fontSize="20" text="Monto:"/>
<s:Label x="112" y="146" fontSize="20" text="Fecha"/>
<s:Label x="0" y="17" fontSize="20" text="Concepto"/>
<s:Button id="boton_agregar" x="53" y="487" width="106" height="56" label="Agregar" click="inserta_gasto()"
enabled="true"/>
<s:TextInput id="concepto" x="204" y="70" width="159" change="button1_activateHandler(event)"
<s:TextInput id="fecha" x="196" y="312" width="191" enabled="true" visible="false" />
<s:TextInput id="monto" x="202" y="316" width="154" enabled="true" fontSize="14"
returnKeyLabel="done" softKeyboardType="number" text="$"/>
<s:TextInput id="observaciones" x="262" y="389" width="264" enabled="true" fontSize="14"
returnKeyLabel="done"/>
<s:Button id="boton_sincronizar" x="203" y="487" width="122" height="56" label="Sincronizar" click="button1_clickHandler(event)"/>
<s:SpinnerListContainer id="contenedor" visible="false" x="107" y="15" width="149" height="137">
<s:SpinnerList id="supplyList" visible="false" width="100%" height="147"
dataProvider="{suppliesAC}" labelField="name"/>
</s:SpinnerListContainer>
<s:Image x="-2" y="44" width="58" height="63" source="assets/Facturas.png"/>
<s:Image x="5" y="101" source="assets/Calendario.png"/>
<s:Image x="25" y="291" source="assets/Gastos.png"/>
<s:Image x="21" y="365" source="assets/Comentario.png"/>
<s:DateSpinner id="ds1" x="86" y="128" change="ds1_changeHandler(event)"
displayMode="{DateSelectorDisplayMode.DATE}" visible="true"/>
<s:TextInput id="recurso" x="290" y="10" width="144" text="Juan Perez" visible="false"/>
<s:Button x="134" y="436" id="guardar_local" label="save locally" click="saveResource()"/>
<s:Label id="pruebita" x="161" y="10" text="Label"/>
</s:View>