/// <summary>Archives a Execution record.</summary> /// <param name="transaction">Commits or rejects a set of commands as a unit</param> /// <param name="RowVersion">The version number of this row.</param> /// <param name="executionId">The value for the ExecutionId column.</param> /// <param name="archive">true to archive the object, false to unarchive it.</param> public static void Archive(AdoTransaction adoTransaction, SqlTransaction sqlTransaction, long rowVersion, int executionId) { // Accessor for the Execution Table. ServerMarketData.ExecutionDataTable executionTable = ServerMarketData.Execution; // Rule #1: Make sure the record exists before updating it. ServerMarketData.ExecutionRow executionRow = executionTable.FindByExecutionId(executionId); if ((executionRow == null)) { throw new Exception(string.Format("The Execution table does not have an element identified by {0}", executionId)); } // Rule #2: Optimistic Concurrency Check if ((executionRow.RowVersion != rowVersion)) { throw new System.Exception("This record is busy. Please try again later."); } // Archive the child records. for (int index = 0; (index < executionRow.GetNegotiationRows().Length); index = (index + 1)) { ServerMarketData.NegotiationRow childNegotiationRow = executionRow.GetNegotiationRows()[index]; Negotiation.Archive(adoTransaction, sqlTransaction, childNegotiationRow.RowVersion, childNegotiationRow.NegotiationId); } // Increment the row version rowVersion = ServerMarketData.RowVersion.Increment(); // Delete the record in the ADO database. executionRow[executionTable.RowVersionColumn] = rowVersion; adoTransaction.DataRows.Add(executionRow); executionRow.Delete(); // Archive the record in the SQL database. SqlCommand sqlCommand = new SqlCommand("update \"Execution\" set \"IsArchived\" = 1 where \"ExecutionId\"=@executionId"); sqlCommand.Connection = sqlTransaction.Connection; sqlCommand.Transaction = sqlTransaction; sqlCommand.Parameters.Add(new SqlParameter("@executionId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, executionId)); sqlCommand.ExecuteNonQuery(); }
/// <summary>Deletes a Execution record.</summary> /// <param name="transaction">Commits or rejects a set of commands as a unit</param> /// <param name="executionId">The value for the ExecutionId column.</param> /// <param name="rowVersion">The value for the RowVersion column.</param> public static void Delete(Transaction transaction, int executionId, long rowVersion) { // Accessor for the Execution Table. ServerMarketData.ExecutionDataTable executionTable = ServerMarketData.Execution; // Rule #1: Make sure the record exists before updating it. ServerMarketData.ExecutionRow executionRow = executionTable.FindByExecutionId(executionId); if ((executionRow == null)) { throw new Exception(string.Format("The Execution table does not have an element identified by {0}", executionId)); } // Rule #2: Optimistic Concurrency Check if ((executionRow.RowVersion != rowVersion)) { throw new System.Exception("This record is busy. Please try again later."); } // Provide the modified time and current user id to the base class. int modifiedLoginId = ServerMarketData.LoginId; DateTime modifiedTime = DateTime.Now; // Delete the child records. // Delete the record in the ADO database. transaction.DataRows.Add(executionRow); executionRow.Delete(); // Delete the record in the SQL database. SqlCommand updateCommand = new SqlCommand(@"update ""Execution"" set ""ModifiedTime""=@modifiedTime,""ModifiedLoginId""=@modifiedLoginId where ""ExecutionId""=@executionId"); updateCommand.Connection = transaction.SqlConnection; updateCommand.Transaction = transaction.SqlTransaction; updateCommand.Parameters.Add("@executionId", @executionId); updateCommand.Parameters.Add("@modifiedTime", modifiedTime); updateCommand.Parameters.Add("@modifiedLoginId", modifiedLoginId); updateCommand.ExecuteNonQuery(); // Delete the record in the SQL database. SqlCommand deleteCommand = new SqlCommand(@"delete ""Execution"" where ""ExecutionId""=@executionId"); deleteCommand.Connection = transaction.SqlConnection; deleteCommand.Transaction = transaction.SqlTransaction; deleteCommand.Parameters.Add("@executionId", @executionId); deleteCommand.ExecuteNonQuery(); }