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

📄 frmbusinessman.vb

📁 VB写的进销存管理系统
💻 VB
📖 第 1 页 / 共 2 页
字号:
    Private Sub bshowfield()
        If myIndex >= 0 Then
            Dim currRows() As DataRow = myDataSet.Tables(0).Select(Nothing, Nothing, DataViewRowState.CurrentRows)
            Dim myRow As DataRow = currRows(myIndex)
            TxtId.Text = myRow("b_id")
            txtName.Text = myRow("b_name")
            txtAddr.Text = myRow("b_addr")
            txtPhone.Text = myRow("b_phone")
            txtSalary.Text = myRow("b_limitsalary")
            txtWorkyear.Text = myRow("b_workyear")
            txtTrades.Text = myRow("b_trades")
        End If
    End Sub

    Private Sub frmBusinessman_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ShowStatus("数据管理--", "业务员数据表")
        TableName = CurrentTable
        Dim strSelectBusinessman As String = "select * from Businessman"
        Dim cmdSelectBusinessman As New SqlClient.SqlCommand(strSelectBusinessman, db)
        myDataAdapter.SelectCommand = cmdSelectBusinessman
        Dim xx As SqlClient.SqlCommandBuilder = New SqlClient.SqlCommandBuilder(myDataAdapter)
        db.Open()
        myDataAdapter.Fill(myDataSet)
        db.Close()
        Dim currrows() As DataRow = myDataSet.Tables(0).Select(Nothing, Nothing, DataViewRowState.CurrentRows)
        RowsMax = currrows.Length - 1
        If RowsMax < 0 Then
            myIndex = -1
            MsgBox("库里还没有记录,请添加业务员", , "业务员数据表")
            TxtId.Text = "b000000001"
            bunPrevious.Enabled = False
            bunAdd.Enabled = False
            bunDelete.Enabled = False
            bunSearch.Enabled = False
            bunSave.Enabled = False
            bunNext.Enabled = False
            neworchange = True
        Else
            myIndex = 0
            bshowfield()
        End If
    End Sub

    Private Sub frmBusinessman_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Activated
        ShowStatus("数据管理--", "业务员数据表")
    End Sub

    Private Sub frmBusinessman_Closed(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Closed
        Me.Dispose()
        Me.Close()
        ShowStatus("", "")
        BusinessmanTableOpened = False
        TableMenuEnable()
    End Sub

    Private Sub txtAddr_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtAddr.TextChanged
        On Error GoTo ErrorHandle
        If neworchange Then
            If txtName.Text <> "" And txtSalary.Text <> "" And txtWorkyear.Text <> "" And txtTrades.Text <> "" Then
                bunSave.Enabled = True
            End If
        End If
        Exit Sub
ErrorHandle:
        ShowErr()
    End Sub

    Private Sub txtName_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtName.TextChanged
        On Error GoTo ErrorHandle
        If neworchange Then
            If txtName.Text <> "" And txtSalary.Text <> "" And txtWorkyear.Text <> "" And txtTrades.Text <> "" Then
                bunSave.Enabled = True
            End If
        End If
        Exit Sub
ErrorHandle:
        ShowErr()
    End Sub

    Private Sub txtPhone_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtPhone.TextChanged
        On Error GoTo ErrorHandle
        If neworchange Then
            If txtName.Text <> "" And txtSalary.Text <> "" And txtWorkyear.Text <> "" And txtTrades.Text <> "" Then
                bunSave.Enabled = True
            End If
        End If
        Exit Sub
ErrorHandle:
        ShowErr()
    End Sub

    Private Sub txtSalary_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtSalary.TextChanged
        On Error GoTo ErrorHandle
        If neworchange Then
            If txtName.Text <> "" And txtSalary.Text <> "" And txtWorkyear.Text <> "" And txtTrades.Text <> "" Then
                bunSave.Enabled = True
            End If
        End If
        Exit Sub
ErrorHandle:
        ShowErr()
    End Sub

    Private Sub txtTrades_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtTrades.TextChanged
        On Error GoTo ErrorHandle
        If neworchange Then
            If txtName.Text <> "" And txtSalary.Text <> "" And txtWorkyear.Text <> "" And txtTrades.Text <> "" Then
                bunSave.Enabled = True
            End If
        End If
        Exit Sub
ErrorHandle:
        ShowErr()
    End Sub

    Private Sub txtWorkyear_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtWorkyear.TextChanged
        On Error GoTo ErrorHandle
        If neworchange Then
            If txtName.Text <> "" And txtSalary.Text <> "" And txtWorkyear.Text <> "" And txtTrades.Text <> "" Then
                bunSave.Enabled = True
            End If
        End If
        Exit Sub
ErrorHandle:
        ShowErr()
    End Sub

    Private Sub bunAdd_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles bunAdd.Click
        Dim CountInTable As Integer
        Dim IID As String
        On Error GoTo ErrorHandle
        neworchange = True
        If RowsMax >= 0 Then
            CountInTable = RowsMax + 2
            IID = "b" & Format(CountInTable, "000000000")
        Else
            IID = "b000000001"
        End If
        TxtId.Text = IID
        txtName.Text = ""
        txtAddr.Text = ""
        txtPhone.Text = ""
        txtSalary.Text = ""
        txtTrades.Text = ""
        txtWorkyear.Text = ""
        bunPrevious.Enabled = False
        bunAdd.Enabled = False
        bunDelete.Enabled = False
        bunSearch.Enabled = False
        bunSave.Enabled = False
        bunNext.Enabled = False
        Exit Sub
ErrorHandle:
        ShowErr()
    End Sub

    Private Sub bunCancel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles bunCancel.Click
        On Error GoTo ErrorHandle
        If RowsMax < 0 Then
            TxtId.Text = ""
            txtName.Text = ""
            txtAddr.Text = ""
            txtPhone.Text = ""
            txtSalary.Text = ""
            txtTrades.Text = ""
            txtWorkyear.Text = ""
            bunAdd.Enabled = True
            neworchange = False
            Exit Sub
        End If
        bshowfield()
        If neworchange Then
            bunPrevious.Enabled = True
            bunAdd.Enabled = True
            bunDelete.Enabled = True
            bunSearch.Enabled = True
            bunSave.Enabled = True
            bunNext.Enabled = True
        End If
        Exit Sub
ErrorHandle:
        ShowErr()
    End Sub

    Private Sub bunDelete_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles bunDelete.Click
        On Error GoTo ErrorHandle
        If RowsMax < 0 Then
            MsgBox("库中没有可删除的记录!", , "业务员数据表")
            Exit Sub
        End If
        If MsgBox("是否删除?", 36, "提示") = vbYes Then
            Dim myRow As DataRow = myDataSet.Tables(0).Rows(myIndex)
            Dim strsql As String = "delete from businessman where b_id='" & myRow("b_id") & "'"
            Dim mycommand As New SqlClient.SqlCommand(strsql, db)
            db.Open()
            mycommand.ExecuteNonQuery()
            db.Close()
            myRow.Delete()
            myDataSet.AcceptChanges()
            RowsMax = RowsMax - 1
            If RowsMax >= 0 Then
                myIndex = 0
                bshowfield()
            Else
                TxtId.Text = ""
                txtName.Text = ""
                txtAddr.Text = ""
                txtPhone.Text = ""
                txtSalary.Text = ""
                txtTrades.Text = ""
                txtWorkyear.Text = ""
                bunPrevious.Enabled = False
                bunAdd.Enabled = False
                bunDelete.Enabled = False
                bunSearch.Enabled = False
                bunSave.Enabled = False
                bunNext.Enabled = False
            End If
        Else
            Exit Sub
        End If
        Exit Sub
ErrorHandle:
        ShowErr()
    End Sub

    Private Sub bunNext_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles bunNext.Click
        On Error Resume Next
        If myIndex < RowsMax Then
            myIndex = myIndex + 1
        End If
        bshowfield()
    End Sub

    Private Sub bunPrevious_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles bunPrevious.Click
        On Error Resume Next
        If myIndex > 0 Then
            myIndex = myIndex - 1
        End If
        bshowfield()
    End Sub

    Private Sub bunSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles bunSave.Click
        On Error GoTo ErrorHandle
        If neworchange Then
            Dim myRow As DataRow = myDataSet.Tables(0).NewRow
            myRow("b_id") = TxtId.Text
            myRow("b_name") = txtName.Text
            myRow("b_addr") = txtAddr.Text
            myRow("b_phone") = txtPhone.Text
            myRow("b_limitsalary") = txtSalary.Text
            myRow("b_workyear") = txtWorkyear.Text
            myRow("b_trades") = txtTrades.Text
            myDataSet.Tables(0).Rows.Add(myRow)
            MsgBox(txtName.Text & "已经添加进数据库", , "业务员数据表")
            RowsMax = RowsMax + 1
            myIndex = RowsMax
            bunPrevious.Enabled = True
            bunAdd.Enabled = True
            bunDelete.Enabled = True
            bunSearch.Enabled = True
            bunSave.Enabled = True
            bunNext.Enabled = True
            neworchange = False
        Else
            Dim myRow As DataRow = myDataSet.Tables(0).Rows(myIndex)
            myRow("b_id") = TxtId.Text
            myRow("b_name") = txtName.Text
            myRow("b_addr") = txtAddr.Text
            myRow("b_phone") = txtPhone.Text
            myRow("b_limitsalary") = txtSalary.Text
            myRow("b_workyear") = txtWorkyear.Text
            myRow("b_trades") = txtTrades.Text
            myDataSet.AcceptChanges()
            Dim strsql As String = "update businessman set b_name='" & myrow("b_name") & "', b_addr='" & myrow("b_addr") & "', b_phone='" & myrow("b_phone") & "', b_limitsalary='" & myrow("b_limitsalary") & "', b_workyear='" & myrow("b_workyear") & "', b_trades='" & myrow("b_trades") & "' where b_id='" & myrow("b_id") & "'"
            Dim mycommand As New SqlClient.SqlCommand(strsql, db)
            db.Open()
            mycommand.ExecuteNonQuery()
            db.Close()
        End If
        Exit Sub
ErrorHandle:
        ShowErr()
    End Sub

    Private Sub bunSearch_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles bunSearch.Click
        On Error GoTo ErrorHandle
        Dim IDQuery As String
        Dim NameQuery As String
        Dim myRow As DataRow
        myIndex = 0
        IDQuery = InputBox("输入要搜索的业务员编号:", "按业务员ID搜索")
        Dim currRows() As DataRow = myDataSet.Tables(0).Select(Nothing, Nothing, DataViewRowState.CurrentRows)
            For Each myRow In currRows
            If myRow("b_id") Like "*" & LCase(IDQuery) & "*" Then
                bshowfield()
                Exit Sub
            Else
                myIndex = myIndex + 1
            End If
        Next
            MsgBox("没有找到符合条件的记录", , "业务员数据表")
            Exit Sub
        Exit Sub
ErrorHandle:
        ShowErr()
    End Sub

    Private Sub bunUpdate_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles bunUpdate.Click
        db.Open()
        myDataAdapter.Update(myDataSet)
        db.Close()
        MsgBox("已经保存修改", , "业务员数据表")
    End Sub
End Class

⌨️ 快捷键说明

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