001.
Imports
System.Data.OleDb
002.
Public
Class
Form1
003.
Const
DATABASE_FILE
As
String
=
"C:\busdb1.MDB"
004.
Dim
strConnection
As
String
=
"Provider=Microsoft.Jet.OLEDB.4.0;"
& _
005.
"Data Source="
& DATABASE_FILE
006.
Dim
cn
As
New
OleDbConnection(strConnection)
007.
Dim
da1
As
New
OleDbDataAdapter
008.
Dim
da
As
New
OleDbDataAdapter
009.
Dim
eda
As
New
OleDbDataAdapter
010.
Dim
neda
As
New
OleDbDataAdapter
011.
Dim
sda
As
New
OleDbDataAdapter
012.
Dim
ds
As
New
DataSet
013.
Dim
ds2
As
New
DataSet
014.
015.
Dim
WithEvents
objCurrencyManager
As
CurrencyManager
016.
017.
Private
Sub
Form1_Load(
ByVal
sender
As
System.
Object
,
ByVal
e
As
System.EventArgs)
Handles
MyBase
.Load
018.
Dim
strSQL
As
String
=
"SELECT * FROM tblProvince"
019.
da.SelectCommand =
New
OleDbCommand(strSQL, cn)
020.
021.
strSQL =
"SELECT * FROM Route"
022.
da1.SelectCommand =
New
OleDbCommand(strSQL, cn)
023.
024.
025.
026.
027.
028.
029.
030.
031.
032.
033.
Try
034.
035.
036.
da.Fill(ds,
"tblProvince"
)
037.
da1.Fill(ds,
"Route"
)
038.
039.
040.
Catch
ex
As
OleDbException
041.
MsgBox(ex.Message)
042.
Exit
Sub
043.
End
Try
044.
045.
046.
Dim
parentColumn
As
DataColumn = ds.Tables(
"tblProvince"
).Columns(
"ProvinceID"
)
047.
Dim
childColumn
As
DataColumn = ds.Tables(
"Route"
).Columns(
"ProvinceID"
)
048.
Dim
relation
As
DataRelation =
New
DataRelation(
"tblProvinceRoute"
, parentColumn, childColumn)
049.
050.
ds.Relations.Add(relation)
051.
052.
ListBox1.DataSource = ds.Tables(
"tblProvince"
)
053.
ListBox1.DisplayMember =
"ProvinceName"
054.
055.
End
Sub
056.
057.
058.
Private
Sub
ListBox1_SelectedIndexChanged(
ByVal
sender
As
System.
Object
,
ByVal
e
As
System.EventArgs)
Handles
ListBox1.SelectedIndexChanged
059.
Dim
iCurrentIndex
As
Integer
= ListBox1.SelectedIndex
060.
Dim
rows()
As
DataRow = ds.Tables(
"tblProvince"
).Rows(iCurrentIndex).GetChildRows(
"tblProvinceRoute"
)
061.
062.
063.
ListBoxRoute.Items.Clear()
064.
ListBoxall.Items.Clear()
065.
RouthBox.Items.Clear()
066.
FareBox.Items.Clear()
067.
DistanceBox.Items.Clear()
068.
TimeBox.Items.Clear()
069.
FromBKKBox.Items.Clear()
070.
ToBKKBox.Items.Clear()
071.
072.
For
Each
row
As
DataRow
In
rows
073.
ListBoxRoute.Items.Add(row(
"RouteName"
).ToString & ControlChars.Tab)
074.
075.
ListBoxall.Items.Add(row(
"Fare"
).ToString & ControlChars.Tab)
076.
FareBox.Items.Add(row(
"Distance"
).ToString & ControlChars.Tab)
077.
DistanceBox.Items.Add(row(
"Time"
).ToString)
078.
TimeBox.Items.Add(row(
"FromBKK"
).ToString)
079.
FromBKKBox.Items.Add(row(
"ToBKK"
).ToString)
080.
ToBKKBox.Items.Add(row(
"ToBKK"
).ToString)
081.
082.
objCurrencyManager_PositionChanged(
Nothing
,
Nothing
)
083.
Next
084.
085.
086.
End
Sub
087.
088.
089.
090.
Private
Sub
EditTool_Click(
ByVal
sender
As
System.
Object
,
ByVal
e
As
System.EventArgs)
Handles
Edittool.Click
091.
Dim
newForm
As
New
Password
092.
newForm.Show()
093.
Me
.Hide()
094.
End
Sub
095.
096.
Private
Sub
NorthMenu_Click(
ByVal
sender
As
System.
Object
,
ByVal
e
As
System.EventArgs)
Handles
NorthMenu.Click
097.
Dim
NorthForm
As
New
North
098.
NorthForm.Show()
099.
End
Sub
100.
101.
Private
Sub
NortheastMenu_Click(
ByVal
sender
As
System.
Object
,
ByVal
e
As
System.EventArgs)
Handles
NortheastMenu.Click
102.
Dim
NortheastForm
As
New
Northeast
103.
NortheastForm.Show()
104.
End
Sub
105.
106.
Private
Sub
East_Click(
ByVal
sender
As
System.
Object
,
ByVal
e
As
System.EventArgs)
Handles
East.Click
107.
Dim
EastForm
As
New
East
108.
EastForm.Show()
109.
End
Sub
110.
111.
Private
Sub
South_Click(
ByVal
sender
As
System.
Object
,
ByVal
e
As
System.EventArgs)
Handles
South.Click
112.
Dim
SouthForm
As
New
South
113.
SouthForm.Show()
114.
End
Sub
115.
116.
Private
Sub
RefToolStripMenuItem_Click(
ByVal
sender
As
System.
Object
,
ByVal
e
As
System.EventArgs)
Handles
RefToolStripMenuItem.Click
117.
Me
.Refresh()
118.
End
Sub
119.
Private
Sub
btnMoveFirst_Click(
ByVal
sender
As
System.
Object
,
ByVal
e
As
System.EventArgs)
120.
objCurrencyManager.Position = 0
121.
End
Sub
122.
123.
Private
Sub
btnMovePrevious_Click(
ByVal
sender
As
System.
Object
,
ByVal
e
As
System.EventArgs)
124.
objCurrencyManager.Position -= 1
125.
126.
End
Sub
127.
128.
129.
Private
Sub
btnMoveNext_Click(
ByVal
sender
As
System.
Object
,
ByVal
e
As
System.EventArgs)
130.
131.
objCurrencyManager.Position += 1
132.
133.
End
Sub
134.
135.
Private
Sub
btnMoveLast_Click(
ByVal
sender
As
System.
Object
,
ByVal
e
As
System.EventArgs)
136.
objCurrencyManager.Position = objCurrencyManager.Count - 1
137.
End
Sub
138.
139.
Private
Sub
objCurrencyManager_PositionChanged(
ByVal
sender
As
Object
,
ByVal
e
As
System.EventArgs)
Handles
objCurrencyManager.PositionChanged
140.
141.
lblRecordPosition.Text =
"จำนวนเส้นทาง "
& RouthBox.Items.Count &
" เส้นทาง"
142.
143.
End
Sub
144.
145.
Private
Sub
Timer1_Tick(
ByVal
sender
As
System.
Object
,
ByVal
e
As
System.EventArgs)
Handles
Timer1.Tick
146.
147.
Label10.Text = DateTime.Now.ToString()
148.
149.
End
Sub
150.
151.
Private
Sub
ExitToolStripMenuItem_Click(
ByVal
sender
As
System.
Object
,
ByVal
e
As
System.EventArgs)
152.
End
153.
End
Sub
154.
155.
Private
Sub
ToolStripMenuItem_Click(
ByVal
sender
As
System.
Object
,
ByVal
e
As
System.EventArgs)
Handles
ToolStripMenuItem.Click
156.
PrintDialog1.ShowDialog()
157.
End
Sub
158.
End
Class