コード例 #1
0
        /// <summary>
        /// Delete current project.
        /// </summary>
        private void _DeleteProject()
        {
            // deletes item in insertion row
            if (_InsertionRow.IsBeingEdited)
            {
                XceedGrid.CancelEdit();
                return;
            }

            if (XceedGrid.IsBeingEdited)
            {
                XceedGrid.CancelEdit();
            }

            string selectedProjectName = SelectedProjectName;

            if (selectedProjectName == null)
            {
                return;
            }

            bool doProcess = true;

            if (Settings.Default.IsAllwaysAskBeforeDeletingEnabled)
            {
                // show warning dialog
                doProcess = DeletingWarningHelper.Execute(selectedProjectName, "Project", "Project");
            }

            // do process
            if (doProcess)
            {
                _itemIndexToSelection = XceedGrid.SelectedIndex;

                string path = string.Empty;
                foreach (ProjectConfiguration project in App.Current.ProjectCatalog.Projects)
                {
                    if (project.Name.Equals(selectedProjectName, StringComparison.OrdinalIgnoreCase))
                    {
                        path = project.FilePath;
                        break; // NOTE: founded
                    }
                }

                try
                {
                    ProjectFactory.DeleteProject(path);
                    UpdateView();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(App.Current.MainWindow, ex.Message, (string)App.Current.FindResource("WarningMessageBoxTitle"), MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Delete button click handler.
        /// </summary>
        private void _DeleteTemplate_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                ReportInfo selectedInfo = _GetSelectedInfo();
                if (null != selectedInfo)
                {
                    bool doProcess = true;
                    if (Settings.Default.IsAllwaysAskBeforeDeletingEnabled)
                    {
                        // show warning dialog
                        doProcess = DeletingWarningHelper.Execute(selectedInfo.Name, "ReportTemplate", "ReportTemplate");
                    }

                    if (doProcess)
                    {
                        App.Current.ReportGenerator.DeleteReportInfo(selectedInfo.Name);
                        _itemIndexToSelection = xceedGridReports.SelectedIndex;

                        // remove template file
                        string reportTemplatePath = ReportsGenerator.GetTemplateAbsolutelyPath(selectedInfo.TemplatePath);
                        _DeleteFileSafe(reportTemplatePath);

                        // remove sub report templates
                        foreach (SubReportInfo subReport in selectedInfo.SubReports)
                        {
                            reportTemplatePath = ReportsGenerator.GetTemplateAbsolutelyPath(subReport.TemplatePath);
                            _DeleteFileSafe(reportTemplatePath);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
            }

            _InitReportTable();
        }
コード例 #3
0
        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]);
                    }
                }
            }
        }