/// <summary> /// React on new version button click. /// </summary> /// <param name="sender">Ignored.</param> /// <param name="e">Ignored.</param> private void _NewVersionButtonClick(object sender, RoutedEventArgs e) { try { XceedGrid.EndEdit(); WorkingStatusHelper.SetBusy((string)App.Current.FindResource("CreatingScheduleVersionStatus")); _UnsubscribeFromGridSelection(); // Make version, add to project and save. Debug.Assert(_SelectedSchedule != null); Schedule newSchedule = _MakeScheduleVersion(_SelectedSchedule, _ScheduleVersions); App.Current.Project.Schedules.Add(newSchedule); App.Current.Project.Save(); _SubscribeToGridSelection(); // Select new schedule. XceedGrid.SelectedItem = newSchedule; } finally { WorkingStatusHelper.SetReleased(); } }
/////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////// protected override void _Execute(params object[] args) { bool needClearBusyState = false; string projectName = null; try { Debug.Assert(args.Length > 0); string projectPath = args[0] as string; Debug.Assert(projectPath != null); // get project name projectName = Path.GetFileNameWithoutExtension(projectPath); // get project configuration ProjectConfiguration config = _FindConfigByName(projectName); if (config != null) { // check if we need to auto-archive project if (_NeedToAutoArchive(config)) { // set status string statusMessage = string.Format((string)_Application.FindResource("ArchiveMessageProcessStatusFormat"), projectName); WorkingStatusHelper.SetBusy(statusMessage); needClearBusyState = true; ProjectArchivingSettings arSet = config.ProjectArchivingSettings; DateTime date = DateTime.Now.Date.AddMonths(-arSet.TimeDomain); ArchiveResult result = ProjectFactory.ArchiveProject(config, date); _ShowResult(projectName, result); if (result.IsArchiveCreated) { // Update project page ProjectsPage projectsPage = (ProjectsPage)_Application.MainWindow.GetPage(PagePaths.ProjectsPagePath); projectsPage.UpdateView(); } } } } catch (Exception ex) { Logger.Error(ex); Collection <MessageDetail> details = new Collection <MessageDetail>(); details.Add(new MessageDetail(MessageType.Error, ex.Message)); string message = string.Format((string)_Application.FindResource("ArchiveMessageProcessFailedFromat"), projectName); _Application.Messenger.AddMessage(MessageType.Warning, message, details); } if (needClearBusyState) { WorkingStatusHelper.SetReleased(); } }
/// <summary> /// Change type of current schedule to current. /// </summary> /// <param name="sender">Ignored.</param> /// <param name="e">Ignored.</param> private void _CommitToCurrentButtonClick(object sender, RoutedEventArgs e) { try { WorkingStatusHelper.SetBusy((string)App.Current.FindResource("CommitingScheduleVersionStatus")); // Remove all schedules except one with Original type and curently selected one. Collection <Schedule> removingSchedules = new Collection <Schedule>(); foreach (Schedule schedule in _ScheduleVersions) { if (schedule.Type == ScheduleType.Current && !schedule.Equals(_SelectedSchedule)) { removingSchedules.Add(schedule); } } // Unsubscribe from selection since data grid raises this event when data source changes. _UnsubscribeFromGridSelection(); // Workaround: data grid changes selection for some reason, so we need to save current selection Schedule selectedItem = _SelectedSchedule; foreach (Schedule schedule in removingSchedules) { if (schedule.UnassignedOrders != null) { schedule.UnassignedOrders.Dispose(); } App.Current.Project.Schedules.Remove(schedule); } // Select remembered item. XceedGrid.SelectedItem = selectedItem; // Subscribe to SelectionChanged event again. _SubscribeToGridSelection(); Schedule newCurrentSchedule = _MakeScheduleVersion(_SelectedSchedule, _ScheduleVersions); newCurrentSchedule.Name = (string)App.Current.FindResource("CurrentScheduleName"); newCurrentSchedule.Type = ScheduleType.Current; App.Current.Project.Schedules.Add(newCurrentSchedule); App.Current.Project.Save(); // need to save before seleting XceedGrid.SelectedItem = newCurrentSchedule; // Save all changes. App.Current.Project.Save(); _UpdateButtonsState(); } finally { WorkingStatusHelper.SetReleased(); } }
private void _DoExport(Profile profile, ICollection <Schedule> exportedSchedule) { string statusMessage = (string)App.Current.FindResource("ExportStartMessage"); WorkingStatusHelper.SetBusy(statusMessage); try { MapLayer currentMapLayer = null; foreach (MapLayer layer in App.Current.Map.Layers) { if (layer.IsVisible && layer.IsBaseMap) { currentMapLayer = layer; break; } } App.Current.Exporter.DoExport(profile, exportedSchedule, currentMapLayer); string format = (string)App.Current.FindResource("ExportMessageFormatSucceded"); statusMessage = string.Format(format, ExportProfilesEditPage.GetTypeFaceName(profile.Type), profile.FilePath); App.Current.Messenger.AddInfo(statusMessage); } catch (Exception ex) { string format = (string)App.Current.FindResource("ExportMessageFormatFailed"); statusMessage = string.Format(format, ExportProfilesEditPage.GetTypeFaceName(profile.Type), profile.FilePath); if (ex is AuthenticationException || ex is CommunicationException) { string service = (string)App.Current.FindResource("ServiceNameMap"); CommonHelpers.AddServiceMessageWithDetail(statusMessage, service, ex); Logger.Error(ex); } else { string message = string.Format("{0} {1}", statusMessage, ex.Message); App.Current.Messenger.AddError(message); Logger.Critical(ex); } } WorkingStatusHelper.SetReleased(); App.Current.MainWindow.StatusBar.SetStatus(this, statusMessage); }
/// <summary> /// Occurs when user press enter in inserion row. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void DataGridCollectionViewSource_CommittingNewItem(object sender, DataGridCommittingNewItemEventArgs e) { try { WorkingStatusHelper.SetBusy((string)App.Current.FindResource("LoadingProjectStatus")); ProjectCatalog projectBrowser = App.Current.ProjectCatalog; List <ProjectDataWrapper> source = e.CollectionView.SourceCollection as List <ProjectDataWrapper>; ProjectDataWrapper projectDataTemplate = e.Item as ProjectDataWrapper; App.Current.NewProject(projectDataTemplate.Name, projectBrowser.FolderPath, projectDataTemplate.Description); source.Add(projectDataTemplate); // update layout UpdateView(); e.Index = source.Count - 1; e.NewCount = source.Count; e.Handled = true; } catch (ApplicationException ex) { Logger.Info(ex); App.Current.Messenger.AddWarning(ex.Message); } catch (Exception ex) { Logger.Info(ex); App.Current.Messenger.AddWarning(ex.Message); } finally { WorkingStatusHelper.SetReleased(); App.Current.MainWindow.StatusBar.SetStatus(this, null); } }
/// <summary> /// Reloads project when user checks any CheckBox. /// </summary> protected void _LoadProject(string checkedProjectName) { try { WorkingStatusHelper.SetBusy((string)App.Current.FindResource("LoadingProjectStatus")); // init old project path string oldProjectPath = String.Empty; if (App.Current.Project != null) { oldProjectPath = App.Current.Project.Path; } if (!checkedProjectName.Equals(CurrentProjectName, StringComparison.OrdinalIgnoreCase)) { _TryToLoadProject(oldProjectPath, checkedProjectName); } } finally { WorkingStatusHelper.SetReleased(); _CheckPageComplete(); } }
/// <summary> /// Does generation directions. Start solver operation. /// </summary> private void _DoGenerateDirections(IList <Route> routes) { WorkingStatusHelper.SetBusy((string)_app.FindResource("GenerateDirections")); var message = string.Format((string)_app.FindResource("GenerateDirectionsStartText"), routes.First().Schedule.PlannedDate.Value.ToShortDateString()); _app.Messenger.AddInfo(message); _app.MainWindow.Lock(true); _app.Solver.AsyncSolveCompleted += _Cmd_AsyncSolveCompleted; try { _operationID = _app.Solver.GenerateDirectionsAsync(routes); } catch (Exception ex) { _app.Solver.AsyncSolveCompleted -= _Cmd_AsyncSolveCompleted; _OnSolveError(ex); } }
/// <summary> /// Occurs when user select other month/year /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ArcLogisticsCalendar_DisplayDateChanged(object sender, CalendarDateChangedEventArgs e) { WorkingStatusHelper.SetBusy(null); _UpdateCalendarView(); WorkingStatusHelper.SetReleased(); }
protected override void _Execute(params object[] args) { // If editing is process in optimize and edit page - cancel editing. if (OptimizePage.IsEditingInProgress) { ((ICancelDataObjectEditing)OptimizePage).CancelObjectEditing(); } Collection <Route> selected = _GetRoutesFromSelection(); if (0 < selected.Count) { bool doProcess = true; if (Settings.Default.IsAllwaysAskBeforeDeletingEnabled) { // show warning dialog doProcess = DeletingWarningHelper.Execute(selected, "Route", "Routes"); } if (doProcess) { WorkingStatusHelper.SetBusy((string)App.Current.FindResource("DeletingRoutesStatus")); // Workaround: Xceed throw exception when deleting expanded details view. // Collapse route details before deleting. List <Xceed.Wpf.DataGrid.DataGridContext> dataGridContexts = new List <Xceed.Wpf.DataGrid.DataGridContext>(OptimizePage.RoutesView.RoutesGrid.GetChildContexts()); foreach (Xceed.Wpf.DataGrid.DataGridContext dataGridContext in dataGridContexts) { for (int index = 0; index < selected.Count; ++index) { if (dataGridContext.ParentItem.Equals(selected[index])) { dataGridContext.ParentDataGridContext.CollapseDetails(dataGridContext.ParentItem); break; // Exit. For this data grid context all done. } } } // Save current selected index. int previousSelectedIndex = OptimizePage.RoutesView.RoutesGrid.SelectedIndex; // Delete routes. for (int index = 0; index < selected.Count; ++index) { CurrentSchedule.Routes.Remove(selected[index]); } Project project = App.Current.Project; project.Save(); // Set unassigned orders. if (CurrentSchedule.UnassignedOrders != null) { CurrentSchedule.UnassignedOrders.Dispose(); } CurrentSchedule.UnassignedOrders = project.Orders.SearchUnassignedOrders(CurrentSchedule, true); WorkingStatusHelper.SetReleased(); // Schedule has changed - all views should be refreshed. OptimizePage.OnScheduleChanged(CurrentSchedule); // Select item, which goes after deleted. Special logic used for routes, because schedule reloads. int newSelectedIndex = OptimizePage.RoutesView.RoutesGrid.Items.Count - 1; if (OptimizePage.RoutesView.RoutesGrid.Items.Count > previousSelectedIndex) { newSelectedIndex = previousSelectedIndex; } if (newSelectedIndex != -1) { OptimizePage.Dispatcher.BeginInvoke(new ParamsDelegate(_SelectItem), DispatcherPriority.Input, OptimizePage.RoutesView.RoutesGrid.Items[newSelectedIndex]); } } } }
protected override void _Execute(params object[] args) { Debug.Assert(null != _projectsPage); string filePath = null; bool needClearBusyState = false; string projectName = null; bool isAutoArchive = false; try { // select project to archiving isAutoArchive = ((1 == args.Length) && (null != args[0])); projectName = (isAutoArchive) ? args[0] as string : _projectsPage.SelectedProjectName; // prescribed for command or selected project Debug.Assert(null != projectName); // find checked project configuration ProjectConfiguration config = _FindConfigByName(projectName); Debug.Assert(null != config); // set status string statusMessage = string.Format((string)_Application.FindResource("ArchiveMessageProcessStatusFormat"), projectName); WorkingStatusHelper.SetBusy(statusMessage); needClearBusyState = true; bool routingOperationsInProgress = false; if (projectName.Equals(_projectsPage.CurrentProjectName, StringComparison.InvariantCultureIgnoreCase)) { // check some routing operation is on progress if (_Application.Solver.HasPendingOperations) { _Application.Messenger.AddWarning((string)_Application.FindResource("ArchiveMessageRoutingOperationsInProgress")); routingOperationsInProgress = true; } else { // since archiving requires project to be closed, the command must close the project at first _Application.CloseCurProject(); filePath = config.FilePath; } } if (!routingOperationsInProgress) { // archive it ProjectArchivingSettings archivingSettings = config.ProjectArchivingSettings; Debug.Assert(!archivingSettings.IsArchive); DateTime date = DateTime.Now.Date.AddMonths(-archivingSettings.TimeDomain); ArchiveResult result = ProjectFactory.ArchiveProject(config, date); if (result.IsArchiveCreated) { // project was successfully archived string message = string.Format((string)_Application.FindResource("ArchiveMessageProcessDoneFromat"), projectName, Path.GetFileNameWithoutExtension(result.ArchivePath)); _Application.Messenger.AddInfo(message); _projectsPage.UpdateView(); } else { // command run for a project and there is nothing to archive actually string message = string.Format((string)_Application.FindResource("ArchiveMessageNothingArchiveFormat"), projectName); _Application.Messenger.AddWarning(message); } } } catch (Exception ex) { Logger.Critical(ex); Collection <MessageDetail> details = new Collection <MessageDetail>(); details.Add(new MessageDetail(MessageType.Error, ex.Message)); string message = string.Format((string)_Application.FindResource("ArchiveMessageProcessFailedFromat"), projectName); MessageType type = (isAutoArchive)? MessageType.Warning : MessageType.Error; _Application.Messenger.AddMessage(type, message, details); } if (needClearBusyState) { WorkingStatusHelper.SetReleased(); } // open it again if (!string.IsNullOrEmpty(filePath)) { _Application.OpenProject(filePath, false); } }