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.