3 층 빠 른 일람 - 작은 예

4142 단어
오늘 다시 내 가 초학 3 층 때 쓴 작은 예 와 할 것 을 비교 해 보 자. 우 리 는 디자인 과 모델 을 추가 하 는 것 과 디자인 모델 을 추가 하지 않 은 것 의 차 이 를 살 펴 보 자.
'/************************************************* 
'  :  
'  :  
'  :            
'    :2013.1.30
'   :
'**********************************************/

'     
Public Class userServers

    '        
    Public Shared Function TestingUser(ByVal UI_TestUser As Model.User) As Boolean

        Dim DAl_TestUser As Model.User
        Dim DAl_User = New DAL.User
        DAl_TestUser = DAl_User.User_select(UI_TestUser.Name)

        If DAl_TestUser Is Nothing Then
            Return False
        End If

        If Trim(UI_TestUser.PassWord) = Trim(DAl_TestUser.PassWord) Then
            Return True
        Else
            Return False
        End If

    End Function

End Class


'/************************************************* 
'  :  
'  :  
'  :           
'    :2013.1.30
'   :
'**********************************************/

Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports Model

'       
Public Class User

    '    
    Private str_SqlConnection As String = "Data Source=192.168.24.188;Initial Catalog=Charge;User ID=sa;Password=123456"
    'Dim str_SqlConnection As String = "Data Source=localhost;Initial Catalog=Charge;Persist Security Info=True;User ID=sa;Password=123456"

    '    
    Public Function User_select(ByVal Name As String) As Model.User
        Dim strSqlstring As String
        strSqlstring = "select * from user_info where user_id='" & Name & "'"
        'strSqlstring = "Select * From user_info Where user_id='" & Name & "'"
        Dim seting As String
        seting = str_SqlConnection

        Dim MyConn As SqlConnection
        MyConn = New SqlConnection(seting)

        Dim MyCmd As SqlCommand
        MyCmd = New SqlCommand(strSqlstring, MyConn)
        Try
            MyConn.Open()
            Dim MyReader As SqlDataReader


            MyReader = MyCmd.ExecuteReader

            Dim testUser As New Model.User
            If MyReader.Read() Then
                testUser.Name = MyReader.GetFieldValue(Of String)(0)
                testUser.PassWord = MyReader.GetFieldValue(Of String)(1)




                MyReader.Close()
                MyConn.Close()

                Return testUser
            Else
                Return Nothing
            End If

        Catch ex As Exception
            MsgBox(ex.Message)
        End Try

    End Function

End Class


'/************************************************* 
'  :  
'  :  
'  :   
'    :2013.1.30
'   :
'**********************************************/

' user     
Public Class User


    Private _name As String

    Private _password As String


    ' user    name   
    Public Property Name() As String
        Get
            Return _name
        End Get

        Set(value As String)
            _name = value
        End Set
    End Property

    ' user         
    Public Property PassWord() As String
        Get
            Return _password
        End Get

        Set(value As String)
            _password = value
        End Set
    End Property


End Class
'/************************************************* 
'  :  
'  :  
'  :UI     
'    :2013.1.30
'   :
'**********************************************/


Public Class frm_Landing


    Private Sub cmd_Cancel_Click(sender As Object, e As EventArgs) Handles cmd_Cancel.Click
        End
    End Sub

    '  
    Private Sub cmd_OK_Click(sender As Object, e As EventArgs) Handles cmd_OK.Click

        '     
        Dim UI_TestUser As New Model.User
        UI_TestUser.Name = txt_Name.Text
        UI_TestUser.PassWord = txt_PassWord.Text

        '    
        If BLL.userServers.TestingUser(UI_TestUser) Then
            MsgBox("    !")
        Else
            MsgBox("    !")
        End If



    End Sub
End Class

좋은 웹페이지 즐겨찾기