// ========================================================================
// Copyright 2007 - Volian Enterprises, Inc. All rights reserved.          
// Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE
// ------------------------------------------------------------------------
// $Workfile: $     $Revision: $                                           
// $Author: $   $Date: $                                                   
//                                                                         
// $History: $                                                             
// ========================================================================
using System;
using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel;
using System.Collections.Generic;
using Csla.Validation;
namespace VEPROMS.CSLA.Library
{
    /// 
    ///	ZTransition Generated by MyGeneration using the CSLA Object Mapping template
    /// 
    [Serializable()]
    [TypeConverter(typeof(ZTransitionConverter))]
    public partial class ZTransition : BusinessBase, IDisposable, IVEHasBrokenRules
    {
        #region Log4Net
        private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
        #endregion
        #region Refresh
        private List _RefreshZTransitions = new List();
        private void AddToRefreshList(List refreshZTransitions)
        {
            if (IsDirty)
                refreshZTransitions.Add(this);
        }
        private void ClearRefreshList()
        {
            _RefreshZTransitions = new List();
        }
        private void BuildRefreshList()
        {
            ClearRefreshList();
            AddToRefreshList(_RefreshZTransitions);
        }
        private void ProcessRefreshList()
        {
            foreach (ZTransition tmp in _RefreshZTransitions)
            {
                ZTransitionInfo.Refresh(tmp);
            }
            ClearRefreshList();
        }
        #endregion
        #region Collection
        private static List _CacheList = new List();
        protected static void AddToCache(ZTransition zTransition)
        {
            if (!_CacheList.Contains(zTransition)) _CacheList.Add(zTransition); // In AddToCache
        }
        protected static void RemoveFromCache(ZTransition zTransition)
        {
            while (_CacheList.Contains(zTransition)) _CacheList.Remove(zTransition); // In RemoveFromCache
        }
        private static Dictionary> _CacheByPrimaryKey = new Dictionary>();
        private static void ConvertListToDictionary()
        {
            while (_CacheList.Count > 0) // Move ZTransition(s) from temporary _CacheList to _CacheByPrimaryKey
            {
                ZTransition tmp = _CacheList[0]; // Get the first ZTransition
                string pKey = tmp.TransitionID.ToString();
                if (!_CacheByPrimaryKey.ContainsKey(pKey))
                {
                    _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey
                }
                _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list
                _CacheList.RemoveAt(0); // Remove the first ZTransition
            }
        }
        protected static ZTransition GetCachedByPrimaryKey(int transitionID)
        {
            ConvertListToDictionary();
            string key = transitionID.ToString();
            if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0];
            return null;
        }
        #endregion
        #region Business Methods
        private string _ErrorMessage = string.Empty;
        public string ErrorMessage
        {
            get { return _ErrorMessage; }
        }
        private int _TransitionID;
        [System.ComponentModel.DataObjectField(true, true)]
        public int TransitionID
        {
            [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
            get
            {
                if (_MyTransition != null) _TransitionID = _MyTransition.TransitionID;
                return _TransitionID;
            }
        }
        private Transition _MyTransition;
        [System.ComponentModel.DataObjectField(true, true)]
        public Transition MyTransition
        {
            [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
            get
            {
                if (_MyTransition == null && _TransitionID != 0) _MyTransition = Transition.Get(_TransitionID);
                return _MyTransition;
            }
        }
        private string _Oldto = string.Empty;
        public string Oldto
        {
            [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
            get
            {
                return _Oldto;
            }
            [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
            set
            {
                if (value == null) value = string.Empty;
                if (_Oldto != value)
                {
                    _Oldto = value;
                    PropertyHasChanged();
                }
            }
        }
        private byte[] _LastChanged = new byte[8];//timestamp
        public override bool IsDirty
        {
            get { return base.IsDirty; }
        }
        public bool IsDirtyList(List