Esempio n. 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.
            ServerDataModel.AllocationDataTable allocationTable = ServerDataModel.Allocation;
            // Rule #1: Make sure the record exists before updating it.
            ServerDataModel.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 = ServerDataModel.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();
        }
Esempio n. 2
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="allocationId">The value for the AllocationId column.</param>
        /// <param name="blockOrderId">The value for the BlockOrderId column.</param>
        /// <param name="accountId">The value for the AccountId column.</param>
        /// <param name="securityId">The value for the SecurityId column.</param>
        /// <param name="settlementId">The value for the SettlementId column.</param>
        /// <param name="positionTypeCode">The value for the PositionTypeCode column.</param>
        /// <param name="transactionTypeCode">The value for the TransactionTypeCode 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>
        /// <param name="createdTime">The value for the CreatedTime column.</param>
        /// <param name="createdUserId">The value for the CreatedUserId column.</param>
        /// <param name="modifiedTime">The value for the ModifiedTime column.</param>
        /// <param name="modifiedUserId">The value for the ModifiedUserId column.</param>
        public static void Update(
            AdoTransaction adoTransaction,
            SqlTransaction sqlTransaction,
            ref long rowVersion,
            int allocationId,
            object blockOrderId,
            object accountId,
            object securityId,
            object settlementId,
            object positionTypeCode,
            object transactionTypeCode,
            object quantity,
            object price,
            object commission,
            object accruedInterest,
            object userFee0,
            object userFee1,
            object userFee2,
            object userFee3,
            object tradeDate,
            object settlementDate,
            object createdTime,
            object createdUserId,
            object modifiedTime,
            object modifiedUserId)
        {
            // Accessor for the Allocation Table.
            ServerDataModel.AllocationDataTable allocationTable = ServerDataModel.Allocation;
            // Rule #1: Make sure the record exists before updating it.
            ServerDataModel.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 ((blockOrderId == null))
            {
                blockOrderId = allocationRow[allocationTable.BlockOrderIdColumn];
            }
            if ((accountId == null))
            {
                accountId = allocationRow[allocationTable.AccountIdColumn];
            }
            if ((securityId == null))
            {
                securityId = allocationRow[allocationTable.SecurityIdColumn];
            }
            if ((settlementId == null))
            {
                settlementId = allocationRow[allocationTable.SettlementIdColumn];
            }
            if ((positionTypeCode == null))
            {
                positionTypeCode = allocationRow[allocationTable.PositionTypeCodeColumn];
            }
            if ((transactionTypeCode == null))
            {
                transactionTypeCode = allocationRow[allocationTable.TransactionTypeCodeColumn];
            }
            if ((quantity == null))
            {
                quantity = allocationRow[allocationTable.QuantityColumn];
            }
            if ((price == null))
            {
                price = allocationRow[allocationTable.PriceColumn];
            }
            if ((commission == null))
            {
                commission = allocationRow[allocationTable.CommissionColumn];
            }
            if ((accruedInterest == null))
            {
                accruedInterest = allocationRow[allocationTable.AccruedInterestColumn];
            }
            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 ((tradeDate == null))
            {
                tradeDate = allocationRow[allocationTable.TradeDateColumn];
            }
            if ((settlementDate == null))
            {
                settlementDate = allocationRow[allocationTable.SettlementDateColumn];
            }
            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];
            }
            // Increment the row version
            rowVersion = ServerDataModel.RowVersion.Increment();
            // Update the record in the ADO database.
            allocationRow[allocationTable.RowVersionColumn]          = rowVersion;
            allocationRow[allocationTable.BlockOrderIdColumn]        = blockOrderId;
            allocationRow[allocationTable.AccountIdColumn]           = accountId;
            allocationRow[allocationTable.SecurityIdColumn]          = securityId;
            allocationRow[allocationTable.SettlementIdColumn]        = settlementId;
            allocationRow[allocationTable.PositionTypeCodeColumn]    = positionTypeCode;
            allocationRow[allocationTable.TransactionTypeCodeColumn] = transactionTypeCode;
            allocationRow[allocationTable.QuantityColumn]            = quantity;
            allocationRow[allocationTable.PriceColumn]           = price;
            allocationRow[allocationTable.CommissionColumn]      = commission;
            allocationRow[allocationTable.AccruedInterestColumn] = accruedInterest;
            allocationRow[allocationTable.UserFee0Column]        = userFee0;
            allocationRow[allocationTable.UserFee1Column]        = userFee1;
            allocationRow[allocationTable.UserFee2Column]        = userFee2;
            allocationRow[allocationTable.UserFee3Column]        = userFee3;
            allocationRow[allocationTable.TradeDateColumn]       = tradeDate;
            allocationRow[allocationTable.SettlementDateColumn]  = settlementDate;
            allocationRow[allocationTable.CreatedTimeColumn]     = createdTime;
            allocationRow[allocationTable.CreatedUserIdColumn]   = createdUserId;
            allocationRow[allocationTable.ModifiedTimeColumn]    = modifiedTime;
            allocationRow[allocationTable.ModifiedUserIdColumn]  = modifiedUserId;
            adoTransaction.DataRows.Add(allocationRow);
            // Update the record in the SQL database.
            SqlCommand sqlCommand = new SqlCommand(@"update ""Allocation"" set ""RowVersion""=@rowVersion,""BlockOrderId""=@blockOrderId,""AccountId""=@accountId,""SecurityId""=@securityId,""SettlementId""=@settlementId,""PositionTypeCode""=@positionTypeCode,""TransactionTypeCode""=@transactionTypeCode,""Quantity""=@quantity,""Price""=@price,""Commission""=@commission,""AccruedInterest""=@accruedInterest,""UserFee0""=@userFee0,""UserFee1""=@userFee1,""UserFee2""=@userFee2,""UserFee3""=@userFee3,""TradeDate""=@tradeDate,""SettlementDate""=@settlementDate,""CreatedTime""=@createdTime,""CreatedUserId""=@createdUserId,""ModifiedTime""=@modifiedTime,""ModifiedUserId""=@modifiedUserId 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("@allocationId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, allocationId));
            sqlCommand.Parameters.Add(new SqlParameter("@blockOrderId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, blockOrderId));
            sqlCommand.Parameters.Add(new SqlParameter("@accountId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, accountId));
            sqlCommand.Parameters.Add(new SqlParameter("@securityId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, securityId));
            sqlCommand.Parameters.Add(new SqlParameter("@settlementId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, settlementId));
            sqlCommand.Parameters.Add(new SqlParameter("@positionTypeCode", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, positionTypeCode));
            sqlCommand.Parameters.Add(new SqlParameter("@transactionTypeCode", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, transactionTypeCode));
            sqlCommand.Parameters.Add(new SqlParameter("@quantity", SqlDbType.Decimal, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, quantity));
            sqlCommand.Parameters.Add(new SqlParameter("@price", SqlDbType.Decimal, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, price));
            sqlCommand.Parameters.Add(new SqlParameter("@commission", SqlDbType.Decimal, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, commission));
            sqlCommand.Parameters.Add(new SqlParameter("@accruedInterest", SqlDbType.Decimal, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, accruedInterest));
            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("@tradeDate", SqlDbType.DateTime, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, tradeDate));
            sqlCommand.Parameters.Add(new SqlParameter("@settlementDate", SqlDbType.DateTime, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, settlementDate));
            sqlCommand.Parameters.Add(new SqlParameter("@createdTime", SqlDbType.DateTime, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, createdTime));
            sqlCommand.Parameters.Add(new SqlParameter("@createdUserId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, createdUserId));
            sqlCommand.Parameters.Add(new SqlParameter("@modifiedTime", SqlDbType.DateTime, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, modifiedTime));
            sqlCommand.Parameters.Add(new SqlParameter("@modifiedUserId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, modifiedUserId));
            // Update the record in the SQL database.
            sqlCommand.ExecuteNonQuery();
        }