// ========================================================================
// 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
{
    /// 
    ///	Owner Generated by MyGeneration using the CSLA Object Mapping template
    /// 
    [Serializable()]
    [TypeConverter(typeof(OwnerConverter))]
    public partial class Owner : BusinessBase, IDisposable, IVEHasBrokenRules
    {
        #region Log4Net
        private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
        #endregion
        #region Refresh
        private List _RefreshOwners = new List();
        private void AddToRefreshList(List refreshOwners)
        {
            if (IsDirty)
                refreshOwners.Add(this);
        }
        private void ClearRefreshList()
        {
            _RefreshOwners = new List();
        }
        private void BuildRefreshList()
        {
            ClearRefreshList();
            AddToRefreshList(_RefreshOwners);
        }
        private void ProcessRefreshList()
        {
            foreach (Owner tmp in _RefreshOwners)
            {
                OwnerInfo.Refresh(tmp);
            }
            ClearRefreshList();
        }
        #endregion
        #region Collection
        private static List _CacheList = new List();
        protected static void AddToCache(Owner owner)
        {
            if (!_CacheList.Contains(owner)) _CacheList.Add(owner); // In AddToCache
        }
        protected static void RemoveFromCache(Owner owner)
        {
            while (_CacheList.Contains(owner)) _CacheList.Remove(owner); // In RemoveFromCache
        }
        private static Dictionary> _CacheByPrimaryKey = new Dictionary>();
        private static void ConvertListToDictionary()
        {
            while (_CacheList.Count > 0) // Move Owner(s) from temporary _CacheList to _CacheByPrimaryKey
            {
                Owner tmp = _CacheList[0]; // Get the first Owner
                string pKey = tmp.OwnerID.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 Owner
            }
        }
        protected static Owner GetCachedByPrimaryKey(int ownerID)
        {
            ConvertListToDictionary();
            string key = ownerID.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 static int _nextOwnerID = -1;
        public static int NextOwnerID
        {
            get { return _nextOwnerID--; }
        }
        private int _OwnerID;
        [System.ComponentModel.DataObjectField(true, true)]
        public int OwnerID
        {
            [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
            get
            {
                return _OwnerID;
            }
        }
        private int _SessionID;
        public int SessionID
        {
            [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
            get
            {
                return _SessionID;
            }
            [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
            set
            {
                if (_SessionID != value)
                {
                    _SessionID = value;
                    PropertyHasChanged();
                }
            }
        }
        private byte _OwnerType;
        public byte OwnerType
        {
            [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
            get
            {
                return _OwnerType;
            }
            [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
            set
            {
                if (_OwnerType != value)
                {
                    _OwnerType = value;
                    PropertyHasChanged();
                }
            }
        }
        private int _OwnerItemID;
        public int OwnerItemID
        {
            [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
            get
            {
                return _OwnerItemID;
            }
            [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
            set
            {
                if (_OwnerItemID != value)
                {
                    _OwnerItemID = value;
                    PropertyHasChanged();
                }
            }
        }
        private DateTime _DTSStart = new DateTime();
        public DateTime DTSStart
        {
            [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
            get
            {
                return _DTSStart;
            }
            [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
            set
            {
                if (_DTSStart != value)
                {
                    _DTSStart = value;
                    PropertyHasChanged();
                }
            }
        }
        private byte[] _LastChanged = new byte[8];//timestamp
        public override bool IsDirty
        {
            get { return base.IsDirty; }
        }
        public bool IsDirtyList(List