Imports System.Data
Imports System.Data.OleDb
Public Class FormListSend
Dim ds As New DataSet()
Dim da As OleDbDataAdapter
Dim dt As New DataTable
Dim r As Integer
Dim cp As String
Dim Lcount As Integer
Dim iRow As Integer
Dim bs As New BindingSource()
Dim WithEvents objCurrencymanager As CurrencyManager
Dim Comm As New OleDbCommand
Dim strSQL As String
Private Property cn As OleDbConnection
Private Sub FormListSend_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
cn = New OleDbConnection("provider=microsoft.jet.oledb.4.0;user id=admin;password=;data source = C:/project.mdb")
cn.Open()
da = New OleDbDataAdapter("select * from send", cn)
Try
da.Fill(ds, "send")
Catch ex As OleDb.OleDbException
MsgBox(ex.Message)
End Try
Send_no.DataBindings.Add("text", ds.Tables("send"), "Send_no")
Send_that.DataBindings.Add("text", ds.Tables("send"), "Send_that")
Send_date.DataBindings.Add("text", ds.Tables("send"), "Send_date")
Send_from.DataBindings.Add("text", ds.Tables("send"), "Send_from")
Send_up.DataBindings.Add("text", ds.Tables("send"), "Send_up")
Send_subject.DataBindings.Add("text", ds.Tables("send"), "Send_subject")
DataGridView1.DataSource = ds.Tables("send")
With DataGridView1
.Columns(0).HeaderText = "เลขทะเบียนส่ง"
.Columns(0).Width = 140
.Columns(1).HeaderText = "ที่"
.Columns(1).Width = 80
.Columns(2).HeaderText = "วันที่"
.Columns(2).Width = 90
.Columns(3).HeaderText = "จาก"
.Columns(3).Width = 100
.Columns(4).HeaderText = "ถึง"
.Columns(4).Width = 100
.Columns(5).HeaderText = "เรื่ิอง"
.Columns(5).Width = 180
.Columns(6).HeaderText = "หมายเหตุ"
.Columns(6).Width = 90
.Columns(7).HeaderText = "สิ่งที่แนบมาด้วย"
.Columns(7).Width = 120
.Columns(8).HeaderText = "ไฟล์เอกสาร"
.Columns(8).Width = 100
End With
Itemcb1()
objCurrencymanager = CType(Me.BindingContext(ds.Tables("send")), CurrencyManager)
cn.Close()
End Sub
Private Sub Itemcb1()
ComboBox1.Items.Add("ด่วนที่สุด")
ComboBox1.Items.Add("ด่วนมาก")
ComboBox1.Items.Add("ด่วน")
End Sub
Private Sub Buttonback_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Buttonback.Click
FormMenu.Show()
Me.Hide()
End Sub
Private Sub Buttonadd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Buttonadd.Click
objCurrencymanager.AddNew()
End Sub
Private Sub Buttonsave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Buttonsave.Click
Try
cn.Open()
strSQL = "INSERT INTO send(Send_no,Send_that,Send_date,Send_from,Send_up,Send_subject)VALUES('" & Send_no.Text & "','" & Me.Send_that.Text & "','" & Me.Send_date.Value & "','" & Me.Send_from.Text & "','" & Me.Send_up.Text & "','" & Me.Send_subject.Text & "')"
Comm = New OleDbCommand(strSQL, cn)
Comm.ExecuteNonQuery()
Dim ds As New DataSet
Dim dt As New DataTable
Dim r As Integer
Dim cp As String
Dim Lcount As Integer
cp = "c1"
strSQL = "SELECT * FROM book"
Comm = New OleDbCommand(strSQL, cn)
da.SelectCommand = Comm
da.Fill(ds, "book")
Lcount = ds.Tables(0).Rows.Count + 1
If RadioButton1.Checked = True Then
r = "1"
ElseIf RadioButton2.Checked = True Then
r = "2"
ElseIf RadioButton3.Checked = True Then
r = "3"
ElseIf RadioButton4.Checked = True Then
r = "4"
End If
strSQL = "INSERT INTO book(book_id,book_name,cat_id,Send_no)VALUES('" & Lcount & "','" & Me.Send_that.Text & "','" & r & "','" & Me.Send_no.Text & "')"
Comm = New OleDbCommand(strSQL, cn)
Comm.ExecuteNonQuery()
strSQL = "INSERT INTO practice(pra_id,pra_name,cat_pra_id,book_id)VALUES('" & Lcount & "','" & ComboBox1.SelectedItem & "','" & cp & "','" & Lcount & "')"
Comm = New OleDbCommand(strSQL, cn)
Comm.ExecuteNonQuery()
MsgBox("บันทึกข้อมูลเรียบร้อย")
DataGridView1.Refresh()
ClearsubData()
ClearradData()
ClearcbData()
Catch ex As OleDb.OleDbException
MsgBox(ex.Message)
End Try
cn.Close()
End Sub
Private Sub ClearsubData()
Send_no.Text = ""
Send_that.Text = ""
Send_date.Text = ""
Send_from.Text = ""
Send_up.Text = ""
Send_subject.Text = ""
End Sub
Private Sub ClearradData()
RadioButton1.Checked = False
RadioButton2.Checked = False
RadioButton3.Checked = False
RadioButton4.Checked = False
End Sub
Private Sub ClearcbData()
ComboBox1.SelectedItem = False
End Sub
Private Sub Buttonedit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Buttonedit.Click
If MsgBox("คุณต้องการจะแก้ไขรายการนี้ใช่หรือไม่ ?...", MsgBoxStyle.Question + MsgBoxStyle.YesNo, "ยืนยันการแก้ไขรายการ") = MsgBoxResult.Yes Then
Try
cn.Open()
strSQL = "UPDATE send SET Send_no = '" & Send_no.Text & "',Send_that = '" & Me.Send_that.Text & "',Send_date = '" & Me.Send_date.Text & "',Send_from = '" & Me.Send_from.Text & "',Send_up = '" & Me.Send_up.Text & "',Send_subject = '" & Me.Send_subject.Text & "' WHERE (Send_no = '" & Send_no.Text & "')"
Comm = New OleDbCommand(strSQL, cn)
Comm.ExecuteNonQuery()
cp = "c1"
strSQL = "SELECT * FROM book"
Comm = New OleDbCommand(strSQL, cn)
da.SelectCommand = Comm
da.Fill(ds, "book")
Lcount = ds.Tables(0).Rows.Count
If RadioButton1.Checked = True Then
r = "1"
ElseIf RadioButton2.Checked = True Then
r = "2"
ElseIf RadioButton3.Checked = True Then
r = "3"
ElseIf RadioButton4.Checked = True Then
r = "4"
End If
strSQL = "UPDATE book SET book_name = '" & Me.Send_subject.Text & "',cat_id = '" & r & "',Send_no = '" & Me.Send_no.Text & "' WHERE (Send_no = '" & Send_no.Text & "')"
Comm = New OleDbCommand(strSQL, cn)
Comm.ExecuteNonQuery()
MsgBox("แก้ไขข้อมูลเรียบร้อย")
DataGridView1.Refresh()
ClearsubData()
ClearradData()
ClearcbData()
Catch ex As OleDb.OleDbException
MsgBox(ex.Message)
End Try
cn.Close()
Else
MsgBox("ยกเลิกการแก้ไขรายการปัจจุบัน", MsgBoxStyle.Information, "ยกเลิกคําสั่งแก้ไข")
End If
End Sub
Private Sub Buttondel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Buttondel.Click
If MsgBox("คุณแน่ใจหรือไม่ว่าต้องการลบเรคคอร์ดนี ?...", MsgBoxStyle.Question + MsgBoxStyle.YesNo, "ยืนยันการลบข้อมูล") = MsgBoxResult.Yes Then
Try
cn.Open()
strSQL = "DELETE FROM send WHERE Send_no = '" & Send_no.Text & "'"
Comm = New OleDbCommand(strSQL, cn)
Comm.ExecuteNonQuery()
cp = "c1"
strSQL = "SELECT * FROM book"
Comm = New OleDbCommand(strSQL, cn)
da.SelectCommand = Comm
da.Fill(ds, "book")
Lcount = ds.Tables(0).Rows.Count + 1
If RadioButton1.Checked = True Then
r = "1"
ElseIf RadioButton2.Checked = True Then
r = "2"
ElseIf RadioButton3.Checked = True Then
r = "3"
ElseIf RadioButton4.Checked = True Then
r = "4"
End If
strSQL = "DELETE FROM book WHERE Send_no = '" & Me.Send_no.Text & "'"
Comm = New OleDbCommand(strSQL, cn)
Comm.ExecuteNonQuery()
MsgBox("แก้ไขข้อมูลเรียบร้อย")
DataGridView1.Refresh()
ClearsubData()
ClearradData()
ClearcbData()
Catch ex As OleDb.OleDbException
MsgBox(ex.Message)
End Try
cn.Close()
Else
MsgBox("ยกเลิกการลบเรคคอร์ดปัจจุบัน", MsgBoxStyle.Information, "ยกเลิกคําสั่งลบ")
End If
End Sub
End Class