CYQ. The path to the lightweight Data layer of Data using the triqu MAction value assignment (14)

Source: Internet
Author: User

Previous Article: CYQ. Data lightweight Data layer road to use Article II. MAction Data Query (13)

 

Content Overview

This article continues with the previous article. This section describes all operations related to values and assignments.
1: Native: Like Row Operations
2: extended: GetFrom and SetTo operations on the UI
3. Extension: Get and Set for non-UI operations

 

The common part of the code is described in advance. We assume that a row of data is queried using the following method.

MAction action = new MAction (TableNames. Users );
If (action. Fill ("UserName = ' '"))
{
// Here is the value and value assignment operation today
Action. Close ();
}

 

 

I. Native operations

1. Get row data

MDataRow row = action. Data;

2: Use the field value

String username = row ["UserName"]. Value;
// When enumeration exists
String username = row [Users. UserName]. Value;

3: Index Value

String userName = row [1]. Value;

 

Ii. Extended UI operations

Note: Control IDs comply with naming conventions: three letter prefixes + Field Names

For example, the TextBox Control ID is txtUserName.
Txt (prefix) + UserName (database field name)

 

1: GetFrom: set the value from the control to the row.

Method prototype:
Public void GetFrom (Control ct)
Public void GetFrom (Control ct, object value)

Example 1:

Action. GetFrom (txtUserName );
// Equivalent
Action. Data ["UserName"]. Value = txtUserName. Text;

Example 2:

Action. GetFrom (txtUserName, "passing by autumn ");
// Equivalent
Action. Data ["UserName"]. Value = "passing by autumn ";

 

2: SetTo: Set the data in the row to the control.

Original method:
Public void SetTo (Control ct)
Public void SetTo (Control ct, object value)
Public void SetTo (Control ct, object value, bool isControlEnabled)

Example 1:

Action. SetTo (txtUserName );
// Equivalent:
TxtUserName. Text = action. Data ["UserName"]. Value. ToString ();

Example 2:

Action. SetTo (txtUserName, "passing by autumn ");
// Equivalent
TxtUserName. Text = "passing by autumn ";

Example 3:

Action. SetTo (txtUserName, null, false );
// Equivalent:
TxtUserName. Text = action. Data ["UserName"]. Value. ToString ();
TxtUserName. Enabled = false;

 

Iii. Scaling: Non-UI operations

1: Get data from the row

Native method: public T Get <T> (object key)

Example 1:

String userName = action. Get <string> ("UserName ");
String userName = action. Get <string> (Users. UserName); // when enumeration exists
// Equivalent
String userName = action. Data ["UserName"]. Value. ToString ();

 

2: Set the value from the variable to the row.

Native method: public void Set (object key, object value)

Example 1:

Action. Set ("UserName", "passing by autumn ");
// Equivalent:
Action. Data ["UserName"]. Value = "passing by autumn ";

 

Statement:

This section describes the basic operations on a single row of data.
For the following instructions: the content and name are still not fixed.

 

 

 

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.