Exemplo n.º 1
0
        void Add_Click(object sender, RoutedEventArgs e)
        {
            var  sel      = SelectedCat;
            long?parentId = null;

            if (sel != null)
            {
                var kindOfAdd = MessageBox.Show("Create a sub-item of the selected category? (If No, it will be created at the root level.)", "Add Category", MessageBoxButton.YesNoCancel, MessageBoxImage.Question);
                if (kindOfAdd == MessageBoxResult.Yes)
                {
                    parentId = sel.RowId;
                }
                else if (kindOfAdd != MessageBoxResult.No)
                {
                    return; //canceled
                }
            }
            string s = StringDialog.GetInput("New category name", "", 40);

            if (s == null)
            {
                return;
            }
            Globals.UI.ModifyCat(0, cat =>
            {
                cat.ParentId = parentId;
                cat.Name     = s;
            });
            DataContext = new VM();
        }
Exemplo n.º 2
0
        void AddCat_Click(object sender, RoutedEventArgs e)
        {
            var prevSelectedCatIds = _VM.GetEditedSelectedIds();

            //get whether root or child
            long?parentId = null;
            var  sel      = SelectedItem;

            if (sel != null)
            {
                var answer = MessageBox.Show($"Add as sub-category of {sel.Name}? (If No, it will be created at the root level.)", "New Category", MessageBoxButton.YesNoCancel, MessageBoxImage.Question);
                if (answer == MessageBoxResult.Yes)
                {
                    parentId = sel.RowId;
                }
                else if (answer != MessageBoxResult.No)
                {
                    return;
                }
            }

            //get name
            var name = StringDialog.GetInput("Category name", "", 40);

            if (name == null)
            {
                return;
            }
            name = name.Trim();
            if (name.Length == 0)
            {
                return;
            }

            //save
            Globals.UI.ModifyCat(0, c =>
            {
                c.Name     = name;
                c.ParentId = parentId;
            });

            //reload
            _VM         = new VM(prevSelectedCatIds);
            DataContext = _VM;
        }
Exemplo n.º 3
0
        void Rename_Click(object sender, RoutedEventArgs e)
        {
            var sel = SelectedCat;

            if (sel == null)
            {
                return;
            }
            string s = StringDialog.GetInput("New name", sel.Name, 40);

            if (s == null)
            {
                return;
            }
            Globals.UI.ModifyCat(sel.RowId, cat =>
            {
                cat.Name = s;
            });
            DataContext = new VM();
        }