机房收费系统之上下机

简介:

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

       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,是有一些技巧的,学会用这些技巧感觉比把逻辑理清楚更重要,大家有什么不同的见解,希望和大家交流!

        

相关文章
机房收费系统——下机封装、点击下机、全员下机、选择下机和动态下机(有关下机的所有代码)
机房收费系统——下机封装、点击下机、全员下机、选择下机和动态下机(有关下机的所有代码)
|
7月前
|
存储 区块链
无聊猿大逃杀游戏卷轴模式系统开发逻辑步骤
区块链的去中心化,数据的防篡改,决定了智能合约更加适合于在区块链上来实现
|
10月前
|
数据可视化 测试技术 BI
机房收费系统—功能介绍
机房收费系统—功能介绍
|
10月前
重构-动态下机
重构-动态下机
32 0
|
10月前
机房收费系统—组合查询逻辑分析
机房收费系统—组合查询逻辑分析
|
10月前
【第一次机房】机房收费系统——下机
【第一次机房】机房收费系统——下机
39 0
|
11月前
|
BI 数据库 容器
机房收费系统——技术总结
机房收费系统——技术总结
57 0
|
SQL BI 索引
【SQL开发实战技巧】系列(二十八):数仓报表场景☞人员分布问题以及不同组(分区)同时聚集如何实现
【SQL开发实战技巧】这一系列博主当作复习旧知识来进行写作,毕竟SQL开发在数据分析场景非常重要且基础,面试也会经常问SQL开发和调优经验,相信当我写完这一系列文章,也能再有所收获,未来面对SQL面试也能游刃有余~。
【SQL开发实战技巧】系列(二十八):数仓报表场景☞人员分布问题以及不同组(分区)同时聚集如何实现
|
数据采集 SQL 存储
整体技术流程-数据入库(ETL)|学习笔记
快速学习整体技术流程-数据入库(ETL)
936 0
整体技术流程-数据入库(ETL)|学习笔记
|
小程序 搜索推荐
聚合卡牌盲盒模式系统开发逻辑方案设计程序(成熟代码)
聚合卡牌盲盒模式系统开发逻辑方案设计程序(成熟代码)
241 0