Imports system.data.oledb
Public Class Make_up
Const DATABASE_FILE As String = "C:\Documents and Settings\Modemzaa\My Documents\dbvoicetv.MDB"
Dim strConnection As String = "Provider=Microsoft.jet.OLEDB.4.0;" & _
"Data Source=" & DATABASE_FILE
Dim cn As New OleDbConnection(strConnection)
Dim da As New OleDbDataAdapter
Dim ds As New DataSet
Dim WithEvents objCurrencyManager As CurrencyManager
Private Sub ComboBox3_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox3.SelectedIndexChanged
End Sub
Private Sub Make_up_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim strSQL As String = "SELECT * FROM Make_up"
da.SelectCommand = New OleDbCommand(strSQL, cn)
Try
da.Fill(ds, "Make_up")
Catch ex As Exception
MsgBox(ex.Message)
Exit Sub
End Try
DateTimePicker1.DataBindings.Add("Value", ds.Tables("Make_up"), "วัน/เดือน/ปี")
ComboBox1.DataBindings.Add("text", ds.Tables("Make_up"), "ประเภทงาน")
ComboBox2.DataBindings.Add("text", ds.Tables("Make_up"), "เวลาเข้างาน")
ComboBox3.DataBindings.Add("text", ds.Tables("Make_up"), "รายการ")
TextBox1.DataBindings.Add("text", ds.Tables("Make_up"), "ชือ")
TextBox2.DataBindings.Add("text", ds.Tables("Make_up"), "นามสกุล")
TextBox3.DataBindings.Add("text", ds.Tables("Make_up"), "จำนวนเงิน")
DataGridView1.DataSource = ds.Tables("Make_up")
objCurrencyManager = Me.BindingContext(ds.Tables("Make_up"))
objCurrencyManager_PositionChanged(Nothing, Nothing)
End Sub
Private Sub objCurrencyManager_PositionChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles objCurrencyManager.PositionChanged
If objCurrencyManager.Position = 0 Then
Button10.Enabled = False
Button9.Enabled = False
Else
Button10.Enabled = True
Button9.Enabled = True
End If
If objCurrencyManager.Position = objCurrencyManager.Count - 1 Then
Button13.Enabled = False
Button12.Enabled = False
Else
Button13.Enabled = True
Button12.Enabled = True
End If
End Sub
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
objCurrencyManager.AddNew()
DateTimePicker1.Focus()
End Sub
Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
If MsgBox("คุณแน่ใจหรือว่าต้องการลบเรคอร์นี้", _
MsgBoxStyle.Question + MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then
objCurrencyManager.RemoveAt(objCurrencyManager.Position)
End If
objCurrencyManager_PositionChanged(Nothing, Nothing)
End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
Try
Dim cb As New OleDbCommandBuilder(da)
objCurrencyManager.EndCurrentEdit()
Dim iRecordChanged As Integer = da.Update(ds, "Make_up")
MsgBox("บันทึกการเปลี่ยนเแปลงลงฐานข้อมูลแล้ว" & ControlChars.CrLf & _
"จำนวนเรคอร์ดที่ทีการเปลียนแปลงเท่ากับ " & iRecordChanged & " เรคอร์ด")
Catch ex As OleDbException
MsgBox(ex.Message)
End Try
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Me.Close()
End Sub
Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click
objCurrencyManager.Position = 0
End Sub
Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click
objCurrencyManager.Position -= 1
End Sub
Private Sub Button12_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button12.Click
objCurrencyManager.Position += 1
End Sub
Private Sub Button13_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button13.Click
objCurrencyManager.Position = objCurrencyManager.Count - 1
End Sub
Private Sub Label9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label9.Click
Label9.Text = " เรคอร์ดที่ " & objCurrencyManager.Position + 1 & _
" จากทั้งหมด " & objCurrencyManager.Count & "เรคอร์ด"
End Sub
End Class