Exemple #1
0
 /// <summary>Archives a BlockOrder 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="blockOrderId">The value for the BlockOrderId 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 blockOrderId)
 {
     // Accessor for the BlockOrder Table.
     ServerDataModel.BlockOrderDataTable blockOrderTable = ServerDataModel.BlockOrder;
     // Rule #1: Make sure the record exists before updating it.
     ServerDataModel.BlockOrderRow blockOrderRow = blockOrderTable.FindByBlockOrderId(blockOrderId);
     if ((blockOrderRow == null))
     {
         throw new Exception(string.Format("The BlockOrder table does not have an element identified by {0}", blockOrderId));
     }
     // Rule #2: Optimistic Concurrency Check
     if ((blockOrderRow.RowVersion != rowVersion))
     {
         throw new System.Exception("This record is busy.  Please try again later.");
     }
     // Archive the child records.
     for (int index = 0; (index < blockOrderRow.GetAllocationRows().Length); index = (index + 1))
     {
         ServerDataModel.AllocationRow childAllocationRow = blockOrderRow.GetAllocationRows()[index];
         Allocation.Archive(adoTransaction, sqlTransaction, childAllocationRow.RowVersion, childAllocationRow.AllocationId);
     }
     for (int index = 0; (index < blockOrderRow.GetBlockOrderTreeRowsByFKBlockOrderBlockOrderTreeChildId().Length); index = (index + 1))
     {
         ServerDataModel.BlockOrderTreeRow childBlockOrderTreeRow = blockOrderRow.GetBlockOrderTreeRowsByFKBlockOrderBlockOrderTreeChildId()[index];
         BlockOrderTree.Archive(adoTransaction, sqlTransaction, childBlockOrderTreeRow.RowVersion, childBlockOrderTreeRow.ParentId, childBlockOrderTreeRow.ChildId);
     }
     for (int index = 0; (index < blockOrderRow.GetBlockOrderTreeRowsByFKBlockOrderBlockOrderTreeParentId().Length); index = (index + 1))
     {
         ServerDataModel.BlockOrderTreeRow childBlockOrderTreeRow = blockOrderRow.GetBlockOrderTreeRowsByFKBlockOrderBlockOrderTreeParentId()[index];
         BlockOrderTree.Archive(adoTransaction, sqlTransaction, childBlockOrderTreeRow.RowVersion, childBlockOrderTreeRow.ParentId, childBlockOrderTreeRow.ChildId);
     }
     for (int index = 0; (index < blockOrderRow.GetExecutionRows().Length); index = (index + 1))
     {
         ServerDataModel.ExecutionRow childExecutionRow = blockOrderRow.GetExecutionRows()[index];
         Execution.Archive(adoTransaction, sqlTransaction, childExecutionRow.RowVersion, childExecutionRow.ExecutionId);
     }
     for (int index = 0; (index < blockOrderRow.GetOrderRows().Length); index = (index + 1))
     {
         ServerDataModel.OrderRow childOrderRow = blockOrderRow.GetOrderRows()[index];
         Order.Archive(adoTransaction, sqlTransaction, childOrderRow.RowVersion, childOrderRow.OrderId);
     }
     for (int index = 0; (index < blockOrderRow.GetPlacementRows().Length); index = (index + 1))
     {
         ServerDataModel.PlacementRow childPlacementRow = blockOrderRow.GetPlacementRows()[index];
         Placement.Archive(adoTransaction, sqlTransaction, childPlacementRow.RowVersion, childPlacementRow.PlacementId);
     }
     // Increment the row version
     rowVersion = ServerDataModel.RowVersion.Increment();
     // Delete the record in the ADO database.
     blockOrderRow[blockOrderTable.RowVersionColumn] = rowVersion;
     adoTransaction.DataRows.Add(blockOrderRow);
     blockOrderRow.Delete();
     // Archive the record in the SQL database.
     SqlCommand sqlCommand = new SqlCommand("update \"BlockOrder\" set \"IsArchived\" = 1 where \"BlockOrderId\"=@blockOrderId");
     sqlCommand.Connection = sqlTransaction.Connection;
     sqlCommand.Transaction = sqlTransaction;
     sqlCommand.Parameters.Add(new SqlParameter("@blockOrderId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, blockOrderId));
     sqlCommand.ExecuteNonQuery();
 }
        /// <summary>Archives a TransactionType 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="transactionTypeCode">The value for the TransactionTypeCode 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 transactionTypeCode)
        {
            // Accessor for the TransactionType Table.
            ServerDataModel.TransactionTypeDataTable transactionTypeTable = ServerDataModel.TransactionType;
            // Rule #1: Make sure the record exists before updating it.
            ServerDataModel.TransactionTypeRow transactionTypeRow = transactionTypeTable.FindByTransactionTypeCode(transactionTypeCode);
            if ((transactionTypeRow == null))
            {
                throw new Exception(string.Format("The TransactionType table does not have an element identified by {0}", transactionTypeCode));
            }
            // Rule #2: Optimistic Concurrency Check
            if ((transactionTypeRow.RowVersion != rowVersion))
            {
                throw new System.Exception("This record is busy.  Please try again later.");
            }
            // Archive the child records.
            for (int index = 0; (index < transactionTypeRow.GetAllocationRows().Length); index = (index + 1))
            {
                ServerDataModel.AllocationRow childAllocationRow = transactionTypeRow.GetAllocationRows()[index];
                Allocation.Archive(adoTransaction, sqlTransaction, childAllocationRow.RowVersion, childAllocationRow.AllocationId);
            }
            for (int index = 0; (index < transactionTypeRow.GetBlockOrderRows().Length); index = (index + 1))
            {
                ServerDataModel.BlockOrderRow childBlockOrderRow = transactionTypeRow.GetBlockOrderRows()[index];
                BlockOrder.Archive(adoTransaction, sqlTransaction, childBlockOrderRow.RowVersion, childBlockOrderRow.BlockOrderId);
            }
            for (int index = 0; (index < transactionTypeRow.GetOrderRows().Length); index = (index + 1))
            {
                ServerDataModel.OrderRow childOrderRow = transactionTypeRow.GetOrderRows()[index];
                Order.Archive(adoTransaction, sqlTransaction, childOrderRow.RowVersion, childOrderRow.OrderId);
            }
            for (int index = 0; (index < transactionTypeRow.GetProposedOrderRows().Length); index = (index + 1))
            {
                ServerDataModel.ProposedOrderRow childProposedOrderRow = transactionTypeRow.GetProposedOrderRows()[index];
                ProposedOrder.Archive(adoTransaction, sqlTransaction, childProposedOrderRow.RowVersion, childProposedOrderRow.ProposedOrderId);
            }
            // Increment the row version
            rowVersion = ServerDataModel.RowVersion.Increment();
            // Delete the record in the ADO database.
            transactionTypeRow[transactionTypeTable.RowVersionColumn] = rowVersion;
            adoTransaction.DataRows.Add(transactionTypeRow);
            transactionTypeRow.Delete();
            // Archive the record in the SQL database.
            SqlCommand sqlCommand = new SqlCommand("update \"TransactionType\" set \"IsArchived\" = 1 where \"TransactionTypeCode\"=@transa" +
                                                   "ctionTypeCode");

            sqlCommand.Connection  = sqlTransaction.Connection;
            sqlCommand.Transaction = sqlTransaction;
            sqlCommand.Parameters.Add(new SqlParameter("@transactionTypeCode", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, transactionTypeCode));
            sqlCommand.ExecuteNonQuery();
        }
        /// <summary>Collects the table lock request(s) for an Update operation</summary>
        /// <param name="adoTransaction">A list of locks required for this operation.</param>
        public static void LockArchive(ParameterList parameters)
        {
            // Extract the ADO transaction from the command batch.
            AdoTransaction adoTransaction = parameters["adoTransaction"];
            // This will create a request to lock this record for a write operation when the transaction begins.
            int orderId = parameters["orderId"];

            ServerDataModel.OrderRow orderRow = ServerDataModel.Order.FindByOrderId(orderId);
            if ((orderRow == null))
            {
                throw new Exception(string.Format("The Order table does not have an element identified by {0}", orderId));
            }
            adoTransaction.LockRequests.Add(new RowWriterRequest(orderRow));
        }
Exemple #4
0
 /// <summary>Updates a Order record using Metadata Parameters.</summary>
 /// <param name="transaction">Contains the parameters and exceptions for this command.</param>
 public static void Update(ParameterList parameters)
 {
     // Accessor for the Order Table.
     ServerDataModel.OrderDataTable orderTable = ServerDataModel.Order;
     // Extract the parameters from the command batch.
     AdoTransaction adoTransaction = parameters["adoTransaction"];
     SqlTransaction sqlTransaction = parameters["sqlTransaction"];
     object configurationId = parameters["configurationId"].Value;
     int orderId = ((string)(parameters["orderId"]));
     object blockOrderId = parameters["blockOrderId"].Value;
     object externalAccountId = parameters["accountId"].Value;
     object externalSecurityId = parameters["securityId"].Value;
     object externalSettlementId = parameters["settlementId"].Value;
     object brokerId = parameters["brokerId"].Value;
     object positionTypeCode = parameters["positionTypeCode"].Value;
     object externalTransactionTypeCode = parameters["transactionTypeCode"].Value;
     object externalTimeInForceCode = parameters["timeInForceCode"].Value;
     object externalOrderTypeCode = parameters["orderTypeCode"].Value;
     object conditionCode = parameters["conditionCode"].Value;
     object isDeleted = parameters["isDeleted"].Value;
     object isAgency = parameters["isAgency"].Value;
     object quantity = parameters["quantity"].Value;
     object price1 = parameters["price1"].Value;
     object price2 = parameters["price2"].Value;
     object note = parameters["note"].Value;
     object createdTime = parameters["createdTime"].Value;
     object createdUserId = parameters["createdUserId"].Value;
     object modifiedTime = parameters["modifiedTime"].Value;
     object modifiedUserId = parameters["modifiedUserId"].Value;
     // The row versioning is largely disabled for external operations.
     long rowVersion = long.MinValue;
     // Resolve External Identifiers
     object accountId = Account.FindOptionalKey(configurationId, "accountId", externalAccountId);
     object securityId = Security.FindOptionalKey(configurationId, "securityId", externalSecurityId);
     object settlementId = Security.FindOptionalKey(configurationId, "settlementId", externalSettlementId);
     object transactionTypeCode = TransactionType.FindOptionalKey(configurationId, "transactionTypeCode", externalTransactionTypeCode);
     object timeInForceCode = TimeInForce.FindOptionalKey(configurationId, "timeInForceCode", externalTimeInForceCode);
     object orderTypeCode = OrderType.FindOptionalKey(configurationId, "orderTypeCode", externalOrderTypeCode);
     // While the optimistic concurrency checking is disabled for the external methods, the internal methods
     // still need to perform the check.  This ncurrency checking logic by finding the current row version to be
     // will bypass the coused when the internal method is called.
     ServerDataModel.OrderRow orderRow = orderTable.FindByOrderId(orderId);
     rowVersion = ((long)(orderRow[orderTable.RowVersionColumn]));
     // Call the internal method to complete the operation.
     MarkThree.Quasar.Core.Order.Update(adoTransaction, sqlTransaction, ref rowVersion, orderId, blockOrderId, accountId, securityId, settlementId, brokerId, positionTypeCode, transactionTypeCode, timeInForceCode, orderTypeCode, conditionCode, isDeleted, isAgency, quantity, price1, price2, note, createdTime, createdUserId, modifiedTime, modifiedUserId);
     // Return values.
     parameters["rowVersion"] = rowVersion;
 }
 /// <summary>Collects the table lock request(s) for an Update operation</summary>
 /// <param name="adoTransaction">A list of locks required for this operation.</param>
 public static void LockUpdate(AdoTransaction adoTransaction, int orderId, object blockOrderId, object accountId, object securityId, object settlementId, object brokerId, object positionTypeCode, object transactionTypeCode, object timeInForceCode, object orderTypeCode, object conditionCode, object createdUserId, object modifiedUserId)
 {
     // This will create a request to lock this record for a write operation when the transaction begins.
     ServerDataModel.OrderRow orderRow = ServerDataModel.Order.FindByOrderId(orderId);
     if ((orderRow == null))
     {
         throw new Exception(string.Format("The Order table does not have an element identified by {0}", orderId));
     }
     adoTransaction.LockRequests.Add(new RowWriterRequest(orderRow));
     // Lock the block order record.
     if (blockOrderId != null)
     {
         ServerDataModel.BlockOrderRow blockOrderRow = ServerDataModel.BlockOrder.FindByBlockOrderId((int)blockOrderId);
         if ((blockOrderRow == null))
         {
             throw new Exception(string.Format("The Block Order table does not have an element identified by {0}", blockOrderId));
         }
         adoTransaction.LockRequests.Add(new RowReaderRequest(blockOrderRow));
     }
 }
Exemple #6
0
 /// <summary>Archives a Order record using Metadata Parameters.</summary>
 /// <param name="transaction">Contains the parameters and exceptions for this command.</param>
 public static void Archive(ParameterList parameters)
 {
     // Accessor for the Order Table.
     ServerDataModel.OrderDataTable orderTable = ServerDataModel.Order;
     // Extract the parameters from the command batch.
     AdoTransaction adoTransaction = parameters["adoTransaction"];
     SqlTransaction sqlTransaction = parameters["sqlTransaction"];
     object configurationId = parameters["configurationId"].Value;
     string externalOrderId = parameters["orderId"];
     // The row versioning is largely disabled for external operations.
     long rowVersion = long.MinValue;
     // Find the internal identifier using the primar key elements.
     // identifier is used to determine if a record exists with the same key.
     int orderId = Order.FindRequiredKey(configurationId, "orderId", externalOrderId);
     // While the optimistic concurrency checking is disabled for the external methods, the internal methods
     // still need to perform the check.  This ncurrency checking logic by finding the current row version to be
     // will bypass the coused when the internal method is called.
     ServerDataModel.OrderRow orderRow = orderTable.FindByOrderId(orderId);
     rowVersion = ((long)(orderRow[orderTable.RowVersionColumn]));
     // Call the internal method to complete the operation.
     MarkThree.Quasar.Core.Order.Archive(adoTransaction, sqlTransaction, rowVersion, orderId);
 }
Exemple #7
0
        /// <summary>ArchiveChildrens a Security 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="securityId">The value for the SecurityId column.</param>
        /// <param name="archive">true to archive the object, false to unarchive it.</param>
        internal static void ArchiveChildren(AdoTransaction adoTransaction, SqlTransaction sqlTransaction, long rowVersion, int securityId)
        {
            // Accessor for the Security Table.
            ServerDataModel.SecurityDataTable securityTable = ServerDataModel.Security;
            // This record can be used to iterate through all the children.
            ServerDataModel.SecurityRow securityRow = securityTable.FindBySecurityId(securityId);
            // Archive the child records.
            for (int index = 0; (index < securityRow.GetAccountRows().Length); index = (index + 1))
            {
                ServerDataModel.AccountRow childAccountRow = securityRow.GetAccountRows()[index];
                Account.ArchiveChildren(adoTransaction, sqlTransaction, childAccountRow.RowVersion, childAccountRow.AccountId);
            }
            for (int index = 0; (index < securityRow.GetAllocationRowsByFKSecurityAllocationSecurityId().Length); index = (index + 1))
            {
                ServerDataModel.AllocationRow childAllocationRow = securityRow.GetAllocationRowsByFKSecurityAllocationSecurityId()[index];
                Allocation.Archive(adoTransaction, sqlTransaction, childAllocationRow.RowVersion, childAllocationRow.AllocationId);
            }
            for (int index = 0; (index < securityRow.GetAllocationRowsByFKSecurityAllocationSettlementId().Length); index = (index + 1))
            {
                ServerDataModel.AllocationRow childAllocationRow = securityRow.GetAllocationRowsByFKSecurityAllocationSettlementId()[index];
                Allocation.Archive(adoTransaction, sqlTransaction, childAllocationRow.RowVersion, childAllocationRow.AllocationId);
            }
            for (int index = 0; (index < securityRow.GetBlockOrderRowsByFKSecurityBlockOrderSecurityId().Length); index = (index + 1))
            {
                ServerDataModel.BlockOrderRow childBlockOrderRow = securityRow.GetBlockOrderRowsByFKSecurityBlockOrderSecurityId()[index];
                BlockOrder.Archive(adoTransaction, sqlTransaction, childBlockOrderRow.RowVersion, childBlockOrderRow.BlockOrderId);
            }
            for (int index = 0; (index < securityRow.GetBlockOrderRowsByFKSecurityBlockOrderSettlementId().Length); index = (index + 1))
            {
                ServerDataModel.BlockOrderRow childBlockOrderRow = securityRow.GetBlockOrderRowsByFKSecurityBlockOrderSettlementId()[index];
                BlockOrder.Archive(adoTransaction, sqlTransaction, childBlockOrderRow.RowVersion, childBlockOrderRow.BlockOrderId);
            }
            for (int index = 0; (index < securityRow.GetBlotterMapRows().Length); index = (index + 1))
            {
                ServerDataModel.BlotterMapRow childBlotterMapRow = securityRow.GetBlotterMapRows()[index];
                BlotterMap.Archive(adoTransaction, sqlTransaction, childBlotterMapRow.RowVersion, childBlotterMapRow.BlotterMapId);
            }
            for (int index = 0; (index < securityRow.GetDebtRowsByFKSecurityDebtDebtId().Length); index = (index + 1))
            {
                ServerDataModel.DebtRow childDebtRow = securityRow.GetDebtRowsByFKSecurityDebtDebtId()[index];
                Debt.ArchiveChildren(adoTransaction, sqlTransaction, childDebtRow.RowVersion, childDebtRow.DebtId);
            }
            for (int index = 0; (index < securityRow.GetDebtRowsByFKSecurityDebtSettlementId().Length); index = (index + 1))
            {
                ServerDataModel.DebtRow childDebtRow = securityRow.GetDebtRowsByFKSecurityDebtSettlementId()[index];
                Debt.ArchiveChildren(adoTransaction, sqlTransaction, childDebtRow.RowVersion, childDebtRow.DebtId);
            }
            for (int index = 0; (index < securityRow.GetCurrencyRows().Length); index = (index + 1))
            {
                ServerDataModel.CurrencyRow childCurrencyRow = securityRow.GetCurrencyRows()[index];
                Currency.ArchiveChildren(adoTransaction, sqlTransaction, childCurrencyRow.RowVersion, childCurrencyRow.CurrencyId);
            }
            for (int index = 0; (index < securityRow.GetEquityRowsByFKSecurityEquityEquityId().Length); index = (index + 1))
            {
                ServerDataModel.EquityRow childEquityRow = securityRow.GetEquityRowsByFKSecurityEquityEquityId()[index];
                Equity.ArchiveChildren(adoTransaction, sqlTransaction, childEquityRow.RowVersion, childEquityRow.EquityId);
            }
            for (int index = 0; (index < securityRow.GetEquityRowsByFKSecurityEquitySettlementId().Length); index = (index + 1))
            {
                ServerDataModel.EquityRow childEquityRow = securityRow.GetEquityRowsByFKSecurityEquitySettlementId()[index];
                Equity.ArchiveChildren(adoTransaction, sqlTransaction, childEquityRow.RowVersion, childEquityRow.EquityId);
            }
            for (int index = 0; (index < securityRow.GetOrderRowsByFKSecurityOrderSecurityId().Length); index = (index + 1))
            {
                ServerDataModel.OrderRow childOrderRow = securityRow.GetOrderRowsByFKSecurityOrderSecurityId()[index];
                Order.Archive(adoTransaction, sqlTransaction, childOrderRow.RowVersion, childOrderRow.OrderId);
            }
            for (int index = 0; (index < securityRow.GetOrderRowsByFKSecurityOrderSettlementId().Length); index = (index + 1))
            {
                ServerDataModel.OrderRow childOrderRow = securityRow.GetOrderRowsByFKSecurityOrderSettlementId()[index];
                Order.Archive(adoTransaction, sqlTransaction, childOrderRow.RowVersion, childOrderRow.OrderId);
            }
            for (int index = 0; (index < securityRow.GetPositionRows().Length); index = (index + 1))
            {
                ServerDataModel.PositionRow childPositionRow = securityRow.GetPositionRows()[index];
                Position.Archive(adoTransaction, sqlTransaction, childPositionRow.RowVersion, childPositionRow.AccountId, childPositionRow.SecurityId, childPositionRow.PositionTypeCode);
            }
            for (int index = 0; (index < securityRow.GetPositionTargetRows().Length); index = (index + 1))
            {
                ServerDataModel.PositionTargetRow childPositionTargetRow = securityRow.GetPositionTargetRows()[index];
                PositionTarget.Archive(adoTransaction, sqlTransaction, childPositionTargetRow.RowVersion, childPositionTargetRow.ModelId, childPositionTargetRow.SecurityId, childPositionTargetRow.PositionTypeCode);
            }
            for (int index = 0; (index < securityRow.GetPriceRows().Length); index = (index + 1))
            {
                ServerDataModel.PriceRow childPriceRow = securityRow.GetPriceRows()[index];
                Price.Archive(adoTransaction, sqlTransaction, childPriceRow.RowVersion, childPriceRow.SecurityId, childPriceRow.CurrencyId);
            }
            for (int index = 0; (index < securityRow.GetProposedOrderRowsByFKSecurityProposedOrderSecurityId().Length); index = (index + 1))
            {
                ServerDataModel.ProposedOrderRow childProposedOrderRow = securityRow.GetProposedOrderRowsByFKSecurityProposedOrderSecurityId()[index];
                ProposedOrder.Archive(adoTransaction, sqlTransaction, childProposedOrderRow.RowVersion, childProposedOrderRow.ProposedOrderId);
            }
            for (int index = 0; (index < securityRow.GetProposedOrderRowsByFKSecurityProposedOrderSettlementId().Length); index = (index + 1))
            {
                ServerDataModel.ProposedOrderRow childProposedOrderRow = securityRow.GetProposedOrderRowsByFKSecurityProposedOrderSettlementId()[index];
                ProposedOrder.Archive(adoTransaction, sqlTransaction, childProposedOrderRow.RowVersion, childProposedOrderRow.ProposedOrderId);
            }
            for (int index = 0; (index < securityRow.GetTaxLotRows().Length); index = (index + 1))
            {
                ServerDataModel.TaxLotRow childTaxLotRow = securityRow.GetTaxLotRows()[index];
                TaxLot.Archive(adoTransaction, sqlTransaction, childTaxLotRow.RowVersion, childTaxLotRow.TaxLotId);
            }
            for (int index = 0; (index < securityRow.GetViolationRows().Length); index = (index + 1))
            {
                ServerDataModel.ViolationRow childViolationRow = securityRow.GetViolationRows()[index];
                Violation.Archive(adoTransaction, sqlTransaction, childViolationRow.RowVersion, childViolationRow.ViolationId);
            }
            // Increment the row version
            rowVersion = ServerDataModel.RowVersion.Increment();
            // Delete the record in the ADO database.
            securityRow[securityTable.RowVersionColumn] = rowVersion;
            adoTransaction.DataRows.Add(securityRow);
            securityRow.Delete();
            // Archive the record in the SQL database.
            SqlCommand sqlCommand = new SqlCommand("update \"Security\" set \"IsArchived\" = 1 where \"SecurityId\"=@securityId");

            sqlCommand.Connection  = sqlTransaction.Connection;
            sqlCommand.Transaction = sqlTransaction;
            sqlCommand.Parameters.Add(new SqlParameter("@securityId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, securityId));
            sqlCommand.ExecuteNonQuery();
        }
        /// <summary>Updates a Order 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="orderId">The value for the OrderId column.</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 void Update(
            AdoTransaction adoTransaction,
            SqlTransaction sqlTransaction,
            ref long rowVersion,
            int orderId,
            object blockOrderId,
            object accountId,
            object securityId,
            object settlementId,
            object brokerId,
            object positionTypeCode,
            object transactionTypeCode,
            object timeInForceCode,
            object orderTypeCode,
            object conditionCode,
            object isDeleted,
            object isAgency,
            object quantity,
            object price1,
            object price2,
            object note,
            object createdTime,
            object createdUserId,
            object modifiedTime,
            object modifiedUserId)
        {
            // Accessor for the Order Table.
            ServerDataModel.OrderDataTable orderTable = ServerDataModel.Order;
            // Rule #1: Make sure the record exists before updating it.
            ServerDataModel.OrderRow orderRow = orderTable.FindByOrderId(orderId);
            if ((orderRow == null))
            {
                throw new Exception(string.Format("The Order table does not have an element identified by {0}", orderId));
            }
            // Rule #2: Optimistic Concurrency Check
            if ((orderRow.RowVersion != rowVersion))
            {
                throw new System.Exception("This record is busy.  Please try again later.");
            }
            // Apply Defaults
            if ((blockOrderId == null))
            {
                blockOrderId = orderRow[orderTable.BlockOrderIdColumn];
            }
            if ((accountId == null))
            {
                accountId = orderRow[orderTable.AccountIdColumn];
            }
            if ((securityId == null))
            {
                securityId = orderRow[orderTable.SecurityIdColumn];
            }
            if ((settlementId == null))
            {
                settlementId = orderRow[orderTable.SettlementIdColumn];
            }
            if ((brokerId == null))
            {
                brokerId = orderRow[orderTable.BrokerIdColumn];
            }
            if ((positionTypeCode == null))
            {
                positionTypeCode = orderRow[orderTable.PositionTypeCodeColumn];
            }
            if ((transactionTypeCode == null))
            {
                transactionTypeCode = orderRow[orderTable.TransactionTypeCodeColumn];
            }
            if ((timeInForceCode == null))
            {
                timeInForceCode = orderRow[orderTable.TimeInForceCodeColumn];
            }
            if ((orderTypeCode == null))
            {
                orderTypeCode = orderRow[orderTable.OrderTypeCodeColumn];
            }
            if ((conditionCode == null))
            {
                conditionCode = orderRow[orderTable.ConditionCodeColumn];
            }
            if ((isDeleted == null))
            {
                isDeleted = orderRow[orderTable.IsDeletedColumn];
            }
            if ((isAgency == null))
            {
                isAgency = orderRow[orderTable.IsAgencyColumn];
            }
            if ((quantity == null))
            {
                quantity = orderRow[orderTable.QuantityColumn];
            }
            if ((price1 == null))
            {
                price1 = orderRow[orderTable.Price1Column];
            }
            if ((price2 == null))
            {
                price2 = orderRow[orderTable.Price2Column];
            }
            if ((note == null))
            {
                note = orderRow[orderTable.NoteColumn];
            }
            if ((createdTime == null))
            {
                createdTime = orderRow[orderTable.CreatedTimeColumn];
            }
            if ((createdUserId == null))
            {
                createdUserId = orderRow[orderTable.CreatedUserIdColumn];
            }
            if ((modifiedTime == null))
            {
                modifiedTime = orderRow[orderTable.ModifiedTimeColumn];
            }
            if ((modifiedUserId == null))
            {
                modifiedUserId = orderRow[orderTable.ModifiedUserIdColumn];
            }
            // Increment the row version
            rowVersion = ServerDataModel.RowVersion.Increment();
            // Update the record in the ADO database.
            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;
            adoTransaction.DataRows.Add(orderRow);
            // Update the record in the SQL database.
            SqlCommand sqlCommand = new SqlCommand(@"update ""Order"" set ""RowVersion""=@rowVersion,""BlockOrderId""=@blockOrderId,""AccountId""=@accountId,""SecurityId""=@securityId,""SettlementId""=@settlementId,""BrokerId""=@brokerId,""PositionTypeCode""=@positionTypeCode,""TransactionTypeCode""=@transactionTypeCode,""TimeInForceCode""=@timeInForceCode,""OrderTypeCode""=@orderTypeCode,""ConditionCode""=@conditionCode,""IsDeleted""=@isDeleted,""IsAgency""=@isAgency,""Quantity""=@quantity,""Price1""=@price1,""Price2""=@price2,""Note""=@note,""CreatedTime""=@createdTime,""CreatedUserId""=@createdUserId,""ModifiedTime""=@modifiedTime,""ModifiedUserId""=@modifiedUserId where ""OrderId""=@orderId");

            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, orderId));
            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));
            // Update the record in the SQL database.
            sqlCommand.ExecuteNonQuery();
        }
        /// <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);
        }
Exemple #10
0
        /// <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);
        }
Exemple #11
0
 /// <summary>Loads a Order record using Metadata Parameters.</summary>
 /// <param name="transaction">Contains the parameters and exceptions for this command.</param>
 public static void Load(ParameterList parameters)
 {
     // Accessor for the Order Table.
     ServerDataModel.OrderDataTable orderTable = ServerDataModel.Order;
     // Extract the parameters from the command batch.
     AdoTransaction adoTransaction = parameters["adoTransaction"];
     SqlTransaction sqlTransaction = parameters["sqlTransaction"];
     object configurationId = parameters["configurationId"].Value;
     object externalOrderId = parameters["orderId"].Value;
     string externalBlockOrderId = parameters["blockOrderId"];
     string externalAccountId = parameters["accountId"];
     string externalSecurityId = parameters["securityId"];
     string externalSettlementId = parameters["settlementId"];
     object brokerId = parameters["brokerId"].Value;
     int positionTypeCode = parameters["positionTypeCode"];
     string externalTransactionTypeCode = parameters["transactionTypeCode"];
     string externalTimeInForceCode = parameters["timeInForceCode"];
     string externalOrderTypeCode = parameters["orderTypeCode"];
     object conditionCode = parameters["conditionCode"].Value;
     object isDeleted = parameters["isDeleted"].Value;
     object isAgency = parameters["isAgency"].Value;
     decimal quantity = parameters["quantity"];
     object price1 = parameters["price1"].Value;
     object price2 = parameters["price2"].Value;
     object note = parameters["note"].Value;
     System.DateTime createdTime = parameters["createdTime"];
     int createdUserId = parameters["createdUserId"];
     System.DateTime modifiedTime = parameters["modifiedTime"];
     int modifiedUserId = parameters["modifiedUserId"];
     // The row versioning is largely disabled for external operations.  The value is returned to the caller in the
     // event it's needed for operations within the batch.
     long rowVersion = long.MinValue;
     // Resolve External Identifiers
     int accountId = Account.FindRequiredKey(configurationId, "accountId", externalAccountId);
     int securityId = Security.FindRequiredKey(configurationId, "securityId", externalSecurityId);
     int settlementId = Security.FindRequiredKey(configurationId, "settlementId", externalSettlementId);
     int transactionTypeCode = TransactionType.FindRequiredKey(configurationId, "transactionTypeCode", externalTransactionTypeCode);
     int timeInForceCode = TimeInForce.FindRequiredKey(configurationId, "timeInForceCode", externalTimeInForceCode);
     int orderTypeCode = OrderType.FindRequiredKey(configurationId, "orderTypeCode", externalOrderTypeCode);
     // The load operation will create a record if it doesn't exist, or update an existing record.  The external
     // identifier is used to determine if a record exists with the same key.
     if ((orderId == int.MinValue))
     {
         // Populate the 'externalId' varaibles so that the external identifier can be used to find the row when an
         // external method is called with the same 'configurationId' parameter.
         int externalKeyIndex = Order.GetExternalKeyIndex(configurationId, "orderId");
         object[] externalIdArray = new object[0];
         externalIdArray[externalKeyIndex] = externalOrderId;
         // Call the internal method to complete the operation.
         MarkThree.Quasar.Core.Order.Insert(adoTransaction, sqlTransaction, ref rowVersion, blockOrderId, accountId, securityId, settlementId, brokerId, positionTypeCode, transactionTypeCode, timeInForceCode, orderTypeCode, conditionCode, isDeleted, isAgency, quantity, price1, price2, note, createdTime, createdUserId, modifiedTime, modifiedUserId);
     }
     else
     {
         // While the optimistic concurrency checking is disabled for the external methods, the internal methods
         // still need to perform the check.  This ncurrency checking logic by finding the current row version to be
         // will bypass the coused when the internal method is called.
         ServerDataModel.OrderRow orderRow = orderTable.FindByOrderId(orderId);
         rowVersion = ((long)(orderRow[orderTable.RowVersionColumn]));
         // Call the internal method to complete the operation.
         MarkThree.Quasar.Core.Order.Update(adoTransaction, sqlTransaction, ref rowVersion, orderId, blockOrderId, accountId, securityId, settlementId, brokerId, positionTypeCode, transactionTypeCode, timeInForceCode, orderTypeCode, conditionCode, isDeleted, isAgency, quantity, price1, price2, note, createdTime, createdUserId, modifiedTime, modifiedUserId);
     }
     // Return values.
     parameters["rowVersion"] = rowVersion;
 }