📄 manmenu.vb
字号:
'
Me.Label4.ForeColor = System.Drawing.Color.Blue
Me.Label4.Location = New System.Drawing.Point(192, 72)
Me.Label4.Name = "Label4"
Me.Label4.Size = New System.Drawing.Size(72, 20)
Me.Label4.TabIndex = 6
Me.Label4.Text = "菜谱类型*"
Me.Label4.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
'
'Label3
'
Me.Label3.ForeColor = System.Drawing.Color.Blue
Me.Label3.Location = New System.Drawing.Point(192, 49)
Me.Label3.Name = "Label3"
Me.Label3.Size = New System.Drawing.Size(64, 20)
Me.Label3.TabIndex = 5
Me.Label3.Text = "菜谱名称*"
Me.Label3.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
'
'Label2
'
Me.Label2.Location = New System.Drawing.Point(8, 24)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(104, 16)
Me.Label2.TabIndex = 3
Me.Label2.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(160, 232)
Me.ListBox1.TabIndex = 2
'
'TextBox1
'
Me.TextBox1.Location = New System.Drawing.Point(272, 16)
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.Size = New System.Drawing.Size(144, 21)
Me.TextBox1.TabIndex = 1
Me.TextBox1.Text = ""
'
'Label1
'
Me.Label1.ForeColor = System.Drawing.Color.Blue
Me.Label1.Location = New System.Drawing.Point(192, 24)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(80, 16)
Me.Label1.TabIndex = 0
Me.Label1.Text = "菜单编码*"
'
'Button3
'
Me.Button3.FlatStyle = System.Windows.Forms.FlatStyle.Flat
Me.Button3.ForeColor = System.Drawing.Color.Navy
Me.Button3.Location = New System.Drawing.Point(448, 304)
Me.Button3.Name = "Button3"
Me.Button3.Size = New System.Drawing.Size(48, 24)
Me.Button3.TabIndex = 5
Me.Button3.Text = "更新"
'
'Form2
'
Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
Me.ClientSize = New System.Drawing.Size(504, 335)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Button3, Me.GroupBox1, Me.Button2, Me.Button1})
Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle
Me.MaximizeBox = False
Me.Name = "Form2"
Me.Text = "点菜菜谱管理"
Me.GroupBox1.ResumeLayout(False)
CType(Me.NumericUpDown1, System.ComponentModel.ISupportInitialize).EndInit()
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
AddMenuLst()
ShowData(0)
End Sub
Public Function GetMenuFromCustomer()
Dim menuID As String
Dim SelMenu As Boolean
Dim Count As Integer
Dim i As Integer
End Function
Public Sub AddMenuLst()
Me.ListBox1.Items.Clear()
Dim strSQL As String
strSQL = "SELECT * FROM MenuInfo"
myDS.Clear()
myDS = GetDataFromDB(strSQL)
Dim strTemp As String
Dim count, i As Integer
count = myDS.Tables(0).Rows.Count
If count <= 0 Then
Exit Sub
End If
For i = 0 To count - 1
strTemp = Trim(myDS.Tables(0).Rows(i)("menu_id"))
strTemp = strTemp & " — " & myDS.Tables(0).Rows(i)("menu_name")
Me.ListBox1.Items.Add(strTemp)
Next
End Sub
Private Sub ListBox1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
ShowData(Me.ListBox1.SelectedIndex)
End Sub
Public Sub ShowData(ByVal index As Integer)
If index < 0 Then
Exit Sub
End If
Dim menuInfo As New MenuInfo()
menuInfo.menuID = myDS.Tables(0).Rows(index)("menu_id")
menuInfo.menuName = myDS.Tables(0).Rows(index)("menu_name")
menuInfo.menuStyle = myDS.Tables(0).Rows(index)("menu_style")
menuInfo.menuPrice = myDS.Tables(0).Rows(index)("menu_price")
menuInfo.menuDiscount = myDS.Tables(0).Rows(index)("menu_discount")
If myDS.Tables(0).Rows(index)("menu_description").GetType.ToString <> "System.DBNull" Then
menuInfo.menuDescription = myDS.Tables(0).Rows(index)("menu_description")
Else
menuInfo.menuDescription = ""
End If
If myDS.Tables(0).Rows(index)("menu_sapor").GetType.ToString <> "System.DBNull" Then
menuInfo.menuSapor = myDS.Tables(0).Rows(index)("menu_sapor")
Else
menuInfo.menuSapor = ""
End If
If myDS.Tables(0).Rows(index)("menu_material").GetType.ToString <> "System.DBNull" Then
menuInfo.menuMaterial = myDS.Tables(0).Rows(index)("menu_material")
Else
menuInfo.menuMaterial = ""
End If
Me.TextBox1.Text = menuInfo.menuID.Trim
Me.TextBox2.Text = menuInfo.menuName.Trim
Me.TextBox3.Text = CDbl(menuInfo.menuPrice)
Me.TextBox4.Text = menuInfo.menuSapor.Trim
Me.TextBox5.Text = menuInfo.menuMaterial.Trim
Me.TextBox6.Text = menuInfo.menuDescription.Trim
Me.ComboBox1.Text = menuInfo.menuStyle.Trim
Me.NumericUpDown1.Value = CDbl(menuInfo.menuDiscount) * 100
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
DeleteMenu()
AddMenuLst()
ShowData(0)
End Sub
Public Sub DeleteMenu()
Dim temp As String
temp = Trim(Me.ListBox1.SelectedItem.ToString)
If temp = "" Then
Exit Sub
End If
temp = temp.Substring(0, temp.IndexOf(" — "))
Dim sqlstr As String
sqlstr = "DELETE FROM MenuInfo WHERE menu_id='" & temp & "'"
If UpdateData(sqlstr) = True Then
Me.ListBox1.Items.Remove(Me.ListBox1.SelectedItem)
End If
End Sub
Public Sub AddMenu()
Dim menuInfo As New MenuInfo()
If Me.TextBox1.Text = "" Then
Exit Sub
End If
If Me.TextBox2.Text = "" Then
Exit Sub
End If
If Me.TextBox3.Text = "" Then
Exit Sub
End If
menuInfo.menuID = Me.TextBox1.Text
menuInfo.menuName = Me.TextBox2.Text
menuInfo.menuPrice = Me.TextBox3.Text
menuInfo.menuSapor = Me.TextBox4.Text
menuInfo.menuMaterial = Me.TextBox5.Text
menuInfo.menuDescription = Me.TextBox6.Text
menuInfo.menuDiscount = CDbl(Me.NumericUpDown1.Value / 100)
menuInfo.menuStyle = Me.ComboBox1.SelectedItem.ToString.Trim
With menuInfo
Dim sqlstr As String
sqlstr = "INSERT INTO MenuInfo (menu_id,menu_name,menu_price,menu_discount,menu_style,menu_sapor,menu_description,menu_material) VALUES ('" & .menuID & "','" & .menuName & "','" & .menuPrice & "','" & .menuDiscount & "','" & .menuStyle & "','" & .menuSapor & "','" & .menuDescription & "','" & .menuMaterial & "')"
UpdateData(sqlstr)
End With
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
AddMenu()
AddMenuLst()
ShowData(0)
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim menuInfo As New MenuInfo()
If Me.TextBox1.Text = "" Then
Exit Sub
End If
If Me.TextBox2.Text = "" Then
Exit Sub
End If
If Me.TextBox3.Text = "" Then
Exit Sub
End If
menuInfo.menuID = Me.TextBox1.Text
menuInfo.menuName = Me.TextBox2.Text
menuInfo.menuPrice = Me.TextBox3.Text
menuInfo.menuSapor = Me.TextBox4.Text
menuInfo.menuMaterial = Me.TextBox5.Text
menuInfo.menuDescription = Me.TextBox6.Text
menuInfo.menuDiscount = CDbl(Me.NumericUpDown1.Value / 100)
menuInfo.menuStyle = Me.ComboBox1.SelectedItem.ToString.Trim
Dim sqlstr As String
With menuInfo
sqlstr = "UPDATE MenuInfo SET menu_name='" & .menuName & "',menu_price='" & .menuPrice & "',menu_discount='" & .menuDiscount & "',menu_style='" & .menuStyle & "',menu_sapor='" & .menuSapor & "',menu_description='" & .menuDescription & "',menu_material='" & .menuMaterial & "' WHERE menu_id='" & .menuID & "'"
If UpdateData(sqlstr) = True Then
AddMenuLst()
ShowData(0)
End If
End With
End Sub
End Class
Public Class MenuInfo
Public menuID As String
Public menuName As String
Public menuStyle As String
Public menuPrice As Double
Public menuDiscount As Double
Public menuDescription As String
Public menuSapor As String
Public menuMaterial As String
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -