?? orderinfo.vb
字號:
Imports System
Imports System.Data
Imports System.Drawing
Imports System.Data.SqlClient
Public Class Form6
Inherits System.Windows.Forms.Form
#Region " Windows 窗體設計器生成的代碼 "
Public Sub New()
MyBase.New()
'該調用是 Windows 窗體設計器所必需的。
InitializeComponent()
'在 InitializeComponent() 調用之后添加任何初始化
End Sub
'窗體重寫處置以清理組件列表。
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Windows 窗體設計器所必需的
Private components As System.ComponentModel.IContainer
'注意:以下過程是 Windows 窗體設計器所必需的
'可以使用 Windows 窗體設計器修改此過程。
'不要使用代碼編輯器修改它。
Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents Button2 As System.Windows.Forms.Button
Friend WithEvents Button3 As System.Windows.Forms.Button
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
Friend WithEvents Label2 As System.Windows.Forms.Label
Friend WithEvents TextBox2 As System.Windows.Forms.TextBox
Friend WithEvents Label4 As System.Windows.Forms.Label
Friend WithEvents ComboBox1 As System.Windows.Forms.ComboBox
Friend WithEvents Label5 As System.Windows.Forms.Label
Friend WithEvents DateTimePicker1 As System.Windows.Forms.DateTimePicker
Friend WithEvents ListBox1 As System.Windows.Forms.ListBox
Friend WithEvents Label3 As System.Windows.Forms.Label
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.GroupBox1 = New System.Windows.Forms.GroupBox()
Me.Label3 = New System.Windows.Forms.Label()
Me.ListBox1 = New System.Windows.Forms.ListBox()
Me.DateTimePicker1 = New System.Windows.Forms.DateTimePicker()
Me.Label5 = New System.Windows.Forms.Label()
Me.ComboBox1 = New System.Windows.Forms.ComboBox()
Me.Label4 = New System.Windows.Forms.Label()
Me.TextBox2 = New System.Windows.Forms.TextBox()
Me.Label2 = New System.Windows.Forms.Label()
Me.TextBox1 = New System.Windows.Forms.TextBox()
Me.Label1 = New System.Windows.Forms.Label()
Me.Button1 = New System.Windows.Forms.Button()
Me.Button2 = New System.Windows.Forms.Button()
Me.Button3 = New System.Windows.Forms.Button()
Me.GroupBox1.SuspendLayout()
Me.SuspendLayout()
'
'GroupBox1
'
Me.GroupBox1.Controls.AddRange(New System.Windows.Forms.Control() {Me.Label3, Me.ListBox1, Me.DateTimePicker1, Me.Label5, Me.ComboBox1, Me.Label4, Me.TextBox2, Me.Label2, Me.TextBox1, Me.Label1})
Me.GroupBox1.Location = New System.Drawing.Point(8, 8)
Me.GroupBox1.Name = "GroupBox1"
Me.GroupBox1.Size = New System.Drawing.Size(360, 256)
Me.GroupBox1.TabIndex = 0
Me.GroupBox1.TabStop = False
Me.GroupBox1.Text = "訂單信息"
'
'Label3
'
Me.Label3.Location = New System.Drawing.Point(8, 24)
Me.Label3.Name = "Label3"
Me.Label3.Size = New System.Drawing.Size(80, 24)
Me.Label3.TabIndex = 13
Me.Label3.Text = "已有訂單"
'
'ListBox1
'
Me.ListBox1.ItemHeight = 12
Me.ListBox1.Location = New System.Drawing.Point(8, 48)
Me.ListBox1.Name = "ListBox1"
Me.ListBox1.Size = New System.Drawing.Size(152, 196)
Me.ListBox1.TabIndex = 12
'
'DateTimePicker1
'
Me.DateTimePicker1.Location = New System.Drawing.Point(176, 136)
Me.DateTimePicker1.Name = "DateTimePicker1"
Me.DateTimePicker1.Size = New System.Drawing.Size(168, 21)
Me.DateTimePicker1.TabIndex = 11
'
'Label5
'
Me.Label5.Location = New System.Drawing.Point(176, 160)
Me.Label5.Name = "Label5"
Me.Label5.Size = New System.Drawing.Size(72, 21)
Me.Label5.TabIndex = 9
Me.Label5.Text = "桌號列表"
Me.Label5.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
'
'ComboBox1
'
Me.ComboBox1.Items.AddRange(New Object() {"預定訂單"})
Me.ComboBox1.Location = New System.Drawing.Point(176, 88)
Me.ComboBox1.Name = "ComboBox1"
Me.ComboBox1.Size = New System.Drawing.Size(168, 20)
Me.ComboBox1.TabIndex = 8
Me.ComboBox1.Text = "預定訂單"
'
'Label4
'
Me.Label4.Location = New System.Drawing.Point(176, 112)
Me.Label4.Name = "Label4"
Me.Label4.Size = New System.Drawing.Size(72, 21)
Me.Label4.TabIndex = 6
Me.Label4.Text = "執(zhí)行日期"
Me.Label4.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
'
'TextBox2
'
Me.TextBox2.Location = New System.Drawing.Point(176, 184)
Me.TextBox2.Multiline = True
Me.TextBox2.Name = "TextBox2"
Me.TextBox2.Size = New System.Drawing.Size(168, 64)
Me.TextBox2.TabIndex = 3
Me.TextBox2.Text = ""
'
'Label2
'
Me.Label2.Location = New System.Drawing.Point(176, 64)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(72, 21)
Me.Label2.TabIndex = 2
Me.Label2.Text = "訂單類型"
Me.Label2.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
'
'TextBox1
'
Me.TextBox1.Location = New System.Drawing.Point(176, 40)
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.Size = New System.Drawing.Size(168, 21)
Me.TextBox1.TabIndex = 1
Me.TextBox1.Text = ""
'
'Label1
'
Me.Label1.Location = New System.Drawing.Point(176, 16)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(72, 21)
Me.Label1.TabIndex = 0
Me.Label1.Text = "訂單編碼"
Me.Label1.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
'
'Button1
'
Me.Button1.FlatStyle = System.Windows.Forms.FlatStyle.Flat
Me.Button1.ForeColor = System.Drawing.Color.Navy
Me.Button1.Location = New System.Drawing.Point(184, 272)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(56, 32)
Me.Button1.TabIndex = 1
Me.Button1.Text = "添加"
'
'Button2
'
Me.Button2.FlatStyle = System.Windows.Forms.FlatStyle.Flat
Me.Button2.ForeColor = System.Drawing.Color.Navy
Me.Button2.Location = New System.Drawing.Point(248, 272)
Me.Button2.Name = "Button2"
Me.Button2.Size = New System.Drawing.Size(56, 32)
Me.Button2.TabIndex = 2
Me.Button2.Text = "刪除"
'
'Button3
'
Me.Button3.FlatStyle = System.Windows.Forms.FlatStyle.Flat
Me.Button3.ForeColor = System.Drawing.Color.Navy
Me.Button3.Location = New System.Drawing.Point(312, 272)
Me.Button3.Name = "Button3"
Me.Button3.Size = New System.Drawing.Size(56, 32)
Me.Button3.TabIndex = 3
Me.Button3.Text = "更新"
'
'Form6
'
Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
Me.ClientSize = New System.Drawing.Size(376, 309)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Button3, Me.Button2, Me.Button1, Me.GroupBox1})
Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle
Me.Name = "Form6"
Me.Text = "預定訂單"
Me.GroupBox1.ResumeLayout(False)
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Dim sqlstr As String
Dim order As New PreOrder()
order = GetDataFromForm()
If order.id = "" Then
Exit Sub
End If
If order.num = "" Then
Exit Sub
End If
sqlstr = "INSERT INTO OrderInfo (orderid,orderstyle," & _
"orderdate,requiredate,tbnum) VALUES ('" & order.id & "'," & _
"'" & order.style & "','" & CDate(Now.ToShortDateString) & "'," & _
"'" & order.rdate & "','" & order.num & "')"
UpdateData(sqlstr)
GetAllData()
ShowData(0)
AlterStatus(True)
End Sub
Public Sub GetAllData()
Dim sqlstr As String
Dim ds As New DataSet()
ds.Clear()
Me.ListBox1.Items.Clear()
sqlstr = "SELECT orderid FROM OrderInfo WHERE orderstyle='預定'"
ds = GetDataFromDB(sqlstr)
Dim i As Integer
Dim temp As String
If Not ds Is Nothing Then
For i = 0 To ds.Tables(0).Rows.Count - 1
temp = Trim(ds.Tables(0).Rows(i)("orderid").ToString)
Me.ListBox1.Items.Add(temp)
Next
End If
End Sub
Public Function GetDataFromForm() As PreOrder
Dim order As New PreOrder()
order.id = Trim(Me.TextBox1.Text)
order.rdate = CDate(Me.DateTimePicker1.Value.ToShortDateString)
order.num = Trim(Me.TextBox2.Text)
Return order
End Function
Private Sub Button2_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button2.Click
Dim sqlstr As String
sqlstr = "DELETE FROM OrderInfo WHERE orderid=" & _
"'" & Me.TextBox1.Text.Trim & "'"
UpdateData(sqlstr)
AlterStatus(False)
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button3.Click
Dim order As New PreOrder()
order = GetDataFromForm()
If order.id = "" Then
Exit Sub
End If
Dim sqlstr As String
With order
sqlstr = "UPDATE OrderInfo SET requiredate ='" & .rdate & "'," & _
"tbnum='" & .num & "' WHERE orderid='" & .id & "'"
End With
UpdateData(sqlstr)
AlterStatus(True)
End Sub
Private Sub Form6_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
GetAllData()
If Me.ListBox1.Items.Count > 0 Then
Me.ListBox1.SetSelected(0, True)
ShowData(0)
End If
End Sub
Public Function ShowData(ByVal index As Integer)
If index >= 0 Then
Dim order As New PreOrder()
order = getOrder(Trim(Me.ListBox1.SelectedItem.ToString))
Me.TextBox1.Text = order.id
Me.DateTimePicker1.Value = order.rdate
Me.TextBox2.Text = order.num
End If
End Function
Public Function getOrder(ByVal orderid As String) As PreOrder
Dim sqlstr As String
Dim order As New PreOrder()
sqlstr = "SELECT * FROM OrderInfo WHERE orderid='" & orderid & "'"
Dim ds As New DataSet()
ds.Clear()
ds = GetDataFromDB(sqlstr)
If Not ds Is Nothing Then
order.id = ds.Tables(0).Rows(0)("orderid")
order.rdate = ds.Tables(0).Rows(0)("requiredate")
order.num = ds.Tables(0).Rows(0)("tbnum")
End If
Return order
End Function
Private Sub ListBox1_SelectedIndexChanged(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
Dim i As Integer
i = Me.ListBox1.SelectedIndex
If i >= 0 Then
ShowData(i)
End If
End Sub
Public Sub AlterStatus(ByVal add As Boolean)
Dim temp As String
Dim str As String
Dim num As Integer
temp = Trim(Me.TextBox2.Text)
Do While temp.Length > 0
If temp.Length = 1 Then
num = CInt(temp)
Else
str = temp.Substring(0, temp.IndexOf(","))
num = CInt(str.Trim)
temp = temp.Remove(0, str.Length + 1)
End If
Dim sqlstr As String
If add = True Then
sqlstr = "UPDATE TableInfo SET status='被預定'" & _
" WHERE tablenum='" & num & "'"
Else
sqlstr = "UPDATE TableInfo SET status='空閑' " & _
"WHERE tablenum='" & num & "'"
End If
UpdateData(sqlstr)
Loop
End Sub
End Class
Public Class PreOrder
Public id As String
Public Const style As String = "預定"
Public rdate As Date
Public num As String
End Class
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -