Imports System.Data
Imports System.Data.OleDb
Public Class Orderfood
Dim Conn As New OleDbConnection
Dim cm As OleDbCommand
Dim dr As OleDbDataReader
Dim ds As DataSet
Dim da As OleDbDataAdapter
Dim strSQL As String
Dim procode, Maxcode As Integer
Private Sub Orderfood_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Conn = New OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\user\Documents\Visual Studio 2012\Projects\RESTAURANT SYSTEM KUNGTENT\DATA.accdb")
Conn.Open()
strSQL = "select id_food,name_food,type,price,unit from Food"
ds = New DataSet
cm = New OleDb.OleDbCommand(strSQL, Conn)
da = New OleDbDataAdapter(cm)
da.Fill(ds, "Food")
dr = cm.ExecuteReader
DataGridView1.DataSource = ds.Tables("Food")
DataGridView1.Columns(0).HeaderText = "รหัสอาหาร"
DataGridView1.Columns(1).HeaderText = "ชื่ออาหาร"
DataGridView1.Columns(2).HeaderText = "ประเภทอาหาร"
DataGridView1.Columns(3).HeaderText = "ราคา / หน่วย"
DataGridView1.Columns(4).HeaderText = "หน่วยนับ"
End Sub
Private Sub DataGridView1_CellMouseClick(ByVal sender As Object, ByVal e As DataGridViewCellMouseEventArgs) Handles DataGridView1.CellMouseClick
fm14.TextBox1.Text = DataGridView1.Rows(e.RowIndex).Cells(0).Value
fm14.TextBox2.Text = DataGridView1.Rows(e.RowIndex).Cells(1).Value
fm14.TextBox3.Text = DataGridView1.Rows(e.RowIndex).Cells(3).Value
fm14.Label7.Text = DataGridView1.Rows(e.RowIndex).Cells(4).Value
fm14.TextBox4.Clear()
fm14.TextBox9.Clear()
Me.Close()
End Sub
End Class
แนะนำให้ ประกาศตัวแปร แบบ public ใน Orderfood ครับ
แล้วให้ fm14 เอา ตัวแปร แบบ public ใน Orderfood ไปใช้งาน
Code (VB.NET)
Imports System.Data
Imports System.Data.OleDb
Public Class Orderfood
Dim Conn As New OleDbConnection
Dim cm As OleDbCommand
Dim dr As OleDbDataReader
Dim ds As DataSet
Dim da As OleDbDataAdapter
Dim strSQL As String
Dim procode, Maxcode As Integer
Private Sub Orderfood_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Conn = New OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\user\Documents\Visual Studio 2012\Projects\RESTAURANT SYSTEM KUNGTENT\DATA.accdb")
Conn.Open()
strSQL = "select id_food,name_food,type,price,unit from Food"
ds = New DataSet
cm = New OleDb.OleDbCommand(strSQL, Conn)
da = New OleDbDataAdapter(cm)
da.Fill(ds, "Food")
dr = cm.ExecuteReader
DataGridView1.DataSource = ds.Tables("Food")
DataGridView1.Columns(0).HeaderText = "รหัสอาหาร"
DataGridView1.Columns(1).HeaderText = "ชื่ออาหาร"
DataGridView1.Columns(2).HeaderText = "ประเภทอาหาร"
DataGridView1.Columns(3).HeaderText = "ราคา / หน่วย"
DataGridView1.Columns(4).HeaderText = "หน่วยนับ"
End Sub
Public v_1 As String
Public v_2 As String
Public v_3 As String
Public v_4 As String
Private Sub DataGridView1_CellMouseClick(ByVal sender As Object, ByVal e As DataGridViewCellMouseEventArgs) Handles DataGridView1.CellMouseClick
v_1 = DataGridView1.Rows(e.RowIndex).Cells(0).Value
v_2 = DataGridView1.Rows(e.RowIndex).Cells(1).Value
v_3 = DataGridView1.Rows(e.RowIndex).Cells(3).Value
v_4 = DataGridView1.Rows(e.RowIndex).Cells(4).Value
Me.Close()
End Sub
End Class
Imports System.Data
Imports System.Data.OleDb
Public Class Orderfood
Dim Conn As New OleDbConnection
Dim cm As OleDbCommand
Dim dr As OleDbDataReader
Dim ds As DataSet
Dim da As OleDbDataAdapter
Dim strSQL As String
Dim procode, Maxcode As Integer
Private Sub Orderfood_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Conn = New OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\user\Documents\Visual Studio 2012\Projects\RESTAURANT SYSTEM KUNGTENT\DATA.accdb")
Conn.Open()
strSQL = "select id_food,name_food,type,price,unit from Food"
ds = New DataSet
cm = New OleDb.OleDbCommand(strSQL, Conn)
da = New OleDbDataAdapter(cm)
da.Fill(ds, "Food")
dr = cm.ExecuteReader
DataGridView1.DataSource = ds.Tables("Food")
DataGridView1.Columns(0).HeaderText = "รหัสอาหาร"
DataGridView1.Columns(1).HeaderText = "ชื่ออาหาร"
DataGridView1.Columns(2).HeaderText = "ประเภทอาหาร"
DataGridView1.Columns(3).HeaderText = "ราคา / หน่วย"
DataGridView1.Columns(4).HeaderText = "หน่วยนับ"
End Sub
Public v_1 As String
Public v_2 As String
Public v_3 As String
Public v_4 As String
Private Sub DataGridView1_CellMouseClick(ByVal sender As Object, ByVal e As DataGridViewCellMouseEventArgs) Handles DataGridView1.CellMouseClick
v_1 = DataGridView1.Rows(e.RowIndex).Cells(0).Value
v_2 = DataGridView1.Rows(e.RowIndex).Cells(1).Value
v_3 = DataGridView1.Rows(e.RowIndex).Cells(3).Value
v_4 = DataGridView1.Rows(e.RowIndex).Cells(4).Value
Me.Close()
End Sub
End Class
Code (VB.NET)
Imports System.Data
Imports System.Data.OleDb
Public Class fm14
Private Sub Event ซักอย่าง
Dim f As New Orderfood
f.ShowDialog()
TextBox1.Text = f.v_1
TextBox2.Text = f.v_2
TextBox3.Text = f.v_3
Label7.Text = f.v_4
TextBox4.Clear()
TextBox9.Clear()
End Sub
End Class
Imports System.Data
Imports System.Data.OleDb
Public Class fm14
Dim Conn As New OleDbConnection
Dim Dr As OleDbDataReader
Dim cm As OleDbCommand
Dim DS As New DataSet
Dim DA As OleDbDataAdapter
Dim strSQL As String
Dim procode, Maxcode As Integer
Private Sub statustable_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Conn = New OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\user\Documents\Visual Studio 2012\Projects\RESTAURANT SYSTEM KUNGTENT\DATA.accdb")
Conn.Open()
Button2.Enabled = False
Call select1()
Call autocode()
Timer1.Enabled = True
Call FF()
End Sub
Private Sub Button25_Click(sender As Object, e As EventArgs) Handles Button25.Click
Orderfood.ShowDialog()
Button2.Enabled = True
End Sub
Private Sub autocode()
'เลขรหัสสั่งซื้อ อัตโนมัติ
If T.Text <> "" Then
cm = New OleDbCommand("select max(tid)As Maxcode from Ordersave", Conn)
Dr = cm.ExecuteReader
Dr.Read()
If Dr.Item("Maxcode") Is DBNull.Value Then
TextBox8.Text = "0001"
Else
procode = Dr.Item("Maxcode") + 1
Select Case procode
Case Is < 10
TextBox8.Text = "000" & procode
Case Is < 100
TextBox8.Text = "00" & procode
Case Is < 1000
TextBox8.Text = "0" & procode
Case Is < 10000
TextBox8.Text = procode
End Select
End If
End If
End Sub
Private Sub select1()
'แสดงข้อมูลในgrid
strSQL = "select tid,id_food,name_food,price,amouth,unit,total from Orderlist where idtable='" & T.Text & "'"
ds = New DataSet
cm = New OleDb.OleDbCommand(strSQL, Conn)
DA = New OleDbDataAdapter(cm)
DA.Fill(DS, "Orderlist")
dr = cm.ExecuteReader
DataGridView1.DataSource = ds.Tables("Orderlist")
''กำหนดชื่อของหัวตาราง
DataGridView1.Columns(0).HeaderText = "รหัสการสั่ง"
DataGridView1.Columns(1).HeaderText = "รหัส"
DataGridView1.Columns(2).HeaderText = "รายการ"
DataGridView1.Columns(3).HeaderText = "ราคา"
DataGridView1.Columns(4).HeaderText = "จำนวณ"
DataGridView1.Columns(5).HeaderText = "หน่วยนับ"
DataGridView1.Columns(6).HeaderText = "ราคารวม"
End Sub
Private Sub FF()
If T.Text <> "" Then
Call select1()
End If
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
ordredrinks.Show()
Button2.Enabled = True
End Sub
Private Sub TextBox4_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox4.KeyDown
If e.KeyCode = Keys.Enter Then
TextBox9.Text = TextBox3.Text * TextBox4.Text
Button2.Enabled = True
End If
End Sub
Private Sub DataGridView1_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick
Button2.Enabled = True
Button26.Enabled = True
Button27.Enabled = True
TextBox8.Text = DataGridView1.Rows(e.RowIndex).Cells(0).Value.ToString
TextBox1.Text = DataGridView1.Rows(e.RowIndex).Cells(1).Value.ToString
TextBox2.Text = DataGridView1.Rows(e.RowIndex).Cells(2).Value.ToString
TextBox3.Text = DataGridView1.Rows(e.RowIndex).Cells(3).Value.ToString
TextBox4.Text = DataGridView1.Rows(e.RowIndex).Cells(4).Value.ToString
Label7.Text = DataGridView1.Rows(e.RowIndex).Cells(5).Value.ToString
TextBox9.Text = DataGridView1.Rows(e.RowIndex).Cells(6).Value.ToString
End Sub
Private Sub statustable_Show(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shown
Timer1.Enabled = True
Call FF()
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
If T.Text <> "" Then
'บันทึกในตารางสำรอง
strSQL = "Insert Into Orderlist values('" & TextBox8.Text & "','" & T.Text & "','" & TextBox1.Text & "' ,'" & TextBox2.Text & "','" & TextBox3.Text & "' ,'" & TextBox4.Text & "' ,'" & Label7.Text & "','" & TextBox9.Text & "')"
cm = New OleDb.OleDbCommand(strSQL, Conn)
Dr = cm.ExecuteReader
'บันทึกในตารางจริง
strSQL = "Insert Into Ordersave values('" & TextBox8.Text & "','" & T.Text & "','" & TextBox1.Text & "' ,'" & TextBox2.Text & "','" & TextBox3.Text & "' ,'" & TextBox4.Text & "' ,'" & Label7.Text & "','" & TextBox9.Text & "')"
cm = New OleDb.OleDbCommand(strSQL, Conn)
Dr = cm.ExecuteReader
'เคลียร์
TextBox1.Clear()
TextBox2.Clear()
TextBox3.Clear()
TextBox4.Clear()
TextBox9.Clear()
Label7.Text = ""
Call select1()
Call autocode()
Button2.Enabled = True
End If
End Sub
Private Sub Button26_Click(sender As Object, e As EventArgs) Handles Button26.Click
If T.Text <> "" Then
'แก้ไขตารางสำรอง
strSQL = "Update Orderlist Set amouth='" & TextBox4.Text & "',total='" & TextBox9.Text & "'where tid='" & TextBox8.Text & "'"
cm = New OleDb.OleDbCommand(strSQL, Conn)
cm.ExecuteNonQuery()
'แก้ไขตารางจริง
strSQL = "Update Ordersave Set amouth='" & TextBox4.Text & "',total='" & TextBox9.Text & "'where tid='" & TextBox8.Text & "'"
cm = New OleDb.OleDbCommand(strSQL, Conn)
cm.ExecuteNonQuery()
MsgBox("ได้ทำการแก้ไขข้อมูลแล้ว", MsgBoxStyle.OkOnly, "Update")
'เคลียร์
Button26.Enabled = False
Button27.Enabled = False
TextBox1.Clear()
TextBox2.Clear()
TextBox3.Clear()
TextBox4.Clear()
TextBox9.Clear()
Label7.Text = ""
Call select1()
Call autocode()
End If
End Sub
Private Sub Button27_Click(sender As Object, e As EventArgs) Handles Button27.Click
If T.Text <> " " Then
If MsgBox("คุณต้องการลบข้อมูล หรือไม่", vbYesNo, "Delete") = vbYes Then
'ลบข้อมูลในตารางสำรอง
strSQL = "Delete From Orderlist Where tid = '" & TextBox8.Text & "'"
cm = New OleDb.OleDbCommand(strSQL, Conn)
cm.ExecuteNonQuery()
'ลบข้อมูลในตารางจริง
strSQL = "Delete From Ordersave Where tid = '" & TextBox8.Text & "'"
cm = New OleDb.OleDbCommand(strSQL, Conn)
cm.ExecuteNonQuery()
MsgBox("ลบข้อมูลเรียบร้อย", MsgBoxStyle.OkOnly, "Delete")
Button26.Enabled = False
Button27.Enabled = False
TextBox1.Clear()
TextBox2.Clear()
TextBox3.Clear()
TextBox4.Clear()
TextBox9.Clear()
Call select1()
Call autocode()
End If
End If
End Sub
Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
Button26.Enabled = False
Button27.Enabled = False
'เคลียร์
TextBox1.Clear()
TextBox2.Clear()
TextBox3.Clear()
TextBox4.Clear()
TextBox9.Clear()
Label7.Text = ""
Call select1()
Call autocode()
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
TextBox6.Text = ("วันที่ :") & DateTime.Today & (" เวลา :") & Now.ToLongTimeString
End Sub
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
Payment.T.Text = T.Text
Payment.Show()
Me.Hide()
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Me.Close()
End Sub
Private Sub TextBox2_TextChanged(sender As Object, e As EventArgs)
End Sub
End Class
Private Sub Button25_Click(sender As Object, e As EventArgs) Handles Button25.Click
Dim f As New Orderfood
f.ShowDialog()
TextBox1.Text = f.v_1
TextBox2.Text = f.v_2
TextBox3.Text = f.v_3
Label7.Text = f.v_4
TextBox4.Clear()
TextBox9.Clear()
End Sub