01.
Private
Sub
Button1_Click(
ByVal
sender
As
System.
Object
,
ByVal
e
As
System.EventArgs)
Handles
Button1.Click
02.
Dim
Conn
As
New
OleDbConnection
03.
Dim
Cmd
As
New
OleDbCommand
04.
Dim
Str
As
String
05.
MyModule.Connection(Con)
06.
Select
Case
status
07.
Case
"add"
08.
If
TextBox1.Text =
""
Then
09.
MessageBox.Show(
"กรุณาป้อนเลขที่การใช้น้ำ !!!"
,
"ข้อผิดพลาด"
, MessageBoxButtons.OK, MessageBoxIcon.Information)
10.
TextBox1.Focus()
11.
TextBox1.SelectAll()
12.
Exit
Sub
13.
14.
ElseIf
TextBox2.Text =
""
Then
15.
MessageBox.Show(
"กรุณาป้อนเลขที่มาตรน้ำ !!!"
,
"ข้อผิดพลาด"
, MessageBoxButtons.OK, MessageBoxIcon.Information)
16.
TextBox2.Focus()
17.
TextBox2.SelectAll()
18.
Exit
Sub
19.
ElseIf
TextBox3.Text =
""
Then
20.
MessageBox.Show(
"กรุณาป้อนเลขที่อ่านครั้งก่อน !!!"
,
"ข้อผิดพลาด"
, MessageBoxButtons.OK, MessageBoxIcon.Information)
21.
TextBox3.Focus()
22.
TextBox3.SelectAll()
23.
Exit
Sub
24.
ElseIf
TextBox4.Text =
""
Then
25.
MessageBox.Show(
"กรุณาป้อนเลขที่อ่านครั้งหลัง !!!"
,
"ข้อผิดพลาด"
, MessageBoxButtons.OK, MessageBoxIcon.Information)
26.
TextBox4.Focus()
27.
TextBox4.SelectAll()
28.
Exit
Sub
29.
Else
30.
If
CheckDubplicate1(
"W_No"
,
"M"
, TextBox2.Text) =
False
Then
31.
Str =
"INSERT INTO WaterUse([Wu_No],[Wu_WM],[Wu_Date],[Wu_water],[Wu_Auto],[Wu_Name],[Wu_Add],[Wu_M],[Wu_N],[Wu_Before],[Wu_Datebefore],[Wu_After],[Wu_Dateafter],[Wu_Consumption],[Wu_Peo],[Wu_total],[Wu_Sta]) VALUES("
32.
Str &=
"'"
& TextBox1.Text &
"',"
33.
Str &=
"'"
& TextBox2.Text &
"',"
34.
Str &=
"'"
& Dat1.Value.ToString &
"',"
35.
Str &=
"'"
& TextBox14.Text &
"',"
36.
Str &=
"'"
& TextBox8.Text &
"',"
37.
Str &=
"'"
& TextBox9.Text &
"',"
38.
Str &=
"'"
& TextBox10.Text &
"',"
39.
Str &=
"'"
& TextBox13.Text &
"',"
40.
Str &=
"'"
& TextBox7.Text &
"',"
41.
Str &=
"'"
& TextBox3.Text &
"',"
42.
Str &=
"'"
& Date2.Value.ToString &
"',"
43.
Str &=
"'"
& TextBox4.Text &
"',"
44.
Str &=
"'"
& Date3.Value.ToString &
"',"
45.
Str &=
"'"
& TextBox5.Text &
"',"
46.
Str &=
"'"
& TextBox12.Text &
"',"
47.
Str &=
"'"
& CheckBox1.Text &
"',"
48.
Str &=
"'"
& TextBox6.Text &
"' "
49.
Str &=
")"
50.
Try
51.
Cmd =
New
OleDbCommand(Str, Con)
52.
Cmd.ExecuteNonQuery()
53.
MsgBox(
"บันทึกข้อมูล เรียบร้อย"
, MsgBoxStyle.Information + MsgBoxStyle.OkOnly,
"แจ้งเตือน"
)
54.
Catch
ex
As
Exception
55.
MsgBox(
"ไม่สามารถบันทึกข้อมูลได้"
, MsgBoxStyle.Critical + MsgBoxStyle.OkOnly,
"แจ้งเตือน"
)
56.
End
Try
57.
Else
58.
MsgBox(
"ไม่พบเลขที่มาตรน้ำในระบบ"
& vbCrLf &
"กรุณาเพิ่มข้อมูลของเลขที่มาตรน้ำนี้ก่อน"
, MsgBoxStyle.Critical + MsgBoxStyle.OkOnly,
"แจ้งเตือน"
)
59.
End
If
60.
End
If
61.
Case
"Edit"
62.
Str =
"UPDATE WaterUse SET Wu_WM= '"
& TextBox2.Text &
"',Wu_Date='"
& Dat1.Value.ToString &
"',Wu_Before= '"
& TextBox3.Text &
"',Wu_Datebefore='"
& Date2.Value.ToString &
"',Wu_After='"
& TextBox4.Text &
"',Wu_Dateafter='"
& Date3.Value.ToString &
"',Wu_Consumption='"
& TextBox5.Text &
"',Wu_total='"
& TextBox6.Text &
"',Wu_Peo= '"
& TextBox12.Text &
"',Wu_water= '"
& TextBox14.Text &
"',Wu_Auto= '"
& TextBox8.Text &
"',Wu_Name= '"
& TextBox9.Text &
"',Wu_Add= '"
& TextBox10.Text &
"',Wu_M= '"
& TextBox13.Text &
"',Wu_N= '"
& TextBox7.Text &
"' WHERE [Wu_No]= '"
& TextBox1.Text &
"'"
63.
Try
64.
Cmd =
New
OleDbCommand(Str, Con)
65.
Cmd.ExecuteNonQuery()
66.
MsgBox(
"แก้ไขข้อมูล เรียบร้อย"
, MsgBoxStyle.Information + MsgBoxStyle.OkOnly,
"แจ้งเตือน"
)
67.
Catch
ex
As
Exception
68.
MsgBox(
"ไม่สามาารถแก้ไขข้อมูลได้"
, MsgBoxStyle.Critical + MsgBoxStyle.OkOnly,
"แจ้งเตือน"
)
69.
End
Try
70.
End
Select
71.
72.
73.
Showdata()
74.
Clear()
75.
Disable()
76.
Autocomplete1()
77.
status =
""
78.
Button1.Text =
"บันทึก"
79.
End
Sub