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

📄 inoutseek.vb

📁 vb.net+sql进销存管理系统
💻 VB
字号:
Imports System.Data.SqlClient

Public Class InOutSeek
    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 GroupBox1 As System.Windows.Forms.GroupBox
    Friend WithEvents btBack As System.Windows.Forms.Button
    Friend WithEvents btOK As System.Windows.Forms.Button
    Friend WithEvents dtPicker2 As System.Windows.Forms.DateTimePicker
    Friend WithEvents dtPicker1 As System.Windows.Forms.DateTimePicker
    Friend WithEvents cbHandler As System.Windows.Forms.ComboBox
    Friend WithEvents cbGoods As System.Windows.Forms.ComboBox
    Friend WithEvents tbDate2 As System.Windows.Forms.TextBox
    Friend WithEvents tbDate1 As System.Windows.Forms.TextBox
    Friend WithEvents Label4 As System.Windows.Forms.Label
    Friend WithEvents Label3 As System.Windows.Forms.Label
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents Label5 As System.Windows.Forms.Label
    Friend WithEvents GroupBox2 As System.Windows.Forms.GroupBox
    Friend WithEvents rbIn As System.Windows.Forms.RadioButton
    Friend WithEvents rbOut As System.Windows.Forms.RadioButton
    Friend WithEvents dgIO As System.Windows.Forms.DataGrid
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.dgIO = New System.Windows.Forms.DataGrid
        Me.GroupBox1 = New System.Windows.Forms.GroupBox
        Me.Label5 = New System.Windows.Forms.Label
        Me.btBack = New System.Windows.Forms.Button
        Me.btOK = New System.Windows.Forms.Button
        Me.dtPicker2 = New System.Windows.Forms.DateTimePicker
        Me.dtPicker1 = New System.Windows.Forms.DateTimePicker
        Me.cbHandler = New System.Windows.Forms.ComboBox
        Me.cbGoods = New System.Windows.Forms.ComboBox
        Me.tbDate2 = New System.Windows.Forms.TextBox
        Me.tbDate1 = New System.Windows.Forms.TextBox
        Me.Label4 = New System.Windows.Forms.Label
        Me.Label3 = New System.Windows.Forms.Label
        Me.Label2 = New System.Windows.Forms.Label
        Me.Label1 = New System.Windows.Forms.Label
        Me.GroupBox2 = New System.Windows.Forms.GroupBox
        Me.rbOut = New System.Windows.Forms.RadioButton
        Me.rbIn = New System.Windows.Forms.RadioButton
        CType(Me.dgIO, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.GroupBox1.SuspendLayout()
        Me.GroupBox2.SuspendLayout()
        Me.SuspendLayout()
        '
        'dgIO
        '
        Me.dgIO.DataMember = ""
        Me.dgIO.HeaderForeColor = System.Drawing.SystemColors.ControlText
        Me.dgIO.Location = New System.Drawing.Point(8, 136)
        Me.dgIO.Name = "dgIO"
        Me.dgIO.ReadOnly = True
        Me.dgIO.Size = New System.Drawing.Size(480, 224)
        Me.dgIO.TabIndex = 0
        '
        'GroupBox1
        '
        Me.GroupBox1.Controls.Add(Me.Label5)
        Me.GroupBox1.Controls.Add(Me.btBack)
        Me.GroupBox1.Controls.Add(Me.btOK)
        Me.GroupBox1.Controls.Add(Me.dtPicker2)
        Me.GroupBox1.Controls.Add(Me.dtPicker1)
        Me.GroupBox1.Controls.Add(Me.cbHandler)
        Me.GroupBox1.Controls.Add(Me.cbGoods)
        Me.GroupBox1.Controls.Add(Me.tbDate2)
        Me.GroupBox1.Controls.Add(Me.tbDate1)
        Me.GroupBox1.Controls.Add(Me.Label4)
        Me.GroupBox1.Controls.Add(Me.Label3)
        Me.GroupBox1.Controls.Add(Me.Label2)
        Me.GroupBox1.Controls.Add(Me.Label1)
        Me.GroupBox1.Controls.Add(Me.GroupBox2)
        Me.GroupBox1.Location = New System.Drawing.Point(8, 8)
        Me.GroupBox1.Name = "GroupBox1"
        Me.GroupBox1.Size = New System.Drawing.Size(480, 110)
        Me.GroupBox1.TabIndex = 1
        Me.GroupBox1.TabStop = False
        Me.GroupBox1.Text = "查询条件"
        '
        'Label5
        '
        Me.Label5.Location = New System.Drawing.Point(8, 24)
        Me.Label5.Name = "Label5"
        Me.Label5.Size = New System.Drawing.Size(72, 23)
        Me.Label5.TabIndex = 32
        Me.Label5.Text = "出入库选择"
        Me.Label5.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
        '
        'btBack
        '
        Me.btBack.Location = New System.Drawing.Point(416, 80)
        Me.btBack.Name = "btBack"
        Me.btBack.Size = New System.Drawing.Size(56, 23)
        Me.btBack.TabIndex = 31
        Me.btBack.Text = "还原"
        '
        'btOK
        '
        Me.btOK.Location = New System.Drawing.Point(352, 80)
        Me.btOK.Name = "btOK"
        Me.btOK.Size = New System.Drawing.Size(56, 23)
        Me.btOK.TabIndex = 29
        Me.btOK.Text = "确定"
        '
        'dtPicker2
        '
        Me.dtPicker2.Location = New System.Drawing.Point(224, 80)
        Me.dtPicker2.Name = "dtPicker2"
        Me.dtPicker2.Size = New System.Drawing.Size(120, 21)
        Me.dtPicker2.TabIndex = 12
        '
        'dtPicker1
        '
        Me.dtPicker1.Location = New System.Drawing.Point(96, 80)
        Me.dtPicker1.Name = "dtPicker1"
        Me.dtPicker1.Size = New System.Drawing.Size(120, 21)
        Me.dtPicker1.TabIndex = 11
        '
        'cbHandler
        '
        Me.cbHandler.Location = New System.Drawing.Point(344, 56)
        Me.cbHandler.Name = "cbHandler"
        Me.cbHandler.Size = New System.Drawing.Size(72, 20)
        Me.cbHandler.TabIndex = 9
        '
        'cbGoods
        '
        Me.cbGoods.Location = New System.Drawing.Point(256, 56)
        Me.cbGoods.Name = "cbGoods"
        Me.cbGoods.Size = New System.Drawing.Size(80, 20)
        Me.cbGoods.TabIndex = 8
        '
        'tbDate2
        '
        Me.tbDate2.Location = New System.Drawing.Point(176, 56)
        Me.tbDate2.Name = "tbDate2"
        Me.tbDate2.ReadOnly = True
        Me.tbDate2.Size = New System.Drawing.Size(64, 21)
        Me.tbDate2.TabIndex = 6
        Me.tbDate2.Text = ""
        '
        'tbDate1
        '
        Me.tbDate1.Location = New System.Drawing.Point(96, 56)
        Me.tbDate1.Name = "tbDate1"
        Me.tbDate1.ReadOnly = True
        Me.tbDate1.Size = New System.Drawing.Size(64, 21)
        Me.tbDate1.TabIndex = 5
        Me.tbDate1.Text = ""
        '
        'Label4
        '
        Me.Label4.Location = New System.Drawing.Point(352, 24)
        Me.Label4.Name = "Label4"
        Me.Label4.Size = New System.Drawing.Size(72, 23)
        Me.Label4.TabIndex = 3
        Me.Label4.Text = "处理者"
        Me.Label4.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
        '
        'Label3
        '
        Me.Label3.Location = New System.Drawing.Point(264, 24)
        Me.Label3.Name = "Label3"
        Me.Label3.Size = New System.Drawing.Size(72, 23)
        Me.Label3.TabIndex = 2
        Me.Label3.Text = "商品"
        Me.Label3.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
        '
        'Label2
        '
        Me.Label2.Location = New System.Drawing.Point(176, 24)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(72, 23)
        Me.Label2.TabIndex = 1
        Me.Label2.Text = "日期(后)"
        Me.Label2.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
        '
        'Label1
        '
        Me.Label1.Location = New System.Drawing.Point(96, 24)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(72, 23)
        Me.Label1.TabIndex = 0
        Me.Label1.Text = "日期(前)"
        Me.Label1.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
        '
        'GroupBox2
        '
        Me.GroupBox2.Controls.Add(Me.rbOut)
        Me.GroupBox2.Controls.Add(Me.rbIn)
        Me.GroupBox2.Location = New System.Drawing.Point(8, 40)
        Me.GroupBox2.Name = "GroupBox2"
        Me.GroupBox2.Size = New System.Drawing.Size(80, 64)
        Me.GroupBox2.TabIndex = 2
        Me.GroupBox2.TabStop = False
        '
        'rbOut
        '
        Me.rbOut.Location = New System.Drawing.Point(8, 40)
        Me.rbOut.Name = "rbOut"
        Me.rbOut.Size = New System.Drawing.Size(56, 24)
        Me.rbOut.TabIndex = 1
        Me.rbOut.Text = "出库"
        '
        'rbIn
        '
        Me.rbIn.Checked = True
        Me.rbIn.Location = New System.Drawing.Point(8, 8)
        Me.rbIn.Name = "rbIn"
        Me.rbIn.Size = New System.Drawing.Size(56, 24)
        Me.rbIn.TabIndex = 0
        Me.rbIn.TabStop = True
        Me.rbIn.Text = "入库"
        '
        'InOutSeek
        '
        Me.AcceptButton = Me.btOK
        Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
        Me.ClientSize = New System.Drawing.Size(492, 366)
        Me.Controls.Add(Me.GroupBox1)
        Me.Controls.Add(Me.dgIO)
        Me.Name = "InOutSeek"
        Me.Text = "出入库查询"
        CType(Me.dgIO, System.ComponentModel.ISupportInitialize).EndInit()
        Me.GroupBox1.ResumeLayout(False)
        Me.GroupBox2.ResumeLayout(False)
        Me.ResumeLayout(False)

    End Sub

#End Region

    Private sql As String = "SELECT INNO AS '编号',INDATE AS '日期',CATEGORYNAME AS '商品',INCOUNT AS '数量',USERNAME AS '处理者',REMARK AS '备注' FROM INVIEW"

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

    Private Sub rbIn_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rbIn.CheckedChanged
        me.SetSql()
    End Sub

    Private Sub rbOut_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rbOut.CheckedChanged
        me.SetSql()
    End Sub

    Private Sub dtPicker1_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dtPicker1.ValueChanged
        Me.tbDate1.Text = Me.dtPicker1.Value.ToShortDateString()
    End Sub

    Private Sub dtPicker2_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dtPicker2.ValueChanged
        Me.tbDate2.Text = Me.dtPicker2.Value.ToShortDateString()
    End Sub

    Private Sub btOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btOK.Click
        If (Me.tbDate1.Text.Trim() = String.Empty) <> (Me.tbDate2.Text.Trim() = String.Empty) Then
            MessageBox.Show("日期不能只填一个")
            Return
        Else
            Me.sql = Me.GetSql().Trim()
            Me.BindDg()

            Me.SetSql()
        End If
    End Sub

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

    Private Sub SetDefault()

        Me.rbIn.Checked = True
        Me.dtPicker1.Value = System.DateTime.Now
        Me.dtPicker2.Value = System.DateTime.Now
        Me.tbDate1.Text = String.Empty
        Me.tbDate2.Text = String.Empty
        Me.cbGoods.Text = String.Empty
        Me.cbHandler.Text = String.Empty

        Me.SetSql()
        Me.BindDg()
    End Sub

    Private Sub SetSql()
        If Me.rbIn.Checked Then
            Me.sql = "SELECT INNO AS '编号',INDATE AS '日期',CATEGORYNAME AS '商品',INCOUNT AS '数量',USERNAME AS '处理者',REMARK AS '备注' FROM INVIEW"
        Else
            Me.sql = "SELECT OUTNO AS '编号',OUTDATE AS '日期',CATEGORYNAME AS '商品',OUTCOUNT AS '数量',USERNAME AS '处理者',REMARK AS '备注'  FROM OUTVIEW"
        End If
    End Sub

    Private Sub BindDg()

        Dim dtNew As DataTable
        Dim SqlAda As New SqlDataAdapter
        Dim SqlCmd As New SqlCommand(Me.sql, Sample02.SqlCon)

        Dim ds As New DataSet

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

            Me.dgIO.DataSource = ds.Tables(0)

        Catch ex As Exception
            Sample02.WriteErr(ex)
        End Try

    End Sub

    Private Function GetSql() As String
        Dim w As String = "WHERE"
        Dim InOut As String = String.Empty
        If Me.rbIn.Checked Then
            InOut = "IN"
        Else
            InOut = "OUT"
        End If

        If Me.tbDate1.Text.Trim() <> String.Empty Then
            w += " " + InOut.Trim() + "DATE BETWEEN '" + Me.tbDate1.Text.Trim() + "' and '" + Me.tbDate2.Text.Trim() + "' "
        End If

        If Me.cbGoods.Text.Trim() <> String.Empty Then
            w += " CATEGORYNAME = '" + Me.cbGoods.Text.Trim() + "'"
        End If

        If Me.cbHandler.Text.Trim() <> String.Empty Then
            w += " USERNAME = '" + Me.cbHandler.Text.Trim() + "'"
        End If

        If w.Trim() = "WHERE" Then
            Return Me.sql
        Else
            Return Me.sql + " " + w
        End If
    End Function
End Class

⌨️ 快捷键说明

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