Click here to Skip to main content
15,896,453 members
Articles / Database Development / SQL Server

Tier Generator 1.0

Rate me:
Please Sign up or sign in to vote.
4.89/5 (140 votes)
26 Jul 2008CPOL2 min read 256.5K   13.3K   297  
A powerful tool for rapid application development.
using System;
using System.Collections.Generic;
using System.ComponentModel;


namespace $PROJECT_NAMESPACE$.BusinessLayer
{
    /// <summary>
    /// base class for all business objects
    /// </summary>
    public abstract class BusinessObjectBase : INotifyPropertyChanged
    {

        #region Data Member

        bool _disablePropertyChangeEvent = false;
        Validation.ValidationRules _validationRules = null;

        #endregion

        #region Properties

        #region Internal Properties

        /// <summary>
        /// get/set the Disable Property change event value
        /// </summary>
        internal bool DisablePropertyChangeEvent
        {
            get { return _disablePropertyChangeEvent; }
            set { _disablePropertyChangeEvent = value; }
        }

        /// <summary>
        /// get the list of validation rules
        /// </summary>
        internal Validation.ValidationRules ValidationRules
        {
            get 
            {
                if (_validationRules == null)
                {
                    _validationRules = new Validation.ValidationRules(this);

                    // Add the validation rules for this object
                    AddValidationRules(); 
                }

                return _validationRules; 
            
            }

        }

        #endregion

        #region Public Properties

        /// <summary>
        /// gets the valid status of the object
        /// </summary>
        public bool IsValid
        {
            get
            {
                return this.ValidationRules.IsValid;  
            }
        }

        /// <summary>
        /// get the list of the broken rules
        /// </summary>
        public Validation.BrokenRulesList BrokenRulesList
        {
            get
            {
                return ValidationRules.BrokenRules;
            }
        }

        #endregion

        #endregion

        #region Virtual Methods

        /// <summary>
        /// Add validation rules
        /// </summary>
        internal virtual void AddValidationRules()
        {
            
        }

        #endregion

        #region Implement INotifyPropertyChanged

        /// <summary>
        /// override Property Change event of INotifyPropertyChanged
        /// </summary>
        public event PropertyChangedEventHandler PropertyChanged;

        /// <summary>
        /// method called when property has changed
        /// </summary>
        /// <param name="propertyName">The name of the property that has changed.</param>
        protected virtual void PropertyHasChanged(string propertyName)
        {
            if (!DisablePropertyChangeEvent)
            {
                // call overloaded method
                PropertyHasChanged(new PropertyChangedEventArgs(propertyName));
            }
        }

        /// <summary>
        /// Called when a property has changed
        /// </summary>
        /// <param name="e">PropertyChangedEventArgs</param>
        protected virtual void PropertyHasChanged(PropertyChangedEventArgs e)
        {
            if (!DisablePropertyChangeEvent)
            {
                ValidationRules.ValidateRules(e.PropertyName);

                if (PropertyChanged != null)
                {
                    PropertyChanged(this, e);
                }
            }
        }

        #endregion

    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Chief Technology Officer
Pakistan Pakistan
Passion and positive dedication is essential part of success. I believe on hardworking and sharing knowledge with others. I always try to be a better than I am and think positive for positive result.

My Blogs

My Linked-In Profile

Comments and Discussions