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

📄 frmcustomer.vb

📁 VB写的进销存管理系统
💻 VB
📖 第 1 页 / 共 2 页
字号:

    End Sub

#End Region
    Private Sub frmCustomer_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ShowStatus("数据管理--", "客户数据表")
        TableName = CurrentTable
        Dim strSelectCustomer As String = "select * from customer"
        Dim cmdSelectCustomer As New SqlClient.SqlCommand(strSelectCustomer, db)
        myDataAdapter.SelectCommand = cmdSelectCustomer
        Dim xx As SqlCommandBuilder = New 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 = "c000000001"
            bunPrevious.Enabled = False
            bunAdd.Enabled = False
            bunDelete.Enabled = False
            bunSearch.Enabled = False
            bunSave.Enabled = False
            bunNext.Enabled = False
            neworchange = True
        Else
            myIndex = 0
            Cshowfield()
        End If
    End Sub

    Private Sub frmCustomer_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Activated
        ShowStatus("数据管理--", "客户数据表")
    End Sub

    Private Sub frmCustomer_Closed(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Closed
        Me.Dispose()
        Me.Close()
        ShowStatus("", "")
        CustomerTableOpened = 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 <> "" 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 <> "" 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 <> "" 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 = "c" & Format(CountInTable, "000000000")
        Else
            IID = "c000000001"
        End If
        TxtId.Text = IID
        txtName.Text = ""
        txtAddr.Text = ""
        txtPhone.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 = ""
            bunAdd.Enabled = True
            neworchange = False
            Exit Sub
        End If
        Cshowfield()
        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 customer where c_id='" & myRow("c_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 = myIndex - 1
                Cshowfield()
            Else
                TxtId.Text = ""
                txtName.Text = ""
                txtAddr.Text = ""
                txtPhone.Text = ""
                bunPrevious.Enabled = False
                bunAdd.Enabled = False
                bunDelete.Enabled = False
                bunSearch.Enabled = False
                bunSave.Enabled = False
                bunNext.Enabled = False
                Exit Sub
            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
        Cshowfield()
    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
        Cshowfield()
    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("c_id") = TxtId.Text
            myRow("c_name") = txtName.Text
            myRow("c_addr") = txtAddr.Text
            myRow("c_phone") = txtPhone.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("c_id") = TxtId.Text
            myRow("c_name") = txtName.Text
            myRow("c_addr") = txtAddr.Text
            myRow("c_phone") = txtPhone.Text
            myDataSet.AcceptChanges()
            Dim strsql As String = "update from customer set c_name='" & myrow("c_name") & "', c_addr='" & myrow("c_addr") & "', c_phone='" & myrow("c_phone") & "' where c_id='" & myrow("c_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("c_id") Like "*" & LCase(IDQuery) & "*" Then
                Cshowfield()
                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 + -