Пример #1
0
        /// <summary>
        /// The sum total of the quantities of all the source orders in a given working order.
        /// </summary>
        /// <param name="dataModelTransaction"></param>
        /// <param name="workingOrderRow">A working order row.</param>
        /// <returns>The total quantity of all the source orders associated with the working order.</returns>
        internal static Decimal GetSourceOrderQuantity(DataModelTransaction dataModelTransaction, WorkingOrderRow workingOrderRow)
        {
            // This will aggregate all the source order quantities.  Note that the rows are kept locked for the duration of the transaction.  This guarantees
            // the integrity of the aggregate values.
            Decimal sourceOrderQuantity = 0.0m;

            foreach (SourceOrderRow sourceOrderRow in workingOrderRow.GetSourceOrderRows())
            {
                try
                {
                    sourceOrderRow.AcquireReaderLock(dataModelTransaction.TransactionId, DataModel.LockTimeout);
                    sourceOrderQuantity += sourceOrderRow.OrderedQuantity;
                }
                finally
                {
                    sourceOrderRow.ReleaseLock(dataModelTransaction.TransactionId);
                }
            }

            // This is the sum total of all the source orders in the given working order.
            return(sourceOrderQuantity);
        }
        /// <summary>
        /// Initialize the data used in this application.
        /// </summary>
        private void InitializeData(object parameter)
        {
            String           title            = String.Empty;
            String           symbol           = String.Empty;
            String           name             = String.Empty;
            String           logoSource       = null;
            Decimal          leavesQuantity   = 0.0m;
            NegotiationState negotiationState = NegotiationState.None;

            lock (DataModel.SyncRoot)
            {
                // Find the Match record.
                MatchRow        matchRow        = DataModel.Match.MatchKey.Find(this.matchId);
                WorkingOrderRow workingOrderRow = matchRow.WorkingOrderRow;
                OrderTypeRow    orderTypeRow    = workingOrderRow.OrderTypeRow;
                SecurityRow     securityRow     = workingOrderRow.SecurityRowByFK_Security_WorkingOrder_SecurityId;

                symbol         = securityRow.Symbol;
                name           = securityRow.EntityRow.Name;
                logoSource     = securityRow.IsLogoNull() ? String.Empty : securityRow.Logo;
                title          = String.Format("{0} of {1}", orderTypeRow.Description, symbol);
                leavesQuantity = 0.0M;
                foreach (SourceOrderRow sourceOrderRow in workingOrderRow.GetSourceOrderRows())
                {
                    leavesQuantity += sourceOrderRow.OrderedQuantity;
                }
                foreach (DestinationOrderRow destinationOrderRow in workingOrderRow.GetDestinationOrderRows())
                {
                    foreach (ExecutionRow executionRow in destinationOrderRow.GetExecutionRows())
                    {
                        leavesQuantity -= executionRow.ExecutionQuantity;
                    }
                }
                leavesQuantity /= securityRow.QuantityFactor;
            }

            this.Dispatcher.Invoke(DispatcherPriority.Normal, new SetDialogAttributesDelegate(SetDialogAttributes), title, symbol, name, logoSource, leavesQuantity, negotiationState);
        }