/// <summary>
 /// Handles a change to the WorkingOrderRow table.
 /// </summary>
 /// <param name="sender">The object that originated the event.</param>
 /// <param name="e">The event arguments.</param>
 private void OnWorkingOrderRowChanged(object sender, WorkingOrderRowChangeEventArgs e)
 {
     // When the merge is completed, this indicates that the document should be refreshed.
     this.isDataChanged = true;
 }
Beispiel #2
0
        /// <summary>
        /// Handler for validating Source Order records.
        /// </summary>
        /// <param name="sender">The object that originated the event.</param>
        /// <param name="e">The event arguments.</param>
        internal static void OnWorkingOrderRowValidate(object sender, WorkingOrderRowChangeEventArgs e)
        {
            // The Business Rules will be enforced on this Working Order.  Note that it is locked at the point this handler is called.
            WorkingOrderRow workingOrderRow = e.Row;

            // The action on the row determines which rule to evaluate.
            switch (e.Action)
            {
            case DataRowAction.Add:
            case DataRowAction.Change:

                // This will evaluate whether the given Working Order is a candidate for matching.
                Boolean isSubmitted = false;

                // The 'Away' flag is used to inhibit matching without loosing the original preference for matching.  It is used when the trader wants to walk
                // away from his blotter.  When the trader returns, they want to flip a switch and have all the previous settings active for the orders on the
                // blotter.  This skips the matching logic for any trade marked 'Away'.
                if ((CrossingMap.FromId(workingOrderRow.CrossingId) & Crossing.Away) == Crossing.None)
                {
                    // This determines if the trade is eligible for crossing.
                    switch (CrossingMap.FromId(workingOrderRow.CrossingId) & ~Crossing.Away)
                    {
                    case Crossing.AlwaysMatch:

                        // The trade is eligible for crossing.
                        isSubmitted = true;
                        break;

                    case Crossing.UsePreferences:

                        // The trade is only eligible for crossing if it passes a set of preferences properties set by the user.
                        isSubmitted = workingOrderRow.IsAwake;

                        // The start and stop time must be extracted from the record using the base class.  It is safe here because the triggers are only
                        // invoked while the record is locked.
                        DateTime startTime = workingOrderRow.StartTime;
                        DateTime stopTime  = workingOrderRow.StopTime;

                        // The order is only eligible for crossing if the time of day is after the start time.
                        if (startTime != null && DateTime.UtcNow.TimeOfDay < startTime.TimeOfDay)
                        {
                            isSubmitted = false;
                        }

                        // The order is only eligible for crossing if the time if day is before the end time.
                        if (stopTime != null && DateTime.UtcNow.TimeOfDay > stopTime.TimeOfDay)
                        {
                            isSubmitted = false;
                        }

                        break;
                    }
                }

                // This will submit the order for crossing when it isn't already submitted.
                if (isSubmitted && workingOrderRow.StatusId != StatusMap.FromCode(Status.Submitted))
                {
                    UpdateWorkingOrderStatus(workingOrderRow, Status.Submitted);
                }

                // This removes the order for consideration in the crossing pool when it has been submitted.
                if (!isSubmitted && workingOrderRow.StatusId == StatusMap.FromCode(Status.Submitted))
                {
                    UpdateWorkingOrderStatus(workingOrderRow, Status.New);
                }

                break;
            }
        }