001.
Imports
System.Data.OleDb
002.
Imports
System.Data
003.
Public
Class
f_employee_2
004.
Dim
posi
As
Int32 = 0
005.
Dim
Status
As
String
006.
Public
conn
As
New
OleDbConnection
007.
Public
Sub
ShowDataUsergroup()
008.
tid.Text = DS.Tables(
"tb_employee"
).Rows(posi)(
"id_em"
)
009.
tcard.Text = DS.Tables(
"tb_employee"
).Rows(posi)(
"card_em"
)
010.
tfront.Text = DS.Tables(
"tb_employee"
).Rows(posi)(
"front_em"
)
011.
tfname.Text = DS.Tables(
"tb_employee"
).Rows(posi)(
"fname_em"
)
012.
tlname.Text = DS.Tables(
"tb_employee"
).Rows(posi)(
"lname_em"
)
013.
tbdate.Text = DS.Tables(
"tb_employee"
).Rows(posi)(
"bdate_em"
)
014.
taddress.Text = DS.Tables(
"tb_employee"
).Rows(posi)(
"address_em"
)
015.
tprovince.Text = DS.Tables(
"tb_employee"
).Rows(posi)(
"province_em"
)
016.
ttel.Text = DS.Tables(
"tb_employee"
).Rows(posi)(
"tel_em"
)
017.
tmobile.Text = DS.Tables(
"tb_employee"
).Rows(posi)(
"mobile_em"
)
018.
temail.Text = DS.Tables(
"tb_employee"
).Rows(posi)(
"email_em"
)
019.
tdepartment.Text = DS.Tables(
"tb_employee"
).Rows(posi)(
"department_em"
)
020.
tfunction.Text = DS.Tables(
"tb_employee"
).Rows(posi)(
"function_em"
)
021.
tposition.Text = DS.Tables(
"tb_employee"
).Rows(posi)(
"position_em"
)
022.
023.
End
Sub
024.
025.
Public
Sub
connectData()
026.
Dim
s
As
String
027.
If
conn.State = ConnectionState.Open
Then
conn.Close()
028.
s = StrConn
029.
conn.ConnectionString = s
030.
conn.Open()
031.
End
Sub
032.
Private
Sub
f_employee(
ByVal
sender
As
Object
,
ByVal
e
As
System.Windows.Forms.FormClosingEventArgs)
Handles
Me
.FormClosing
033.
If
MessageBox.Show(
"ต้องการจบการทำงานหรือไม่"
,
"ระบบ"
, MessageBoxButtons.YesNo) = DialogResult.No
Then
034.
035.
e.Cancel =
True
036.
End
If
037.
End
Sub
038.
Public
Function
executeReader(
ByVal
prmsql
As
String
)
As
OleDbDataReader
039.
Dim
dr
As
OleDbDataReader
040.
Dim
comm
As
New
OleDbCommand
041.
connectData()
042.
With
comm
043.
.CommandType = CommandType.Text
044.
.CommandText = prmsql
045.
.Connection = conn
046.
dr = .ExecuteReader()
047.
Return
dr
048.
End
With
049.
End
Function
050.
Public
Function
executesql(
ByVal
prmsql
As
String
)
As
Boolean
051.
connectData()
052.
Dim
addcom
As
New
OleDbCommand
053.
With
addcom
054.
.CommandType = CommandType.Text
055.
.CommandText = prmsql
056.
.Connection = conn
057.
Try
058.
.ExecuteNonQuery()
059.
Catch
ex
As
Exception
060.
MsgBox(ex.Message, vbOKOnly,
"Error During DBCon.Open()"
)
061.
executesql =
False
062.
Exit
Function
063.
End
Try
064.
End
With
065.
executesql =
True
066.
End
Function
067.
Private
Sub
f_employee_Load(
ByVal
sender
As
System.
Object
,
ByVal
e
As
System.EventArgs)
Handles
MyBase
.Load
068.
loademployee()
069.
End
Sub
070.
Private
Sub
loademployee()
071.
Dim
tposi
As
Integer
072.
Dim
pst
As
Integer
073.
074.
OpenDBtb_department(
"Select * From tb_department"
)
075.
tposi = DS.Tables(
"tb_department"
).Rows.Count - 1
076.
For
pst = 0
To
tposi
077.
tdepartment.Items.Add(DS.Tables(
"tb_department"
).Rows(pst)(
"name_department"
))
078.
Next
079.
080.
OpenDBtb_status(
"Select * From tb_status"
)
081.
tposi = DS.Tables(
"tb_status"
).Rows.Count - 1
082.
For
pst = 0
To
tposi
083.
tposition.Items.Add(DS.Tables(
"tb_status"
).Rows(pst)(
"status_full"
))
084.
Next
085.
End
Sub
086.
Private
Sub
bsearch_Click(
ByVal
sender
As
System.
Object
,
ByVal
e
As
System.EventArgs)
Handles
bsearch.Click
087.
DS =
New
DataSet
088.
StrSQL =
"select id_em,card_em,front_em,fname_em,lname_em,bdate_em,address_em,province_em,tel_em,mobile_em,email_em,department_em,function_em,position_em from tb_employee "
089.
If
Rid.Checked =
True
Then
090.
StrSQL &=
"WHERE id_em = '"
& tsearch.Text &
"'"
091.
ElseIf
Rcard.Checked =
True
Then
092.
StrSQL &=
"WHERE card_em = '"
& tsearch.Text &
"'"
093.
ElseIf
Rname.Checked =
True
Then
094.
StrSQL &=
"WHERE fname_em = '"
& tsearch.Text &
"'"
095.
End
If
096.
097.
StrSQL &=
" order by fname_em"
098.
Try
099.
With
conn
100.
If
.State = ConnectionState.Open
Then
.Close()
101.
.ConnectionString = StrConn
102.
.Open()
103.
End
With
104.
DA =
New
OleDb.OleDbDataAdapter(StrSQL, conn)
105.
DA.Fill(DS,
"tb_employee"
)
106.
conn.Close()
107.
If
DS.Tables(
"tb_employee"
).Rows.Count > 0
Then
108.
tid.Text = DS.Tables(
"tb_employee"
).Rows(posi)(
"id_em"
)
109.
tcard.Text = DS.Tables(
"tb_employee"
).Rows(posi)(
"card_em"
)
110.
tfront.Text = DS.Tables(
"tb_employee"
).Rows(posi)(
"front_em"
)
111.
tfname.Text = DS.Tables(
"tb_employee"
).Rows(posi)(
"fname_em"
)
112.
tlname.Text = DS.Tables(
"tb_employee"
).Rows(posi)(
"lname_em"
)
113.
tbdate.Text = DS.Tables(
"tb_employee"
).Rows(posi)(
"bdate_em"
)
114.
taddress.Text = DS.Tables(
"tb_employee"
).Rows(posi)(
"address_em"
)
115.
tprovince.Text = DS.Tables(
"tb_employee"
).Rows(posi)(
"province_em"
)
116.
ttel.Text = DS.Tables(
"tb_employee"
).Rows(posi)(
"tel_em"
)
117.
tmobile.Text = DS.Tables(
"tb_employee"
).Rows(posi)(
"mobile_em"
)
118.
temail.Text = DS.Tables(
"tb_employee"
).Rows(posi)(
"email_em"
)
119.
tdepartment.Text = DS.Tables(
"tb_employee"
).Rows(posi)(
"department_em"
)
120.
tfunction.Text = DS.Tables(
"tb_employee"
).Rows(posi)(
"function_em"
)
121.
tposition.Text = DS.Tables(
"tb_employee"
).Rows(posi)(
"position_em"
)
122.
123.
DS.Tables(
"tb_employee"
).Rows.Clear()
124.
Else
125.
MsgBox(
"ไม่พบข้อมูลของ :"
+ tsearch.Text)
126.
End
If
127.
Catch
ex
As
Exception
128.
End
Try
129.
End
Sub
130.
Private
Sub
bexit_Click(
ByVal
sender
As
System.
Object
,
ByVal
e
As
System.EventArgs)
Handles
bexit.Click
131.
Me
.Close()
132.
End
Sub
133.
Private
Sub
bcancel_Click(
ByVal
sender
As
System.
Object
,
ByVal
e
As
System.EventArgs)
Handles
bcancel.Click
134.
tid.Text =
""
135.
tcard.Text =
""
136.
tfront.Text =
""
137.
tfname.Text =
""
138.
tlname.Text =
""
139.
tbdate.Text =
""
140.
taddress.Text =
""
141.
tprovince.Text =
""
142.
ttel.Text =
""
143.
tmobile.Text =
""
144.
temail.Text =
""
145.
tdepartment.Text =
""
146.
tfunction.Text =
""
147.
tposition.Text =
""
148.
149.
End
Sub
150.
Private
Sub
bdelete_Click(
ByVal
sender
As
System.
Object
,
ByVal
e
As
System.EventArgs)
Handles
bdelete.Click
151.
Dim
MsgResult
As
MsgBoxResult
152.
Dim
StrMsg
As
String
153.
If
DS.Tables(0).Rows.Count >= 1
Then
154.
StrMsg =
"คุณต้องการลบข้อมูล [ "
& DS.Tables(0).Rows(posi)(
"id_em"
) &
" ] นี้หรือไม่"
155.
Else
156.
MsgBox(
"ไม่สามารถลบข้อมูลได้เนื่องจากไม่มีข้อมูลใดๆในฐานข้อมูล"
)
157.
Exit
Sub
158.
End
If
159.
160.
MsgResult = MsgBox(StrMsg, MsgBoxStyle.YesNoCancel + MsgBoxStyle.Critical,
"em System"
)
161.
If
MsgResult = MsgBoxResult.Yes
Then
162.
If
DS.Tables(0).Rows.Count >= 2
Then
163.
Dim
cmb
As
New
OleDb.OleDbCommandBuilder(DA)
164.
DS.Tables(
"tb_employee"
).Rows(posi).Delete()
165.
DA.Update(DS,
"tb_employee"
)
166.
MsgBox(
"ลบข้อมูลเรียบร้อยแล้ว !!!"
)
167.
posi = 0
168.
ShowDataUsergroup()
169.
ElseIf
DS.Tables(0).Rows.Count = 1
Then
170.
Dim
cmb
As
New
OleDb.OleDbCommandBuilder(DA)
171.
DS.Tables(
"tb_employee"
).Rows(posi).Delete()
172.
DA.Update(DS,
"tb_employee"
)
173.
MsgBox(
"ลบข้อมูลเรียบร้อยแล้ว!!!"
)
174.
ElseIf
DS.Tables(0).Rows.Count <= 0
Then
175.
MsgBox(
"ไม่สามารถลบข้อมูลได้เนื่องจากไม่มีข้อมูลใดๆในฐานข้อมูล"
)
176.
Exit
Sub
177.
End
If
178.
End
If
179.
End
Sub
180.
181.
End
Class