开发者社区> 丁国华> 正文
阿里云
为了无法计算的价值
打开APP
阿里云APP内打开

VB.NET版机房收费系统---组合查询

简介:        查询的意思就是查找,寻找,指在某一个或几个地方找出自己所要的信息,假如我想搜索一下我自己写的博客,名字叫做初雪之恋,我在百度的搜索框中输入丁国华三个字,会有怎样的惊喜等着我?                          ...
+关注继续查看

       查询的意思就是查找,寻找,指在某一个或几个地方找出自己所要的信息,假如我想搜索一下我自己写的博客,名字叫做初雪之恋,我在百度的搜索框中输入丁国华三个字,会有怎样的惊喜等着我?

        

       

          啊哦,这个信息并不是我想要的,于是我再搜,“丁国华 廊坊师范学院  csdn”搜索结果如下:

        

           很显然,这个还不是我想要的结果,我接着搜,“丁国华 廊坊师范学院 csdn 初雪之恋”;

        

        在我的理解中,组合查询就是通过条件层层限制,一步一步精确,得到我们想要的答案,在机房收费系统中,有好几处涉及组合查询,接下来,以学生基本信息维护为例,讲解组合查询。在第二次机房收费系统中,我没有按原来胡阳版的模板来,原版的通过卡号,学号,姓名,性别,系别,年级,班号七个字段,来进行查询,操作符分别为等于,大于,小于,不等于,可是,现实生活中哪有性别大于什么,姓名小于什么的条件,所以我重新设计了一下窗体,从中挑选了四个字段名作为组合查询的条件简化了组合查询的难度,主界面设计如下:

         

         接下来,看看我们的具体实现过程,首先实体层---E层;

           

<span style="font-size:18px;">Public Class Studentinfo
    Public studentNo As String                      '字段
    Public Property _studentNo As String            '属性
        Get
            Return studentNo
        End Get
        Set(value As String)
            studentNo = value
        End Set
    End Property
    Public cardNo As String
    Public Property _cardNo As String
        Get
            Return cardNo
        End Get
        Set(value As String)
            cardNo = value
        End Set
    End Property
    Public studentName As String
    Public Property _studentName As String
        Get
            Return studentName
        End Get
        Set(value As String)
            studentName = value
        End Set
    End Property
    Public sex As String
    Public Property _sex As String
        Get
            Return sex
        End Get
        Set(value As String)
            sex = value
        End Set
    End Property
    Public department As String
    Public Property _department
        Get
            Return department
        End Get
        Set(value)
            department = value
        End Set
    End Property
    Public grade As String
    Public Property _grade
        Get
            Return grade
        End Get
        Set(value)
            grade = value
        End Set
    End Property
    Public stuclass As String
    Public Property _stuclass
        Get
            Return stuclass
        End Get
        Set(value)
            stuclass = value
        End Set
    End Property
    Public remark As String
    Public Property _remark
        Get
            Return remark
        End Get
        Set(value)
            remark = value
        End Set
    End Property
    Public Handler As String
    Public Property _Handler
        Get
            Return Handler
        End Get
        Set(value)
            Handler = value
        End Set
    End Property
End Class
</span>
         数据访问层---D层

           

<span style="font-size:18px;">Imports System.Data.SqlClient
Public Class StuBaInforPreserveDAO
    Public Function query(ByVal cmbOperator1 As String, ByVal cardNo As String, ByVal cmbOperator2 As String, ByVal studentNo As String, ByVal cmbOperator3 As String, ByVal department As String, ByVal cmbOperator4 As String, ByVal grade As String) As DataTable
        Dim db As New Entity.Dbutil '实例化数据库连接
        Dim dt As New DataTable       '实例化DataTable

        Using conn As New SqlConnection(db.connstring)
            conn.Open()                       '打开数据库连接

            Dim sql As String
            Dim cmd As SqlCommand
            Dim dataAdpter As New SqlDataAdapter
            Dim dst As New DataSet
            Dim flag(3) As Boolean             ’定义标签

            sql = "select studentNo,cardNo,studentName,sex,department,grade,class,remark,handler  from Student_info where "
            If Not (cardNo = "") Then                                   '如果卡号不为空,执行下面这句sql语句
                sql = sql & "studentNo" & cmbOperator1 & "'" & cardNo & "'"
                flag(0) = True
            End If

            If Not (studentNo = "") Then     '如果学号不为空,且卡号不为空,执行第一个sql语句,如果学号不为空,卡号为空执行第二个sql语句
                flag(1) = True
                If flag(0) = True Then
                    sql = sql & "and studentNo " & cmbOperator2 & "'" & studentNo & "'"
                Else
                    sql = sql & "studentNo" & cmbOperator2 & "'" & studentNo & "'"
                End If
            End If

            If Not (department = "") Then '如果系别不为空,且学号和卡号中有一个被选择,或者两个都选,执行第一个sql语句,否则执行第二个sql语句
                flag(2) = True
                If flag(0) = True Or flag(1) = True Then
                    sql = sql & "and department " & cmbOperator3 & "'" & department & "'"
                Else
                    sql = sql & "department" & cmbOperator3 & "'" & department & "'"
                End If
            End If

            If Not (grade = "") Then      '如果年级不为空,且学号,卡号,系别中有一个被选择,或者一个or两个被选择执行第一个sql语句,否则执行第二句
                flag(3) = True
                If flag(0) = True Or flag(1) = True Or flag(2) = True Then
                    sql = sql & "and grade" & cmbOperator4 & "'" & grade & "'"
                Else
                    sql = sql & "grade" & cmbOperator4 & "'" & grade & "'"
                End If
            End If
            cmd = New SqlCommand(sql, conn)
            dataAdpter.SelectCommand = cmd
            dataAdpter.Fill(dst, "Student_info")
            dt = dst.Tables("Student_info")
        End Using
        Return dt
    End Function
End Class
</span>
            业务逻辑层---B层;

             

<span style="font-size:18px;">Public Class StuBaInforPreserveManager
    Public Function query(ByVal cmbOperator1 As String, ByVal cardNo As String, ByVal cmbOperator2 As String, ByVal studentNo As String, ByVal cmbOperator3 As String, ByVal department As String, ByVal cmbOperator4 As String, ByVal grade As String) As DataTable
        Dim StuBaInforPreserveDAO As New DAL.StuBaInforPreserveDAO                 '调用D层
        Return StuBaInforPreserveDAO.query(cmbOperator1, cardNo, cmbOperator2, studentNo, cmbOperator3, department, cmbOperator4, grade)
    End Function
End Class</span>
        显示层---U层;

       

<span style="font-size:18px;">Imports BLL

Public Class frmStuBaInforPreserve
    Private Sub btnInquery_Click(sender As Object, e As EventArgs) Handles btnInquery.Click
        Dim StuBaInforPreserveManager As New BLL.StuBaInforPreserveManager  '调用B层
        Dim dt As New DataTable

        dt = StuBaInforPreserveManager.query(cmbOperator1.Text, txtCardNo.Text, cmbOperator2.Text, txtStuNo.Text, cmbOperator3.Text, txtDepartment.Text, cmbOperator4.Text, txtGrade.Text)
        DataGridView1.AutoGenerateColumns = True  '自动创建列
        DataGridView1.DataSource = dt

        DataGridView1.Columns(0).HeaderText = "学号"         '把相关信息在datagridview中显示出来
        DataGridView1.Columns(1).HeaderText = "卡号"
        DataGridView1.Columns(2).HeaderText = "姓名"
        DataGridView1.Columns(3).HeaderText = "性别"
        DataGridView1.Columns(4).HeaderText = "系别"
        DataGridView1.Columns(5).HeaderText = "年级"
        DataGridView1.Columns(6).HeaderText = "班级"
        DataGridView1.Columns(7).HeaderText = "备注"


    End Sub

    Private Sub frmStuBaInforPreserve_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        cmbOperator1.Enabled = False             '窗体加载时,需要注意的一些细节问题,比如那些按钮能点,那些不能点
        txtCardNo.Text = ""
        txtCardNo.Enabled = False

        cmbOperator1.Items.Add("=")
        cmbOperator1.Items.Add(">")
        cmbOperator1.Items.Add("<")
        cmbOperator1.Items.Add("<>")
        cmbOperator1.SelectedIndex = 0

        cmbOperator2.Enabled = False
        txtStuNo.Text = ""
        txtStuNo.Enabled = False
        cmbOperator2.Items.Add("=")
        cmbOperator2.Items.Add(">")
        cmbOperator2.Items.Add("<")
        cmbOperator2.Items.Add("<>")
        cmbOperator2.SelectedIndex = 0

        cmbOperator3.Enabled = False
        txtDepartment.Text = ""
        txtDepartment.Enabled = False
        cmbOperator3.Items.Add("=")
        cmbOperator3.Items.Add("<>")
        cmbOperator3.SelectedIndex = 0

        cmbOperator4.Enabled = False
        txtGrade.Text = ""
        txtGrade.Enabled = False
        cmbOperator4.Items.Add("=")
        cmbOperator4.Items.Add("<>")
        cmbOperator4.SelectedIndex = 0

    End Sub

    Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click        '退出按钮
        Me.Close()
    End Sub
    Private Sub chkCardNo_Click(sender As Object, e As EventArgs) Handles chkCardNo.Click  '如果卡号被选中,则txtCardNo和cmbOperator1可以点否者不能点,并且文本框的内容自动情况,恢复默认值
        If chkCardNo.Checked Then
            txtCardNo.Enabled = True
            cmbOperator1.Enabled = True
        Else
            txtCardNo.Enabled = False
            cmbOperator1.Enabled = False
            txtCardNo.Text = ""
            cmbOperator1.SelectedIndex = 0

        End If
    End Sub
    Private Sub chkStuNo_Click(sender As Object, e As EventArgs) Handles chkStuNo.Click
        If chkStuNo.Checked Then
            txtStuNo.Enabled = True
            cmbOperator2.Enabled = True
        Else
            txtStuNo.Enabled = False
            cmbOperator2.Enabled = False
            txtStuNo.Text = ""
            cmbOperator2.SelectedIndex = 0
        End If
    End Sub

   
    Private Sub chkDepartment_Click(sender As Object, e As EventArgs) Handles chkDepartment.Click
        If chkDepartment.Checked Then
            txtDepartment.Enabled = True
            cmbOperator3.Enabled = True
        Else
            txtDepartment.Enabled = False
            cmbOperator3.Enabled = False
            txtDepartment.Text = ""
            cmbOperator3.SelectedIndex = 0
        End If
    End Sub
    Private Sub chkGrade_Click(sender As Object, e As EventArgs) Handles chkGrade.Click
        If chkGrade.Checked Then
            txtGrade.Enabled = True
            cmbOperator4.Enabled = True
        Else
            txtGrade.Enabled = False
            cmbOperator4.Enabled = False
            txtGrade.Text = ""
            cmbOperator4.SelectedIndex = 0
        End If
    End Sub
End Class</span>

      运行效果如下:

      

      自此学生基本信息维护就暂时告一段落,开始敲学生基本信息维护的时候,不知道从哪儿下手,各种纠结,各种逃避,各种不想敲,可是,我已经长大了,我不能再由着我自己的性子来做事,我要为我自己做的事情负责任,走过去了,真的有那么困难么?我想其中的滋味只有走过的人才能够真正明白。

       曾经看到米老师给一篇博文这样的评语,这篇博客的主要内容,我记不清楚了,好像是解决一个问题,然后成功解决的一篇博文,米老师说,这个过程是不是很养人,对,这个过程不光养人,而且锻炼人,考验我们面对新知识的心态,是一拖再拖,今目标红了又红,还是坦然面对,两天把三个组合查询一一搞定,机房收费系统未完,待续......

版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。

相关文章
【夯实Java基础】(二)掌握面向对象编程的正确姿势
【夯实Java基础】(二)掌握面向对象编程的正确姿势
29 0
毕业设计So Easy:基于Java Web学生选课系统
毕业设计So Easy:基于Java Web学生选课系统
343 0
《JavaScript面向对象编程指南(第2版)》——1.6 面向对象的程序设计
现在,我们就来详细了解每个概念。当然,如果您在面向对象程序设计方面是一个新手,或者不能确定自己是否真的理解了这些概念,那也不必太过担心。以后我们还会通过一些代码来为您具体分析它们。尽管这些概念说起来好像很复杂、很高级,但一旦我们进入真正的实践,事情往往就会简单得多。
1493 0
《JavaScript面向对象编程指南(第2版)》——1.5 ECMAScript 5
几乎所有的现代浏览器与其他相关环境都实现了ECMAScript的第3版,对此我们可以安心使用。第4版则直接被跳过了。而ECMAScript的第5版(以下简称为ES5)则到2009年12月才被正式采纳。
1333 0
《Linux系统编程(第2版)》——2.8 定位读写
这两个调用和read()、write()调用的最主要区别在于它们完全忽略了当前文件位置;相反,pread()和pwrite()调用用的是参数pos值。此外,当调用完成时,它们不会更新文件位置指针。换句话说,任何read()和write()交替调用可能会破坏定位读写的结果。
1546 0
机房收费系统之组合查询
<span style="white-space:pre"><span style="font-family:KaiTi_GB2312; font-size:24px"><strong><span style="white-space:pre"></span><span style="white-space:pre"></span>增删改查,数据库中最基本的四个操作。不论是学生信息管理系统
1135 0
小结:VB.NET机房收费系统个人版
      经过几天的缝缝补补,自己的个人版终于OK了,!也许是因为有第一次的机房收费系统的经验,这次做,感觉非常亲切。      在业务逻辑方面,沿袭以前的逻辑,做了一点升级,但是改动不大。
893 0
VB.NET版机房收费系统---导出Excel表格
       datagridview,翻译成中文的意思是数据表格显示,使用DataGridView控件,可以显示和编辑来自不同类型的数据源的表格,将数据绑定到DataGridView控件非常简单和直观,大多数情况下,只需要设置DataSource属性即可,在绑定到包含多个列表或表的数据库源时,只需将DataMember属性设置为绑定的列表或表的字符串即可。
1325 0
+关注
丁国华
你只管努力,剩下的交给时光!
文章
问答
文章排行榜
最热
最新
相关电子书
更多
低代码开发师(初级)实战教程
立即下载
阿里巴巴DevOps 最佳实践手册
立即下载
冬季实战营第三期:MySQL数据库进阶实战
立即下载