To achieve rapid development and easy maintenance of the web framework, a series of efforts have been made.
Please refer to the initial ASP. NET page for Data OperationsCodeThe Basic Code of the page is as follows:
Protected VoidPage_load (ObjectSender, eventargs e ){If(! Ispostback) {loaddata ();}}Private VoidLoaddata () {userentity current = getuser ();
tbxname. TEXT = current. name; tbxremark. TEXT = current. remark ;} protected void btnsave_click ( Object sender, eventargs e) { int id = getqueryintvalue ( "ID" ); ixrolemanager menumanager = clientproxyfactory. createproxyinstance
(); xroleentity item = menumanager. getxrole (ID); item. name = tbxname. text. trim (); item. remark = tbxremark. text. trim (); menumanager. savexrole (item); extaspnet. alert. show (
"Save successfully" ) ;}
Load data in page_load and bind it to the control. In the Save button event, write the modified value to the database. Such code must be repeated many times in the project. The more data items, the larger the amount of code required. Is there a way to automatically bind data to the control and automatically write the data back to the database during storage? Enterprise Solution.
Enterprise Solution provides the same interface for operations such as inputting data and saving it to the database, allowing quick data operations. Taking notepad as an example, the final result is as follows:
The toolbar button is automatically loaded by the Framework. When your type is inherited from entrypagebase, it loads the toolbar for data operations.
[Function ("Aiitrl","~ /Module/Note. aspx")]Public Partial ClassNote: entrypagebase {Protected Override VoidPageloadevent (ObjectSender, eventargs e ){If(! Ispostback) transactiontype ="Blotterentity";Base. Pageloadevent (sender, e );}}
Override the pageloadevent method of the base class and pass in transactiontype. The framework uses transactiontype to identify the object on the interface and automatically implement read/write operations. The code for loading, saving, and deleting button events on the page is as follows:
Public Override Entitybase2 loadentity ( String Customerno) {iblottermanager manager = clientproxyfactory. createproxyinstance <iblottermanager> (); blotterentity customer = manager. getblotter (convert. toint16 (customerno )); Return Customer ;} Public Override Void Deleteentity (entitybase2 entity) {blotterentity user = (blotterentity) entity; iblottermanager manager = clientproxyfactory. createproxyinstance <iblottermanager> (); manager. deleteblotter (User );} Public Override Void Saveentity (entitybase2 entity) {blotterentity user = (blotterentity) entity; iblottermanager manager = clientproxyfactory. createproxyinstance <iblottermanager> (); manager. saveblotter (User );}
As you can see, this is all the code, the code for data loading, storage, and deletion, no data binding, and no data written back to the database. Finally, let's take a look at how the ASPX page achieves this goal.
<Ext: numberbox id = "textbox3" autofind = "true" runat = "server" label = "title" databindingstring = "blotterentity: ID"> </ext: numberbox>
Each extaspnet control that needs to bind data comes with a databindingstring attribute, indicating the property name bound to the object. This numeric input box is bound to the ID attribute of notepad. during design, you can specify it as follows:
The Web Framework supports fast data property binding. SpecifyProgramComplete path of the set.
<Deleetask>
<Add key = "assembly" value = "E: \ solution \ enterprise solution \ build \ Benin. businesslogic. dll"/>
</Appsettings>
Databindingstring editor reflects this Assembly and displays its attributes in listview for binding.
Using this model significantly reduces the amount of code. For example, if there are 100 controls, write 100 lines to read the value and bind it to the Code on the interface. When saving the control, write 100 lines of code and write the value back to the database. In this development method, data binding is automatic. You only need to specify the necessary attributes, and the framework will do other things for you. Let's take a look at the efforts behind implementation.
1. specify the type to be reflected. transactiontype ="Blotterentity"The role of this sentence is critical.
2. Bind The reflected value to the control. The code for assigning values based on reflection is as follows:
Reflectionhelper. setpropertyvalue (Textbox, targetproperty, OBJ );
This sentence is used to give a value. It converts the value obtained from the database to an available type and assigns it to the text attribute of textbox to complete data binding.
3. Write the value back to the database. Still reflection. Get the value and assign it to entity.
ObjectOBJ = reflectionhelper. getpropertyvalue (Textbox, targetproperty );ObjectConverted = convert. changetype (OBJ, type); reflectionhelper. setpropertyvalue (entity, arr [1], converted );
As shown in the code, get the value and write it back to the attributes of the object class. The key role is the databindingstring.
Let's take a look at the read and write operations on the master and slave tables, which is more complex than reading and writing from the preceding single table.
A sales order consists of a table header, a reference number, and a detailed multi-line material number. You can use the preceding method to read and write detailed data.
protected override void initnavigator (entitybase2 entity) {salesorderentity user = (salesorderentity) entity; grid1.datasource = user. salesorderdetails; grid1.databind () ;}
initnavigator is used to obtain the current object and bind the value to the details list. The implementation principle of the insert button is as follows. It takes the primary key value of the table header to the details page and uses hiddenfield to hide it in the page. In this way, this value is saved as the primary key when the details are saved. When the table header is returned, refresh the main table and obtain the value again. The value added to the detail table can be displayed.