<?xml version="1.0" encoding="utf-8"?>
<s:BorderContainer xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
width="374" height="205" borderVisible="true" backgroundColor="#F6F6F6" cornerRadius="7"
dropShadowVisible="true" creationComplete="bordercontainer1_creationCompleteHandler(event)">
<s:layout>
<s:VerticalLayout horizontalAlign="center" verticalAlign="middle" paddingBottom="5" paddingLeft="5" paddingRight="5" paddingTop="5"/>
</s:layout>
<fx:Declarations>
</fx:Declarations>
<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.controls.Alert;
import mx.events.FlexEvent;
private var dbFile:File = File.applicationDirectory.resolvePath("Example4_Files/test.sqlite");
private var sampleDB:SQLConnection;
/** Event Listener for the creationComplete Event
*
* Displays Records in the Database, which have got
* accumulated over time due to subsequent calls to
* the webservice
*/
protected function bordercontainer1_creationCompleteHandler(event:FlexEvent):void
{
sampleDB = new SQLConnection();
sampleDB.addEventListener(SQLEvent.OPEN, function():void
{
var stmt1:SQLStatement = new SQLStatement();
stmt1.sqlConnection = sampleDB;
stmt1.text = "SELECT * from sampletable ORDER BY sampleDataID DESC";
stmt1.addEventListener(SQLEvent.RESULT, function():void
{
dgSample.dataProvider = new ArrayCollection(stmt1.getResult().data);
sampleDB.close();
});
stmt1.addEventListener(SQLErrorEvent.ERROR, function():void
{
sampleDB.close();
Alert.show("Error in retreiving from Database");
});
stmt1.execute();
});
sampleDB.open(dbFile);
}
/** Event Listener for the ButtonClick Event
*
* Deletes all rows in the Database
*/
protected function button1_clickHandler(event:MouseEvent):void
{
sampleDB = new SQLConnection();
sampleDB.addEventListener(SQLEvent.OPEN, function():void
{
var stmt1:SQLStatement = new SQLStatement();
stmt1.sqlConnection = sampleDB;
stmt1.text = "DELETE FROM sampletable";
stmt1.addEventListener(SQLEvent.RESULT, function():void
{
sampleDB.close();
dgSample.dataProvider = null;
});
stmt1.addEventListener(SQLErrorEvent.ERROR, function():void
{
sampleDB.close();
Alert.show("Error Clearing Database");
});
stmt1.execute();
});
sampleDB.open(dbFile);
}
]]>
</fx:Script>
<s:HGroup width="100%">
<s:Label text="Custom Alert" width="100%" color="#0C0C0C" fontFamily="Verdana" fontWeight="bold"/>
</s:HGroup>
<mx:HRule width="80%"/>
<mx:DataGrid id="dgSample" width="100%" height="100%">
<mx:columns>
<mx:DataGridColumn headerText="ID" dataField="sampleDataID" width="30"/>
<mx:DataGridColumn headerText="Data" dataField="sampleData"/>
</mx:columns>
</mx:DataGrid>
<s:HGroup width="100%" verticalAlign="middle" horizontalAlign="center" gap="10">
<s:Button label="Clear DB" click="button1_clickHandler(event)"/>
<s:Button label="Close" click="{this.parent.removeChild(this);}"/>
</s:HGroup>
</s:BorderContainer>