机房收费——七层

七层,顾名思义就是把一个窗体分层七块,上篇博客我们分析了三层,那么七层也就是在三层的基础上,再加上四层。

这入住新家的四层是什么呢?这个就可以因人而异了,因为我们之前学过大话,那么这四层,我们就可以从大话借了,因为我比较不聪明,所以我就遵循常规,和大多数一样用最常见的七层了。

先看看我的七层有什么。

接着看他们的关系





如图,可知,我们首先要解决的依旧是实体层。

  1. Public Class User  
  2.     Private name As String  
  3.     Private password As String  
  4.     Private Userid As String  
  5.     Private level As String  
  6.     Private account As String  
  7. '以下为可读写属性  
  8.     Public Property user_name() As String  
  9.         Get  
  10.             Return name  
  11.         End Get  
  12.         Set(ByVal value As String)  
  13.             name = value  
  14.         End Set  
  15.     End Property  
  16.     Public Property user_id() As String  
  17.         Get  
  18.             Return Userid  
  19.         End Get  
  20.         Set(ByVal value As String)  
  21.             Userid = value  
  22.         End Set  
  23.     End Property  
  24.     Public Property user_pwd() As String  
  25.         Get  
  26.             Return password  
  27.         End Get  
  28.         Set(ByVal value As String)  
  29.             password = value  
  30.         End Set  
  31.     End Property  
  32.     Public Property user_level() As String  
  33.         Get  
  34.             Return level  
  35.         End Get  
  36.         Set(ByVal value As String)  
  37.             level = value  
  38.         End Set  
  39.     End Property  
  40.     Public Property user_account() As String  
  41.         Get  
  42.             Return account  
  43.         End Get  
  44.         Set(ByVal value As String)  
  45.             account = value  
  46.         End Set  
  47.     End Property  
  48. End Class  
接着,我们就可以发现,联系最多,关系最密集的就是IDAL接口。我们新建一个接口类,然后

  1. Public Interface IUserInfo  
  2.     '查询用户的接口函数  
  3.     Function QueryUserInfo(ByVal user As Entity.UserInfo) As Entity.UserInfo  
  4.   
  5. End Interface  
有了接口,我们就可以从后往前写了,DAL
 

  1. Public Class T_UserDAL : Implements IUser  
  2.     '/// <summary>  
  3.     '/// depiction:<查询用户名和密码是否正确>  
  4.     '/// </summary>  
  5.     '/// <param name="<enUser>"><用户实体></param>  
  6.     '/// <returns>  
  7.     '///<返回一个用户实体的集合>  
  8.     '/// </returns>  
  9.     Public Function SelectUser(ByVal enUser As Entity.UserEntity) As List(Of Entity.UserEntity) Implements IUser.SelectUser  
  10.         Dim strText As String = "select * from T_User where UserID=@UserID and password=@password"  'sql语句  
  11.         Dim cmdType As CommandType = CommandType.Text   '命令类型  
  12.         Dim Parameter As SqlParameter()  
  13.         '传参   
  14.         Parameter = {New SqlParameter("@UserID", enUser.userID),  
  15.                      New SqlParameter("@password", enUser.password)}  
  16.   
  17.         Dim SqlHelper As New SqlHelper  '实例化SqlHelper这个类的一个对象  
  18.         Dim dt As New DataTable  
  19.         Dim myList As List(Of Entity.UserEntity)  
  20.   
  21.         dt = SqlHelper.ExecuteReaderTable(strText, cmdType, Parameter) '调用sqlhelper中executereadertable的方法  
  22.         myList = EntityHelper.convertToList(Of Entity.UserEntity)(dt)  
  23.   
  24.         Return myList  
  25.     End Function  
  26.   
  27. End Class  

然后就是和他紧密联系的设计模式。工厂141页,不懂看看(我也不太懂,呵呵、)

  1. Imports System.Reflection  
  2. Public Class DataAccess  
  3.     '/// <summary>  
  4.     '/// depiction:<创建用户接口>  
  5.     '/// </summary>  
  6.     '/// <param name="<>"><></param>  
  7.     '/// <returns>  
  8.     '///<返回IUserDAL>  
  9.     '/// </returns>  
  10.     Public Function CreateIUser() As IDAL.IUser  
  11.         Return CType(Assembly.Load("DAL").CreateInstance("DAL.T_UserDAL"), IDAL.IUser)  
  12.     End Function  
  13. End Class
接着是逻辑判断的BLL

  1. Public Function SelectUser(ByVal enUser As Entity.UserEntity) As List(Of Entity.UserEntity)  
  2.         Dim factory As New Factory.DataAccess  
  3.         Dim IUser As IDAL.IUser  
  4.         Dim myList As List(Of Entity.UserEntity)  
  5.   
  6.         IUser = factory.CreateIUser()  
  7.         myList = IUser.SelectUser(enUser)  
  8.   
  9.         Return myList  
  10.   
  11.     End Function  
然后,减负的外观、

  1.  Public Function SelectUser(ByVal enUser As Entity.UserEntity) As List(Of Entity.UserEntity)  
  2.         Dim userBLL As New BLL.T_UserBLL  
  3.         Dim myList As List(Of Entity.UserEntity)  
  4.   
  5.         myList = userBLL.SelectUser(enUser)  
  6.   
  7.         If myList.Count = 0 Then  
  8.             Throw New Exception("用户名或密码输入错误")  
  9.         Else  
  10.             Return myList  
  11.         End If  
  12.     End Function
最后,就是见人的UI

  1.  Private Sub btnConfirm_Click(sender As Object, e As EventArgs) Handles btnConfirm.Click  
  2.         Dim facade As New Facade.LoginFacade  
  3.         Dim myList As New List(Of Entity.UserEntity)  
  4.         Dim enUser As New Entity.UserEntity      '封装实体  
  5.         Dim flag As Boolean  
  6.         Try  
  7.             enUser.userID = txtUserName.Text.Trim()  
  8.             enUser.password = txtPassword.Text.Trim()  
  9.   
  10.             myList = facade.SelectUser(enUser)  
  11.   
  12.             If myList.Count > 0 Then  
  13.                 MsgBox("登录成功")  
  14.   
  15.                 Dim enWorklog As New Entity.WorklogEntity  
  16.                 enWorklog.userID = txtUserName.Text.Trim()  
  17.                 enWorklog.loginDate = CStr(Format(Now(), "yyyy-MM-dd"))  
  18.                 enWorklog.loginTime = CStr(Format(Now(), "HH:mm:ss"))  
  19.                 enWorklog.status = "正在值班"  
  20.                 enWorklog.computer = Environment.GetEnvironmentVariable("USERNAME")  
  21.   
  22.                 flag = facade.InsertWorklog(enWorklog)  
  23.   
  24.                 enLogin.userID = myList.Item(0).userID  
  25.                 enLogin.level = myList.Item(0).level  
  26.   
  27.             End If  
  28.         Catch ex As Exception  
  29.             MessageBox.Show(ex.Message.ToString())  
  30.             txtUserName.Focus()  
  31.             txtUserName.SelectAll()  
  32.             txtPassword.Text = ""  
  33.   
  34.         End Try  
  35.     End Sub  
  36.     Private Sub btnCancel_Click(sender As Object, e As EventArgs) Handles btnCancel.Click  
  37.         Me.Close()  
  38.     End Sub  



评论 10
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值