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

📄 facform.vb

📁 vb.net+sql进销存管理系统
💻 VB
字号:
Imports System.Data.SqlClient
Public Class FacForm
    Inherits System.Windows.Forms.Form

#Region " Windows 窗体设计器生成的代码 "

    Public Sub New()
        MyBase.New()

        '该调用是 Windows 窗体设计器所必需的。
        InitializeComponent()

        '在 InitializeComponent() 调用之后添加任何初始化

    End Sub

    '窗体重写 dispose 以清理组件列表。
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Windows 窗体设计器所必需的
    Private components As System.ComponentModel.IContainer

    '注意: 以下过程是 Windows 窗体设计器所必需的
    '可以使用 Windows 窗体设计器修改此过程。
    '不要使用代码编辑器修改它。
    Friend WithEvents dgFac As System.Windows.Forms.DataGrid
    Friend WithEvents DataGridTableStyle1 As System.Windows.Forms.DataGridTableStyle
    Friend WithEvents DataGridTextBoxColumn1 As System.Windows.Forms.DataGridTextBoxColumn
    Friend WithEvents DataGridTextBoxColumn2 As System.Windows.Forms.DataGridTextBoxColumn
    Friend WithEvents DataGridTextBoxColumn3 As System.Windows.Forms.DataGridTextBoxColumn
    Friend WithEvents DataGridTextBoxColumn4 As System.Windows.Forms.DataGridTextBoxColumn
    Friend WithEvents DataGridTextBoxColumn5 As System.Windows.Forms.DataGridTextBoxColumn
    Friend WithEvents DataGridTextBoxColumn6 As System.Windows.Forms.DataGridTextBoxColumn
    Friend WithEvents btOK As System.Windows.Forms.Button
    Friend WithEvents btBack As System.Windows.Forms.Button
    Friend WithEvents btCancel As System.Windows.Forms.Button
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.dgFac = New System.Windows.Forms.DataGrid
        Me.DataGridTableStyle1 = New System.Windows.Forms.DataGridTableStyle
        Me.DataGridTextBoxColumn1 = New System.Windows.Forms.DataGridTextBoxColumn
        Me.DataGridTextBoxColumn2 = New System.Windows.Forms.DataGridTextBoxColumn
        Me.DataGridTextBoxColumn3 = New System.Windows.Forms.DataGridTextBoxColumn
        Me.DataGridTextBoxColumn4 = New System.Windows.Forms.DataGridTextBoxColumn
        Me.DataGridTextBoxColumn5 = New System.Windows.Forms.DataGridTextBoxColumn
        Me.DataGridTextBoxColumn6 = New System.Windows.Forms.DataGridTextBoxColumn
        Me.btOK = New System.Windows.Forms.Button
        Me.btBack = New System.Windows.Forms.Button
        Me.btCancel = New System.Windows.Forms.Button
        CType(Me.dgFac, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.SuspendLayout()
        '
        'dgFac
        '
        Me.dgFac.DataMember = ""
        Me.dgFac.HeaderForeColor = System.Drawing.SystemColors.ControlText
        Me.dgFac.Location = New System.Drawing.Point(10, 10)
        Me.dgFac.Name = "dgFac"
        Me.dgFac.Size = New System.Drawing.Size(470, 318)
        Me.dgFac.TabIndex = 0
        Me.dgFac.TableStyles.AddRange(New System.Windows.Forms.DataGridTableStyle() {Me.DataGridTableStyle1})
        '
        'DataGridTableStyle1
        '
        Me.DataGridTableStyle1.DataGrid = Me.dgFac
        Me.DataGridTableStyle1.GridColumnStyles.AddRange(New System.Windows.Forms.DataGridColumnStyle() {Me.DataGridTextBoxColumn1, Me.DataGridTextBoxColumn2, Me.DataGridTextBoxColumn3, Me.DataGridTextBoxColumn4, Me.DataGridTextBoxColumn5, Me.DataGridTextBoxColumn6})
        Me.DataGridTableStyle1.HeaderForeColor = System.Drawing.SystemColors.ControlText
        Me.DataGridTableStyle1.MappingName = ""
        '
        'DataGridTextBoxColumn1
        '
        Me.DataGridTextBoxColumn1.Format = ""
        Me.DataGridTextBoxColumn1.FormatInfo = Nothing
        Me.DataGridTextBoxColumn1.HeaderText = "厂商编号"
        Me.DataGridTextBoxColumn1.MappingName = "FACTORYNO"
        Me.DataGridTextBoxColumn1.Width = 50
        '
        'DataGridTextBoxColumn2
        '
        Me.DataGridTextBoxColumn2.Format = ""
        Me.DataGridTextBoxColumn2.FormatInfo = Nothing
        Me.DataGridTextBoxColumn2.HeaderText = "厂商名称"
        Me.DataGridTextBoxColumn2.MappingName = "FACTORYNAME"
        Me.DataGridTextBoxColumn2.Width = 75
        '
        'DataGridTextBoxColumn3
        '
        Me.DataGridTextBoxColumn3.Format = ""
        Me.DataGridTextBoxColumn3.FormatInfo = Nothing
        Me.DataGridTextBoxColumn3.HeaderText = "联系电话"
        Me.DataGridTextBoxColumn3.MappingName = "TELEPHONE"
        Me.DataGridTextBoxColumn3.Width = 75
        '
        'DataGridTextBoxColumn4
        '
        Me.DataGridTextBoxColumn4.Format = ""
        Me.DataGridTextBoxColumn4.FormatInfo = Nothing
        Me.DataGridTextBoxColumn4.HeaderText = "地址"
        Me.DataGridTextBoxColumn4.MappingName = "ADDRESS"
        Me.DataGridTextBoxColumn4.Width = 75
        '
        'DataGridTextBoxColumn5
        '
        Me.DataGridTextBoxColumn5.Format = ""
        Me.DataGridTextBoxColumn5.FormatInfo = Nothing
        Me.DataGridTextBoxColumn5.HeaderText = "邮编"
        Me.DataGridTextBoxColumn5.MappingName = "POSTCODE"
        Me.DataGridTextBoxColumn5.Width = 75
        '
        'DataGridTextBoxColumn6
        '
        Me.DataGridTextBoxColumn6.Format = ""
        Me.DataGridTextBoxColumn6.FormatInfo = Nothing
        Me.DataGridTextBoxColumn6.HeaderText = "备注"
        Me.DataGridTextBoxColumn6.MappingName = "REMARK"
        Me.DataGridTextBoxColumn6.Width = 75
        '
        'btOK
        '
        Me.btOK.Location = New System.Drawing.Point(296, 336)
        Me.btOK.Name = "btOK"
        Me.btOK.Size = New System.Drawing.Size(56, 23)
        Me.btOK.TabIndex = 1
        Me.btOK.Text = "更新"
        '
        'btBack
        '
        Me.btBack.Location = New System.Drawing.Point(360, 336)
        Me.btBack.Name = "btBack"
        Me.btBack.Size = New System.Drawing.Size(56, 23)
        Me.btBack.TabIndex = 2
        Me.btBack.Text = "还原"
        '
        'btCancel
        '
        Me.btCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel
        Me.btCancel.Location = New System.Drawing.Point(424, 336)
        Me.btCancel.Name = "btCancel"
        Me.btCancel.Size = New System.Drawing.Size(56, 23)
        Me.btCancel.TabIndex = 3
        Me.btCancel.Text = "退出"
        '
        'FacForm
        '
        Me.AcceptButton = Me.btOK
        Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
        Me.CancelButton = Me.btCancel
        Me.ClientSize = New System.Drawing.Size(492, 366)
        Me.Controls.Add(Me.btCancel)
        Me.Controls.Add(Me.btBack)
        Me.Controls.Add(Me.btOK)
        Me.Controls.Add(Me.dgFac)
        Me.Name = "FacForm"
        Me.StartPosition = System.Windows.Forms.FormStartPosition.Manual
        Me.Text = "厂商管理"
        CType(Me.dgFac, System.ComponentModel.ISupportInitialize).EndInit()
        Me.ResumeLayout(False)

    End Sub

#End Region

    Private SqlAda As New SqlDataAdapter
    Private SqlCmd As New SqlCommand("SELECT * FROM FACTORY", Sample02.SqlCon)

    Private ds As New DataSet
    Private dt_Row As Int16
    Private dt_Col As Int16

    Private s As Boolean = False

    Private Sub FacForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.BindDg()
    End Sub

    Private Sub btOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btOK.Click

        Dim flag As Boolean = True

        If dt_Row < ds.Tables(0).Rows.Count Then
            Dim No_New As String = String.Empty
            No_New = Convert.ToString(Me.dgFac.Item(dt_Row, 0)).Trim()
            If No_New = String.Empty Then
                MessageBox.Show("新增编号不能为空")
                Me.dgFac.CurrentCell = New DataGridCell(dt_Row, 0)
                flag = False
            Else
                For i As Int16 = 0 To dt_Row - 1
                    If No_New = Convert.ToString(Me.dgFac.Item(i, 0)).Trim() Then
                        MessageBox.Show("新增编号与第" + (i + 1).ToString().Trim() + "行编号重复")
                        Me.dgFac.CurrentCell = New DataGridCell(dt_Row, 0)
                        flag = False
                    End If
                Next
            End If
        End If

        If flag Then

            Try
                Dim SqlBuilder As New SqlCommandBuilder(SqlAda)
                SqlAda.Update(ds.Tables(0))
                MessageBox.Show("更新成功")
            Catch ex As Exception
                Sample02.WriteErr(ex)
                MessageBox.Show("更新失败")
            End Try

            Me.BindDg()
        End If
    End Sub

    Private Sub btBack_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btBack.Click
        Me.BindDg()
    End Sub


    Private Sub btCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btCancel.Click
        Me.Close()
    End Sub

    Private Sub BindDg()

        Try
            SqlAda.SelectCommand = SqlCmd
            ds.Clear()
            SqlAda.Fill(ds)

            Me.dgFac.TableStyles(0).MappingName = ds.Tables(0).TableName.Trim()
            Me.dgFac.DataSource = ds.Tables(0)
            Me.dgFac.CurrentCell = New DataGridCell(0, 1)

            dt_Row = ds.Tables(0).Rows.Count
            dt_Col = ds.Tables(0).Columns.Count

            s = False
        Catch ex As Exception
            Sample02.WriteErr(ex)
        End Try
    End Sub

    Private Sub dgFac_CurrentCellChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles dgFac.CurrentCellChanged
        Dim Cell As DataGridCell = Me.dgFac.CurrentCell

        Dim Row As Int16 = Cell.RowNumber
        Dim Col As Int16 = Cell.ColumnNumber

        If Row < dt_Row And Col = 0 And s Then
            MessageBox.Show("编号不能修改")
            Me.dgFac.CurrentCell = New DataGridCell(Row, 1)
        ElseIf Row = dt_Row + 1 Then
            MessageBox.Show("一次只能添加一条记录")
            Me.dgFac.CurrentCell = New DataGridCell(dt_Row, 0)
        End If

        s = True
    End Sub

End Class

⌨️ 快捷键说明

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