ArticleDirectory
I haven't written this series for a long time, and it seems that it has been nearly half a year since the previous one. Looking back at what I have already written, it's a bit naive. I'm glad someone will go back and comment on it. Thank you. I read an article written by golden ocean a few days ago. I feel that I have not finished my mind yet. I also wrote an article on my own, and I am ugly here.
This article is equivalent to a summary. It can be said that it is a new kind of understanding, and I am also trying. If you don't talk nonsense, go to the topic. First, we need to explain some terms.
Glossary
Data domain: whether it is a CS structure or bsstructure software, pages are used to display and maintain data operations, such as adding, modifying, and deleting data. Each page has several data modules. For example, a list page usually has only one grid control. Using batch data display is equivalent to a data field. There may also be a tree control, used for grouping display, which can also be considered as a data field. There are also the document page, the main list (two data fields), the main table + four tabs (five data fields ).
Business scenarios
A page or form is used to operate data, including adding, deleting, and modifying data. Some pages may have several new operations, such as the list of inspection modules in his software. There may be new inspections and new inspections. If you compare these two operations to two classes, the possibility of coupling between them is very small. It may be two sealing classes. But there are many common things between them, such as adding data. How can we distinguish the commonalities and personalities between them. Here we will introduce the third class, which is also the method for general decoupling, put the common things in the third class, and then reference them together.
The role of data domains is to integrate these operations and encapsulate them into a separate class to manage them.
Data domain operations
The following is a summary of all operations completed in a data domain.
L main operations
1.Load data and bind it to the control: Get DatasetOr datatableObject, bound to the gridDisplay controls.
2. perform data operations, such as ADD, modify, and delete operations, as well as some function operations (enter the Pinyin input code obtained by name to the pinyin code column ). During this period, a simple check is also conducted, for example, whether the mandatory field is empty. This is something to do at the interface layer.
3. After the data operation is complete, you also need to fill in some column values that do not need to be filled but must be filled in the UI Layer, such as ID serial number, creator, and creation time.
4. data Storage check, including data correctness check (whether the column value conforms to the column type) and data accuracy check (the column value complies with custom rules, for example, the document date cannot exceed the end of this month), data repeatability detection, etc;
Data deletion Detection: Check the data reference relationship.
5.Business detection, real industry business detection, just inherit the interface. This part will be the focus of future operations, because it involves the business needs of an industry and can be clarified in less than a year or two.
6. Obtain and save the generated synchronous SQL statement. This statement has the following business scenario: when the main detailed document is saved, all the detailed data may be deleted before all the new operations are performed. This operation is to obtain the SQL statement Delete from table_detail where danjuid = xxx.
7. Obtain the SQL syntax for data synchronization. This statement has a business scenario: when a document is added, the addition of another module may be triggered synchronously. This operation is used to obtain the SQL syntax of the operation.
8. Obtain the SQL Syntax of this module for saving
9. Data is truly saved, SQL statements are executed in batches, and transactions are used.
The above operation process is the process of extracting and displaying data from the database to the user, browsing and operating the data, and finally backfilling the data to the database. My idea is that developers only need to pay attention to two parts: one is the data binding dB field value on the UI Layer and the data collection before saving. The other part is the operation at the industry business layer.
Program Layered
LData Layer
This is nothing to say. It encapsulates some method sets related to DB operations, for example, using transactions for saving.
LUIControl Layer
Three projects are created here, as shown in-1.
Figure-1
Among them, the Navi. kernel. uilayer Project is a common method used by the webform and winform controls, such as permission and definition of various control parameters.
Navi. kernel. uilayer. webcontrols is a webform control set. It is not encapsulated because it is exposed. For various types of methods, we put them in several class files in different categories, and then pagebase uniformly calls their interfaces, as shown in-2.
Figure 2
Navi. kerncel. uilayer. winconrols is a set of winform controls that encapsulate some common controls.
LServiceLayer
This layer is mainly used to collect various methods, such as strings, dates, files, and DB operations. As shown in-3 and figure-4, two projects are created to load interfaces and object classes respectively.
Figure-3
Figure 4
When using these methods, I use the singleton constructor mode, as shown in-5.
Figure 5
LModelLayer
This is a detailed description. In my entire program, the model layer is a very important layer, because it runs through the entire program and plays an important role. The model layer contains two subclasses, winform and webform, which correspond to CS and BS software respectively.
On the one hand, it is responsible for calling the methods at the DB and service layers, which is equivalent to a set, as shown in-6 and Figure-7.
Figure 6
Figure-7
On the other hand, there are many modules in the UI Layer. For his software, there will be inspection tickets and checklists. I will assign them a model file to assist in UI Layer operations.
The model layer contains many methods, including loading data, saving data, and deleting data in the "data domain operations" step described above. -8
This is a module list page. If we want to read data from the database and load it to the specified control (not necessarily the grid control ). First, we create a class that inherits from the basemodel class, as shown in-9.
Then, we only need to configure some information in the constructor of this class, as shown in-10 and 11.
Figure-10
Figure-11
In the preceding figure, the attribute of the authorid series is to determine the module ID of the module. The unique variables of the module are identified throughout the system, And the listeventlevel is used to define the button event level on the toolbar of the List page, events are divided into three levels: the ancestor level. All modules can be used and the module level is used only by this module. The Custom Level is written in the industry business level (which can be self-coded for different industry businesses ).
The attributes of the listmaster series are various parameters required to define a data domain, such as SQL statements, DB tables corresponding to the data domain, and data storage locations (including databases and XML files ), if the data field has data operations, you also need to define whether to enable the primary key and set how to obtain the primary key. There are no insert or update statements, because the insert or update statements are automatically generated based on the row status when the database is submitted, and logs are generated using lognet for ease of viewing. In Figure 11, additional attributes are set, such as the column title of the grid control.
After setting the above attributes, the non-UI part of the module has been basically completed. Next let's look at what the UI Layer is doing? -12
Figure-12
Declare a mode layer that only belongs to this module.
First, load the page title, then load the toolbar data (you can configure it by yourself, you can also set permissions to determine whether the button is displayed and available, accurate to the individual), and finally load the list. the master data field data is displayed using the grid control.
Through the use of the model layer, the pressure on the UI Layer is reduced a lot. You only need to call the properties already configured in the model layer. Isn't it easy! Let's take a look at the data storage section, as shown in-13.
Figure 13
It consists of three parts: data collection, data verification, and data storage. What the UI Layer needs to do is to collect data, and the verification part is completed through the configuration file, for example, whether the data is repeated or accurate. Of course, some special verifications must be written by yourself, the configuration file is only responsible for regular verification. -14
Figure 14
L common Layer
This layer is generally used to compile common functions, such as search, advanced search, positioning, and statistics, as shown in-15.
Figure-15
The "Search" function is used to create a class file and inherit from the basemodel class (because it is a set of service methods, which is equivalent to a proxy ), call the method to open the frmfind page in the class file, as shown in-16.
Figure 16
When we use the "Search" function in the business module, we only need to writeCodeYou can, as shown in-17.
Figure-17
L Business Layer
This layer is put at the end because it is important and unimportant. It is important because it is the flesh and blood of the entire system. Without it, the entire framework is a pile of skeleton, which does not play any role. It is used to fill in the business functions of the system, it only needs to inherit some interfaces in the service layer. As mentioned above, we want to rewrite the new operation and write it here. -As shown in Figure 18, a module corresponds to a business-layer file.
Figure-18
Answer
L is there any source code? I hope to provide it.
Sorry, for some reason, the source code is lost. If you have any questions, you can leave a message at any time.