Imports Microsoft.VisualBasic
Imports System.Data
Imports System.Data.Sql
Imports System.Data.SqlClient
Imports System.Windows.Forms.Application
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim Con As SqlConnection
Dim ConStr As String
ConStr = "Server=user-PC\SQLEXPRESS;Initial Catalog=internetcafe;Integrated Security=SSPI"
Con = New SqlConnection(ConStr)
Con.Open()
Dim OldThreading = System.Threading.Thread.CurrentThread.CurrentCulture
System.Threading.Thread.CurrentThread.CurrentCulture = New System.Globalization.CultureInfo("en-US")
Dim Cmd As SqlCommand
Dim MySQL As String
If TextBox1.Text = "" Then
MySQL = "Insert Into Officer(Name,Surname,Birthday,LoginRight,Username,Password)"
MySQL += "Values(" ' & TextBox2.Text & '","' & TextBox3.Text & '",'"
MySQL += Format(DateTimePicker1.Value, "MM/dd/yyyy") & "'," & CheckBox1.CheckState
MySQL += "," ' & TextBox4.Text & '","' & TextBox5.Text & '")"
Else
MySQL = "update Officer Set Name =" ' & TextBox2.Text & '",Surname="' & TextBox3.Text & '","
MySQL += "Birthday=" ' & Format(DateTimePicker1.Value, "MM/dd/yyyy") & '","
MySQL += "LoginRight=" & CheckBox1.CheckState & ",Username=" ' & TextBox4.Text& '","
MySQL += "Password=" ' & TextBox5.Text&"'Where OfficeID =" & TextBox1.Text
End If
Cmd = New SqlCommand(MySQL, Con)
Cmd.ExecuteNonQuery()
System.Threading.Thread.CurrentThread.CurrentCulture = OldThreading
MsgBox("บันทึกรายการเรียบร้อย")
TextBox1.Clear()
TextBox2.Clear()
TextBox3.Clear()
TextBox4.Clear()
TextBox5.Clear()
CheckBox1.Checked = False
CheckBox2.Checked = True
DateTimePicker1.Value = Today.Date
GroupBox1.Enabled = False
DataGridView1.Enabled = True
Call DisplayDGV()
End Sub
Private Sub DisplayDGV()
Dim Con As SqlConnection
Dim ConStr As String
ConStr = "Server=user-PC\SQLEXPRESS;Initial Catalog=internetcafe;Integrated Security=SSPI"
Con = New SqlConnection(ConStr)
Con.Open()
Dim MySQL As String
MySQL = "select OfficeID รหัส,Name+''+Surname ชื่อสกุล,Birthday วันเกิด,LoginRight สิทธิ์"
MySQL += "from Officer"
Dim DataT As New DataTable
Dim DataA = New SqlDataAdapter(MySQL, Con)
DataA.Fill(DataT)
Me.DataGridView1.DataSource = DataT
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
GroupBox1.Enabled = False
TextBox1.ReadOnly = True
TextBox4.Enabled = False
TextBox5.Enabled = False
CheckBox2.Checked = True
DataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect
Call DisplayDGV()
End Sub
Private Sub DataGridView1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs)
If DataGridView1.RowCount = 0 Then
Exit Sub
End If
TextBox1.Text = DataGridView1.CurrentRow.Cells(0).Value
DataGridView1.Enabled = False
GroupBox1.Enabled = True
End Sub
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
Dim Con As SqlConnection
Dim ConStr As String
ConStr = "Server=user-PC\SQLEXPRESS;Initial Catalog=internetcafe;Integrated Security=SSPI"
Con = New SqlConnection(ConStr)
Con.Open()
Dim MyReader As SqlDataReader
Dim Cmd As SqlCommand
Dim MySQL As String
MySQL = "Select*from Officer Where Officeid=" & Val(TextBox1.Text)
Cmd = New SqlCommand(MySQL, Con)
MyReader = Cmd.ExecuteReader
MyReader.Read()
If MyReader.HasRows Then
TextBox2.Text = MyReader("Name")
TextBox3.Text = MyReader("Surname")
DateTimePicker1.Value = MyReader("Birthday")
CheckBox1.Checked = MyReader("loginright")
TextBox4.Text = MyReader("Username")
TextBox5.Text = MyReader("Password")
End If
Con.Close()
End Sub
Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
If CheckBox1.Checked = True Then
TextBox4.Enabled = True
TextBox5.Enabled = True
Else
TextBox4.Enabled = False
TextBox5.Enabled = False
TextBox4.Clear()
TextBox5.Clear()
End If
End Sub
Private Sub CheckBox2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox2.CheckedChanged
If CheckBox2.Checked = True Then
TextBox5.PasswordChar = "*"
Else
TextBox5.PasswordChar = ""
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim Con As SqlConnection
Dim ConStr As String
ConStr = "Server=user-PC\SQLEXPRESS;Initial Catalog=internetcafe;Integrated Security=SSPI"
Con = New SqlConnection(ConStr)
Con.Open()
Dim Cmd As SqlCommand
Dim MySQL As String
MySQL = "Delete From Officer Where OfficeID =" & TextBox1.Text
If TextBox1.Text <> "" Then
End If
If MsgBox("ท่านต้องการลบฐานข้อมูลนี้ใช้หรือไหม", MsgBoxStyle.Critical + MsgBoxStyle.YesNo) =
MsgBoxResult.Yes Then
Cmd = New SqlCommand(MySQL, Con)
Cmd.ExecuteNonQuery()
Else
End If
TextBox1.Clear()
TextBox2.Clear()
TextBox3.Clear()
TextBox4.Clear()
TextBox5.Clear()
CheckBox1.Checked = False
CheckBox2.Checked = True
DateTimePicker1.Value = Today.Date
GroupBox1.Enabled = False
DataGridView1.Enabled = True
Call DisplayDGV()
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
GroupBox1.Enabled = True
CheckBox1.Checked = False
CheckBox2.Checked = True
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Me.Close()
End Sub
End Class
Private Sub DisplayDGV()
Dim Con As SqlConnection
Dim ConStr As String
ConStr = "Server=user-PC\SQLEXPRESS;Initial Catalog=internetcafe;Integrated Security=SSPI"
Con = New SqlConnection(ConStr)
Con.Open()
Dim MySQL As String
MySQL = "select TableIDรหัส,TableNameโต๊ะบริการ,TableStatusสถานะ"
MySQL += "from Tables"
Dim DataT As New DataTable
Dim DataA = New SqlDataAdapter(MySQL, Con)
DataA.Fill(DataT)
Me.DataGridView1.DataSource = DataT
End Sub
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
Dim Con As SqlConnection
Dim ConStr As String
ConStr = "Server=user-PC\SQLEXPRESS;Initial Catalog=internetcafe;Integrated Security=SSPI"
Con = New SqlConnection(ConStr)
Con.Open()
Dim MyReader As SqlDataReader
Dim Cmd As SqlCommand
Dim MySQL As String
MySQL = "SELECT*from Tables Where TableId=" & Val(TextBox1.Text)
Cmd = New SqlCommand(MySQL, Con)
MyReader = Cmd.ExecuteReader
MyReader.Read()
If MyReader.HasRows Then
TextBox2.Text = MyReader("TableName")
If MyReader("TableStatus") Then
RadioButton1.Checked = True
Else
RadioButton2.Checked = True
End If
End If
Con.Close()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim Con As SqlConnection
Dim ConStr As String
ConStr = "Server=user-PC\SQLEXPRESS;Initial Catalog=internetcafe;Integrated Security=SSPI"
Con = New SqlConnection(ConStr)
Con.Open()
Dim Cmd As SqlCommand
Dim MySQL As String
If TextBox1.Text = "" Then
MySQL = "Insert Into Tables(TableName,TableStatus)"
MySQL += "Values(" ' & TextBox2.Text & '"," & Math.Abs(CInt(RadioButton1.Checked))& ")"
Else
MySQL = "update Tables Set TableName=" ' & TextBox2.Text& '","
MySQL += "TableStatus=" & Math.Abs(CInt(RadioButton1.Checked)) & ""
MySQL += "Where TableID =" & TextBox1.Text
End If
Cmd = New SqlCommand(MySQL, Con)
Cmd.ExecuteNonQuery()
MsgBox("บันทึกรายการเรียบร้อย")
TextBox1.Clear()
TextBox2.Clear()
RadioButton1.Checked = True
GroupBox1.Enabled = False
DataGridView1.Enabled = True
Call DisplayDGV()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim Con As SqlConnection
Dim ConStr As String
ConStr = "Server=user-PC\SQLEXPRESS;Initial Catalog=internetcafe;Integrated Security=SSPI"
Con = New SqlConnection(ConStr)
Con.Open()
Dim Cmd As SqlCommand
Dim MySQL As String
MySQL = "Delecte From Tables Where TableID = " & TextBox1.Text
If TextBox1.Text <> "" Then
If MsgBox("ท่านต้องการลบการนี้จากฐานข้อมูลใช้หรือไม่", MsgBoxStyle.Critical + MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then
Cmd = New SqlCommand(MySQL, Con)
Cmd.ExecuteNonQuery()
Else
End If
Else
End If
TextBox1.Clear()
TextBox2.Clear()
RadioButton1.Checked = True
GroupBox1.Enabled = False
DataGridView1.Enabled = True
Call DisplayDGV()
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
GroupBox1.Enabled = True
RadioButton1.Checked = True
TextBox2.Focus()
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Me.Close()
End Sub
Private Sub DataGridView1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGridView1.DoubleClick
If DataGridView1.RowCount = 0 Then
Exit Sub
End If
TextBox1.Text = DataGridView1.CurrentRow.Cells(0).Value
DataGridView1.Enabled = False
GroupBox1.Enabled = True
End Sub
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
GroupBox1.Enabled = False
Call DisplayDGV()
End Sub
End Class
Imports Microsoft.VisualBasic
Imports System.Data
Imports System.Data.Sql
Imports System.Data.SqlClient
Imports System.Windows.Forms.Application
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim Con As SqlConnection
Dim ConStr As String
ConStr = "Server=user-PC\SQLEXPRESS;Initial Catalog=internetcafe;Integrated Security=SSPI"
Con = New SqlConnection(ConStr)
Con.Open()
Dim OldThreading = System.Threading.Thread.CurrentThread.CurrentCulture
System.Threading.Thread.CurrentThread.CurrentCulture = New System.Globalization.CultureInfo("en-US")
Dim Cmd As SqlCommand
Dim MySQL As String
If TextBox1.Text = "" Then
MySQL = "Insert Into Officer(Name,Surname,Birthday,LoginRight,Username,Password)"
MySQL += "Values(''' & TextBox2.Text & ''',''' & TextBox3.Text & ''','"
MySQL += Format(DateTimePicker1.Value, "MM/dd/yyyy") & "'," & CheckBox1.CheckState
MySQL += ",''' & TextBox4.Text & ''',''' & TextBox5.Text & ''')"
Else
MySQL = "update Officer Set Name =''' & TextBox2.Text &''',Surname=''' & TextBox3.Text &''',"
MySQL += "Birthday=''' & Format(DateTimePicker1.Value, ''MM/dd/yyyy'') &''',"
MySQL += "LoginRight=" & CheckBox1.CheckState & ",Username=''' & TextBox4.Text& ''',"
MySQL += "Password=''' & TextBox5.Text &'''Where OfficeID =" & TextBox1.Text
End If
Cmd = New SqlCommand(MySQL, Con)
Cmd.ExecuteNonQuery()
System.Threading.Thread.CurrentThread.CurrentCulture = OldThreading
MsgBox("บันทึกรายการเรียบร้อย")
TextBox1.Clear()
TextBox2.Clear()
TextBox3.Clear()
TextBox4.Clear()
TextBox5.Clear()
CheckBox1.Checked = False
CheckBox2.Checked = True
DateTimePicker1.Value = Today.Date
GroupBox1.Enabled = False
DataGridView1.Enabled = True
Call DisplayDGV()
End Sub
Private Sub DisplayDGV()
Dim Con As SqlConnection
Dim ConStr As String
ConStr = "Server=user-PC\SQLEXPRESS;Initial Catalog=internetcafe;Integrated Security=SSPI"
Con = New SqlConnection(ConStr)
Con.Open()
Dim MySQL As String
MySQL = "select OfficeID รหัส,Name+''+Surname ชื่อสกุล,Birthday วันเกิด,LoginRight สิทธิ์"
MySQL += "from Officer"
Dim DataT As New DataTable
Dim DataA = New SqlDataAdapter(MySQL, Con)
DataA.Fill(DataT)
Me.DataGridView1.DataSource = DataT
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'InternetcafeDataSet.Officer' table. You can move, or remove it, as needed.
Me.OfficerTableAdapter.Fill(Me.InternetcafeDataSet.Officer)
GroupBox1.Enabled = False
TextBox1.ReadOnly = True
TextBox4.Enabled = False
TextBox5.Enabled = False
CheckBox2.Checked = True
DataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect
Call DisplayDGV()
End Sub
Private Sub DataGridView1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs)
If DataGridView1.RowCount = 0 Then
Exit Sub
End If
TextBox1.Text = DataGridView1.CurrentRow.Cells(0).Value
DataGridView1.Enabled = False
GroupBox1.Enabled = True
End Sub
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
Dim Con As SqlConnection
Dim ConStr As String
ConStr = "Server=user-PC\SQLEXPRESS;Initial Catalog=internetcafe;Integrated Security=SSPI"
Con = New SqlConnection(ConStr)
Con.Open()
Dim MyReader As SqlDataReader
Dim Cmd As SqlCommand
Dim MySQL As String
MySQL = "Select*from Officer Where Officeid=" & Val(TextBox1.Text)
Cmd = New SqlCommand(MySQL, Con)
MyReader = Cmd.ExecuteReader
MyReader.Read()
If MyReader.HasRows Then
TextBox2.Text = MyReader("Name")
TextBox3.Text = MyReader("Surname")
DateTimePicker1.Value = MyReader("Birthday")
CheckBox1.Checked = MyReader("loginright")
TextBox4.Text = MyReader("Username")
TextBox5.Text = MyReader("Password")
End If
Con.Close()
End Sub
Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
If CheckBox1.Checked = True Then
TextBox4.Enabled = True
TextBox5.Enabled = True
Else
TextBox4.Enabled = False
TextBox5.Enabled = False
TextBox4.Clear()
TextBox5.Clear()
End If
End Sub
Private Sub CheckBox2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox2.CheckedChanged
If CheckBox2.Checked = True Then
TextBox5.PasswordChar = "*"
Else
TextBox5.PasswordChar = ""
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim Con As SqlConnection
Dim ConStr As String
ConStr = "Server=user-PC\SQLEXPRESS;Initial Catalog=internetcafe;Integrated Security=SSPI"
Con = New SqlConnection(ConStr)
Con.Open()
Dim Cmd As SqlCommand
Dim MySQL As String
MySQL = "Delete From Officer Where OfficeID =" & TextBox1.Text
If TextBox1.Text <> "" Then
If MsgBox("ท่านต้องการลบฐานข้อมูลนี้ใช้หรือไหม", MsgBoxStyle.Critical + MsgBoxStyle.YesNo) =
MsgBoxResult.Yes Then
Cmd = New SqlCommand(MySQL, Con)
Cmd.ExecuteNonQuery()
Else
End If
Else
End If
TextBox1.Clear()
TextBox2.Clear()
TextBox3.Clear()
TextBox4.Clear()
TextBox5.Clear()
CheckBox1.Checked = False
CheckBox2.Checked = True
DateTimePicker1.Value = Today.Date
GroupBox1.Enabled = False
DataGridView1.Enabled = True
Call DisplayDGV()
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
GroupBox1.Enabled = True
CheckBox1.Checked = False
CheckBox2.Checked = True
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Me.Close()
End Sub
End Class
INSERT INTO Customers (CustomerName, ContactName, Address, City, PostalCode, Country)
VALUES ('Cardinal','Tom B. Erichsen','Skagen 21','Stavanger','4006','Norway')