机房收费系统之上下机

简介:

          上下机这块儿,主要是算法,很容易乱,不过有第一次 的经验,现在也有些头绪,下面和大家分享一下:

       U层: 

    ''' <summary>
    ''' 上机
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub btnLoginIn_Click(sender As Object, e As EventArgs) Handles btnLoginIn.Click
        Try
            If txtCardNo.Text = "" Then
                MessageBox.Show("卡号不能为空!", "提示")
                txtCardNo.Focus()
            End If
            Dim enCardNo As New CardInfoEntity
            enCardNo.CardNo = txtCardNo.Text.Trim()
            '第一步判断该卡是否存在
            Dim bllfrmMain As New frmMainBLL
            Dim dtCard As New DataTable
            dtCard = bllfrmMain.IsCardExists(enCardNo)
            If dtCard.Rows.Count > 0 Then
                '第二步判断该卡是否正在上机
                Dim dtLine As DataTable
                dtLine = bllfrmMain.isOnline(enCardNo)
                If dtLine.Rows.Count = 0 Then
                    '第三步上机并更新T_LineInfo
                    txtCash.Text = dtCard.Rows(0).Item("Cash").ToString().Trim
                    txtDepartment.Text = dtCard.Rows(0).Item("Department")
                    txtType.Text = "固定用户"
                    txtSex.Text = dtCard.Rows(0).Item("Sex")
                    txtStudentName.Text = dtCard.Rows(0).Item("StudentName")
                    txtStudentNo.Text = dtCard.Rows(0).Item("StudentNo")
                    txtOnDate.Text = DateTime.Today.ToString("yyyy-MM-dd")
                    txtOnTime.Text = DateTime.Now.ToString("HH:mm ")

                    Dim enLine As New LineInfoEntity
                    Dim intResult As Integer
                    enLine.CardNo = txtCardNo.Text.Trim()
                    enLine.StudentName = dtCard.Rows(0).Item("StudentName")
                    enLine.Computer = pubshare.strComputer
                    enLine.OnDate = txtOnDate.Text.Trim()
                    enLine.OnTime = txtOnTime.Text.Trim()
                    intResult = bllfrmMain.AddOnline(enLine)
                    If intResult <= 0 Then
                        Throw New Exception("添加上机信息失败")
                    Else
                        Label24.Visible = True
                        Label24.Text = "欢  迎  光   临  !"
                    End If
                End If
            Else
                Throw New Exception("该卡不存在")
            End If

        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Exclamation, "提示")
        End Try
    End Sub
  ''' <summary>
    ''' 下机
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub btnLogOut_Click(sender As Object, e As EventArgs) Handles btnLogOut.Click


        If txtCardNo.Text.Trim = "" Then
            MessageBox.Show("卡号不能为空!")
            txtCardNo.Focus()
        Else
            Call OffLine()
        End If


    End Sub
         这里写的过程OffLine()如下:

 Public Sub OffLine()
        Dim enOnLine As New Entity.LineInfoEntity
        Dim bllAllOffLine As New QueryOnStatusBLL
        Dim enLine As New LineInfoEntity '更新上机信息
        Dim dtOnLine As DataTable
        '判断DataGridView中是否存在数据
        Try
            '第一步,判断该用户是否正在上机
            enOnLine.CardNo = txtCardNo.Text.Trim
            dtOnLine = bllAllOffLine.SelectOnLine(enOnLine)
            If dtOnLine.Rows.Count <= 0 Then
                Throw New Exception("该卡尚未上机")
            Else
                '第二步,获取收费信息
                Dim dtBasicData As New DataTable

                Dim enBasicData As New BasicDataEntity
                Dim bllBasicData As New BasicDataBLL
                dtBasicData = bllBasicData.SelectBasicData()
                enBasicData.Rate = dtBasicData.Rows(0).Item("Rate")
                enBasicData.PrepareTime = dtBasicData.Rows(0).Item("PrepareTime")
                enBasicData.UnitTime = dtBasicData.Rows(0).Item("UnitTime")

                '第三步,获取上机信息
                Dim bllQueryOnStatus As New QueryOnStatusBLL
                Dim dtOnlineinfo As New DataTable
                Dim enOnlineinfo As New LineInfoEntity
                enOnlineinfo.CardNo = txtCardNo.Text.Trim
                dtOnlineinfo = bllQueryOnStatus.SelectOnLine(enOnlineinfo)
                If dtOnlineinfo.Rows.Count <= 0 Then
                    Throw New Exception("获取上机信息失败")
                End If
                '第四步,获取卡余额信息
                Dim bllCard As New CardBLL
                Dim dtCard As New DataTable
                Dim enCard As New CardInfoEntity
                enCard.CardNo = txtCardNo.Text.Trim
                dtCard = bllCard.SelectCash(enCard)
                If dtCard.Rows.Count <= 0 Then
                    Throw New Exception("获取卡余额信息失败")
                End If
                '第五步,计算消费时间和消费金额
                Dim consumeTime As Integer
                Dim intResult As Integer

                enLine.OffDate = DateTime.Today.ToString("yyyy-MM-dd")
                enLine.OffTime = DateTime.Now.ToString("HH:mm")
                enOnLine.OnDate = dtOnlineinfo.Rows(0).Item("OnDate")
                enOnLine.OnTime = dtOnlineinfo.Rows(0).Item("OnTime")
                enLine.Note = "正常下机"
                'Dim a As Date = CDate(enOnLine.OffDate)
                consumeTime = Val(DateDiff("n", Format(CDate(enOnLine.OnDate)), CDate(enLine.OffDate)) + DateDiff("n", CDate(enOnLine.OnTime), CDate(enLine.OffTime))) - enBasicData.PrepareTime

                '如果消费时间小于0
                If consumeTime < 0 Then
                    consumeTime = 0
                    enLine.ConsumeCash = Val("0")
                    enLine.Cash = dtCard.Rows(0).Item("Cash")
                    intResult = bllAllOffLine.AllOffLine(enLine)
                Else
                    Dim intCard As Integer
                    Dim enCardInfo As New CardInfoEntity
                    Dim bllCardInfo As New CardBLL
                    enLine.CardNo = txtCardNo.Text.Trim
                    '如果消费时间不是30的倍数
                    If consumeTime Mod 30 > enBasicData.UnitTime Then
                        enLine.ConsumeCash = Int(consumeTime / 30) * Val(enBasicData.Rate) + Val(enBasicData.Rate)
                        enLine.Cash = Val(dtCard.Rows(0).Item("Cash")) - Val(enLine.ConsumeCash)
                        '更新LineInfo
                        intResult = bllAllOffLine.AllOffLine(enLine)
                        '更新卡表
                        enCardInfo.Cash = enLine.Cash
                        enCardInfo.CardNo = txtCardNo.Text.Trim
                        intCard = bllCardInfo.UpdCard(enCardInfo)
                        '将上下机信息返回到主界面
                        Dim enCardNO As New CardInfoEntity
                        Dim dtLine As New DataTable
                        Dim bllfrmMain As New frmMainBLL
                        enCardNO.CardNo = txtCardNo.Text.Trim
                        dtLine = bllfrmMain.LineInfo(enCardNO)
                        txtCash.Text = dtLine.Rows(0).Item("Cash")
                        txtConsumeCash.Text = dtLine.Rows(0).Item("ConsumeCash")
                        txtConsumeTime.Text = Format(consumeTime / 60, "0.00")
                        txtDepartment.Text = dtLine.Rows(0).Item("Department")
                        txtOffDate.Text = dtLine.Rows(0).Item("OffDate").ToString
                        txtOffTime.Text = dtLine.Rows(0).Item("OffTime").ToString
                        txtOnDate.Text = dtLine.Rows(0).Item("OnDate").ToString
                        txtOnTime.Text = dtLine.Rows(0).Item("OnTime").ToString
                        txtSex.Text = dtLine.Rows(0).Item("Sex")
                        txtStudentName.Text = dtLine.Rows(0).Item("StudentName")
                        txtStudentNo.Text = dtLine.Rows(0).Item("StudentNo")
                        txtType.Text = dtLine.Rows(0).Item("Type")
                        Label24.Text = "欢迎下次再来!"
                    Else
                        enLine.ConsumeCash = Int(consumeTime / 30) * Val(enBasicData.Rate)
                        enLine.Cash = Val(dtCard.Rows(0).Item("Cash")) - Val(enLine.ConsumeCash)
                        '更新T_LineInfo
                        intResult = bllAllOffLine.AllOffLine(enLine)
                        '更新卡表
                        enCardInfo.Cash = enLine.Cash
                        enCardInfo.CardNo = txtCardNo.Text.Trim
                        intCard = bllCardInfo.UpdCard(enCardInfo)
                        '将上下机信息返回到主界面
                        Dim enCardNO As New CardInfoEntity
                        Dim dtLine As New DataTable
                        Dim bllfrmMain As New frmMainBLL
                        enCardNO.CardNo = txtCardNo.Text.Trim
                        dtLine = bllfrmMain.LineInfo(enCardNO)
                        txtCash.Text = dtLine.Rows(0).Item("Cash")
                        txtConsumeCash.Text = dtLine.Rows(0).Item("ConsumeCash")
                        txtConsumeTime.Text = Format(consumeTime / 60, "0.00")
                        txtDepartment.Text = dtLine.Rows(0).Item("Department")
                        txtOffDate.Text = dtLine.Rows(0).Item("OffDate").ToString
                        txtOffTime.Text = dtLine.Rows(0).Item("OffTime").ToString
                        txtOnDate.Text = dtLine.Rows(0).Item("OnDate").ToString
                        txtOnTime.Text = dtLine.Rows(0).Item("OnTime").ToString
                        txtSex.Text = dtLine.Rows(0).Item("Sex")
                        txtStudentName.Text = dtLine.Rows(0).Item("StudentName")
                        txtStudentNo.Text = dtLine.Rows(0).Item("StudentNo")
                        txtType.Text = dtLine.Rows(0).Item("Type")
                    End If
                End If
            End If
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Exclamation, "提示")
        End Try
    End Sub
          这里主要是U层的计算,剩下B层,D层和其他的没有区别,在调试代码的过程中,出现了一些问题,不过也都用各种办法解决了,突然发现抛异常真的能够非常有效的提高调试的效率,而且经过对每个窗体的调试,我发现调试绝不仅仅是用F11,是有一些技巧的,学会用这些技巧感觉比把逻辑理清楚更重要,大家有什么不同的见解,希望和大家交流!

        

相关文章
|
缓存 Java 关系型数据库
某人事系统架构搭建设计记录
某人事系统架构搭建设计记录
|
7月前
|
数据库 数据安全/隐私保护
机房收费系统之总结(一)
机房收费系统之总结(一)
50 0
机房收费系统——下机封装、点击下机、全员下机、选择下机和动态下机(有关下机的所有代码)
机房收费系统——下机封装、点击下机、全员下机、选择下机和动态下机(有关下机的所有代码)
|
数据可视化 测试技术 BI
机房收费系统—功能介绍
机房收费系统—功能介绍
138 0
|
数据安全/隐私保护
机房收费系统-限制总结
机房收费系统-限制总结
44 0
|
数据库 数据安全/隐私保护
第一次机房收费系统总结
第一次机房收费系统总结
【第一次机房】机房收费系统——下机
【第一次机房】机房收费系统——下机
50 0
|
SQL
机房收费系统—心得
机房收费系统—心得
72 0
|
BI 数据库 容器
机房收费系统——技术总结
机房收费系统——技术总结
87 0