標籤:style blog http get 使用 strong
前段時間用簡單的三層實現了表單登入功能,心中有點小小的成就感,但是很快就被潑了涼水,機房收費不可能只用三層實現,如果你用三層,也就是說後面機房收費所有的功能都必須使用三層來實現功能。所以一周前始了七層的研究。經過一個星期的看部落格,總結,調代碼,終於實現了表單登入,資訊錄入,和簡單充值查詢功能。
說說自己這次七層之旅的總結吧。
1.毋庸置疑,研究一個表單功能,我首先判斷的是需要用到資料庫中的哪些表(這是屬於我自己的編程習慣,不適用全部),然後再實體層中將表中的欄位表示出來,有多少個表就有多少實體類,實體類只會多於表的數量!一個表映射出一個實體類,表中的欄位就是實體類的屬性!這裡附帶上自己代碼中的一部分吧!
Public Class LoginModel Private _userID As String Private _level As String Private _password As String Private _userName As String Private _computer As String Public Shared UserHead As String ' 設定全域變數 Public Shared UserLevel As String Public Property UserID() As String Get Return _userID End Get Set(value As String) _userID = value End Set End Property Public Property PassWord() As String Get Return _password End Get Set(value As String) _password = value End Set End Property Public Property level() As String Get Return _level End Get Set(value As String) _level = value End Set End Property Public Property UserName() As String Get Return _userName End Get Set(value As String) _userName = value End Set End Property Public Property Computer() As String Get Return _computer End Get Set(value As String) _computer = value End Set End PropertyEnd Class
2.接下倆進行的是關於工廠+反射+介面+DAL的介紹了
這個過程中涉及的東西比較多。我先概括的說說自己這部分用到了什麼知識吧!
(1) 用反射+抽象工廠的資料訪問程式
開始以為是新知識,但是大家可以看看咱們《設計模式》,抽象工廠一章中說到反射利用字串來執行個體化對象,而變數時可以更換的!
大家記住一段簡單的代碼吧:
Assmbly.load("程式集名稱").CreadteInstance("命名空間.類名稱")我把這段話理解為製造介面的過程。
關於這部分內容會有專門的部落格寫到!
在敲工廠時會經常出現這樣的錯誤:
出現了這個錯誤,查了查部落格,下面我只說出自己的方法,將DAL中產生輸出路徑,改為UI的產生輸出路徑即可,關於這個錯誤,有好多詳細的部落格介紹。我就不多說了。
(2)接下來我就開始理解關於工廠,介面和DAL之間的關係了,,工廠反射,就是防止更換資料庫,接著工廠其實就是生產介面,將DAL中的類產生介面,然後在DAL中調用介面,來實現介面。
關於DAL中對資料庫的增刪改查都是重複的,這裡我們抽象出一個類Sqlhelper,我們學的是物件導向,就是學會使用物件導向的思想,關於Sqlhelper會有詳細的部落格奉上。
Sqlhelper類我寫在了DAL的下面,而後面的代碼就會變得簡單起來,就是聲明,執行個體化,返回值的應用了。附上小部分代碼:
<strong><span style="font-size:18px;"> Public Function RechargeQuery(cardno As Model.RechargeModel) As Model.RechargeModel Implements IDAL.IRecharge.RechargeQuery Dim sqlparams As SqlParameter() = {New SqlParameter("@CardNo", cardno.StuInfoQuery)} Dim strText As String = "select * from T_StuInfo where CardNo [email protected]" Dim helper As New SqlHelper Dim cmdtype As CommandType = New CommandType() cmdtype = CommandType.Text Dim table As DataTable Dim Ucardno As New Model.RechargeModel table = helper.ExecuteQuery(strText, cmdtype, sqlparams) If table.Rows.Count <> 0 Then Ucardno.StuInfoQuery = table.Rows(0).Item("CardNo") End If Return Ucardno End Function</span></strong>
其實在這一部分還會有關於預存程序的介紹,但是介於篇幅的影響就不向大家介紹了。
這篇文章純屬個人理解,如有錯誤理解,歡迎大家踴躍拍磚!
接下來我會向大家介紹BLL和外觀層的理解