VB.net 2010 视频教程 VB.net 2010 视频教程 python基础视频教程
SQL Server 2008 视频教程 c#入门经典教程 Visual Basic从门到精通视频教程
当前位置:
首页 > VB.net教程 >
  • vb.net 教程 20-4 库存管理系统3.13 出库单查询(FormStorageOutQuery)

版权声明:本文为博主原创文章,转载请在显著位置标明本文出处以及作者网名,未经作者允许不得用于商业目的。
 
    关于《Visual Basic.Net 循序渐进》请到百度网盘下载,具体下载地址:
    链接:https://pan.baidu.com/s/1IfaLvlklx-nT4KK4VKZuIw 
    提取码:ip5n
 
 
 
    全部代码如下:
 
 
Imports System.ComponentModel
Imports System.Data.OleDb
 
Public Class FormStorageOutQuery
    Dim connection As OleDbConnection
    Dim arrRecordUser As List(Of Integer)
 
    Private Sub FormStockOutQuery_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        arrRecordUser = New List(Of Integer)
 
        connection = New OleDbConnection(databaseConnString)
        '打开数据连接
        connection.Open()
 
        '新建OleDbCommand对象实例
        Dim command As New OleDbCommand()
 
        '=========填充操作员选择框==================
        '要执行的SQL查询
        command.CommandText = "select ID,姓名 from 操作员"
        '设置OleDbCommand的数据连接为OleDbConnection
        command.Connection = connection
 
        '声明OleDbDataReader对象
        Dim odReader As OleDbDataReader
        odReader = command.ExecuteReader()
 
        '如果OleDbDataReader中包含数据
        If odReader.HasRows Then
            '循环读取每一行数据,直到Read方法返回False
            Do While odReader.Read
                arrRecordUser.Add(odReader.GetValue(0))
                cbRecordUser.Items.Add(odReader.GetValue(1))
            Loop
        End If
        odReader.Close()
 
        If cbRecordUser.Items.Count > 0 Then
            cbRecordUser.SelectedIndex = 0
        End If
        cbOrderCondition.SelectedIndex = 0
        cbSendCondition.SelectedIndex = 0
        If cbRecordUser.Items.Count > 0 Then cbRecordUser.SelectedIndex = 0
    End Sub
 
    Private Sub FormStockOutQuery_Closing(sender As Object, e As CancelEventArgs) Handles Me.Closing
        connection.Close()
    End Sub
 
    Private Sub btnOk_Click(sender As Object, e As EventArgs) Handles btnOk.Click
        Dim SqlWhere As String = ""
        Dim subSqlWhere As String = ""
 
        '判断是否勾选了查询条件
        Dim checkCondition As Boolean = False
 
        '构建查询的where语句
        '1、出库单号
        If ckOrderID.Checked = True Then
            checkCondition = True
            If txtOrderID.Text.Trim = "" Then
                MessageBox.Show("订单编号不能为空值")
                Exit Sub
            End If
            SqlWhere = getSqlOrderID()
        End If
 
        '2、操作人员
        If ckRecordUser.Checked = True Then
            checkCondition = True
            If cbRecordUser.Text = "" Then
                MessageBox.Show("操作人员姓名不能为空值")
                Exit Sub
            End If
            subSqlWhere = getRecordUser()
            SqlWhere = IIf(SqlWhere = "", subSqlWhere, SqlWhere & " And " & subSqlWhere)
        End If
 
        '3、快递单号
        If ckExpressID.Checked = True Then
            checkCondition = True
            If txtExpressID.Text.Trim = "" Then
                MessageBox.Show("订单编号不能为空值")
                Exit Sub
            End If
            subSqlWhere = getExpressID()
            SqlWhere = IIf(SqlWhere = "", subSqlWhere, SqlWhere & " And " & subSqlWhere)
        End If
 
        '4、订购日期
        If ckOrder.Checked = True Then
            checkCondition = True
            subSqlWhere = getOrder()
            SqlWhere = IIf(SqlWhere = "", subSqlWhere, SqlWhere & " And " & subSqlWhere)
        End If
 
        '5、发货日期
        If ckSend.Checked = True Then
            checkCondition = True
            subSqlWhere = getSend()
            SqlWhere = IIf(SqlWhere = "", subSqlWhere, SqlWhere & " And " & subSqlWhere)
        End If
 
        '6、买家姓名
        If ckName.Checked = True Then
            checkCondition = True
            If txtName.Text.Trim = "" Then
                MessageBox.Show("订单编号不能为空值")
                Exit Sub
            End If
            subSqlWhere = getName()
            SqlWhere = IIf(SqlWhere = "", subSqlWhere, SqlWhere & " And " & subSqlWhere)
        End If
 
        '7、手机号码
        If ckTel.Checked = True Then
            checkCondition = True
            If txtTel.Text.Trim = "" Then
                MessageBox.Show("订单编号不能为空值")
                Exit Sub
            End If
            subSqlWhere = getTel()
            SqlWhere = IIf(SqlWhere = "", subSqlWhere, SqlWhere & " And " & subSqlWhere)
        End If
 
        If checkCondition = False Then
            MessageBox.Show("必须勾选一个查询条件")
            Exit Sub
        End If
 
        '关闭此窗口
        Dim F_StorageOut As FormStorageOut
        F_StorageOut = Me.Owner
        F_StorageOut.customWhere = SqlWhere
        Me.Close()
 
    End Sub
 
#Region "设置各个条件下的查询语句"
 
    '注意:查询条件在使用like时
    '在Access中,应该使用*
    '在vb中,应该使用%
    Private Function getSqlOrderID() As String
        Return "(出库单.订单ID like '%" & txtOrderID.Text.Trim & "%')"
    End Function
 
    Private Function getRecordUser() As String
        Return "(出库单.雇员ID=" & arrRecordUser(cbRecordUser.SelectedIndex) & ")"
    End Function
 
    Private Function getExpressID() As String
        Return "(出库单.快递单号 like '%" & txtExpressID.Text.Trim & "%')"
    End Function
 
    Private Function getOrder() As String
        If cbOrderCondition.Text = "等于" Then
            Return "(出库单.订购日期 between #" & dtpOrderStart.Text & " 0:00:00# and #" & dtpOrderStart.Text & " 23:59:59#)"
        Else
            Return "(出库单.订购日期 between #" & dtpOrderStart.Text & " 0:00:00# and #" & dtpOrderEnd.Text & " 23:59:59#)"
        End If
    End Function
 
    Private Function getSend() As String
        If cbSendCondition.Text = "等于" Then
            Return "(出库单.订购日期 between #" & dtpSendStart.Text & " 0:00:00# and #" & dtpSendStart.Text & " 23:59:59#)"
        Else
            Return "(出库单.订购日期 between #" & dtpSendStart.Text & " 0:00:00# and #" & dtpSendEnd.Text & " 23:59:59#)"
        End If
    End Function
 
    Private Function getName() As String
        Return "(出库单.买家姓名 like '%" & txtName.Text.Trim & "%')"
    End Function
 
    Private Function getTel() As String
        Return "(出库单.买家手机号码 like '%" & txtTel.Text.Trim & "%')"
    End Function
 
#End Region
 
    Private Sub btnCancel_Click(sender As Object, e As EventArgs) Handles btnCancel.Click
        Dim F_StorageOut As FormStorageOut
        F_StorageOut = Me.Owner
        F_StorageOut.customWhere = ""
        Me.Close()
    End Sub
End Class
由于.net平台下C#和vb.NET很相似,本文也可以为C#爱好者提供的参考。
————————————————
版权声明:本文为CSDN博主「VB.Net」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/UruseiBest/article/details/114224669

相关教程