Пример #1
0
        /// <summary>Archives a Negotiation 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="negotiationId">The value for the NegotiationId 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 negotiationId)
        {
            // Accessor for the Negotiation Table.
            ServerMarketData.NegotiationDataTable negotiationTable = ServerMarketData.Negotiation;
            // Rule #1: Make sure the record exists before updating it.
            ServerMarketData.NegotiationRow negotiationRow = negotiationTable.FindByNegotiationId(negotiationId);
            if ((negotiationRow == null))
            {
                throw new Exception(string.Format("The Negotiation table does not have an element identified by {0}", negotiationId));
            }
            // Rule #2: Optimistic Concurrency Check
            if ((negotiationRow.RowVersion != rowVersion))
            {
                throw new System.Exception("This record is busy.  Please try again later.");
            }
            // Archive the child records.
            // Increment the row version
            rowVersion = ServerMarketData.RowVersion.Increment();
            // Delete the record in the ADO database.
            negotiationRow[negotiationTable.RowVersionColumn] = rowVersion;
            adoTransaction.DataRows.Add(negotiationRow);
            negotiationRow.Delete();
            // Archive the record in the SQL database.
            SqlCommand sqlCommand = new SqlCommand("update \"Negotiation\" set \"IsArchived\" = 1 where \"NegotiationId\"=@negotiationId");

            sqlCommand.Connection  = sqlTransaction.Connection;
            sqlCommand.Transaction = sqlTransaction;
            sqlCommand.Parameters.Add(new SqlParameter("@negotiationId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, negotiationId));
            sqlCommand.ExecuteNonQuery();
        }
Пример #2
0
        /// <summary>Updates a Negotiation record.</summary>
        /// <param name="transaction">Commits or rejects a set of commands as a unit</param>
        /// <param name="rowVersion">The version number of the row</param>
        /// <param name="executionId">The value for the ExecutionId column.</param>
        /// <param name="matchId">The value for the MatchId column.</param>
        /// <param name="negotiationId">The value for the NegotiationId column.</param>
        /// <param name="quantity">The value for the Quantity column.</param>
        /// <param name="statusCode">The value for the StatusCode column.</param>
        public static void Update(AdoTransaction adoTransaction, SqlTransaction sqlTransaction, ref long rowVersion, object executionId, object matchId, int negotiationId, object quantity, object statusCode)
        {
            // Accessor for the Negotiation Table.
            ServerMarketData.NegotiationDataTable negotiationTable = ServerMarketData.Negotiation;
            // Rule #1: Make sure the record exists before updating it.
            ServerMarketData.NegotiationRow negotiationRow = negotiationTable.FindByNegotiationId(negotiationId);
            if ((negotiationRow == null))
            {
                throw new Exception(string.Format("The Negotiation table does not have an element identified by {0}", negotiationId));
            }
            // Rule #2: Optimistic Concurrency Check
            if ((negotiationRow.RowVersion != rowVersion))
            {
                throw new System.Exception("This record is busy.  Please try again later.");
            }
            // Apply Defaults
            if ((executionId == null))
            {
                executionId = negotiationRow[negotiationTable.ExecutionIdColumn];
            }
            if ((matchId == null))
            {
                matchId = negotiationRow[negotiationTable.MatchIdColumn];
            }
            if ((quantity == null))
            {
                quantity = negotiationRow[negotiationTable.QuantityColumn];
            }
            if ((statusCode == null))
            {
                statusCode = negotiationRow[negotiationTable.StatusCodeColumn];
            }
            // Increment the row version
            rowVersion = ServerMarketData.RowVersion.Increment();
            // Update the record in the ADO database.
            negotiationRow[negotiationTable.RowVersionColumn]  = rowVersion;
            negotiationRow[negotiationTable.ExecutionIdColumn] = executionId;
            negotiationRow[negotiationTable.MatchIdColumn]     = matchId;
            negotiationRow[negotiationTable.QuantityColumn]    = quantity;
            negotiationRow[negotiationTable.StatusCodeColumn]  = statusCode;
            adoTransaction.DataRows.Add(negotiationRow);
            // Update the record in the SQL database.
            SqlCommand sqlCommand = new SqlCommand("update \"Negotiation\" set \"RowVersion\"=@rowVersion,\"ExecutionId\"=@executionId,\"Mat" +
                                                   "chId\"=@matchId,\"Quantity\"=@quantity,\"StatusCode\"=@statusCode where \"NegotiationI" +
                                                   "d\"=@negotiationId");

            sqlCommand.Connection  = sqlTransaction.Connection;
            sqlCommand.Transaction = sqlTransaction;
            sqlCommand.Parameters.Add(new SqlParameter("@rowVersion", SqlDbType.BigInt, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, rowVersion));
            sqlCommand.Parameters.Add(new SqlParameter("@executionId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, executionId));
            sqlCommand.Parameters.Add(new SqlParameter("@matchId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, matchId));
            sqlCommand.Parameters.Add(new SqlParameter("@negotiationId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, negotiationId));
            sqlCommand.Parameters.Add(new SqlParameter("@quantity", SqlDbType.Decimal, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, quantity));
            sqlCommand.Parameters.Add(new SqlParameter("@statusCode", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, statusCode));
            // Update the record in the SQL database.
            sqlCommand.ExecuteNonQuery();
        }
Пример #3
0
        /// <summary>Inserts a Negotiation 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="matchId">The value for the MatchId column.</param>
        /// <param name="quantity">The value for the Quantity column.</param>
        /// <param name="statusCode">The value for the StatusCode column.</param>
        public static int Insert(AdoTransaction adoTransaction, SqlTransaction sqlTransaction, ref long rowVersion, object executionId, int matchId, decimal quantity, int statusCode)
        {
            // Accessor for the Negotiation Table.
            ServerMarketData.NegotiationDataTable negotiationTable = ServerMarketData.Negotiation;
            // Apply Defaults
            if ((executionId == null))
            {
                executionId = System.DBNull.Value;
            }
            // Increment the row version
            rowVersion = ServerMarketData.RowVersion.Increment();
            // Insert the record into the ADO database.
            ServerMarketData.NegotiationRow negotiationRow = negotiationTable.NewNegotiationRow();
            negotiationRow[negotiationTable.RowVersionColumn]  = rowVersion;
            negotiationRow[negotiationTable.ExecutionIdColumn] = executionId;
            negotiationRow[negotiationTable.MatchIdColumn]     = matchId;
            negotiationRow[negotiationTable.QuantityColumn]    = quantity;
            negotiationRow[negotiationTable.StatusCodeColumn]  = statusCode;
            negotiationTable.AddNegotiationRow(negotiationRow);
            adoTransaction.DataRows.Add(negotiationRow);
            // Insert the record into the SQL database.
            SqlCommand sqlCommand = new SqlCommand("insert \"Negotiation\" (\"rowVersion\",\"ExecutionId\",\"MatchId\",\"NegotiationId\",\"Quant" +
                                                   "ity\",\"StatusCode\") values (@rowVersion,@executionId,@matchId,@negotiationId,@qua" +
                                                   "ntity,@statusCode)");

            sqlCommand.Connection  = sqlTransaction.Connection;
            sqlCommand.Transaction = sqlTransaction;
            sqlCommand.Parameters.Add(new SqlParameter("@rowVersion", SqlDbType.BigInt, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, rowVersion));
            sqlCommand.Parameters.Add(new SqlParameter("@executionId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, executionId));
            sqlCommand.Parameters.Add(new SqlParameter("@matchId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, matchId));
            sqlCommand.Parameters.Add(new SqlParameter("@negotiationId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, negotiationRow[negotiationTable.NegotiationIdColumn]));
            sqlCommand.Parameters.Add(new SqlParameter("@quantity", SqlDbType.Decimal, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, quantity));
            sqlCommand.Parameters.Add(new SqlParameter("@statusCode", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, statusCode));
            sqlCommand.ExecuteNonQuery();
            // Return Statements
            return(negotiationRow.NegotiationId);
        }