vb.net版機房收費系統——教你七層架構(三)—面板模式

來源:互聯網
上載者:User

標籤:七層   vb.net   

   上次我們看到了D層是怎樣運作的,現在,我簡單示範一下我的外觀和B層是如何和U層和D層打交道的。

  首先我跟大家說的是我的外觀是按照介面功能劃分的,粒度有點小,大家在做的時候,記得外觀有幾個就行了,但是不能沒有,U層不能直接調用B層,這樣就會增加U層和B層的耦合:


'**************************'文 件 名:UserInfo_BLL'命名空間:BLL'內    容:'功    能:'檔案關係:'作    者:邱慕夏'小    組:邱慕夏'產生日期:2014-06-07 17:36:40'版 本 號:V1.0.0.0'修改日誌:'著作權說明:'***************************Imports IDALPublic Class LoginBLL    '/// <summary>    '/// depiction:<查詢User表是否存在該使用者名稱和密碼>    '/// </summary>    '/// <param name="<參數名稱>"><參數說明></param>    '/// <returns>    '///<要返回的是一個實體,entity>    ' /// </returns>    Public Function IsExits(ByVal user As Entity.LoginEntity, ByVal worklog As Entity.WorkLogEntity) As Boolean        Dim IUser As IDAL.IUser        Dim factory As New Factory.DataAccess        Dim IWorklog As IDAL.IWorkLog        IUser = factory.CreateUserInfo()        IWorklog = factory.CreateWorkLog()        Dim table As New DataTable        Dim table1 As New DataTable        table = IUser.User_Login(user)        If table.Rows.Count = 0 Then            Return False        Else            Entity.LoginEntity.UserLevel = table.Rows(0)(3)            If IWorklog.SaveWorkLog(worklog) Then                Return True            End If            Return True        End If    End FunctionEnd Class

  B層不但是用來調用D層,而且我們常常會忘記的是:B層是用來做邏輯判斷的。

  看看外觀層:


 

'**************************'文 件 名:FLogin'命名空間:Facade'內    容:'功    能:'檔案關係:'作    者:邱慕夏'小    組:邱慕夏'產生日期:2014-06-07 17:41:39'版 本 號:V1.0.0.0'修改日誌:'著作權說明:'***************************Imports BLLPublic Class FA_Login    '/// <summary>    '/// depiction:<判斷使用者名稱和密碼是否有誤>    '/// </summary>    '/// <param name="<參數名稱>"><參數說明></param>    '/// <returns>    '///<返回了string類型,可以直接用在msgbox中>    '/// </returns>    Public Function FLogin(ByVal user As Entity.LoginEntity, worklog As Entity.WorkLogEntity) As String        Dim ConfirmUserBll As New BLL.LoginBLL        If ConfirmUserBll.IsExits(user, worklog) = False Then            Return "輸入有誤"        Else            Return "登陸成功"        End If    End FunctionEnd Class

  其實這裡如果不是一個類,而是一個function就更加完美了,這裡需要注意的是:外觀是這樣工作的:


  這個圖在設計模式中很不起眼,但是我只記得這個圖了。精髓所在。

  U層怎樣調用外觀呢?

 

'**************************'文 件 名:FrmLogin'命名空間:UI'內    容:'功    能:'檔案關係:'作    者:邱慕夏'小    組:邱慕夏'產生日期:2014-06-07 16:53:46'版 本 號:V1.0.0.0'修改日誌:'著作權說明:'***************************Public Class FrmLogin    Private Sub btnLogin_Click(sender As Object, e As EventArgs) Handles btnLogin.Click        Dim login As New Entity.LoginEntity        Dim Flogin As New Facade.FA_Login        Dim strResult As String        login.UserID = txtUserID.Text.Trim()        login.Password = TxtPassword.Text.Trim()        Entity.LoginEntity.UserHead = txtUserID.Text.Trim()        Dim worklog As New Entity.WorkLogEntity        worklog.LoginDateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")        worklog.Status = "正在值班"        worklog.UserID = Entity.LoginEntity.UserHead        worklog.Computer = System.Net.Dns.GetHostName().ToString()        strResult = Flogin.FLogin(login, worklog) '插入worklog資料        Select Case strResult            Case "輸入有誤"                MsgBox("輸入有誤,請重新輸入")                txtUserID.Focus()            Case "登陸成功"                MsgBox("登陸成功")                Entity.WorkLogEntity.Login_DateTime = worklog.LoginDateTime                Me.Hide()                FrmMain.Show()        End Select    End Sub    Private Sub btnQuit_Click(sender As Object, e As EventArgs) Handles btnQuit.Click        Me.Close()    End SubEnd Class

  大家注意調用的時候,好好看看返回值就好了,facade層中返回的是string類型的,那麼調用的時候,就這樣:

  dim str as string =fa_login(login,worklog)

  這樣就行了,U層select case str,就可以判斷是否是成功了。

  關於外觀層我就不錯說了,外觀的設計在:

  http://blog.csdn.net/qiumuxia0921/article/details/33738319

  寫的很明白,多說無益。

  


  

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.