1291 lines
		
	
	
		
			43 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			1291 lines
		
	
	
		
			43 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;
 | 
						|
using Csla.Validation;
 | 
						|
namespace VEPROMS.CSLA.Library
 | 
						|
{
 | 
						|
	/// <summary>
 | 
						|
	///	Revision Generated by MyGeneration using the CSLA Object Mapping template
 | 
						|
	/// </summary>
 | 
						|
	[Serializable()]
 | 
						|
	[TypeConverter(typeof(RevisionConverter))]
 | 
						|
	public partial class Revision : BusinessBase<Revision>, IDisposable, IVEHasBrokenRules
 | 
						|
	{
 | 
						|
		#region Log4Net
 | 
						|
		private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
 | 
						|
		#endregion
 | 
						|
		#region Refresh
 | 
						|
		private List<Revision> _RefreshRevisions = new List<Revision>();
 | 
						|
		private List<RevisionCheck> _RefreshRevisionChecks = new List<RevisionCheck>();
 | 
						|
		private List<RevisionVersion> _RefreshRevisionVersions = new List<RevisionVersion>();
 | 
						|
		private void AddToRefreshList(List<Revision> refreshRevisions, List<RevisionCheck> refreshRevisionChecks, List<RevisionVersion> refreshRevisionVersions)
 | 
						|
		{
 | 
						|
			if (IsDirty)
 | 
						|
				refreshRevisions.Add(this);
 | 
						|
			if (_RevisionChecks != null && _RevisionChecks.IsDirty)
 | 
						|
			{
 | 
						|
				foreach (RevisionCheck tmp in _RevisionChecks)
 | 
						|
				{
 | 
						|
					if (tmp.IsDirty) refreshRevisionChecks.Add(tmp);
 | 
						|
				}
 | 
						|
			}
 | 
						|
			if (_RevisionVersions != null && _RevisionVersions.IsDirty)
 | 
						|
			{
 | 
						|
				foreach (RevisionVersion tmp in _RevisionVersions)
 | 
						|
				{
 | 
						|
					if (tmp.IsDirty) refreshRevisionVersions.Add(tmp);
 | 
						|
				}
 | 
						|
			}
 | 
						|
		}
 | 
						|
		private void ClearRefreshList()
 | 
						|
		{
 | 
						|
			_RefreshRevisions = new List<Revision>();
 | 
						|
			_RefreshRevisionChecks = new List<RevisionCheck>();
 | 
						|
			_RefreshRevisionVersions = new List<RevisionVersion>();
 | 
						|
		}
 | 
						|
		private void BuildRefreshList()
 | 
						|
		{
 | 
						|
			ClearRefreshList();
 | 
						|
			AddToRefreshList(_RefreshRevisions, _RefreshRevisionChecks, _RefreshRevisionVersions);
 | 
						|
		}
 | 
						|
		private void ProcessRefreshList()
 | 
						|
		{
 | 
						|
			foreach (Revision tmp in _RefreshRevisions)
 | 
						|
			{
 | 
						|
				RevisionInfo.Refresh(tmp);
 | 
						|
			}
 | 
						|
			foreach (RevisionCheck tmp in _RefreshRevisionChecks)
 | 
						|
			{
 | 
						|
				CheckInfo.Refresh(tmp);
 | 
						|
			}
 | 
						|
			foreach (RevisionVersion tmp in _RefreshRevisionVersions)
 | 
						|
			{
 | 
						|
				VersionInfo.Refresh(tmp);
 | 
						|
			}
 | 
						|
			ClearRefreshList();
 | 
						|
		}
 | 
						|
		#endregion
 | 
						|
		#region Collection
 | 
						|
		private static List<Revision> _CacheList = new List<Revision>();
 | 
						|
		protected static void AddToCache(Revision revision)
 | 
						|
		{
 | 
						|
			if (!_CacheList.Contains(revision)) _CacheList.Add(revision); // In AddToCache
 | 
						|
		}
 | 
						|
		protected static void RemoveFromCache(Revision revision)
 | 
						|
		{
 | 
						|
			while (_CacheList.Contains(revision)) _CacheList.Remove(revision); // In RemoveFromCache
 | 
						|
		}
 | 
						|
		private static Dictionary<string, List<Revision>> _CacheByPrimaryKey = new Dictionary<string, List<Revision>>();
 | 
						|
		private static void ConvertListToDictionary()
 | 
						|
		{
 | 
						|
			while (_CacheList.Count > 0) // Move Revision(s) from temporary _CacheList to _CacheByPrimaryKey
 | 
						|
			{
 | 
						|
				Revision tmp = _CacheList[0]; // Get the first Revision
 | 
						|
				string pKey = tmp.RevisionID.ToString();
 | 
						|
				if (!_CacheByPrimaryKey.ContainsKey(pKey))
 | 
						|
				{
 | 
						|
					_CacheByPrimaryKey[pKey] = new List<Revision>(); // Add new list for PrimaryKey
 | 
						|
				}
 | 
						|
				_CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list
 | 
						|
				_CacheList.RemoveAt(0); // Remove the first Revision
 | 
						|
			}
 | 
						|
		}
 | 
						|
		protected static Revision GetCachedByPrimaryKey(int revisionID)
 | 
						|
		{
 | 
						|
			ConvertListToDictionary();
 | 
						|
			string key = revisionID.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 _nextRevisionID = -1;
 | 
						|
		public static int NextRevisionID
 | 
						|
		{
 | 
						|
			get { return _nextRevisionID--; }
 | 
						|
		}
 | 
						|
		private int _RevisionID;
 | 
						|
		[System.ComponentModel.DataObjectField(true, true)]
 | 
						|
		public int RevisionID
 | 
						|
		{
 | 
						|
			[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
 | 
						|
			get
 | 
						|
			{
 | 
						|
				CanReadProperty("RevisionID", true);
 | 
						|
				return _RevisionID;
 | 
						|
			}
 | 
						|
		}
 | 
						|
		private int _ItemID;
 | 
						|
		public int ItemID
 | 
						|
		{
 | 
						|
			[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
 | 
						|
			get
 | 
						|
			{
 | 
						|
				CanReadProperty("ItemID", true);
 | 
						|
				return _ItemID;
 | 
						|
			}
 | 
						|
			[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
 | 
						|
			set
 | 
						|
			{
 | 
						|
				CanWriteProperty("ItemID", true);
 | 
						|
				if (_ItemID != value)
 | 
						|
				{
 | 
						|
					_ItemID = value;
 | 
						|
					PropertyHasChanged();
 | 
						|
				}
 | 
						|
			}
 | 
						|
		}
 | 
						|
		private int _TypeID;
 | 
						|
		public int TypeID
 | 
						|
		{
 | 
						|
			[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
 | 
						|
			get
 | 
						|
			{
 | 
						|
				CanReadProperty("TypeID", true);
 | 
						|
				return _TypeID;
 | 
						|
			}
 | 
						|
			[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
 | 
						|
			set
 | 
						|
			{
 | 
						|
				CanWriteProperty("TypeID", true);
 | 
						|
				if (_TypeID != value)
 | 
						|
				{
 | 
						|
					_TypeID = value;
 | 
						|
					PropertyHasChanged();
 | 
						|
				}
 | 
						|
			}
 | 
						|
		}
 | 
						|
		private string _RevisionNumber = string.Empty;
 | 
						|
		public string RevisionNumber
 | 
						|
		{
 | 
						|
			[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
 | 
						|
			get
 | 
						|
			{
 | 
						|
				CanReadProperty("RevisionNumber", true);
 | 
						|
				return _RevisionNumber;
 | 
						|
			}
 | 
						|
			[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
 | 
						|
			set
 | 
						|
			{
 | 
						|
				CanWriteProperty("RevisionNumber", true);
 | 
						|
				if (value == null) value = string.Empty;
 | 
						|
				if (_RevisionNumber != value)
 | 
						|
				{
 | 
						|
					_RevisionNumber = value;
 | 
						|
					PropertyHasChanged();
 | 
						|
				}
 | 
						|
			}
 | 
						|
		}
 | 
						|
		private DateTime? _RevisionDate;
 | 
						|
		public DateTime? RevisionDate
 | 
						|
		{
 | 
						|
			[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
 | 
						|
			get
 | 
						|
			{
 | 
						|
				CanReadProperty("RevisionDate", true);
 | 
						|
				return _RevisionDate;
 | 
						|
			}
 | 
						|
			[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
 | 
						|
			set
 | 
						|
			{
 | 
						|
				CanWriteProperty("RevisionDate", true);
 | 
						|
				if (_RevisionDate != value)
 | 
						|
				{
 | 
						|
					_RevisionDate = value;
 | 
						|
					PropertyHasChanged();
 | 
						|
				}
 | 
						|
			}
 | 
						|
		}
 | 
						|
		private string _Notes = string.Empty;
 | 
						|
		public string Notes
 | 
						|
		{
 | 
						|
			[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
 | 
						|
			get
 | 
						|
			{
 | 
						|
				CanReadProperty("Notes", true);
 | 
						|
				return _Notes;
 | 
						|
			}
 | 
						|
			[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
 | 
						|
			set
 | 
						|
			{
 | 
						|
				CanWriteProperty("Notes", true);
 | 
						|
				if (value == null) value = string.Empty;
 | 
						|
				if (_Notes != value)
 | 
						|
				{
 | 
						|
					_Notes = value;
 | 
						|
					PropertyHasChanged();
 | 
						|
				}
 | 
						|
			}
 | 
						|
		}
 | 
						|
		private string _Config = string.Empty;
 | 
						|
		public string Config
 | 
						|
		{
 | 
						|
			[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
 | 
						|
			get
 | 
						|
			{
 | 
						|
				CanReadProperty("Config", true);
 | 
						|
				return _Config;
 | 
						|
			}
 | 
						|
			[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
 | 
						|
			set
 | 
						|
			{
 | 
						|
				CanWriteProperty("Config", true);
 | 
						|
				if (value == null) value = string.Empty;
 | 
						|
				if (_Config != value)
 | 
						|
				{
 | 
						|
					_Config = value;
 | 
						|
					PropertyHasChanged();
 | 
						|
				}
 | 
						|
			}
 | 
						|
		}
 | 
						|
		private DateTime _DTS = new DateTime();
 | 
						|
		public DateTime DTS
 | 
						|
		{
 | 
						|
			[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
 | 
						|
			get
 | 
						|
			{
 | 
						|
				CanReadProperty("DTS", true);
 | 
						|
				return _DTS;
 | 
						|
			}
 | 
						|
			[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
 | 
						|
			set
 | 
						|
			{
 | 
						|
				CanWriteProperty("DTS", true);
 | 
						|
				if (_DTS != value)
 | 
						|
				{
 | 
						|
					_DTS = value;
 | 
						|
					PropertyHasChanged();
 | 
						|
				}
 | 
						|
			}
 | 
						|
		}
 | 
						|
		private string _UserID = string.Empty;
 | 
						|
		public string UserID
 | 
						|
		{
 | 
						|
			[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
 | 
						|
			get
 | 
						|
			{
 | 
						|
				CanReadProperty("UserID", true);
 | 
						|
				return _UserID;
 | 
						|
			}
 | 
						|
			[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
 | 
						|
			set
 | 
						|
			{
 | 
						|
				CanWriteProperty("UserID", true);
 | 
						|
				if (value == null) value = string.Empty;
 | 
						|
				if (_UserID != value)
 | 
						|
				{
 | 
						|
					_UserID = value;
 | 
						|
					PropertyHasChanged();
 | 
						|
				}
 | 
						|
			}
 | 
						|
		}
 | 
						|
		private byte[] _LastChanged = new byte[8];//timestamp
 | 
						|
		private int _RevisionCheckCount = 0;
 | 
						|
		/// <summary>
 | 
						|
		/// Count of RevisionChecks for this Revision
 | 
						|
		/// </summary>
 | 
						|
		public int RevisionCheckCount
 | 
						|
		{
 | 
						|
			[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
 | 
						|
			get
 | 
						|
			{
 | 
						|
				CanReadProperty("RevisionCheckCount", true);
 | 
						|
				return _RevisionCheckCount;
 | 
						|
			}
 | 
						|
		}
 | 
						|
		private RevisionChecks _RevisionChecks = null;
 | 
						|
		/// <summary>
 | 
						|
		/// Related Field
 | 
						|
		/// </summary>
 | 
						|
		[TypeConverter(typeof(RevisionChecksConverter))]
 | 
						|
		public RevisionChecks RevisionChecks
 | 
						|
		{
 | 
						|
			[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
 | 
						|
			get
 | 
						|
			{
 | 
						|
				CanReadProperty("RevisionChecks", true);
 | 
						|
				if (_RevisionCheckCount < 0 || (_RevisionCheckCount > 0 && _RevisionChecks == null))
 | 
						|
					_RevisionChecks = RevisionChecks.GetByRevisionID(RevisionID);
 | 
						|
				if (_RevisionCheckCount < 0 )
 | 
						|
					_RevisionCheckCount = _RevisionChecks == null ? 0 : _RevisionChecks.Count;
 | 
						|
				if (_RevisionChecks == null)
 | 
						|
					_RevisionChecks = RevisionChecks.New();
 | 
						|
				return _RevisionChecks;
 | 
						|
			}
 | 
						|
		}
 | 
						|
		public void Reset_RevisionChecks()
 | 
						|
		{
 | 
						|
			_RevisionCheckCount = -1;
 | 
						|
		}
 | 
						|
		private int _RevisionVersionCount = 0;
 | 
						|
		/// <summary>
 | 
						|
		/// Count of RevisionVersions for this Revision
 | 
						|
		/// </summary>
 | 
						|
		public int RevisionVersionCount
 | 
						|
		{
 | 
						|
			[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
 | 
						|
			get
 | 
						|
			{
 | 
						|
				CanReadProperty("RevisionVersionCount", true);
 | 
						|
				return _RevisionVersionCount;
 | 
						|
			}
 | 
						|
		}
 | 
						|
		private RevisionVersions _RevisionVersions = null;
 | 
						|
		/// <summary>
 | 
						|
		/// Related Field
 | 
						|
		/// </summary>
 | 
						|
		[TypeConverter(typeof(RevisionVersionsConverter))]
 | 
						|
		public RevisionVersions RevisionVersions
 | 
						|
		{
 | 
						|
			[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
 | 
						|
			get
 | 
						|
			{
 | 
						|
				CanReadProperty("RevisionVersions", true);
 | 
						|
				if (_RevisionVersionCount < 0 || (_RevisionVersionCount > 0 && _RevisionVersions == null))
 | 
						|
					_RevisionVersions = RevisionVersions.GetByRevisionID(RevisionID);
 | 
						|
				if (_RevisionVersionCount < 0 )
 | 
						|
					_RevisionVersionCount = _RevisionVersions == null ? 0 : _RevisionVersions.Count;
 | 
						|
				if (_RevisionVersions == null)
 | 
						|
					_RevisionVersions = RevisionVersions.New();
 | 
						|
				return _RevisionVersions;
 | 
						|
			}
 | 
						|
		}
 | 
						|
		public void Reset_RevisionVersions()
 | 
						|
		{
 | 
						|
			_RevisionVersionCount = -1;
 | 
						|
		}
 | 
						|
		public override bool IsDirty
 | 
						|
		{
 | 
						|
			get 
 | 
						|
			{
 | 
						|
				if ( base.IsDirty ) 
 | 
						|
					return true;
 | 
						|
				return IsDirtyList(new List<object>());
 | 
						|
			}
 | 
						|
		}
 | 
						|
		public bool IsDirtyList(List<object> list)
 | 
						|
		{
 | 
						|
			if (base.IsDirty || list.Contains(this))
 | 
						|
				return base.IsDirty;
 | 
						|
			list.Add(this);
 | 
						|
			return base.IsDirty || (_RevisionChecks == null ? false : _RevisionChecks.IsDirtyList(list)) || (_RevisionVersions == null ? false : _RevisionVersions.IsDirtyList(list));
 | 
						|
		}
 | 
						|
		public override bool IsValid
 | 
						|
		{
 | 
						|
			get { return IsValidList(new List<object>()); }
 | 
						|
		}
 | 
						|
		public bool IsValidList(List<object> list)
 | 
						|
		{
 | 
						|
			if(list.Contains(this))
 | 
						|
				return (IsNew && !IsDirty) ? true : base.IsValid;
 | 
						|
			list.Add(this);
 | 
						|
			return ((IsNew && !IsDirty) ? true : base.IsValid) && (_RevisionChecks == null ? true : _RevisionChecks.IsValidList(list)) && (_RevisionVersions == null ? true : _RevisionVersions.IsValidList(list));
 | 
						|
		}
 | 
						|
		// CSLATODO: Replace base Revision.ToString function as necessary
 | 
						|
		/// <summary>
 | 
						|
		/// Overrides Base ToString
 | 
						|
		/// </summary>
 | 
						|
		/// <returns>A string representation of current Revision</returns>
 | 
						|
		//public override string ToString()
 | 
						|
		//{
 | 
						|
		//  return base.ToString();
 | 
						|
		//}
 | 
						|
		// CSLATODO: Check Revision.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 Revision</returns>
 | 
						|
		protected override object GetIdValue()
 | 
						|
		{
 | 
						|
			return MyRevisionUnique; // Absolutely Unique ID
 | 
						|
		}
 | 
						|
		#endregion
 | 
						|
		#region ValidationRules
 | 
						|
		[NonSerialized]
 | 
						|
		private bool _CheckingBrokenRules = false;
 | 
						|
		public IVEHasBrokenRules HasBrokenRules
 | 
						|
		{
 | 
						|
			get
 | 
						|
			{
 | 
						|
				if (_CheckingBrokenRules) return null;
 | 
						|
				if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this;
 | 
						|
				try
 | 
						|
				{
 | 
						|
					_CheckingBrokenRules = true;
 | 
						|
					IVEHasBrokenRules hasBrokenRules = null;
 | 
						|
					if (_RevisionChecks != null && (hasBrokenRules = _RevisionChecks.HasBrokenRules) != null) return hasBrokenRules;
 | 
						|
					if (_RevisionVersions != null && (hasBrokenRules = _RevisionVersions.HasBrokenRules) != null) return hasBrokenRules;
 | 
						|
					return hasBrokenRules;
 | 
						|
				}
 | 
						|
				finally
 | 
						|
				{
 | 
						|
					_CheckingBrokenRules = false;
 | 
						|
				}
 | 
						|
			}
 | 
						|
		}
 | 
						|
		public BrokenRulesCollection BrokenRules
 | 
						|
		{
 | 
						|
			get
 | 
						|
			{
 | 
						|
				IVEHasBrokenRules hasBrokenRules = HasBrokenRules;
 | 
						|
				if (this.Equals(hasBrokenRules)) return BrokenRulesCollection;
 | 
						|
				return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null);
 | 
						|
			}
 | 
						|
		}
 | 
						|
		protected override void AddBusinessRules()
 | 
						|
		{
 | 
						|
			ValidationRules.AddRule(
 | 
						|
				Csla.Validation.CommonRules.StringMaxLength,
 | 
						|
				new Csla.Validation.CommonRules.MaxLengthRuleArgs("RevisionNumber", 50));
 | 
						|
			ValidationRules.AddRule(
 | 
						|
				Csla.Validation.CommonRules.StringMaxLength,
 | 
						|
				new Csla.Validation.CommonRules.MaxLengthRuleArgs("Notes", 1073741823));
 | 
						|
			ValidationRules.AddRule(
 | 
						|
				Csla.Validation.CommonRules.StringMaxLength,
 | 
						|
				new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823));
 | 
						|
			ValidationRules.AddRule(
 | 
						|
				Csla.Validation.CommonRules.StringRequired, "UserID");
 | 
						|
			ValidationRules.AddRule(
 | 
						|
				Csla.Validation.CommonRules.StringMaxLength,
 | 
						|
				new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100));
 | 
						|
			//ValidationRules.AddDependantProperty("x", "y");
 | 
						|
			_RevisionExtension.AddValidationRules(ValidationRules);
 | 
						|
			// CSLATODO:  Add other validation rules
 | 
						|
		}
 | 
						|
		protected override void AddInstanceBusinessRules()
 | 
						|
		{
 | 
						|
			_RevisionExtension.AddInstanceValidationRules(ValidationRules);
 | 
						|
			// CSLATODO:  Add other validation rules
 | 
						|
		}
 | 
						|
		// Sample data comparison validation rule
 | 
						|
		//private bool StartDateGTEndDate(object target, Csla.Validation.RuleArgs e)
 | 
						|
		//{
 | 
						|
		//	if (_started > _ended)
 | 
						|
		//	{
 | 
						|
		//		e.Description = "Start date can't be after end date";
 | 
						|
		//		return false;
 | 
						|
		//	}
 | 
						|
		//	else
 | 
						|
		//		return true;
 | 
						|
		//}
 | 
						|
		#endregion
 | 
						|
		#region Authorization Rules
 | 
						|
		protected override void AddAuthorizationRules()
 | 
						|
		{
 | 
						|
			//CSLATODO: Who can read/write which fields
 | 
						|
			//AuthorizationRules.AllowRead(RevisionID, "<Role(s)>");
 | 
						|
			//AuthorizationRules.AllowRead(ItemID, "<Role(s)>");
 | 
						|
			//AuthorizationRules.AllowRead(TypeID, "<Role(s)>");
 | 
						|
			//AuthorizationRules.AllowRead(RevisionNumber, "<Role(s)>");
 | 
						|
			//AuthorizationRules.AllowRead(RevisionDate, "<Role(s)>");
 | 
						|
			//AuthorizationRules.AllowRead(Notes, "<Role(s)>");
 | 
						|
			//AuthorizationRules.AllowRead(Config, "<Role(s)>");
 | 
						|
			//AuthorizationRules.AllowRead(DTS, "<Role(s)>");
 | 
						|
			//AuthorizationRules.AllowRead(UserID, "<Role(s)>");
 | 
						|
			//AuthorizationRules.AllowWrite(ItemID, "<Role(s)>");
 | 
						|
			//AuthorizationRules.AllowWrite(TypeID, "<Role(s)>");
 | 
						|
			//AuthorizationRules.AllowWrite(RevisionNumber, "<Role(s)>");
 | 
						|
			//AuthorizationRules.AllowWrite(RevisionDate, "<Role(s)>");
 | 
						|
			//AuthorizationRules.AllowWrite(Notes, "<Role(s)>");
 | 
						|
			//AuthorizationRules.AllowWrite(Config, "<Role(s)>");
 | 
						|
			//AuthorizationRules.AllowWrite(DTS, "<Role(s)>");
 | 
						|
			//AuthorizationRules.AllowWrite(UserID, "<Role(s)>");
 | 
						|
			_RevisionExtension.AddAuthorizationRules(AuthorizationRules);
 | 
						|
		}
 | 
						|
		protected override void AddInstanceAuthorizationRules()
 | 
						|
		{
 | 
						|
			//CSLATODO: Who can read/write which fields
 | 
						|
			_RevisionExtension.AddInstanceAuthorizationRules(AuthorizationRules);
 | 
						|
		}
 | 
						|
		public static bool CanAddObject()
 | 
						|
		{
 | 
						|
			// CSLATODO: Can Add Authorization
 | 
						|
			//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
 | 
						|
			return true;
 | 
						|
		}
 | 
						|
		public static bool CanGetObject()
 | 
						|
		{
 | 
						|
			// CSLATODO: CanGet Authorization
 | 
						|
			return true;
 | 
						|
		}
 | 
						|
		public static bool CanDeleteObject()
 | 
						|
		{
 | 
						|
			// CSLATODO: CanDelete Authorization
 | 
						|
			//bool result = false;
 | 
						|
			//if (Csla.ApplicationContext.User.IsInRole("ProjectManager"))result = true;
 | 
						|
			//if (Csla.ApplicationContext.User.IsInRole("Administrator"))result = true;
 | 
						|
			//return result;
 | 
						|
			return true;
 | 
						|
		}
 | 
						|
		/// <summary>
 | 
						|
		/// determines if related records (Foreign Keys) will keep this Item from being deleted
 | 
						|
		/// </summary>
 | 
						|
		public bool CanDelete
 | 
						|
		{
 | 
						|
			get
 | 
						|
			{
 | 
						|
				// Check to make sure that there are not any related records
 | 
						|
				int usedByCount = 0;
 | 
						|
				usedByCount += _RevisionCheckCount;
 | 
						|
				usedByCount += _RevisionVersionCount;
 | 
						|
				return (usedByCount == 0);
 | 
						|
			}
 | 
						|
		}
 | 
						|
		public static bool CanEditObject()
 | 
						|
		{
 | 
						|
			// CSLATODO: CanEdit Authorization
 | 
						|
			//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
 | 
						|
			return true;
 | 
						|
		}
 | 
						|
		#endregion
 | 
						|
		#region Factory Methods
 | 
						|
		public int CurrentEditLevel
 | 
						|
		{ get { return EditLevel; } }
 | 
						|
		private static int _RevisionUnique = 0;
 | 
						|
		protected static int RevisionUnique
 | 
						|
		{ get { return ++_RevisionUnique; } }
 | 
						|
		private int _MyRevisionUnique = RevisionUnique;
 | 
						|
		public int MyRevisionUnique // Absolutely Unique ID - Editable
 | 
						|
		{ get { return _MyRevisionUnique; } }
 | 
						|
		protected Revision()
 | 
						|
		{/* require use of factory methods */
 | 
						|
			AddToCache(this);
 | 
						|
		}
 | 
						|
		private bool _Disposed = false;
 | 
						|
		private static int _CountCreated = 0;
 | 
						|
		private static int _CountDisposed = 0;
 | 
						|
		private static int _CountFinalized = 0;
 | 
						|
		private static int IncrementCountCreated
 | 
						|
		{ get { return ++_CountCreated; } }
 | 
						|
		private int _CountWhenCreated = IncrementCountCreated;
 | 
						|
		public static int CountCreated
 | 
						|
		{ get { return _CountCreated; } }
 | 
						|
		public static int CountNotDisposed
 | 
						|
		{ get { return _CountCreated - _CountDisposed; } }
 | 
						|
		public static int CountNotFinalized
 | 
						|
		{ get { return _CountCreated - _CountFinalized; } }
 | 
						|
		~Revision()
 | 
						|
		{
 | 
						|
			_CountFinalized++;
 | 
						|
		}
 | 
						|
		public void Dispose()
 | 
						|
		{
 | 
						|
			if (_Disposed) return;
 | 
						|
			_CountDisposed++;
 | 
						|
			_Disposed = true;
 | 
						|
			RemoveFromDictionaries();
 | 
						|
		}
 | 
						|
		private void RemoveFromDictionaries()
 | 
						|
		{
 | 
						|
			RemoveFromCache(this);
 | 
						|
			if (_CacheByPrimaryKey.ContainsKey(RevisionID.ToString()))
 | 
						|
			{
 | 
						|
				List<Revision> listRevision = _CacheByPrimaryKey[RevisionID.ToString()]; // Get the list of items
 | 
						|
				while (listRevision.Contains(this)) listRevision.Remove(this); // Remove the item from the list
 | 
						|
				if (listRevision.Count == 0) //If there are no items left in the list
 | 
						|
					_CacheByPrimaryKey.Remove(RevisionID.ToString()); // remove the list
 | 
						|
			}
 | 
						|
		}
 | 
						|
		public static Revision New()
 | 
						|
		{
 | 
						|
			if (!CanAddObject())
 | 
						|
				throw new System.Security.SecurityException("User not authorized to add a Revision");
 | 
						|
			try
 | 
						|
			{
 | 
						|
				return DataPortal.Create<Revision>();
 | 
						|
			}
 | 
						|
			catch (Exception ex)
 | 
						|
			{
 | 
						|
				throw new DbCslaException("Error on Revision.New", ex);
 | 
						|
			}
 | 
						|
		}
 | 
						|
		public static Revision New(int itemID)
 | 
						|
		{
 | 
						|
			Revision tmp = Revision.New();
 | 
						|
			tmp.ItemID = itemID;
 | 
						|
			return tmp;
 | 
						|
		}
 | 
						|
		public static Revision New(int itemID, int typeID, string revisionNumber, DateTime? revisionDate, string notes, string config, DateTime dts, string userID)
 | 
						|
		{
 | 
						|
			Revision tmp = Revision.New();
 | 
						|
			tmp.ItemID = itemID;
 | 
						|
			tmp.TypeID = typeID;
 | 
						|
			tmp.RevisionNumber = revisionNumber;
 | 
						|
			tmp.RevisionDate = revisionDate;
 | 
						|
			tmp.Notes = notes;
 | 
						|
			tmp.Config = config;
 | 
						|
			tmp.DTS = dts;
 | 
						|
			tmp.UserID = userID;
 | 
						|
			return tmp;
 | 
						|
		}
 | 
						|
		public static Revision MakeRevision(int itemID, int typeID, string revisionNumber, DateTime? revisionDate, string notes, string config, DateTime dts, string userID)
 | 
						|
		{
 | 
						|
			Revision tmp = Revision.New(itemID, typeID, revisionNumber, revisionDate, notes, config, dts, userID);
 | 
						|
			if (tmp.IsSavable)
 | 
						|
				tmp = tmp.Save();
 | 
						|
			else
 | 
						|
			{
 | 
						|
				Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules();
 | 
						|
				tmp._ErrorMessage = "Failed Validation:";
 | 
						|
				foreach (Csla.Validation.BrokenRule br in brc)
 | 
						|
				{
 | 
						|
					tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName;
 | 
						|
				}
 | 
						|
			}
 | 
						|
			return tmp;
 | 
						|
		}
 | 
						|
		public static Revision New(int itemID, string revisionNumber, DateTime? revisionDate, string notes, string config)
 | 
						|
		{
 | 
						|
			Revision tmp = Revision.New();
 | 
						|
			tmp.ItemID = itemID;
 | 
						|
			tmp.RevisionNumber = revisionNumber;
 | 
						|
			tmp.RevisionDate = revisionDate;
 | 
						|
			tmp.Notes = notes;
 | 
						|
			tmp.Config = config;
 | 
						|
			return tmp;
 | 
						|
		}
 | 
						|
		public static Revision MakeRevision(int itemID, string revisionNumber, DateTime? revisionDate, string notes, string config)
 | 
						|
		{
 | 
						|
			Revision tmp = Revision.New(itemID, revisionNumber, revisionDate, notes, config);
 | 
						|
			if (tmp.IsSavable)
 | 
						|
				tmp = tmp.Save();
 | 
						|
			else
 | 
						|
			{
 | 
						|
				Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules();
 | 
						|
				tmp._ErrorMessage = "Failed Validation:";
 | 
						|
				foreach (Csla.Validation.BrokenRule br in brc)
 | 
						|
				{
 | 
						|
					tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName;
 | 
						|
				}
 | 
						|
			}
 | 
						|
			return tmp;
 | 
						|
		}
 | 
						|
		public static Revision Get(int revisionID)
 | 
						|
		{
 | 
						|
			if (!CanGetObject())
 | 
						|
				throw new System.Security.SecurityException("User not authorized to view a Revision");
 | 
						|
			try
 | 
						|
			{
 | 
						|
				Revision tmp = GetCachedByPrimaryKey(revisionID);
 | 
						|
				if (tmp == null)
 | 
						|
				{
 | 
						|
					tmp = DataPortal.Fetch<Revision>(new PKCriteria(revisionID));
 | 
						|
					AddToCache(tmp);
 | 
						|
				}
 | 
						|
				if (tmp.ErrorMessage == "No Record Found") 
 | 
						|
				{
 | 
						|
					tmp.Dispose(); // Clean-up Revision
 | 
						|
					tmp = null;
 | 
						|
				}
 | 
						|
				return tmp;
 | 
						|
			}
 | 
						|
			catch (Exception ex)
 | 
						|
			{
 | 
						|
				throw new DbCslaException("Error on Revision.Get", ex);
 | 
						|
			}
 | 
						|
		}
 | 
						|
		public static Revision Get(SafeDataReader dr)
 | 
						|
		{
 | 
						|
			if (dr.Read()) return new Revision(dr);
 | 
						|
			return null;
 | 
						|
		}
 | 
						|
		internal Revision(SafeDataReader dr)
 | 
						|
		{
 | 
						|
			ReadData(dr);
 | 
						|
		}
 | 
						|
		public static void Delete(int revisionID)
 | 
						|
		{
 | 
						|
			if (!CanDeleteObject())
 | 
						|
				throw new System.Security.SecurityException("User not authorized to remove a Revision");
 | 
						|
			try
 | 
						|
			{
 | 
						|
				DataPortal.Delete(new PKCriteria(revisionID));
 | 
						|
			}
 | 
						|
			catch (Exception ex)
 | 
						|
			{
 | 
						|
				throw new DbCslaException("Error on Revision.Delete", ex);
 | 
						|
			}
 | 
						|
		}
 | 
						|
		public override Revision Save()
 | 
						|
		{
 | 
						|
			if (IsDeleted && !CanDeleteObject())
 | 
						|
				throw new System.Security.SecurityException("User not authorized to remove a Revision");
 | 
						|
			else if (IsNew && !CanAddObject())
 | 
						|
				throw new System.Security.SecurityException("User not authorized to add a Revision");
 | 
						|
			else if (!CanEditObject())
 | 
						|
				throw new System.Security.SecurityException("User not authorized to update a Revision");
 | 
						|
			try
 | 
						|
			{
 | 
						|
				BuildRefreshList();
 | 
						|
				Revision revision = base.Save();
 | 
						|
				RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache
 | 
						|
				AddToCache(revision);//Refresh the item in AllList
 | 
						|
				ProcessRefreshList();
 | 
						|
				return revision;
 | 
						|
			}
 | 
						|
			catch (Exception ex)
 | 
						|
			{
 | 
						|
				throw new DbCslaException("Error on CSLA Save", ex);
 | 
						|
			}
 | 
						|
		}
 | 
						|
		#endregion
 | 
						|
		#region Data Access Portal
 | 
						|
		[Serializable()]
 | 
						|
		protected class PKCriteria
 | 
						|
		{
 | 
						|
			private int _RevisionID;
 | 
						|
			public int RevisionID
 | 
						|
			{ get { return _RevisionID; } }
 | 
						|
			public PKCriteria(int revisionID)
 | 
						|
			{
 | 
						|
				_RevisionID = revisionID;
 | 
						|
			}
 | 
						|
		}
 | 
						|
		// CSLATODO: If Create needs to access DB - It should not be marked RunLocal
 | 
						|
		[RunLocal()]
 | 
						|
		private new void DataPortal_Create()
 | 
						|
		{
 | 
						|
			_RevisionID = NextRevisionID;
 | 
						|
			// Database Defaults
 | 
						|
			_TypeID = _RevisionExtension.DefaultTypeID;
 | 
						|
			_DTS = _RevisionExtension.DefaultDTS;
 | 
						|
			_UserID = _RevisionExtension.DefaultUserID;
 | 
						|
			// CSLATODO: Add any defaults that are necessary
 | 
						|
			ValidationRules.CheckRules();
 | 
						|
		}
 | 
						|
		private void ReadData(SafeDataReader dr)
 | 
						|
		{
 | 
						|
			if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Revision.ReadData", GetHashCode());
 | 
						|
			try
 | 
						|
			{
 | 
						|
				_RevisionID = dr.GetInt32("RevisionID");
 | 
						|
				_ItemID = dr.GetInt32("ItemID");
 | 
						|
				_TypeID = dr.GetInt32("TypeID");
 | 
						|
				_RevisionNumber = dr.GetString("RevisionNumber");
 | 
						|
				if (!dr.IsDBNull(dr.GetOrdinal("RevisionDate"))) _RevisionDate = dr.GetDateTime("RevisionDate");
 | 
						|
				_Notes = dr.GetString("Notes");
 | 
						|
				_Config = dr.GetString("Config");
 | 
						|
				_DTS = dr.GetDateTime("DTS");
 | 
						|
				_UserID = dr.GetString("UserID");
 | 
						|
				dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8);
 | 
						|
				_RevisionCheckCount = dr.GetInt32("CheckCount");
 | 
						|
				_RevisionVersionCount = dr.GetInt32("VersionCount");
 | 
						|
				MarkOld();
 | 
						|
			}
 | 
						|
			catch (Exception ex)
 | 
						|
			{
 | 
						|
				if (_MyLog.IsErrorEnabled) _MyLog.Error("Revision.ReadData", ex);
 | 
						|
				_ErrorMessage = ex.Message;
 | 
						|
				throw new DbCslaException("Revision.ReadData", ex);
 | 
						|
			}
 | 
						|
		}
 | 
						|
		private void DataPortal_Fetch(PKCriteria criteria)
 | 
						|
		{
 | 
						|
			if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Revision.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 = "getRevision";
 | 
						|
						cm.Parameters.AddWithValue("@RevisionID", criteria.RevisionID);
 | 
						|
						cm.CommandTimeout = Database.DefaultTimeout;
 | 
						|
						using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader()))
 | 
						|
						{
 | 
						|
							if (!dr.Read())
 | 
						|
							{
 | 
						|
								_ErrorMessage = "No Record Found";
 | 
						|
								return;
 | 
						|
							}
 | 
						|
							ReadData(dr);
 | 
						|
							// load child objects
 | 
						|
							dr.NextResult();
 | 
						|
							_RevisionChecks = RevisionChecks.Get(dr);
 | 
						|
							// load child objects
 | 
						|
							dr.NextResult();
 | 
						|
							_RevisionVersions = RevisionVersions.Get(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("Revision.DataPortal_Fetch", ex);
 | 
						|
				_ErrorMessage = ex.Message;
 | 
						|
				throw new DbCslaException("Revision.DataPortal_Fetch", ex);
 | 
						|
			}
 | 
						|
		}
 | 
						|
		[Transactional(TransactionalTypes.TransactionScope)]
 | 
						|
		protected override void DataPortal_Insert()
 | 
						|
		{
 | 
						|
			try
 | 
						|
			{
 | 
						|
				using (SqlConnection cn = Database.VEPROMS_SqlConnection)
 | 
						|
				{
 | 
						|
					ApplicationContext.LocalContext["cn"] = cn;
 | 
						|
					SQLInsert();
 | 
						|
					// 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("Revision.DataPortal_Insert", ex);
 | 
						|
				_ErrorMessage = ex.Message;
 | 
						|
				throw new DbCslaException("Revision.DataPortal_Insert", ex);
 | 
						|
			}
 | 
						|
			finally
 | 
						|
			{
 | 
						|
				if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Revision.DataPortal_Insert", GetHashCode());
 | 
						|
			}
 | 
						|
		}
 | 
						|
		[Transactional(TransactionalTypes.TransactionScope)]
 | 
						|
		internal void SQLInsert()
 | 
						|
		{
 | 
						|
			if (!this.IsDirty) return;
 | 
						|
			try
 | 
						|
			{
 | 
						|
				SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
 | 
						|
				using (SqlCommand cm = cn.CreateCommand())
 | 
						|
				{
 | 
						|
					cm.CommandType = CommandType.StoredProcedure;
 | 
						|
					cm.CommandText = "addRevision";
 | 
						|
					// Input All Fields - Except Calculated Columns
 | 
						|
					cm.Parameters.AddWithValue("@ItemID", _ItemID);
 | 
						|
					cm.Parameters.AddWithValue("@TypeID", _TypeID);
 | 
						|
					cm.Parameters.AddWithValue("@RevisionNumber", _RevisionNumber);
 | 
						|
					if (_RevisionDate != null && ((DateTime)_RevisionDate).Year >= 1753 && ((DateTime)_RevisionDate).Year <= 9999) cm.Parameters.AddWithValue("@RevisionDate", _RevisionDate);
 | 
						|
					cm.Parameters.AddWithValue("@Notes", _Notes);
 | 
						|
					cm.Parameters.AddWithValue("@Config", _Config);
 | 
						|
					if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
 | 
						|
					cm.Parameters.AddWithValue("@UserID", _UserID);
 | 
						|
					// Output Calculated Columns
 | 
						|
					SqlParameter param_RevisionID = new SqlParameter("@newRevisionID", SqlDbType.Int);
 | 
						|
					param_RevisionID.Direction = ParameterDirection.Output;
 | 
						|
					cm.Parameters.Add(param_RevisionID);
 | 
						|
					SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp);
 | 
						|
					param_LastChanged.Direction = ParameterDirection.Output;
 | 
						|
					cm.Parameters.Add(param_LastChanged);
 | 
						|
					// CSLATODO: Define any additional output parameters
 | 
						|
					cm.ExecuteNonQuery();
 | 
						|
					// Save all values being returned from the Procedure
 | 
						|
					_RevisionID = (int)cm.Parameters["@newRevisionID"].Value;
 | 
						|
					_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
 | 
						|
				}
 | 
						|
				MarkOld();
 | 
						|
				// update child objects
 | 
						|
				if (_RevisionChecks != null) _RevisionChecks.Update(this);
 | 
						|
				if (_RevisionVersions != null) _RevisionVersions.Update(this);
 | 
						|
				if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Revision.SQLInsert", GetHashCode());
 | 
						|
			}
 | 
						|
			catch (Exception ex)
 | 
						|
			{
 | 
						|
				if (_MyLog.IsErrorEnabled) _MyLog.Error("Revision.SQLInsert", ex);
 | 
						|
				_ErrorMessage = ex.Message;
 | 
						|
				throw new DbCslaException("Revision.SQLInsert", ex);
 | 
						|
			}
 | 
						|
		}
 | 
						|
		[Transactional(TransactionalTypes.TransactionScope)]
 | 
						|
		public static byte[] Add(SqlConnection cn, ref int revisionID, int itemID, int typeID, string revisionNumber, DateTime? revisionDate, string notes, string config, DateTime dts, string userID)
 | 
						|
		{
 | 
						|
			if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Revision.Add", 0);
 | 
						|
			try
 | 
						|
			{
 | 
						|
				using (SqlCommand cm = cn.CreateCommand())
 | 
						|
				{
 | 
						|
					cm.CommandType = CommandType.StoredProcedure;
 | 
						|
					cm.CommandText = "addRevision";
 | 
						|
					// Input All Fields - Except Calculated Columns
 | 
						|
					cm.Parameters.AddWithValue("@ItemID", itemID);
 | 
						|
					cm.Parameters.AddWithValue("@TypeID", typeID);
 | 
						|
					cm.Parameters.AddWithValue("@RevisionNumber", revisionNumber);
 | 
						|
					if (revisionDate != null && ((DateTime)revisionDate).Year >= 1753 && ((DateTime)revisionDate).Year <= 9999) cm.Parameters.AddWithValue("@RevisionDate", revisionDate);
 | 
						|
					cm.Parameters.AddWithValue("@Notes", notes);
 | 
						|
					cm.Parameters.AddWithValue("@Config", config);
 | 
						|
					if (dts.Year >= 1753 && dts.Year <= 9999) cm.Parameters.AddWithValue("@DTS", dts);
 | 
						|
					cm.Parameters.AddWithValue("@UserID", userID);
 | 
						|
					// Output Calculated Columns
 | 
						|
					SqlParameter param_RevisionID = new SqlParameter("@newRevisionID", SqlDbType.Int);
 | 
						|
					param_RevisionID.Direction = ParameterDirection.Output;
 | 
						|
					cm.Parameters.Add(param_RevisionID);
 | 
						|
					SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp);
 | 
						|
					param_LastChanged.Direction = ParameterDirection.Output;
 | 
						|
					cm.Parameters.Add(param_LastChanged);
 | 
						|
					// CSLATODO: Define any additional output parameters
 | 
						|
					cm.ExecuteNonQuery();
 | 
						|
					// Save all values being returned from the Procedure
 | 
						|
					revisionID = (int)cm.Parameters["@newRevisionID"].Value;
 | 
						|
					return (byte[])cm.Parameters["@newLastChanged"].Value;
 | 
						|
				}
 | 
						|
			}
 | 
						|
			catch (Exception ex)
 | 
						|
			{
 | 
						|
				if (_MyLog.IsErrorEnabled) _MyLog.Error("Revision.Add", ex);
 | 
						|
				throw new DbCslaException("Revision.Add", ex);
 | 
						|
			}
 | 
						|
		}
 | 
						|
		[Transactional(TransactionalTypes.TransactionScope)]
 | 
						|
		protected override void DataPortal_Update()
 | 
						|
		{
 | 
						|
			if (!IsDirty) return;	// If not dirty - nothing to do
 | 
						|
			if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Revision.DataPortal_Update", GetHashCode());
 | 
						|
			try
 | 
						|
			{
 | 
						|
				using (SqlConnection cn = Database.VEPROMS_SqlConnection)
 | 
						|
				{
 | 
						|
					ApplicationContext.LocalContext["cn"] = cn;
 | 
						|
					SQLUpdate();
 | 
						|
					// 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("Revision.DataPortal_Update", ex);
 | 
						|
				_ErrorMessage = ex.Message;
 | 
						|
				if (!ex.Message.EndsWith("has been edited by another user.")) throw ex;
 | 
						|
			}
 | 
						|
		}
 | 
						|
		[Transactional(TransactionalTypes.TransactionScope)]
 | 
						|
		internal void SQLUpdate()
 | 
						|
		{
 | 
						|
			if (!IsDirty) return;	// If not dirty - nothing to do
 | 
						|
			if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Revision.SQLUpdate", GetHashCode());
 | 
						|
			try
 | 
						|
			{
 | 
						|
				SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
 | 
						|
				if (base.IsDirty)
 | 
						|
				{
 | 
						|
					using (SqlCommand cm = cn.CreateCommand())
 | 
						|
					{
 | 
						|
						cm.CommandType = CommandType.StoredProcedure;
 | 
						|
						cm.CommandText = "updateRevision";
 | 
						|
						// All Fields including Calculated Fields
 | 
						|
						cm.Parameters.AddWithValue("@RevisionID", _RevisionID);
 | 
						|
						cm.Parameters.AddWithValue("@ItemID", _ItemID);
 | 
						|
						cm.Parameters.AddWithValue("@TypeID", _TypeID);
 | 
						|
						cm.Parameters.AddWithValue("@RevisionNumber", _RevisionNumber);
 | 
						|
						if (_RevisionDate != null && ((DateTime)_RevisionDate).Year >= 1753 && ((DateTime)_RevisionDate).Year <= 9999) cm.Parameters.AddWithValue("@RevisionDate", _RevisionDate);
 | 
						|
						cm.Parameters.AddWithValue("@Notes", _Notes);
 | 
						|
						cm.Parameters.AddWithValue("@Config", _Config);
 | 
						|
						if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
 | 
						|
						cm.Parameters.AddWithValue("@UserID", _UserID);
 | 
						|
						cm.Parameters.AddWithValue("@LastChanged", _LastChanged);
 | 
						|
						// Output Calculated Columns
 | 
						|
						SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp);
 | 
						|
						param_LastChanged.Direction = ParameterDirection.Output;
 | 
						|
						cm.Parameters.Add(param_LastChanged);
 | 
						|
						// CSLATODO: Define any additional output parameters
 | 
						|
						cm.ExecuteNonQuery();
 | 
						|
						// Save all values being returned from the Procedure
 | 
						|
						_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
 | 
						|
					}
 | 
						|
				}
 | 
						|
				MarkOld();
 | 
						|
				// use the open connection to update child objects
 | 
						|
				if (_RevisionChecks != null) _RevisionChecks.Update(this);
 | 
						|
				if (_RevisionVersions != null) _RevisionVersions.Update(this);
 | 
						|
			}
 | 
						|
			catch (Exception ex)
 | 
						|
			{
 | 
						|
				if (_MyLog.IsErrorEnabled) _MyLog.Error("Revision.SQLUpdate", ex);
 | 
						|
				_ErrorMessage = ex.Message;
 | 
						|
				if (!ex.Message.EndsWith("has been edited by another user.")) throw ex;
 | 
						|
			}
 | 
						|
		}
 | 
						|
		internal void Update()
 | 
						|
		{
 | 
						|
			if (!this.IsDirty) return;
 | 
						|
			if (base.IsDirty)
 | 
						|
			{
 | 
						|
				SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
 | 
						|
				if (IsNew)
 | 
						|
					_LastChanged = Revision.Add(cn, ref _RevisionID, _ItemID, _TypeID, _RevisionNumber, _RevisionDate, _Notes, _Config, _DTS, _UserID);
 | 
						|
				else
 | 
						|
					_LastChanged = Revision.Update(cn, ref _RevisionID, _ItemID, _TypeID, _RevisionNumber, _RevisionDate, _Notes, _Config, _DTS, _UserID, ref _LastChanged);
 | 
						|
				MarkOld();
 | 
						|
			}
 | 
						|
			if (_RevisionChecks != null) _RevisionChecks.Update(this);
 | 
						|
			if (_RevisionVersions != null) _RevisionVersions.Update(this);
 | 
						|
		}
 | 
						|
		[Transactional(TransactionalTypes.TransactionScope)]
 | 
						|
		public static byte[] Update(SqlConnection cn, ref int revisionID, int itemID, int typeID, string revisionNumber, DateTime? revisionDate, string notes, string config, DateTime dts, string userID, ref byte[] lastChanged)
 | 
						|
		{
 | 
						|
			if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Revision.Update", 0);
 | 
						|
			try
 | 
						|
			{
 | 
						|
				using (SqlCommand cm = cn.CreateCommand())
 | 
						|
				{
 | 
						|
					cm.CommandType = CommandType.StoredProcedure;
 | 
						|
					cm.CommandText = "updateRevision";
 | 
						|
					// Input All Fields - Except Calculated Columns
 | 
						|
					cm.Parameters.AddWithValue("@RevisionID", revisionID);
 | 
						|
					cm.Parameters.AddWithValue("@ItemID", itemID);
 | 
						|
					cm.Parameters.AddWithValue("@TypeID", typeID);
 | 
						|
					cm.Parameters.AddWithValue("@RevisionNumber", revisionNumber);
 | 
						|
					if (revisionDate != null && ((DateTime)revisionDate).Year >= 1753 && ((DateTime)revisionDate).Year <= 9999) cm.Parameters.AddWithValue("@RevisionDate", revisionDate);
 | 
						|
					cm.Parameters.AddWithValue("@Notes", notes);
 | 
						|
					cm.Parameters.AddWithValue("@Config", config);
 | 
						|
					if (dts.Year >= 1753 && dts.Year <= 9999) cm.Parameters.AddWithValue("@DTS", dts);
 | 
						|
					cm.Parameters.AddWithValue("@UserID", userID);
 | 
						|
					cm.Parameters.AddWithValue("@LastChanged", lastChanged);
 | 
						|
					// Output Calculated Columns
 | 
						|
					SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp);
 | 
						|
					param_LastChanged.Direction = ParameterDirection.Output;
 | 
						|
					cm.Parameters.Add(param_LastChanged);
 | 
						|
					// CSLATODO: Define any additional output parameters
 | 
						|
					cm.ExecuteNonQuery();
 | 
						|
					// Save all values being returned from the Procedure
 | 
						|
					return (byte[])cm.Parameters["@newLastChanged"].Value;
 | 
						|
				}
 | 
						|
			}
 | 
						|
			catch (Exception ex)
 | 
						|
			{
 | 
						|
				if (_MyLog.IsErrorEnabled) _MyLog.Error("Revision.Update", ex);
 | 
						|
				throw new DbCslaException("Revision.Update", ex);
 | 
						|
			}
 | 
						|
		}
 | 
						|
		[Transactional(TransactionalTypes.TransactionScope)]
 | 
						|
		protected override void DataPortal_DeleteSelf()
 | 
						|
		{
 | 
						|
			DataPortal_Delete(new PKCriteria(_RevisionID));
 | 
						|
		}
 | 
						|
		[Transactional(TransactionalTypes.TransactionScope)]
 | 
						|
		private void DataPortal_Delete(PKCriteria criteria)
 | 
						|
		{
 | 
						|
			if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Revision.DataPortal_Delete", GetHashCode());
 | 
						|
			try
 | 
						|
			{
 | 
						|
				using (SqlConnection cn = Database.VEPROMS_SqlConnection)
 | 
						|
				{
 | 
						|
					using (SqlCommand cm = cn.CreateCommand())
 | 
						|
					{
 | 
						|
						cm.CommandType = CommandType.StoredProcedure;
 | 
						|
						cm.CommandText = "deleteRevision";
 | 
						|
						cm.Parameters.AddWithValue("@RevisionID", criteria.RevisionID);
 | 
						|
						cm.ExecuteNonQuery();
 | 
						|
					}
 | 
						|
				}
 | 
						|
			}
 | 
						|
			catch (Exception ex)
 | 
						|
			{
 | 
						|
				if (_MyLog.IsErrorEnabled) _MyLog.Error("Revision.DataPortal_Delete", ex);
 | 
						|
				_ErrorMessage = ex.Message;
 | 
						|
				throw new DbCslaException("Revision.DataPortal_Delete", ex);
 | 
						|
			}
 | 
						|
		}
 | 
						|
		[Transactional(TransactionalTypes.TransactionScope)]
 | 
						|
		public static void Remove(SqlConnection cn, int revisionID)
 | 
						|
		{
 | 
						|
			if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Revision.Remove", 0);
 | 
						|
			try
 | 
						|
			{
 | 
						|
				using (SqlCommand cm = cn.CreateCommand())
 | 
						|
				{
 | 
						|
					cm.CommandType = CommandType.StoredProcedure;
 | 
						|
					cm.CommandText = "deleteRevision";
 | 
						|
					// Input PK Fields
 | 
						|
					cm.Parameters.AddWithValue("@RevisionID", revisionID);
 | 
						|
					// CSLATODO: Define any additional output parameters
 | 
						|
					cm.ExecuteNonQuery();
 | 
						|
				}
 | 
						|
			}
 | 
						|
			catch (Exception ex)
 | 
						|
			{
 | 
						|
				if (_MyLog.IsErrorEnabled) _MyLog.Error("Revision.Remove", ex);
 | 
						|
				throw new DbCslaException("Revision.Remove", ex);
 | 
						|
			}
 | 
						|
		}
 | 
						|
		#endregion
 | 
						|
		#region Exists
 | 
						|
		public static bool Exists(int revisionID)
 | 
						|
		{
 | 
						|
			ExistsCommand result;
 | 
						|
			try
 | 
						|
			{
 | 
						|
				result = DataPortal.Execute<ExistsCommand>(new ExistsCommand(revisionID));
 | 
						|
				return result.Exists;
 | 
						|
			}
 | 
						|
			catch (Exception ex)
 | 
						|
			{
 | 
						|
				throw new DbCslaException("Error on Revision.Exists", ex);
 | 
						|
			}
 | 
						|
		}
 | 
						|
		[Serializable()]
 | 
						|
		private class ExistsCommand : CommandBase
 | 
						|
		{
 | 
						|
			private int _RevisionID;
 | 
						|
			private bool _exists;
 | 
						|
			public bool Exists
 | 
						|
			{
 | 
						|
				get { return _exists; }
 | 
						|
			}
 | 
						|
			public ExistsCommand(int revisionID)
 | 
						|
			{
 | 
						|
				_RevisionID = revisionID;
 | 
						|
			}
 | 
						|
			protected override void DataPortal_Execute()
 | 
						|
			{
 | 
						|
				if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Revision.DataPortal_Execute", GetHashCode());
 | 
						|
				try
 | 
						|
				{
 | 
						|
					using (SqlConnection cn = Database.VEPROMS_SqlConnection)
 | 
						|
					{
 | 
						|
						cn.Open();
 | 
						|
						using (SqlCommand cm = cn.CreateCommand())
 | 
						|
						{
 | 
						|
							cm.CommandType = CommandType.StoredProcedure;
 | 
						|
							cm.CommandText = "existsRevision";
 | 
						|
							cm.Parameters.AddWithValue("@RevisionID", _RevisionID);
 | 
						|
							int count = (int)cm.ExecuteScalar();
 | 
						|
							_exists = (count > 0);
 | 
						|
						}
 | 
						|
					}
 | 
						|
				}
 | 
						|
				catch (Exception ex)
 | 
						|
				{
 | 
						|
					if (_MyLog.IsErrorEnabled) _MyLog.Error("Revision.DataPortal_Execute", ex);
 | 
						|
					throw new DbCslaException("Revision.DataPortal_Execute", ex);
 | 
						|
				}
 | 
						|
			}
 | 
						|
		}
 | 
						|
		#endregion
 | 
						|
		// Standard Default Code
 | 
						|
		#region extension
 | 
						|
		RevisionExtension _RevisionExtension = new RevisionExtension();
 | 
						|
		[Serializable()]
 | 
						|
		partial class RevisionExtension : extensionBase
 | 
						|
		{
 | 
						|
		}
 | 
						|
		[Serializable()]
 | 
						|
		class extensionBase
 | 
						|
		{
 | 
						|
			// Default Values
 | 
						|
			public virtual int DefaultTypeID
 | 
						|
			{
 | 
						|
				get { return 1; }
 | 
						|
			}
 | 
						|
			public virtual DateTime DefaultDTS
 | 
						|
			{
 | 
						|
				get { return DateTime.Now; }
 | 
						|
			}
 | 
						|
			public virtual string DefaultUserID
 | 
						|
			{
 | 
						|
				get { return Volian.Base.Library.VlnSettings.UserID; }
 | 
						|
			}
 | 
						|
			// Authorization Rules
 | 
						|
			public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules)
 | 
						|
			{
 | 
						|
				// Needs to be overriden to add new authorization rules
 | 
						|
			}
 | 
						|
			// Instance Authorization Rules
 | 
						|
			public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules)
 | 
						|
			{
 | 
						|
				// Needs to be overriden to add new authorization rules
 | 
						|
			}
 | 
						|
			// Validation Rules
 | 
						|
			public virtual void AddValidationRules(Csla.Validation.ValidationRules rules)
 | 
						|
			{
 | 
						|
				// Needs to be overriden to add new validation rules
 | 
						|
			}
 | 
						|
			// InstanceValidation Rules
 | 
						|
			public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules)
 | 
						|
			{
 | 
						|
				// Needs to be overriden to add new validation rules
 | 
						|
			}
 | 
						|
		}
 | 
						|
		#endregion
 | 
						|
	} // Class
 | 
						|
	#region Converter
 | 
						|
	internal class RevisionConverter : ExpandableObjectConverter
 | 
						|
	{
 | 
						|
		public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
 | 
						|
		{
 | 
						|
			if (destType == typeof(string) && value is Revision)
 | 
						|
			{
 | 
						|
				// Return the ToString value
 | 
						|
				return ((Revision)value).ToString();
 | 
						|
			}
 | 
						|
			return base.ConvertTo(context, culture, value, destType);
 | 
						|
		}
 | 
						|
	}
 | 
						|
	#endregion
 | 
						|
} // Namespace
 | 
						|
 | 
						|
 | 
						|
//// The following is a sample Extension File.  You can use it to create RevisionExt.cs
 | 
						|
//using System;
 | 
						|
//using System.Collections.Generic;
 | 
						|
//using System.Text;
 | 
						|
//using Csla;
 | 
						|
 | 
						|
//namespace VEPROMS.CSLA.Library
 | 
						|
//{
 | 
						|
//  public partial class Revision
 | 
						|
//  {
 | 
						|
//    partial class RevisionExtension : extensionBase
 | 
						|
//    {
 | 
						|
//      // CSLATODO: Override automatic defaults
 | 
						|
//      public virtual int DefaultTypeID
 | 
						|
//      {
 | 
						|
//        get { return 1; }
 | 
						|
//      }
 | 
						|
//      public virtual DateTime DefaultDTS
 | 
						|
//      {
 | 
						|
//        get { return DateTime.Now; }
 | 
						|
//      }
 | 
						|
//      public virtual string DefaultUserID
 | 
						|
//      {
 | 
						|
//        get { return Environment.UserName.ToUpper(); }
 | 
						|
//      }
 | 
						|
//      public new void AddAuthorizationRules(Csla.Security.AuthorizationRules rules)
 | 
						|
//      {
 | 
						|
//        //rules.AllowRead(Dbid, "<Role(s)>");
 | 
						|
//      }
 | 
						|
//      public new void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules)
 | 
						|
//      {
 | 
						|
//        //rules.AllowInstanceRead(Dbid, "<Role(s)>");
 | 
						|
//      }
 | 
						|
//      public new void AddValidationRules(Csla.Validation.ValidationRules rules)
 | 
						|
//      {
 | 
						|
//        rules.AddRule(
 | 
						|
//          Csla.Validation.CommonRules.StringMaxLength,
 | 
						|
//          new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100));
 | 
						|
//      }
 | 
						|
//      public new void AddInstanceValidationRules(Csla.Validation.ValidationRules rules)
 | 
						|
//      {
 | 
						|
//        rules.AddInstanceRule(/* Instance Validation Rule */);
 | 
						|
//      }
 | 
						|
//    }
 | 
						|
//  }
 | 
						|
//}
 |