Source

main-vinayFork / Source / Excel / Excel.AddIn / Excel.AddIn / ViewModels / ParameterMetadataViewModel.cs

Full commit
using System;
using System.ComponentModel;

namespace DataUp.Excel.Addin
{
    public class ParameterMetadataViewModel : ViewModelBase, IDataErrorInfo
    {
        private string entityName;
        private string entityDescription;
        private string name;
        private string description;
        private string type;
        private string units;

        private bool enableUnits;

        public string EntityName
        {
            get { return this.entityName; }
            set
            {
                this.entityName = value;
                OnNotifyPropertyChanged("EntityName");
            }
        }

        public string EntityDescription
        {
            get { return this.entityDescription; }
            set
            {
                this.entityDescription = value;
                OnNotifyPropertyChanged("EntityDescription");
            }
        }

        public string Name
        {
            get
            {
                return this.name;
            }
            set
            {
                this.name = value;
                OnNotifyPropertyChanged("Name");
            }
        }

        public string Description
        {
            get
            {
                return this.description;
            }
            set
            {
                this.description = value;
                OnNotifyPropertyChanged("Description");
            }
        }

        public string Type
        {
            get
            {
                return this.type;
            }
            set
            {
                this.type = value;
                OnNotifyPropertyChanged("Type");
                this.EnableUnits = string.Compare(this.type, "Numeric", true) == 0;
                if (!this.EnableUnits)
                {
                    this.Units = string.Empty;
                }
            }
        }

        public string Units
        {
            get
            {
                return this.units;
            }
            set
            {
                this.units = value;
                OnNotifyPropertyChanged("Units");
            }
        }

        public bool EnableUnits
        {
            get
            {
                return this.enableUnits;
            }
            set
            {
                this.enableUnits = value;
                OnNotifyPropertyChanged("EnableUnits");
            }
        }

        public bool Validate()
        {
            if (String.IsNullOrEmpty(this.Name))
            {
                return false;
            }
            
            return true;
        }

        #region IDataErrorInfo Members

        public string Error
        {
            get { return string.Empty; }
        }

        public string this[string columnName]
        {
            get {
                string errorMsg = null;
                switch(columnName)
                {
                    case "Name":
                        if (String.IsNullOrEmpty(Name))
                        {
                            errorMsg = "Name is required.";
                        }
                        break;
                }
                return errorMsg;
            }
        }

        #endregion
    }
}