Beispiel #1
0
        /// <summary>
        /// The Vm_DeleteZipFileRequested.
        /// </summary>
        /// <param name="sender">The sender<see cref="object"/>.</param>
        /// <param name="e">The e<see cref="EventArgs"/>.</param>
        private void Vm_DeleteZipFileRequested(object sender, EventArgs e)
        {
            var a     = Assembly.GetExecutingAssembly();
            var st    = a.GetManifestResourceStream("PluginManager.Wpf.Resources.qmark.ico");
            var qmark = new Icon(st);

            st.Dispose();

            var win = new TaskDialog()
            {
                WindowTitle    = "Delete Requested",
                MainIcon       = TaskDialogIcon.Custom,
                CustomMainIcon = qmark
            };

            var rb1 = new TaskDialogRadioButton()
            {
                Text = "Only delete the zip file."
            };
            var rb2 = new TaskDialogRadioButton()
            {
                Text = "Only delete the database record."
            };
            var rb3 = new TaskDialogRadioButton()
            {
                Text = "Delete both record and file.", Checked = true
            };
            var bt1 = new TaskDialogButton(ButtonType.Cancel);
            var bt2 = new TaskDialogButton(ButtonType.Ok);

            win.RadioButtons.Add(rb1);
            win.RadioButtons.Add(rb2);
            win.RadioButtons.Add(rb3);
            win.Buttons.Add(bt1);
            win.Buttons.Add(bt2);
            win.Content = "What do you want to delete?";

            var result = win.ShowDialog();

            qmark.Dispose();
            win.Dispose();
            rb1.Dispose();
            rb2.Dispose();
            rb3.Dispose();
            bt1.Dispose();
            bt2.Dispose();

            if (result == null || result.ButtonType == ButtonType.Cancel)
            {
                result.Dispose();
                return;
            }

            result.Dispose();

            var vm = sender as ZipFileViewModel;

            Debug.Assert(vm != null);

            var option = win.RadioButtons[0].Checked ? 1 : win.RadioButtons[1].Checked ? 2 : 3;

            switch (option)
            {
            case 1:
                if (!DeleteZipFile(vm))
                {
                    MessageBox.Show($"Unable to delete {vm.Filename}.", "Exception");
                }
                break;

            case 2:
                DeleteRecord(vm);
                break;

            case 3:
                if (!DeleteZipFile(vm))
                {
                    var dr = MessageBox.Show($"Unable to delete {vm.Filename}. Do you want to delete the record anyway?", "Exception", MessageBoxButton.YesNo);
                    if (dr != MessageBoxResult.Yes)
                    {
                        return;
                    }
                }
                DeleteRecord(vm);
                break;

            default:
                throw new ArgumentException("Invalid radio button.");
            }
        }
Beispiel #2
0
        /// <summary>
        /// The Vm_DeleteSelectedZipFilesRequested.
        /// </summary>
        /// <param name="sender">The sender<see cref="object"/>.</param>
        /// <param name="e">The e<see cref="EventArgs"/>.</param>
        private void Vm_DeleteSelectedZipFilesRequested(object sender, EventArgs e)
        {
            var vm    = DataContext as MainViewModel;
            var count = vm.SelectedZipFilesCollection.Count;

            var message = $"You have {count} zip file(s) selected and have initiated the delete function. What do you want to do?";
            var a       = Assembly.GetExecutingAssembly();
            var st      = a.GetManifestResourceStream("PluginManager.Wpf.Resources.qmark.ico");
            var qmark   = new Icon(st);

            var win = new TaskDialog()
            {
                WindowTitle    = "Delete Requested",
                MainIcon       = TaskDialogIcon.Custom,
                Content        = message,
                CustomMainIcon = qmark
            };

            var rb1 = new TaskDialogRadioButton()
            {
                Text = "Only delete zip files."
            };
            var rb2 = new TaskDialogRadioButton()
            {
                Text = "Only delete database records."
            };
            var rb3 = new TaskDialogRadioButton()
            {
                Text = "Delete both records and files.", Checked = true
            };
            var btn1 = new TaskDialogButton(ButtonType.Cancel);
            var btn2 = new TaskDialogButton(ButtonType.Ok);

            win.RadioButtons.Add(rb1);
            win.RadioButtons.Add(rb2);
            win.RadioButtons.Add(rb3);
            win.Buttons.Add(btn1);
            win.Buttons.Add(btn2);

            var result = win.ShowDialog();

            win.Dispose();
            qmark.Dispose();
            rb1.Dispose();
            rb2.Dispose();
            rb3.Dispose();
            btn1.Dispose();
            btn2.Dispose();
            st.Dispose();


            if (result == null || result.ButtonType == ButtonType.Cancel)
            {
                result.Dispose();
                return;
            }

            result.Dispose();

            // #Switch
            var option       = win.RadioButtons[0].Checked ? 1 : win.RadioButtons[1].Checked ? 2 : 3;
            var selectedZips = new List <ZipFileViewModel>(vm.SelectedZipFilesCollection);

            foreach (var item in selectedZips)
            {
                switch (option)
                {
                case 1:
                    if (!DeleteZipFile(item))
                    {
                        MessageBox.Show($"Unable to delete {item.Filename}.", "Exception");
                    }
                    break;

                case 2:
                    DeleteRecord(item);
                    break;

                case 3:
                    if (!DeleteZipFile(item))
                    {
                        var dr = MessageBox.Show($"Unable to delete {item.Filename}. Do you want to delete the record anyway?", "Exception", MessageBoxButton.YesNo);
                        if (dr != MessageBoxResult.Yes)
                        {
                            continue;
                        }
                    }
                    DeleteRecord(item);
                    break;

                default:
                    throw new ArgumentException("Invalid radio button.");
                }
            }
        }