Cyq. Data quick development-Principles of UI (assignment, value, and binding)

Source: Internet
Author: User
Tags tojson

Last night, the garden monkey asked me a few small questions about how to use cyq. Data. After a simple answer, he said,"Mom no longer has to worry about my learning ."I hope the framework will be better and better..

 

Besides technical communication, Both partiesI also had bilateral friendly exchanges on the issue of life and S. Finally, the monkey sent a foreign sex website, which I highly appreciated for sharing.

 

Well, let's get to the point and talk about some technical questions:

The usage of cyq. Data is related Article After the introduction, we will not introduce it again.
This section describes the implementation principles. For specific source code, you can download the open-source v4.0 to learn.
: Http: // Www.cyqdata.com/download/article-detail-426

 

 

Cyq. DataSupported UI: webform and winform and implementation principles:

 

Two internal classes and one interface involved:

 

 

Mactionui:

It is mainly used to operate a single row of data. It assigns a single row of data to the webform server control or winform control.

 

The function is to assign values to a single UI control.Added setall, which allows you to assign values to controls in batches.

ExampleCode:

Using (Maction action = New Maction ( " Users " ))
{
If (Action. Fill (ID ))
{
Action. settoall ( This );
}
}

 

In this case, the settoall (this) line will kill the previous N-plus code similar to the following:

Txtid. Text = xxx. Value 1;
Txtusername. Text = xxx. Value 2;
Txtfullname. Text = xxx. Value 3;
Txtemailname. Text = xxx. Value 4;
Txtpassword. Text = xxx. Value 5;
... N are omitted .....

 

In addition, even if you add or remove field display items, you only need to remove the control on the page without modifying the code.

 

So what is the implementation principle of this function?

In fact, it is "this", which is equivalent to transmitting to the current page. As long as the child control of the page is traversed, the value can be set cyclically according to the "three letter prefix" + field name as agreed.

 

Mbindui:

Mainly for multi-data operations, bind multi-row data to list controls such as the gridview, repleater, and dropdownlist of webform or winform.

 

Its function is actually very simple. It is to bind a list control. You can understand the following code:

Public Static Void BIND ( Object CT, Object Source)
{
If (CT Is Gridview)
{
(Gridview) CT). datasource = source;
(Gridview) CT). databind ();
}
Else If (CT Is Repeater)
{
(Repeater) CT). datasource = source;
(Repeater) CT). databind ();
}
Else If (CT Is Datalist)
{
(Datalist) CT). datasource = source;
(Datalist) CT). databind ();
}
Else If (CT Is DataGrid)
{
(DataGrid) CT). datasource = source;
(DataGrid) CT). databind ();
}
Else If (CT Is Win. DataGrid)
{
(DataGrid) CT). datasource = source;
}
Else If (CT Is Win. datagridview)
{
(System. Windows. Forms. datagridview) CT). datasource = source;
}
Else If (CT Is Basedatalist) // Base Class Processing
{
(Basedatalist) CT). datasource = source;
(Basedatalist) CT). databind ();
}
}

You can set the value of the data source through multiple branches. The classic usage is as follows:

Using (Maction action = New Maction ( " Users " ))
{
Action. Select (). BIND (gvusers );
}

 

Of course, this is not the best way to use the list control, because the binding of the list control, it is best to bind after the database link is closed, the best performance statement should be:

Mdatatable DT;
Using (Maction action = New Maction ( " Users " ))
{
Dt = action. Select ();
}
DT. BIND (gvusers );

Iuivalue:

This is an interface that supports custom controls or third-party controls. You can also use the mactionui function as long as the control implements interfaces.

Three attributes: whether the control is enabled, the Control ID, and the control value. This is generally used only by custom controls compiled by you.

 

The UI is almost mentioned here, and the implementation is still simple, but the idea is accumulated from years of experience in step-by-step optimization.

Traditional non-UI development mode:

 

Apart from webform, there are many development modes, But what keeps changing is that HTML elements are submitted to the server through get, post, and other methods.
Among these interactions, JS is the most common. JSON is a popular interactive format.

 

 

Therefore, cyq. Data also takes into account the rapid development mode of this development mode and implements simple backend encoding through the getfromjson and tojson functions:

The sample code is as follows:

String Result;
Using (Maction action = New Maction ( " Users " ))
{
If (Action. Fill (ID ))
{
Result = action. Data. tojson ();
}
}
Response. Write (result );

Return JSON to the client, which is parsed and displayed by the client Js.

 

Same return batch values:

Bool Result;
Using (Maction action = New Maction ( " Users " ))
{
Action. getfromjson (request [ " JSON " ]);
Result = action. insert ();
}
Response. Write (result );

Data in JSON format is submitted by the client JS, while the backend is fixed and automatically parsed and stored in the database, which is quite convenient.

OK. This section will introduce you here. Thank you for watching it.

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.