예제 #1
0
 public bool ExecuteNonQuery(string connectionString, List <ICommandCustom> CommandList)
 {
     if (string.IsNullOrEmpty(connectionString))
     {
         connectionString = _connectionString;
     }
     if (String.IsNullOrEmpty(connectionString))
     {
         throw new Exception("数据库连接字符串不存在");
     }
     if (CommandList == null)
     {
         throw new Exception("SqlBaseCommand不存在");
     }
     if (CommandList.Count == 0)
     {
         throw new Exception("SqlBaseCommand只有O条");
     }
     if (CommandList.Count == 1)
     {
         //modify by lzc 20170710
         return((CommandList[0]).comparison(ExecuteNonQuery(connectionString, CommandList[0])));
     }
     else
     {
         SqlTransactionCustom Transaction = new SqlTransactionCustom(connectionString);
         Transaction.BeginTransaction();
         try
         {
             SqlCommandCustom Command;
             for (int i = 0; i < CommandList.Count; i++)
             {
                 Command = ((SqlCommandCustom)CommandList[i]);
                 Command.ComparisonTypeCustom = ComparisonTypeCustom.ThanEqual;
                 if (!Command.comparison(ExecuteNonQuery(Transaction, Command)))
                 {
                     Transaction.Rollback();
                     return(false);
                 }
             }
             Transaction.Commit();
             return(true);
         }
         catch (Exception ex)
         {
             Transaction.Rollback();
             throw ex;
         }
     }
 }
예제 #2
0
 public bool ExecuteNonQuery(IConnectionCustom Connection, List <ICommandCustom> CommandList)
 {
     if (Connection == null)
     {
         Connection = _dbConnection;
     }
     if (Connection == null)
     {
         throw new Exception("数据库连接SqlConnection对象不存在");
     }
     if (CommandList == null)
     {
         throw new Exception("SqlBaseCommand不存在");
     }
     if (CommandList.Count == 0)
     {
         throw new Exception("SqlBaseCommand只有O条");
     }
     if (CommandList.Count == 1)
     {
         return(((CommandCustom)CommandList[0]).comparison(ExecuteNonQuery(Connection, CommandList[0])));
     }
     else
     {
         SqlTransactionCustom Transaction = new SqlTransactionCustom(Connection.iDbConnection);
         Transaction.BeginTransaction();
         try
         {
             CommandCustom Command;
             for (int i = 0; i < CommandList.Count; i++)
             {
                 Command = ((CommandCustom)CommandList[i]);
                 Command.ComparisonTypeCustom = ComparisonTypeCustom.ThanEqual;
                 if (!Command.comparison(ExecuteNonQuery(Transaction, Command)))
                 {
                     Transaction.Rollback();
                     return(false);
                 }
             }
             Transaction.Commit();
             return(true);
         }
         catch (Exception ex)
         {
             Transaction.Rollback();
             throw ex;
         }
     }
 }