/// <summary>Inserts a Order record.</summary> /// <param name="transaction">Commits or rejects a set of commands as a unit</param> /// <param name="blockOrderId">The value for the BlockOrderId column.</param> /// <param name="accountId">The value for the AccountId column.</param> /// <param name="securityId">The value for the SecurityId column.</param> /// <param name="settlementId">The value for the SettlementId column.</param> /// <param name="brokerId">The value for the BrokerId column.</param> /// <param name="positionTypeCode">The value for the PositionTypeCode column.</param> /// <param name="transactionTypeCode">The value for the TransactionTypeCode column.</param> /// <param name="timeInForceCode">The value for the TimeInForceCode column.</param> /// <param name="orderTypeCode">The value for the OrderTypeCode column.</param> /// <param name="conditionCode">The value for the ConditionCode column.</param> /// <param name="isDeleted">The value for the IsDeleted column.</param> /// <param name="isAgency">The value for the IsAgency column.</param> /// <param name="quantity">The value for the Quantity column.</param> /// <param name="price1">The value for the Price1 column.</param> /// <param name="price2">The value for the Price2 column.</param> /// <param name="note">The value for the Note column.</param> /// <param name="createdTime">The value for the CreatedTime column.</param> /// <param name="createdUserId">The value for the CreatedUserId column.</param> /// <param name="modifiedTime">The value for the ModifiedTime column.</param> /// <param name="modifiedUserId">The value for the ModifiedUserId column.</param> public static int Insert( AdoTransaction adoTransaction, SqlTransaction sqlTransaction, ref long rowVersion, int blockOrderId, int accountId, int securityId, int settlementId, object brokerId, int positionTypeCode, int transactionTypeCode, int timeInForceCode, int orderTypeCode, object conditionCode, object isDeleted, object isAgency, decimal quantity, object price1, object price2, object note, System.DateTime createdTime, int createdUserId, System.DateTime modifiedTime, int modifiedUserId) { // Accessor for the Order Table. ServerDataModel.OrderDataTable orderTable = ServerDataModel.Order; // Apply Defaults if ((brokerId == null)) { brokerId = System.DBNull.Value; } if ((conditionCode == null)) { conditionCode = System.DBNull.Value; } if ((isDeleted == null)) { isDeleted = false; } if ((isAgency == null)) { isAgency = false; } if ((price1 == null)) { price1 = System.DBNull.Value; } if ((price2 == null)) { price2 = System.DBNull.Value; } if ((note == null)) { note = System.DBNull.Value; } // Increment the row version rowVersion = ServerDataModel.RowVersion.Increment(); // The table must be locked for a short time to insert the record. This lock is to prevent other threads from // modifying the table during this short operation, it cannot be considered part of the locks used for transactional // integrity. ServerDataModel.OrderRow orderRow = null; lock (ServerDataModel.Order) { // Insert the record into the ADO database. orderRow = orderTable.NewOrderRow(); orderRow[orderTable.RowVersionColumn] = rowVersion; orderRow[orderTable.BlockOrderIdColumn] = blockOrderId; orderRow[orderTable.AccountIdColumn] = accountId; orderRow[orderTable.SecurityIdColumn] = securityId; orderRow[orderTable.SettlementIdColumn] = settlementId; orderRow[orderTable.BrokerIdColumn] = brokerId; orderRow[orderTable.PositionTypeCodeColumn] = positionTypeCode; orderRow[orderTable.TransactionTypeCodeColumn] = transactionTypeCode; orderRow[orderTable.TimeInForceCodeColumn] = timeInForceCode; orderRow[orderTable.OrderTypeCodeColumn] = orderTypeCode; orderRow[orderTable.ConditionCodeColumn] = conditionCode; orderRow[orderTable.IsDeletedColumn] = isDeleted; orderRow[orderTable.IsAgencyColumn] = isAgency; orderRow[orderTable.QuantityColumn] = quantity; orderRow[orderTable.Price1Column] = price1; orderRow[orderTable.Price2Column] = price2; orderRow[orderTable.NoteColumn] = note; orderRow[orderTable.CreatedTimeColumn] = createdTime; orderRow[orderTable.CreatedUserIdColumn] = createdUserId; orderRow[orderTable.ModifiedTimeColumn] = modifiedTime; orderRow[orderTable.ModifiedUserIdColumn] = modifiedUserId; orderTable.AddOrderRow(orderRow); } // New rows can't be locked ahed of time because they don't exist. Once the record is created and added to the table, // it is locked and then added retroactively to the transaction. adoTransaction.LockRequests.Add(new RowWriterRequest(orderRow, true)); // This will add the row to the transaction. adoTransaction.DataRows.Add(orderRow); // Insert the record into the SQL database. SqlCommand sqlCommand = new SqlCommand(@"insert ""Order"" (""rowVersion"",""OrderId"",""BlockOrderId"",""AccountId"",""SecurityId"",""SettlementId"",""BrokerId"",""PositionTypeCode"",""TransactionTypeCode"",""TimeInForceCode"",""OrderTypeCode"",""ConditionCode"",""IsDeleted"",""IsAgency"",""Quantity"",""Price1"",""Price2"",""Note"",""CreatedTime"",""CreatedUserId"",""ModifiedTime"",""ModifiedUserId"") values (@rowVersion,@orderId,@blockOrderId,@accountId,@securityId,@settlementId,@brokerId,@positionTypeCode,@transactionTypeCode,@timeInForceCode,@orderTypeCode,@conditionCode,@isDeleted,@isAgency,@quantity,@price1,@price2,@note,@createdTime,@createdUserId,@modifiedTime,@modifiedUserId)"); 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("@orderId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, orderRow[orderTable.OrderIdColumn])); sqlCommand.Parameters.Add(new SqlParameter("@blockOrderId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, blockOrderId)); sqlCommand.Parameters.Add(new SqlParameter("@accountId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, accountId)); sqlCommand.Parameters.Add(new SqlParameter("@securityId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, securityId)); sqlCommand.Parameters.Add(new SqlParameter("@settlementId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, settlementId)); sqlCommand.Parameters.Add(new SqlParameter("@brokerId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, brokerId)); sqlCommand.Parameters.Add(new SqlParameter("@positionTypeCode", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, positionTypeCode)); sqlCommand.Parameters.Add(new SqlParameter("@transactionTypeCode", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, transactionTypeCode)); sqlCommand.Parameters.Add(new SqlParameter("@timeInForceCode", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, timeInForceCode)); sqlCommand.Parameters.Add(new SqlParameter("@orderTypeCode", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, orderTypeCode)); sqlCommand.Parameters.Add(new SqlParameter("@conditionCode", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, conditionCode)); sqlCommand.Parameters.Add(new SqlParameter("@isDeleted", SqlDbType.Bit, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, isDeleted)); sqlCommand.Parameters.Add(new SqlParameter("@isAgency", SqlDbType.Bit, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, isAgency)); sqlCommand.Parameters.Add(new SqlParameter("@quantity", SqlDbType.Decimal, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, quantity)); sqlCommand.Parameters.Add(new SqlParameter("@price1", SqlDbType.Decimal, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, price1)); sqlCommand.Parameters.Add(new SqlParameter("@price2", SqlDbType.Decimal, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, price2)); sqlCommand.Parameters.Add(new SqlParameter("@note", SqlDbType.NVarChar, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, note)); sqlCommand.Parameters.Add(new SqlParameter("@createdTime", SqlDbType.DateTime, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, createdTime)); sqlCommand.Parameters.Add(new SqlParameter("@createdUserId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, createdUserId)); sqlCommand.Parameters.Add(new SqlParameter("@modifiedTime", SqlDbType.DateTime, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, modifiedTime)); sqlCommand.Parameters.Add(new SqlParameter("@modifiedUserId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, modifiedUserId)); sqlCommand.ExecuteNonQuery(); // Return Statements return(orderRow.OrderId); }
/// <summary>Inserts a Order record.</summary> /// <param name="transaction">Commits or rejects a set of commands as a unit</param> /// <param name="blockOrderId">The value for the BlockOrderId column.</param> /// <param name="accountId">The value for the AccountId column.</param> /// <param name="securityId">The value for the SecurityId column.</param> /// <param name="settlementId">The value for the SettlementId column.</param> /// <param name="brokerId">The value for the BrokerId column.</param> /// <param name="positionTypeCode">The value for the PositionTypeCode column.</param> /// <param name="transactionTypeCode">The value for the TransactionTypeCode column.</param> /// <param name="timeInForceCode">The value for the TimeInForceCode column.</param> /// <param name="orderTypeCode">The value for the OrderTypeCode column.</param> /// <param name="conditionCode">The value for the ConditionCode column.</param> /// <param name="isDeleted">The value for the IsDeleted column.</param> /// <param name="isAgency">The value for the IsAgency column.</param> /// <param name="quantity">The value for the Quantity column.</param> /// <param name="price1">The value for the Price1 column.</param> /// <param name="price2">The value for the Price2 column.</param> /// <param name="note">The value for the Note column.</param> /// <param name="createdTime">The value for the CreatedTime column.</param> /// <param name="createdUserId">The value for the CreatedUserId column.</param> /// <param name="modifiedTime">The value for the ModifiedTime column.</param> /// <param name="modifiedUserId">The value for the ModifiedUserId column.</param> public static int Insert( AdoTransaction adoTransaction, SqlTransaction sqlTransaction, ref long rowVersion, int blockOrderId, int accountId, int securityId, int settlementId, object brokerId, int positionTypeCode, int transactionTypeCode, int timeInForceCode, int orderTypeCode, object conditionCode, object isDeleted, object isAgency, decimal quantity, object price1, object price2, object note, System.DateTime createdTime, int createdUserId, System.DateTime modifiedTime, int modifiedUserId) { // Accessor for the Order Table. ServerDataModel.OrderDataTable orderTable = ServerDataModel.Order; // Apply Defaults if ((brokerId == null)) { brokerId = System.DBNull.Value; } if ((conditionCode == null)) { conditionCode = System.DBNull.Value; } if ((isDeleted == null)) { isDeleted = false; } if ((isAgency == null)) { isAgency = false; } if ((price1 == null)) { price1 = System.DBNull.Value; } if ((price2 == null)) { price2 = System.DBNull.Value; } if ((note == null)) { note = System.DBNull.Value; } // Increment the row version rowVersion = ServerDataModel.RowVersion.Increment(); // Insert the record into the ADO database. ServerDataModel.OrderRow orderRow = orderTable.NewOrderRow(); orderRow[orderTable.RowVersionColumn] = rowVersion; orderRow[orderTable.BlockOrderIdColumn] = blockOrderId; orderRow[orderTable.AccountIdColumn] = accountId; orderRow[orderTable.SecurityIdColumn] = securityId; orderRow[orderTable.SettlementIdColumn] = settlementId; orderRow[orderTable.BrokerIdColumn] = brokerId; orderRow[orderTable.PositionTypeCodeColumn] = positionTypeCode; orderRow[orderTable.TransactionTypeCodeColumn] = transactionTypeCode; orderRow[orderTable.TimeInForceCodeColumn] = timeInForceCode; orderRow[orderTable.OrderTypeCodeColumn] = orderTypeCode; orderRow[orderTable.ConditionCodeColumn] = conditionCode; orderRow[orderTable.IsDeletedColumn] = isDeleted; orderRow[orderTable.IsAgencyColumn] = isAgency; orderRow[orderTable.QuantityColumn] = quantity; orderRow[orderTable.Price1Column] = price1; orderRow[orderTable.Price2Column] = price2; orderRow[orderTable.NoteColumn] = note; orderRow[orderTable.CreatedTimeColumn] = createdTime; orderRow[orderTable.CreatedUserIdColumn] = createdUserId; orderRow[orderTable.ModifiedTimeColumn] = modifiedTime; orderRow[orderTable.ModifiedUserIdColumn] = modifiedUserId; orderTable.AddOrderRow(orderRow); adoTransaction.DataRows.Add(orderRow); // Insert the record into the SQL database. SqlCommand sqlCommand = new SqlCommand(@"insert ""Order"" (""rowVersion"",""OrderId"",""BlockOrderId"",""AccountId"",""SecurityId"",""SettlementId"",""BrokerId"",""PositionTypeCode"",""TransactionTypeCode"",""TimeInForceCode"",""OrderTypeCode"",""ConditionCode"",""IsDeleted"",""IsAgency"",""Quantity"",""Price1"",""Price2"",""Note"",""CreatedTime"",""CreatedUserId"",""ModifiedTime"",""ModifiedUserId"") values (@rowVersion,@orderId,@blockOrderId,@accountId,@securityId,@settlementId,@brokerId,@positionTypeCode,@transactionTypeCode,@timeInForceCode,@orderTypeCode,@conditionCode,@isDeleted,@isAgency,@quantity,@price1,@price2,@note,@createdTime,@createdUserId,@modifiedTime,@modifiedUserId)"); 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("@orderId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, orderRow[orderTable.OrderIdColumn])); sqlCommand.Parameters.Add(new SqlParameter("@blockOrderId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, blockOrderId)); sqlCommand.Parameters.Add(new SqlParameter("@accountId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, accountId)); sqlCommand.Parameters.Add(new SqlParameter("@securityId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, securityId)); sqlCommand.Parameters.Add(new SqlParameter("@settlementId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, settlementId)); sqlCommand.Parameters.Add(new SqlParameter("@brokerId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, brokerId)); sqlCommand.Parameters.Add(new SqlParameter("@positionTypeCode", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, positionTypeCode)); sqlCommand.Parameters.Add(new SqlParameter("@transactionTypeCode", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, transactionTypeCode)); sqlCommand.Parameters.Add(new SqlParameter("@timeInForceCode", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, timeInForceCode)); sqlCommand.Parameters.Add(new SqlParameter("@orderTypeCode", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, orderTypeCode)); sqlCommand.Parameters.Add(new SqlParameter("@conditionCode", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, conditionCode)); sqlCommand.Parameters.Add(new SqlParameter("@isDeleted", SqlDbType.Bit, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, isDeleted)); sqlCommand.Parameters.Add(new SqlParameter("@isAgency", SqlDbType.Bit, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, isAgency)); sqlCommand.Parameters.Add(new SqlParameter("@quantity", SqlDbType.Decimal, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, quantity)); sqlCommand.Parameters.Add(new SqlParameter("@price1", SqlDbType.Decimal, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, price1)); sqlCommand.Parameters.Add(new SqlParameter("@price2", SqlDbType.Decimal, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, price2)); sqlCommand.Parameters.Add(new SqlParameter("@note", SqlDbType.NVarChar, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, note)); sqlCommand.Parameters.Add(new SqlParameter("@createdTime", SqlDbType.DateTime, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, createdTime)); sqlCommand.Parameters.Add(new SqlParameter("@createdUserId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, createdUserId)); sqlCommand.Parameters.Add(new SqlParameter("@modifiedTime", SqlDbType.DateTime, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, modifiedTime)); sqlCommand.Parameters.Add(new SqlParameter("@modifiedUserId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, modifiedUserId)); sqlCommand.ExecuteNonQuery(); // Return Statements return(orderRow.OrderId); }