CYQ. Data lightweight Data layer road to gorgeous upgrades V1.3 (5)

Source: Internet
Author: User

Following the previous article: CYQ. Data simple Data layer path application example (4), interested readers can safely use and apply or practice it!

 

However, after the stable version, I performed another gorgeous upgrade. The upgrade record is as follows:

1: MAction: added the ResetTable function.
2: MAction: automatically calls Close () When Update/Insert/Fill/ResetTable fails ()
3: MAction: Modify the Fill method. If multiple records have been filled before, the system will fail to return the first record.
4: MAction: added the SetAutoPrefix method. Multiple Control prefixes can be uploaded.
5: MAction: The Update method enables automatic control value acquisition.

6: MAction: Disable the returned result of DataSQLHelper.
7: MProce: New Production Class for Stored Procedure operations
8: OutPutData: new export of Stored Procedure Enumeration

9: OutPutData: added the ExeCreateProc method to directly execute the paging storage process.

 

The following is a new description:

 

1: added the ResetTable function:Reduce the number of New MAction

In the same function, if you want to use multiple tables to switch queries, you may need a New MAction each time. Therefore, to reduce the number of New tables, you need to add this function. The usage of this function is as follows:

MAction action = new MAction (TableNames. Users );
If (action. Fill ("UserName = 'cyq '"))
{
Action. SetTo (labUserName );
Int id = action. Get <int> (Users. ID );
If (Action. ResetTable (TableNames. Message ))
{
If (action. Fill ("UserID =" + id ))
{
Action. SetTo (labBody );
}
}
Action. Close ();
}

 

After obtaining the data according to the user name, obtain the user ID, switch to the message table, and fill in the first data according to the user ID.

 

2: When Update/Insert/Fill/ResetTable fails, Close () is automatically called ():Code can be saved after improvement

Let's take a look at the sample code login in the previous section:

Protected void btnLogin_Click (object sender, EventArgs e)
{
MAction action = new MAction (TableNames. Users );
If (action. fill (string. format ("UserName = '{0}' and Password = '{1}'", txtUserName. text. trim (), txtPassword. text. trim ())))
{
Session ["ID"] = action. Get <int> (Users. ID );
Action. Close ();
Response. Redirect ("Default. aspx ");
}
Else
{
LbMsg. Text = "incorrect user password! ";
Action. Close ();
}
}

 

After no improvement, you will find that the action. Close () appears twice in the Code ();

Of course, if there is no such sudden turn in the middle of Response. Redirect, you can put Action. Close () to the end, so there is only one.

However, after a small improvement, even if Response. Redirect exists, you can omit the following action. Close.

---- Just omit a row. It seems that it is not very good. if you use it in multiple if branches, the effect will become quite obvious, for example:

MAction action = new MAction (TableNames. Users );
If (action. Fill (1 ))
{
// N lines of code are omitted
If (action. Insert ())
{
// N lines of code are omitted
If (action. Update ())
{
Action. Close ();
}
}
}

 

In this case, you do not need to pay attention to closing the database link when the database fails. You only need to pay attention to closing the link when the database is successful,

Of course, you have to pay attention to break/return/continue in the middle.

 

3: MAction: Fill modification method: YesWhen multiple records existFailed to return, changedReturns the first record.

Before the current version, if multiple records exist after Fill, false is returned. The first record is returned for this modification:

Therefore, you can even fill in to obtain the last record as follows:

MAction action = new MAction (TableNames. Message );
If (action. Fill ("UserID = 2 order by id desc "))
{
Action. SetTo (txtBody );
Action. Close ();
}

 

Because the where statement is combined after Fill, you can add order by to sort and obtain the last record.

 

4: MAction: added the SetAutoPrefix method,Multiple Control prefixes can be uploaded.
The previous version already exists for the automatic value of the control, but does not introduce the related usage. However, the previous version can only have the following prefix values for one control:

MAction action = new MAction (TableNames. Message );
Action. AutoPrefix = "txt ";
If (action. Insert (true ))
{
Action. Close ();
}

 

The above operation can automatically obtain the value of the txt + field name control; however, in general, the control prefix is diverse, so after improvement:

MAction action = new MAction (TableNames. Message );
Action. SetAutoPrefix ("txt", "ddl", "lab ");
If (action. Insert (true ))
{
Action. Close ();
}

The system can automatically obtain the control values of the three prefix combinations on the interface. The AutoPrefix attribute is also removed.

 

5: MAction: Update MethodEnable Automatic Control Value RetrievalFunction.

Before this version, the Update method does not provide the automatic value function. After the improvement, the automatic Value Function of the Update method is enabled, such:

MAction action = new MAction (TableNames. Message );
Action. SetAutoPrefix ("txt", "ddl", "lab ");
If (action. Update ("id = 1", true ))
{
Action. Close ();
}

 

 

6: MAction:Disable attributesReturned DataSQLHelper

Before this version, you can obtain the underlying SQLHelper object through action. DataSqlHelper.

Previously, it was opened to open the underlying layer to operate stored procedures. Because MProc professional users are produced to process the stored procedure, the attribute is disabled.

 

7: MProce: New Production Class,Stored ProcedureOperation professional
The usage is concise as follows:

MProc proc = new MProc (ProcNames. GetUserList );
Proc. AddParas (Users. ID, 1 );
GvProcUsers. DataSource = proc. ExeDataTable ();
GvProcUsers. DataBind ();

Proc. ResetProc (ProcNames. GetMessageList );
Proc. AddParas (Message. UserID, 1 );
GvProcMessage. DataSource = proc. ExeDataTable ();
GvProcMessage. DataBind ();

Proc. Close ();

 

8: OutPutData: new pairExport of Stored Procedure Enumeration
This method generates the Stored Procedure enumeration:

CYQ. Data. SQL. OutPutData write = new CYQ. Data. SQL. OutPutData ();
Response. Write (write. OutPutAllTableEnum (CYQ. Data. SQL. OutPutData. TableType. P, CYQ. Data. SQL. OutPutData. FiledDescriptionType. Sql2005 ));

Note:

TableType. P: Stored Procedure Enumeration
TableType. U: Table Enumeration
TableType. V: View Enumeration

For example, the storage process is enumerated as follows:

Public enum ProcNames
{
GetMessageList,
GetUserList,
}

 

9: OutPutData: added the ExeCreateProc MethodDirectly execute the generated paging Stored Procedure.

CYQ. Data. SQL. OutPutData write = new CYQ. Data. SQL. OutPutData ();
Response. Write (write. ExeCreateProc (CYQ. Data. SQL. OutPutData. FiledDescriptionType. Sql2005 ));

The generated stored procedure is directly executed in the database, and you do not need to copy it to the database.

 

OK. This upgrade is over. Welcome to discuss, use, and leave a message !!!

Finally, the upgraded version V1.3 is provided. Download: Click to download [size: 60 K unencrypted, unlimited, available for easy use, you can directly use reflector.exe to view the source code]

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.