📄 frmsite.vb
字号:
strRe = "停用"
Case "使用"
strRe = "U"
Case "结帐"
strRe = "B"
Case "空闲"
strRe = "F"
Case "预订"
strRe = "O"
Case "停用"
strRe = "T"
Case Else
strRe = "Error!"
End Select
Return strRe
End Function
Private Sub cmbStatus_SelectedIndexChanged(ByVal sender As Object, ByVal e As _
System.EventArgs) Handles cmbStatus.SelectedIndexChanged
'状态变化时进行验证
Select Case OrigStatus
Case "O"
Select Case ConvertStatus(Trim(cmbStatus.Text))
Case "B"
'预订 —> 结帐非法
MsgBox("与订的餐位不能变为结帐餐位!", MsgBoxStyle.Exclamation)
cmbStatus.Text = "预订"
btnOK.Focus()
Case "U"
'预订 -> 使用
OrigStatus = "U"
MsgBox("客人已到,转为使用餐位!", MsgBoxStyle.Information)
'调用点菜操作
GetDish()
'点菜之后输入人数
txtPer.Focus()
Case "T"
'预订 -> 停用非法
MsgBox("与订的餐位不能变为停用餐位!", MsgBoxStyle.Exclamation)
cmbStatus.Text = "预订"
btnOK.Focus()
Case "F"
'预订 -> 空闲
OrigStatus = "F"
MsgBox("预订餐位被取消!转为空闲餐位!", MsgBoxStyle.Information)
btnOK.Focus()
End Select
Case "B"
If Not (ConvertStatus(Trim(cmbStatus.Text)) = "F" Or _
ConvertStatus(Trim(cmbStatus.Text)) = "B") Then
'结帐餐位不能变为停用、预订或者使用状态
MsgBox("结帐的餐位只能变为空闲餐位!", MsgBoxStyle.Exclamation)
cmbStatus.Text = "结帐"
btnOK.Focus()
ElseIf ConvertStatus(Trim(cmbStatus.Text)) = "F" Then
'结帐 -> 空闲,说明结帐完毕,清除消费记录
btnOK.Focus()
MsgBox("结帐的餐位变为空闲餐位!", MsgBoxStyle.Information)
OrigStatus = "F"
txtPer.Text = "0人"
txtDish.Text = "0道"
txtDiscount.Text = "0元"
txtMoney.Text = "0元"
lvwGetDish.Items.Clear()
lvwSiteOpre.Items.Clear()
lvwSiteOpre.Refresh()
lvwGetDish.Visible = False
lvwSiteOpre.Visible = True
End If
Case "U"
If Not (ConvertStatus(Trim(cmbStatus.Text)) = "U" Or _
ConvertStatus(Trim(cmbStatus.Text)) = "B") Then
'使用餐位不能转为空闲、停用或者预订
MsgBox("使用的餐位只能变为结帐餐位!", MsgBoxStyle.Exclamation)
cmbStatus.Text = "使用"
btnOK.Focus()
ElseIf ConvertStatus(Trim(cmbStatus.Text)) = "B" Then
'使用 -> 结帐,可以适当优惠,优惠文本框可用
MsgBox("使用的餐位变为结帐餐位!", MsgBoxStyle.Information)
OrigStatus = "B"
txtDiscount.ReadOnly = False
txtDiscount.Focus()
End If
Case "F"
Select Case ConvertStatus(Trim(cmbStatus.Text))
Case "B"
'空闲 -> 结帐非法
MsgBox("空闲的餐位不能变为结帐餐位!", MsgBoxStyle.Exclamation)
cmbStatus.Text = "空闲"
btnOK.Focus()
Case "U"
'空闲 -> 使用
OrigStatus = "U"
MsgBox("有客人,转为使用餐位!", MsgBoxStyle.Information)
'点菜
GetDish()
'输入用餐人数
txtPer.Focus()
Case "T"
'空闲 -> 停用
OrigStatus = "T"
MsgBox("空闲的餐位被停用,转为停用餐位!", MsgBoxStyle.Information)
btnOK.Focus()
Case "O"
'空闲 -> 预订
OrigStatus = "O"
MsgBox("空闲的餐位被预订!转为预订餐位!", MsgBoxStyle.Information)
btnOK.Focus()
End Select
Case "T"
'停用餐位只能变为空闲状态
If Not (ConvertStatus(Trim(cmbStatus.Text)) = "F" Or _
ConvertStatus(Trim(cmbStatus.Text)) = "T") Then
MsgBox("停用的餐位只能变为空闲餐位!", MsgBoxStyle.Exclamation)
cmbStatus.Text = "停用"
btnOK.Focus()
ElseIf ConvertStatus(Trim(cmbStatus.Text)) = "F" Then
MsgBox("停用的餐位变为空闲餐位!", MsgBoxStyle.Information)
OrigStatus = "F"
btnOK.Focus()
End If
End Select
End Sub
Private Sub GetDish()
'点菜操作
'菜单列表视图不可见
'点菜列表视图可见
lvwSiteOpre.Visible = False
lvwGetDish.Visible = True
'调整点菜列表视图的位置
lvwGetDish.Top = lvwSiteOpre.Top
lvwGetDish.Left = lvwSiteOpre.Left
lvwGetDish.Width = lvwSiteOpre.Width
lvwGetDish.Height = lvwSiteOpre.Height
lvwGetDish.MultiSelect = True
lvwGetDish.CheckBoxes = True
'用餐人数文本框和菜数文本框可用
txtPer.ReadOnly = False
txtDish.ReadOnly = False
'为点菜列表视图添加列名
lvwGetDish.Columns.Add(" ", lvwGetDish.Width / 10, HorizontalAlignment.Center)
lvwGetDish.Columns.Add("菜 名", 3 * lvwGetDish.Width / 10, _
HorizontalAlignment.Center)
lvwGetDish.Columns.Add("价 格", 3 * lvwGetDish.Width / 10, _
HorizontalAlignment.Center)
lvwGetDish.Columns.Add("类 型", 3 * lvwGetDish.Width / 10, _
HorizontalAlignment.Center)
lvwGetDish.Columns.Add(" ", 0, HorizontalAlignment.Center)
strSQL = "select name ,price ,type,id from menu where status='Y' order by type"
Try
Dim str(5) As String
Dim itm As ListViewItem
Dim i As Integer
lvwGetDish.Items.Clear()
myTab = odb.CreateDataTable(strSQL)
If myTab.Rows.Count > 0 Then
'将可用的菜肴加入到点菜列表视图中
For i = 0 To myTab.Rows.Count - 1
str(1) = myTab.Rows(i).Item(0)
str(2) = myTab.Rows(i).Item(1)
str(3) = myTab.Rows(i).Item(2)
str(4) = myTab.Rows(i).Item(3)
itm = New ListViewItem(str)
lvwGetDish.Items.Add(itm)
Next
End If
Catch ex As Exception
'异常处理
MsgBox(ex.Message, MsgBoxStyle.Exclamation)
End Try
End Sub
Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles btnOK.Click
'先检查输入合法性
Select Case ConvertStatus(Trim(cmbStatus.Text))
Case "U"
'使用状态餐位的用餐人数必须为自然数
If Not (Val(Trim(txtPer.Text).Substring(0, Len(txtPer.Text) - 1)) > 0 _
And Int(Val(Trim(txtPer.Text).Substring(0, Len(txtPer.Text) - 1))) _
= Val(Trim(txtPer.Text).Substring(0, Len(txtPer.Text) - 1))) Then
MsgBox("使用中的餐位人数必须是自然数!", MsgBoxStyle.Exclamation)
'将焦点转移到用餐人数文本框
txtPer.Focus()
'选中文本框中数字部分
txtPer.Select(0, Len(txtPer.Text) - 1)
Exit Sub
'使用状态的餐位必须要菜单
ElseIf lvwGetDish.CheckedItems.Count < 1 And lvwSiteOpre.Items.Count < 1 Then
MsgBox("使用中的餐位必须有菜单!", MsgBoxStyle.Exclamation)
lvwGetDish.Focus()
Exit Sub
End If
Case "B"
'结帐状态的优惠金额必须是正数,而且优惠金额必须小于消费金额的20%
If Not (Val(Trim(txtDiscount.Text).Substring(0, Len(txtDiscount.Text) - 1)) >= 0 _
And Val(Trim(txtDiscount.Text).Substring(0, Len(txtDiscount.Text) - 1)) < 0.2 _
* Val(Trim(txtMoney.Text).Substring(0, Len(txtMoney.Text) - 1))) Then
MsgBox("优惠金额不正确!", MsgBoxStyle.Exclamation)
txtDiscount.Focus()
'选中优惠金额文本框中数字部分
txtDiscount.Select(0, Len(txtDiscount.Text) - 1)
Exit Sub
End If
End Select
'输入合法性检查结束后开始更新数据库中相应数据表
Try
'更新Site数据表中的餐位信息
strSQL = "update site set status='" & ConvertStatus(Trim(cmbStatus.Text)) & _
"',numperson=" & Val(Trim(txtPer.Text).Substring(0, Len(txtPer.Text) - 1)) & _
",totalconsu =" & Val(Trim(txtMoney.Text).Substring(0, Len(txtMoney.Text) - 1)) _
& ",discount=" & Val(Trim(txtDiscount.Text).Substring(0, Len(txtDiscount.Text) - 1)) _
& " where tableID='" & Trim(txtID.Text) & "'"
odb.UpdateDataBase(strSQL)
Catch mm As Exception
' 捕捉异常
MsgBox(mm.Message, MsgBoxStyle.Exclamation)
Exit Sub
End Try
Try
'状态变为空闲的餐位需要删除和餐位关联的菜单
strSQL = "delete billofsite from billofsite,site where billofsite.tableid=site.tableid" & _
" and site.status='F'"
odb.UpdateDataBase(strSQL)
Catch mm As Exception
' 捕捉异常
MsgBox(mm.Message, MsgBoxStyle.Exclamation)
Exit Sub
End Try
'如果状态变为使用,需要保存GetDish过程中生成的菜单
If cmbStatus.Text = "使用" Then
Dim i As Integer
For i = 1 To lvwGetDish.CheckedItems.Count
Try
strSQL = "insert into billofsite " _
& "values (" & Val(Trim(txtID.Text)) & ",'" & _
Trim(lvwGetDish.CheckedItems(i - 1).SubItems(4).Text) & "')"
odb.UpdateDataBase(strSQL)
Catch mm As Exception
' 捕捉异常
MsgBox(mm.Message, MsgBoxStyle.Exclamation)
Exit Sub
End Try
Next i
End If
palSiteOpre.Visible = False
ImgArr(Val(txtID.Text) - 1).Image = Image.FromFile(Application.StartupPath & _
"\..\Icon\" & ConvertStatus(cmbStatus.Text) & ".jpg")
End Sub
Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles btnCancel.Click
palSiteOpre.Visible = False
End Sub
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -