标签:style blog http color strong 文件
初接触三层
显示层
Imports LogIn.BLL Imports LogIn.Model Public Class frmLogin Public Sub btnLogIn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogIn.Click Dim admininfo As AdminInfoEntity Dim manager As New adminBLL Dim _name As String Dim _password As String _name = txtAdminName.Text _password = txtAdminPwd.Text admininfo = manager.selectAdmin_info(_name, _password) '调用逻辑层,返回的admininfo可能为空,也可能不为空 If admininfo Is Nothing Then MessageBox.Show("登陆失败") Else MessageBox.Show("登陆用户" + admininfo.Name) End If End Sub Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click Me.Close() End Sub End Class业务逻辑层
Imports LogIn.Model Imports LogIn.DAL Public Class adminBLL Dim AdminInfo As AdminInfoEntity Dim AdminDAL As New AdminDAL '验证用户登录信息是否正确 Public Function selectAdmin_info(ByVal name As String, ByVal password As String) As AdminInfoEntity AdminInfo = AdminDAL.getAdminInfo(name, password) '调用数据访问层,返回的admininfo可能为空,也可能不为空 Return AdminInfo End Function End Class数据访问层
Imports System.Data.SqlClient Imports System.Data Imports System.Data.OleDb Imports System Public Class ConnectionToDB Public Function ConnectionToDB() As SqlConnection Dim con As New SqlConnection("Data Source=刘颖-PC;Initial Catalog=Room_Charge_System;User ID=sa;password=123456") '连接数据库 con.Open() Return con End Function End Class
Imports System Imports System.Data Imports System.Data.OleDb Imports System.Data.SqlClient Imports LogIn.Model Public Class AdminDAL Dim AdminInfo As AdminInfoEntity Dim con As New ConnectionToDB '得到用户信息 Public Function getAdminInfo(ByVal name As String, ByVal password As String) As AdminInfoEntity '查表中的记录 Dim cmd As New SqlCommand("select*from T_Admin_info where Name=" & "'" & name & "'" & "and Password=" & "'" & password & "'", con.ConnectionToDB()) Dim reader As SqlDataReader reader = cmd.ExecuteReader() While (reader.Read()) '如果数据表中有用户名和密码都与文本框对应的记录,则利用new 关键字调用AdminInfoEntity构造函数,使admininfo不为空,并对其属性赋值 AdminInfo = New AdminInfoEntity AdminInfo.ID = reader.GetString(0) AdminInfo.Name = reader.GetString(1) AdminInfo.Level = reader.GetString(2) AdminInfo.Password = reader.GetString(3) End While Return AdminInfo End Function End Class实体层
'用户类,分别提供了其他类可以调用的公有属性,也提供了供类内部成员调用的字段,其他类通过属性可以限制对字段的无条件进行操作,例如只读,只写,限定范围赋值。 Public Class AdminInfoEntity Dim _name As String Public Property Name() As String Get Return _name End Get Set(ByVal value As String) _name = value End Set End Property Dim _id As String Public Property ID() As String Get Return _id End Get Set(ByVal value As String) _id = value End Set End Property Dim _level As String Public Property Level() As String Get Return _level End Get Set(ByVal value As String) _level = value End Set End Property Dim _password As String Public Property Password() As String Get Return _password End Get Set(ByVal value As String) _password = value End Set End Property End Class
VB.NET之旅-三层架构之登陆,布布扣,bubuko.com
标签:style blog http color strong 文件
原文地址:http://blog.csdn.net/tgbsqliuying/article/details/37368529