335 lines
		
	
	
		
			11 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			335 lines
		
	
	
		
			11 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
| // ========================================================================
 | |
| // 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;
 | |
| namespace VEPROMS.CSLA.Library
 | |
| {
 | |
| 	public delegate void RevisionROCheckInfoEvent(object sender);
 | |
| 	/// <summary>
 | |
| 	///	RevisionROCheckInfo Generated by MyGeneration using the CSLA Object Mapping template
 | |
| 	/// </summary>
 | |
| 	[Serializable()]
 | |
| 	[TypeConverter(typeof(RevisionROCheckInfoConverter))]
 | |
| 	public partial class RevisionROCheckInfo : ReadOnlyBase<RevisionROCheckInfo>, IDisposable
 | |
| 	{
 | |
| 		public event RevisionROCheckInfoEvent Changed;
 | |
| 		private void OnChange()
 | |
| 		{
 | |
| 			if (Changed != null) Changed(this);
 | |
| 		}
 | |
| 		#region Log4Net
 | |
| 		private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
 | |
| 		#endregion
 | |
| 		#region Collection
 | |
| 		private static List<RevisionROCheckInfo> _CacheList = new List<RevisionROCheckInfo>();
 | |
| 		protected static void AddToCache(RevisionROCheckInfo revisionROCheckInfo)
 | |
| 		{
 | |
| 			if (!_CacheList.Contains(revisionROCheckInfo)) _CacheList.Add(revisionROCheckInfo); // In AddToCache
 | |
| 		}
 | |
| 		protected static void RemoveFromCache(RevisionROCheckInfo revisionROCheckInfo)
 | |
| 		{
 | |
| 			while (_CacheList.Contains(revisionROCheckInfo)) _CacheList.Remove(revisionROCheckInfo); // In RemoveFromCache
 | |
| 		}
 | |
| 		private static Dictionary<string, List<RevisionROCheckInfo>> _CacheByPrimaryKey = new Dictionary<string, List<RevisionROCheckInfo>>();
 | |
| 		private static void ConvertListToDictionary()
 | |
| 		{
 | |
| 			while (_CacheList.Count > 0) // Move RevisionROCheckInfo(s) from temporary _CacheList to _CacheByPrimaryKey
 | |
| 			{
 | |
| 				RevisionROCheckInfo tmp = _CacheList[0]; // Get the first RevisionROCheckInfo
 | |
| 				string pKey = tmp.CheckID.ToString();
 | |
| 				if (!_CacheByPrimaryKey.ContainsKey(pKey))
 | |
| 				{
 | |
| 					_CacheByPrimaryKey[pKey] = new List<RevisionROCheckInfo>(); // Add new list for PrimaryKey
 | |
| 				}
 | |
| 				_CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list
 | |
| 				_CacheList.RemoveAt(0); // Remove the first RevisionROCheckInfo
 | |
| 			}
 | |
| 		}
 | |
| 		internal static void AddList(RevisionROCheckInfoList lst)
 | |
| 		{
 | |
| 			foreach (RevisionROCheckInfo item in lst) AddToCache(item);
 | |
| 		}
 | |
| 		protected static RevisionROCheckInfo GetCachedByPrimaryKey(int checkID)
 | |
| 		{
 | |
| 			ConvertListToDictionary();
 | |
| 			string key = checkID.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; }
 | |
| 		}
 | |
| 		protected RevisionROCheck _Editable;
 | |
| 		private IVEHasBrokenRules HasBrokenRules
 | |
| 		{
 | |
| 			get
 | |
| 			{
 | |
| 				IVEHasBrokenRules hasBrokenRules = null;
 | |
| 				if (_Editable != null)
 | |
| 					hasBrokenRules = _Editable.HasBrokenRules;
 | |
| 				return hasBrokenRules;
 | |
| 			}
 | |
| 		}
 | |
| 		private int _CheckID;
 | |
| 		[System.ComponentModel.DataObjectField(true, true)]
 | |
| 		public int CheckID
 | |
| 		{
 | |
| 			[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
 | |
| 			get
 | |
| 			{
 | |
| 				CanReadProperty("CheckID", true);
 | |
| 				return _CheckID;
 | |
| 			}
 | |
| 		}
 | |
| 		private int _ItemID;
 | |
| 		public int ItemID
 | |
| 		{
 | |
| 			[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
 | |
| 			get
 | |
| 			{
 | |
| 				CanReadProperty("ItemID", true);
 | |
| 				return _ItemID;
 | |
| 			}
 | |
| 		}
 | |
| 		private int _ROID;
 | |
| 		public int ROID
 | |
| 		{
 | |
| 			[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
 | |
| 			get
 | |
| 			{
 | |
| 				CanReadProperty("ROID", true);
 | |
| 				return _ROID;
 | |
| 			}
 | |
| 		}
 | |
| 		private string _RODate = string.Empty;
 | |
| 		public string RODate
 | |
| 		{
 | |
| 			[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
 | |
| 			get
 | |
| 			{
 | |
| 				CanReadProperty("RODate", true);
 | |
| 				return _RODate;
 | |
| 			}
 | |
| 		}
 | |
| 		private string _ROValue = string.Empty;
 | |
| 		public string ROValue
 | |
| 		{
 | |
| 			[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
 | |
| 			get
 | |
| 			{
 | |
| 				CanReadProperty("ROValue", true);
 | |
| 				return _ROValue;
 | |
| 			}
 | |
| 		}
 | |
| 		// CSLATODO: Replace base RevisionROCheckInfo.ToString function as necessary
 | |
| 		/// <summary>
 | |
| 		/// Overrides Base ToString
 | |
| 		/// </summary>
 | |
| 		/// <returns>A string representation of current RevisionROCheckInfo</returns>
 | |
| 		//public override string ToString()
 | |
| 		//{
 | |
| 		//  return base.ToString();
 | |
| 		//}
 | |
| 		// CSLATODO: Check RevisionROCheckInfo.GetIdValue to assure that the ID returned is unique
 | |
| 		/// <summary>
 | |
| 		/// Overrides Base GetIdValue - Used internally by CSLA to determine equality
 | |
| 		/// </summary>
 | |
| 		/// <returns>A Unique ID for the current RevisionROCheckInfo</returns>
 | |
| 		protected override object GetIdValue()
 | |
| 		{
 | |
| 			return MyRevisionROCheckInfoUnique; // Absolutely Unique ID
 | |
| 		}
 | |
| 		#endregion
 | |
| 		#region Factory Methods
 | |
| 		private static int _RevisionROCheckInfoUnique = 0;
 | |
| 		private static int RevisionROCheckInfoUnique
 | |
| 		{ get { return ++_RevisionROCheckInfoUnique; } }
 | |
| 		private int _MyRevisionROCheckInfoUnique = RevisionROCheckInfoUnique;
 | |
| 		public int MyRevisionROCheckInfoUnique // Absolutely Unique ID - Info
 | |
| 		{ get { return _MyRevisionROCheckInfoUnique; } }
 | |
| 		protected RevisionROCheckInfo()
 | |
| 		{/* require use of factory methods */
 | |
| 			AddToCache(this);
 | |
| 		}
 | |
| 		public void Dispose()
 | |
| 		{
 | |
| 			RemoveFromCache(this);
 | |
| 			if (!_CacheByPrimaryKey.ContainsKey(CheckID.ToString())) return;
 | |
| 			List<RevisionROCheckInfo> listRevisionROCheckInfo = _CacheByPrimaryKey[CheckID.ToString()]; // Get the list of items
 | |
| 			while (listRevisionROCheckInfo.Contains(this)) listRevisionROCheckInfo.Remove(this); // Remove the item from the list
 | |
| 			if (listRevisionROCheckInfo.Count == 0) // If there are no items left in the list
 | |
| 				_CacheByPrimaryKey.Remove(CheckID.ToString()); // remove the list
 | |
| 		}
 | |
| 		public virtual RevisionROCheck Get()
 | |
| 		{
 | |
| 			return _Editable = RevisionROCheck.Get(_CheckID);
 | |
| 		}
 | |
| 		public static void Refresh(RevisionROCheck tmp)
 | |
| 		{
 | |
| 			string key = tmp.CheckID.ToString();
 | |
| 			ConvertListToDictionary();
 | |
| 			if (_CacheByPrimaryKey.ContainsKey(key))
 | |
| 				foreach (RevisionROCheckInfo tmpInfo in _CacheByPrimaryKey[key])
 | |
| 					tmpInfo.RefreshFields(tmp);
 | |
| 		}
 | |
| 		protected virtual void RefreshFields(RevisionROCheck tmp)
 | |
| 		{
 | |
| 			_ItemID = tmp.ItemID;
 | |
| 			_ROID = tmp.ROID;
 | |
| 			_RODate = tmp.RODate;
 | |
| 			_ROValue = tmp.ROValue;
 | |
| 			_RevisionROCheckInfoExtension.Refresh(this);
 | |
| 			OnChange();// raise an event
 | |
| 		}
 | |
| 		public static RevisionROCheckInfo Get(int checkID)
 | |
| 		{
 | |
| 			//if (!CanGetObject())
 | |
| 			//  throw new System.Security.SecurityException("User not authorized to view a RevisionROCheck");
 | |
| 			try
 | |
| 			{
 | |
| 				RevisionROCheckInfo tmp = GetCachedByPrimaryKey(checkID);
 | |
| 				if (tmp == null)
 | |
| 				{
 | |
| 					tmp = DataPortal.Fetch<RevisionROCheckInfo>(new PKCriteria(checkID));
 | |
| 					AddToCache(tmp);
 | |
| 				}
 | |
| 				if (tmp.ErrorMessage == "No Record Found")
 | |
| 				{
 | |
| 					tmp.Dispose(); // Clean-up RevisionROCheckInfo
 | |
| 					tmp = null;
 | |
| 				}
 | |
| 				return tmp;
 | |
| 			}
 | |
| 			catch (Exception ex)
 | |
| 			{
 | |
| 				throw new DbCslaException("Error on RevisionROCheckInfo.Get", ex);
 | |
| 			}
 | |
| 		}
 | |
| 		#endregion
 | |
| 		#region Data Access Portal
 | |
| 		internal RevisionROCheckInfo(SafeDataReader dr)
 | |
| 		{
 | |
| 			if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RevisionROCheckInfo.Constructor", GetHashCode());
 | |
| 			try
 | |
| 			{
 | |
| 				ReadData(dr);
 | |
| 			}
 | |
| 			catch (Exception ex)
 | |
| 			{
 | |
| 				if (_MyLog.IsErrorEnabled) _MyLog.Error("RevisionROCheckInfo.Constructor", ex);
 | |
| 				throw new DbCslaException("RevisionROCheckInfo.Constructor", ex);
 | |
| 			}
 | |
| 		}
 | |
| 		[Serializable()]
 | |
| 		protected class PKCriteria
 | |
| 		{
 | |
| 			private int _CheckID;
 | |
| 			public int CheckID
 | |
| 			{ get { return _CheckID; } }
 | |
| 			public PKCriteria(int checkID)
 | |
| 			{
 | |
| 				_CheckID = checkID;
 | |
| 			}
 | |
| 		}
 | |
| 		private void ReadData(SafeDataReader dr)
 | |
| 		{
 | |
| 			if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RevisionROCheckInfo.ReadData", GetHashCode());
 | |
| 			try
 | |
| 			{
 | |
| 				_CheckID = dr.GetInt32("CheckID");
 | |
| 				_ItemID = dr.GetInt32("ItemID");
 | |
| 				_ROID = dr.GetInt32("ROID");
 | |
| 				_RODate = dr.GetSmartDate("RODate").Text;
 | |
| 				_ROValue = dr.GetString("ROValue");
 | |
| 			}
 | |
| 			catch (Exception ex)
 | |
| 			{
 | |
| 				if (_MyLog.IsErrorEnabled) _MyLog.Error("RevisionROCheckInfo.ReadData", ex);
 | |
| 				_ErrorMessage = ex.Message;
 | |
| 				throw new DbCslaException("RevisionROCheckInfo.ReadData", ex);
 | |
| 			}
 | |
| 		}
 | |
| 		private void DataPortal_Fetch(PKCriteria criteria)
 | |
| 		{
 | |
| 			if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RevisionROCheckInfo.DataPortal_Fetch", GetHashCode());
 | |
| 			try
 | |
| 			{
 | |
| 				using (SqlConnection cn = Database.VEPROMS_SqlConnection)
 | |
| 				{
 | |
| 					ApplicationContext.LocalContext["cn"] = cn;
 | |
| 					using (SqlCommand cm = cn.CreateCommand())
 | |
| 					{
 | |
| 						cm.CommandType = CommandType.StoredProcedure;
 | |
| 						cm.CommandText = "getRevisionROCheck";
 | |
| 						cm.Parameters.AddWithValue("@CheckID", criteria.CheckID);
 | |
| 						using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader()))
 | |
| 						{
 | |
| 							if (!dr.Read())
 | |
| 							{
 | |
| 								_ErrorMessage = "No Record Found";
 | |
| 								return;
 | |
| 							}
 | |
| 							ReadData(dr);
 | |
| 						}
 | |
| 					}
 | |
| 					// removing of item only needed for local data portal
 | |
| 					if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client)
 | |
| 						ApplicationContext.LocalContext.Remove("cn");
 | |
| 				}
 | |
| 			}
 | |
| 			catch (Exception ex)
 | |
| 			{
 | |
| 				if (_MyLog.IsErrorEnabled) _MyLog.Error("RevisionROCheckInfo.DataPortal_Fetch", ex);
 | |
| 				_ErrorMessage = ex.Message;
 | |
| 				throw new DbCslaException("RevisionROCheckInfo.DataPortal_Fetch", ex);
 | |
| 			}
 | |
| 		}
 | |
| 		#endregion
 | |
| 		// Standard Refresh
 | |
| 		#region extension
 | |
| 		RevisionROCheckInfoExtension _RevisionROCheckInfoExtension = new RevisionROCheckInfoExtension();
 | |
| 		[Serializable()]
 | |
| 		partial class RevisionROCheckInfoExtension : extensionBase { }
 | |
| 		[Serializable()]
 | |
| 		class extensionBase
 | |
| 		{
 | |
| 			// Default Refresh
 | |
| 			public virtual void Refresh(RevisionROCheckInfo tmp) { }
 | |
| 		}
 | |
| 		#endregion
 | |
| 	} // Class
 | |
| 	#region Converter
 | |
| 	internal class RevisionROCheckInfoConverter : ExpandableObjectConverter
 | |
| 	{
 | |
| 		public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
 | |
| 		{
 | |
| 			if (destType == typeof(string) && value is RevisionROCheckInfo)
 | |
| 			{
 | |
| 				// Return the ToString value
 | |
| 				return ((RevisionROCheckInfo)value).ToString();
 | |
| 			}
 | |
| 			return base.ConvertTo(context, culture, value, destType);
 | |
| 		}
 | |
| 	}
 | |
| 	#endregion
 | |
| } // Namespace
 |