VB. NET data center charging system-how to write the appearance Layer

Source: Internet
Author: User

VB. NET data center charging system-how to write the appearance Layer
The design pattern is detailed on page 103rd of "big talk Design Pattern". It is only the first step for you to read, read, and repeat the examples on the design pattern, next, if we use the design pattern flexibly in our projects and use the design pattern out of the flowers, it would be king. Some people always say that the paper will end with a glimpse, and we will never know how to do this, however, when it comes to practice, it will never work, but the language will not work. The design mode is C #, and the fee for the IDC is VB. in the NET version, the model in the book cannot be connected to the data center, and I don't know how to use it. I can't help it. I just read the blog, ask people, and check the information online. In this way, I have a look, although it is not perfect, it is very precious, because it is the flower that I have struggled for a long time from the dust, and the application of the appearance model is summarized here.
As for the registration function in the data room charging system, before proceeding, we need to do the following:
A. Check whether the student ID exists in the student table;
B. Check whether the card number exists in the card table;
C. Insert a record into the student table;
D. Insert a record into the table;
E. Insert a record in the recharge table;
In the appearance layer, my code is as follows: (this blog post focuses on the style of the appearance layer, and its layer will not be repeated here)

'*************************************** * ****** 'File Name: registerFacade 'namespace: Facade 'internal volume: queries from the card table and student table whether the card number and student number exist. If yes, a prompt is displayed, indicating that the account does not exist. After successful registration, the account is directed to the card table at one time, student table and recharge table write related information 'function: Register 'file relationship:' OPERATOR: Ding Guohua 'small group: Baby scheduler' generation Date: 15:06:56 'version: v2.0 'modify log: 'copyright description: '*************************************** * ****** Public Class RegisterFacade '///'// Depiction:
  <从学生表里面查询是否存在该学号>
   
'///
  '///
 <学生实体>
  
'///
  
   
'///
   <返回一个学生实体的集合>
    
'///
   
  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 ("this student ID already exists") Else Return myList End If End Function '///
  '// Depiction:
   <从卡表里面查询是否存在该卡号>
    
'///
   '///
  
  <卡实体>
   
'///
   
    
'///
    <返回一个卡实体的集合>
     
'///
    
   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 ("this card number already exists") Else Return myList End If End Function '///
   '// Depiction:
    <插入一条学生信息>
     
'///
    '///
   
   <学生实体>
    
'///
    
     
'///
     <返回布尔值>
      
'///
     
    Public Function InsertStudent (ByVal enStudent As Entity. StudentEntity) As Boolean Dim StudentBLL As New BLL. Adjust Dim flag As Boolean flag = gradient. InsertStudent (enStudent) Return flag End Function '///
    '// Depiction:
     <插入一条卡信息>
      
'///
     '///
    
    <卡实体>
     
'///
     
      
'///
      <返回布尔值>
        '///
      
     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 '///
     '// Depiction:
      <插入一条充值信息>
        '///
      '///
     
     <充值实体>
      
'///
      
        '///
       <返回布尔值>
         '///
       
      Public Function InsertRecharge (ByVal enRecharge As Entity. RechargeEntity) As Boolean Dim defined As New BLL. Adjust Dim Flag As Boolean Flag = RechargeBLL. InsertRecharge (enRecharge) Return Flag End FunctionEnd Class
     
    
   
  
 
Next, let's look at the next recharge function. Before proceeding, we need to think about it:
A. Check whether the card number exists in the card table;
B. Insert a recharge record in the recharge table;
C. Update the balance in the card table

Compared with the above registration function, both functions require querying from the card table and inserting a record into the recharge table. So recharge this function, her interface layer (IDAL), D Layer (DAL), Factory-Factory layer, BLL-business logic layer, her code writing method is the same as the above-mentioned registration function, so we don't need to write it once, just call it directly, But how should we write the appearance layer, I can't write any more. According to the previous writing method, I only need to write a method to update the balance in the card table on the appearance layer, to query and insert a recharge record from the card table, you only need to call the registered appearance. However, in this case, the U layer calls two appearance layers, is it the appearance layer? Obviously not. In the big talk Design Model of Dr. Cheng Jie, the appearance is written in a summary of small methods into a general method and written in a large method, how can I write the recharge appearance? As follows:

'*************************************** * ****** 'File Name: rechargeFacade 'namespace: Facade' internal volume: 'function:' file relation: 'OPERATOR: Ding Guohua' small group: Baby scheduler 'generation Date: 22:18:04' version: v2.0 'modify log: 'copyright description: '*************************************** * ****** Public Class RechargeFacade '///'// Depiction:
  <查询卡号>
   
'///
  '///
 <卡号>
  
'///
  
   
'///
   <返回集合>
    
'///
   
  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 ("this card number does not exist") Else Return mylist End If End function '///
  '// Depiction:
   <需要向卡表中插入一条记录,更新卡表中的余额,我们把这两个写成一个方法,因为都需要返回一个布尔值>
    
'///
   '///
  
  <卡号>
   
'///
   
    
'///
    <返回集合>
     
'///
    
   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
  
 
The partner must have doubts. Isn't there still two ways to register the appearance layer above? To explain it simply, when querying the card number, we need to return the object of a card table, find the previous balance from it, and then add the recharge amount, when a new balance is formed, a table entity can be created during update. The recharge party below returns a boolean value. true indicates that the account is successfully recharged. A method cannot return two values, therefore, two methods are written. In general, there are several methods for the specific appearance layer, which are determined by the return value. The second IDC charging system has not been completed. It is to be continued ......


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.