⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 global.asax.vb

📁 用VB.NET在VS.NET 2003下开发的完整的设备管理系统,后台数据库为SQL SERVER 2000,解压缩后请先阅读"说明"文件来部署此系统.
💻 VB
字号:
Imports System.Web
Imports System.Web.SessionState
Imports System.Data
Imports System.Data.SqlClient
Imports System.IO
Imports System.Collections

Public Class Global
    Inherits System.Web.HttpApplication
    Public Shared RootPath As String
    Public Shared StrConnectionHead As String
    Public Shared OnlinePerson As ArrayList     ' 用来存储在线人员的ArrayList

#Region " 组件设计器生成的代码 "

    Public Sub New()
        MyBase.New()

        '该调用是组件设计器所必需的。
        InitializeComponent()

        '在 InitializeComponent() 调用之后添加任何初始化

    End Sub

    '组件设计器所必需的
    Private components As System.ComponentModel.IContainer

    '注意: 以下过程是组件设计器所必需的
    '可以使用组件设计器修改此过程。
    '不要使用代码编辑器修改它。
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        components = New System.ComponentModel.Container()
    End Sub

#End Region

    Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
        ' 在应用程序启动时激发
        RootPath = Server.MapPath("ApplicationInfo")
        Dim file As New FileStream(RootPath & "\ConnectionStringHead.txt", FileMode.Open, FileAccess.Read)
        Dim read As New StreamReader(file)
        StrConnectionHead = read.ReadToEnd()
        file.Close()
        OnlinePerson = New ArrayList
    End Sub

    Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs)
        ' 在会话启动时激发
    End Sub

    Sub Application_BeginRequest(ByVal sender As Object, ByVal e As EventArgs)
        ' 在每个请求开始时激发
    End Sub

    Sub Application_AuthenticateRequest(ByVal sender As Object, ByVal e As EventArgs)
        ' 尝试对使用进行身份验证时激发
    End Sub

    Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
        ' 在发生错误时激发
    End Sub

    Sub Session_End(ByVal sender As Object, ByVal e As EventArgs)
        ' 在会话结束时激发
        OnlinePerson.Remove(Convert.ToString(Session("login_name")))
    End Sub

    Sub Application_End(ByVal sender As Object, ByVal e As EventArgs)
        ' 在应用程序结束时激发
    End Sub

    Shared Function GetConnection(ByVal strDatabase As String) As System.Data.SqlClient.SqlConnection
        ' 获得一个连接,strDatabase为要连接的数据库字符串
        Dim con As New SqlConnection(StrConnectionHead & "database=" & strDatabase)
        Return con
    End Function

    Shared Function CreateDataView(ByVal SQLstr As String) As System.Data.DataView
        ' 通过传递查询字符串返回一个相应的视图
        Dim myConnection As SqlConnection = GetConnection("equipment")
        Dim myDataAdapter As New SqlDataAdapter(SQLstr, myConnection)
        Dim myDataSet As New DataSet
        myConnection.Open()
        myDataAdapter.Fill(myDataSet)
        myConnection.Close()
        CreateDataView = New DataView(myDataSet.Tables.Item(0))
    End Function

    Shared Function ReturnSingleInfo(ByVal str As String) As String
        ' 通过参数传递查询字符串,返回唯一的目标字符串
        Dim myConnection As SqlConnection = GetConnection("equipment")
        Dim myCommand As New SqlCommand(str, myConnection)
        Dim cloneStr As String
        myConnection.Open()
        Dim reader As SqlDataReader = myCommand.ExecuteReader()
        While reader.Read()
            cloneStr = Trim(Convert.ToString(reader.Item(0)))
        End While
        reader.Close()
        myConnection.Close()
        Return cloneStr
    End Function
End Class

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -