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

📄 frmfactory.vb

📁 VB写的进销存管理系统
💻 VB
📖 第 1 页 / 共 2 页
字号:
        Me.bunDelete.Text = "删除"
        '
        'bunAdd
        '
        Me.bunAdd.Location = New System.Drawing.Point(56, 152)
        Me.bunAdd.Name = "bunAdd"
        Me.bunAdd.Size = New System.Drawing.Size(40, 24)
        Me.bunAdd.TabIndex = 24
        Me.bunAdd.Text = "添加"
        '
        'bunPrevious
        '
        Me.bunPrevious.Location = New System.Drawing.Point(16, 152)
        Me.bunPrevious.Name = "bunPrevious"
        Me.bunPrevious.Size = New System.Drawing.Size(32, 24)
        Me.bunPrevious.TabIndex = 23
        Me.bunPrevious.Text = "<<"
        '
        'bunUpdate
        '
        Me.bunUpdate.Location = New System.Drawing.Point(344, 152)
        Me.bunUpdate.Name = "bunUpdate"
        Me.bunUpdate.Size = New System.Drawing.Size(88, 24)
        Me.bunUpdate.TabIndex = 30
        Me.bunUpdate.Text = "更新到数据库"
        '
        'frmFactory
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
        Me.ClientSize = New System.Drawing.Size(440, 198)
        Me.Controls.Add(Me.bunUpdate)
        Me.Controls.Add(Me.bunNext)
        Me.Controls.Add(Me.bunCancel)
        Me.Controls.Add(Me.bunSave)
        Me.Controls.Add(Me.bunSearch)
        Me.Controls.Add(Me.bunDelete)
        Me.Controls.Add(Me.bunAdd)
        Me.Controls.Add(Me.bunPrevious)
        Me.Controls.Add(Me.Label8)
        Me.Controls.Add(Me.txtManager)
        Me.Controls.Add(Me.Label5)
        Me.Controls.Add(Me.txtPhone)
        Me.Controls.Add(Me.txtAddr)
        Me.Controls.Add(Me.txtName)
        Me.Controls.Add(Me.TxtId)
        Me.Controls.Add(Me.Label4)
        Me.Controls.Add(Me.Label3)
        Me.Controls.Add(Me.Label2)
        Me.Controls.Add(Me.Label1)
        Me.MaximizeBox = False
        Me.MinimizeBox = False
        Me.Name = "frmFactory"
        Me.Text = "frmFactory"
        Me.ResumeLayout(False)

    End Sub

#End Region

    Private Sub frmFactory_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ShowStatus("数据管理--", "厂商数据表")
        TableName = CurrentTable
        Dim strSelectFactory As String = "select * from Factory"
        Dim cmdSelectFactory As New SqlClient.SqlCommand(strSelectFactory, db)
        myDataAdapter.SelectCommand = cmdSelectFactory
        Dim xx As SqlCommandBuilder = New SqlCommandBuilder(myDataAdapter)
        db.Open()
        myDataAdapter.Fill(myDataSet)
        db.Close()
        bunAdd.Enabled = False
        Dim currRows() As DataRow = myDataSet.Tables(0).Select(Nothing, Nothing, DataViewRowState.CurrentRows)
        RowsMax = currRows.Length - 1
        If RowsMax < 0 Then
            myIndex = -1
            MsgBox("数据库中没有记录,请添加厂商!", , "厂商数据表")
            neworchange = False
            bunPrevious.Enabled = False
            bunDelete.Enabled = False
            bunSearch.Enabled = False
            bunSave.Enabled = False
            bunNext.Enabled = False
        Else
            neworchange = True
            FshowField()
        End If
    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 = ""
            txtManager.Text = ""
            txtAddr.Text = ""
            txtPhone.Text = ""
            Exit Sub
        End If
        Fshowfield()
        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 factory where f_id='" & myRow("f_id") & "'"
            Dim mycommand As New SqlClient.SqlCommand(strsql, db)
            db.Open()
            mycommand.ExecuteNonQuery()
            db.Close()
            myRow.Delete()
            RowsMax = RowsMax - 1
            If RowsMax >= 0 Then
                myIndex = myIndex - 1
                Fshowfield()
                Exit Sub
            Else
                TxtId.Text = ""
                txtName.Text = ""
                txtManager.Text = ""
                txtAddr.Text = ""
                txtPhone.Text = ""
                bunPrevious.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
        Fshowfield()
    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
        Fshowfield()
    End Sub

    Private Sub bunSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles bunSave.Click
        On Error GoTo ErrorHandle
        Dim myRow As DataRow = myDataSet.Tables(0).Rows(myIndex)
        myRow("f_id") = TxtId.Text
        myRow("f_name") = txtName.Text
        myRow("f_addr") = txtAddr.Text
        myRow("f_phone") = txtPhone.Text
        myRow("f_manager") = txtManager.Text
        MsgBox("已经保存修改", , "厂商数据表")
        Dim strsql As String = "update factory set f_name='" & myRow("f_name") & "', f_addr='" & myRow("f_addr") & "', f_phone='" & myRow("f_phone") & "', f_manager='" & myRow("f_manager") & "' where f_id='" & myRow("f_id") & "'"
        Dim mycommand As New SqlClient.SqlCommand(strsql, db)
        db.Open()
        mycommand.ExecuteNonQuery()
        db.Close()
        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("f_id") Like "*" & LCase(IDQuery) & "*" Then
                Fshowfield()
                Exit Sub
            Else
                myIndex = myIndex + 1
            End If
        Next
            MsgBox("没有找到符合条件的记录", , "厂商数据表")
            Exit Sub
        Exit Sub
ErrorHandle:
        ShowErr()
    End Sub

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

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

    Private Sub txtName_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtName.TextChanged
        If neworchange Then
            If txtName.Text <> "" Then
                bunSave.Enabled = True
            End If
        End If
    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 + -