Six Form Designer of data solution development Diary of Knowledge Management System

Source: Internet
Author: User

Knowledge management system data solution has fiveArticleIntroduce it. You can find the previous article through the following connection.

Knowledge management system data solution one of the R & D diaries Scenario Design and requirements list

Knowledge management system data solution R & D diary 2 Application Series

Knowledge management system data solution development diary 3 Documentation Solution

Knowledge management system data solution development diary-4-segment data Solution

Knowledge management system data solution 5-page download, conversion, import

Every article tries to analyze the purpose and design ideas of this system from a perspective. AsSource codeThere is no special difficulty. The key to the problem is the idea. It is easier to implement it by finding a suitable solution. This article describes the main content of the Form Designer.

The Form file generated by the designer can be saved in two ways, one is the sourceCodeMethod, C #, VB. NET code format, and XML format. Here, the XML format is used to save the Form Design format. If you are not familiar with this, read the article "enterprise management software development tools based on Form Designer" to learn more.

In the development of Windows Forms, The bindingsource control acts as a bridge between data and controls, and is a two-way data binding. When learning ASP. NET, this sentence cannot be solved. What is the difference between two-way data binding and one-way data binding. To put it bluntly, two-way Data Binding allows users to modify the data in the control, re-write the data to the bound data source, and save the data in the form, you can save the modified data. Two-way Data Binding can save a lot of data binding code. Imagine that when I was just learning programming, I often wrote such code.

  protected   override   void  onload () {txtusername. TEXT = user. username; txtemal. TEXT = user. email ;}  protected   override   void  onclosing () {user. username = txtusername. text; user. emal = txtemail. text ;}

When the form is opened, You need to bind data from the data entity type to the control. When the form is closed, the control value is written to the data entity type. If there is no two-way data binding, such code will be repeated in large quantities in the interface.

 

First, read a single data table. For example, read only one table from the purchase order puordh. In the Form Designer, there are two flexdatatable controls used to obtain the data source. Its name is the table name in the database, and its SQL attribute is the SQL statement for reading data. For example, a table is puordh (purchase order ), you need to write the SQL attribute for it as select * From puordh. Theoretically, the SQL attribute does not need to be written after the table name is known, because the default SELECT statement can be generated. For efficiency consideration, the SQL writing can be simplified, for example, in the form above, it only reads the Ref No of puord. in this case, if the automatically generated SQL statement is still select * From puordh, the efficiency will be greatly reduced, and other unnecessary fields will be read to the memory. Therefore, the SQL attribute of flextdatatable can be used to optimize SQL Performance. When its value is null, the Form Designer automatically generates select * From puordh.

 

Let's take a look at the reading of the Master/Slave table. As shown in, the main table puordh and the detail table puordd have a one-to-multiple relationship in the database. At this time, the key code for data binding is the three lines

 
This. Bsh. datasource =This. Dataset;
 
// This. BSD. datasource = This. dataset;This. BSD. datasource = bsh;This. BSD. datamember ="Fk_puordd_puordh";

The data in the table header is still dataset. In the initial test, the data is read to dataset Based on the flexdatatable table name and its SQL attributes. If the data in the slave table is dataset, there is no error, but the data associated with the master table and the slave table is not displayed normally. It selects all the slave table data. Therefore, the following two lines of code are the key to binding slave table data. When the Form Designer generates the Cs source code, it must generate the correct master-slave data link binding code.

 

XSD is the preferred solution for generating master-slave data relationships. refer to the following call code to generate an XSD file containing the relationships.

 String Connectionstring = "Data Source = (local); initial catalog = emp5; Integrated Security = sspi; persist Security info = false; packet size = 4096" ; String Destinationfile = path. Combine (appdomain. currentdomain. basedirectory, xsdname); List < String > Tables = New List < String > (); Foreach (Icomponent compIn Host. Container. Components ){ If (Comp Is Flexdatatable) {tables. Add (Comp. Site. Name) ;}} datasetgeneratorform dlgxsd = New Datasetgeneratorform (connectionstring, destinationfile, False , "CS" , Tables); dlgxsd. generatexsdsource ();

The Form Designer obtains the relationship between the table and the table from the generated XSD file to generate the data binding code for the master-slave table mentioned above.

 

Codedom is the preferred Code Generation Technology for the Form Designer to generate code. This is mainly because it can generate both C # and VB. NET sets of code with a set of code. This flexibility is much better than the combination of hard-coded strings. Sample Code:

  // This. dataadapter = da;  codevariablereferenceexpression da =  New  codevariablereferenceexpression ( "da"  ); codepropertyreferenceexpression thisda =  New  codepropertyreferenceexpression ( New  codethisreferenceexpression (),  "dataadapter" ); codeassignstatement AS1 =  New  codeassignstatement (thisda, DA ); method. statements. add (AS1); 

In order to write a value assignment statement, four lines of code are used, and the target code generated by codedom cannot be seen during debugging. This is similar to the experience of debugging SQL statements with parameters. You cannot know the final appearance of the SQL statements to be sent to the server. Fortunately, with msdn and a large number of online resources, you can easily obtain how to express a C # statement with codedom. In most cases, you have written the codedom statement correctly. The running result is correct. Microsoft is so amazing that it has created codedom, a powerful code generation technology.

 

Let's take a look at the code for interoperability between forms. To open a form, you can use this statement.

= Open ("purchase") or = open ("purchase", this)

The open method with a parameter is combined into a purchase using the parameter as the XML file name. XML string, which is used to search for purchase in the specified directory of the system. the XML form Definition Format File is read and converted to the form type and displayed. The open method with two parameters will find the purchase in the directory specified by the system. DLLProgramSet file, reflecting its type members, called and displayed. There is also an agreement here that the source code file generated by the Form Designer contains only one type definition and is compiled by codedomprovider to generate the Assembly file of the form.

Continue to look at the form designed by the Form Designer, and write the click events of several other buttons.

The Save button click event is written as: = save ();

The delete button click event is written as: = Delete (bsh, BSD );

The method for creating a button's click event is: = new (bsh, BSD );

In this case, you do not need to specify a primary or foreign key or the association between the table and the table. Therefore, these are automatically determined by the background program. This is also inefficient. The Data Reading operation reads data into a dataset, and then allocates and binds the data according to the flexdatatable table name. The save operation writes the data back to the database and determines whether the data in the dataset changes, this process of writing data back to the database is very inefficient. Of course, in most cases, it is used to view the data in the database, rather than editing the data. According to this standard, the Form Designer has also achieved its goal.

 

By integrating these technologies, the development of the Form Designer is completed. When I think about these relationships, they are usually messy and incomplete. the design process is also the process of code evolution and adjustment of ideas. Maybe you don't know what I'm talking about here. Maybe you have a better implementation method.

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.