/// <summary>
        /// Handlers for the Toggle button class of controls.
        /// </summary>
        /// <param name="sender">The object that originated the event.</param>
        /// <param name="routedEventArgs">The routed event arguments.</param>
        private void OnToggleButtonChange(object sender, RoutedEventArgs routedEventArgs)
        {
            // The main idea of this handler is to sort out the user generated actions from the machine generated actions.  Once
            // its determined that it was a user action, a background thread is called to change the associated field to the value
            // selected by the ToggleButton.
            ToggleButton toggleButton = routedEventArgs.OriginalSource as ToggleButton;
            IContent     iContent     = toggleButton.DataContext as IContent;

            // This filters all the ToggleButton events looking for user initiated actions that are bound to the data model.
            if (InputHelper.IsUserInitiated(toggleButton, ToggleButton.IsCheckedProperty) &&
                iContent != null && iContent.Key is DataTableCoordinate)
            {
                // At this point, a ToggleButton was modified by the user and it is connected to a data model field.  This will
                // extract the coordinates of the field in the table.  That, in turn, drives the decision about how to update the
                // shared data model.
                DataTableCoordinate dataTableCoordiante = iContent.Key as DataTableCoordinate;
                WorkingOrderRow     workingOrderRow     = dataTableCoordiante.DataRow as WorkingOrderRow;
                bool toggleButtonState = toggleButton.IsChecked.GetValueOrDefault();

                // Update the Crossing column.
                if (dataTableCoordiante.DataColumn == DataModel.WorkingOrder.CrossingIdColumn)
                {
                    UpdateCrossing(workingOrderRow, toggleButton.IsChecked);
                }

                // Update the IsInstitutionMatch column.
                if (dataTableCoordiante.DataColumn == DataModel.WorkingOrder.IsInstitutionMatchColumn)
                {
                    FluidTrade.Core.ThreadPoolHelper.QueueUserWorkItem(UpdateField, new Func <MethodResponseErrorCode>(() =>
                                                                                                                       TradingSupportWebService.UpdateWorkingOrder(new WorkingOrderRecord(workingOrderRow)
                    {
                        IsInstitutionMatch = toggleButtonState
                    })));
                }

                // Update the IsBrokerMatch column.
                if (dataTableCoordiante.DataColumn == DataModel.WorkingOrder.IsBrokerMatchColumn)
                {
                    FluidTrade.Core.ThreadPoolHelper.QueueUserWorkItem(UpdateField, new Func <MethodResponseErrorCode>(() =>
                                                                                                                       TradingSupportWebService.UpdateWorkingOrder(new WorkingOrderRecord(workingOrderRow)
                    {
                        IsBrokerMatch = toggleButtonState
                    })));
                }


                // Update the IsHedgeMatch column.
                if (dataTableCoordiante.DataColumn == DataModel.WorkingOrder.IsHedgeMatchColumn)
                {
                    FluidTrade.Core.ThreadPoolHelper.QueueUserWorkItem(UpdateField, new Func <MethodResponseErrorCode>(() =>
                                                                                                                       TradingSupportWebService.UpdateWorkingOrder(new WorkingOrderRecord(workingOrderRow)
                    {
                        IsHedgeFundMatch = toggleButtonState
                    })));
                }
            }
        }
        /// <summary>
        /// Update the Crossing field.
        /// </summary>
        /// <param name="dataModelClient">The client channel to the shared data model.</param>
        /// <param name="workingOrderRow">The record that is to be updated.</param>
        /// <param name="value">The value of the IsInstutitionMatch field.</param>
        private void UpdateCrossing(WorkingOrderRow workingOrderRow, object newValue)
        {
            // Update the Crossing field.
            Crossing    crossing      = (Boolean)newValue ? Crossing.AlwaysMatch : Crossing.NeverMatch;
            Object      submittedTime = crossing == Crossing.AlwaysMatch ? (Object)DateTime.UtcNow : (Object)null;
            CrossingRow crossingRow   = DataModel.Crossing.CrossingKeyCrossingCode.Find(crossing);


            FluidTrade.Core.ThreadPoolHelper.QueueUserWorkItem(UpdateField, new Func <MethodResponseErrorCode>(() =>
                                                                                                               TradingSupportWebService.UpdateWorkingOrder(new WorkingOrderRecord(workingOrderRow)
            {
                CrossingCode = crossingRow.CrossingId, SubmittedUTCTime = submittedTime
            })));
        }
        /// <summary>
        /// Handlers for the ComboBox class of controls.
        /// </summary>
        /// <param name="sender">The object that originated the event.</param>
        /// <param name="routedEventArgs">The routed event arguments.</param>
        private void OnSelectorSelectionChanged(object sender, RoutedEventArgs routedEventArgs)
        {
            // The main idea of this handler is to sort out the user generated actions from the machine generated actions.  Once
            // its determined that it was a user action, a background thread is called to change the associated field to the value
            // selected by the ComboBox.
            SelectionChangedEventArgs selectionChangedEventArgs = routedEventArgs as SelectionChangedEventArgs;

            // Handle changes to ComboBox elements.
            if (selectionChangedEventArgs.OriginalSource is ComboBox)
            {
                ComboBox comboBox = selectionChangedEventArgs.OriginalSource as ComboBox;
                IContent iContent = comboBox.DataContext as IContent;

                // This filters all the ComboBox events looking for user initiated actions that are bound to the data model.
                if (InputHelper.IsUserInitiated(comboBox, ComboBox.SelectedValueProperty) &&
                    iContent != null && iContent.Key is DataTableCoordinate)
                {
                    // At this point, a ComboBox was modified by the user and it is connected to a data model field.  This will extract
                    // the coordinates of the field in the table.  That, in turn, drives the decision about how to update the shared
                    // data model.
                    DataTableCoordinate dataTableCoordiante = iContent.Key as DataTableCoordinate;
                    WorkingOrderRow     workingOrderRow     = dataTableCoordiante.DataRow as WorkingOrderRow;

                    if (dataTableCoordiante.DataColumn == DataModel.WorkingOrder.TimeInForceIdColumn)
                    {
                        TimeInForceRow timeInForceRow = DataModel.TimeInForce.TimeInForceKeyTimeInForceCode.Find((TimeInForce)comboBox.SelectedValue);
                        FluidTrade.Core.ThreadPoolHelper.QueueUserWorkItem(UpdateField, new Func <MethodResponseErrorCode>(() =>
                                                                                                                           TradingSupportWebService.UpdateWorkingOrder(new WorkingOrderRecord(workingOrderRow)
                        {
                            TimeInForceId = timeInForceRow.TimeInForceId
                        })));
                    }

                    // This will update changes make to the Side field in a background thread.
                    if (dataTableCoordiante.DataColumn == DataModel.WorkingOrder.SideIdColumn)
                    {
                        SideRow sideRow = DataModel.Side.SideKeySideCode.Find((Side)comboBox.SelectedValue);
                        FluidTrade.Core.ThreadPoolHelper.QueueUserWorkItem(UpdateField, new Func <MethodResponseErrorCode>(() =>
                                                                                                                           TradingSupportWebService.UpdateWorkingOrder(new WorkingOrderRecord(workingOrderRow)
                        {
                            SideId = sideRow.SideId
                        })));
                    }
                }
            }
        }