Source

main / Source / Excel / Excel.AddIn / Excel.AddIn / ViewModels / AlertViewModel.cs

Full commit
Naethra D ba1cb57 















































































































































































using System;
using System.Windows.Input;
using DataUp.Excel.BizLogic;
using DataUp.Excel.Common;

namespace DataUp.Excel.Addin
{
    public class AlertViewModel : ViewModelBase
    {
        private bool showIgnoreButton;
        private string alertMessage;
        private string generateButtonName;
        private string ignoreButtonName;

        private ICommand generateCommand;
        private ICommand ignoreErrors;
        private ICommand cancel;

        /// <summary>
        /// Capture View window close request
        /// </summary>
        public event EventHandler RequestClose;
        public event EventHandler Ignore;
        public event EventHandler CancelClose;

        public bool ShowIgnoreButton
        {
            get
            {
                return showIgnoreButton;
            }
            set
            {
                showIgnoreButton = value;
                OnNotifyPropertyChanged("ShowIgnoreButton");
            }
        }

        public string AlertMessage
        {
            get
            {
                return alertMessage;
            }
            set
            {
                alertMessage = value;
                OnNotifyPropertyChanged("AlertMessage");
            }
        }

        public string GenerateButtonName
        {
            get
            {
                return generateButtonName;
            }
            set
            {
                generateButtonName = value;
                OnNotifyPropertyChanged("GenerateButtonName");
            }
        }

        public string IgnoreButtonName
        {
            get
            {
                return ignoreButtonName;
            }
            set
            {
                ignoreButtonName = value;
                OnNotifyPropertyChanged("IgnoreButtonName");
            }
        }

        public AlertType Type { get; set; }

        public ICommand GenerateCommand
        {
            get
            {
                return generateCommand;
            }
            set
            {
                if (generateCommand != value)
                {
                    generateCommand = value;
                    OnNotifyPropertyChanged("GenerateCommand");
                }
            }
        }

        public ICommand IgnoreCommand
        {
            get
            {
                return ignoreErrors;
            }
            set
            {
                if (ignoreErrors != value)
                {
                    ignoreErrors = value;
                    OnNotifyPropertyChanged("IgnoreCommand");
                }
            }
        }

        public ICommand CancelCommand
        {
            get
            {
                return cancel;
            }
            set
            {
                if (cancel != value)
                {
                    cancel = value;
                    OnNotifyPropertyChanged("CancelCommand");
                }
            }
        }

        public AlertViewModel(AlertType alertType, string message, string generateButtonName, string ignoreButtonName, bool showIgnore = true)
        {
            this.Type = alertType;
            this.AlertMessage = message;
            this.GenerateButtonName = generateButtonName;
            this.ShowIgnoreButton = showIgnore;
            this.IgnoreButtonName = ignoreButtonName;

            InitCommands();
        }

        /// <summary>
        /// Raise window close event
        /// </summary>
        public void OnRequestClose()
        {
            RequestClose.OnFire(this, EventArgs.Empty);
        }

        public void OnIgnoreClose()
        {
            Ignore.OnFire(this, EventArgs.Empty);
        }

        public void OnCancelClose()
        {
            CancelClose.OnFire(this, EventArgs.Empty);
        }

        private void InitCommands()
        {
            this.GenerateCommand = new DelegateCommand<MetadataListViewModel>(viewModel =>
            {
                this.OnRequestClose();
            });

            this.IgnoreCommand = new DelegateCommand<MetadataListViewModel>(viewModel =>
            {
                this.OnIgnoreClose();
            });

            this.cancel = new DelegateCommand<MetadataListViewModel>(viewModel =>
            {
                this.OnCancelClose();
            });
        }
    }
}