Application of MVC architecture in C # .NET
Keyword
Data sets, controls, data bindings, MVC structures.
description
When the software is developed, the class passes the data, namely: Database -Component - DataSet - Class - Viewer (Show Control), which has to bring a lot of trouble when the data and class exchange have to write a lot of code programming (can The maintenance is greatly reduced). This paper introduces this issue with data set and data binding to solve this problem in conjunction with the MVC three-layer structure example.
Data binding
Data Binding is a mechanism provided by Microsoft .NET controls that enable controls directly to data sources (such as: DataSet, DataTable, etc.) through this mechanism.
The following image shows the fields of the data set to the TextBox control.
Multi-level software architecture
Multi-level software can improve software collaborative development efficiency, and enhanced software portability, MVC is a relatively mature three-layer architecture.
Application of data binding in multi-layer software architecture
Below is a structural diagram of the sample program, visible data passes directly through the data set through components and controls, and the data set is directly binding to the control, namely: Database - Component - DataSet -viewer. The user activates the method in the corresponding component by triggering the control on the form, the component completes the service rules and database processing of the system.
The steps developed are as follows:
1 Establish a data set;
2 Establish a component class and define various methods (business rules, etc., you can define the framework when you develop, and the components and display are synchronized;
3 New form, join the control and bind the dataset, if you need a binding field, you can use the wizard (recommended) to generate and bind, the steps that use the wizard binding are as follows:
1) Add new item - Data Form Wizard - Select "Single Records in a Single Control when selecting the display style - Press" Finish ";
2) Adjust the interface (button, text, location, etc.);
4 Write (Modify) Button or other controls of other controls corresponding event; (eg, the following code completes "loading" data)
Private void btnload_click (Object Sender, System.EventArgs E)
{
Component1 comp = new component1 ();
System.Data.DataSet DS = new system.data.dataset ();
DS = this.objdataset1.clone ();
DS = comp.exportemployee ();
Objdatats1.clear ();
ObjDataSet1.merge (DS);
}
Sample program
applicability
Applicable to an application system based on a document (data sheet).