| 1 |
import flash.events.*; |
|---|
| 2 |
import mx.events.*; |
|---|
| 3 |
import mx.collections.ArrayCollection; |
|---|
| 4 |
import org.libspark.snippets.controls.SQLComboBox; |
|---|
| 5 |
import org.libspark.snippets.controls.SQLTextInput; |
|---|
| 6 |
import org.libspark.snippets.controls.SQLList; |
|---|
| 7 |
import org.libspark.snippets.controls.SQLLabel; |
|---|
| 8 |
|
|---|
| 9 |
private function bOpenDB_click(event:MouseEvent):void { |
|---|
| 10 |
var file:File = new File(); |
|---|
| 11 |
var filter:FileFilter = new FileFilter("DB File", "*.db"); |
|---|
| 12 |
file.browseForOpen("Open Database file (*.db)", [filter]); |
|---|
| 13 |
file.addEventListener(Event.SELECT, dbFileSelected); |
|---|
| 14 |
} |
|---|
| 15 |
|
|---|
| 16 |
private function dbFileSelected(event:Event):void { |
|---|
| 17 |
//trace(event.target.nativePath); |
|---|
| 18 |
title = "ZIP Search - " + event.target.nativePath; |
|---|
| 19 |
GetTableList(File(event.target), SQLMode.READ); |
|---|
| 20 |
} |
|---|
| 21 |
|
|---|
| 22 |
private var connection:SQLConnection = null; |
|---|
| 23 |
|
|---|
| 24 |
private function GetTableList(file:File, mode:String):void { |
|---|
| 25 |
if (connection != null) { |
|---|
| 26 |
if (connection.connected) { |
|---|
| 27 |
try { |
|---|
| 28 |
connection.close(); |
|---|
| 29 |
} catch (error:Error) { |
|---|
| 30 |
trace("Failed:", error.message); |
|---|
| 31 |
} |
|---|
| 32 |
} |
|---|
| 33 |
} |
|---|
| 34 |
|
|---|
| 35 |
connection = new SQLConnection(); |
|---|
| 36 |
try { |
|---|
| 37 |
connection.open(file, mode); |
|---|
| 38 |
cbPrefecture.sqlConnection = connection; |
|---|
| 39 |
cbCity.sqlConnection = connection; |
|---|
| 40 |
cbArea.sqlConnection = connection; |
|---|
| 41 |
tZipCode.sqlConnection = connection; |
|---|
| 42 |
lAddress.sqlConnection = connection; |
|---|
| 43 |
lPrefecture.sqlConnection = connection; |
|---|
| 44 |
lCity.sqlConnection = connection; |
|---|
| 45 |
lArea.sqlConnection = connection; |
|---|
| 46 |
Records.sqlConnection = connection; |
|---|
| 47 |
cbPrefecture.executeQuery("select distinct prefecture as label from postcode"); |
|---|
| 48 |
lPrefecture.executeQuery("select distinct prefecture as label from postcode"); |
|---|
| 49 |
} catch (error:Error) { |
|---|
| 50 |
trace("Failed:", error.message); |
|---|
| 51 |
} |
|---|
| 52 |
} |
|---|
| 53 |
|
|---|
| 54 |
private function cbPrefecture_close(event:DropdownEvent):void { |
|---|
| 55 |
//trace("cbPrefecture close", event.target.selectedLabel); |
|---|
| 56 |
var sql:String = "select distinct city from postcode"; |
|---|
| 57 |
sql += " where prefecture == '" + cbPrefecture.selectedLabel + "'"; |
|---|
| 58 |
//trace(sql); |
|---|
| 59 |
cbCity.executeQuery(sql); |
|---|
| 60 |
cbArea.dataProvider = new Array(); |
|---|
| 61 |
tZipCode.text = ""; |
|---|
| 62 |
lAddress.dataProvider = new Array(); |
|---|
| 63 |
} |
|---|
| 64 |
|
|---|
| 65 |
private function cbCity_close(event:DropdownEvent):void { |
|---|
| 66 |
//trace("cbCity close", event.target.selectedLabel); |
|---|
| 67 |
var sql:String = "select distinct area from postcode"; |
|---|
| 68 |
sql += " where prefecture == '" + cbPrefecture.selectedLabel + "'"; |
|---|
| 69 |
sql += " and city == '" + cbCity.selectedLabel + "'"; |
|---|
| 70 |
//trace(sql); |
|---|
| 71 |
cbArea.executeQuery(sql); |
|---|
| 72 |
tZipCode.text = ""; |
|---|
| 73 |
lAddress.dataProvider = new Array(); |
|---|
| 74 |
} |
|---|
| 75 |
|
|---|
| 76 |
private function cbArea_close(event:DropdownEvent):void { |
|---|
| 77 |
//trace("cbArea close", event.target.selectedLabel); |
|---|
| 78 |
var sql:String = "select zip_code from postcode"; |
|---|
| 79 |
sql += " where prefecture == '" + cbPrefecture.selectedLabel + "' "; |
|---|
| 80 |
sql += " and city == '" + cbCity.selectedLabel + "'"; |
|---|
| 81 |
sql += " and area == '" + cbArea.selectedLabel + "'"; |
|---|
| 82 |
//trace(sql); |
|---|
| 83 |
tZipCode.executeQuery(sql); |
|---|
| 84 |
lAddress.dataProvider = new Array(); |
|---|
| 85 |
} |
|---|
| 86 |
|
|---|
| 87 |
private function lPrefecture_change(event:ListEvent):void { |
|---|
| 88 |
//trace("lPrefecture change", event.target.selectedItem); |
|---|
| 89 |
var sql:String = "select distinct city from postcode"; |
|---|
| 90 |
sql += " where prefecture == '" + lPrefecture.selectedItem + "'"; |
|---|
| 91 |
//trace(sql); |
|---|
| 92 |
lCity.executeQuery(sql); |
|---|
| 93 |
lArea.dataProvider = new Array(); |
|---|
| 94 |
tZipCode.text = ""; |
|---|
| 95 |
lAddress.dataProvider = new Array(); |
|---|
| 96 |
} |
|---|
| 97 |
|
|---|
| 98 |
private function lCity_change(event:ListEvent):void { |
|---|
| 99 |
//trace("lCity change", event.target.selectedItem); |
|---|
| 100 |
var sql:String = "select distinct area from postcode"; |
|---|
| 101 |
sql += " where prefecture == '" + lPrefecture.selectedItem + "'"; |
|---|
| 102 |
sql += " and city == '" + lCity.selectedItem + "'"; |
|---|
| 103 |
//trace(sql); |
|---|
| 104 |
lArea.executeQuery(sql); |
|---|
| 105 |
tZipCode.text = ""; |
|---|
| 106 |
lAddress.dataProvider = new Array(); |
|---|
| 107 |
} |
|---|
| 108 |
|
|---|
| 109 |
private function lArea_change(event:ListEvent):void { |
|---|
| 110 |
//trace("lArea change", event.target.selectedItem); |
|---|
| 111 |
var sql:String = "select zip_code from postcode"; |
|---|
| 112 |
sql += " where prefecture == '" + lPrefecture.selectedItem + "' "; |
|---|
| 113 |
sql += " and city == '" + lCity.selectedItem + "'"; |
|---|
| 114 |
sql += " and area == '" + lArea.selectedItem + "'"; |
|---|
| 115 |
//trace(sql); |
|---|
| 116 |
tZipCode.executeQuery(sql); |
|---|
| 117 |
lAddress.dataProvider = new Array(); |
|---|
| 118 |
} |
|---|
| 119 |
|
|---|
| 120 |
private function onZIPChange(event:KeyboardEvent):void { |
|---|
| 121 |
if (tZipCode.text == "") { |
|---|
| 122 |
lAddress.dataProvider = new Array(); |
|---|
| 123 |
return; |
|---|
| 124 |
} |
|---|
| 125 |
var sql:String = "select zip_code, prefecture, city, area from postcode"; |
|---|
| 126 |
sql += " where zip_code like '" + tZipCode.text + "%'"; |
|---|
| 127 |
sql += " order by zip_code"; |
|---|
| 128 |
//trace(sql); |
|---|
| 129 |
lAddress.delimiter = " "; |
|---|
| 130 |
lAddress.executeQuery(sql); |
|---|
| 131 |
sql = "select count(*) from postcode"; |
|---|
| 132 |
sql += " where zip_code like '" + tZipCode.text + "%'"; |
|---|
| 133 |
Records.frontCaption = "Total: "; |
|---|
| 134 |
Records.rearCaption = " record(s)"; |
|---|
| 135 |
Records.executeQuery(sql); |
|---|
| 136 |
} |
|---|
| 137 |
|
|---|
| 138 |
private function onAppClosing(event:Event):void { |
|---|
| 139 |
trace("Application closing..."); |
|---|
| 140 |
connectionClose(); |
|---|
| 141 |
} |
|---|
| 142 |
|
|---|
| 143 |
private function connectionClose():void { |
|---|
| 144 |
if (connection != null) |
|---|
| 145 |
if(connection.connected) |
|---|
| 146 |
connection.close(); |
|---|
| 147 |
} |
|---|
| 148 |
|
|---|
| 149 |
private var cbPrefecture:SQLComboBox = new SQLComboBox(); |
|---|
| 150 |
private var cbCity:SQLComboBox = new SQLComboBox(); |
|---|
| 151 |
private var cbArea:SQLComboBox = new SQLComboBox(); |
|---|
| 152 |
private var tZipCode:SQLTextInput = new SQLTextInput(); |
|---|
| 153 |
private var tAddress:SQLTextInput = new SQLTextInput(); |
|---|
| 154 |
private var lPrefecture:SQLList = new SQLList(); |
|---|
| 155 |
private var lCity:SQLList = new SQLList(); |
|---|
| 156 |
private var lArea:SQLList = new SQLList(); |
|---|
| 157 |
private var lAddress:SQLList = new SQLList(); |
|---|
| 158 |
private var Records:SQLLabel = new SQLLabel; |
|---|
| 159 |
|
|---|
| 160 |
private function init():void { |
|---|
| 161 |
addEventListener(Event.CLOSING, onAppClosing); |
|---|
| 162 |
cbPrefecture.x = 26; cbPrefecture.y = 90; cbPrefecture.width = 105; |
|---|
| 163 |
cbPrefecture.addEventListener(DropdownEvent.CLOSE, cbPrefecture_close); |
|---|
| 164 |
addChild(cbPrefecture); |
|---|
| 165 |
cbCity.x = 156; cbCity.y = 90; cbCity.width = 129; |
|---|
| 166 |
cbCity.addEventListener(DropdownEvent.CLOSE, cbCity_close); |
|---|
| 167 |
addChild(cbCity); |
|---|
| 168 |
cbArea.x = 305; cbArea.y = 90; cbArea.width = 303; |
|---|
| 169 |
cbArea.addEventListener(DropdownEvent.CLOSE, cbArea_close); |
|---|
| 170 |
addChild(cbArea); |
|---|
| 171 |
tZipCode.x = 90; tZipCode.y = 324; tZipCode.width = 80; tZipCode.height = 22; tZipCode.text = ""; |
|---|
| 172 |
tZipCode.addEventListener(KeyboardEvent.KEY_UP, onZIPChange); |
|---|
| 173 |
addChild(tZipCode); |
|---|
| 174 |
lPrefecture.x = 26; lPrefecture.y = 132; lPrefecture.width = 105; lPrefecture.height = 160; |
|---|
| 175 |
lPrefecture.addEventListener(ListEvent.CHANGE, lPrefecture_change); |
|---|
| 176 |
addChild(lPrefecture); |
|---|
| 177 |
lCity.x = 156; lCity.y = 132; lCity.width = 129; lCity.height = 160; |
|---|
| 178 |
lCity.addEventListener(ListEvent.CHANGE, lCity_change); |
|---|
| 179 |
addChild(lCity); |
|---|
| 180 |
lArea.x = 305; lArea.y = 132; lArea.width = 303; lArea.height = 160; |
|---|
| 181 |
lArea.addEventListener(ListEvent.CHANGE, lArea_change); |
|---|
| 182 |
addChild(lArea); |
|---|
| 183 |
lAddress.x = 90; lAddress.y = 360; lAddress.width = 518; lAddress.height = 150; |
|---|
| 184 |
addChild(lAddress); |
|---|
| 185 |
Records.x = 468; Records.y = 520; Records.width = 140; |
|---|
| 186 |
addChild(Records); |
|---|
| 187 |
} |
|---|