Lightweight road CYQ.Data gorgeous upgrade data layers V1.3 born (e)

Following Previous: CYQ.Data Road, lightweight data-tier application examples of articles (four)  after, interested readers can rest assured that the use and application or practice!

 

However, after the stable version, it also had a gorgeous upgrade, upgrade recorded as follows:

05233152_5gRF.gif
1: MAction: increase RESETTABLE Function
2: MAction: increases when the Update / Insert / Fill / ResetTable failure, automatically calls the Close ()
. 3: MAction: Review Fill method: before the return failure if a plurality of recording the time of filling, into returns the first record
4: MAction: increasing SetAutoPrefix method controls a plurality of prefixes can pass
5: MAction: Update open automatically obtain the control value function method

6: MAction: DataSQLHelper off property returns
7: MProce: produce new class, for storing during operation
8: outPutData: new enumeration procedure stored increased export

9: outPutData: a method for increasing the direct execution ExeCreateProc generating paging stored procedure

 

For the following updates into Description:

 

1: increase ResetTable functions : to reduce the number of New MAction

The same function, if you use more than one table to switch to a query, you might every time a New MAction, so in order to reduce the number of New, more function, look at the following usage:

05233152_5gRF.gif
        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.Clo
se();
        }

 

The user name after acquiring the data, accessible to the user ID, and then switch to the message a message table is filled according to the data taking the first user ID.

 

2: increases when Update / Insert / Fill / ResetTable failure, automatically calls the Close (): The improved dot code can be saved

We look at the sample code section Online:

05233152_5gRF.gif
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 " );
        }
        
the else
        {
            lbMsg.Text 
= " wrong password! " ;             action.Close ();         }     }  


 

After no improvement, you will find that the code will appear twice action.Close ();

Of course, if there is no middle Response.Redirect appear so suddenly turn, you can Action.Close () to put the final surface, so only one.

However, after a little improvement, even if there Response.Redirect, you can also omit one of the following action.Close () a.

---- row is omitted, it not seems BAD, if in a multiplex can be used if the branch, the effect will become quite obvious, such as:

05233152_5gRF.gif
Action MAction  = new new  MAction (TableNames.Users); IF  (action.Fill ( . 1 ))         { // N is omitted lines IF  (action.Insert ())             { // N is omitted lines IF  (action.Update ())                 {                     action.Close ();                 }             }         }  
        


           

            

                

                




 

In this case, you do not focus on failure to close the database link, you only need to focus on success, closed on the line,

Of course, intermediate to a break / return / continue; have to pay attention point.

 

There are: 3: MAction: Modify Fill method when multiple records returns a failure, changed returned the first record

Prior to this release, after Fill finished, if multiple records, returns false, this revision to return the first record:

So, you can even get so filled with the last record:

05233152_5gRF.gif
            MAction action  =   new  MAction(TableNames.Message);
            
if  (action.Fill( " UserID=2 order by id desc " ))
            {
                action.SetTo(txtBody);
                action.Close();
            }

 

Due to the combination of Fill is where the statement, you can increase the order by the end get to sort records.

 

4: MAction: increase SetAutoPrefix method can pass multiple controls prefix
for automatic control value, the previous version existed, but did not introduce usage-related, but only for one version control prefix values such as:

05233152_5gRF.gif
            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 control txt + field name; however, we normally prefix controls are varied, so after the improvement:

05233152_5gRF.gif
            MAction action  =   new  MAction(TableNames.Message);
            action.SetAutoPrefix(
" txt " , " ddl " , " lab " );
            
if  (action.Insert( true ))
            {
                action.Close();
            }

The control system can automatically obtain the value of the interface above three kinds of combinations of the prefix. At the same time removed AutoPrefix property.

 

5: MAction: Update Method open automatically takes control value function.

Prior to this release, the Update method does not open automatically value function, improved after opening the automatic function value Update method, such as:

05233152_5gRF.gif
            MAction action  =   new  MAction(TableNames.Message);
            action.SetAutoPrefix(
" txt " , " ddl " , " lab " );
            
if  (action.Update( " id=1 " , true ))
            {
                action.Close();
            }

 

 

6: MAction: off property DataSQLHelper return

Before this release, you can get to the bottom of the object SQLHelper by action.DataSqlHelper.

Before opening in order to open the underlying storage process. Since the production process of the stored procedure MProc specialist, so the property closed.

 

7: MProce: a new class of production, storage process operation specialist
uses simple follows:

05233152_5gRF.gif
        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: newly added to the stored procedure to enumerate derived
by this method, generate stored procedures 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));

Description:

TableType.P: Stored Procedure enumeration
TableType.U: Table enumeration
TableType.V: view Enumeration

The enumeration procedure to generate stored as follows:

public   enum  ProcNames
{
    GetMessageList,
    GetUserList,
}

 

9: OutPutData: a method for increasing ExeCreateProc directly 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));

Generate stored procedures will be executed directly to the database, you do not have to copy the database to be executed.

 

OK, this upgrade introduces this end, welcomed the discussion, using the comments! ! !

Last offers gorgeous upgraded version V1.3 Download: Download [size: 60K unencrypted did not confuse restriction, ease of use, can be directly used Reflector.exe View Source]

Reproduced in: https: //my.oschina.net/secyaher/blog/274055

Guess you like

Origin blog.csdn.net/weixin_33937499/article/details/91966940