Analysis of computer room toll system

Source: Internet
Author: User
Tags first row

In the preliminary analysis of the computer room charge system, it simply says the relationship between the table and the table.

Next, in the realization of the function of the thinking analysis.

The first is to go down the machine.

When the machine, first judge whether registration, no registration is first registered;

has been registered, then in the judge whether is on the machine;

Not on the machine, in determining whether the balance in the card is greater than the minimum balance, meet the conditions can be successful on the computer;

When on the machine, the machine information is written to the machine table;

When the machine, calculate the consumption amount, update the Student Basic information table in the content of the amount;

The information on the machine is added to the record of the machine information, and the record in the card table is deleted.

Note: The minimum balance in the card can not be too small, if the student on the machine for a long time, the amount spent, the balance will appear negative.

Second, register.

At the same time, add information to the registration card information and student basic information table;

To determine whether to register, directly in the Student information table to obtain information can be

Again, login

In the Login form box to get the user name, and time, date, written on the watch information;

When you exit the system, the user name, login time, date, exit time, and date are written on the watch.

Specific function implementation:

1, calculate the time period difference

On the machine time, and the next machine time, calculation on the computer

Obviously can not use the machine time directly minus on the machine time, with the code to achieve, I first of all two time are converted to minutes, in the subtraction, you can draw the difference between the difference.

In this way, the same date on the premise is correct, but the next day the calculation is wrong. If you write the code, it must be particularly troublesome, rather than directly with someone else to write a good date function, quite simple.

          Dim a1 As String
          Dim a2 As String 
          a1= txtstartdate & "   " & Txtstarttime "    on machine time
          a2= Txtenddate & Amp "   " & Txtendtime        ' down time
          txtshow. Text = DateDiff ("n", a1, A2)       ' shows the time difference, which is the minute representation


It should be noted that the result is A2 to A1 this time period difference in minutes, the date is large in front, the date is small in the back.

By changing the parameter n, you can also return the two-time difference of the month-day variables.

(yyyy year, Q season, M month, Y, day of year, D-Day, W-week days, WW week, H, N minutes, s seconds)

2, Export to Excel

There are several forms in the system that need to export the data in the table to Excel. Functional code can be encapsulated into the process, the use of the direct call process on the line. The province writes duplicate code every time.

Code:

' *************************************************************************
' * * Function name: Toexcel
' * * lost    Into: Mygrid (MSFlexGrid)-
' * * output    : no
' * * Function Description: Export to Excel table
' * * *    : Li Di
' * * Date    : 2012-09-13
' * * Modified person:
' * * days    :
' * * version    : 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 = Createo Bject ("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

When the list box's Style property is set to 2 o'clock, is only optional, cannot add content to the above, in the program, we want it to display our specific values, directly assigned to the error.

Workaround, define the function in the module, and return the index value of the corresponding string in the control.

Defined:

' *************************************************************************
' * * Function name: GetIndex
' * * lost    Into: Combo (ComboBox)        -
' * *        : ByVal strvalue (String)-
' * * output    : (Integer)-
' * * Function Description: Returns the index value of the corresponding string in the combo control
' * *    : Li Di ' * *
days    : 2012-08-21 ' * *
modified person:
' * * days    :
' * * Version    : 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
    Next end
function


When assigning a value:

Cmbgrade.listindex = GetIndex (Cmbgrade, M_rstclassinfo. Fields (1). Value)


4, conditional query

In the first row, if the first one is selected, the next two cannot be empty, and A is true

In the second row, if the first one is selected, the following two are not empty, and B is true

In the third line, if the first one is selected, the following two are not empty, and C is true

A b c is used in the first row, the second line, the third line

Use a query: DD (0) =true

Query by B: Do not use a DD (1) =true

With a DD (2) =true

C query: Without a, B without AB DD (3) =true

With one or two DD (4) =true

When DD (0) DD (1) is true, it is not necessary to determine that the first composite relationship is empty.

When DD (2) is true, the first combination of the following must be judged to be not empty,

DD (4) ensures that the second combination is not empty,

The specific code is as follows:

    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" If you choose the first line first, ' The first line is not empty, A is true If testtxt (CMBCRL1. Text) Then ' control operator not empty MsgBox ' operator cannot be empty, select operator. ", vbOKOnly + vbinformation," hint "cmbcrl1. SetFocus Exit Sub End If Testtxt (TXTMSG1. Text) Then ' control query content not empty MsgBox ' the content you want to query cannot be empty, please enter the content you want to query. ", vbOKOnly + vbinformation," hint "TXTMSG1. SetFocus Exit Sub End If a = True End If cmbname2.                                                   Text <> "Then ' If you choose the second line first ' ' The second line is not empty, B is true If testtxt (cmbcrl2.               Text) Then        The ' control operator MsgBox ' operator cannot be empty, please select an operator. ", vbOKOnly + vbinformation," hint "cmbcrl2. SetFocus Exit Sub End If Testtxt (TXTMSG2. Text) Then ' control query content not empty MsgBox ' the content you want to query cannot be empty, please enter the content you want to query. ", vbOKOnly + vbinformation," hint "txtmsg2. SetFocus Exit Sub End If B = True End If Cmbname3.                                                   Text <> "Then ' If you choose the third line first ' ' The third line is not empty, and C is true If testtxt (cmbcrl3. Text) Then ' control operator not empty MsgBox ' operator cannot be empty, select operator. ", vbOKOnly + vbinformation," hint "cmbcrl3. SetFocus Exit Sub End If Testtxt (TXTMSG3. Text) Then ' control query content not empty MsgBox ' the content you want to query cannot be empty, please enter the content you want to query. ", vbOKOnly + vbinformation," hint "txtmsg3. SetFocus Exit Sub End If C = True End If If a Then                                              ' If A,DD (0) is selected as True if Cmbname1. Text = "card number" Then AA = "card_id" BB = trim$ (TXTMSG1. Text) End If cmbname1. Text = "Up date" 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 b Then ' Select B and select A,DD (1) as true If cmbname2. Text = "card number" Then AA = "card_id" BB = trim$ (txtmsg2. Text) End If cmbname2. Text = "Up date" Then AA = "date" BB = format$ (trim$ (TXTMSG2). Text), "YYYY/MM/DD") End If If not DD (0) Then ' If select B does not select a s TR = str & trim$ (AA) & "" & Trim$ (Cmbcrl2.   Text) & "'" & BB & "" dd (1) = True Else                                             ' That is, select a and choose b If testtxt (cmb0. Text) Then MsgBox "The combined relationship cannot be empty, select a combination relationship", vbOKOnly + vbinformation, "hint" cmb0. SetFocus Exit Sub End If cmb0. Text = "or" Then guanxi = "or" End if cmb0. Text = "and" Then guanxi = "and" end If str = str & "" & Guanxi & "" & AA & "" & Trim$ (Cmbcrl2. Text) & "' & BB &" ' "dd (2) = True End If Then if Cmbname3. Text = "card number" Then AA = "card_id" BB = trim$ (txtmsg3. Text) End If Cmbname3. Text = "Up date" Then AA = "date" BB = format$ (trim$ (TXTMSG3). Text), "YYYY/MM/DD") End If If not (DD (0) or DD (1) or DD (2)) Then ' If A and B do not select S TR = str & trim$ (AA) & "" & Trim$ (Cmbcrl3. Text) & "" & BB & "" dd (3) = True Else ' Select one or two to select the If testtxt (CMB1. Text) Then MsgBox "The combined relationship cannot be empty, select a group relationship." ", vbOKOnly + vbinformation," hint "cmb1. SetFocus Exit Sub End If Cmb1. Text = "or" Then guanxi = "or" End if cmb1. Text = "and" Then guanxi = "and" end If str = str & "" & Guanxi & "" & trim$ (AA) & "" & Trim$ (Cmbcrl3.  Text) & "' & BB &" ' "dd (4) = True End If If if not (DD (0) or DD (1) or DD (2) or DD (3) Or DD (4)) Then MsgBox "Please select a Query method", vbOKOnly + vbinformation, "Prompt" cmbname1.
 SetFocus Exit Sub End If


A,b, c Three can be a separate query, can also be combined to query.

One problem is that when querying two conditions, the combination of a and C must be the second and the first one will not work.

Three statement query, the combination of relations must be used.

The whole process of judgment is to determine the SQL statement.

The condition is judged well, the SQL statement splicing is not wrong, the result of the query comes out naturally also can not be wrong.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.