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

Naethra D ba1cb57 








































































































































using System.Collections.ObjectModel;
using System.Linq;

namespace DataUp.Excel.Addin
{
    /// <summary>
    /// TODO: Update summary.
    /// </summary>
    public class SheetViewModel : ErrorDetailsViewModelBase
    {
        private ObservableCollection<ErrorDetailViewModel> errors;
        private int totalErrorCount = 0;
        private bool? allSelected;

        public SheetViewModel()
        {
            this.SelectAllCommand = new DelegateCommand(SelectAllExecute);
            this.ErrorSelectedCommand = new DelegateCommand(ErrorSelectedExecute);
            this.FixSelectedCommand = new DelegateCommand(RemoveSelectedItemsExecute, RemoveSelectedCanExecute);
            this.AllSelected = false;

            this.Errors = new ObservableCollection<ErrorDetailViewModel>();
        }

        /// <summary>
        /// Gets or sets the errors.
        /// </summary>
        public ObservableCollection<ErrorDetailViewModel> Errors
        {
            get
            {
                return errors;
            }
            set
            {
                errors = value;
                OnNotifyPropertyChanged("Errors");
                OnNotifyPropertyChanged("CategoryHighCount");
                OnNotifyPropertyChanged("CategoryMediumCount");
                OnNotifyPropertyChanged("CategoryLowCount");
            }
        }

        /// <summary>
        /// Gets or sets TotalErrorCount
        /// </summary>
        public int TotalErrorCount
        {
            get
            {
                return totalErrorCount;
            }
            set
            {
                totalErrorCount = value;
                OnNotifyPropertyChanged("TotalErrorCount");
            }
        }

        public DelegateCommand SelectAllCommand { get; private set; }

        public DelegateCommand ErrorSelectedCommand { get; private set; }

        public DelegateCommand FixSelectedCommand { get; private set; }

        public bool? AllSelected
        {
            get
            {
                return allSelected;
            }
            set
            {
                allSelected = value;
                this.OnNotifyPropertyChanged("AllSelected");
            }
        }

        public void RemoveSelected()
        {
            ObservableCollection<ErrorDetailViewModel> selectedErrors = new ObservableCollection<ErrorDetailViewModel>();

            foreach (var error in this.Errors)
            {
                if (error.IsChecked)
                {
                    selectedErrors.Add(error);
                    Controller.Instance.ResolveAllErrors(error.Error, error.SheetName);
                }
            }

            foreach (var item in selectedErrors)
            {
                this.Errors.Remove(item);
            }

            this.TotalErrorCount = this.Errors.Count;
        }

        private void SelectAllExecute()
        {
            if (this.AllSelected.HasValue)
            {
                foreach (var error in this.Errors.Where(s => s.IsRemovable))
                {
                    error.IsChecked = this.AllSelected.Value;
                }
            }
        }

        private void ErrorSelectedExecute()
        {
            if (this.errors.Where(s => s.IsRemovable).All(s => s.IsChecked))
            {
                this.AllSelected = true;
            }
            else if (this.errors.Where(s => s.IsRemovable).All(s => !s.IsChecked))
            {
                this.AllSelected = false;
            }
            else
            {
                this.AllSelected = null;
            }
        }

        private void RemoveSelectedItemsExecute()
        {
            RemoveSelected();
        }

        private bool RemoveSelectedCanExecute()
        {
            return this.Errors.ToList().FindAll(s => s.IsRemovable).Count > 0; ;
        }
    }
}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.