機房收費系統分析二

來源:互聯網
上載者:User

    

      在機房收費系統初步分析中,簡單說了說表和表間的關係。

 

 

     下面說說,在實現功能時候的思路分析。

 

 

 

 

      首先就是上下機啦。

 

     上機的時候,首先判斷是否註冊,沒有註冊則先註冊;

 

     已經註冊了,則在判斷是否正在上機;

 

     沒有上機時,在判斷卡內餘額是否大於最小餘額,滿足條件後才能成功上機;

 

     上機的時候,將上機資訊寫入到正在上機表中;

 

     下機的時候,算出消費金額,更新學生基本資料表中金額的內容;

 

     將上機資訊,添加到上機資訊記錄中,在刪除在正在上機卡表中的記錄;

      注意:    卡內最小餘額不能太小,如果學生上機時間很長,將金額消費完了,餘額就會出現負值。

     

 

 

 

      其次,註冊。

 

      註冊的時候,同時向註冊卡資訊和學生基本資料表中添加資訊;

 

      判斷是否註冊,直接在學生資訊表中擷取資訊即可

 

 

 

 

         再次,登入

 

      在登入表單框中獲得使用者名稱,將其與時間,日期,一併寫入正在值班表資訊中;

 

      退出系統的時候,再將使用者名稱,登入時間,日期,退出時間,日期,一併寫入值班記錄表中。

  

       具體功能實現:

 

       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語句拼接沒有錯了,查詢出來的結果自然也不會錯。   

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.