VassistX 常用快捷方式

<summary> ... </summary>

///

/// <summary>

///  $end$

/// </summary>

------------------------------------------------------

if () { ... }

if

if ($end$)

{

        

}

------------------------------------------------------

if () { } else { ... }

ifel

if ($end$)

{

        

}

else

{

        

}

------------------------------------------------------

if (!Page.IsPostBack)

ifi

if (!Page.IsPostBack)

{

         $end$

}

------------------------------------------------------

if (String.IsNullOrEmpty(…))

ifs

if(String.IsNullOrEmpty($end$))

{

        

}

------------------------------------------------------

if(null==..){}

ifn

if($end$ == null)

{

        

}

------------------------------------------------------   

switch..case..

switch

switch ($end$)

{

         case "" :

                   //...

                   break;

         case "" :

                   //...

                   break;

         case "" :

                   //...

                   break;

         default:

                   //...

                   break;

}

------------------------------------------------------ 

for () { ... }

for

for (int i=0;i<$end$; i++)

{

        

}

------------------------------------------------------

foreach(){...}

fore

foreach (var item in$end$)

{

        

}

------------------------------------------------------

try { ... } catch {}

try

try

{

         $end$

}

catch(System.Exception ex)

{

         LoftE.Log.LogOut.Error(ex.Message,"");

}

------------------------------------------------------

try { ... } catch {} finally {}

try3

try

{

         $end$

}

catch(System.Exception ex)

{

         LoftE.Log.LogOut.Error(ex.Message,"");

}

finally

{

        

}

------------------------------------------------------

#region **

#

#region ** $end$ **

 

#endregion

------------------------------------------------------

Request.QureyString[]

qs

Request.QueryString["$end$"]

------------------------------------------------------

Request.Form[..]

qf

Request.Form["$end$"]

------------------------------------------------------

生成 GetModelByReader(DbReader) 函数

getmodel

#region ** DbReader转换为Model **

/// <summary>

/// 填充 Model

/// </summary>

private T GetModelByReader(DB_Readerdr)

{

         var model = new T();

         try

         {

                   //model.A =dr.GetInt32("A");

                   //model.B =dr.GetString("B");                                                               

                   //model.C =dr.GetDecimal("C");            

                   //model.D =dr.GetDateTime("D");                  

                   //model.E =dr.GetBoolean("E");                                                                     

         }

         catch (Exception ex)

         {

                   Log.Error(ex);

         }

         return model;

}

#endregion

------------------------------------------------------

执行存储过程

exec

var response = newWSResponse();

 

SqlCommand comd = newSqlCommand();

comd.CommandType =CommandType.StoredProcedure;

comd.CommandText ="$end$";

comd.Parameters.AddWithValue("@",);

comd.Parameters.AddWithValue("@",);

 

LogHelper.LogExecStoreProc(Log,comd.CommandText, comd.Parameters);

 

try

{

    NonQuery util = new NonQuery();

    util.ExecSP(comd);

            

         response.Message = "success";

         response.Result = WSResponseResult.Success;    

}

catch (Exception ex)

{

    response.Message = ex.Message;

    response.Result = WSResponseResult.Error;

}

 

LogHelper.LogFinishStoreProc(Log,command.CommandText, response);

 

return response;

------------------------------------------------------

执行存储过程,返回 Return Value 值

execret

var response = newWSResponse();

 

SqlCommand comd = newSqlCommand();

comd.CommandType =CommandType.StoredProcedure;

comd.CommandText ="$end$";

comd.Parameters.AddWithValue("@",);

comd.Parameters.AddWithValue("@",);           

 

SqlParameter p = newSqlParameter();

p.Direction =ParameterDirection.ReturnValue;

comd.Parameters.Add(p);

 

//记录日志

LogHelper.LogExecStoreProc(Log,comd.CommandText, comd.Parameters);

 

try

{

    NonQuery util = new NonQuery();

    util.ExecSP(comd);

        

         var returnValue = p.Value.ToString();

        

    if (returnValue == ??)

    {

        response.Message = "success";

        response.Result =WSResponseResult.Success;

    }else{

                   //...

                   //response.Message ="failed";

        //response.Result =WSResponseResult.Failed;

         }

}

catch (Exception ex)

{

    response.Message = ex.Message;

    response.Result = WSResponseResult.Error;

}

 

//记录执行结果

LogHelper.LogFinishStoreProc(Log,command.CommandText, response);

 

return response;

------------------------------------------------------ 

执行存储过程,返回 Output 值

execout

var response = newWSResponse();

 

SqlCommand comd = newSqlCommand();

comd.CommandType =CommandType.StoredProcedure;

comd.CommandText ="$end$";

comd.Parameters.AddWithValue("@",);

comd.Parameters.AddWithValue("@",);

 

SqlParameter p = newSqlParameter("@outvalue", SqlDbType.Int);

p.Direction =ParameterDirection.Output;

comd.Parameters.Add(p);

 

LogHelper.LogExecStoreProc(Log,comd.CommandText, comd.Parameters);

 

try

{

    NonQuery util = new NonQuery();

    util.ExecSP(comd);

         var outval = p.Value.ToString();

        

         if(outval == ??)

         {

                   response.Message ="success";

                   response.Result =WSResponseResult.Success;

         }

         else

         {

                   //...

                   response.Message ="failed";

                   response.Result =WSResponseResult.Failed;

         }          

}

catch (Exception ex)

{

    response.Message = ex.Message;

    response.Result = WSResponseResult.Error;

}

 

LogHelper.LogFinishStoreProc(Log,command.CommandText, response);

 

return response;

------------------------------------------------------

返回 Collection Response

collectionresp

var response = newCollectionWSResponse<T>();

List<T> list =new List<T>();

 

SqlCommand cmd = newSqlCommand();

cmd.CommandType =CommandType.StoredProcedure;

cmd.CommandText ="$end$";

cmd.Parameters.AddWithValue("@",);

cmd.Parameters.AddWithValue("@",);

 

LogHelper.LogExecStoreProc(Log,cmd.CommandText, cmd.Parameters);

 

DB_Reader dr = newDB_Reader();

try

{

         dr.ExecSP(cmd);

         while (dr.Read())

         {

                   var model =GetModelByReader(dr);       

                   list.Add(model);

         }

        

         if(list.Count>0)

         {

                   response.List = list;

                   response.Result =WSResponseResult.Success;

                   response.Message ="success";

         }

         else

         {

                   response.List = list;

                   response.Result =WSResponseResult.Failed;

                   response.Message ="failed";

         }       

                               

}

catch (Exception ex)

{

         response.List = list;

         response.Message = ex.Message;

         response.Result =WSResponseResult.Error;

}

finally

{

         dr.Close();

}

                  

LogHelper.LogFinishStoreProc(Log,cmd.CommandText, response);

                  

return response;

------------------------------------------------------

返回 Single Response

singleresp

var response = newSingleObjectWSResponse<T>();

 

SqlCommand comd = newSqlCommand();

comd.CommandType =CommandType.StoredProcedure;     

comd.CommandText ="$end$";

comd.Parameters.AddWithValue("@",);

 

LogHelper.LogExecStoreProc(Log,comd.CommandText, comd.Parameters);

 

DB_Reader dr = newDB_Reader();

try

{

         dr.ExecSP(comd);

         if (dr.Read())

         {

                   response.Object =GetModelByReader(dr);

                   response.Result =WSResponseResult.Success;

                   response.Message ="success";                       

         }

         else

         {

                   response.Object = null;

                   response.Result =WSResponseResult.Failed;                                             

                   response.Message ="0";

         }

}

catch (Exception ex)

{

         response.Object = null;                              

         response.Result =WSResponseResult.Error;

         response.Message = ex.Message;

}

finally

{

         dr.Close();

}

 

LogHelper.LogFinishStoreProc(Log,command.CommandText, response);

 

return response;

------------------------------------------------------

返回 ID Response

idresp

var response = newIDWSResponse();

 

SqlCommand comd = newSqlCommand();

comd.CommandType =CommandType.StoredProcedure;

comd.CommandText ="$end$";

comd.Parameters.AddWithValue("@",);

comd.Parameters.AddWithValue("@",);

 

SqlParameter p = newSqlParameter("@outvalue", SqlDbType.Int);

p.Direction =ParameterDirection.Output;

comd.Parameters.Add(p);

 

LogHelper.LogExecStoreProc(Log,comd.CommandText, comd.Parameters);

 

try

{

    NonQuery util = new NonQuery();

    util.ExecSP(comd);

         var outval = p.Value;

 

    response.ObjectID =Convert.ToInt32(outval);

         response.Message = "success";

         response.Result =WSResponseResult.Success;    

}

catch (Exception ex)

{

    response.Message = ex.Message;

    response.Result = WSResponseResult.Error;

}

 

LogHelper.LogFinishStoreProc(Log,command.CommandText, response);

 

return response;

 

 

你可能感兴趣的:(exception,list,cmd,null,存储,output)