コード例 #1
0
        /// <summary>
        /// Method starts moving orders.
        /// </summary>
        /// <param name="ordersToAssign">Collection of orders to move.</param>
        /// <param name="targetRoutes">Target routes.</param>
        /// <param name="sequence">Order sequence. Can be null.</param>
        private void _MoveOrders(Collection <Order> ordersToAssign, ICollection <Route> targetRoutes, int?sequence)
        {
            _RemoveRedundantOrders(ref ordersToAssign, targetRoutes, sequence);

            // if collection of dropping orders is empty - return
            if (ordersToAssign.Count == 0)
            {
                return;
            }

            // get current schedule
            OptimizeAndEditPage schedulePage = (OptimizeAndEditPage)(App.Current.MainWindow).GetPage(PagePaths.SchedulePagePath);
            Schedule            schedule     = schedulePage.CurrentSchedule;

            if (_CheckRoutingParams(schedule, targetRoutes, ordersToAssign))
            {
                SolveOptions options = new SolveOptions();
                options.GenerateDirections            = App.Current.MapDisplay.TrueRoute;
                options.FailOnInvalidOrderGeoLocation = false;

                // Update status.
                _SetOperationStartedStatus((string)App.Current.FindResource("AssignOrders"), (DateTime)schedule.PlannedDate);

                // Start solve.
                OperationsIds.Add(App.Current.Solver.AssignOrdersAsync(schedule, ordersToAssign,
                                                                       targetRoutes, sequence,
                                                                       false, options));

                IEnumerator <Route> rtEnum = targetRoutes.GetEnumerator();
                rtEnum.MoveNext();

                // Set solve started message.
                string infoMessage = RoutingMessagesHelper.GetAssignOperationStartedMessage(
                    ordersToAssign, rtEnum.Current.Name);

                if (!string.IsNullOrEmpty(infoMessage))
                {
                    App.Current.Messenger.AddInfo(infoMessage);
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Excecutes command.
        /// </summary>
        /// <param name="args"></param>
        protected override void _Execute(params object[] args)
        {
            try
            {
                OptimizeAndEditPage schedulePage = (OptimizeAndEditPage)App.Current.MainWindow.GetPage(PagePaths.SchedulePagePath);
                Schedule            schedule     = schedulePage.CurrentSchedule;

                // Get selected orders.
                Collection <Order> selectedOrders = _GetOrdersWhichCanBeMovedFromSelection(schedulePage.SelectedItems);
                selectedOrders = RoutingCmdHelpers.GetOrdersIncludingPairs(schedule, selectedOrders) as Collection <Order>;
                bool keepViolOrdrsUnassigned = false;

                Debug.Assert(args[0] != null);
                ICollection <Route> targetRoutes = args[0] as ICollection <Route>;
                Debug.Assert(targetRoutes != null);

                string routeName = args[1] as string;

                if (_CheckRoutingParams(schedule, targetRoutes, selectedOrders))
                {
                    SolveOptions options = new SolveOptions();
                    options.GenerateDirections            = App.Current.MapDisplay.TrueRoute;
                    options.FailOnInvalidOrderGeoLocation = false;

                    _SetOperationStartedStatus((string)App.Current.FindResource(ASSIGN_ORDERS), (DateTime)schedule.PlannedDate);

                    // Start "Assign to best other route" operation.
                    OperationsIds.Add(App.Current.Solver.AssignOrdersAsync(schedule, selectedOrders,
                                                                           targetRoutes, null,
                                                                           keepViolOrdrsUnassigned,
                                                                           options));
                    // Set solve started message
                    string infoMessage = RoutingMessagesHelper.GetAssignOperationStartedMessage(selectedOrders, routeName);

                    if (!string.IsNullOrEmpty(infoMessage))
                    {
                        App.Current.Messenger.AddInfo(infoMessage);
                    }
                }
            }
            catch (RouteException e)
            {
                if (e.InvalidObjects != null) // If exception throw because any Routes or Orders are invalid
                {
                    _ShowSolveValidationResult(e.InvalidObjects);
                }
                else
                {
                    _ShowErrorMsg(RoutingCmdHelpers.FormatRoutingExceptionMsg(e));
                }
            }
            catch (Exception e)
            {
                Logger.Error(e);
                if ((e is LicenseException) || (e is AuthenticationException) || (e is CommunicationException))
                {
                    CommonHelpers.AddRoutingErrorMessage(e);
                }
                else
                {
                    throw;
                }
            }
        }