Serial: (b) Gradual, through the XML configuration, the implementation of common to WinForm (. Net), WebForm (Asp.net+jquery+easyui) forms, reports--principle

Source: Internet
Author: User

Serial: (ii) Progressive, through XML configuration, to achieve common use in WinForm (. Net), WebForm (Asp.net+jquery+easyui) forms, reports--Principle

Yangtze River tributary

This principle applies to the CSof Window Form and also to the BSof ASP .

Before describing the principle, let's look at an example of a traditional ORM writing code.

Entity Mappings


Now many architectures implement ORM, to dynamically generate code, to achieve data enhancement, deletion, change, check the function.
The mapping of entities is mapped by code, and whether an XML file can be used to configure the mapping of instances, the answer is yes.

Code Mappinghere, first look at the primary Key ID table Test_entityaccessorm has two fields DM, MC represents code, Name, table field and entity mapping code implementation way.

( Note: Writing code is not our intention, we are going to discard the code, the programmer is to not write code or write less code!) )

Using system;using webmis.data.entityaccess;using Webmis.data.entityaccess.mapattribute;namespace webmis.data.entityaccess.test{///<summary>///entity mappings. </summary>//Describes the table name of the map, the primary key (the primary key can be multiple), such as ("MyTable", "Id,no") or ("MyTable", "ID", "no"), can be written on the class declaration, can also be written on the parameterless public constructor, and the class precedence. [WebMIS.Data.EntityAccess.MapAttribute.TableMap ("Test_entityaccessorm", "ID")] public class Entitymapbyauto: Webmis.data.entityaccess.entityautomap{private long _id;//idprivate string _code;//code private string _name;//Name//[ WebMIS.Data.EntityAccess.MapAttribute.TableMap ("Test_entityaccessorm", "ID")] public Entitymapbyauto () {}[ WebMIS.Data.EntityAccess.MapAttribute.ColumnMap ("ID", System.Data.DbType.UInt32)]public long id{get{return _id;} set{_id = value;}} [WebMIS.Data.EntityAccess.MapAttribute.ColumnMap ("DM")]public string Code{get{return _code;} Set{_code = value;}} [WebMIS.Data.EntityAccess.MapAttribute.ColumnMap ("MC")]public string Name{get{return _name;} Set{_name = value;}} The following public field or property, without Columnmap, does not participate in the Ormpublic string abc= "";pUblic static string Abcd{get{return "ABCD1";}}} 

So, Specify the table and primary key through the attribute class WebMIS.Data.EntityAccess.MapAttribute.TableMap, specifying the corresponding database table fields and properties by WebMIS.Data.EntityAccess.MapAttribute.ColumnMap Mapping relationships. You can also find similar implementation principles from the VS-bring Entity Framework EF.

XML mappingWhat we are going to do here is to configure the mapping of the table fields to the entities through the XML configuration file, without writing how the code is implemented. Such benefits, only need to change the configuration file, no need to compile and release the deployment program, flexible and convenient.

In particular, it is important to note that theXML<Field> node <LD> represents the ID property of the control in Winform/webform or the name property of the standard HTML element,<name > represents the field name specified in Select .

and also note that: < Field > definition,<LD> to be the same as the control or element Id/name property in the UI (case-sensitive),<Name > is a field that is written out in the <Select> element, and is case-sensitive.

<?xml version= "1.0" encoding= "Utf-8"? ><webmiscontrollerserializer xmlns:xsi= "http://www.w3.org/2001/ Xmlschema-instance "xmlns:xsd=" Http://www.w3.org/2001/XMLSchema "> <Controller> <!--Note that the field in select is case- So the name node in field, to be the same as--<select>select ID, DM,MC from Test_entityaccessorm</select> <tablename&gt ;test_entityaccessorm</tablename> <PrimaryKey>ID</PrimaryKey> <primarykeyvalue/> <upd Atewhere/> <deletewhere/> <Fields> <Field> <!--ID node represents the ID property or label of the control in Winform/webform The Name property of the quasi-HTML element-<ID>ID</ID> <!--the name node represents the field name specified in the Select--<name>id</na me> <type/> <Save>false</Save> <Visible>false</Visible> </f ield> <Field> <ID>Code</ID> <Name>DM</Name> <align>right& Lt;/align> <width>30</width> <type/> <Save>true</Save> <Title> code </Title> <formtyp E/> <Visible>true</Visible> <Null>false</Null> <NullTitle> code cannot be empty, please lose Into!      </NullTitle> <sql/> <value/> <excel/> <userinputvalue/> </Field> <Field> <ID>Name</ID> <Name>MC</Name> <title&gt Name </Title> <NullTitle> name cannot be empty, please enter! </NullTitle> </Field> </Fields> </Controller></WebMisControllerSerializer>


Operating principle

Suppose you click the Edit button or double-click a row in the grid after selecting a row in the grid to pop up a UI interface (WinForm or Web page, developed by a consumer or UI Designer) that displays an edit. The resolver obtains the data source from the Select node in the XML configuration file, obtains a unique record by passing the primary key value, and maps the value of the record to the fields mapped by the XML configuration and with the UI To display the data that is read in the UI .

If you save the data, you first determine that NULL is not allowed to be null when the setting is False, prompts the user for input according to Nulltitle, and then determines that if an existence check is set, the specified check rule will be executed ... Finally, get the value of the field to deposit in the database. Values are typically entered through UI element controls, or can be obtained from Excel cells, or obtained through SQL, and priority is given to configuring Userinputvalue's key-value pair settings through the program.

In addition, the system will read the parameter values according to certain rules, such as ASP. URL parameter specified value, Session, application value.

    • Control files

The control file described by XML is called a control file, it can describe model definition, UI form, interactive callback function, query report data source, query filter condition field, etc.

    • Template file

user defined by themselves The page template of the UI interface, called the template file, is used to enter or display data from the specified data source in the XML. Of course, if you do not specify a template file, you can automatically generate pages based on the XML control file.

    • Parser

The control file, described by XML , is handled and controlled by the parser, which displays the data in the database in the UI View or stores the form data in the database according to the model description of the control file.

in the next section of this connection, the XML configuration file related classes will be implemented in C # and the source code .

Disclaimer: This article copyright for the Yangtze River tributary Zhou Fangyong All, if necessary to reprint, please retain the full content and source.

Yangtze River tributary [email protected] : winxin8001234567

Serial: (b) Gradual, through the XML configuration, the implementation of common to WinForm (. Net), WebForm (Asp.net+jquery+easyui) forms, reports--principle

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.