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

📄 frmoutput.vb

📁 VB写的进销存管理系统
💻 VB
📖 第 1 页 / 共 3 页
字号:
    Public Sub FillProduct()
        On Error GoTo ErrorHandle
        With cobProduct
            .Items.Clear()
            Dim myRow As DataRow
            Dim currRows() As DataRow = myDataSetProduct.Tables(0).Select(Nothing, Nothing, DataViewRowState.CurrentRows)
            For Each myRow In currRows
                .Items.Add(myRow("p_name") & " " & myRow("p_model"))
            Next
        End With
        Exit Sub
ErrorHandle:
        ShowErr()
    End Sub
    Public Sub FillBusinessman()
        On Error GoTo ErrorHandle
        With cobBusinessman
            .Items.Clear()
            Dim myRow As DataRow
            Dim currRows() As DataRow = myDataSetBusinessman.Tables(0).Select(Nothing, Nothing, DataViewRowState.CurrentRows)
            For Each myRow In currRows
                .Items.Add(myRow("b_name"))
            Next
        End With
        Exit Sub
ErrorHandle:
        ShowErr()
    End Sub

    Private Sub frmOutput_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
        bunAddOutput.Enabled = False
        txtYear.Text = Microsoft.VisualBasic.DateAndTime.Year(Now)
        txtMonth.Text = Microsoft.VisualBasic.DateAndTime.Month(Now)
        txtDay.Text = Microsoft.VisualBasic.DateAndTime.Day(Now)
        ShowStatus("销售登记", "")
        On Error GoTo ErrorHandle
        Dim strSelectOutput As String = "select * from Output"
        Dim cmdSelectOutput As New SqlClient.SqlCommand(strSelectOutput, db)
        myDataAdapterOutput.SelectCommand = cmdSelectOutput
        Dim xxOutput As SqlCommandBuilder = New SqlCommandBuilder(myDataAdapterOutput)
        Dim strSelectProduct As String = "select * from Product"
        Dim cmdSelectProduct As New SqlClient.SqlCommand(strSelectProduct, db)
        myDataAdapterProduct.SelectCommand = cmdSelectProduct
        Dim xxProduct As SqlCommandBuilder = New SqlCommandBuilder(myDataAdapterProduct)
        Dim strSelectBusinessman As String = "select * from Businessman"
        Dim cmdSelectBusinessman As New SqlClient.SqlCommand(strSelectBusinessman, db)
        myDataAdapterBusinessman.SelectCommand = cmdSelectBusinessman
        Dim xxBusinessman As SqlCommandBuilder = New SqlCommandBuilder(myDataAdapterBusinessman)
        Dim strSelectStore As String = "select * from Store"
        Dim cmdSelectStore As New SqlClient.SqlCommand(strSelectStore, db)
        myDataAdapterStore.SelectCommand = cmdSelectStore
        Dim xxStore As SqlCommandBuilder = New SqlCommandBuilder(myDataAdapterStore)
        Dim strSelectCustomer As String = "select * from Customer"
        Dim cmdSelectCustomer As New SqlClient.SqlCommand(strSelectCustomer, db)
        myDataAdapterCustomer.SelectCommand = cmdSelectCustomer
        Dim xxCustomer As SqlCommandBuilder = New SqlCommandBuilder(myDataAdapterCustomer)
        db.Open()
        myDataAdapterOutput.Fill(myDataSetOutput)
        myDataAdapterProduct.Fill(myDataSetProduct)
        myDataAdapterBusinessman.Fill(myDataSetBusinessman)
        myDataAdapterStore.Fill(myDataSetStore)
        myDataAdapterCustomer.Fill(myDataSetCustomer)
        db.Close()
        Dim currRows() As DataRow = myDataSetOutput.Tables(0).Select(Nothing, Nothing, DataViewRowState.CurrentRows)
        RowsMaxOutput = currRows.Length - 1
        Dim currRows2() As DataRow = myDataSetProduct.Tables(0).Select(Nothing, Nothing, DataViewRowState.CurrentRows)
        RowsMaxProduct = currRows2.Length - 1
        Dim currRows3() As DataRow = myDataSetBusinessman.Tables(0).Select(Nothing, Nothing, DataViewRowState.CurrentRows)
        RowsMaxBusinessman = currRows3.Length - 1
        Dim currRows4() As DataRow = myDataSetCustomer.Tables(0).Select(Nothing, Nothing, DataViewRowState.CurrentRows)
        RowsMaxCustomer = currRows4.Length - 1
        FillCustomer()
        FillProduct()
        FillBusinessman()
        SetOutputID()
        Exit Sub
ErrorHandle:
        ShowErr()
    End Sub

    Private Sub frmOutput_Closed(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Closed
        Me.Dispose()
        ShowStatus("", "")
        frmMain1.mnuTrade.MenuItems(1).Enabled = True
    End Sub

    Private Sub bunAddCustomer_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles bunAddCustomer.Click
        On Error GoTo ErrorHandle
        Dim myRow As DataRow = myDataSetCustomer.Tables(0).NewRow
        myRow("c_id") = txtCId.Text
        myRow("c_name") = txtCName.Text
        myRow("c_addr") = txtCaddr.Text
        myRow("c_phone") = txtCPhone.Text
        myDataSetCustomer.Tables(0).Rows.Add(myRow)
        MsgBox(txtCName.Text & " 已经添加到客户数据表", vbInformation, "添加客户")
        Exit Sub
ErrorHandle:
        ShowErr()
    End Sub

    Private Sub bunCustomerCancel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles bunCustomerCancel.Click
        GBOutput.Enabled = True
        bunAddOutput.Enabled = True
    End Sub

    Sub bunAddOutput_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles bunAddOutput.Click
        Dim i As Integer
        Dim M As String
        Dim P As String
        On Error GoTo ErrorHandle
        i = InStr(cobProduct.Text, " ")
        P = Mid(cobProduct.Text, 1, i - 1)
        M = Mid(cobProduct.Text, i + 1)
        Dim myRow As DataRow
        Dim currRows() As DataRow = myDataSetProduct.Tables(0).Select(Nothing, Nothing, DataViewRowState.CurrentRows)
        For Each myRow In currRows
            If (myRow("p_name") = P) And (myRow("p_model") = M) Then
                PID = myRow("p_id")
            End If
        Next
        Dim myRow2 As DataRow
        Dim currRows2() As DataRow = myDataSetCustomer.Tables(0).Select(Nothing, Nothing, DataViewRowState.CurrentRows)
        For Each myRow2 In currRows2
            If myRow2("c_name") = cobCustomer.Text Then
                CID = myRow2("c_id")
            End If
        Next
        Dim myRow3 As DataRow
        Dim currRows3() As DataRow = myDataSetBusinessman.Tables(0).Select(Nothing, Nothing, DataViewRowState.CurrentRows)
        For Each myRow3 In currRows3
            If myRow3("b_name") = cobBusinessman.Text Then
                BID = myRow3("b_id")
            End If
        Next
        Dim myRow4 As DataRow
        Dim currRows4() As DataRow = myDataSetStore.Tables(0).Select(Nothing, Nothing, DataViewRowState.CurrentRows)
        For Each myRow4 In currRows4
            If myRow4("p_id") = PID Then
                SID = myRow4("s_id")
                myRow4("s_count") = myRow4("s_count") - CLng(txtCount.Text)
                myDataSetStore.AcceptChanges()
                Dim strsql As String = "update store set s_count='" & myRow4("s_count") & "' where s_id='" & myRow4("s_id") & "'"
                Dim mycommand As New SqlClient.SqlCommand(strsql, db)
                db.Open()
                mycommand.ExecuteNonQuery()
                db.Close()
            End If
        Next
        For Each myRow3 In currRows3
            If myRow3("b_id") = BID Then
                myRow3("b_trades") = myRow3("b_trades") + CLng(txtCount.Text) * CLng(txtPrice.Text)
                myDataSetBusinessman.AcceptChanges()
                Dim strsql As String = "update businessman set b_trades='" & myRow3("b_trades") & "' where b_id='" & myRow3("b_id") & "'"
                Dim mycommand As New SqlClient.SqlCommand(strsql, db)
                db.Open()
                mycommand.ExecuteNonQuery()
                db.Close()
            End If
        Next
        Dim myRow5 As DataRow = myDataSetOutput.Tables(0).NewRow
        myRow5("o_id") = txtOId.Text
        myRow5("p_id") = PID
        myRow5("b_id") = BID
        myRow5("c_id") = CID
        myRow5("o_count") = CLng(txtCount.Text)
        myRow5("r_count") = 0
        myRow5("o_price") = CSng(txtPrice.Text)
        myRow5("o_date") = CDate(txtYear.Text & "/" & txtMonth.Text & "/" & txtDay.Text)
        myDataSetOutput.Tables(0).Rows.Add(myRow5)
        MsgBox("已经登记到销售数据表", vbInformation, "销售登记")
        InitOutput()
        SetOutputID()
        Exit Sub
ErrorHandle:
        ShowErr()
    End Sub

    Private Sub bunCancelAdd_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles bunCancelAdd.Click
        Me.Close()
        frmMain1.mnuTrade.MenuItems(1).Enabled = True
    End Sub

    Private Sub cobBusinessman_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cobBusinessman.Click
        IfCanAddOutput()
    End Sub

    Private Sub cobCustomer_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cobCustomer.Click
        IfCanAddOutput()
        If cobCustomer.Text = "<new>" Then
            cobCustomer.Text = ""
            GBOutput.Enabled = False
            InitAddCustomer()
            SetCustomerID()
            bunAddCustomer.Enabled = True
        End If
    End Sub

    Private Sub cobProduct_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cobProduct.Click
        Dim storecount As Integer
        IfCanAddOutput()
        On Error GoTo ErrorHandle
        Dim myRow As DataRow
        Dim currRows() As DataRow = myDataSetProduct.Tables(0).Select(Nothing, Nothing, DataViewRowState.CurrentRows)
        For Each myRow In currRows
            If myRow("p_name") & " " & myRow("p_model") = cobProduct.Text Then
                PID = myRow("p_id")
            End If
        Next
        storecount = 0
        Dim myRow2 As DataRow
        Dim currRows2() As DataRow = myDataSetStore.Tables(0).Select(Nothing, Nothing, DataViewRowState.CurrentRows)
        For Each myRow2 In currRows2
            If myRow2("p_id") = PID Then
                storecount = storecount + myRow2("s_count")
            End If
        Next
        txtStoreCount.Text = storecount
        Exit Sub
ErrorHandle:
        ShowErr()
    End Sub

    Private Sub cobBusinessman_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cobBusinessman.TextChanged
        IfCanAddOutput()
    End Sub

    Private Sub cobCustomer_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cobCustomer.TextChanged
        IfCanAddOutput()
    End Sub

    Private Sub cobProduct_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cobProduct.TextChanged
        IfCanAddOutput()
    End Sub

    Private Sub txtCId_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtCId.TextChanged
        IfCanAddCustomer()
    End Sub

    Private Sub txtCName_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtCName.TextChanged
        IfCanAddCustomer()
    End Sub

    Private Sub txtCount_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtCount.TextChanged
        On Error GoTo ErrorHandle
        If (txtStoreCount.Text <> "") And (txtCount.Text <> "") Then
            If CLng(txtCount.Text) > CLng(txtStoreCount.Text) Then
                Err.Description = "出售数目大于库存量!"
                Err.Number = 3000
                Err.Raise(3000)
            End If
        End If
        IfCanAddOutput()
        Exit Sub
ErrorHandle:
        ShowErr()
        txtCount.Text = ""
    End Sub

    Private Sub txtDay_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtDay.TextChanged
        IfCanAddOutput()
    End Sub

    Private Sub txtMonth_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtMonth.TextChanged
        IfCanAddOutput()
    End Sub

    Private Sub txtOId_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtOId.TextChanged
        IfCanAddOutput()
    End Sub

    Private Sub txtPrice_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtPrice.TextChanged
        IfCanAddOutput()
    End Sub

    Private Sub txtYear_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtYear.TextChanged
        IfCanAddOutput()
    End Sub

    Private Sub bunOutputUpdate_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles bunOutputUpdate.Click
        db.Open()
        myDataAdapterOutput.Update(myDataSetOutput)
        myDataAdapterStore.Update(myDataSetStore)
        myDataAdapterBusinessman.Update(myDataSetBusinessman)
        db.Close()
        MsgBox("已经更新到数据库", , "销售登记")
    End Sub

    Private Sub bunCustomerUpdate_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles bunCustomerUpdate.Click
        db.Open()
        myDataAdapterCustomer.Update(myDataSetCustomer)
        db.Close()
        MsgBox("已经更新到数据库", , "添加客户")
        FillCustomer()
        GBOutput.Enabled = True
        bunAddOutput.Enabled = True
    End Sub
End Class

⌨️ 快捷键说明

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