vb.net机房收费系统的系统登录

       这是第一次用vb.net写机房收费系统的系统登录,用到了三层的知识,三天前当我正准备去做着手做系统的时候,还不知道从那里下手,经过查资料,看博客自己也写出了一个登录的例子,通过这次能够了解了三层每一层的真正的含义,也为自己以后做机房收费系统做一个基础的开端

'DAL层
Imports System.Data.SqlClient
Public Class LoginDAL
    Public Function LoginDALSelectUser(ByVal UserName As String) As Model.LoginModel
        '建立数据库连接字符串
        Dim LoginConn As New SqlClient.SqlConnection("server=yiqing-pc;database=charge_sys;user id=sa;password=******")
        '建立数据库命令字符串
        Dim LoginCmm As New SqlClient.SqlCommand("select userid ,pwd from user_info where userid='" & UserName & "'", LoginConn)
        '打开数据库
        LoginConn.Open()
        '定义一个数据库库读取方式
        Dim LoginReader As SqlDataReader
        '读取数据库中的内容
        LoginReader = LoginCmm.ExecuteReader

        Dim testUser As New Model.LoginModel
        If LoginReader.Read() Then
            testUser.userName = LoginReader.GetFieldValue(Of String)(0)
            testUser.passWord = Trim(LoginReader.GetFieldValue(Of String)(1))

            Return testUser

            LoginReader.Close()
            LoginConn.Close()
        Else
            Return Nothing
        End If
    End Function
End Class

'BLL层
Public Class LoginBLL
    Public Shared Function isnullLoginBLL(ByVal UI_testUser As Model.LoginModel) As String
        Dim DAL_testUser As Model.LoginModel
        Dim BLL_user As New DAL.LoginDAL

        DAL_testUser = BLL_user.LoginDALSelectUser(UI_testUser.userName)

        '判断BLL_testUser.LoginDALSelectUser的返回值
        If DAL_testUser Is Nothing Then
            Return False
        End If

        If UI_testUser.passWord = DAL_testUser.passWord Then
            Return True
        Else
            Return False
        End If
    End Function
End Class

 '系统登录UI层
    Private Sub BtnOk_Click(sender As Object, e As EventArgs) Handles BtnOk.Click
        '实例化一个ui层用到的实体类
        Dim UI_user As New Model.LoginModel
        '将输入的内容,赋给实例化对象
        UI_user.userName = txtUserName.Text
        UI_user.passWord = txtPassWord.Text

        '判断isnullLoginBLL(UI_user)的返回值
        If BLL.LoginBLL.isnullLoginBLL(UI_user) Then
            MsgBox("登录成功")
        Else
            MsgBox("登录失败")
        End If

    End Sub

'实体层
Public Class LoginModel
    Private MuserName As String
    Public Property userName() As String
        Get
            Return MuserName
        End Get
        Set(value As String)
            MuserName = value
        End Set
    End Property

    Private MpassWord As String
    Public Property passWord() As String
        Get
            Return MpassWord
        End Get
        Set(value As String)
            MpassWord = value
        End Set
    End Property
End Class



你可能感兴趣的:(VB.NET)