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

            sqlCommand.Connection  = sqlTransaction.Connection;
            sqlCommand.Transaction = sqlTransaction;
            sqlCommand.Parameters.Add(new SqlParameter("@allocationId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, allocationId));
            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 FilterAllocation(DataRow userDataRow, DataRow allocationDataRow)
 {
     // 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.AllocationRow allocationRow = (ServerMarketData.AllocationRow)allocationDataRow;
     return(Hierarchy.IsDescendant(userRow.SystemFolderRow.FolderRow.ObjectRow,
                                   allocationRow.WorkingOrderRow.BlotterRow.ObjectRow));
 }
Пример #3
0
        /// <summary>Archives a OrderType 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="orderTypeCode">The value for the OrderTypeCode 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 orderTypeCode)
        {
            // Accessor for the OrderType Table.
            ServerMarketData.OrderTypeDataTable orderTypeTable = ServerMarketData.OrderType;
            // Rule #1: Make sure the record exists before updating it.
            ServerMarketData.OrderTypeRow orderTypeRow = orderTypeTable.FindByOrderTypeCode(orderTypeCode);
            if ((orderTypeRow == null))
            {
                throw new Exception(string.Format("The OrderType table does not have an element identified by {0}", orderTypeCode));
            }
            // Rule #2: Optimistic Concurrency Check
            if ((orderTypeRow.RowVersion != rowVersion))
            {
                throw new System.Exception("This record is busy.  Please try again later.");
            }
            // Archive the child records.
            for (int index = 0; (index < orderTypeRow.GetAllocationRows().Length); index = (index + 1))
            {
                ServerMarketData.AllocationRow childAllocationRow = orderTypeRow.GetAllocationRows()[index];
                Allocation.Archive(adoTransaction, sqlTransaction, childAllocationRow.RowVersion, childAllocationRow.AllocationId);
            }
            for (int index = 0; (index < orderTypeRow.GetSourceOrderRows().Length); index = (index + 1))
            {
                ServerMarketData.SourceOrderRow childSourceOrderRow = orderTypeRow.GetSourceOrderRows()[index];
                SourceOrder.Archive(adoTransaction, sqlTransaction, childSourceOrderRow.RowVersion, childSourceOrderRow.SourceOrderId);
            }
            for (int index = 0; (index < orderTypeRow.GetWorkingOrderRows().Length); index = (index + 1))
            {
                ServerMarketData.WorkingOrderRow childWorkingOrderRow = orderTypeRow.GetWorkingOrderRows()[index];
                WorkingOrder.Archive(adoTransaction, sqlTransaction, childWorkingOrderRow.RowVersion, childWorkingOrderRow.WorkingOrderId);
            }
            // Increment the row version
            rowVersion = ServerMarketData.RowVersion.Increment();
            // Delete the record in the ADO database.
            orderTypeRow[orderTypeTable.RowVersionColumn] = rowVersion;
            adoTransaction.DataRows.Add(orderTypeRow);
            orderTypeRow.Delete();
            // Archive the record in the SQL database.
            SqlCommand sqlCommand = new SqlCommand("update \"OrderType\" set \"IsArchived\" = 1 where \"OrderTypeCode\"=@orderTypeCode");

            sqlCommand.Connection  = sqlTransaction.Connection;
            sqlCommand.Transaction = sqlTransaction;
            sqlCommand.Parameters.Add(new SqlParameter("@orderTypeCode", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, orderTypeCode));
            sqlCommand.ExecuteNonQuery();
        }
Пример #4
0
        /// <summary>ArchiveChildrens a Account 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="accountId">The value for the AccountId 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 accountId)
        {
            // Accessor for the Account Table.
            ServerMarketData.AccountDataTable accountTable = ServerMarketData.Account;
            // This record can be used to iterate through all the children.
            ServerMarketData.AccountRow accountRow = accountTable.FindByAccountId(accountId);
            // Archive the child records.
            for (int index = 0; (index < accountRow.GetAllocationRows().Length); index = (index + 1))
            {
                ServerMarketData.AllocationRow childAllocationRow = accountRow.GetAllocationRows()[index];
                Allocation.Archive(adoTransaction, sqlTransaction, childAllocationRow.RowVersion, childAllocationRow.AllocationId);
            }
            for (int index = 0; (index < accountRow.GetPositionRows().Length); index = (index + 1))
            {
                ServerMarketData.PositionRow childPositionRow = accountRow.GetPositionRows()[index];
                Position.Archive(adoTransaction, sqlTransaction, childPositionRow.RowVersion, childPositionRow.AccountId, childPositionRow.SecurityId, childPositionRow.PositionTypeCode);
            }
            for (int index = 0; (index < accountRow.GetTaxLotRows().Length); index = (index + 1))
            {
                ServerMarketData.TaxLotRow childTaxLotRow = accountRow.GetTaxLotRows()[index];
                TaxLot.Archive(adoTransaction, sqlTransaction, childTaxLotRow.RowVersion, childTaxLotRow.TaxLotId);
            }
            // Increment the row version
            rowVersion = ServerMarketData.RowVersion.Increment();
            // Delete the record in the ADO database.
            accountRow[accountTable.RowVersionColumn] = rowVersion;
            adoTransaction.DataRows.Add(accountRow);
            accountRow.Delete();
            // Archive the record in the SQL database.
            SqlCommand sqlCommand = new SqlCommand("update \"Account\" set \"IsArchived\" = 1 where \"AccountId\"=@accountId");

            sqlCommand.Connection  = sqlTransaction.Connection;
            sqlCommand.Transaction = sqlTransaction;
            sqlCommand.Parameters.Add(new SqlParameter("@accountId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, accountId));
            sqlCommand.ExecuteNonQuery();
        }
Пример #5
0
        /// <summary>Updates a Allocation 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="accountId">The value for the AccountId column.</param>
        /// <param name="accruedInterest">The value for the AccruedInterest column.</param>
        /// <param name="allocationId">The value for the AllocationId 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="modifiedTime">The value for the ModifiedTime column.</param>
        /// <param name="modifiedUserId">The value for the ModifiedUserId column.</param>
        /// <param name="orderTypeCode">The value for the OrderTypeCode column.</param>
        /// <param name="positionTypeCode">The value for the PositionTypeCode column.</param>
        /// <param name="price">The value for the Price column.</param>
        /// <param name="quantity">The value for the Quantity column.</param>
        /// <param name="securityId">The value for the SecurityId column.</param>
        /// <param name="settlementDate">The value for the SettlementDate column.</param>
        /// <param name="settlementId">The value for the SettlementId 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>
        /// <param name="workingOrderId">The value for the WorkingOrderId column.</param>
        public static void Update(
            AdoTransaction adoTransaction,
            SqlTransaction sqlTransaction,
            ref long rowVersion,
            object accountId,
            object accruedInterest,
            int allocationId,
            object commission,
            object createdTime,
            object createdUserId,
            object modifiedTime,
            object modifiedUserId,
            object orderTypeCode,
            object positionTypeCode,
            object price,
            object quantity,
            object securityId,
            object settlementDate,
            object settlementId,
            object tradeDate,
            object userFee0,
            object userFee1,
            object userFee2,
            object userFee3,
            object workingOrderId)
        {
            // Accessor for the Allocation Table.
            ServerMarketData.AllocationDataTable allocationTable = ServerMarketData.Allocation;
            // Rule #1: Make sure the record exists before updating it.
            ServerMarketData.AllocationRow allocationRow = allocationTable.FindByAllocationId(allocationId);
            if ((allocationRow == null))
            {
                throw new Exception(string.Format("The Allocation table does not have an element identified by {0}", allocationId));
            }
            // Rule #2: Optimistic Concurrency Check
            if ((allocationRow.RowVersion != rowVersion))
            {
                throw new System.Exception("This record is busy.  Please try again later.");
            }
            // Apply Defaults
            if ((accountId == null))
            {
                accountId = allocationRow[allocationTable.AccountIdColumn];
            }
            if ((accruedInterest == null))
            {
                accruedInterest = allocationRow[allocationTable.AccruedInterestColumn];
            }
            if ((commission == null))
            {
                commission = allocationRow[allocationTable.CommissionColumn];
            }
            if ((createdTime == null))
            {
                createdTime = allocationRow[allocationTable.CreatedTimeColumn];
            }
            if ((createdUserId == null))
            {
                createdUserId = allocationRow[allocationTable.CreatedUserIdColumn];
            }
            if ((modifiedTime == null))
            {
                modifiedTime = allocationRow[allocationTable.ModifiedTimeColumn];
            }
            if ((modifiedUserId == null))
            {
                modifiedUserId = allocationRow[allocationTable.ModifiedUserIdColumn];
            }
            if ((orderTypeCode == null))
            {
                orderTypeCode = allocationRow[allocationTable.OrderTypeCodeColumn];
            }
            if ((positionTypeCode == null))
            {
                positionTypeCode = allocationRow[allocationTable.PositionTypeCodeColumn];
            }
            if ((price == null))
            {
                price = allocationRow[allocationTable.PriceColumn];
            }
            if ((quantity == null))
            {
                quantity = allocationRow[allocationTable.QuantityColumn];
            }
            if ((securityId == null))
            {
                securityId = allocationRow[allocationTable.SecurityIdColumn];
            }
            if ((settlementDate == null))
            {
                settlementDate = allocationRow[allocationTable.SettlementDateColumn];
            }
            if ((settlementId == null))
            {
                settlementId = allocationRow[allocationTable.SettlementIdColumn];
            }
            if ((tradeDate == null))
            {
                tradeDate = allocationRow[allocationTable.TradeDateColumn];
            }
            if ((userFee0 == null))
            {
                userFee0 = allocationRow[allocationTable.UserFee0Column];
            }
            if ((userFee1 == null))
            {
                userFee1 = allocationRow[allocationTable.UserFee1Column];
            }
            if ((userFee2 == null))
            {
                userFee2 = allocationRow[allocationTable.UserFee2Column];
            }
            if ((userFee3 == null))
            {
                userFee3 = allocationRow[allocationTable.UserFee3Column];
            }
            if ((workingOrderId == null))
            {
                workingOrderId = allocationRow[allocationTable.WorkingOrderIdColumn];
            }
            // Increment the row version
            rowVersion = ServerMarketData.RowVersion.Increment();
            // Update the record in the ADO database.
            allocationRow[allocationTable.RowVersionColumn]       = rowVersion;
            allocationRow[allocationTable.AccountIdColumn]        = accountId;
            allocationRow[allocationTable.AccruedInterestColumn]  = accruedInterest;
            allocationRow[allocationTable.CommissionColumn]       = commission;
            allocationRow[allocationTable.CreatedTimeColumn]      = createdTime;
            allocationRow[allocationTable.CreatedUserIdColumn]    = createdUserId;
            allocationRow[allocationTable.ModifiedTimeColumn]     = modifiedTime;
            allocationRow[allocationTable.ModifiedUserIdColumn]   = modifiedUserId;
            allocationRow[allocationTable.OrderTypeCodeColumn]    = orderTypeCode;
            allocationRow[allocationTable.PositionTypeCodeColumn] = positionTypeCode;
            allocationRow[allocationTable.PriceColumn]            = price;
            allocationRow[allocationTable.QuantityColumn]         = quantity;
            allocationRow[allocationTable.SecurityIdColumn]       = securityId;
            allocationRow[allocationTable.SettlementDateColumn]   = settlementDate;
            allocationRow[allocationTable.SettlementIdColumn]     = settlementId;
            allocationRow[allocationTable.TradeDateColumn]        = tradeDate;
            allocationRow[allocationTable.UserFee0Column]         = userFee0;
            allocationRow[allocationTable.UserFee1Column]         = userFee1;
            allocationRow[allocationTable.UserFee2Column]         = userFee2;
            allocationRow[allocationTable.UserFee3Column]         = userFee3;
            allocationRow[allocationTable.WorkingOrderIdColumn]   = workingOrderId;
            adoTransaction.DataRows.Add(allocationRow);
            // Update the record in the SQL database.
            SqlCommand sqlCommand = new SqlCommand(@"update ""Allocation"" set ""RowVersion""=@rowVersion,""AccountId""=@accountId,""AccruedInterest""=@accruedInterest,""Commission""=@commission,""CreatedTime""=@createdTime,""CreatedUserId""=@createdUserId,""ModifiedTime""=@modifiedTime,""ModifiedUserId""=@modifiedUserId,""OrderTypeCode""=@orderTypeCode,""PositionTypeCode""=@positionTypeCode,""Price""=@price,""Quantity""=@quantity,""SecurityId""=@securityId,""SettlementDate""=@settlementDate,""SettlementId""=@settlementId,""TradeDate""=@tradeDate,""UserFee0""=@userFee0,""UserFee1""=@userFee1,""UserFee2""=@userFee2,""UserFee3""=@userFee3,""WorkingOrderId""=@workingOrderId where ""AllocationId""=@allocationId");

            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("@accountId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, accountId));
            sqlCommand.Parameters.Add(new SqlParameter("@accruedInterest", SqlDbType.Decimal, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, accruedInterest));
            sqlCommand.Parameters.Add(new SqlParameter("@allocationId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, allocationId));
            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("@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("@orderTypeCode", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, orderTypeCode));
            sqlCommand.Parameters.Add(new SqlParameter("@positionTypeCode", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, positionTypeCode));
            sqlCommand.Parameters.Add(new SqlParameter("@price", SqlDbType.Decimal, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, price));
            sqlCommand.Parameters.Add(new SqlParameter("@quantity", SqlDbType.Decimal, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, quantity));
            sqlCommand.Parameters.Add(new SqlParameter("@securityId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, securityId));
            sqlCommand.Parameters.Add(new SqlParameter("@settlementDate", SqlDbType.DateTime, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, settlementDate));
            sqlCommand.Parameters.Add(new SqlParameter("@settlementId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, settlementId));
            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.Parameters.Add(new SqlParameter("@workingOrderId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, workingOrderId));
            // Update the record in the SQL database.
            sqlCommand.ExecuteNonQuery();
        }
Пример #6
0
        /// <summary>Inserts a Allocation record.</summary>
        /// <param name="transaction">Commits or rejects a set of commands as a unit</param>
        /// <param name="accountId">The value for the AccountId column.</param>
        /// <param name="accruedInterest">The value for the AccruedInterest 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="modifiedTime">The value for the ModifiedTime column.</param>
        /// <param name="modifiedUserId">The value for the ModifiedUserId column.</param>
        /// <param name="orderTypeCode">The value for the OrderTypeCode column.</param>
        /// <param name="positionTypeCode">The value for the PositionTypeCode column.</param>
        /// <param name="price">The value for the Price column.</param>
        /// <param name="quantity">The value for the Quantity column.</param>
        /// <param name="securityId">The value for the SecurityId column.</param>
        /// <param name="settlementDate">The value for the SettlementDate column.</param>
        /// <param name="settlementId">The value for the SettlementId 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>
        /// <param name="workingOrderId">The value for the WorkingOrderId column.</param>
        public static int Insert(
            AdoTransaction adoTransaction,
            SqlTransaction sqlTransaction,
            ref long rowVersion,
            int accountId,
            decimal accruedInterest,
            decimal commission,
            System.DateTime createdTime,
            int createdUserId,
            System.DateTime modifiedTime,
            int modifiedUserId,
            int orderTypeCode,
            int positionTypeCode,
            decimal price,
            decimal quantity,
            int securityId,
            System.DateTime settlementDate,
            int settlementId,
            System.DateTime tradeDate,
            decimal userFee0,
            decimal userFee1,
            decimal userFee2,
            decimal userFee3,
            int workingOrderId)
        {
            // Accessor for the Allocation Table.
            ServerMarketData.AllocationDataTable allocationTable = ServerMarketData.Allocation;
            // Apply Defaults
            // Increment the row version
            rowVersion = ServerMarketData.RowVersion.Increment();
            // Insert the record into the ADO database.
            ServerMarketData.AllocationRow allocationRow = allocationTable.NewAllocationRow();
            allocationRow[allocationTable.RowVersionColumn]       = rowVersion;
            allocationRow[allocationTable.AccountIdColumn]        = accountId;
            allocationRow[allocationTable.AccruedInterestColumn]  = accruedInterest;
            allocationRow[allocationTable.CommissionColumn]       = commission;
            allocationRow[allocationTable.CreatedTimeColumn]      = createdTime;
            allocationRow[allocationTable.CreatedUserIdColumn]    = createdUserId;
            allocationRow[allocationTable.ModifiedTimeColumn]     = modifiedTime;
            allocationRow[allocationTable.ModifiedUserIdColumn]   = modifiedUserId;
            allocationRow[allocationTable.OrderTypeCodeColumn]    = orderTypeCode;
            allocationRow[allocationTable.PositionTypeCodeColumn] = positionTypeCode;
            allocationRow[allocationTable.PriceColumn]            = price;
            allocationRow[allocationTable.QuantityColumn]         = quantity;
            allocationRow[allocationTable.SecurityIdColumn]       = securityId;
            allocationRow[allocationTable.SettlementDateColumn]   = settlementDate;
            allocationRow[allocationTable.SettlementIdColumn]     = settlementId;
            allocationRow[allocationTable.TradeDateColumn]        = tradeDate;
            allocationRow[allocationTable.UserFee0Column]         = userFee0;
            allocationRow[allocationTable.UserFee1Column]         = userFee1;
            allocationRow[allocationTable.UserFee2Column]         = userFee2;
            allocationRow[allocationTable.UserFee3Column]         = userFee3;
            allocationRow[allocationTable.WorkingOrderIdColumn]   = workingOrderId;
            allocationTable.AddAllocationRow(allocationRow);
            adoTransaction.DataRows.Add(allocationRow);
            // Insert the record into the SQL database.
            SqlCommand sqlCommand = new SqlCommand(@"insert ""Allocation"" (""rowVersion"",""AccountId"",""AccruedInterest"",""AllocationId"",""Commission"",""CreatedTime"",""CreatedUserId"",""ModifiedTime"",""ModifiedUserId"",""OrderTypeCode"",""PositionTypeCode"",""Price"",""Quantity"",""SecurityId"",""SettlementDate"",""SettlementId"",""TradeDate"",""UserFee0"",""UserFee1"",""UserFee2"",""UserFee3"",""WorkingOrderId"") values (@rowVersion,@accountId,@accruedInterest,@allocationId,@commission,@createdTime,@createdUserId,@modifiedTime,@modifiedUserId,@orderTypeCode,@positionTypeCode,@price,@quantity,@securityId,@settlementDate,@settlementId,@tradeDate,@userFee0,@userFee1,@userFee2,@userFee3,@workingOrderId)");

            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("@accountId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, accountId));
            sqlCommand.Parameters.Add(new SqlParameter("@accruedInterest", SqlDbType.Decimal, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, accruedInterest));
            sqlCommand.Parameters.Add(new SqlParameter("@allocationId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, allocationRow[allocationTable.AllocationIdColumn]));
            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("@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("@orderTypeCode", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, orderTypeCode));
            sqlCommand.Parameters.Add(new SqlParameter("@positionTypeCode", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, positionTypeCode));
            sqlCommand.Parameters.Add(new SqlParameter("@price", SqlDbType.Decimal, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, price));
            sqlCommand.Parameters.Add(new SqlParameter("@quantity", SqlDbType.Decimal, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, quantity));
            sqlCommand.Parameters.Add(new SqlParameter("@securityId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, securityId));
            sqlCommand.Parameters.Add(new SqlParameter("@settlementDate", SqlDbType.DateTime, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, settlementDate));
            sqlCommand.Parameters.Add(new SqlParameter("@settlementId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, settlementId));
            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.Parameters.Add(new SqlParameter("@workingOrderId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, workingOrderId));
            sqlCommand.ExecuteNonQuery();
            // Return Statements
            return(allocationRow.AllocationId);
        }
Пример #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.
            ServerMarketData.SecurityDataTable securityTable = ServerMarketData.Security;
            // This record can be used to iterate through all the children.
            ServerMarketData.SecurityRow securityRow = securityTable.FindBySecurityId(securityId);
            // Archive the child records.
            for (int index = 0; (index < securityRow.GetAccountBaseRows().Length); index = (index + 1))
            {
                ServerMarketData.AccountBaseRow childAccountBaseRow = securityRow.GetAccountBaseRows()[index];
                AccountBase.ArchiveChildren(adoTransaction, sqlTransaction, childAccountBaseRow.RowVersion, childAccountBaseRow.AccountBaseId);
            }
            for (int index = 0; (index < securityRow.GetAllocationRowsBySecurityAllocationSecurityId().Length); index = (index + 1))
            {
                ServerMarketData.AllocationRow childAllocationRow = securityRow.GetAllocationRowsBySecurityAllocationSecurityId()[index];
                Allocation.Archive(adoTransaction, sqlTransaction, childAllocationRow.RowVersion, childAllocationRow.AllocationId);
            }
            for (int index = 0; (index < securityRow.GetAllocationRowsBySecurityAllocationSettlementId().Length); index = (index + 1))
            {
                ServerMarketData.AllocationRow childAllocationRow = securityRow.GetAllocationRowsBySecurityAllocationSettlementId()[index];
                Allocation.Archive(adoTransaction, sqlTransaction, childAllocationRow.RowVersion, childAllocationRow.AllocationId);
            }
            for (int index = 0; (index < securityRow.GetCurrencyRows().Length); index = (index + 1))
            {
                ServerMarketData.CurrencyRow childCurrencyRow = securityRow.GetCurrencyRows()[index];
                Currency.ArchiveChildren(adoTransaction, sqlTransaction, childCurrencyRow.RowVersion, childCurrencyRow.CurrencyId);
            }
            for (int index = 0; (index < securityRow.GetDebtRowsBySecurityDebtDebtId().Length); index = (index + 1))
            {
                ServerMarketData.DebtRow childDebtRow = securityRow.GetDebtRowsBySecurityDebtDebtId()[index];
                Debt.ArchiveChildren(adoTransaction, sqlTransaction, childDebtRow.RowVersion, childDebtRow.DebtId);
            }
            for (int index = 0; (index < securityRow.GetDebtRowsBySecurityDebtSettlementId().Length); index = (index + 1))
            {
                ServerMarketData.DebtRow childDebtRow = securityRow.GetDebtRowsBySecurityDebtSettlementId()[index];
                Debt.ArchiveChildren(adoTransaction, sqlTransaction, childDebtRow.RowVersion, childDebtRow.DebtId);
            }
            for (int index = 0; (index < securityRow.GetEquityRowsBySecurityEquityEquityId().Length); index = (index + 1))
            {
                ServerMarketData.EquityRow childEquityRow = securityRow.GetEquityRowsBySecurityEquityEquityId()[index];
                Equity.ArchiveChildren(adoTransaction, sqlTransaction, childEquityRow.RowVersion, childEquityRow.EquityId);
            }
            for (int index = 0; (index < securityRow.GetEquityRowsBySecurityEquitySettlementId().Length); index = (index + 1))
            {
                ServerMarketData.EquityRow childEquityRow = securityRow.GetEquityRowsBySecurityEquitySettlementId()[index];
                Equity.ArchiveChildren(adoTransaction, sqlTransaction, childEquityRow.RowVersion, childEquityRow.EquityId);
            }
            for (int index = 0; (index < securityRow.GetPositionRows().Length); index = (index + 1))
            {
                ServerMarketData.PositionRow childPositionRow = securityRow.GetPositionRows()[index];
                Position.Archive(adoTransaction, sqlTransaction, childPositionRow.RowVersion, childPositionRow.AccountId, childPositionRow.SecurityId, childPositionRow.PositionTypeCode);
            }
            for (int index = 0; (index < securityRow.GetPriceRows().Length); index = (index + 1))
            {
                ServerMarketData.PriceRow childPriceRow = securityRow.GetPriceRows()[index];
                Price.Archive(adoTransaction, sqlTransaction, childPriceRow.RowVersion, childPriceRow.SecurityId);
            }
            for (int index = 0; (index < securityRow.GetSourceOrderRowsBySecuritySourceOrderSecurityId().Length); index = (index + 1))
            {
                ServerMarketData.SourceOrderRow childSourceOrderRow = securityRow.GetSourceOrderRowsBySecuritySourceOrderSecurityId()[index];
                SourceOrder.Archive(adoTransaction, sqlTransaction, childSourceOrderRow.RowVersion, childSourceOrderRow.SourceOrderId);
            }
            for (int index = 0; (index < securityRow.GetSourceOrderRowsBySecuritySourceOrderSettlementId().Length); index = (index + 1))
            {
                ServerMarketData.SourceOrderRow childSourceOrderRow = securityRow.GetSourceOrderRowsBySecuritySourceOrderSettlementId()[index];
                SourceOrder.Archive(adoTransaction, sqlTransaction, childSourceOrderRow.RowVersion, childSourceOrderRow.SourceOrderId);
            }
            for (int index = 0; (index < securityRow.GetTaxLotRows().Length); index = (index + 1))
            {
                ServerMarketData.TaxLotRow childTaxLotRow = securityRow.GetTaxLotRows()[index];
                TaxLot.Archive(adoTransaction, sqlTransaction, childTaxLotRow.RowVersion, childTaxLotRow.TaxLotId);
            }
            for (int index = 0; (index < securityRow.GetWorkingOrderRowsBySecurityWorkingOrderSecurityId().Length); index = (index + 1))
            {
                ServerMarketData.WorkingOrderRow childWorkingOrderRow = securityRow.GetWorkingOrderRowsBySecurityWorkingOrderSecurityId()[index];
                WorkingOrder.Archive(adoTransaction, sqlTransaction, childWorkingOrderRow.RowVersion, childWorkingOrderRow.WorkingOrderId);
            }
            for (int index = 0; (index < securityRow.GetWorkingOrderRowsBySecurityWorkingOrderSettlementId().Length); index = (index + 1))
            {
                ServerMarketData.WorkingOrderRow childWorkingOrderRow = securityRow.GetWorkingOrderRowsBySecurityWorkingOrderSettlementId()[index];
                WorkingOrder.Archive(adoTransaction, sqlTransaction, childWorkingOrderRow.RowVersion, childWorkingOrderRow.WorkingOrderId);
            }
            // Increment the row version
            rowVersion = ServerMarketData.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();
        }
Пример #8
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();
        }