-
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
栏目列表
最新更新
nodejs爬虫
Python正则表达式完全指南
爬取豆瓣Top250图书数据
shp 地图文件批量添加字段
爬虫小试牛刀(爬取学校通知公告)
【python基础】函数-初识函数
【python基础】函数-返回值
HTTP请求:requests模块基础使用必知必会
Python初学者友好丨详解参数传递类型
如何有效管理爬虫流量?
SQL SERVER中递归
2个场景实例讲解GaussDB(DWS)基表统计信息估
常用的 SQL Server 关键字及其含义
动手分析SQL Server中的事务中使用的锁
openGauss内核分析:SQL by pass & 经典执行
一招教你如何高效批量导入与更新数据
天天写SQL,这些神奇的特性你知道吗?
openGauss内核分析:执行计划生成
[IM002]Navicat ODBC驱动器管理器 未发现数据
初入Sql Server 之 存储过程的简单使用
这是目前我见过最好的跨域解决方案!
减少回流与重绘
减少回流与重绘
如何使用KrpanoToolJS在浏览器切图
performance.now() 与 Date.now() 对比
一款纯 JS 实现的轻量化图片编辑器
关于开发 VS Code 插件遇到的 workbench.scm.
前端设计模式——观察者模式
前端设计模式——中介者模式
创建型-原型模式