机房收费系统分析二

来源:互联网 发布:matlab矩阵的逆 编辑:程序博客网 时间:2024/05/16 15:50

    

      在机房收费系统初步分析中,简单说了说表和表间的关系。

 

 

     下面说说,在实现功能时候的思路分析。

 

 

 

 

      首先就是上下机啦。

 

     上机的时候,首先判断是否注册,没有注册则先注册;

 

     已经注册了,则在判断是否正在上机;

 

     没有上机时,在判断卡内余额是否大于最小余额,满足条件后才能成功上机;

 

     上机的时候,将上机信息写入到正在上机表中;

 

     下机的时候,算出消费金额,更新学生基本信息表中金额的内容;

 

     将上机信息,添加到上机信息记录中,在删除在正在上机卡表中的记录;

      注意:    卡内最小余额不能太小,如果学生上机时间很长,将金额消费完了,余额就会出现负值。

     

 

 

 

      其次,注册。

 

      注册的时候,同时向注册卡信息和学生基本信息表中添加信息;

 

      判断是否注册,直接在学生信息表中获取信息即可

 

 

 

 

         再次,登录

 

      在登录窗体框中获得用户名,将其与时间,日期,一并写入正在值班表信息中;

 

      退出系统的时候,再将用户名,登录时间,日期,退出时间,日期,一并写入值班记录表中。

  

       具体功能实现:

 

       1,计算时间段差值

 

       有上机时间,还有下机时间,计算上机时间

 

       很显然是不能用下机时间直接减去上机时间的,用代码实现的时候,我首先是将两个时间都转换为分钟,在相减,就可以得出之间的时间差。

 

       这样算,在同一日期的前提下是正确的,但是隔天计算就出错。如果自己编写代码的话,肯定特别麻烦,不如直接用别人写好的日期函数,挺简单的。

 

          dim a1 as string          dim a2 as string           a1= txtstartdate & "   " & txtstarttime    '上机时间          a2= txtenddate & "   " & txtendtime        '下机时间          txtshow.Text = DateDiff("n", a1, a2)       '显示时间差,为分钟表示


      

          

           需要注意的是,算出来的结果是 a2 到a1 这个时间段差的分钟数;  日期大的在前面,日期小的在后面。

 

       通过改变参数n ,还可以返回两个时间段差值的年月日等变量。

 

      (yyyy 年 、q 季、 m 月、 y 一年的日数、 d 日、 w 一周的日数、 ww 周 、h 时 、n 分钟、 s秒)

 

 

 

        2,导出到excel    

 

       系统中有好几个窗体都需要把表格中的数据导出到excel中。可以把功能代码封装到过程中,用到的时候直接调用过程就行。省的每次都写重复代码。

 

        代码:

 

'*************************************************************************'**函 数 名:ToExcel'**输    入:mygrid(MSFlexGrid) -'**输    出:无'**功能描述:导出到 Excel 表格'**作    者:李双喆'**日    期:2012-09-13'**修 改 人:'**日    期:'**版    本:V1.0.0'************************************************************************* Sub ToExcel(mygrid As MSFlexGrid)         Dim xlApp As Excel.Application    Dim xlBook As Excel.Workbook    Dim xlSheet As Excel.Worksheet    Dim i As Integer    Dim j As Integer    Set xlApp = CreateObject("Excel.Application")    Set xlBook = xlApp.Workbooks.Add    Set xlSheet = xlBook.Worksheets(1)    For i = 0 To mygrid.Rows - 1        For j = 0 To mygrid.Cols - 1            xlSheet.Cells(i + 1, j + 1) = mygrid.TextMatrix(i, j)        Next j        DoEvents    Next    xlApp.Visible = True    End Sub


 

       3,listbox

 

      当列表框的style属性设置为2时,就是只能选,不能往上面添加内容时,在程序中,我们又想让它显示我们特定的值,直接赋值时会出错的。

      解决方法,在模块中定义函数,返回控件中对应字符串的索引值。

 

 

       定义:

'*************************************************************************'**函 数 名:GetIndex'**输    入:combo(ComboBox)        -'**        :ByVal strValue(String) -'**输    出:(Integer) -'**功能描述:返回combo控件中对应字符串的索引值'**作    者:李双喆'**日    期:2012-08-21'**修 改 人:'**日    期:'**版    本:V1.0.0'*************************************************************************Public Function GetIndex(combo As ComboBox, ByVal strValue As String) As Integer    Dim index As Integer    If combo.ListCount <= 0 Then        GetIndex = -1        Exit Function    End If        For index = 0 To combo.ListCount - 1        If Trim(strValue) = Trim(combo.List(index)) Then            GetIndex = index            Exit Function        End If    NextEnd Function


赋值的时候 :

 cmbGrade.ListIndex = GetIndex(cmbGrade, m_rstclassinfo.Fields(1).Value)


 

 

 

       4,条件查询

 

 

 

 

         第一行中,如果选了第一个,则后面的两个不能为空,a 为true

 

        第二行中,如果选了第一个,后面的两个不为空,b为true

 

        第三行中,如果选了第一个,后面的两个不为空,此时c 为true

        a   b  c  分别是用第一行,第二行,第三行

 

       用a 查询: dd(0)=true

 

       用b 查询:  不用a dd(1)=true

 

                        用a  dd(2)=true

 

       用c 查询:  不用a ,b  不用ab dd(3)=true

 

                        用其中一个或两个 dd(4)=true

 

       dd(0)   dd(1) 为真时,不需要判断第一个组合关系空不空,

 

       dd(2)为真时,必须判断后面的第一个组合关系,保证不空,

 

       dd(4) 的时候,保证第二个组合关系不空,

      具体代码如下:

 

    Dim objrs As ADODB.Recordset    Dim str As String    Dim txt As String    Dim aa As String, bb As String    Dim dd(5) As Boolean, guanxi As String    str = "select * from Oncard where "    If cmbname1.Text <> "" Then                             '如果选择第一行第一个,                                                            '第一行都不为空,a为true        If Testtxt(cmbcrl1.Text) Then                       '控制操作符不空            MsgBox "操作符不能为空,请选择操作符!", vbOKOnly + vbInformation, "提示"            cmbcrl1.SetFocus            Exit Sub        End If        If Testtxt(txtmsg1.Text) Then                       '控制查询内容不空            MsgBox "要查询的内容不能为空,请输入要查询的内容!", vbOKOnly + vbInformation, "提示"            txtmsg1.SetFocus            Exit Sub        End If        a = True    End If    If cmbname2.Text <> "" Then                             '如果选择第二行第一个        '                                                   '第二行都不为空,b为true        If Testtxt(cmbcrl2.Text) Then                       '控制操作符不空            MsgBox "操作符不能为空,请选择操作符!", vbOKOnly + vbInformation, "提示"            cmbcrl2.SetFocus            Exit Sub        End If        If Testtxt(txtmsg2.Text) Then                       '控制查询内容不空            MsgBox "要查询的内容不能为空,请输入要查询的内容!", vbOKOnly + vbInformation, "提示"            txtmsg2.SetFocus            Exit Sub        End If        b = True    End If    If cmbname3.Text <> "" Then                             '如果选择第三行第一个        '                                                   '第三行都不为空,c为true        If Testtxt(cmbcrl3.Text) Then                       '控制操作符不空            MsgBox "操作符不能为空,请选择操作符!", vbOKOnly + vbInformation, "提示"            cmbcrl3.SetFocus            Exit Sub        End If        If Testtxt(txtmsg3.Text) Then                       '控制查询内容不空            MsgBox "要查询的内容不能为空,请输入要查询的内容!", vbOKOnly + vbInformation, "提示"            txtmsg3.SetFocus            Exit Sub        End If        c = True    End If    If a Then                                              '如果选择a,dd(0)为true        If cmbname1.Text = "卡号" Then            aa = "card_id"            bb = Trim$(txtmsg1.Text)        End If        If cmbname1.Text = "上机日期" Then            aa = "date"            bb = Format$(Trim$(txtmsg1.Text), "yyyy/mm/dd")        End If        str = str & Trim$(aa) & " " & Trim$(cmbcrl1.Text) & "'" & bb & "'"        dd(0) = True    End If    If b Then                                               '选择b,又选择了a,dd(1)为真        If cmbname2.Text = "卡号" Then            aa = "card_id"            bb = Trim$(txtmsg2.Text)        End If        If cmbname2.Text = "上机日期" Then            aa = "date"            bb = Format$(Trim$(txtmsg2.Text), "yyyy/mm/dd")        End If        If Not dd(0) Then                                   '如果选择b 不选择 a            str = str & Trim$(aa) & " " & Trim$(cmbcrl2.Text) & "'" & bb & "'"            dd(1) = True        Else                                                '即选择a ,又选择 b            If Testtxt(cmb0.Text) Then                MsgBox "组合关系不能为空,请选择组合关系", vbOKOnly + vbInformation, "提示"                cmb0.SetFocus                Exit Sub            End If            If cmb0.Text = "或" Then                guanxi = "or"            End If            If cmb0.Text = "与" Then                guanxi = "and"            End If            str = str & " " & guanxi & " " & aa & " " & Trim$(cmbcrl2.Text) & "'" & bb & "'"            dd(2) = True        End If    End If    If c Then        If cmbname3.Text = "卡号" Then            aa = "card_id"            bb = Trim$(txtmsg3.Text)        End If        If cmbname3.Text = "上机日期" Then            aa = "date"            bb = Format$(Trim$(txtmsg3.Text), "yyyy/mm/dd")        End If        If Not (dd(0) Or dd(1) Or dd(2)) Then                '如果a 和b 都不选            str = str & Trim$(aa) & " " & Trim$(cmbcrl3.Text) & "'" & bb & "'"            dd(3) = True        Else                                                 '选一个或者是两个都选            If Testtxt(cmb1.Text) Then                MsgBox "组合关系不能为空,请选择组合关系!", vbOKOnly + vbInformation, "提示"                cmb1.SetFocus                Exit Sub            End If            If cmb1.Text = "或" Then                guanxi = "or"            End If            If cmb1.Text = "与" Then                guanxi = "and"            End If            str = str & " " & guanxi & " " & Trim$(aa) & " " & Trim$(cmbcrl3.Text) & "'" & bb & "'"            dd(4) = True        End If    End If    If Not (dd(0) Or dd(1) Or dd(2) Or dd(3) Or dd(4)) Then        MsgBox "请选择一种查询方法", vbOKOnly + vbInformation, "提示"        cmbname1.SetFocus        Exit Sub    End If


 

 

 

        a,b ,c 三行可以单独的进行查询,也可以联合起来进行查询。

      

        有一个问题是,查询两个条件时,用a ,c 之间的组合关系必须是第二个,第一个不起作用。。

 

        三条语句查询时,组合关系必须都用上。。

 

 

        整个判断过程,就是确定sql语句的。

        条件判断好了,sql语句拼接没有错了,查询出来的结果自然也不会错。   

原创粉丝点击