001.
Imports
Microsoft.VisualBasic
002.
Imports
System.Data
003.
Imports
System.Data.Sql
004.
Imports
System.Data.SqlClient
005.
Imports
System.Windows.Forms.Application
006.
007.
Public
Class
Form1
008.
009.
Private
Sub
Button1_Click(
ByVal
sender
As
System.
Object
,
ByVal
e
As
System.EventArgs)
Handles
Button1.Click
010.
011.
Dim
Con
As
SqlConnection
012.
Dim
ConStr
As
String
013.
014.
ConStr =
"Server=user-PC\SQLEXPRESS;Initial Catalog=internetcafe;Integrated Security=SSPI"
015.
Con =
New
SqlConnection(ConStr)
016.
Con.Open()
017.
018.
019.
Dim
OldThreading = System.Threading.Thread.CurrentThread.CurrentCulture
020.
System.Threading.Thread.CurrentThread.CurrentCulture =
New
System.Globalization.CultureInfo(
"en-US"
)
021.
022.
Dim
Cmd
As
SqlCommand
023.
Dim
MySQL
As
String
024.
025.
If
TextBox1.Text =
""
Then
026.
027.
MySQL =
"Insert Into Officer(Name,Surname,Birthday,LoginRight,Username,Password)"
028.
MySQL +=
"Values(''' & TextBox2.Text & ''',''' & TextBox3.Text & ''','"
029.
MySQL += Format(DateTimePicker1.Value,
"MM/dd/yyyy"
) &
"',"
& CheckBox1.CheckState
030.
MySQL +=
",''' & TextBox4.Text & ''',''' & TextBox5.Text & ''')"
031.
032.
Else
033.
034.
MySQL =
"update Officer Set Name =''' & TextBox2.Text &''',Surname=''' & TextBox3.Text &''',"
035.
MySQL +=
"Birthday=''' & Format(DateTimePicker1.Value, ''MM/dd/yyyy'') &''',"
036.
MySQL +=
"LoginRight="
& CheckBox1.CheckState &
",Username=''' & TextBox4.Text& ''',"
037.
MySQL +=
"Password=''' & TextBox5.Text &'''Where OfficeID ="
& TextBox1.Text
038.
039.
End
If
040.
041.
Cmd =
New
SqlCommand(MySQL, Con)
042.
Cmd.ExecuteNonQuery()
043.
System.Threading.Thread.CurrentThread.CurrentCulture = OldThreading
044.
MsgBox(
"บันทึกรายการเรียบร้อย"
)
045.
046.
TextBox1.Clear()
047.
TextBox2.Clear()
048.
TextBox3.Clear()
049.
TextBox4.Clear()
050.
TextBox5.Clear()
051.
CheckBox1.Checked =
False
052.
CheckBox2.Checked =
True
053.
DateTimePicker1.Value = Today.
Date
054.
GroupBox1.Enabled =
False
055.
DataGridView1.Enabled =
True
056.
Call
DisplayDGV()
057.
058.
End
Sub
059.
Private
Sub
DisplayDGV()
060.
061.
Dim
Con
As
SqlConnection
062.
Dim
ConStr
As
String
063.
064.
ConStr =
"Server=user-PC\SQLEXPRESS;Initial Catalog=internetcafe;Integrated Security=SSPI"
065.
Con =
New
SqlConnection(ConStr)
066.
Con.Open()
067.
068.
Dim
MySQL
As
String
069.
MySQL =
"select OfficeID รหัส,Name+''+Surname ชื่อสกุล,Birthday วันเกิด,LoginRight สิทธิ์"
070.
MySQL +=
"from Officer"
071.
072.
Dim
DataT
As
New
DataTable
073.
Dim
DataA =
New
SqlDataAdapter(MySQL, Con)
074.
DataA.Fill(DataT)
075.
Me
.DataGridView1.DataSource = DataT
076.
077.
End
Sub
078.
Private
Sub
Form1_Load(
ByVal
sender
As
System.
Object
,
ByVal
e
As
System.EventArgs)
Handles
MyBase
.Load
079.
080.
Me
.OfficerTableAdapter.Fill(
Me
.InternetcafeDataSet.Officer)
081.
GroupBox1.Enabled =
False
082.
TextBox1.
ReadOnly
=
True
083.
TextBox4.Enabled =
False
084.
TextBox5.Enabled =
False
085.
CheckBox2.Checked =
True
086.
DataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect
087.
Call
DisplayDGV()
088.
End
Sub
089.
Private
Sub
DataGridView1_DoubleClick(
ByVal
sender
As
Object
,
ByVal
e
As
System.EventArgs)
090.
If
DataGridView1.RowCount = 0
Then
091.
Exit
Sub
092.
End
If
093.
TextBox1.Text = DataGridView1.CurrentRow.Cells(0).Value
094.
DataGridView1.Enabled =
False
095.
GroupBox1.Enabled =
True
096.
End
Sub
097.
098.
Private
Sub
TextBox1_TextChanged(
ByVal
sender
As
System.
Object
,
ByVal
e
As
System.EventArgs)
Handles
TextBox1.TextChanged
099.
Dim
Con
As
SqlConnection
100.
Dim
ConStr
As
String
101.
102.
ConStr =
"Server=user-PC\SQLEXPRESS;Initial Catalog=internetcafe;Integrated Security=SSPI"
103.
Con =
New
SqlConnection(ConStr)
104.
Con.Open()
105.
106.
Dim
MyReader
As
SqlDataReader
107.
Dim
Cmd
As
SqlCommand
108.
Dim
MySQL
As
String
109.
MySQL =
"Select*from Officer Where Officeid="
& Val(TextBox1.Text)
110.
Cmd =
New
SqlCommand(MySQL, Con)
111.
MyReader = Cmd.ExecuteReader
112.
MyReader.Read()
113.
If
MyReader.HasRows
Then
114.
115.
TextBox2.Text = MyReader(
"Name"
)
116.
TextBox3.Text = MyReader(
"Surname"
)
117.
DateTimePicker1.Value = MyReader(
"Birthday"
)
118.
CheckBox1.Checked = MyReader(
"loginright"
)
119.
TextBox4.Text = MyReader(
"Username"
)
120.
TextBox5.Text = MyReader(
"Password"
)
121.
End
If
122.
Con.Close()
123.
124.
End
Sub
125.
Private
Sub
CheckBox1_CheckedChanged(
ByVal
sender
As
System.
Object
,
ByVal
e
As
System.EventArgs)
Handles
CheckBox1.CheckedChanged
126.
If
CheckBox1.Checked =
True
Then
127.
128.
TextBox4.Enabled =
True
129.
TextBox5.Enabled =
True
130.
Else
131.
TextBox4.Enabled =
False
132.
TextBox5.Enabled =
False
133.
TextBox4.Clear()
134.
TextBox5.Clear()
135.
End
If
136.
End
Sub
137.
138.
Private
Sub
CheckBox2_CheckedChanged(
ByVal
sender
As
System.
Object
,
ByVal
e
As
System.EventArgs)
Handles
CheckBox2.CheckedChanged
139.
If
CheckBox2.Checked =
True
Then
140.
TextBox5.PasswordChar =
"*"
141.
Else
142.
TextBox5.PasswordChar =
""
143.
End
If
144.
End
Sub
145.
Private
Sub
Button2_Click(
ByVal
sender
As
System.
Object
,
ByVal
e
As
System.EventArgs)
Handles
Button2.Click
146.
Dim
Con
As
SqlConnection
147.
Dim
ConStr
As
String
148.
149.
ConStr =
"Server=user-PC\SQLEXPRESS;Initial Catalog=internetcafe;Integrated Security=SSPI"
150.
Con =
New
SqlConnection(ConStr)
151.
Con.Open()
152.
153.
Dim
Cmd
As
SqlCommand
154.
Dim
MySQL
As
String
155.
MySQL =
"Delete From Officer Where OfficeID ="
& TextBox1.Text
156.
157.
If
TextBox1.Text <>
""
Then
158.
159.
If
MsgBox(
"ท่านต้องการลบฐานข้อมูลนี้ใช้หรือไหม"
, MsgBoxStyle.Critical + MsgBoxStyle.YesNo) =
160.
MsgBoxResult.Yes
Then
161.
Cmd =
New
SqlCommand(MySQL, Con)
162.
Cmd.ExecuteNonQuery()
163.
Else
164.
165.
End
If
166.
167.
Else
168.
End
If
169.
170.
171.
TextBox1.Clear()
172.
TextBox2.Clear()
173.
TextBox3.Clear()
174.
TextBox4.Clear()
175.
TextBox5.Clear()
176.
CheckBox1.Checked =
False
177.
CheckBox2.Checked =
True
178.
DateTimePicker1.Value = Today.
Date
179.
GroupBox1.Enabled =
False
180.
DataGridView1.Enabled =
True
181.
Call
DisplayDGV()
182.
183.
184.
185.
End
Sub
186.
187.
Private
Sub
Button3_Click(
ByVal
sender
As
System.
Object
,
ByVal
e
As
System.EventArgs)
Handles
Button3.Click
188.
GroupBox1.Enabled =
True
189.
CheckBox1.Checked =
False
190.
CheckBox2.Checked =
True
191.
192.
End
Sub
193.
194.
Private
Sub
Button4_Click(
ByVal
sender
As
System.
Object
,
ByVal
e
As
System.EventArgs)
Handles
Button4.Click
195.
Me
.Close()
196.
End
Sub
197.
End
Class