机房重构——退卡

前言:

    关于机房重构实现了几条线之后也能“照着葫芦画瓢”一步步实现自己所需的功能,心态与刚开始敲得时候已经完全不一样了!

    其实上一篇写的是充值,充值和退卡的实现思路基本是一样的但是我充值没有用存储过程,想着退卡的时候用已下存储过程!

功能说明篇:

   1.通过输入卡号判断是否有这个卡号

   2.若有判断是否正在上机,没有的话提示没有重新输入卡号再判断

   3.若在上机,提示不能退卡,否则更新退卡表,卡表,和充值表(注册的时候用充值表)

机房重构——退卡_第1张图片

代码篇:

  接口层:

Function Cancelcard(ByVal card As Entity.CardEntity, ByVal cancelinfo As Entity.CancelCardEntity) As DataTable

Function selectcardno(ByVal Line As Entity.LineEntity) As DataTable

  接下来是D层

Public Class SqlserverCancelCardDAL : Implements IDAL.ICancelCard

    Private sqlhelper As New SQLHelper.sqlHelper
    Public Function Cancelcard(card As CardEntity, cancelinfo As CancelCardEntity) As DataTable Implements ICancelCard.Cancelcard
        Dim dt As DataTable
        Dim sql As String = "proc_Cancelcard"  '用存储过程
        Dim sqlparams As SqlParameter() = {New SqlParameter("@cardNo", cancelinfo.cardNo),
                                           New SqlParameter("@Date", cancelinfo.CancelDate),
                                           New SqlParameter("@Time", cancelinfo.CancelTime),
                                           New SqlParameter("@OperatorId", cancelinfo.OperatorID)}

        dt = sqlhelper.ExecSelect(sql, CommandType.StoredProcedure, sqlparams)

        Return dt
    End Function

    Public Function selectcardno(Line As LineEntity) As DataTable Implements ICancelCard.selectcardno
        Dim table As DataTable
        Dim sql As String

        Dim paras As SqlParameter() = {New SqlParameter("@cardno", Line.cardNo)}
        sql = "select * from T_Lineinfo where cardNo=@cardno and offLineDate is null"
        table = sqlhelper.ExecSelect(sql, CommandType.Text, paras)
        Return table
    End Function

   
End Class

  B层:

 Public Function selectcardno(ByVal Line As Entity.LineEntity) As DataTable
        Dim factory As New Factory.CardFactory
        Dim Icancelcard As ICancelCard
        Dim table As DataTable

        Icancelcard = factory.cancelcard
        table = Icancelcard.selectcardno(Line)
        Return table
    End Function

    Public Function Cancelcard(ByVal card As Entity.CardEntity, ByVal cancelinfo As Entity.CancelCardEntity) As DataTable
        Dim fac As New Factory.CardFactory
        Dim icancelcard As ICancelCard
        Dim dt As DataTable

        icancelcard = fac.cancelcard
        dt = icancelcard.Cancelcard(card, cancelinfo)
        Return dt


  外观:

Public Function selectcardno(ByVal Line As Entity.LineEntity) As DataTable
        Dim ccbll As New BLL.CancelCardBLL
        Dim table As DataTable
        table = ccbll.selectcardno(Line)
        Return table
    End Function
    Public Function canclecard(ByVal cancelinfo As CancelCardEntity, ByVal card As CardEntity) As DataTable
        Dim CancleBLL As New BLL.CancelCardBLL
        Dim dt As DataTable
        dt = CancleBLL.cancelcard(card, cancelinfo)
        Return dt
    End Function

  U层:

 If txtCardNo.Text = "" Or IsNumeric(txtCardNo.Text) = False Then
            MsgBox("请输入卡号,卡号为数字!", vbExclamation, "警告")
            txtCardNo.Select()
            txtCardNo.Focus()
            Exit Sub
        End If


        Dim card As New Entity.CardEntity
        Dim Line As New Entity.LineEntity
        Dim cancelinfo As New Entity.CancelCardEntity
        Line.cardNo = txtCardNo.Text.Trim()
        

        Dim canclefacade As New Facade.CancelCardFacade
        Dim Rresult As DataTable
        Rresult = canclefacade.selectcardno(Line)

        If Rresult.Rows.Count > 0 Then
            MsgBox("此卡号正在上机,不能进行退卡", , "提示")
            txtCardNo.Text = ""
            
        Else


            cancelinfo.cardNo = txtCardNo.Text.Trim()
            cancelinfo.OperatorID = FrmLogin.txtUserName.Text.Trim()

            cancelinfo.CancelDate = Date.Now.ToString("yyyy-MM-dd")
            cancelinfo.CancelTime = DateTime.Now.ToString("HH:mm:ss")

            Dim ccfacade As New Facade.CancelCardFacade
            Dim dt As DataTable
            dt = ccfacade.canclecard(cancelinfo, card)


            If dt.Rows.Count > 0 Then

                txtcash.Text = dt.Rows(0).Item(6)


                TextBox3.Text = "退卡卡号为:" & cancelinfo.cardNo & vbCrLf & vbCrLf & "退卡金额是:" & txtcash.Text + vbCrLf & vbCrLf & "退卡时间为:" & Now & vbCrLf & vbCrLf & "进行退卡老师是:" & cancelinfo.OperatorID
                MsgBox("退卡成功", , "提示")

                txtCardNo.Text = ""
                txtcash.Text = ""
                TextBox3.Text = ""
            Else
                MsgBox("没有此卡号!", vbExclamation, "警告")
                txtCardNo.Text = ""
                txtCardNo.Select()
                txtCardNo.Focus()
            End If
        End If

小结篇:

  其中关于上机不能退卡一开始这个功能实现不对发现是D层的sql语句写的有问题:

  一开始代码是这样写的:

 sql = "select * from T_Lineinfo where cardNo=@cardno and offLineDate =''"
  发现执行的结果不对,应改为:

sql = "select * from T_Lineinfo where cardNo=@cardno and offLineDate is null"
  null和字符串为空这个问题也是需要注意的!

你可能感兴趣的:(重构,退卡)