Пример #1
0
        /// <summary>Archives a Execution record.</summary>
        /// <param name="transaction">Commits or rejects a set of commands as a unit</param>
        /// <param name="RowVersion">The version number of this row.</param>
        /// <param name="executionId">The value for the ExecutionId column.</param>
        /// <param name="archive">true to archive the object, false to unarchive it.</param>
        public static void Archive(AdoTransaction adoTransaction, SqlTransaction sqlTransaction, long rowVersion, int executionId)
        {
            // Accessor for the Execution Table.
            ServerMarketData.ExecutionDataTable executionTable = ServerMarketData.Execution;
            // Rule #1: Make sure the record exists before updating it.
            ServerMarketData.ExecutionRow executionRow = executionTable.FindByExecutionId(executionId);
            if ((executionRow == null))
            {
                throw new Exception(string.Format("The Execution table does not have an element identified by {0}", executionId));
            }
            // Rule #2: Optimistic Concurrency Check
            if ((executionRow.RowVersion != rowVersion))
            {
                throw new System.Exception("This record is busy.  Please try again later.");
            }
            // Archive the child records.
            for (int index = 0; (index < executionRow.GetNegotiationRows().Length); index = (index + 1))
            {
                ServerMarketData.NegotiationRow childNegotiationRow = executionRow.GetNegotiationRows()[index];
                Negotiation.Archive(adoTransaction, sqlTransaction, childNegotiationRow.RowVersion, childNegotiationRow.NegotiationId);
            }
            // Increment the row version
            rowVersion = ServerMarketData.RowVersion.Increment();
            // Delete the record in the ADO database.
            executionRow[executionTable.RowVersionColumn] = rowVersion;
            adoTransaction.DataRows.Add(executionRow);
            executionRow.Delete();
            // Archive the record in the SQL database.
            SqlCommand sqlCommand = new SqlCommand("update \"Execution\" set \"IsArchived\" = 1 where \"ExecutionId\"=@executionId");

            sqlCommand.Connection  = sqlTransaction.Connection;
            sqlCommand.Transaction = sqlTransaction;
            sqlCommand.Parameters.Add(new SqlParameter("@executionId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, executionId));
            sqlCommand.ExecuteNonQuery();
        }
Пример #2
0
 /// <summary>
 /// Authorizes a WorkingOrder to be returned to the client.
 /// </summary>
 /// <param name="userDataRow">Identifies the current user.</param>
 /// <param name="workingOrderDataRow">The record to be tested for authorization.</param>
 /// <returns>true if the record belongs in the user's hierarchy.</returns>
 public static bool FilterExecution(DataRow userDataRow, DataRow executionDataRow)
 {
     // This will test the record and return true if it belongs to the hierarchies this user is authorized to view.  False
     // if the record should not be included in the user's data model.
     ServerMarketData.UserRow      userRow      = (ServerMarketData.UserRow)userDataRow;
     ServerMarketData.ExecutionRow executionRow = (ServerMarketData.ExecutionRow)executionDataRow;
     return(Hierarchy.IsDescendant(userRow.SystemFolderRow.FolderRow.ObjectRow,
                                   executionRow.DestinationOrderRow.WorkingOrderRow.BlotterRow.ObjectRow));
 }
Пример #3
0
 /// <summary>Updates a Execution 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 Execution Table.
     ServerMarketData.ExecutionDataTable executionTable = ServerMarketData.Execution;
     // Extract the parameters from the command batch.
     AdoTransaction adoTransaction = parameters["adoTransaction"];
     SqlTransaction sqlTransaction = parameters["sqlTransaction"];
     object configurationId = parameters["configurationId"].Value;
     object accruedInterest = parameters["accruedInterest"].Value;
     object externalBrokerAccountId = parameters["brokerAccountId"].Value;
     object externalBrokerId = parameters["brokerId"].Value;
     object commission = parameters["commission"].Value;
     object createdTime = parameters["createdTime"].Value;
     object externalCreatedUserId = parameters["createdUserId"].Value;
     object externalDestinationOrderId = parameters["destinationOrderId"].Value;
     object externalDestinationStateCode = parameters["destinationStateCode"].Value;
     string externalExecutionId = ((string)(parameters["executionId"]));
     object executionPrice = parameters["executionPrice"].Value;
     object executionQuantity = parameters["executionQuantity"].Value;
     object fixMessageId = parameters["fixMessageId"].Value;
     object isHidden = parameters["isHidden"].Value;
     object modifiedTime = parameters["modifiedTime"].Value;
     object externalModifiedUserId = parameters["modifiedUserId"].Value;
     object originalDestinationOrderId = parameters["originalDestinationOrderId"].Value;
     object originalPrice = parameters["originalPrice"].Value;
     object originalQuantity = parameters["originalQuantity"].Value;
     object settlementDate = parameters["settlementDate"].Value;
     object sourceExecutionId = parameters["sourceExecutionId"].Value;
     object externalSourceStateCode = parameters["sourceStateCode"].Value;
     object tradeDate = parameters["tradeDate"].Value;
     object userFee0 = parameters["userFee0"].Value;
     object userFee1 = parameters["userFee1"].Value;
     object userFee2 = parameters["userFee2"].Value;
     object userFee3 = parameters["userFee3"].Value;
     // The row versioning is largely disabled for external operations.
     long rowVersion = long.MinValue;
     // Resolve External Identifiers
     object brokerAccountId = BrokerAccount.FindOptionalKey(configurationId, "brokerAccountId", externalBrokerAccountId);
     object brokerId = Broker.FindOptionalKey(configurationId, "brokerId", externalBrokerId);
     object createdUserId = User.FindOptionalKey(configurationId, "createdUserId", externalCreatedUserId);
     object destinationOrderId = DestinationOrder.FindOptionalKey(configurationId, "destinationOrderId", externalDestinationOrderId);
     object destinationStateCode = State.FindOptionalKey(configurationId, "destinationStateCode", externalDestinationStateCode);
     int executionId = Execution.FindRequiredKey(configurationId, "executionId", externalExecutionId);
     object modifiedUserId = User.FindOptionalKey(configurationId, "modifiedUserId", externalModifiedUserId);
     object sourceStateCode = State.FindOptionalKey(configurationId, "sourceStateCode", externalSourceStateCode);
     // 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.
     ServerMarketData.ExecutionRow executionRow = executionTable.FindByExecutionId(executionId);
     rowVersion = ((long)(executionRow[executionTable.RowVersionColumn]));
     // Call the internal method to complete the operation.
     MarkThree.Guardian.Core.Execution.Update(adoTransaction, sqlTransaction, ref rowVersion, accruedInterest, brokerAccountId, brokerId, commission, createdTime, createdUserId, destinationOrderId, destinationStateCode, executionId, executionPrice, executionQuantity, null, fixMessageId, isHidden, modifiedTime, modifiedUserId, originalDestinationOrderId, originalPrice, originalQuantity, settlementDate, sourceExecutionId, sourceStateCode, tradeDate, userFee0, userFee1, userFee2, userFee3);
     // Return values.
     parameters["rowVersion"] = rowVersion;
 }
Пример #4
0
        /// <summary>Archives a State 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="stateCode">The value for the StateCode 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 stateCode)
        {
            // Accessor for the State Table.
            ServerMarketData.StateDataTable stateTable = ServerMarketData.State;
            // Rule #1: Make sure the record exists before updating it.
            ServerMarketData.StateRow stateRow = stateTable.FindByStateCode(stateCode);
            if ((stateRow == null))
            {
                throw new Exception(string.Format("The State table does not have an element identified by {0}", stateCode));
            }
            // Rule #2: Optimistic Concurrency Check
            if ((stateRow.RowVersion != rowVersion))
            {
                throw new System.Exception("This record is busy.  Please try again later.");
            }
            // Archive the child records.
            for (int index = 0; (index < stateRow.GetDestinationOrderRows().Length); index = (index + 1))
            {
                ServerMarketData.DestinationOrderRow childDestinationOrderRow = stateRow.GetDestinationOrderRows()[index];
                DestinationOrder.Archive(adoTransaction, sqlTransaction, childDestinationOrderRow.RowVersion, childDestinationOrderRow.DestinationOrderId);
            }
            for (int index = 0; (index < stateRow.GetExecutionRowsByStateExecutionDestinationStateCode().Length); index = (index + 1))
            {
                ServerMarketData.ExecutionRow childExecutionRow = stateRow.GetExecutionRowsByStateExecutionDestinationStateCode()[index];
                Execution.Archive(adoTransaction, sqlTransaction, childExecutionRow.RowVersion, childExecutionRow.ExecutionId);
            }
            for (int index = 0; (index < stateRow.GetExecutionRowsByStateExecutionSourceStateCode().Length); index = (index + 1))
            {
                ServerMarketData.ExecutionRow childExecutionRow = stateRow.GetExecutionRowsByStateExecutionSourceStateCode()[index];
                Execution.Archive(adoTransaction, sqlTransaction, childExecutionRow.RowVersion, childExecutionRow.ExecutionId);
            }
            // Increment the row version
            rowVersion = ServerMarketData.RowVersion.Increment();
            // Delete the record in the ADO database.
            stateRow[stateTable.RowVersionColumn] = rowVersion;
            adoTransaction.DataRows.Add(stateRow);
            stateRow.Delete();
            // Archive the record in the SQL database.
            SqlCommand sqlCommand = new SqlCommand("update \"State\" set \"IsArchived\" = 1 where \"StateCode\"=@stateCode");

            sqlCommand.Connection  = sqlTransaction.Connection;
            sqlCommand.Transaction = sqlTransaction;
            sqlCommand.Parameters.Add(new SqlParameter("@stateCode", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, stateCode));
            sqlCommand.ExecuteNonQuery();
        }
Пример #5
0
        /// <summary>Deletes a Execution record.</summary>
        /// <param name="transaction">Commits or rejects a set of commands as a unit</param>
        /// <param name="executionId">The value for the ExecutionId column.</param>
        /// <param name="rowVersion">The value for the RowVersion column.</param>
        public static void Delete(Transaction transaction, int executionId, long rowVersion)
        {
            // Accessor for the Execution Table.
            ServerMarketData.ExecutionDataTable executionTable = ServerMarketData.Execution;
            // Rule #1: Make sure the record exists before updating it.
            ServerMarketData.ExecutionRow executionRow = executionTable.FindByExecutionId(executionId);
            if ((executionRow == null))
            {
                throw new Exception(string.Format("The Execution table does not have an element identified by {0}", executionId));
            }
            // Rule #2: Optimistic Concurrency Check
            if ((executionRow.RowVersion != rowVersion))
            {
                throw new System.Exception("This record is busy.  Please try again later.");
            }
            // Provide the modified time and current user id to the base class.
            int      modifiedLoginId = ServerMarketData.LoginId;
            DateTime modifiedTime    = DateTime.Now;

            // Delete the child records.
            // Delete the record in the ADO database.
            transaction.DataRows.Add(executionRow);
            executionRow.Delete();
            // Delete the record in the SQL database.
            SqlCommand updateCommand = new SqlCommand(@"update ""Execution"" set ""ModifiedTime""=@modifiedTime,""ModifiedLoginId""=@modifiedLoginId where ""ExecutionId""=@executionId");

            updateCommand.Connection  = transaction.SqlConnection;
            updateCommand.Transaction = transaction.SqlTransaction;
            updateCommand.Parameters.Add("@executionId", @executionId);
            updateCommand.Parameters.Add("@modifiedTime", modifiedTime);
            updateCommand.Parameters.Add("@modifiedLoginId", modifiedLoginId);
            updateCommand.ExecuteNonQuery();
            // Delete the record in the SQL database.
            SqlCommand deleteCommand = new SqlCommand(@"delete ""Execution"" where ""ExecutionId""=@executionId");

            deleteCommand.Connection  = transaction.SqlConnection;
            deleteCommand.Transaction = transaction.SqlTransaction;
            deleteCommand.Parameters.Add("@executionId", @executionId);
            deleteCommand.ExecuteNonQuery();
        }
Пример #6
0
 /// <summary>Archives a Execution 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 Execution Table.
     ServerMarketData.ExecutionDataTable executionTable = ServerMarketData.Execution;
     // Extract the parameters from the command batch.
     AdoTransaction adoTransaction = parameters["adoTransaction"];
     SqlTransaction sqlTransaction = parameters["sqlTransaction"];
     object configurationId = parameters["configurationId"].Value;
     string externalExecutionId = parameters["executionId"];
     // 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 executionId = Execution.FindRequiredKey(configurationId, "executionId", externalExecutionId);
     // 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.
     ServerMarketData.ExecutionRow executionRow = executionTable.FindByExecutionId(executionId);
     rowVersion = ((long)(executionRow[executionTable.RowVersionColumn]));
     // Call the internal method to complete the operation.
     MarkThree.Guardian.Core.Execution.Archive(adoTransaction, sqlTransaction, rowVersion, executionId);
 }
Пример #7
0
        /// <summary>ArchiveChildrens a Broker 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="brokerId">The value for the BrokerId column.</param>
        /// <param name="archive">true to archive the object, false to unarchive it.</param>
        internal new static void ArchiveChildren(AdoTransaction adoTransaction, SqlTransaction sqlTransaction, long rowVersion, int brokerId)
        {
            // Accessor for the Broker Table.
            ServerMarketData.BrokerDataTable brokerTable = ServerMarketData.Broker;
            // This record can be used to iterate through all the children.
            ServerMarketData.BrokerRow brokerRow = brokerTable.FindByBrokerId(brokerId);
            // Archive the child records.
            for (int index = 0; (index < brokerRow.GetExecutionRows().Length); index = (index + 1))
            {
                ServerMarketData.ExecutionRow childExecutionRow = brokerRow.GetExecutionRows()[index];
                Execution.Archive(adoTransaction, sqlTransaction, childExecutionRow.RowVersion, childExecutionRow.ExecutionId);
            }
            for (int index = 0; (index < brokerRow.GetBrokerAccountRows().Length); index = (index + 1))
            {
                ServerMarketData.BrokerAccountRow childBrokerAccountRow = brokerRow.GetBrokerAccountRows()[index];
                BrokerAccount.Archive(adoTransaction, sqlTransaction, childBrokerAccountRow.RowVersion, childBrokerAccountRow.BrokerAccountId);
            }
            for (int index = 0; (index < brokerRow.GetClearingBrokerRows().Length); index = (index + 1))
            {
                ServerMarketData.ClearingBrokerRow childClearingBrokerRow = brokerRow.GetClearingBrokerRows()[index];
                ClearingBroker.ArchiveChildren(adoTransaction, sqlTransaction, childClearingBrokerRow.RowVersion, childClearingBrokerRow.ClearingBrokerId);
            }
            // Increment the row version
            rowVersion = ServerMarketData.RowVersion.Increment();
            // Delete the record in the ADO database.
            brokerRow[brokerTable.RowVersionColumn] = rowVersion;
            adoTransaction.DataRows.Add(brokerRow);
            brokerRow.Delete();
            // Archive the record in the SQL database.
            SqlCommand sqlCommand = new SqlCommand("update \"Broker\" set \"IsArchived\" = 1 where \"BrokerId\"=@brokerId");

            sqlCommand.Connection  = sqlTransaction.Connection;
            sqlCommand.Transaction = sqlTransaction;
            sqlCommand.Parameters.Add(new SqlParameter("@brokerId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, brokerId));
            sqlCommand.ExecuteNonQuery();
        }
Пример #8
0
        /// <summary>Inserts a Execution record using Metadata Parameters.</summary>
        /// <param name="transaction">Commits or rejects a set of commands as a unit.</param>
        /// <param name="remoteMethod">Contains the metadata parameters and exceptions for this command.</param>
        public static void InsertFile(ParameterList parameters)
        {
            // Accessor for the Execution Table.
            ServerMarketData.ExecutionDataTable executionTable = ServerMarketData.Execution;

            // Extract the parameters from the command batch.
            AdoTransaction adoTransaction             = parameters["adoTransaction"];
            SqlTransaction sqlTransaction             = parameters["sqlTransaction"];
            object         configurationId            = parameters["configurationId"].Value;
            object         sourceExecutionId          = parameters["sourceExecutionId"].Value;
            string         externalDestinationOrderId = parameters["destinationOrderId"];
            object         externalExecutionId        = parameters["executionId"].Value;
            object         externalId0 = parameters["externalId0"].Value;

            System.Decimal  executionPrice    = parameters["executionPrice"];
            System.Decimal  executionQuantity = parameters["executionQuantity"];
            System.DateTime settlementDate    = parameters["settlementDate"];
            System.DateTime tradeDate         = parameters["tradeDate"];

            // Resolve External Identifiers
            int destinationOrderId = External.DestinationOrder.FindRequiredKey(configurationId, "destinationOrderId", externalDestinationOrderId);
            int executionId        = External.Execution.FindKey(configurationId, "executionId", (string)externalExecutionId);

            // 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;

            // Optional Parameters
            object accruedInterest = parameters["accruedInterest"] is MissingParameter ? (object)null :
                                     Convert.ToDecimal(parameters["accruedInterest"].Value);
            object commission = parameters["commission"] is MissingParameter ? (object)null :
                                Convert.ToDecimal(parameters["commission"].Value);
            object isHidden = parameters["isHidden"] is MissingParameter ? (object)null :
                              Convert.ToBoolean(parameters["isHidden"].Value);
            object userFee0 = parameters["userFee0"] is MissingParameter ? (object)null :
                              Convert.ToDecimal(parameters["userFee0"].Value);
            object userFee1 = parameters["userFee1"] is MissingParameter ? (object)null :
                              Convert.ToDecimal(parameters["userFee1"].Value);
            object userFee2 = parameters["userFee2"] is MissingParameter ? (object)null :
                              Convert.ToDecimal(parameters["userFee2"].Value);
            object userFee3 = parameters["userFee3"] is MissingParameter ? (object)null :
                              Convert.ToDecimal(parameters["userFee3"].Value);

            // Default Status codes
            int destinationStateCode = State.Acknowledged;
            int sourceStateCode      = State.Initial;

            // Time stamps and user stamps
            int      createdUserId  = ServerMarketData.UserId;
            DateTime createdTime    = DateTime.Now;
            int      modifiedUserId = ServerMarketData.UserId;
            DateTime modifiedTime   = DateTime.Now;

            // 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 ((executionId == 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 = External.Execution.GetExternalKeyIndex(configurationId, "executionId");
                object[] externalIdArray  = new object[1];
                externalIdArray[externalKeyIndex] = externalExecutionId;
                externalId0 = externalIdArray[0];

                // Call the internal method to complete the operation.
                MarkThree.Guardian.Core.Execution.Insert(adoTransaction, sqlTransaction, ref rowVersion, accruedInterest,
                                                         null, null, commission, createdTime, createdUserId, destinationOrderId, destinationStateCode, executionPrice,
                                                         executionQuantity, externalId0, null, isHidden, modifiedTime, modifiedUserId, null, null, null,
                                                         settlementDate, sourceExecutionId, sourceStateCode, tradeDate, userFee0, userFee1, userFee2, userFee3);
            }
            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.
                ServerMarketData.ExecutionRow executionRow = executionTable.FindByExecutionId(executionId);
                rowVersion = ((long)(executionRow[executionTable.RowVersionColumn]));

                // Call the internal method to complete the operation.
                MarkThree.Guardian.Core.Execution.Update(adoTransaction, sqlTransaction, ref rowVersion, accruedInterest,
                                                         null, null, commission, createdTime, createdUserId, destinationOrderId, destinationStateCode, executionId,
                                                         executionPrice, executionQuantity, externalId0, null, isHidden, modifiedTime, modifiedUserId, null, null,
                                                         null, settlementDate, sourceExecutionId, sourceStateCode, tradeDate, userFee0, userFee1, userFee2, userFee3);
            }

            // Return values.
            parameters["rowVersion"] = rowVersion;
        }
Пример #9
0
        /// <summary>ArchiveChildrens a User 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="userId">The value for the UserId 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 userId)
        {
            // Accessor for the User Table.
            ServerMarketData.UserDataTable userTable = ServerMarketData.User;
            // This record can be used to iterate through all the children.
            ServerMarketData.UserRow userRow = userTable.FindByUserId(userId);
            // Archive the child records.
            for (int index = 0; (index < userRow.GetAccountBaseRows().Length); index = (index + 1))
            {
                ServerMarketData.AccountBaseRow childAccountBaseRow = userRow.GetAccountBaseRows()[index];
                AccountBase.ArchiveChildren(adoTransaction, sqlTransaction, childAccountBaseRow.RowVersion, childAccountBaseRow.AccountBaseId);
            }
            for (int index = 0; (index < userRow.GetAllocationRowsByUserAllocationCreatedUserId().Length); index = (index + 1))
            {
                ServerMarketData.AllocationRow childAllocationRow = userRow.GetAllocationRowsByUserAllocationCreatedUserId()[index];
                Allocation.Archive(adoTransaction, sqlTransaction, childAllocationRow.RowVersion, childAllocationRow.AllocationId);
            }
            for (int index = 0; (index < userRow.GetAllocationRowsByUserAllocationModifiedUserId().Length); index = (index + 1))
            {
                ServerMarketData.AllocationRow childAllocationRow = userRow.GetAllocationRowsByUserAllocationModifiedUserId()[index];
                Allocation.Archive(adoTransaction, sqlTransaction, childAllocationRow.RowVersion, childAllocationRow.AllocationId);
            }
            for (int index = 0; (index < userRow.GetComplianceOfficerRows().Length); index = (index + 1))
            {
                ServerMarketData.ComplianceOfficerRow childComplianceOfficerRow = userRow.GetComplianceOfficerRows()[index];
                ComplianceOfficer.ArchiveChildren(adoTransaction, sqlTransaction, childComplianceOfficerRow.RowVersion, childComplianceOfficerRow.ComplianceOfficerId);
            }
            for (int index = 0; (index < userRow.GetExecutionRowsByUserExecutionCreatedUserId().Length); index = (index + 1))
            {
                ServerMarketData.ExecutionRow childExecutionRow = userRow.GetExecutionRowsByUserExecutionCreatedUserId()[index];
                Execution.Archive(adoTransaction, sqlTransaction, childExecutionRow.RowVersion, childExecutionRow.ExecutionId);
            }
            for (int index = 0; (index < userRow.GetExecutionRowsByUserExecutionModifiedUserId().Length); index = (index + 1))
            {
                ServerMarketData.ExecutionRow childExecutionRow = userRow.GetExecutionRowsByUserExecutionModifiedUserId()[index];
                Execution.Archive(adoTransaction, sqlTransaction, childExecutionRow.RowVersion, childExecutionRow.ExecutionId);
            }
            for (int index = 0; (index < userRow.GetSourceOrderRowsByUserSourceOrderCreatedUserId().Length); index = (index + 1))
            {
                ServerMarketData.SourceOrderRow childSourceOrderRow = userRow.GetSourceOrderRowsByUserSourceOrderCreatedUserId()[index];
                SourceOrder.Archive(adoTransaction, sqlTransaction, childSourceOrderRow.RowVersion, childSourceOrderRow.SourceOrderId);
            }
            for (int index = 0; (index < userRow.GetSourceOrderRowsByUserSourceOrderModifiedUserId().Length); index = (index + 1))
            {
                ServerMarketData.SourceOrderRow childSourceOrderRow = userRow.GetSourceOrderRowsByUserSourceOrderModifiedUserId()[index];
                SourceOrder.Archive(adoTransaction, sqlTransaction, childSourceOrderRow.RowVersion, childSourceOrderRow.SourceOrderId);
            }
            for (int index = 0; (index < userRow.GetTraderRows().Length); index = (index + 1))
            {
                ServerMarketData.TraderRow childTraderRow = userRow.GetTraderRows()[index];
                Trader.ArchiveChildren(adoTransaction, sqlTransaction, childTraderRow.RowVersion, childTraderRow.TraderId);
            }
            for (int index = 0; (index < userRow.GetWorkingOrderRowsByUserWorkingOrderCreatedUserId().Length); index = (index + 1))
            {
                ServerMarketData.WorkingOrderRow childWorkingOrderRow = userRow.GetWorkingOrderRowsByUserWorkingOrderCreatedUserId()[index];
                WorkingOrder.Archive(adoTransaction, sqlTransaction, childWorkingOrderRow.RowVersion, childWorkingOrderRow.WorkingOrderId);
            }
            for (int index = 0; (index < userRow.GetWorkingOrderRowsByUserWorkingOrderModifiedUserId().Length); index = (index + 1))
            {
                ServerMarketData.WorkingOrderRow childWorkingOrderRow = userRow.GetWorkingOrderRowsByUserWorkingOrderModifiedUserId()[index];
                WorkingOrder.Archive(adoTransaction, sqlTransaction, childWorkingOrderRow.RowVersion, childWorkingOrderRow.WorkingOrderId);
            }
            // Increment the row version
            rowVersion = ServerMarketData.RowVersion.Increment();
            // Delete the record in the ADO database.
            userRow[userTable.RowVersionColumn] = rowVersion;
            adoTransaction.DataRows.Add(userRow);
            userRow.Delete();
            // Archive the record in the SQL database.
            SqlCommand sqlCommand = new SqlCommand("update \"User\" set \"IsArchived\" = 1 where \"UserId\"=@userId");

            sqlCommand.Connection  = sqlTransaction.Connection;
            sqlCommand.Transaction = sqlTransaction;
            sqlCommand.Parameters.Add(new SqlParameter("@userId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, userId));
            sqlCommand.ExecuteNonQuery();
        }
Пример #10
0
        /// <summary>Updates a Execution record.</summary>
        /// <param name="transaction">Commits or rejects a set of commands as a unit</param>
        /// <param name="rowVersion">The version number of the row</param>
        /// <param name="accruedInterest">The value for the AccruedInterest column.</param>
        /// <param name="brokerAccountId">The value for the BrokerAccountId column.</param>
        /// <param name="brokerId">The value for the BrokerId column.</param>
        /// <param name="commission">The value for the Commission column.</param>
        /// <param name="createdTime">The value for the CreatedTime column.</param>
        /// <param name="createdUserId">The value for the CreatedUserId column.</param>
        /// <param name="destinationOrderId">The value for the DestinationOrderId column.</param>
        /// <param name="destinationStateCode">The value for the DestinationStateCode column.</param>
        /// <param name="executionId">The value for the ExecutionId column.</param>
        /// <param name="executionPrice">The value for the ExecutionPrice column.</param>
        /// <param name="executionQuantity">The value for the ExecutionQuantity column.</param>
        /// <param name="externalId0">The value for the ExternalId0 column.</param>
        /// <param name="fixMessageId">The value for the FixMessageId column.</param>
        /// <param name="isHidden">The value for the IsHidden column.</param>
        /// <param name="modifiedTime">The value for the ModifiedTime column.</param>
        /// <param name="modifiedUserId">The value for the ModifiedUserId column.</param>
        /// <param name="originalDestinationOrderId">The value for the OriginalDestinationOrderId column.</param>
        /// <param name="originalPrice">The value for the OriginalPrice column.</param>
        /// <param name="originalQuantity">The value for the OriginalQuantity column.</param>
        /// <param name="settlementDate">The value for the SettlementDate column.</param>
        /// <param name="sourceExecutionId">The value for the SourceExecutionId column.</param>
        /// <param name="sourceStateCode">The value for the SourceStateCode column.</param>
        /// <param name="tradeDate">The value for the TradeDate column.</param>
        /// <param name="userFee0">The value for the UserFee0 column.</param>
        /// <param name="userFee1">The value for the UserFee1 column.</param>
        /// <param name="userFee2">The value for the UserFee2 column.</param>
        /// <param name="userFee3">The value for the UserFee3 column.</param>
        public static void Update(
            AdoTransaction adoTransaction,
            SqlTransaction sqlTransaction,
            ref long rowVersion,
            object accruedInterest,
            object brokerAccountId,
            object brokerId,
            object commission,
            object createdTime,
            object createdUserId,
            object destinationOrderId,
            object destinationStateCode,
            int executionId,
            object executionPrice,
            object executionQuantity,
            object externalId0,
            object fixMessageId,
            object isHidden,
            object modifiedTime,
            object modifiedUserId,
            object originalDestinationOrderId,
            object originalPrice,
            object originalQuantity,
            object settlementDate,
            object sourceExecutionId,
            object sourceStateCode,
            object tradeDate,
            object userFee0,
            object userFee1,
            object userFee2,
            object userFee3)
        {
            // Accessor for the Execution Table.
            ServerMarketData.ExecutionDataTable executionTable = ServerMarketData.Execution;
            // Rule #1: Make sure the record exists before updating it.
            ServerMarketData.ExecutionRow executionRow = executionTable.FindByExecutionId(executionId);
            if ((executionRow == null))
            {
                throw new Exception(string.Format("The Execution table does not have an element identified by {0}", executionId));
            }
            // Rule #2: Optimistic Concurrency Check
            if ((executionRow.RowVersion != rowVersion))
            {
                throw new System.Exception("This record is busy.  Please try again later.");
            }
            // Apply Defaults
            if ((accruedInterest == null))
            {
                accruedInterest = executionRow[executionTable.AccruedInterestColumn];
            }
            if ((brokerAccountId == null))
            {
                brokerAccountId = executionRow[executionTable.BrokerAccountIdColumn];
            }
            if ((brokerId == null))
            {
                brokerId = executionRow[executionTable.BrokerIdColumn];
            }
            if ((commission == null))
            {
                commission = executionRow[executionTable.CommissionColumn];
            }
            if ((createdTime == null))
            {
                createdTime = executionRow[executionTable.CreatedTimeColumn];
            }
            if ((createdUserId == null))
            {
                createdUserId = executionRow[executionTable.CreatedUserIdColumn];
            }
            if ((destinationOrderId == null))
            {
                destinationOrderId = executionRow[executionTable.DestinationOrderIdColumn];
            }
            if ((destinationStateCode == null))
            {
                destinationStateCode = executionRow[executionTable.DestinationStateCodeColumn];
            }
            if ((executionPrice == null))
            {
                executionPrice = executionRow[executionTable.ExecutionPriceColumn];
            }
            if ((executionQuantity == null))
            {
                executionQuantity = executionRow[executionTable.ExecutionQuantityColumn];
            }
            if ((externalId0 == null))
            {
                externalId0 = executionRow[executionTable.ExternalId0Column];
            }
            if ((fixMessageId == null))
            {
                fixMessageId = executionRow[executionTable.FixMessageIdColumn];
            }
            if ((isHidden == null))
            {
                isHidden = executionRow[executionTable.IsHiddenColumn];
            }
            if ((modifiedTime == null))
            {
                modifiedTime = executionRow[executionTable.ModifiedTimeColumn];
            }
            if ((modifiedUserId == null))
            {
                modifiedUserId = executionRow[executionTable.ModifiedUserIdColumn];
            }
            if ((originalDestinationOrderId == null))
            {
                originalDestinationOrderId = executionRow[executionTable.OriginalDestinationOrderIdColumn];
            }
            if ((originalPrice == null))
            {
                originalPrice = executionRow[executionTable.OriginalPriceColumn];
            }
            if ((originalQuantity == null))
            {
                originalQuantity = executionRow[executionTable.OriginalQuantityColumn];
            }
            if ((settlementDate == null))
            {
                settlementDate = executionRow[executionTable.SettlementDateColumn];
            }
            if ((sourceExecutionId == null))
            {
                sourceExecutionId = executionRow[executionTable.SourceExecutionIdColumn];
            }
            if ((sourceStateCode == null))
            {
                sourceStateCode = executionRow[executionTable.SourceStateCodeColumn];
            }
            if ((tradeDate == null))
            {
                tradeDate = executionRow[executionTable.TradeDateColumn];
            }
            if ((userFee0 == null))
            {
                userFee0 = executionRow[executionTable.UserFee0Column];
            }
            if ((userFee1 == null))
            {
                userFee1 = executionRow[executionTable.UserFee1Column];
            }
            if ((userFee2 == null))
            {
                userFee2 = executionRow[executionTable.UserFee2Column];
            }
            if ((userFee3 == null))
            {
                userFee3 = executionRow[executionTable.UserFee3Column];
            }
            // Increment the row version
            rowVersion = ServerMarketData.RowVersion.Increment();
            // Update the record in the ADO database.
            executionRow[executionTable.RowVersionColumn]                 = rowVersion;
            executionRow[executionTable.AccruedInterestColumn]            = accruedInterest;
            executionRow[executionTable.BrokerAccountIdColumn]            = brokerAccountId;
            executionRow[executionTable.BrokerIdColumn]                   = brokerId;
            executionRow[executionTable.CommissionColumn]                 = commission;
            executionRow[executionTable.CreatedTimeColumn]                = createdTime;
            executionRow[executionTable.CreatedUserIdColumn]              = createdUserId;
            executionRow[executionTable.DestinationOrderIdColumn]         = destinationOrderId;
            executionRow[executionTable.DestinationStateCodeColumn]       = destinationStateCode;
            executionRow[executionTable.ExecutionPriceColumn]             = executionPrice;
            executionRow[executionTable.ExecutionQuantityColumn]          = executionQuantity;
            executionRow[executionTable.ExternalId0Column]                = externalId0;
            executionRow[executionTable.FixMessageIdColumn]               = fixMessageId;
            executionRow[executionTable.IsHiddenColumn]                   = isHidden;
            executionRow[executionTable.ModifiedTimeColumn]               = modifiedTime;
            executionRow[executionTable.ModifiedUserIdColumn]             = modifiedUserId;
            executionRow[executionTable.OriginalDestinationOrderIdColumn] = originalDestinationOrderId;
            executionRow[executionTable.OriginalPriceColumn]              = originalPrice;
            executionRow[executionTable.OriginalQuantityColumn]           = originalQuantity;
            executionRow[executionTable.SettlementDateColumn]             = settlementDate;
            executionRow[executionTable.SourceExecutionIdColumn]          = sourceExecutionId;
            executionRow[executionTable.SourceStateCodeColumn]            = sourceStateCode;
            executionRow[executionTable.TradeDateColumn]                  = tradeDate;
            executionRow[executionTable.UserFee0Column]                   = userFee0;
            executionRow[executionTable.UserFee1Column]                   = userFee1;
            executionRow[executionTable.UserFee2Column]                   = userFee2;
            executionRow[executionTable.UserFee3Column]                   = userFee3;
            adoTransaction.DataRows.Add(executionRow);
            // Update the record in the SQL database.
            SqlCommand sqlCommand = new SqlCommand(@"update ""Execution"" set ""RowVersion""=@rowVersion,""AccruedInterest""=@accruedInterest,""BrokerAccountId""=@brokerAccountId,""BrokerId""=@brokerId,""Commission""=@commission,""CreatedTime""=@createdTime,""CreatedUserId""=@createdUserId,""DestinationOrderId""=@destinationOrderId,""DestinationStateCode""=@destinationStateCode,""ExecutionPrice""=@executionPrice,""ExecutionQuantity""=@executionQuantity,""ExternalId0""=@externalId0,""FixMessageId""=@fixMessageId,""IsHidden""=@isHidden,""ModifiedTime""=@modifiedTime,""ModifiedUserId""=@modifiedUserId,""OriginalDestinationOrderId""=@originalDestinationOrderId,""OriginalPrice""=@originalPrice,""OriginalQuantity""=@originalQuantity,""SettlementDate""=@settlementDate,""SourceExecutionId""=@sourceExecutionId,""SourceStateCode""=@sourceStateCode,""TradeDate""=@tradeDate,""UserFee0""=@userFee0,""UserFee1""=@userFee1,""UserFee2""=@userFee2,""UserFee3""=@userFee3 where ""ExecutionId""=@executionId");

            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("@accruedInterest", SqlDbType.Decimal, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, accruedInterest));
            sqlCommand.Parameters.Add(new SqlParameter("@brokerAccountId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, brokerAccountId));
            sqlCommand.Parameters.Add(new SqlParameter("@brokerId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, brokerId));
            sqlCommand.Parameters.Add(new SqlParameter("@commission", SqlDbType.Decimal, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, commission));
            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("@destinationOrderId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, destinationOrderId));
            sqlCommand.Parameters.Add(new SqlParameter("@destinationStateCode", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, destinationStateCode));
            sqlCommand.Parameters.Add(new SqlParameter("@executionId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, executionId));
            sqlCommand.Parameters.Add(new SqlParameter("@executionPrice", SqlDbType.Decimal, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, executionPrice));
            sqlCommand.Parameters.Add(new SqlParameter("@executionQuantity", SqlDbType.Decimal, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, executionQuantity));
            sqlCommand.Parameters.Add(new SqlParameter("@externalId0", SqlDbType.NVarChar, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, externalId0));
            sqlCommand.Parameters.Add(new SqlParameter("@fixMessageId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, fixMessageId));
            sqlCommand.Parameters.Add(new SqlParameter("@isHidden", SqlDbType.Bit, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, isHidden));
            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.Parameters.Add(new SqlParameter("@originalDestinationOrderId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, originalDestinationOrderId));
            sqlCommand.Parameters.Add(new SqlParameter("@originalPrice", SqlDbType.Decimal, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, originalPrice));
            sqlCommand.Parameters.Add(new SqlParameter("@originalQuantity", SqlDbType.Decimal, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, originalQuantity));
            sqlCommand.Parameters.Add(new SqlParameter("@settlementDate", SqlDbType.DateTime, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, settlementDate));
            sqlCommand.Parameters.Add(new SqlParameter("@sourceExecutionId", SqlDbType.NVarChar, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, sourceExecutionId));
            sqlCommand.Parameters.Add(new SqlParameter("@sourceStateCode", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, sourceStateCode));
            sqlCommand.Parameters.Add(new SqlParameter("@tradeDate", SqlDbType.DateTime, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, tradeDate));
            sqlCommand.Parameters.Add(new SqlParameter("@userFee0", SqlDbType.Decimal, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, userFee0));
            sqlCommand.Parameters.Add(new SqlParameter("@userFee1", SqlDbType.Decimal, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, userFee1));
            sqlCommand.Parameters.Add(new SqlParameter("@userFee2", SqlDbType.Decimal, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, userFee2));
            sqlCommand.Parameters.Add(new SqlParameter("@userFee3", SqlDbType.Decimal, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, userFee3));
            // Update the record in the SQL database.
            sqlCommand.ExecuteNonQuery();
        }
Пример #11
0
        /// <summary>Inserts a Execution record.</summary>
        /// <param name="transaction">Commits or rejects a set of commands as a unit</param>
        /// <param name="accruedInterest">The value for the AccruedInterest column.</param>
        /// <param name="brokerAccountId">The value for the BrokerAccountId column.</param>
        /// <param name="brokerId">The value for the BrokerId column.</param>
        /// <param name="commission">The value for the Commission column.</param>
        /// <param name="createdTime">The value for the CreatedTime column.</param>
        /// <param name="createdUserId">The value for the CreatedUserId column.</param>
        /// <param name="destinationOrderId">The value for the DestinationOrderId column.</param>
        /// <param name="destinationStateCode">The value for the DestinationStateCode column.</param>
        /// <param name="executionPrice">The value for the ExecutionPrice column.</param>
        /// <param name="executionQuantity">The value for the ExecutionQuantity column.</param>
        /// <param name="externalId0">The value for the ExternalId0 column.</param>
        /// <param name="fixMessageId">The value for the FixMessageId column.</param>
        /// <param name="isHidden">The value for the IsHidden column.</param>
        /// <param name="modifiedTime">The value for the ModifiedTime column.</param>
        /// <param name="modifiedUserId">The value for the ModifiedUserId column.</param>
        /// <param name="originalDestinationOrderId">The value for the OriginalDestinationOrderId column.</param>
        /// <param name="originalPrice">The value for the OriginalPrice column.</param>
        /// <param name="originalQuantity">The value for the OriginalQuantity column.</param>
        /// <param name="settlementDate">The value for the SettlementDate column.</param>
        /// <param name="sourceExecutionId">The value for the SourceExecutionId column.</param>
        /// <param name="sourceStateCode">The value for the SourceStateCode column.</param>
        /// <param name="tradeDate">The value for the TradeDate column.</param>
        /// <param name="userFee0">The value for the UserFee0 column.</param>
        /// <param name="userFee1">The value for the UserFee1 column.</param>
        /// <param name="userFee2">The value for the UserFee2 column.</param>
        /// <param name="userFee3">The value for the UserFee3 column.</param>
        public static int Insert(
            AdoTransaction adoTransaction,
            SqlTransaction sqlTransaction,
            ref long rowVersion,
            object accruedInterest,
            object brokerAccountId,
            object brokerId,
            object commission,
            object createdTime,
            object createdUserId,
            int destinationOrderId,
            int destinationStateCode,
            decimal executionPrice,
            decimal executionQuantity,
            object externalId0,
            object fixMessageId,
            object isHidden,
            object modifiedTime,
            object modifiedUserId,
            object originalDestinationOrderId,
            object originalPrice,
            object originalQuantity,
            System.DateTime settlementDate,
            object sourceExecutionId,
            int sourceStateCode,
            System.DateTime tradeDate,
            object userFee0,
            object userFee1,
            object userFee2,
            object userFee3)
        {
            // Accessor for the Execution Table.
            ServerMarketData.ExecutionDataTable executionTable = ServerMarketData.Execution;
            // Apply Defaults
            if ((accruedInterest == null))
            {
                accruedInterest = 0.0m;
            }
            if ((brokerAccountId == null))
            {
                brokerAccountId = System.DBNull.Value;
            }
            if ((brokerId == null))
            {
                brokerId = System.DBNull.Value;
            }
            if ((commission == null))
            {
                commission = 0.0m;
            }
            if ((createdTime == null))
            {
                createdTime = System.DBNull.Value;
            }
            if ((createdUserId == null))
            {
                createdUserId = System.DBNull.Value;
            }
            if ((externalId0 == null))
            {
                externalId0 = System.DBNull.Value;
            }
            if ((fixMessageId == null))
            {
                fixMessageId = System.DBNull.Value;
            }
            if ((isHidden == null))
            {
                isHidden = false;
            }
            if ((modifiedTime == null))
            {
                modifiedTime = System.DBNull.Value;
            }
            if ((modifiedUserId == null))
            {
                modifiedUserId = System.DBNull.Value;
            }
            if ((originalDestinationOrderId == null))
            {
                originalDestinationOrderId = System.DBNull.Value;
            }
            if ((originalPrice == null))
            {
                originalPrice = System.DBNull.Value;
            }
            if ((originalQuantity == null))
            {
                originalQuantity = System.DBNull.Value;
            }
            if ((sourceExecutionId == null))
            {
                sourceExecutionId = System.DBNull.Value;
            }
            if ((userFee0 == null))
            {
                userFee0 = 0.0m;
            }
            if ((userFee1 == null))
            {
                userFee1 = 0.0m;
            }
            if ((userFee2 == null))
            {
                userFee2 = 0.0m;
            }
            if ((userFee3 == null))
            {
                userFee3 = 0.0m;
            }
            // Increment the row version
            rowVersion = ServerMarketData.RowVersion.Increment();
            // Insert the record into the ADO database.
            ServerMarketData.ExecutionRow executionRow = executionTable.NewExecutionRow();
            executionRow[executionTable.RowVersionColumn]                 = rowVersion;
            executionRow[executionTable.AccruedInterestColumn]            = accruedInterest;
            executionRow[executionTable.BrokerAccountIdColumn]            = brokerAccountId;
            executionRow[executionTable.BrokerIdColumn]                   = brokerId;
            executionRow[executionTable.CommissionColumn]                 = commission;
            executionRow[executionTable.CreatedTimeColumn]                = createdTime;
            executionRow[executionTable.CreatedUserIdColumn]              = createdUserId;
            executionRow[executionTable.DestinationOrderIdColumn]         = destinationOrderId;
            executionRow[executionTable.DestinationStateCodeColumn]       = destinationStateCode;
            executionRow[executionTable.ExecutionPriceColumn]             = executionPrice;
            executionRow[executionTable.ExecutionQuantityColumn]          = executionQuantity;
            executionRow[executionTable.ExternalId0Column]                = externalId0;
            executionRow[executionTable.FixMessageIdColumn]               = fixMessageId;
            executionRow[executionTable.IsHiddenColumn]                   = isHidden;
            executionRow[executionTable.ModifiedTimeColumn]               = modifiedTime;
            executionRow[executionTable.ModifiedUserIdColumn]             = modifiedUserId;
            executionRow[executionTable.OriginalDestinationOrderIdColumn] = originalDestinationOrderId;
            executionRow[executionTable.OriginalPriceColumn]              = originalPrice;
            executionRow[executionTable.OriginalQuantityColumn]           = originalQuantity;
            executionRow[executionTable.SettlementDateColumn]             = settlementDate;
            executionRow[executionTable.SourceExecutionIdColumn]          = sourceExecutionId;
            executionRow[executionTable.SourceStateCodeColumn]            = sourceStateCode;
            executionRow[executionTable.TradeDateColumn]                  = tradeDate;
            executionRow[executionTable.UserFee0Column]                   = userFee0;
            executionRow[executionTable.UserFee1Column]                   = userFee1;
            executionRow[executionTable.UserFee2Column]                   = userFee2;
            executionRow[executionTable.UserFee3Column]                   = userFee3;
            executionTable.AddExecutionRow(executionRow);
            adoTransaction.DataRows.Add(executionRow);
            // Insert the record into the SQL database.
            SqlCommand sqlCommand = new SqlCommand(@"insert ""Execution"" (""rowVersion"",""AccruedInterest"",""BrokerAccountId"",""BrokerId"",""Commission"",""CreatedTime"",""CreatedUserId"",""DestinationOrderId"",""DestinationStateCode"",""ExecutionId"",""ExecutionPrice"",""ExecutionQuantity"",""ExternalId0"",""FixMessageId"",""IsHidden"",""ModifiedTime"",""ModifiedUserId"",""OriginalDestinationOrderId"",""OriginalPrice"",""OriginalQuantity"",""SettlementDate"",""SourceExecutionId"",""SourceStateCode"",""TradeDate"",""UserFee0"",""UserFee1"",""UserFee2"",""UserFee3"") values (@rowVersion,@accruedInterest,@brokerAccountId,@brokerId,@commission,@createdTime,@createdUserId,@destinationOrderId,@destinationStateCode,@executionId,@executionPrice,@executionQuantity,@externalId0,@fixMessageId,@isHidden,@modifiedTime,@modifiedUserId,@originalDestinationOrderId,@originalPrice,@originalQuantity,@settlementDate,@sourceExecutionId,@sourceStateCode,@tradeDate,@userFee0,@userFee1,@userFee2,@userFee3)");

            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("@accruedInterest", SqlDbType.Decimal, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, accruedInterest));
            sqlCommand.Parameters.Add(new SqlParameter("@brokerAccountId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, brokerAccountId));
            sqlCommand.Parameters.Add(new SqlParameter("@brokerId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, brokerId));
            sqlCommand.Parameters.Add(new SqlParameter("@commission", SqlDbType.Decimal, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, commission));
            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("@destinationOrderId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, destinationOrderId));
            sqlCommand.Parameters.Add(new SqlParameter("@destinationStateCode", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, destinationStateCode));
            sqlCommand.Parameters.Add(new SqlParameter("@executionId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, executionRow[executionTable.ExecutionIdColumn]));
            sqlCommand.Parameters.Add(new SqlParameter("@executionPrice", SqlDbType.Decimal, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, executionPrice));
            sqlCommand.Parameters.Add(new SqlParameter("@executionQuantity", SqlDbType.Decimal, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, executionQuantity));
            sqlCommand.Parameters.Add(new SqlParameter("@externalId0", SqlDbType.NVarChar, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, externalId0));
            sqlCommand.Parameters.Add(new SqlParameter("@fixMessageId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, fixMessageId));
            sqlCommand.Parameters.Add(new SqlParameter("@isHidden", SqlDbType.Bit, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, isHidden));
            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.Parameters.Add(new SqlParameter("@originalDestinationOrderId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, originalDestinationOrderId));
            sqlCommand.Parameters.Add(new SqlParameter("@originalPrice", SqlDbType.Decimal, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, originalPrice));
            sqlCommand.Parameters.Add(new SqlParameter("@originalQuantity", SqlDbType.Decimal, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, originalQuantity));
            sqlCommand.Parameters.Add(new SqlParameter("@settlementDate", SqlDbType.DateTime, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, settlementDate));
            sqlCommand.Parameters.Add(new SqlParameter("@sourceExecutionId", SqlDbType.NVarChar, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, sourceExecutionId));
            sqlCommand.Parameters.Add(new SqlParameter("@sourceStateCode", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, sourceStateCode));
            sqlCommand.Parameters.Add(new SqlParameter("@tradeDate", SqlDbType.DateTime, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, tradeDate));
            sqlCommand.Parameters.Add(new SqlParameter("@userFee0", SqlDbType.Decimal, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, userFee0));
            sqlCommand.Parameters.Add(new SqlParameter("@userFee1", SqlDbType.Decimal, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, userFee1));
            sqlCommand.Parameters.Add(new SqlParameter("@userFee2", SqlDbType.Decimal, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, userFee2));
            sqlCommand.Parameters.Add(new SqlParameter("@userFee3", SqlDbType.Decimal, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, userFee3));
            sqlCommand.ExecuteNonQuery();
            // Return Statements
            return(executionRow.ExecutionId);
        }
Пример #12
0
        /// <summary>Updates a Execution record.</summary>
        /// <param name="transaction">Commits or rejects a set of commands as a unit</param>
        /// <param name="executionId">The value for the ExecutionId column.</param>
        /// <param name="blockOrderId">The value for the BlockOrderId column.</param>
        /// <param name="brokerId">The value for the BrokerId column.</param>
        /// <param name="rowVersion">The value for the RowVersion column.</param>
        /// <param name="quantity">The value for the Quantity column.</param>
        /// <param name="price">The value for the Price column.</param>
        /// <param name="commission">The value for the Commission column.</param>
        /// <param name="accruedInterest">The value for the AccruedInterest column.</param>
        /// <param name="userFee0">The value for the UserFee0 column.</param>
        /// <param name="userFee1">The value for the UserFee1 column.</param>
        /// <param name="userFee2">The value for the UserFee2 column.</param>
        /// <param name="userFee3">The value for the UserFee3 column.</param>
        /// <param name="tradeDate">The value for the TradeDate column.</param>
        /// <param name="settlementDate">The value for the SettlementDate column.</param>
        public static void Update(
            Transaction transaction,
            int executionId,
            object blockOrderId,
            object brokerId,
            ref long rowVersion,
            object quantity,
            object price,
            object commission,
            object accruedInterest,
            object userFee0,
            object userFee1,
            object userFee2,
            object userFee3,
            object tradeDate,
            object settlementDate)
        {
            // Provide the modified time and current user id to the base class.
            int      modifiedLoginId = ServerMarketData.LoginId;
            DateTime modifiedTime    = DateTime.Now;

            // Rule #1: Make sure the record exists before updating it.
            ServerMarketData.ExecutionRow executionRow = ServerMarketData.Execution.FindByExecutionId(executionId);
            if ((executionRow == null))
            {
                throw new Exception("This Execution has been deleted by someone else");
            }

            // Rule #2: The block order exist.
            ServerMarketData.BlockOrderRow blockOrderRow = ServerMarketData.BlockOrder.FindByBlockOrderId((int)blockOrderId);
            if (blockOrderRow == null)
            {
                throw new Exception("This block order has been deleted by someone else");
            }

            // Rule #3: The Block Order is active
            if (blockOrderRow.StatusCode == Shadows.Quasar.Common.Status.Closed ||
                blockOrderRow.StatusCode == Shadows.Quasar.Common.Status.Confirmed ||
                blockOrderRow.StatusCode == Shadows.Quasar.Common.Status.Pending)
            {
                throw new Exception("This order isn't active");
            }

            // Rule #4: Quantity executed doesn't exceed the quantity ordered.
            decimal quantityOrdered = 0.0M;

            foreach (ServerMarketData.OrderRow orderSumRow in blockOrderRow.GetOrderRows())
            {
                quantityOrdered += orderSumRow.Quantity;
            }
            decimal quantityPlaced = 0.0M;

            foreach (ServerMarketData.ExecutionRow executionSumRow in blockOrderRow.GetExecutionRows())
            {
                quantityPlaced += executionSumRow.Quantity;
            }
            if (quantityPlaced - executionRow.Quantity + (decimal)quantity > quantityOrdered)
            {
                throw new Exception("The quantity placed is more than the quantity ordered.");
            }

            // Call the base class to insert the execution.
            Shadows.WebService.Core.Execution.Update(transaction, executionId, blockOrderId, brokerId, ref rowVersion, null, quantity,
                                                     price, commission, accruedInterest, userFee0, userFee1, userFee2, userFee3, tradeDate, settlementDate, null, null,
                                                     modifiedTime, modifiedLoginId);
        }