001.
Private
Sub
RefreshData()
002.
If
Not
con.State = ConnectionState.Open
Then
003.
004.
con.Open()
005.
End
If
006.
Dim
da
As
New
OleDbDataAdapter(
"SELECT semet as [ID_Product], "
& _
007.
"txtnum as [out_num], txtna1 as [out_student], txtna2 as [out_store],"
& _
008.
"txtdate as [out_date]"
&
009.
"FROM tb_Out_Product ORDER BY semat "
, con)
010.
011.
012.
013.
014.
Dim
dt
As
New
DataTable
015.
016.
da.Fill(dt)
017.
018.
019.
Me
.DataGridView1.DataSource = dt
020.
021.
022.
con.Close()
023.
024.
End
Sub
025.
026.
027.
Private
Sub
Button1_Click(sender
As
Object
, e
As
EventArgs)
Handles
add.Click
028.
029.
Dim
cmd
As
New
OleDbCommand
030.
If
Not
con.State = ConnectionState.Open
Then
031.
032.
con.Open()
033.
End
If
034.
035.
cmd.Connection = con
036.
037.
038.
If
semat.SelectedItem =
""
Then
039.
MessageBox.Show(
"กรุณาเลือกสินค้า"
)
040.
Me
.semat.Focus()
041.
Exit
Sub
042.
End
If
043.
If
txtnum.Text =
""
Then
044.
MessageBox.Show(
"กรุณากรอกจำนวน"
)
045.
Me
.txtnum.Focus()
046.
Exit
Sub
047.
End
If
048.
If
txtna1.Text =
""
Then
049.
MessageBox.Show(
"กรุณากรอกชือ"
)
050.
Me
.txtna1.Focus()
051.
Exit
Sub
052.
End
If
053.
054.
If
txtna2.Text =
""
Then
055.
MessageBox.Show(
"กรุณากรอกชื่อ"
)
056.
Me
.txtna2.Focus()
057.
Exit
Sub
058.
End
If
059.
If
txtdate.Value.ToShortDateString =
""
Then
060.
MessageBox.Show(
"กรุณาเลือกวัน"
)
061.
Me
.txtdate.Focus()
062.
Exit
Sub
063.
End
If
064.
065.
066.
067.
If
Me
.semat.Tag
Then
068.
069.
070.
071.
cmd.CommandText =
" INSERT INTO tb_Out_Product(ID_Product, out_num, out_student, out_store, out_date)"
& _
072.
" VALUES ('"
&
Me
.semat.Text &
"','"
&
Me
.txtnum.Text &
"','"
& _
073.
Me
.txtna1.Text &
"','"
&
Me
.txtna2.Text &
"','"
& _
074.
Me
.txtdate.Text &
"')"
075.
076.
cmd.CommandType = CommandType.Text
077.
cmd.ExecuteNonQuery()
078.
Else
079.
080.
cmd.CommandText =
"Update tb_Out_Product SET "
& _
081.
" ID_Product= '"
&
Me
.semat.SelectedItem &
"' "
& _
082.
" ,out_num= '"
&
Me
.txtnum.Text &
"' "
& _
083.
" ,out_student= '"
&
Me
.txtna1.Text &
"' "
& _
084.
" ,out_store= '"
&
Me
.txtna2.Text &
"' "
& _
085.
" ,out_date1= '"
&
Me
.txtdate.Value.ToShortDateString &
"' "
& _
086.
" WHERE ID_Product= '"
&
Me
.semat.Tag &
"' "
087.
088.
cmd.ExecuteNonQuery()
089.
End
If
090.
091.
092.
093.
094.
RefreshData()
095.
096.
097.
098.
con.Close()
099.
100.
101.
End
Sub