开发实践教程1:试卷生成系统6.18用户查询(FormUserQuery)
Posted VB.Net
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了开发实践教程1:试卷生成系统6.18用户查询(FormUserQuery)相关的知识,希望对你有一定的参考价值。
设置搜索用户相关条件。
窗体设计如下:
图1-28
具体代码如下:
Public Class FormUserQuery
Dim fUserList As New FormUserList
Private Sub FormUserQuery_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Call drawUI()
fUserList = Me.Owner.ActiveMdiChild
End Sub
Private Sub drawUI()
cbState.Text = cbState.Items(0)
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
If ckName.Checked = True Then
checkCondition = True
If txtName.Text.Trim = "" Then
MessageBox.Show("用户账号不能为空值")
Exit Sub
End If
SqlWhere = getName()
End If
If ckTrueName.Checked = True Then
checkCondition = True
If txtTrueName.Text.Trim = "" Then
MessageBox.Show("真实姓名不能为空值")
Exit Sub
End If
subSqlWhere = getTrueName()
SqlWhere = IIf(SqlWhere = "", subSqlWhere, SqlWhere & " And " & subSqlWhere)
End If
If ckNumber.Checked = True Then
checkCondition = True
If txtNumber.Text.Trim = "" Then
MessageBox.Show("身份证号不能为空值")
Exit Sub
End If
subSqlWhere = getNumber()
SqlWhere = IIf(SqlWhere = "", subSqlWhere, SqlWhere & " And " & subSqlWhere)
End If
If ckTime.Checked = True Then
checkCondition = True
If (CType(dtpStart.Value.ToString("yyyy-MM-dd") & " 00:00:00", Date) - CType(dtpEnd.Value.ToString("yyyy-MM-dd") & " 00:00:00", Date)).TotalSeconds > 0 Then
MessageBox.Show("起始时间应小于结束时间")
Exit Sub
End If
subSqlWhere = getTime()
SqlWhere = IIf(SqlWhere = "", subSqlWhere, SqlWhere & " And " & subSqlWhere)
End If
If ckState.Checked = True Then
checkCondition = True
subSqlWhere = getState()
SqlWhere = IIf(SqlWhere = "", subSqlWhere, SqlWhere & " And " & subSqlWhere)
End If
If checkCondition = False Then
MessageBox.Show("必须勾选一个查询条件")
Exit Sub
End If
SqlWhere = SqlWhere & " And (账号<>'admin') "
fUserList.customWhere = SqlWhere
Me.Close()
End Sub
#Region "设置各个条件下的查询语句"
Private Function getName() As String
Return "(账号 like '%" & txtName.Text.Trim & "%')"
End Function
Private Function getTrueName() As String
Return "(真实姓名 like '%" & txtTrueName.Text.Trim & "%')"
End Function
Private Function getNumber() As String
Return "(身份证号码 like '%" & txtNumber.Text.Trim & "%')"
End Function
Private Function getTime() As String
Dim timeStart, timeEnd As String
timeStart = dtpStart.Value.ToString("yyyy-MM-dd") & " 00:00:00"
timeEnd = dtpEnd.Value.ToString("yyyy-MM-dd") & " 23:59:59"
Return "(申请时间 between '" & timeStart & "' and '" & timeEnd & "')"
End Function
Private Function getState() As String
Return "(状态='" & cbState.Text & "')"
End Function
#End Region
Private Sub btnClose_Click(sender As Object, e As EventArgs) Handles btnClose.Click
Me.Close()
End Sub
Private Sub dtpStart_CloseUp(sender As Object, e As EventArgs) Handles dtpStart.CloseUp
If (CType(dtpStart.Value.ToString("yyyy-MM-dd") & " 00:00:00", Date) - CType(dtpEnd.Value.ToString("yyyy-MM-dd") & " 00:00:00", Date)).TotalSeconds > 0 Then
dtpEnd.Value = CType(dtpStart.Value.ToString("yyyy-MM-dd") & " 23:59:59", Date)
End If
dtpStart.Value = CType(dtpStart.Value.ToString("yyyy-MM-dd") & " 00:00:00", Date)
End Sub
Private Sub dtpEnd_CloseUp(sender As Object, e As EventArgs) Handles dtpEnd.CloseUp
If (CType(dtpStart.Value.ToString("yyyy-MM-dd") & " 00:00:00", Date) - CType(dtpEnd.Value.ToString("yyyy-MM-dd") & " 00:00:00", Date)).TotalSeconds > 0 Then
dtpStart.Value = CType(dtpEnd.Value.ToString("yyyy-MM-dd") & " 00:00:00", Date)
End If
dtpEnd.Value = CType(dtpEnd.Value.ToString("yyyy-MM-dd") & " 23:59:59", Date)
End Sub
End Class
由于.net平台下C#和vb.NET很相似,本文也可以为C#爱好者提供的参考。
学习更多vb.net知识,请参看 vb.net 教程 目录
以上是关于开发实践教程1:试卷生成系统6.18用户查询(FormUserQuery)的主要内容,如果未能解决你的问题,请参考以下文章
开发实践教程1:试卷生成系统6.10 载入试卷(FormLoadTestPaper)
开发实践教程1:试卷生成系统6.4 考题管理(FormExam)
开发实践教程1:试卷生成系统6.19用户备注(FormUserMemo)