001.
Public
Class
vehicle
002.
Dim
x
As
Integer
003.
Dim
strCheck
As
String
004.
Dim
strSQL
As
String
005.
Dim
ID
As
String
006.
007.
008.
Private
Sub
vehicle_Load(
ByVal
sender
As
System.
Object
,
ByVal
e
As
System.EventArgs)
Handles
MyBase
.Load
009.
010.
Me
.WindowState = FormWindowState.Maximized
011.
012.
cb_search.SelectedIndex = 0
013.
ComboBox1.SelectedIndex = 0
014.
ComboBox2.SelectedIndex = 0
015.
ComboBox3.SelectedIndex = 0
016.
017.
018.
Try
019.
With
CnMysql
020.
If
.State = ConnectionState.Open
Then
.Close()
021.
.ConnectionString = strcon
022.
.Open()
023.
End
With
024.
025.
Catch
026.
MessageBox.Show(
"ติดต่อฐานข้อมูลไม่ได้"
)
027.
End
Try
028.
029.
Dim
sqlDePart
As
String
=
"SELECT * FROM vehiclekind ORDER BY Vehicle_ID"
030.
Dim
dsPart
As
New
DataSet()
031.
da =
New
OleDb.OleDbDataAdapter(sqlDePart, CnMysql)
032.
da.Fill(dsPart,
"DePart"
)
033.
If
dsPart.Tables(
"DePart"
).Rows.Count <> 0
Then
034.
cmbkind.DataSource = dsPart.Tables(
"DePart"
)
035.
cmbkind.DisplayMember = dsPart.Tables(
"DePart"
).Columns(
"Vehicle_ID"
).ToString()
036.
cmbkind.ValueMember = dsPart.Tables(
"DePart"
).Columns(
"Vehicle_kind"
).ToString()
037.
End
If
038.
039.
ShowGrid()
040.
End
Sub
041.
042.
Private
Sub
bt_add_Click(
ByVal
sender
As
System.
Object
,
ByVal
e
As
System.EventArgs)
Handles
bt_add.Click
043.
044.
If
txt_no.Text =
""
Then
045.
MessageBox.Show(
"กรุณากรอกข้อมูลรหัส"
)
046.
Exit
Sub
047.
txt_no.Focus()
048.
ElseIf
txt_name.Text =
""
Then
049.
MessageBox.Show(
"กรุณากรอกข้อมูลชื่อ"
)
050.
txt_name.Focus()
051.
End
If
052.
053.
054.
055.
strCheck =
"SELECT * FROM tblvehicle WHERE Vehicle_StudentNo = '"
& txt_no.Text &
"'"
056.
da =
New
OleDb.OleDbDataAdapter()
057.
ds =
New
DataSet()
058.
059.
da =
New
OleDb.OleDbDataAdapter(strCheck, CnMysql)
060.
da.Fill(ds,
"Chk_Emp"
)
061.
If
ds.Tables(
"Chk_Emp"
).Rows.Count <> 0
Then
062.
MessageBox.Show(
"รหัสนี้มีอยู่แล้วในฐานข้อมูล"
,
"ผิดพลาด"
, MessageBoxButtons.OK, MessageBoxIcon.
Error
)
063.
Exit
Sub
064.
End
If
065.
066.
067.
068.
069.
070.
strSQL =
"Insert into tblvehicle(Vehicle_StudentNo,Vehicle_StudentName , Vehicle_StudenLastName, Vehicle_StudentBranch, Vehicle_StudentDegree, Vehicle_StudentYear, Vehicle_StudentPhone, Vehicle_StudentEmail, Vehicle_MemberNo, Vehicle_MemberName, Vehicle_MemberLastName, Vehicle_Memberoccupation, Vehicle_MemberPhone, Vehicle_MemberEmail, Vehicle_kind, Vehicle_registration, Vehicle_trademark, Vehicle_Color, Vehicle_jv, Vehicle_in) values('"
& txt_no.Text &
"','"
& txt_name.Text &
"','"
& txt_lastname.Text &
"','"
& ComboBox1.Text &
"','"
& ComboBox2.Text &
"','"
& ComboBox3.Text &
"','"
& txt_phone.Text &
"','"
& txt_email.Text &
"','"
& txt_no2.Text &
"','"
& txt_name2.Text &
"','"
& txt_lastname2.Text &
"','"
& txt_occ.Text &
"','"
& txt_phone2.Text &
"','"
& txt_email2.Text &
"','"
& cmbkind.SelectedValue.ToString() &
"','"
& txt_red.Text &
"','"
& txt_td.Text &
"','"
& txt_color.Text &
"','"
& txt_jv.Text &
"','"
& txt_in.Text &
"')"
071.
072.
Try
073.
With
cm
074.
.CommandType = CommandType.Text
075.
.CommandText = strSQL
076.
.Connection = CnMysql
077.
.ExecuteNonQuery()
078.
079.
MessageBox.Show(
"เพิ่มข้อมูลเรียบร้อยแล้ว"
)
080.
ShowGrid()
081.
ClearText()
082.
End
With
083.
Catch
084.
MessageBox.Show(
"การเพิ่มข้อมูลผิดพลาด"
)
085.
Exit
Sub
086.
End
Try
087.
End
Sub
088.
089.
090.
Sub
ShowGrid()
091.
Dim
strShow
As
String
092.
strShow =
"SELECT * FROM tblvehicleQuery ORDER BY Vehicle_StudentNo"
093.
ds =
New
DataSet()
094.
da =
New
OleDb.OleDbDataAdapter(strShow, CnMysql)
095.
da.Fill(ds,
"Show"
)
096.
If
ds.Tables(
"Show"
).Rows.Count <> 0
Then
097.
DataGridView1.DataSource = ds.Tables(
"Show"
)
098.
099.
End
If
100.
101.
End
Sub
102.
103.
104.
105.
Sub
ClearText()
106.
txt_no.Text =
""
107.
txt_name.Text =
""
108.
txt_lastname.Text =
""
109.
ComboBox1.SelectedValue = 0
110.
ComboBox2.SelectedValue = 0
111.
ComboBox3.SelectedValue = 0
112.
txt_phone.Text =
""
113.
txt_email.Text =
""
114.
txt_no2.Text =
""
115.
txt_name2.Text =
""
116.
txt_lastname2.Text =
""
117.
txt_occ.Text =
""
118.
txt_phone2.Text =
""
119.
txt_email2.Text =
""
120.
cmbkind.SelectedValue = 0
121.
txt_red.Text =
""
122.
txt_td.Text =
""
123.
txt_color.Text =
""
124.
txt_jv.Text =
""
125.
txt_in.Text =
""
126.
End
Sub
127.
128.
Private
Sub
bt_Canceled_Click(
ByVal
sender
As
System.
Object
,
ByVal
e
As
System.EventArgs)
Handles
bt_Canceled.Click
129.
ClearText()
130.
End
Sub
131.
132.
Private
Sub
bt_cor_Click(
ByVal
sender
As
System.
Object
,
ByVal
e
As
System.EventArgs)
Handles
bt_cor.Click
133.
134.
135.
If
txt_no.Text =
""
Then
136.
MessageBox.Show(
"กรุณาเลือกข้อมูลที่ต้องการแก้ไข"
)
137.
Exit
Sub
138.
End
If
139.
140.
141.
strSQL =
"Update tblvehicle set Vehicle_StudentName ='"
& txt_name.Text &
"',Vehicle_StudenLastName = '"
& txt_lastname.Text &
"',Vehicle_StudentBranch = '"
& ComboBox1.Text &
"',Vehicle_StudentDegree='"
& ComboBox2.Text &
"',Vehicle_StudentYear='"
& ComboBox3.Text &
"',Vehicle_StudentPhone='"
& txt_phone.Text &
"',Vehicle_StudentEmail='"
& txt_email.Text &
"',Vehicle_MemberNo='"
& txt_no2.Text &
"',Vehicle_MemberName='"
& txt_name2.Text &
"',Vehicle_MemberLastName='"
& txt_lastname2.Text &
"',Vehicle_Memberoccupation='"
& txt_occ.Text &
"',Vehicle_MemberPhone='"
& txt_phone2.Text &
"',Vehicle_MemberEmail='"
& txt_email2.Text &
"',Vehicle_kind="
& cmbkind.SelectedValue.ToString() &
",Vehicle_registration='"
& txt_red.Text &
"',Vehicle_trademark='"
& txt_td.Text &
"',Vehicle_Color='"
& txt_color.Text &
"' ,Vehicle_jv='"
& txt_jv.Text &
"',Vehicle_in='"
& txt_in.Text &
"' where Vehicle_StudentNo='"
& ID &
"'"
142.
Try
143.
With
cm
144.
.CommandType = CommandType.Text
145.
.CommandText = strSQL
146.
.Connection = CnMysql
147.
.ExecuteNonQuery()
148.
149.
MessageBox.Show(
"การแก้ไขเรียบร้อยแล้ว"
)
150.
ShowGrid()
151.
ClearText()
152.
End
With
153.
Catch
154.
MessageBox.Show(
"การแก้ไขข้อมูลผิดพลาด"
)
155.
Exit
Sub
156.
End
Try
157.
End
Sub
158.
159.
Private
Sub
DataGridView1_CellContentClick(
ByVal
sender
As
System.
Object
,
ByVal
e
As
System.Windows.Forms.DataGridViewCellEventArgs)
160.
If
e.RowIndex < 0
Then
161.
Exit
Sub
162.
End
If
163.
164.
165.
166.
Dim
sqlSelect
As
String
167.
ID = DataGridView1.Rows(e.RowIndex).Cells(0).Value.ToString()
168.
sqlSelect =
"Select * from tblvehicle Where Vehicle_StudentNo ='"
& ID &
"'"
'ดึงข้อมูลที่มีเลขที่ตัราตรงกับ DPass ที่เลือก
169.
da =
New
OleDb.OleDbDataAdapter(sqlSelect, CnMysql)
170.
ds =
New
DataSet()
171.
da.Fill(ds,
"Emp_Show"
)
172.
173.
If
ds.Tables(
"Emp_Show"
).Rows.Count <> 0
Then
174.
txt_no.Text = ID
175.
txt_name.Text = ds.Tables(
"Emp_Show"
).Rows(0)(
"Vehicle_StudentName"
).ToString()
176.
txt_lastname.Text = ds.Tables(
"Emp_Show"
).Rows(0)(
"Vehicle_StudenLastName"
).ToString()
177.
ComboBox1.Text = ds.Tables(
"Emp_Show"
).Rows(0)(
"Vehicle_StudentBranch"
).ToString()
178.
ComboBox2.Text = ds.Tables(
"Emp_Show"
).Rows(0)(
"Vehicle_StudentDegree"
).ToString()
179.
ComboBox3.Text = ds.Tables(
"Emp_Show"
).Rows(0)(
"Vehicle_StudentYear"
).ToString()
180.
txt_phone.Text = ds.Tables(
"Emp_Show"
).Rows(0)(
"Vehicle_StudentPhone"
).ToString()
181.
txt_email.Text = ds.Tables(
"Emp_Show"
).Rows(0)(
"Vehicle_StudentEmail"
).ToString()
182.
txt_no2.Text = ds.Tables(
"Emp_Show"
).Rows(0)(
"Vehicle_MemberNo"
).ToString()
183.
txt_name2.Text = ds.Tables(
"Emp_Show"
).Rows(0)(
"Vehicle_MemberName"
).ToString()
184.
txt_lastname2.Text = ds.Tables(
"Emp_Show"
).Rows(0)(
"Vehicle_MemberLastName"
).ToString()
185.
txt_occ.Text = ds.Tables(
"Emp_Show"
).Rows(0)(
"Vehicle_Memberoccupation"
).ToString()
186.
txt_phone2.Text = ds.Tables(
"Emp_Show"
).Rows(0)(
"Vehicle_MemberPhone"
).ToString()
187.
txt_email2.Text = ds.Tables(
"Emp_Show"
).Rows(0)(
"Vehicle_MemberEmail"
).ToString()
188.
cmbkind.SelectedValue = ds.Tables(
"Emp_Show"
).Rows(0)(
"Vehicle_kind"
).ToString()
189.
txt_red.Text = ds.Tables(
"Emp_Show"
).Rows(0)(
"Vehicle_registration"
).ToString()
190.
txt_td.Text = ds.Tables(
"Emp_Show"
).Rows(0)(
"Vehicle_trademark"
).ToString()
191.
txt_color.Text = ds.Tables(
"Emp_Show"
).Rows(0)(
"Vehicle_Color"
).ToString()
192.
txt_jv.Text = ds.Tables(
"Emp_Show"
).Rows(0)(
"Vehicle_jv"
).ToString()
193.
txt_in.Text = ds.Tables(
"Emp_Show"
).Rows(0)(
"Vehicle_in"
).ToString()
194.
End
If
195.
End
Sub
196.
197.
Private
Sub
txt_search_TextChanged(
ByVal
sender
As
System.
Object
,
ByVal
e
As
System.EventArgs)
Handles
txt_search.TextChanged
198.
Dim
strwhere
As
String
199.
Dim
strShow
As
String
200.
Select
Case
cb_search.Text
201.
Case
"รหัสนักศึกษา"
202.
strwhere =
" where Vehicle_StudentNo like '%"
& txt_search.Text &
"%'"
203.
Case
"ชื่อ"
204.
strwhere =
" where Vehicle_StudentName like '%"
& txt_search.Text &
"%'"
205.
End
Select
206.
207.
strShow =
"SELECT * FROM tblvehicleQuery "
& strwhere &
" ORDER BY Vehicle_StudentNo"
208.
ds =
New
DataSet()
209.
da =
New
OleDb.OleDbDataAdapter(strShow, CnMysql)
210.
da.Fill(ds,
"Show"
)
211.
DataGridView1.DataSource = ds.Tables(
"Show"
)
212.
If
ds.Tables(
"Show"
).Rows.Count = 0
Then
213.
MessageBox.Show(
"ไม่มีข้อมูลตามเงื่อนไขที่กำหนด"
)
214.
End
If
215.
End
Sub
216.
217.
Private
Sub
bt_del_Click(
ByVal
sender
As
System.
Object
,
ByVal
e
As
System.EventArgs)
218.
219.
End
Sub
220.
End
Class