Source

main / Source / Excel / Excel.AddIn / Excel.AddIn / Helpers / AlertHelper.cs

Full commit
using System;
using DataUp.Excel.BizLogic;

namespace DataUp.Excel.Addin
{
    public static class AlertHelper
    {
        public static AlertResult ShowAlert(AlertType alertType, string message, string generateButtonName, string ignoreButtonName, bool showIgnore = true)
        {
            AlertResult result = AlertResult.Cancel;

            AlertViewModel alertViewModel = new AlertViewModel(alertType, message, generateButtonName, ignoreButtonName, showIgnore);

            AlertMessage alert = new AlertMessage();
            System.Windows.Interop.WindowInteropHelper helper = new System.Windows.Interop.WindowInteropHelper(alert);
            helper.Owner = (IntPtr)ThisAddIn.ExcelApplication.Hwnd;

            alertViewModel.RequestClose += new EventHandler(alert.OnRequestClose);
            alertViewModel.Ignore += new EventHandler(alert.OnIgnore);
            alertViewModel.CancelClose += new EventHandler(alert.OnCancel);

            alert.Model = alertViewModel;
            alert.UpdateLayout();
            alert.ShowDialog();

            if (alert.DialogResult.HasValue && alert.DialogResult.Value)
            {
                result = AlertResult.Generate;
            }
            else
            {
                if (alert.IsCancelButtonClicked)
                {
                    result = AlertResult.Cancel;
                }
                else
                {
                    result = AlertResult.Ignore;
                }
            }

            alertViewModel.RequestClose -= new EventHandler(alert.OnRequestClose);
            alertViewModel.Ignore -= new EventHandler(alert.OnIgnore);
            alertViewModel.CancelClose -= new EventHandler(alert.OnCancel);
            alert.Close();

            return result;
        }
    }
}