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

📄 foodlist.vb

📁 This program is designed for a menu ordering system under pocket pc platform .
💻 VB
字号:
Imports System.Data 'for DataTable
Imports System.Data.SqlClient '新增命名空間 for SQL Server
Imports System.IO

Public Class FoodList

    Public Sub New(ByVal FProductName As String, ByVal FProductId As String)

        InitializeComponent()
        Dim ProductName As String = FProductName
        Dim ProductId As String = FProductId

        txt_ProductName.Text = ProductName
        txt_ProductId.Text = ProductId

    End Sub

    Dim errorMsg As String
    Dim ConnString As String

    Dim conn As SqlConnection
    Dim cmd As SqlCommand
    Dim dr As SqlDataReader
    Dim da As SqlDataAdapter

    Dim strAssmPath As String = System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase
    Dim GlobalAppPath As String = strAssmPath.Substring(0, strAssmPath.LastIndexOf("\") + 1)

#Region "資料庫初始化"

    ''' <summary>
    ''' 資料庫初始化
    ''' </summary>
    Public Sub InitDB()

        ConnString = SQLConnectionString()
        conn = New SqlConnection(ConnString)
        conn.Open()

    End Sub

#End Region

    Private Sub FoodList_Closed(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Closed
        PictureBox1.Image.Dispose()
    End Sub

    Private Sub ProductList_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Dim ProductId As String = Me.txt_ProductId.Text

        Dim Path As String = GlobalAppPath + "tmpImage"
        'Dim clsFBA As ClassLibrary.Class_FileByteArray = New ClassLibrary.Class_FileByteArray

        Dim DT As DataTable = LoadProductData(ProductId)

        For Each row As DataRow In DT.Rows

            Me.txt_ProductClassName.Text = row("ProductClassName").ToString()
            Me.txt_ProductName.Text = row("ProductName").ToString()
            Me.txt_ProductCost.Text = row("ProductCost").ToString()
            Me.txt_ProductStateName.Text = row("ProductStateName").ToString()

            Me.Matreial1.Text = row("Matreial1").ToString()
            Me.Num1.Text = row("Nums1").ToString()
            Me.Matreial2.Text = row("Matreial2").ToString()
            Me.Num2.Text = row("Nums2").ToString()
            Me.Matreial3.Text = row("Matreial3").ToString()
            Me.Num3.Text = row("Nums3").ToString()
            Me.Matreial4.Text = row("Matreial4").ToString()
            Me.Num4.Text = row("Nums4").ToString()
            Me.Matreial5.Text = row("Matreial5").ToString()
            Me.Num5.Text = row("Nums5").ToString()
            Me.Matreial6.Text = row("Matreial6").ToString()
            Me.Num6.Text = row("Nums6").ToString()

            Me.txt_Calory.Text = row("Calory").ToString()
            Me.txt_Fat.Text = row("Fat").ToString()
            Me.txt_Protein.Text = row("Protein").ToString()
            Me.txt_Vitamin.Text = row("Vitamin").ToString()
            Me.txt_Cholesterol.Text = row("Cholesterol").ToString()
            Me.txt_Carbohydrate.Text = row("Carbohydrate").ToString()

            Dim PicturePhoto() As Byte
            PicturePhoto = row("Photo")

            'clsFBA.ByteArrayToFile(PicturePhoto, Path)
            ' Delete the file if it exists.
            If File.Exists(Path) Then
                File.Delete(Path)
            End If

            ' Create the file.
            Dim fs As FileStream = File.Create(Path, 1024)

            ' Add some information to the file.
            fs.Write(PicturePhoto, 0, PicturePhoto.Length)
            fs.Close()

            Dim BP As Bitmap = New Bitmap(Path)
            PictureBox1.Image = BP

        Next

    End Sub

#Region "將ProductInfo資料表的內容以DataTable方式回傳"

    ''' <summary>
    ''' 將ProductInfo資料表的內容以DataTable方式回傳
    ''' </summary>       
    Public Function LoadProductData(ByVal ProductId As String) As DataTable

        Dim selectCmd As String

        selectCmd = "SELECT A4.Photo, A2.ProductClassName, A1.ProductName, A1.ProductCost, A3.ProductStateName, A4.Matreial1, A4.Nums1, A4.Matreial2, A4.Nums2, A4.Matreial3, A4.Nums3, A4.Matreial4, A4.Nums4, A4.Matreial5, A4.Nums5, A4.Matreial6, A4.Nums6, A4.Calory, A4.Fat, A4.Protein, A4.Vitamin, A4.Cholesterol, A4.Carbohydrate FROM ProductInfo AS A1 INNER JOIN ProductClass AS A2 ON A1.ProductClassId = A2.ProductClassId INNER JOIN ProductState AS A3 ON A1.ProductStateId = A3.ProductStateId INNER JOIN ProductFood AS A4 ON A1.ProductId = A4.ProductId WHERE A1.ProductId = '" + ProductId + "' "

        InitDB()

        da = New SqlDataAdapter(selectCmd, conn)
        Dim DT As DataTable = New DataTable()
        da.Fill(DT)

        da.Dispose()
        conn.Close()
        Return DT

    End Function

#End Region

End Class

⌨️ 快捷键说明

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