Exemplo n.º 1
0
        private void OnAddCategory(object sender, ExecutedRoutedEventArgs e)
        {
            if (this.IsEditing)
            {
                return;
            }

            string name = this.Selected != null?Category.Combine(this.Selected.Name, "New Category") : "New Category";

            CategoryDialog dialog = CategoryDialog.ShowDialogCategory(this.MyMoney, name);

            dialog.Owner   = App.Current.MainWindow;
            dialog.Title   = "Add Category";
            dialog.Message = this.Selected != null ? "Please edit your new sub-category name or edit the whole string to add a new top level category"
                : "Please edit your new category name";

            dialog.Select("New Category");

            if (dialog.ShowDialog() == false)
            {
                return;
            }

            treeView.Items.Refresh();

            this.Dispatcher.BeginInvoke(new Action(() =>
            {
                // Now select the new subcategory and enter Rename mode
                this.Selected = dialog.Category;
            }), DispatcherPriority.ContextIdle);
        }
Exemplo n.º 2
0
        public async void OnCategoryItemClick(object sender, ItemClickEventArgs e)
        {
            if (!(e.ClickedItem is CategoryListViewItemViewModel selectedCategory))
            {
                return;
            }

            var editOperationDialog = new CategoryDialog(new CategoryDialogViewModel(selectedCategory.Model))
            {
                PrimaryButtonText = _localizationService.GetTranslateByKey(Localization.Save),
                CloseButtonText   = _localizationService.GetTranslateByKey(Localization.Cancel)
            };

            await editOperationDialog.ShowAsync();

            switch (editOperationDialog.Result)
            {
            case DialogResult.Save:
                await _model.UpdateCategory(selectedCategory.Model, GetCancellationToken());
                await UpdateCategories();

                break;

            case DialogResult.Delete:
                await _model.DeleteCategory(selectedCategory.Model, GetCancellationToken());
                await UpdateCategories();

                break;
            }
        }
Exemplo n.º 3
0
        private async void Select_Click(object sender, RoutedEventArgs e)
        {
            var dialog = new CategoryDialog();

            var button = await dialog.EnqueueAndShowIfAsync();

            if (button == ContentDialogResult.Primary)
            {
                SelectedCategoryTextBlock.Visibility = Visibility.Visible;
                SelectedCategoryTextBlock.Text       = $"Selected category: {(selectedCategory = dialog.Category).Name}";
                CategoryId.Text = selectedCategory.Id.ToString();
            }
        }
Exemplo n.º 4
0
 static public void ShowDetails(MyMoney money, Category c)
 {
     if (c != null)
     {
         CategoryDialog dialog = CategoryDialog.ShowDialogCategory(money, c.Name);
         dialog.Owner = App.Current.MainWindow;
         if (dialog.ShowDialog() == false)
         {
             // User clicked cancel
             return;
         }
         // todo: a bit ambiguous here what to do if they renamed the category...
         // for example, do we move all subcategories with it?
     }
 }
Exemplo n.º 5
0
        private async Task GetUserInputAsync()
        {
            var categoryDialog  = new CategoryDialog();
            var dialogViewModel = new CategoryDialogViewModel(async instance =>
            {
                await dialogCoordinator.HideMetroDialogAsync(this, categoryDialog);
                if (!instance.Cancel)
                {
                    ProcessUserInput(instance.Category);
                }
            });

            categoryDialog.DataContext = dialogViewModel;

            await dialogCoordinator.ShowMetroDialogAsync(this, categoryDialog);
        }
        private async void EditCategory(object sender, RoutedEventArgs e)
        {
            var element  = (FrameworkElement)sender;
            var category = element.DataContext as Category;

            if (category == null)
            {
                return;
            }

            var repository = ServiceLocator.Current.GetInstance <IRepository <Category> >();

            repository.Selected = category;

            var dialog = new CategoryDialog(true);
            await dialog.ShowAsync();
        }
Exemplo n.º 7
0
        public async void OnAddCategoryClick(object sender, RoutedEventArgs e)
        {
            var newCategory    = new CategoryDialogViewModel(_model.CreateNewCategory());
            var categoryDialog = new CategoryDialog(newCategory)
            {
                PrimaryButtonText = _localizationService.GetTranslateByKey(Localization.Save),
                CloseButtonText   = _localizationService.GetTranslateByKey(Localization.Cancel)
            };

            await categoryDialog.ShowAsync();

            if (categoryDialog.Result == DialogResult.Save)
            {
                await _model.SaveCategory(newCategory.Model, GetCancellationToken());
                await UpdateCategories();
            }
        }
        public void OpenDialog(string s)
        {
            switch (s)
            {
            case "Author":
                AuthorDialog ad = new AuthorDialog();
                ad.DataContext = this;
                DialogContent  = ad;
                break;

            case "Category":
                CategoryDialog cd = new CategoryDialog();
                cd.DataContext = this;
                DialogContent  = cd;
                break;

            default:
                PublisherDialog pd = new PublisherDialog();
                pd.DataContext = this;
                DialogContent  = pd;
                break;
            }
            IsDialogOpen = true;
        }
Exemplo n.º 9
0
        public void Delete()
        {
            if (this.IsEditing)
            {
                return; // ignore del key when editing.
            }

            Category c = this.Selected;

            if (c != null)
            {
                IList <Transaction> data = this.MyMoney.Transactions.GetTransactionsByCategory(c, null);
                Category            nc   = null;
                if (data.Count > 0)
                {
                    CategoryDialog dialog = CategoryDialog.ShowDialogCategory(this.MyMoney, c.Name);
                    dialog.Owner   = App.Current.MainWindow;
                    dialog.Title   = "Delete Category";
                    dialog.Message = "Please select a new category for the transactions that are still using the category '" + c.Name + "'";

                    if (dialog.ShowDialog() == false)
                    {
                        return;
                    }

                    // the onmoneychanged event should have fired, and the list is now updated.

                    nc = dialog.Category;
                    Account account = dialog.Transfer;
                    foreach (Transaction t in data)
                    {
                        if (t.Category == c)
                        {
                            if (account != null)
                            {
                                this.MyMoney.Transfer(t, account);
                                this.MyMoney.Rebalance(account);
                            }
                            else
                            {
                                t.Category = nc;
                            }
                        }
                        else if (t.IsSplit)
                        {
                            foreach (Split s in t.Splits.Items)
                            {
                                if (s.Category == c)
                                {
                                    if (account != null)
                                    {
                                        this.MyMoney.Transfer(s, account);
                                    }
                                    else
                                    {
                                        s.Category = nc;
                                    }
                                }
                            }
                        }
                    }
                }

                Category category = this.Selected;

                category.OnDelete();
            }
        }