Imports System.Data.OleDb
Public Class Form1
Const DATABASE_FILE As String = "C:\busdb1.MDB"
Dim strConnection As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & DATABASE_FILE
Dim cn As New OleDbConnection(strConnection)
Dim da1 As New OleDbDataAdapter
Dim da As New OleDbDataAdapter
Dim eda As New OleDbDataAdapter
Dim neda As New OleDbDataAdapter
Dim sda As New OleDbDataAdapter
Dim ds As New DataSet
Dim ds2 As New DataSet
Dim WithEvents objCurrencyManager As CurrencyManager
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim strSQL As String = "SELECT * FROM tblProvince"
da.SelectCommand = New OleDbCommand(strSQL, cn)
strSQL = "SELECT * FROM Route"
da1.SelectCommand = New OleDbCommand(strSQL, cn)
' strSQL = "SELECT * FROM East"
' eda.SelectCommand = New OleDbCommand(strSQL, cn)
' strSQL = "SELECT * FROM Northeast"
' neda.SelectCommand = New OleDbCommand(strSQL, cn)
'
' strSQL = "SELECT * FROM South"
' sda.SelectCommand = New OleDbCommand(strSQL, cn)
Try
' da1.Fill(ds, "Province")
da.Fill(ds, "tblProvince")
da1.Fill(ds, "Route")
' neda.Fill(ds, "Northeast")
' sda.Fill(ds, "South")
Catch ex As OleDbException
MsgBox(ex.Message)
Exit Sub
End Try
Dim parentColumn As DataColumn = ds.Tables("tblProvince").Columns("ProvinceID")
Dim childColumn As DataColumn = ds.Tables("Route").Columns("ProvinceID")
Dim relation As DataRelation = New DataRelation("tblProvinceRoute", parentColumn, childColumn)
ds.Relations.Add(relation)
ListBox1.DataSource = ds.Tables("tblProvince")
ListBox1.DisplayMember = "ProvinceName"
End Sub
Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
Dim iCurrentIndex As Integer = ListBox1.SelectedIndex
Dim rows() As DataRow = ds.Tables("tblProvince").Rows(iCurrentIndex).GetChildRows("tblProvinceRoute")
ListBoxRoute.Items.Clear()
ListBoxall.Items.Clear()
RouthBox.Items.Clear()
FareBox.Items.Clear()
DistanceBox.Items.Clear()
TimeBox.Items.Clear()
FromBKKBox.Items.Clear()
ToBKKBox.Items.Clear()
For Each row As DataRow In rows
ListBoxRoute.Items.Add(row("RouteName").ToString & ControlChars.Tab)
'RouthBox.Items.Add(row("ProvinceName").ToString)
ListBoxall.Items.Add(row("Fare").ToString & ControlChars.Tab)
FareBox.Items.Add(row("Distance").ToString & ControlChars.Tab)
DistanceBox.Items.Add(row("Time").ToString)
TimeBox.Items.Add(row("FromBKK").ToString)
FromBKKBox.Items.Add(row("ToBKK").ToString)
ToBKKBox.Items.Add(row("ToBKK").ToString)
objCurrencyManager_PositionChanged(Nothing, Nothing)
Next
End Sub
Private Sub EditTool_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Edittool.Click
Dim newForm As New Password
newForm.Show()
Me.Hide()
End Sub
Private Sub NorthMenu_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NorthMenu.Click
Dim NorthForm As New North
NorthForm.Show()
End Sub
Private Sub NortheastMenu_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NortheastMenu.Click
Dim NortheastForm As New Northeast
NortheastForm.Show()
End Sub
Private Sub East_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles East.Click
Dim EastForm As New East
EastForm.Show()
End Sub
Private Sub South_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles South.Click
Dim SouthForm As New South
SouthForm.Show()
End Sub
Private Sub RefToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RefToolStripMenuItem.Click
Me.Refresh()
End Sub
Private Sub btnMoveFirst_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
objCurrencyManager.Position = 0
End Sub
Private Sub btnMovePrevious_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
objCurrencyManager.Position -= 1
End Sub
Private Sub btnMoveNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
objCurrencyManager.Position += 1
End Sub
Private Sub btnMoveLast_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
objCurrencyManager.Position = objCurrencyManager.Count - 1
End Sub
Private Sub objCurrencyManager_PositionChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles objCurrencyManager.PositionChanged
lblRecordPosition.Text = "จำนวนเส้นทาง " & RouthBox.Items.Count & " เส้นทาง"
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Label10.Text = DateTime.Now.ToString()
End Sub
Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
End
End Sub
Private Sub ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem.Click
PrintDialog1.ShowDialog()
End Sub
End Class