机房收费系统总结之关闭窗体

我们在系统开发的时候,通常情况下都会遇到关于对主窗口关闭时需要做一些列的业务操作,或者弹出提示框提醒用户是否真的要关闭窗口的情况。但是它们具体是怎么实现的呢?下面和大家来分享一下我在做机房收费系统中遇到的这类问题的具体解决方案。

这是VB6.0的代码:

'判断系统是否退出
Private Sub MDIForm_QueryUnload(Cancel As Integer, UnloadMode As Integer)

    Dim strOnWork As String
    Dim strMsg As String
    Dim rstOnWork As ADODB.Recordset
    Dim rstWorkLog As ADODB.Recordset
    Static intSerial As Integer
    
    If MsgBox("是否确定退出?", vbOKCancel + vbExclamation, "系统提示") = vbOK Then
         
        '查询正值班老师信息表
        strOnWork = "select * from Onwork_info where UserID='" & g_strUserName & "'"
        Set rstOnWork = ExecuteSQL(strOnWork, strMsg)
        
        '查询教师工作记录表,获取记录数
        strOnWork = "select * from worklog_info "
        Set rstWorkLog = ExecuteSQL(strOnWork, strMsg)
        intSerial = rstWorkLog.RecordCount + 1
        
        '更新教师工作记录表
        strOnWork = "INSERT worklog_info VALUES(" & intSerial & ",'" & Trim(rstOnWork!UserID) & _
                    "','" & rstOnWork!UserLevel & "','" & rstOnWork!LoginDate & "','" & _
                    rstOnWork!LoginTime & "','" & Date & "','" & Time & "','" & _
                    rstOnWork!Computer & "','" & "true" & "')"
        Call ExecuteSQL(strOnWork, strMsg)
        
        '更新正值班老师信息表
        rstOnWork.Delete
        
        rstOnWork.Close
        
        Cancel = 0
        
    Else
    
        Cancel = 1
          
    End If
    
End Sub



这是VB.Net的代码:

'***以下系统是三层架构中U层关闭主窗体时,判断系统是否退出的代码***

Private Sub frmMain_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
    Dim teacherWorkManageBLL As New BLL.TeacherWorkManageBLL
    Dim workLogEntity As New Entity.WorkLogEntity

    If MsgBox("是否确定退出?", vbOKCancel + vbExclamation, "系统提示") = vbOK Then
        '用户工作记录实体赋值
        workLogEntity.UserId = frmLogin.txtUser.Text.Trim
        workLogEntity.LogoutTime = Now
        '添加用户下线时间
        teacherWorkManageBLL.ModifyWorkLog(workLogEntity)

        '***在这里可以加入系统退出前的一些列操作***

        e.Cancel = False
        '关闭此父窗体的所有子窗体
        For Each ChildForm As Form In Me.MdiChildren
            ChildForm.Close()
        Next
        Me.Close()
        e.Cancel = False
    Else
        e.Cancel = True
    End If

End Sub


通过这两种语言代码对同一功能的实现比较,我们会发现,在编程的世界里,其实语言都是想通的,只是表达方式不同了而已。我们这些程序员其实要学习的更多的并非语言,而是思想逻辑,系统架构。



你可能感兴趣的:(机房收费系统总结之关闭窗体)