机房之经典代码

在这次的机房收费系统中,有几个类型的代码使用频率非常高,基本上每一个窗体都出了,下面是代码展示

文本框输入限制类型

机房之经典代码_第1张图片机房之经典代码_第2张图片机房之经典代码_第3张图片

数据库连接

机房之经典代码_第4张图片

登录窗体判断

机房之经典代码_第5张图片

特殊的组合查询

机房之经典代码_第6张图片

上机代码:

机房之经典代码_第7张图片

下机:

Private Sub cmdOffline_Click()
    If txtcardno.Text = "" Then             '判断卡号是否为空
        MsgBox "此卡号不可为空!", vbOKOnly + vbExclamation, "警告"
    Else
        Dim stu As ADODB.Recordset          '查看用户是否存在
        Dim txtSQL, Msgtext As String
        txtSQL = "select * from student_Info where cardno='" & Trim(txtcardno.Text) & "'"
        Set stu = ExecuteSQL(txtSQL, Msgtext)
        If stu.EOF Then                     '判断卡号是否存在
            MsgBox "此卡号不存在!"
        Else                                '卡号存在,判断卡号是否正在上机
            Dim onw As ADODB.Recordset
            txtSQL = "select*from OnLine_Info where cardno='" & Trim(txtcardno.Text) & "'"
            Set onw = ExecuteSQL(txtSQL, Msgtext)
            If onw.EOF = False Then         '如果卡号正在上机
                                            '计算消费时间和,金额
                Dim bas As ADODB.Recordset
                Dim txtsql1, msgtext1 As String
                txtsql1 = "select * from BasicData_Info "   '获取基本数据表
                Set bas = ExecuteSQL(txtsql1, msgtext1)
                fixedunit = bas.Fields(0)                   '固定用户和
                temunit = bas.Fields(1)                     '临时用户
                txtontime.Text = Trim(Date)               '下机日期
                txtofftime.Text = Trim(Time)                '下机时间
                intLineTime = (Date - DateValue(onw!ondate)) * 1440 + (Hour(Time) - _
                Hour(TimeValue(onw!OnTime))) * 60 + (Minute(Time) - _
                Minute(TimeValue(onw!OnTime))) '计算机上机时间
                txtctime.Text = Trim(intLineTime)
                
                If intLineTime <= Val(Trim(bas.Fields(4))) Then '判断上机时间是否小于准备时间
                    txtcmoney.Caption = 0
                 
                Else
                       '判断实际时间是否小于最低消费时间
                    If intLineTime <= Val(Trim(bas.Fields(3))) Then '如果小于
                        txtcmoney.Caption = 0
                    Else
                          '实际在线时间大于最低消费时间则按单位时间算,分固定和临时两种用户
                        If intLineTime > Val(Trim(bas!leasttime)) And Trim(stu.Fields(14)) = "固定用户" Then
                        '如果在线时间大于准备时间和他是固定用户
                        curConsume = intLineTime / Val(Trim(bas!unittime)) '用上机时长除以递增时间 等于上机小时
                        txtcmoney.Caption = Val(curConsume) * Val(fixedunit)  '用上机小时乘固定用户每小时费用等于消费金额
                        Else
                            If intLineTime > Val(Trim(bas!leasttime)) And Trim(stu.Fields(14)) = "临时用户" Then
                            '如果是临时用户
                                curConsume = intLineTime / Val(bas!unittime) '用上机时长除以递增时间
                                txtcmoney.Caption = Val(curConsume) * Val(temunit) '用上机小时乘临时用户每小时费用 等于消费金额
                            End If
                        End If
                    End If
                End If
                '计算余额(账户余额=原账户余额-消费余额)
                txtbalance.Text = stu!cash - Val(txtcmoney.Caption)   '账户余额
                txtontime.Text = Date         '下机信息显示
                txtofftime.Text = Time
                txtcardno.Text = Trim(stu.Fields(0))
                txtsid.Text = Trim(stu.Fields(1))
                txtdept.Text = Trim(stu.Fields(4))
                txtondate.Text = Trim(Date)
                txtbalance.Text = Trim(stu.Fields(7))
                txttype.Text = Trim(stu.Fields(14))
                txtname.Text = Trim(stu.Fields(2))
                txtsex.Text = Trim(stu.Fields(3))
                'txtoffdate.Text = Trim(Time)
                '更新学生表的余额
                stu.Fields(7) = txtbalance.Text
                stu.Update
                stu.Close
                
                '更新上机表
                txtSQL = "select * from Line_Info " '获取上机记录表
                Set LineSQL = ExecuteSQL(txtSQL, Msgtext)
                LineSQL.AddNew
                LineSQL.Fields(1) = Trim(txtcardno.Text)
                LineSQL.Fields(2) = Trim(txtsid.Text)
                LineSQL.Fields(3) = Trim(txtname.Text)
                LineSQL.Fields(4) = Trim(txtdept.Text)
                LineSQL.Fields(5) = Trim(txtsex.Text)
                LineSQL.Fields(6) = Trim(txtondate.Text)
                LineSQL.Fields(7) = Trim(txtoffdate.Text)
                LineSQL.Fields(8) = Trim(txtontime.Text)
                LineSQL.Fields(9) = Trim(txtofftime.Text)
                LineSQL.Fields(10) = Trim(txtctime.Text)
                LineSQL.Fields(11) = Trim(txtcmoney.Caption)
                LineSQL.Fields(12) = Trim(txtbalance.Text)
                LineSQL.Fields(13) = Trim("正常下机")
                LineSQL.Fields(14) = Trim(ComputerName)
                LineSQL.Update
                '删除在线信息
                Dim ondele As ADODB.Recordset
                txtSQL = "select * from OnLine_Info" '删除正在上机记录
                Set ondele = ExecuteSQL(txtSQL, Msgtext)
                ondele.Delete '删除
                Label2.Caption = Str(Label2.Caption - 1) '减去上机人数
                Select Case MsgBox("下机成功!", vbInformation + vbYesNo, "机房收费系统")
                Case 6 '判断是否清空
                    txtontime.Text = ""
                    txtofftime.Text = ""
                    txtcardno.Text = ""
                    txtsid.Text = ""
                    txtdept.Text = ""
                    txtondate.Text = ""
                    txtbalance.Text = ""
                    txttype.Text = ""
                    txtname.Text = ""
                    txtsex.Text = ""
                    txtoffdate.Text = ""
                    txtctime.Text = 0
                    txtcmoney.Caption = 0
                Case 7 '不清空
                    MsgBox "您没有下机!", vbOKOnly + vbExclamation, "警告"
                End Select
            Else
                MsgBox "该卡号没有在上机"
            End If
        End If
    End If
End Sub

 

你可能感兴趣的:(机房之经典代码)