Imports System.Data
Imports System.Data.OleDb
Public Class Form1
Dim strConn As String
Dim Conn As New OleDbConnection
Dim da As OleDbDataAdapter
Dim ds As New DataSet
Dim dt As DataTable
Dim dr As DataRow
Dim CurrentEmployees As Integer
Dim isFind As Boolean = False
Dim btnChk As String
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim strconn As String
TextTotal_text.Enabled = False
TextDate.Enabled = False
TextId.Enabled = False
TextVat.Enabled = False
TextTotal_no.Enabled = False
btnSave.Enabled = False
btnEdit.Enabled = False
btnDelete.Enabled = False
strconn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\dbtax.mdb;"
With Conn
If .State = ConnectionState.Open Then Close()
.ConnectionString = strconn
.Open()
End With
ShowALLEmployees()
FormatALLEmployees()
End Sub
Private Sub FormatALLEmployees()
Dim cs As New DataGridViewCellStyle()
cs.Font = New Font("Ms Sans Serif", 10, FontStyle.Bold)
With DataGridView1
.ColumnHeadersDefaultCellStyle = cs
.Columns(0).HeaderText = "Id"
.Columns(1).HeaderText = "Vol"
.Columns(2).HeaderText = "No"
.Columns(3).HeaderText = "Name"
.Columns(4).HeaderText = "Address"
.Columns(5).HeaderText = "Description"
.Columns(6).HeaderText = "Remark"
.Columns(7).HeaderText = "Date"
.Columns(8).HeaderText = "Amount"
.Columns(9).HeaderText = "Vat"
.Columns(10).HeaderText = "Discount"
.Columns(11).HeaderText = "Totalno"
.Columns(12).HeaderText = "Totaltext"
.Columns(0).Width = 100
.Columns(1).Width = 100
.Columns(2).Width = 100
.Columns(3).Width = 100
.Columns(4).Width = 100
.Columns(5).Width = 100
.Columns(6).Width = 100
.Columns(7).Width = 100
.Columns(8).Width = 100
.Columns(9).Width = 100
.Columns(10).Width = 100
.Columns(11).Width = 100
.Columns(12).Width = 100
End With
End Sub
Private Sub ShowALLEmployees()
Dim SqlEmp As String
SqlEmp = " SELECT * "
SqlEmp &= "FROM Tbltax"
If isFind = True Then
ds.Tables("Tbltax").Clear()
End If
da = New OleDbDataAdapter(SqlEmp, Conn)
da.Fill(ds, "Tbltax")
If ds.Tables("Tbltax").Rows.Count <> 0 Then
isFind = True
With DataGridView1
.ReadOnly = True
.DataSource = ds.Tables("Tbltax")
End With
Else
isFind = False
End If
End Sub
Private Sub DataGridView1_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick
End Sub
Private Sub DataGridView1_CellMouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles DataGridView1.CellMouseUp
If e.RowIndex = DataGridView1.RowCount - 1 Then
Exit Sub
End If
With DataGridView1
TextId.Text = .Rows.Item(e.RowIndex).Cells(0).Value.ToString()
TextDate.Text = .Rows.Item(e.RowIndex).Cells(1).Value.ToString()
TextVol.Text = .Rows.Item(e.RowIndex).Cells(2).Value.ToString()
TextNo.Text = .Rows.Item(e.RowIndex).Cells(3).Value.ToString()
TextName.Text = .Rows.Item(e.RowIndex).Cells(4).Value.ToString()
TextAddress.Text = .Rows.Item(e.RowIndex).Cells(5).Value.ToString()
TextDescription.Text = .Rows.Item(e.RowIndex).Cells(6).Value.ToString()
TextRemark.Text = .Rows.Item(e.RowIndex).Cells(7).Value.ToString()
TextAmount.Text = .Rows.Item(e.RowIndex).Cells(8).Value.ToString()
TextVat.Text = .Rows.Item(e.RowIndex).Cells(9).Value.ToString()
TextTotal_no.Text = .Rows.Item(e.RowIndex).Cells(11).Value.ToString()
TextTotal_text.Text = .Rows.Item(e.RowIndex).Cells(12).Value.ToString()
End With
btnEdit.Enabled = True
btnDelete.Enabled = True
End Sub
Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
btnChk = "Add"
btnAdd.Enabled = False
btnEdit.Enabled = False
btnDelete.Enabled = False
btnSave.Enabled = True
TextDate.Text = ""
TextVol.Text = ""
TextNo.Text = ""
TextId.Text = ""
TextName.Text = ""
TextAddress.Text = ""
TextDescription.Text = ""
TextRemark.Text = ""
TextAmount.Text = ""
TextVat.Text = ""
TextTotal_no.Text = ""
TextTotal_text.Text = ""
TextVol.Focus()
End Sub
Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
Dim sqlAdd As String
Dim sqlEdit As String
Dim comAdd As New OleDbCommand
Select Case btnChk
Case "Add"
If (TextDate.Text = "") Or (TextVol.Text = "") Or (TextName.Text = "") Or (TextNo.Text = "") Or (TextAddress.Text = "") Or (TextDescription.Text = "") Or (TextRemark.Text = "") Or (TextAmount.Text = "") Or (TextVat.Text = "") Or (TextTotal_no.Text = "") Or (TextTotal_text.Text = "") Then
MsgBox("โปรดป้อนข้อมูลให้ครบ")
TextVol.Focus()
Exit Sub
End If
sqlAdd = "INSERT INTO Tbltax (Date,Vol,No,Name,Address,Description,Remark,Amount,Vat,Totalno,Totaltex)"
sqlAdd &= "VALUES ('" & TextDate.Text & "',"
sqlAdd &= "'" & TextVol.Text & "',"
sqlAdd &= "'" & TextNo.Text & "',"
sqlAdd &= "'" & TextName.Text & "',"
sqlAdd &= "'" & TextAddress.Text & "',"
sqlAdd &= "'" & TextDescription.Text & "',"
sqlAdd &= "'" & TextRemark.Text & "',"
sqlAdd &= "'" & TextAmount.Text & "',"
sqlAdd &= "'" & TextVat.Text & "',"
sqlAdd &= "'" & TextTotal_no.Text & "',"
sqlAdd &= "'" & TextTotal_text.Text & "')"
With comAdd
.CommandType = CommandType.Text
.CommandText = sqlAdd
.Connection = Conn
.ExecuteNonQuery()
End With
MsgBox("บันทึกข้อมูลเรียนร้อย")
ShowALLEmployees()
Case "Update"
sqlEdit = " UPDATE Tbltax "
sqlEdit &= "SET Date='" & TextDate.Text & "',"
sqlEdit &= "Vol='" & TextVol.Text & "',"
sqlEdit &= "No='" & TextNo.Text & "',"
sqlEdit &= "Name='" & TextName.Text & "',"
sqlEdit &= "Address='" & TextAddress.Text & "',"
sqlEdit &= "Description='" & TextDescription.Text & "',"
sqlEdit &= "Remark='" & TextRemark.Text & "',"
sqlEdit &= "Date='" & TextAmount.Text & "',"
sqlEdit &= "Amount='" & TextVat.Text & "',"
sqlEdit &= "Total_text='" & TextTotal_no.Text & "',"
sqlEdit &= "Discount='" & TextTotal_text.Text & "',"
sqlEdit &= "WHERE ( Id=" & CInt(TextId.Text) & ")"
With comAdd
.CommandType = CommandType.Text
.CommandText = sqlEdit
.Connection = Conn
.ExecuteNonQuery()
End With
MsgBox("แก้ไขข้อมูลเรียบร้อย")
ShowALLEmployees()
Case Else
MsgBox("ไม่มีการทำงาน")
btnAdd.Enabled = True
btnEdit.Enabled = True
btnDelete.Enabled = True
btnSave.Enabled = False
End Select
End Sub
Private Sub TextTotal_no_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextTotal_no.KeyDown
If e.KeyCode = Keys.Enter Then TextTotal_text.Focus()
End Sub
Private Sub TextTotal_no_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextTotal_no.KeyPress
End Sub
Private Sub TextTotal_no_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextTotal_no.TextChanged
End Sub
Private Sub btnEdit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEdit.Click
btnChk = "Update"
btnAdd.Enabled = False
btnEdit.Enabled = False
btnDelete.Enabled = False
btnSave.Enabled = True
End Sub
Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click
Dim sqlDelete As String
Dim comAdd As New OleDbCommand
If MessageBox.Show("ต้องการลบข้อมูล", "ยืนยันการลบ", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) = Windows.Forms.DialogResult.Yes Then
sqlDelete = "Delete From Tbltax "
sqlDelete &= " WHERE (ID=" & CInt(TextId.Text) & ")"
With comAdd
.CommandType = CommandType.Text
.CommandText = sqlDelete
.Connection = Conn
.ExecuteNonQuery()
End With
ShowALLEmployees()
End If
End Sub
Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
Me.Close()
End Sub
Private Sub TextVol_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextVol.KeyDown
If e.KeyCode = Keys.Enter Then TextNo.Focus()
End Sub
Private Sub TextVol_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextVol.KeyPress
End Sub
Private Sub TextVol_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextVol.TextChanged
End Sub
Private Sub TextNo_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextNo.KeyDown
If e.KeyCode = Keys.Enter Then TextName.Focus()
End Sub
Private Sub TextNo_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextNo.TextChanged
End Sub
Private Sub TextName_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextName.KeyDown
If e.KeyCode = Keys.Enter Then TextAddress.Focus()
End Sub
Private Sub TextName_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextName.TextChanged
End Sub
Private Sub TextAddress_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextAddress.KeyDown
If e.KeyCode = Keys.Enter Then TextDescription.Focus()
End Sub
Private Sub TextAddress_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextAddress.TextChanged
End Sub
Private Sub TextDescription_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextDescription.KeyDown
If e.KeyCode = Keys.Enter Then TextRemark.Focus()
End Sub
Private Sub TextDescription_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextDescription.TextChanged
End Sub
Private Sub TextRemark_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextRemark.KeyDown
If e.KeyCode = Keys.Enter Then TextAmount.Focus()
End Sub
Private Sub TextRemark_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextRemark.TextChanged
End Sub
Private Sub TextAmount_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextAmount.KeyDown
End Sub
Private Sub TextAmount_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextAmount.TextChanged
End Sub
Private Sub TextVat_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextVat.KeyDown
End Sub
Private Sub TextVat_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextVat.TextChanged
End Sub
Private Sub TextDiscount_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs)
If e.KeyCode = Keys.Enter Then TextTotal_no.Focus()
End Sub
Private Sub TextDiscount_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
End Sub
Private Sub TextTotal_text_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextTotal_text.TextChanged
End Sub
Private Sub TextDate_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextDate.KeyDown
If e.KeyCode = Keys.Enter Then TextVol.Focus()
End Sub
Private Sub TextDate_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextDate.TextChanged
End Sub
Private Sub btnApl_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnApl.Click
TextDate.Text = DateAndTime.DateString
TextVat.Text = Val(TextAmount.Text) * 7 / 100
TextTotal_no.Text = Val(TextAmount.Text) + Val(TextVat.Text)
TextTotal_text.Text = sample.ThaiBaht(CDbl(TextTotal_no.Text))
End Sub
Private Sub btnPrint1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrint1.Click
End Sub
End Class