ArticleDirectory
- 1. Design Database Table Design
- 2. Object ing ORM Mapping
- 3. Interface and service implementation for data read/write interfaces and Implementations
- 4 ASP. NET page layout and programming ASP. NET page layout design and coding
After explaining the previous six articles, the basic theory has been introduced. This article carries out practical exercises to discuss how to develop a complete asp from the beginning.. NET page, read and write data, and set the business logic.
1. Design Database Table Design
The company Table stores the company instance in the system, indicating the business entity. Its table structure is shown in the following script.
Create Table [DBO]. [Company] ([COMPID] [ Numeric ] (18, 0) Identity (1, 1) Not Null , [Parentcompid] [ Numeric ] (18, 0)Null , [Comptypeid] [ Numeric ] (18, 0) Not Null , [Compno] [ Varchar ] (20) Not Null , [Compname] [ Varchar ] (50) Not Null , [Corporation] [ Varchar ] (20) Null , [Corpmobile] [ Varchar ] (20) Null , [Corptel] [ Varchar ] (20)Null , [Address] [ Varchar ] (100) Null , [Tel1] [ Varchar ] (20) Null , [Tel2] [ Varchar ] (20) Null , [Fax] [ Varchar ] (20) Null , Constraint [Pk_tcompany] Primary Key Clustered ([COMPID] ASC ) With (Pad_index = Off , Statistics_norecompute = Off , Ignore_dup_key = Off , Allow_row_locks = On , Allow_page_locks = On ) On [ Primary ]) On [ Primary ]
2. Object ing ORM Mapping
Open llbl Gen, connect to the database, update the entity, and map the company table above to the entity companyentity. When designing a field name, it is best to name it with concise and readable words, which can enhance the readability of attributes mapped to objects.
If the table is associated with the table, llbl Gen automatically generates the association between the tables.
3. Interface and service implementation for data read/write interfaces and Implementations
This step is automated without additional mental activities. Open the template interface. CST and manager. CST with code Smith, select the table object as company, and generateCodeCopy the code to the project of Visual Studio.
Obtain the two templates mentioned above in the source \ Maintenance \ template path of the project to generate the data read/write interface and implementation code.
4 ASP. NET page layout and programming ASP. NET page layout design and coding
Add an ASP. NET page to a web project named company. aspx. We recommend that you name the folder, file name, and page type name of the web project in lower case. To entrypagebase, I add a toolbar in the first part of the page to carry the tools in the toolbox for data browsing and deletion. In other places, the layout is arranged in formrow mode.
Formrow will allocate an average width for its items, so it is best to place the same items in each formrow to make the interface layout look beautiful and tidy.
The background code of ASP. NET looks like this. All the codes are listed here for your reference.
[Function ( "Aiithd" , "~ /Module/company. aspx" )] Public Partial Class Company: entrypagebase { Protected Override Void Pageloadevent ( Object Sender, eventargs e ){ If (! Ispostback) {transactiontype = entitytype. companyentity; ddlcompanygroup. initializevaluelistfromenum (9 );} Base . Pageloadevent (sender, e );} Public Override Entitybase2 loadentity ( String Refno) {icompanymanager manager = clientproxyfactory. createproxyinstance <icompanymanager> (); companyentity customer = manager. getcompany (convert. toint16 (refno )); Return Customer ;} Public Override Void Deleteentity (entitybase2 entity) {companyentity user = (companyentity) entity; icompanymanager manager = clientproxyfactory. createproxyinstance <icompanymanager> (); manager. deletecompany (User );} Public Override Void Saveentity (entitybase2 entity) {companyentity user = (companyentity) entity; icompanymanager manager = clientproxyfactory. createproxyinstance <icompanymanager> (); manager. savecompany (User );}}
First, assign a function code to the page, such as the aiithd of the page, and then set the URL attribute. Both are appended to the page features at the same time.
[Function ("aiithd ","~ /Module/company. aspx ")]
There are some shortcomings here. So far I have not found the page file based on the ASP. NET page type. ASP. NET requests are sent to the server for execution after the aspx file is typed in the browser. Therefore, if you can find this method, the URL settings here can be omitted.
Second, specify transactiontype = entitytype. companyentity, which is used to specify the object of the current page as companyentity and perform read/write operations on it. This attribute is required when it is bound to page-related data and written back to the database. Three template methods are followed. loadentity is used to load company entities, deleteentity is used to delete objects, and saveentity is used to save the modified objects. All three methods are override, which is called by the page base class.
Finally, run the function code aiithd to see how it works. In the upper-right corner of the page, enter the function code and click go.
For data binding, all the secrets are hidden in the page file. I use company no as an example. Please refer to its page file.
<Ext: textbox ID= "Tbxname" Runat= "Server" Label= "Company no" Databindingstring= "Companyentity: compno"></Ext: textbox>
Its databindingstring attribute binds the object property to this control when reading data. It reads the value while saving the data, writes it back to the object, and saves it to the database, this can reduce a lot of repeated code.