<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:hc="com.hillelcoren.components.*" xmlns:comp="com.adobe.flex.extras.controls.*"
creationComplete="initCollections(),getFecha();" height="700" layout="absolute">
<mx:Style source="miestilo.css"/>
<mx:Panel title="Control de Folios" y="0" width="712" height="539" layout="absolute" >
<mx:MenuBar id="myMenuBar" labelField="@label" x="38.25" y="10" width="615.5" height="50" dataProvider="{menuBarCollection}" itemClick="itemClickHandler(event);" />
<mx:Label x="38.25" y="92" text=" Num de Folio :"/>
<mx:TextInput x="156.25" y="90" width="81" id="folio_txt"/>
<mx:Label x="38" y="146" text="Nombre :"/>
<mx:Label x="38" y="203" text="Falla Reportada :"/>
<mx:Label x="400" y="203" text="Solucion :"/>
<mx:TextInput x="116" y="151" width="309" id="nombre_txt"/>
<mx:TextArea x="38" y="238" width="244" height="164" id="falla_txt"/>
<mx:TextArea x="389" y="238" width="241" height="164" id="solucion_txt"/>
<mx:Button x="43" y="437" label="Guardar" click="onSave()"/>
<mx:Label x="245.25" y="92" text="Fecha :"/>
<mx:Label x="436" y="153" text="Precio :"/>
<mx:Label x="582" y="153" text="$"/>
<mx:TextInput x="501" y="157" width="73" id="precio_txt"/>
<mx:DateField x="340" y="90" id="fechaPrueba" creationComplete="dateChooser_init(fechaPrueba)" initialize="init();"/>
</mx:Panel>
<mx:Script>
<![CDATA[
import mx.messaging.config.ServerConfig;
import mx.events.MenuEvent;
import mx.controls.Alert;
import mx.controls.DataGrid;
import mx.collections.*;
import mx.core.*;
import mx.events.CloseEvent;
import mx.events.CollectionEvent;
import flash.net.navigateToURL;
import mx.collections.ArrayCollection;
import mx.rpc.events.FaultEvent;
import mx.core.Application;
import mx.managers.PopUpManager;
import mx.rpc.AsyncToken;
import mx.controls.Alert;
import mx.flash.*;
import mynamespace.Completa;
import mynamespace.Servicio;
import mynamespace.*;
import mynamespace.ActiveRecords;
import flash.utils.Timer;
private var _model:Servicio = new Servicio();
private var _model2:Completa = new Completa();
[Bindable] public var _searchResult1:ArrayCollection;
[Bindable] public var tiempo:Timer = new Timer(3000,1);
[Bindable] public var _searchResult:ArrayCollection;
[Bindable] public var busqueda:ArrayCollection;
[Bindable] public var busqueda2:ArrayCollection;
[Bindable]
public var menuBarCollection:XMLListCollection;
private var menubarXML:XMLList =<>
<menuitem label="Agregar">
<menuitem label="Folio" id="folio_alta"/>
</menuitem>
<menuitem label="Modificar">
<menuitem label="Folio" id="folio_modificar"/>
</menuitem>
<menuitem label="Consultar">
<menuitem label="Folio Capturado" id="folio_consulta"/>
<menuitem label="Folio Entregado" id="folio_entregado"/>
<menuitem label="Historial" id="folio_historial"/>
</menuitem>
</>
private function initCollections():void {
menuBarCollection = new XMLListCollection(menubarXML);
}
private function itemClickHandler(event:MenuEvent):void {
if(event.item.@id =="folio_alta")
{
navigateToURL(new URLRequest("Alta_folio.html"), "_self")
}
if(event.item.@id =="folio_modificar")
{
navigateToURL(new URLRequest("Modificar_folio.html"), "_self")
}
if(event.item.@id =="folio_consulta")
{
navigateToURL(new URLRequest("Consultar_folio.html"), "_self")
}
if(event.item.@id =="folio_entregado")
{
navigateToURL(new URLRequest("Folio_entregado.html"), "_self")
}
if(event.item.@id =="folio_historial")
{
navigateToURL(new URLRequest("Historial_folio.html"), "_self")
}
}
public function getFecha():void{
var date:Date = new Date();
// fecha_alta_art.text=(date.month+1)+"/"+(date.date)+"/"+date.fullYear;
// fecha_alta_art.text=(date.fullYear)+"-"+(date.month+1)+"-"+date.date;
// fecha_ac.text=(date.fullYear)+"-"+(date.month+1)+"-"+date.date;
fecha.text=(date.month+1)+"/"+(date.date)+"/"+date.fullYear;
}
private function onSave():void
{
busqueda = ActiveRecords.Servicio.findBySql("select * from Servicio where folio='"+folio_txt.text+ "'");
busqueda.addEventListener(CollectionEvent.COLLECTION_CHANGE,function(bajas:*):void{
if(busqueda.length!=0)
{
Alert.show("El numero de folio ya existe por favor ingrese otro");
folio_txt.text="";
tiempo.addEventListener(TimerEvent.TIMER,navigate);
tiempo.start();
}
else{
busqueda2 = ActiveRecords.Completa.findBySql("select * from Completa where folio='"+folio_txt.text+ "'");
busqueda2.addEventListener(CollectionEvent.COLLECTION_CHANGE,function(bajas:*):void{
if(busqueda2.length!=0)
{
Alert.show("El numero de folio ya existe por favor ingrese otro");
folio_txt.text="";
tiempo.addEventListener(TimerEvent.TIMER,navigate);
tiempo.start();
}
else if (folio_txt.text == "")
{
Alert.show("Favor de llenar numero folio");
}
else if(precio_txt.text!="")
{
var asyncToken:AsyncToken = _model2.save();
Alert.show("Guardando datos por favor espere");
tiempo.addEventListener(TimerEvent.TIMER,navigate);
tiempo.start();
}
else
{
var asyncToken:AsyncToken = _model.save();
Alert.show("Guardando datos por favor espere");
tiempo.addEventListener(TimerEvent.TIMER,navigate);
tiempo.start();
}
});
}
});
//navigate();
}
public function navigate(e:TimerEvent):void
{
navigateToURL(new URLRequest("Alta_Folio.html"), "_self")
}
private function dateChooser_init(dt:DateField):void {
dt.dayNames=['Dom', 'Lun', 'Mar', 'Mie', 'Jue', 'Vie', 'Sab'];
dt.monthNames=[ 'Enero', 'Febrero', 'Marzo', 'Abril', 'Mayo', 'Junio',
'Julio', 'Agosto', 'Septiembre', 'Octubre',
'Noviembre', 'Diciembre'];
dt.firstDayOfWeek = 1;
// dt.formatString = "DD/MM/YYYY";
dt.formatString = "YYYY-MM-DD";
}
private function init():void {
fechaPrueba.selectedDate = new Date();
}
]]>
</mx:Script>
<mx:Binding source="{Number(folio_txt.text)}" destination="_model.Folio" />
<mx:Binding source="nombre_txt.text" destination="_model.Nombre" />
<mx:Binding source="falla_txt.text" destination="_model.Falla" />
<mx:Binding source="solucion_txt.text" destination="_model.Descripcion" />
<mx:Binding source="{Number(precio_txt.text)}" destination="_model.Total" />
<mx:Binding source="fechaPrueba.selectedDate" destination="_model.Fecha_prueba" />
<mx:Binding source="{Number(folio_txt.text)}" destination="_model2.Folio" />
<mx:Binding source="nombre_txt.text" destination="_model2.Nombre" />
<mx:Binding source="falla_txt.text" destination="_model2.Falla" />
<mx:Binding source="solucion_txt.text" destination="_model2.Descripcion" />
<mx:Binding source="{Number(precio_txt.text)}" destination="_model2.Total" />