VB.NET版機房收費系統---外觀層如何寫,vb.net收費系統

來源:互聯網
上載者:User

VB.NET版機房收費系統---外觀層如何寫,vb.net收費系統
       外觀設計模式,《大話設計模式》第103頁詳細講解,不記得這塊知識的小夥伴可以翻閱翻閱,看過設計模式,敲過書上的例子,只是學習的第一步,接著,如果在我們的項目中靈活應用,把設計模式用出花兒來,才是王道,有人總說,紙上得來終覺淺,絕知此事要躬行,可是真到了躬行的時候,總是行不通,語言倒不過來,設計模式是C#語言的,機房收費是VB.NET版本的,書上的模式和機房聯絡不起來,不知道怎麼應用,沒辦法,憋唄,看部落格,問人,上網查資料,就這樣,憋出一個外觀,雖不太完美,但卻異常寶貴,因為那是我糾結好長時間從塵埃裡開出的花,就面板模式的應用在這裡小小的總結一下。
       就機房收費系統中的一個註冊功能來說,著手之前,我們需要做以下思考工作:
       a、從學生表裡查詢,是否存在該學號;
       b、從卡表裡查詢,是否存在該卡號;
       c、在學生表裡插入一條記錄;
       d、在卡表裡插入一條記錄;
       e、在充值表裡插入一條記錄;
       在外觀層My Code如下:(該博文,重點闡述外觀層的寫法,其她層再此不再贅述)
       

<span style="font-size:18px;">'**********************************************'文 件 名: RegisterFacade'命名空間: Facade'內    容: 從卡表和學生表裡面查詢是否存在該卡號和學號,存在,給出提示,不存在,註冊成功之後,一次向卡表,學生表和儲值表中寫入相關資訊'功    能: 註冊'檔案關係:'作    者:丁國華'小    組:寶貝計劃'產生日期: 2014/7/17 15:06:56'版本號碼:V2.0'修改日誌:'著作權說明:'**********************************************Public Class RegisterFacade    '/// <summary>    '/// depiction:<從學生表裡面查詢是否存在該學號>    '/// </summary>    '/// <param name="<enStudent>"><學生實體></param>    '/// <returns>    '///<返回一個學生實體的集合>    '/// </returns>    Public Function QueryStudentNo(ByVal studentNo As String) As List(Of Entity.StudentEntity)        Dim studentBLL As New BLL.T_StudentBLL        Dim myList As List(Of Entity.StudentEntity)        myList = studentBLL.QueryStudentNo(studentNo)        If myList.Count > 0 Then            Throw New Exception("該學號已經存在")        Else            Return myList        End If    End Function    '/// <summary>    '/// depiction:<從卡表裡面查詢是否存在該卡號>    '/// </summary>    '/// <param name="<enCard>"><卡實體></param>    '/// <returns>    '///<返回一個卡實體的集合>    '/// </returns>    Public Function QueryCardNo(ByVal cardNo As String) As List(Of Entity.CardEntity)        Dim cardBLL As New BLL.T_CardBLL        Dim myList As List(Of Entity.CardEntity)        myList = cardBLL.QueryCardNo(CardNo)        If myList.Count > 0 Then            Throw New Exception("該卡號已經存在")        Else            Return myList        End If    End Function    '/// <summary>    '/// depiction:<插入一條學生資訊>    '/// </summary>    '/// <param name="<enStudent>"><學生實體></param>    '/// <returns>    '///<返回布爾值>    '/// </returns>    Public Function InsertStudent(ByVal enStudent As Entity.StudentEntity) As Boolean        Dim StudentBLL As New BLL.T_StudentBLL        Dim flag As Boolean        flag = StudentBLL.InsertStudent(enStudent)        Return flag    End Function    '/// <summary>    '/// depiction:<插入一條卡資訊>    '/// </summary>    '/// <param name="<enCard>"><卡實體></param>    '/// <returns>    '///<返回布爾值>    '/// </returns>    Public Function InsertCard(ByVal enCard As Entity.CardEntity) As Boolean        Dim CardBLL As New BLL.T_CardBLL        Dim flag As Boolean        flag = CardBLL.InsertCard(enCard)        Return flag    End Function       '/// <summary>    '/// depiction:<插入一條儲值資訊>    '/// </summary>    '/// <param name="<enRecharge>"><儲值實體></param>    '/// <returns>    '///<返回布爾值>    '/// </returns>    Public Function InsertRecharge(ByVal enRecharge As Entity.RechargeEntity) As Boolean        Dim RechargeBLL As New BLL.T_RechargeBLL        Dim Flag As Boolean        Flag = RechargeBLL.InsertRecharge(enRecharge)        Return Flag    End FunctionEnd Class</span>
       接著,我們再來看下一個充值的功能,著手之前,我們需要做一下思考工作:
       a、從卡表裡面查詢,是否存在該卡號;
       b、在充值表裡面插入一條充值記錄;
       c、更新卡表中的餘額

      和上述的註冊功能相比較,兩個功能都需要從卡表裡面查詢和向充值表裡面插入一條記錄。所以充值這個功能,她的介面層(IDAL),D層(DAL),Factory-工廠層,BLL-商務邏輯層,她的代碼寫法和上述的註冊功能的寫法都是一樣的,我們就不需要在寫一次,直接調用就可以了,但是外觀層要怎麼寫呢,寫著寫著就寫不下去了,按著以前的寫法,只需要在外觀層寫一個更新卡表中餘額的方法就行了,從卡表中查詢和在充值表中插入一條充值記錄,只需要調用註冊的外觀就可以了,可是,這樣寫的話,U層就調用了兩個外觀層,那還是外觀層嗎?顯然不是,看人程傑老師的大話設計模式中,外觀的寫法是把小的方法匯總成一個總的方法,寫在一個大的方法裡面,那充值的外觀到底如何寫呢?如下:

        

<span style="font-size:18px;">'**********************************************'文 件 名: RechargeFacade'命名空間: Facade'內    容:'功    能:'檔案關係:'作    者:丁國華'小    組:寶貝計劃'產生日期: 2014/7/18 22:18:04'版本號碼:V2.0'修改日誌:'著作權說明:'**********************************************Public Class RechargeFacade    '/// <summary>    '/// depiction:<查詢卡號>    '/// </summary>    '/// <param name="<enCard>"><卡號></param>    '/// <returns>    '///<返回集合>    '/// </returns>    Public Function QueryCard(ByVal cardNo As String) As List(Of Entity.CardEntity)        Dim cardbll As New BLL.T_CardBLL        Dim mylist As List(Of Entity.CardEntity)        mylist = cardbll.QueryCardNo(cardNo)        If mylist.Count = 0 Then            Throw New Exception("該卡號不存在")        Else            Return mylist        End If    End Function    '/// <summary>    '/// depiction:<需要向卡表中插入一條記錄,更新卡表中的餘額,我們把這兩個寫成一個方法,因為都需要返回一個布爾值>    '/// </summary>    '/// <param name="<enCard>"><卡號></param>    '/// <returns>    '///<返回集合>    '/// </returns>    Public Function Recharge(ByVal enCard As Entity.CardEntity, ByVal enRecharge As Entity.RechargeEntity) As Boolean        Dim CardBLL As New BLL.T_CardBLL        Dim RechargeBLL As New BLL.T_RechargeBLL        Dim Flag(2) As Boolean        Flag(0) = RechargeBLL.InsertRecharge(enRecharge)        Flag(1) = CardBLL.UpdateCard(enCard)        If Flag(0) And Flag(1) Then            Return Flag(0)        Else            Return False        End If    End FunctionEnd Class</span>
        小夥伴肯定有疑問,上面註冊的外觀層不是仍然有兩個方法?簡單,解釋一下,因為,查詢卡號的時候,我們需要返回一個卡表的實體,然後從裡面找到以前的餘額,然後還要加上充值的金額,形成一個新的餘額,更新的時候才能有一個卡表實體,下面recharge的那個方我們的返回值boolean,true為充值成功,一個方法不可能有兩個返回值,所以寫成兩個方法,總的來說就是具體外觀層有幾個方法,是由返回值定的。第二遍機房收費系統,未完,待續......



vbnet 控制項的Anchor屬性怎寫?

.Anchor =AnchorStyles.Bottom or AnchorStyles.Left or AnchorStyles.Right or AnchorStyles.Top
 
VBnet 2008怎寫使用者控制項?

參考:
Public Class UserControl1
#Region "變數"
Dim Down_Color As Color = Color.Blue
Dim UP_Color As Color = Color.Gray

Dim Mode As Short = 0
Dim flag As Boolean

Dim offset_X As Integer
Dim offset_Y As Integer

Dim Mouse_P As Point
#End Region

#Region "屬性"
'按下顏色
Public Property _DownColor As Color
Get
Return Down_Color
End Get
Set(ByVal value As Color)
Down_Color = value
End Set
End Property

'彈起顏色
Public Property _UpColor As Color
Get
Return UP_Color
End Get
Set(ByVal value As Color)
UP_Color = value
End Set
End Property

'滑動模式 0-橫 1-豎
Public Property _Mode As Short
Get
Return Mode
End Get
Set(ByVal value As Short)
Mode = value
End Set
End Property
#End Region

Private Sub UserControl1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Me.BackColor = UP_Color
End Sub

'滑鼠按下
Private Sub UserControl1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown
Me.BackColor = Down_Color
Mouse_P = e.Location
flag = True
End Sub

'滑鼠移動
Private Sub UserControl1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
If flag = False Then Ex......餘下全文>>
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.