Exemple #1
0
        /// <summary>
        /// The LastChance.
        /// </summary>
        /// <param name="title">The title<see cref="string"/>.</param>
        /// <param name="heading">The heading<see cref="string"/>.</param>
        /// <param name="content">The content<see cref="string"/>.</param>
        /// <param name="warning">The warning<see cref="bool"/>.</param>
        /// <returns>The <see cref="bool"/>.</returns>
        public static bool LastChance(string title, string heading, string content, bool warning = false)
        {
            TaskDialog td;

            td                 = new();
            td.WindowTitle     = title;
            td.MainInstruction = heading;
            td.Content         = content;
            td.MainIcon        = warning ? TaskDialogIcon.Warning : TaskDialogIcon.Information;

            var bt1 = new TaskDialogButton("Yes")
            {
                ButtonType = ButtonType.Yes
            };
            var bt2 = new TaskDialogButton("No")
            {
                ButtonType = ButtonType.No
            };

            td.Buttons.Add(bt1);
            td.Buttons.Add(bt2);

            var d = td.ShowDialog();

            var result = d.ButtonType == ButtonType.Yes;

            bt1.Dispose();
            bt2.Dispose();
            d.Dispose();

            return(result);
        }
Exemple #2
0
        /// <summary>
        /// The Inform.
        /// </summary>
        /// <param name="title">The title<see cref="string"/>.</param>
        /// <param name="content">The content<see cref="string"/>.</param>
        internal static void Inform(string title, string content)
        {
            TaskDialog td;

            td             = new();
            td.WindowTitle = title;
            td.Content     = content;
            td.MainIcon    = TaskDialogIcon.Information;
            var btn = new TaskDialogButton("Okay")
            {
                ButtonType = ButtonType.Ok
            };

            td.Buttons.Add(btn);
            _ = td.Show();

            btn.Dispose();
        }
Exemple #3
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.");
            }
        }
Exemple #4
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.");
                }
            }
        }