⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 frmmenumanager.vb

📁 单机版餐饮服务系统,结合了SqlServer数据库
💻 VB
📖 第 1 页 / 共 3 页
字号:
        Public Sub DisplayMenuInfo(ByVal sMenuInfo As MenuInfo)
            If sMenuInfo Is Nothing Then
                Return
            End If
            Me.txtMenuID.Tag = sMenuInfo.menuID
            Me.txtMenuID.Text = sMenuInfo.menuID.ToString.ToUpper
            Me.txtMenuName.Text = sMenuInfo.menuName.Trim
            Me.txtMenuPrice.Text = CDec(sMenuInfo.menuPrice).ToString("C")
            Me.txtMenuFeature.Text = sMenuInfo.menuSapor.Trim
            Me.txtMenuMaterial.Text = sMenuInfo.menuMaterial.Trim
            Me.txtMenuDescription.Text = sMenuInfo.menuDescription.Trim
            Me.cmbMenuType.Text = sMenuInfo.menuStyle.Trim
            Me.nmdMenuDiscount.Value = CDbl(sMenuInfo.menuDiscount) * 100
            If sMenuInfo.menuPicture = String.Empty Then
                MenuPicture.Image = Nothing
            Else
                '// 将mFileName变量赋值,否则在更新时则可能出现图像丢失
                mFileName = AccessToDatabase.GetStartupPath & _
                "\MenuPhotoes\" & sMenuInfo.menuPicture
                MenuPicture.Image = New Bitmap(mFileName)
            End If
        End Sub

        Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click
            Dim mMenuID As String = txtMenuID.Text.Trim
            If mMenuID = String.Empty Then Return
            MenuInfo.DeleteMenu(mMenuID)
            InitialMenuTree()
            btnClearAll_Click(Nothing, Nothing)
        End Sub

        Private Function GetMenuInfoFromForm() As MenuInfo
            Dim tempMenuInfo As New MenuInfo
            If txtMenuName.Text.Trim = String.Empty Or txtMenuPrice.Text.Trim = String.Empty Or cmbMenuType.SelectedIndex < 0 Then
                Throw New ArgumentNullException
                Return Nothing
            End If
            tempMenuInfo.menuID = CType(Me.txtMenuID.Tag, Guid)
            tempMenuInfo.menuName = Me.txtMenuName.Text.Trim
            tempMenuInfo.menuPrice = Me.txtMenuPrice.Text.Trim
            tempMenuInfo.menuSapor = Me.txtMenuFeature.Text.Trim
            tempMenuInfo.menuMaterial = Me.txtMenuMaterial.Text.Trim
            tempMenuInfo.menuDescription = Me.txtMenuDescription.Text.Trim
            tempMenuInfo.menuDiscount = CDbl(Me.nmdMenuDiscount.Value / 100)
            tempMenuInfo.menuStyle = Me.cmbMenuType.SelectedItem.ToString.Trim.Trim
            tempMenuInfo.menuPicture = mFileName
            Return tempMenuInfo
        End Function

        Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
            Try
                MenuInfo.AddNewMenu(GetMenuInfoFromForm)
            Catch ex As Exception
                MsgBox(ex.Message)
            Finally
                InitialMenuTree()
            End Try
        End Sub

        Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdate.Click
            Try
                MenuInfo.UpdateMenuInfo(GetMenuInfoFromForm)
            Catch ex As Exception
                MsgBox(ex.Message)
            End Try
        End Sub

        Private Sub btnBrowser_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBrowser.Click
            Dim OpenPhotoFileDialog As New OpenFileDialog
            With OpenPhotoFileDialog
                .Title = ""
                .CheckFileExists = True
                .Filter = "BMP Files(*.bmp)|*.bmp|JPEG Files(*.jpg)|*.jpg"
                If .ShowDialog = DialogResult.OK Then
                    mFileName = .FileName
                End If
            End With
            If mFileName = String.Empty Then
                MsgBox("", MsgBoxStyle.OKOnly + MsgBoxStyle.Exclamation, "")
                Exit Sub
            End If
            Dim mImage As Bitmap = New Bitmap(mFileName)
            MenuPicture.Image = mImage
        End Sub

        Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
            Me.Close()
        End Sub

        Private Sub MenuTree_AfterSelect(ByVal sender As Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles MenuTree.AfterSelect
            If e.Node.Tag.GetType.ToString <> "System.String" Then
                gpMenuInfo.Enabled = True
                DisplayMenuInfo(MenuInfo.GetMenuInfoByMenuID(e.Node.Tag))
            Else
                gpMenuInfo.Enabled = False
            End If
        End Sub

        Private Sub btnClearAll_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClearAll.Click
            Me.txtMenuID.Text = String.Empty
            Me.txtMenuName.Text = String.Empty
            Me.txtMenuPrice.Text = 0
            Me.txtMenuFeature.Text = String.Empty
            Me.txtMenuMaterial.Text = String.Empty
            Me.txtMenuDescription.Text = String.Empty
            Me.cmbMenuType.Text = String.Empty
            Me.nmdMenuDiscount.Value = 0
            Me.MenuPicture.Image = Nothing
        End Sub

        Private Sub cmbMenuType_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmbMenuType.SelectedIndexChanged
            If cmbMenuType.SelectedIndex < 0 Then cmbMenuType.SelectedIndex = 0
        End Sub
    End Class

    Public Class MenuInfo

        Public menuID As Guid
        Public menuName As String = String.Empty
        Public menuStyle As String = String.Empty
        Public menuPrice As Double = 0
        Public menuDiscount As Double = 0
        Public menuDescription As String = String.Empty
        Public menuSapor As String = String.Empty
        Public menuMaterial As String = String.Empty
        Public menuPicture As String = String.Empty

        Private Shared sqlstr As String = String.Empty

        Public Shared Sub AddNewMenu(ByVal mMenuInfo As MenuInfo)
            Try
                If mMenuInfo Is Nothing Then
                    Return
                End If
                '// 这是采用存储过程的方法
                If AccessToDatabase.objSqlConnection Is Nothing Then
                    Return
                End If
                If AccessToDatabase.objSqlConnection.State <> ConnectionState.Open Then
                    AccessToDatabase.objSqlConnection.Open()
                End If
                Dim sqlAddCommand As New SqlCommand("sp_MenuInfo_INS")
                With sqlAddCommand
                    .CommandType = CommandType.StoredProcedure
                    With .Parameters
                        .Add("@MenuID", SqlDbType.Char, 38)
                        .Add("@MenuName", SqlDbType.NVarChar, 50)
                        .Add("@MenuPrice", SqlDbType.Money, 8)
                        .Add("@MenuDisCount", SqlDbType.Real, 4)
                        .Add("@MenuStyle", SqlDbType.NVarChar, 20)
                        .Add("@MenuSapor", SqlDbType.NVarChar, 20)
                        .Add("@MenuDescription", SqlDbType.NVarChar, 1000)
                        .Add("@MenuMaterial", SqlDbType.NVarChar, 2000)
                        .Add("@MenuPicture", SqlDbType.NVarChar, 100)

                        .Item("@MenuID").Value = String.Empty
                        .Item("@MenuName").Value = mMenuInfo.menuName
                        .Item("@MenuPrice").Value = mMenuInfo.menuPrice
                        .Item("@MenuDisCount").Value = mMenuInfo.menuDiscount
                        .Item("@MenuStyle").Value = mMenuInfo.menuStyle
                        .Item("@MenuSapor").Value = mMenuInfo.menuSapor
                        .Item("@MenuDescription").Value = mMenuInfo.menuDescription
                        .Item("@MenuMaterial").Value = mMenuInfo.menuMaterial
                        .Item("@MenuPicture").Value = mMenuInfo.menuPicture
                    End With
                    .Connection = AccessToDatabase.objSqlConnection
                    .ExecuteNonQuery()
                End With
                MsgBox("祝贺您,您已经成功的增添了一道新菜哦。", MsgBoxStyle.OKOnly + MsgBoxStyle.Information, "增添新菜谱成功")
            Catch ex As Exception
                MsgBox("太遗憾了,您增添新菜谱时失败了,请检查是否有重复菜谱编码。", MsgBoxStyle.OKOnly + MsgBoxStyle.Exclamation, "增添新菜谱失败")
            End Try
        End Sub

        Public Shared Sub DeleteMenu(ByVal mMenuID As String)
            If mMenuID Is Nothing Or mMenuID = String.Empty Then
                Return
            End If
            sqlstr = "DELETE FROM MenuInfo WHERE menu_id='" & mMenuID & "'"
            If AccessToDatabase.UpdateData(sqlstr) = True Then
                MsgBox("祝贺您,您已经成功的删除了该菜谱了。", MsgBoxStyle.OKOnly + MsgBoxStyle.Information, "删除菜谱成功")
            Else
                MsgBox("很抱歉,您没能删除改菜谱。", MsgBoxStyle.OKOnly + MsgBoxStyle.Exclamation, "删除菜谱失败")
            End If
        End Sub

        Public Shared Sub UpdateMenuInfo(ByVal mMenuInfo As MenuInfo)
            If mMenuInfo Is Nothing Then
                Return
            End If
            With mMenuInfo
                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 & "',menu_Picture='" & .menuPicture & "' WHERE menu_id='" & .menuID.ToString & "'"
                If AccessToDatabase.UpdateData(sqlstr) = True Then
                    MsgBox("耶,修改菜谱信息成功了。", MsgBoxStyle.OKOnly + MsgBoxStyle.Information, "修改菜谱信息成功")
                Else
                    MsgBox("咦,怎么会失败了啦。", MsgBoxStyle.OKOnly + MsgBoxStyle.Exclamation, "修改菜谱信息失败")
                End If
            End With
        End Sub

        Public Shared Function GetMenuInfoByMenuID(ByVal menuID As Guid) As MenuInfo
            sqlstr = "SELECT * FROM MenuInfo WHERE Menu_id='" & menuID.ToString & "'"
            Dim tempDS As New DataSet
            tempDS.Clear()
            Dim tempMenuInfo As New MenuInfo
            tempDS = AccessToDatabase.GetDataFromDB(sqlstr)
            If Not tempDS Is Nothing Then
                If tempDS.Tables(0).Rows.Count >= 1 Then
                    tempMenuInfo.menuID = menuID
                    tempMenuInfo.menuName = CStr(tempDS.Tables(0).Rows(0).Item("Menu_name")).Trim
                    If tempDS.Tables(0).Rows(0).Item("Menu_sapor").GetType.ToString = "System.DBNull" Then
                        tempMenuInfo.menuSapor = String.Empty
                    Else
                        tempMenuInfo.menuSapor = CStr(tempDS.Tables(0).Rows(0).Item("Menu_sapor")).Trim
                    End If
                    tempMenuInfo.menuStyle = CStr(tempDS.Tables(0).Rows(0).Item("Menu_style")).Trim
                    tempMenuInfo.menuPrice = CDec(Val(tempDS.Tables(0).Rows(0).Item("Menu_price")))
                    tempMenuInfo.menuDiscount = CDec(Val(tempDS.Tables(0).Rows(0).Item("Menu_discount")))
                    If tempDS.Tables(0).Rows(0).Item("Menu_description").GetType.ToString = "System.DBNull" Then
                        tempMenuInfo.menuDescription = String.Empty
                    Else
                        tempMenuInfo.menuDescription = CStr(tempDS.Tables(0).Rows(0).Item("Menu_description")).Trim
                    End If
                    If tempDS.Tables(0).Rows(0).Item("Menu_material").GetType.ToString = "System.DBNull" Then
                        tempMenuInfo.menuMaterial = String.Empty
                    Else
                        tempMenuInfo.menuMaterial = CStr(tempDS.Tables(0).Rows(0).Item("Menu_material")).Trim
                    End If
                    If tempDS.Tables(0).Rows(0).Item("Menu_picture").GetType.ToString = "System.DBNull" Then
                        tempMenuInfo.menuPicture = String.Empty
                    Else
                        tempMenuInfo.menuPicture = CStr(tempDS.Tables(0).Rows(0).Item("Menu_picture")).Trim
                    End If
                    Return tempMenuInfo
                Else
                    tempDS = Nothing
                    Return Nothing
                End If
            Else
                Return Nothing
            End If
        End Function

    End Class

End Namespace

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -