1. 程式人生 > >VB.NET版的“8層”使用者登入例項

VB.NET版的“8層”使用者登入例項

Imports LoginBLL
Imports LoginEntity
Imports Facade
Public Class Form1
    Private Sub btnLogin_Click(sender As Object, e As EventArgs) Handles btnLogin.Click
        If txtBox1.Text = "" Then
            MessageBox.Show("請輸入使用者名稱!", "", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
            txtBox1.Text = ""
            txtBox1.Focus()
            Exit Sub
        ElseIf txtBox2.Text = "" Then
            MessageBox.Show("請輸入密碼!", "", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
            txtBox2.Text = ""
            txtBox2.Focus()
            Exit Sub
        End If
        Try
            '定義一個外觀層的物件  
            Dim FacadeLogin As New Facade.LoginFacade
            Dim UserInfo As New LoginEntity.LoginUserEntity()
            UserInfo.userName = txtBox1.Text
            UserInfo.password = txtBox2.Text
            Dim strResult1 As Boolean
            strResult1 = FacadeLogin.CheckUser(UserInfo) '將U層的文字框的內容傳入外觀層,然後通過外觀層傳入B層進行判斷
            If strResult1 = False Then
                MsgBox("使用者不存在!")
                txtBox1.Text = ""
                txtBox2.Text = ""
                txtBox1.Select()
                txtBox1.Focus()
            End If
            Dim table As DataTable
            table = FacadeLogin.CheckPwd(UserInfo)
            If Trim(txtBox2.Text) = Trim(table.Rows(0).Item(2)) Then
                MsgBox("登陸成功!")
                txtBox1.Text = ""
                txtBox2.Text = ""
            End If
        Catch ex As Exception
            MsgBox("使用者不存在或者密碼不正確")
            txtBox1.Text = ""
            txtBox2.Text = ""
            txtBox1.Select()
            txtBox1.Focus()
        End Try
    End Sub
End Class