From 3153ffb024c33fe488a717882e977cf86fc5122b Mon Sep 17 00:00:00 2001 From: Rich Date: Mon, 23 Jan 2012 13:51:04 +0000 Subject: [PATCH] Object support for approval changes to support approval process changes to limit menu to appropriate version of code changes to support consistency check report --- .../Config/ROFSTLookup.cs | 14 + .../Generated/Annotation.cs | 1 + .../Generated/AnnotationInfo.cs | 15 +- PROMS/VEPROMS.CSLA.Library/Generated/Check.cs | 1094 ++++++++++++++ .../Generated/CheckInfo.cs | 476 ++++++ .../Generated/CheckInfoList.cs | 319 +++++ .../Generated/ContentInfo.cs | 4 +- .../Generated/Database.cs | 6 +- .../Generated/Revision.cs | 1272 +++++++++++++++++ .../Generated/RevisionCheck.cs | 554 +++++++ .../Generated/RevisionChecks.cs | 322 +++++ .../Generated/RevisionInfo.cs | 460 ++++++ .../Generated/RevisionInfoList.cs | 205 +++ .../Generated/RevisionVersion.cs | 557 ++++++++ .../Generated/RevisionVersions.cs | 322 +++++ PROMS/VEPROMS.CSLA.Library/Generated/Stage.cs | 1183 +++++++++++++++ .../Generated/StageCheck.cs | 587 ++++++++ .../Generated/StageChecks.cs | 322 +++++ .../Generated/StageInfo.cs | 424 ++++++ .../Generated/StageInfoList.cs | 205 +++ .../Generated/StageVersion.cs | 590 ++++++++ .../Generated/StageVersions.cs | 322 +++++ .../VEPROMS.CSLA.Library/Generated/Version.cs | 1075 ++++++++++++++ .../Generated/VersionInfo.cs | 490 +++++++ .../Generated/VersionInfoList.cs | 319 +++++ 25 files changed, 11132 insertions(+), 6 deletions(-) create mode 100644 PROMS/VEPROMS.CSLA.Library/Generated/Check.cs create mode 100644 PROMS/VEPROMS.CSLA.Library/Generated/CheckInfo.cs create mode 100644 PROMS/VEPROMS.CSLA.Library/Generated/CheckInfoList.cs create mode 100644 PROMS/VEPROMS.CSLA.Library/Generated/Revision.cs create mode 100644 PROMS/VEPROMS.CSLA.Library/Generated/RevisionCheck.cs create mode 100644 PROMS/VEPROMS.CSLA.Library/Generated/RevisionChecks.cs create mode 100644 PROMS/VEPROMS.CSLA.Library/Generated/RevisionInfo.cs create mode 100644 PROMS/VEPROMS.CSLA.Library/Generated/RevisionInfoList.cs create mode 100644 PROMS/VEPROMS.CSLA.Library/Generated/RevisionVersion.cs create mode 100644 PROMS/VEPROMS.CSLA.Library/Generated/RevisionVersions.cs create mode 100644 PROMS/VEPROMS.CSLA.Library/Generated/Stage.cs create mode 100644 PROMS/VEPROMS.CSLA.Library/Generated/StageCheck.cs create mode 100644 PROMS/VEPROMS.CSLA.Library/Generated/StageChecks.cs create mode 100644 PROMS/VEPROMS.CSLA.Library/Generated/StageInfo.cs create mode 100644 PROMS/VEPROMS.CSLA.Library/Generated/StageInfoList.cs create mode 100644 PROMS/VEPROMS.CSLA.Library/Generated/StageVersion.cs create mode 100644 PROMS/VEPROMS.CSLA.Library/Generated/StageVersions.cs create mode 100644 PROMS/VEPROMS.CSLA.Library/Generated/Version.cs create mode 100644 PROMS/VEPROMS.CSLA.Library/Generated/VersionInfo.cs create mode 100644 PROMS/VEPROMS.CSLA.Library/Generated/VersionInfoList.cs diff --git a/PROMS/VEPROMS.CSLA.Library/Config/ROFSTLookup.cs b/PROMS/VEPROMS.CSLA.Library/Config/ROFSTLookup.cs index c7d24505..28b3eac8 100644 --- a/PROMS/VEPROMS.CSLA.Library/Config/ROFSTLookup.cs +++ b/PROMS/VEPROMS.CSLA.Library/Config/ROFSTLookup.cs @@ -277,6 +277,20 @@ namespace VEPROMS.CSLA.Library tmp.ID = -1; return tmp; } + public string GetROTitle(string ROID) + { + StringBuilder sb = new StringBuilder(); + rochild roc = GetRoChild12(ROID); + sb.Append(roc.title.Replace(roc.appid,"").Replace(roc.value,"").Trim()); + do + { + string parent = ROID.Substring(0, 4) + string.Format("{0:X8}", roc.ParentID); + roc = GetRoChild12(parent); + if (roc.ID > 0) + sb.Insert(0, roc.title + " - "); + } while (roc.ID > 0); + return sb.ToString(); + } // The following Method is not correct. It needs to have a RO database id as well as an id. Without that, // the first RO with a specific id will be found regardless of the RO Database id. //public rochild GetRoChildFromID(int id) diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/Annotation.cs b/PROMS/VEPROMS.CSLA.Library/Generated/Annotation.cs index 9f8118d7..628d1511 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/Annotation.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/Annotation.cs @@ -637,6 +637,7 @@ namespace VEPROMS.CSLA.Library RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache AddToCache(annotation);//Refresh the item in AllList ProcessRefreshList(); + AnnotationInfo.StaticOnInfoChanged(); return annotation; } catch (Exception ex) diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/AnnotationInfo.cs b/PROMS/VEPROMS.CSLA.Library/Generated/AnnotationInfo.cs index 97f44af2..b5b2fc51 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/AnnotationInfo.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/AnnotationInfo.cs @@ -27,10 +27,23 @@ namespace VEPROMS.CSLA.Library [TypeConverter(typeof(AnnotationInfoConverter))] public partial class AnnotationInfo : ReadOnlyBase, IDisposable { + public static event AnnotationInfoEvent InfoChanged; + internal void OnInfoChanged(AnnotationInfo annotationInfo) + { + if (InfoChanged != null) + InfoChanged(this); + } + internal static void StaticOnInfoChanged() + { + if (InfoChanged != null) + InfoChanged(null); + } public event AnnotationInfoEvent Changed; private void OnChange() { - if (Changed != null) Changed(this); + if (Changed != null) + Changed(this); + OnInfoChanged(this); } #region Log4Net private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/Check.cs b/PROMS/VEPROMS.CSLA.Library/Generated/Check.cs new file mode 100644 index 00000000..c8c425f1 --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/Check.cs @@ -0,0 +1,1094 @@ +// ======================================================================== +// 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 +{ + /// + /// Check Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(CheckConverter))] + public partial class Check : BusinessBase, IDisposable, IVEHasBrokenRules + { + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Refresh + private List _RefreshChecks = new List(); + private void AddToRefreshList(List refreshChecks) + { + if (IsDirty) + refreshChecks.Add(this); + } + private void BuildRefreshList() + { + _RefreshChecks = new List(); + AddToRefreshList(_RefreshChecks); + } + private void ProcessRefreshList() + { + foreach (Check tmp in _RefreshChecks) + { + CheckInfo.Refresh(tmp); + if (tmp._MyRevision != null) RevisionInfo.Refresh(tmp._MyRevision); + if (tmp._MyStage != null) StageInfo.Refresh(tmp._MyStage); + } + } + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(Check check) + { + if (!_CacheList.Contains(check)) _CacheList.Add(check); // In AddToCache + } + protected static void RemoveFromCache(Check check) + { + while (_CacheList.Contains(check)) _CacheList.Remove(check); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + while (_CacheList.Count > 0) // Move Check(s) from temporary _CacheList to _CacheByPrimaryKey + { + Check tmp = _CacheList[0]; // Get the first Check + string pKey = tmp.CheckID.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 Check + } + } + protected static Check 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; } + } + private static int _nextCheckID = -1; + public static int NextCheckID + { + get { return _nextCheckID--; } + } + 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 _RevisionID; + public int RevisionID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("RevisionID", true); + if (_MyRevision != null) _RevisionID = _MyRevision.RevisionID; + return _RevisionID; + } + } + private Revision _MyRevision; + public Revision MyRevision + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("MyRevision", true); + if (_MyRevision == null && _RevisionID != 0) _MyRevision = Revision.Get(_RevisionID); + return _MyRevision; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + CanWriteProperty("MyRevision", true); + if (_MyRevision != value) + { + _MyRevision = value; + _RevisionID = value.RevisionID;// Update underlying data field + PropertyHasChanged(); + } + } + } + private int _StageID; + public int StageID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("StageID", true); + if (_MyStage != null) _StageID = _MyStage.StageID; + return _StageID; + } + } + private Stage _MyStage; + public Stage MyStage + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("MyStage", true); + if (_MyStage == null && _StageID != 0) _MyStage = Stage.Get(_StageID); + return _MyStage; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + CanWriteProperty("MyStage", true); + if (_MyStage != value) + { + _MyStage = value; + _StageID = value.StageID;// Update underlying data field + PropertyHasChanged(); + } + } + } + private string _ConsistencyChecks = string.Empty; + public string ConsistencyChecks + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("ConsistencyChecks", true); + return _ConsistencyChecks; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + CanWriteProperty("ConsistencyChecks", true); + if (value == null) value = string.Empty; + if (_ConsistencyChecks != value) + { + _ConsistencyChecks = 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 + public override bool IsDirty + { + get + { + if ( base.IsDirty ) + return true; + return IsDirtyList(new List()); + } + } + public bool IsDirtyList(List list) + { + if (base.IsDirty || list.Contains(this)) + return base.IsDirty; + list.Add(this); + return base.IsDirty || (_MyRevision == null ? false : _MyRevision.IsDirtyList(list)) || (_MyStage == null ? false : _MyStage.IsDirtyList(list)); + } + public override bool IsValid + { + get { return IsValidList(new List()); } + } + public bool IsValidList(List list) + { + if(list.Contains(this)) + return (IsNew && !IsDirty) ? true : base.IsValid; + list.Add(this); + return ((IsNew && !IsDirty) ? true : base.IsValid) && (_MyRevision == null ? true : _MyRevision.IsValidList(list)) && (_MyStage == null ? true : _MyStage.IsValidList(list)); + } + // CSLATODO: Replace base Check.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current Check + //public override string ToString() + //{ + // return base.ToString(); + //} + // CSLATODO: Check Check.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current Check + protected override object GetIdValue() + { + return MyCheckUnique; // 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 (_MyRevision != null && (hasBrokenRules = _MyRevision.HasBrokenRules) != null) return hasBrokenRules; + if (_MyStage != null && (hasBrokenRules = _MyStage.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(MyRevisionRequired, "MyRevision"); + ValidationRules.AddRule(MyStageRequired, "MyStage"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("ConsistencyChecks", 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"); + _CheckExtension.AddValidationRules(ValidationRules); + // CSLATODO: Add other validation rules + } + protected override void AddInstanceBusinessRules() + { + _CheckExtension.AddInstanceValidationRules(ValidationRules); + // CSLATODO: Add other validation rules + } + private static bool MyRevisionRequired(Check target, Csla.Validation.RuleArgs e) + { + if (target._RevisionID == 0 && target._MyRevision == null) // Required field missing + { + e.Description = "Required"; + return false; + } + return true; + } + private static bool MyStageRequired(Check target, Csla.Validation.RuleArgs e) + { + if (target._StageID == 0 && target._MyStage == null) // Required field missing + { + e.Description = "Required"; + return false; + } + return true; + } + // 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(CheckID, ""); + //AuthorizationRules.AllowRead(RevisionID, ""); + //AuthorizationRules.AllowRead(StageID, ""); + //AuthorizationRules.AllowRead(ConsistencyChecks, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowRead(UserID, ""); + //AuthorizationRules.AllowWrite(RevisionID, ""); + //AuthorizationRules.AllowWrite(StageID, ""); + //AuthorizationRules.AllowWrite(ConsistencyChecks, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowWrite(UserID, ""); + _CheckExtension.AddAuthorizationRules(AuthorizationRules); + } + protected override void AddInstanceAuthorizationRules() + { + //CSLATODO: Who can read/write which fields + _CheckExtension.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; + } + 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 _CheckUnique = 0; + protected static int CheckUnique + { get { return ++_CheckUnique; } } + private int _MyCheckUnique = CheckUnique; + public int MyCheckUnique // Absolutely Unique ID - Editable + { get { return _MyCheckUnique; } } + protected Check() + {/* require use of factory methods */ + AddToCache(this); + } + public void Dispose() + { + RemoveFromDictionaries(); + } + private void RemoveFromDictionaries() + { + RemoveFromCache(this); + if (_CacheByPrimaryKey.ContainsKey(CheckID.ToString())) + { + List listCheck = _CacheByPrimaryKey[CheckID.ToString()]; // Get the list of items + while (listCheck.Contains(this)) listCheck.Remove(this); // Remove the item from the list + if (listCheck.Count == 0) //If there are no items left in the list + _CacheByPrimaryKey.Remove(CheckID.ToString()); // remove the list + } + } + public static Check New() + { + if (!CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a Check"); + try + { + return DataPortal.Create(); + } + catch (Exception ex) + { + throw new DbCslaException("Error on Check.New", ex); + } + } + public static Check New(Revision myRevision, Stage myStage) + { + Check tmp = Check.New(); + tmp.MyRevision = myRevision; + tmp.MyStage = myStage; + return tmp; + } + public static Check New(Revision myRevision, Stage myStage, string consistencyChecks, DateTime dts, string userID) + { + Check tmp = Check.New(); + tmp.MyRevision = myRevision; + tmp.MyStage = myStage; + tmp.ConsistencyChecks = consistencyChecks; + tmp.DTS = dts; + tmp.UserID = userID; + return tmp; + } + public static Check MakeCheck(Revision myRevision, Stage myStage, string consistencyChecks, DateTime dts, string userID) + { + Check tmp = Check.New(myRevision, myStage, consistencyChecks, dts, userID); + if (tmp.IsSavable) + { + Check tmp2 = tmp; + tmp = tmp2.Save(); + tmp2.Dispose(); + } + 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 Check New(Revision myRevision, Stage myStage, string consistencyChecks) + { + Check tmp = Check.New(); + tmp.MyRevision = myRevision; + tmp.MyStage = myStage; + tmp.ConsistencyChecks = consistencyChecks; + return tmp; + } + public static Check MakeCheck(Revision myRevision, Stage myStage, string consistencyChecks) + { + Check tmp = Check.New(myRevision, myStage, consistencyChecks); + if (tmp.IsSavable) + { + Check tmp2 = tmp; + tmp = tmp2.Save(); + tmp2.Dispose(); + } + 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 Check Get(int checkID) + { + if (!CanGetObject()) + throw new System.Security.SecurityException("User not authorized to view a Check"); + try + { + Check tmp = GetCachedByPrimaryKey(checkID); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(checkID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up Check + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on Check.Get", ex); + } + } + public static Check Get(SafeDataReader dr) + { + if (dr.Read()) return new Check(dr); + return null; + } + internal Check(SafeDataReader dr) + { + ReadData(dr); + } + public static void Delete(int checkID) + { + if (!CanDeleteObject()) + throw new System.Security.SecurityException("User not authorized to remove a Check"); + try + { + DataPortal.Delete(new PKCriteria(checkID)); + } + catch (Exception ex) + { + throw new DbCslaException("Error on Check.Delete", ex); + } + } + public override Check Save() + { + if (IsDeleted && !CanDeleteObject()) + throw new System.Security.SecurityException("User not authorized to remove a Check"); + else if (IsNew && !CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a Check"); + else if (!CanEditObject()) + throw new System.Security.SecurityException("User not authorized to update a Check"); + try + { + BuildRefreshList(); + Check check = base.Save(); + RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache + AddToCache(check);//Refresh the item in AllList + ProcessRefreshList(); + return check; + } + catch (Exception ex) + { + throw new DbCslaException("Error on CSLA Save", ex); + } + } + #endregion + #region Data Access Portal + [Serializable()] + protected class PKCriteria + { + private int _CheckID; + public int CheckID + { get { return _CheckID; } } + public PKCriteria(int checkID) + { + _CheckID = checkID; + } + } + // CSLATODO: If Create needs to access DB - It should not be marked RunLocal + [RunLocal()] + private new void DataPortal_Create() + { + _CheckID = NextCheckID; + // Database Defaults + _DTS = _CheckExtension.DefaultDTS; + _UserID = _CheckExtension.DefaultUserID; + // CSLATODO: Add any defaults that are necessary + ValidationRules.CheckRules(); + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Check.ReadData", GetHashCode()); + try + { + _CheckID = dr.GetInt32("CheckID"); + _RevisionID = dr.GetInt32("RevisionID"); + _StageID = dr.GetInt32("StageID"); + _ConsistencyChecks = dr.GetString("ConsistencyChecks"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + MarkOld(); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Check.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Check.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Check.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 = "getCheck"; + 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("Check.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Check.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("Check.DataPortal_Insert", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Check.DataPortal_Insert", ex); + } + finally + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Check.DataPortal_Insert", GetHashCode()); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + internal void SQLInsert() + { + if (!this.IsDirty) return; + try + { + if (_MyRevision != null) _MyRevision.Update(); + if (_MyStage != null) _MyStage.Update(); + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "addCheck"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@RevisionID", RevisionID); + cm.Parameters.AddWithValue("@StageID", StageID); + cm.Parameters.AddWithValue("@ConsistencyChecks", _ConsistencyChecks); + if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS); + cm.Parameters.AddWithValue("@UserID", _UserID); + // Output Calculated Columns + SqlParameter param_CheckID = new SqlParameter("@newCheckID", SqlDbType.Int); + param_CheckID.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_CheckID); + 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 + _CheckID = (int)cm.Parameters["@newCheckID"].Value; + _LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value; + } + MarkOld(); + // update child objects + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Check.SQLInsert", GetHashCode()); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Check.SQLInsert", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Check.SQLInsert", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + public static byte[] Add(SqlConnection cn, ref int checkID, Revision myRevision, Stage myStage, string consistencyChecks, DateTime dts, string userID) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Check.Add", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "addCheck"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@RevisionID", myRevision.RevisionID); + cm.Parameters.AddWithValue("@StageID", myStage.StageID); + cm.Parameters.AddWithValue("@ConsistencyChecks", consistencyChecks); + if (dts.Year >= 1753 && dts.Year <= 9999) cm.Parameters.AddWithValue("@DTS", dts); + cm.Parameters.AddWithValue("@UserID", userID); + // Output Calculated Columns + SqlParameter param_CheckID = new SqlParameter("@newCheckID", SqlDbType.Int); + param_CheckID.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_CheckID); + 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 + checkID = (int)cm.Parameters["@newCheckID"].Value; + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Check.Add", ex); + throw new DbCslaException("Check.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}] Check.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("Check.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}] Check.SQLUpdate", GetHashCode()); + try + { + if (_MyRevision != null) _MyRevision.Update(); + if (_MyStage != null) _MyStage.Update(); + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + if (base.IsDirty) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "updateCheck"; + // All Fields including Calculated Fields + cm.Parameters.AddWithValue("@CheckID", _CheckID); + cm.Parameters.AddWithValue("@RevisionID", RevisionID); + cm.Parameters.AddWithValue("@StageID", StageID); + cm.Parameters.AddWithValue("@ConsistencyChecks", _ConsistencyChecks); + 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 + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Check.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 = Check.Add(cn, ref _CheckID, _MyRevision, _MyStage, _ConsistencyChecks, _DTS, _UserID); + else + _LastChanged = Check.Update(cn, ref _CheckID, _RevisionID, _StageID, _ConsistencyChecks, _DTS, _UserID, ref _LastChanged); + MarkOld(); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + public static byte[] Update(SqlConnection cn, ref int checkID, int revisionID, int stageID, string consistencyChecks, DateTime dts, string userID, ref byte[] lastChanged) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Check.Update", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "updateCheck"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@CheckID", checkID); + cm.Parameters.AddWithValue("@RevisionID", revisionID); + cm.Parameters.AddWithValue("@StageID", stageID); + cm.Parameters.AddWithValue("@ConsistencyChecks", consistencyChecks); + 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("Check.Update", ex); + throw new DbCslaException("Check.Update", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_DeleteSelf() + { + DataPortal_Delete(new PKCriteria(_CheckID)); + } + [Transactional(TransactionalTypes.TransactionScope)] + private void DataPortal_Delete(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Check.DataPortal_Delete", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "deleteCheck"; + cm.Parameters.AddWithValue("@CheckID", criteria.CheckID); + cm.ExecuteNonQuery(); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Check.DataPortal_Delete", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Check.DataPortal_Delete", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + public static void Remove(SqlConnection cn, int checkID) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Check.Remove", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "deleteCheck"; + // Input PK Fields + cm.Parameters.AddWithValue("@CheckID", checkID); + // CSLATODO: Define any additional output parameters + cm.ExecuteNonQuery(); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Check.Remove", ex); + throw new DbCslaException("Check.Remove", ex); + } + } + #endregion + #region Exists + public static bool Exists(int checkID) + { + ExistsCommand result; + try + { + result = DataPortal.Execute(new ExistsCommand(checkID)); + return result.Exists; + } + catch (Exception ex) + { + throw new DbCslaException("Error on Check.Exists", ex); + } + } + [Serializable()] + private class ExistsCommand : CommandBase + { + private int _CheckID; + private bool _exists; + public bool Exists + { + get { return _exists; } + } + public ExistsCommand(int checkID) + { + _CheckID = checkID; + } + protected override void DataPortal_Execute() + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Check.DataPortal_Execute", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + cn.Open(); + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "existsCheck"; + cm.Parameters.AddWithValue("@CheckID", _CheckID); + int count = (int)cm.ExecuteScalar(); + _exists = (count > 0); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Check.DataPortal_Execute", ex); + throw new DbCslaException("Check.DataPortal_Execute", ex); + } + } + } + #endregion + // Standard Default Code + #region extension + CheckExtension _CheckExtension = new CheckExtension(); + [Serializable()] + partial class CheckExtension : extensionBase + { + } + [Serializable()] + class extensionBase + { + // Default Values + public virtual DateTime DefaultDTS + { + get { return DateTime.Now; } + } + public virtual string DefaultUserID + { + get { return Environment.UserName.ToUpper(); } + } + // 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 CheckConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is Check) + { + // Return the ToString value + return ((Check)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion +} // Namespace + + +//// The following is a sample Extension File. You can use it to create CheckExt.cs +//using System; +//using System.Collections.Generic; +//using System.Text; +//using Csla; + +//namespace VEPROMS.CSLA.Library +//{ +// public partial class Check +// { +// partial class CheckExtension : extensionBase +// { +// // CSLATODO: Override automatic defaults +// 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, ""); +// } +// public new void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) +// { +// //rules.AllowInstanceRead(Dbid, ""); +// } +// 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 */); +// } +// } +// } +//} diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/CheckInfo.cs b/PROMS/VEPROMS.CSLA.Library/Generated/CheckInfo.cs new file mode 100644 index 00000000..83e18d58 --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/CheckInfo.cs @@ -0,0 +1,476 @@ +// ======================================================================== +// 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 CheckInfoEvent(object sender); + /// + /// CheckInfo Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(CheckInfoConverter))] + public partial class CheckInfo : ReadOnlyBase, IDisposable + { + public event CheckInfoEvent 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 _CacheList = new List(); + protected static void AddToCache(CheckInfo checkInfo) + { + if (!_CacheList.Contains(checkInfo)) _CacheList.Add(checkInfo); // In AddToCache + } + protected static void RemoveFromCache(CheckInfo checkInfo) + { + while (_CacheList.Contains(checkInfo)) _CacheList.Remove(checkInfo); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + while (_CacheList.Count > 0) // Move CheckInfo(s) from temporary _CacheList to _CacheByPrimaryKey + { + CheckInfo tmp = _CacheList[0]; // Get the first CheckInfo + string pKey = tmp.CheckID.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 CheckInfo + } + } + internal static void AddList(CheckInfoList lst) + { + foreach (CheckInfo item in lst) AddToCache(item); + } + protected static CheckInfo 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 Check _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 _RevisionID; + public int RevisionID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("RevisionID", true); + if (_MyRevision != null) _RevisionID = _MyRevision.RevisionID; + return _RevisionID; + } + } + private RevisionInfo _MyRevision; + public RevisionInfo MyRevision + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("MyRevision", true); + if (_MyRevision == null && _RevisionID != 0) _MyRevision = RevisionInfo.Get(_RevisionID); + return _MyRevision; + } + } + private int _StageID; + public int StageID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("StageID", true); + if (_MyStage != null) _StageID = _MyStage.StageID; + return _StageID; + } + } + private StageInfo _MyStage; + public StageInfo MyStage + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("MyStage", true); + if (_MyStage == null && _StageID != 0) _MyStage = StageInfo.Get(_StageID); + return _MyStage; + } + } + private string _ConsistencyChecks = string.Empty; + public string ConsistencyChecks + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("ConsistencyChecks", true); + return _ConsistencyChecks; + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("DTS", true); + return _DTS; + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("UserID", true); + return _UserID; + } + } + // CSLATODO: Replace base CheckInfo.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current CheckInfo + //public override string ToString() + //{ + // return base.ToString(); + //} + // CSLATODO: Check CheckInfo.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current CheckInfo + protected override object GetIdValue() + { + return MyCheckInfoUnique; // Absolutely Unique ID + } + #endregion + #region Factory Methods + private static int _CheckInfoUnique = 0; + private static int CheckInfoUnique + { get { return ++_CheckInfoUnique; } } + private int _MyCheckInfoUnique = CheckInfoUnique; + public int MyCheckInfoUnique // Absolutely Unique ID - Info + { get { return _MyCheckInfoUnique; } } + protected CheckInfo() + {/* require use of factory methods */ + AddToCache(this); + } + public void Dispose() + { + RemoveFromCache(this); + if (!_CacheByPrimaryKey.ContainsKey(CheckID.ToString())) return; + List listCheckInfo = _CacheByPrimaryKey[CheckID.ToString()]; // Get the list of items + while (listCheckInfo.Contains(this)) listCheckInfo.Remove(this); // Remove the item from the list + if (listCheckInfo.Count == 0) // If there are no items left in the list + _CacheByPrimaryKey.Remove(CheckID.ToString()); // remove the list + } + public virtual Check Get() + { + return _Editable = Check.Get(_CheckID); + } + public static void Refresh(Check tmp) + { + string key = tmp.CheckID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (CheckInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(Check tmp) + { + if (_RevisionID != tmp.RevisionID) + { + if (MyRevision != null) MyRevision.RefreshRevisionChecks(); // Update List for old value + _RevisionID = tmp.RevisionID; // Update the value + } + _MyRevision = null; // Reset list so that the next line gets a new list + if (MyRevision != null) MyRevision.RefreshRevisionChecks(); // Update List for new value + if (_StageID != tmp.StageID) + { + if (MyStage != null) MyStage.RefreshStageChecks(); // Update List for old value + _StageID = tmp.StageID; // Update the value + } + _MyStage = null; // Reset list so that the next line gets a new list + if (MyStage != null) MyStage.RefreshStageChecks(); // Update List for new value + _ConsistencyChecks = tmp.ConsistencyChecks; + _DTS = tmp.DTS; + _UserID = tmp.UserID; + _CheckInfoExtension.Refresh(this); +//RHM Removed 20090724 - Duplicates function of code above. +// - Dispose caused error when a new step was added. +// - Resequence of transitions did not work properly. +// if(_MyRevision != null) +// { +// _MyRevision.Dispose();// Dispose related value +// _MyRevision = null;// Reset related value +// } +//RHM Removed 20090724 - Duplicates function of code above. +// - Dispose caused error when a new step was added. +// - Resequence of transitions did not work properly. +// if(_MyStage != null) +// { +// _MyStage.Dispose();// Dispose related value +// _MyStage = null;// Reset related value +// } + OnChange();// raise an event + } + public static void Refresh(RevisionCheck tmp) + { + string key = tmp.CheckID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (CheckInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(RevisionCheck tmp) + { + if (_StageID != tmp.StageID) + { + if (MyStage != null) MyStage.RefreshStageChecks(); // Update List for old value + _StageID = tmp.StageID; // Update the value + } + _MyStage = null; // Reset list so that the next line gets a new list + if (MyStage != null) MyStage.RefreshStageChecks(); // Update List for new value + _ConsistencyChecks = tmp.ConsistencyChecks; + _DTS = tmp.DTS; + _UserID = tmp.UserID; + _CheckInfoExtension.Refresh(this); +//RHM Removed 20090724 - Duplicates function of code above. +// - Dispose caused error when a new step was added. +// - Resequence of transitions did not work properly. +// if(_MyRevision != null) +// { +// _MyRevision.Dispose();// Dispose related value +// _MyRevision = null;// Reset related value +// } +//RHM Removed 20090724 - Duplicates function of code above. +// - Dispose caused error when a new step was added. +// - Resequence of transitions did not work properly. +// if(_MyStage != null) +// { +// _MyStage.Dispose();// Dispose related value +// _MyStage = null;// Reset related value +// } + OnChange();// raise an event + } + public static void Refresh(StageCheck tmp) + { + string key = tmp.CheckID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (CheckInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(StageCheck tmp) + { + if (_RevisionID != tmp.RevisionID) + { + if (MyRevision != null) MyRevision.RefreshRevisionChecks(); // Update List for old value + _RevisionID = tmp.RevisionID; // Update the value + } + _MyRevision = null; // Reset list so that the next line gets a new list + if (MyRevision != null) MyRevision.RefreshRevisionChecks(); // Update List for new value + _ConsistencyChecks = tmp.ConsistencyChecks; + _DTS = tmp.DTS; + _UserID = tmp.UserID; + _CheckInfoExtension.Refresh(this); +//RHM Removed 20090724 - Duplicates function of code above. +// - Dispose caused error when a new step was added. +// - Resequence of transitions did not work properly. +// if(_MyRevision != null) +// { +// _MyRevision.Dispose();// Dispose related value +// _MyRevision = null;// Reset related value +// } +//RHM Removed 20090724 - Duplicates function of code above. +// - Dispose caused error when a new step was added. +// - Resequence of transitions did not work properly. +// if(_MyStage != null) +// { +// _MyStage.Dispose();// Dispose related value +// _MyStage = null;// Reset related value +// } + OnChange();// raise an event + } + public static CheckInfo Get(int checkID) + { + //if (!CanGetObject()) + // throw new System.Security.SecurityException("User not authorized to view a Check"); + try + { + CheckInfo tmp = GetCachedByPrimaryKey(checkID); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(checkID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up CheckInfo + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on CheckInfo.Get", ex); + } + } + #endregion + #region Data Access Portal + internal CheckInfo(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] CheckInfo.Constructor", GetHashCode()); + try + { + ReadData(dr); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("CheckInfo.Constructor", ex); + throw new DbCslaException("CheckInfo.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}] CheckInfo.ReadData", GetHashCode()); + try + { + _CheckID = dr.GetInt32("CheckID"); + _RevisionID = dr.GetInt32("RevisionID"); + _StageID = dr.GetInt32("StageID"); + _ConsistencyChecks = dr.GetString("ConsistencyChecks"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("CheckInfo.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("CheckInfo.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] CheckInfo.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 = "getCheck"; + 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("CheckInfo.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("CheckInfo.DataPortal_Fetch", ex); + } + } + #endregion + // Standard Refresh + #region extension + CheckInfoExtension _CheckInfoExtension = new CheckInfoExtension(); + [Serializable()] + partial class CheckInfoExtension : extensionBase { } + [Serializable()] + class extensionBase + { + // Default Refresh + public virtual void Refresh(CheckInfo tmp) { } + } + #endregion + } // Class + #region Converter + internal class CheckInfoConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is CheckInfo) + { + // Return the ToString value + return ((CheckInfo)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion +} // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/CheckInfoList.cs b/PROMS/VEPROMS.CSLA.Library/Generated/CheckInfoList.cs new file mode 100644 index 00000000..3f3616cb --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/CheckInfoList.cs @@ -0,0 +1,319 @@ +// ======================================================================== +// 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 +{ + /// + /// CheckInfoList Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(CheckInfoListConverter))] + public partial class CheckInfoList : ReadOnlyListBase, ICustomTypeDescriptor, IDisposable + { + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Business Methods + internal new IList Items + { get { return base.Items; } } + public void AddEvents() + { + foreach (CheckInfo tmp in this) + { + tmp.Changed += new CheckInfoEvent(tmp_Changed); + } + } + void tmp_Changed(object sender) + { + for (int i = 0; i < Count; i++) + { + if (base[i] == sender) + this.OnListChanged(new ListChangedEventArgs(ListChangedType.ItemChanged, i)); + } + } + public void Dispose() + { + foreach (CheckInfo tmp in this) + { + tmp.Changed -= new CheckInfoEvent(tmp_Changed); + } + } + #endregion + #region Factory Methods + public static CheckInfoList _CheckInfoList = null; + /// + /// Return a list of all CheckInfo. + /// + public static CheckInfoList Get() + { + try + { + if (_CheckInfoList != null) + return _CheckInfoList; + CheckInfoList tmp = DataPortal.Fetch(); + CheckInfo.AddList(tmp); + tmp.AddEvents(); + _CheckInfoList = tmp; + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on CheckInfoList.Get", ex); + } + } + /// + /// Reset the list of all CheckInfo. + /// + public static void Reset() + { + _CheckInfoList = null; + } + // CSLATODO: Add alternative gets - + //public static CheckInfoList Get() + //{ + // try + // { + // return DataPortal.Fetch(new FilteredCriteria()); + // } + // catch (Exception ex) + // { + // throw new DbCslaException("Error on CheckInfoList.Get", ex); + // } + //} + public static CheckInfoList GetByRevisionID(int revisionID) + { + try + { + CheckInfoList tmp = DataPortal.Fetch(new RevisionIDCriteria(revisionID)); + CheckInfo.AddList(tmp); + tmp.AddEvents(); + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on CheckInfoList.GetByRevisionID", ex); + } + } + public static CheckInfoList GetByStageID(int stageID) + { + try + { + CheckInfoList tmp = DataPortal.Fetch(new StageIDCriteria(stageID)); + CheckInfo.AddList(tmp); + tmp.AddEvents(); + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on CheckInfoList.GetByStageID", ex); + } + } + private CheckInfoList() + { /* require use of factory methods */ } + #endregion + #region Data Access Portal + private void DataPortal_Fetch() + { + this.RaiseListChangedEvents = false; + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] CheckInfoList.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getChecks"; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + IsReadOnly = false; + while (dr.Read()) this.Add(new CheckInfo(dr)); + IsReadOnly = true; + } + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("CheckInfoList.DataPortal_Fetch", ex); + throw new DbCslaException("CheckInfoList.DataPortal_Fetch", ex); + } + this.RaiseListChangedEvents = true; + } + [Serializable()] + private class RevisionIDCriteria + { + public RevisionIDCriteria(int revisionID) + { + _RevisionID = revisionID; + } + private int _RevisionID; + public int RevisionID + { + get { return _RevisionID; } + set { _RevisionID = value; } + } + } + private void DataPortal_Fetch(RevisionIDCriteria criteria) + { + this.RaiseListChangedEvents = false; + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] CheckInfoList.DataPortal_FetchRevisionID", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getChecksByRevisionID"; + cm.Parameters.AddWithValue("@RevisionID", criteria.RevisionID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + IsReadOnly = false; + while (dr.Read()) this.Add(new CheckInfo(dr)); + IsReadOnly = true; + } + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("CheckInfoList.DataPortal_FetchRevisionID", ex); + throw new DbCslaException("CheckInfoList.DataPortal_Fetch", ex); + } + this.RaiseListChangedEvents = true; + } + [Serializable()] + private class StageIDCriteria + { + public StageIDCriteria(int stageID) + { + _StageID = stageID; + } + private int _StageID; + public int StageID + { + get { return _StageID; } + set { _StageID = value; } + } + } + private void DataPortal_Fetch(StageIDCriteria criteria) + { + this.RaiseListChangedEvents = false; + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] CheckInfoList.DataPortal_FetchStageID", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getChecksByStageID"; + cm.Parameters.AddWithValue("@StageID", criteria.StageID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + IsReadOnly = false; + while (dr.Read()) this.Add(new CheckInfo(dr)); + IsReadOnly = true; + } + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("CheckInfoList.DataPortal_FetchStageID", ex); + throw new DbCslaException("CheckInfoList.DataPortal_Fetch", ex); + } + this.RaiseListChangedEvents = true; + } + #endregion + #region ICustomTypeDescriptor impl + public String GetClassName() + { return TypeDescriptor.GetClassName(this, true); } + public AttributeCollection GetAttributes() + { return TypeDescriptor.GetAttributes(this, true); } + public String GetComponentName() + { return TypeDescriptor.GetComponentName(this, true); } + public TypeConverter GetConverter() + { return TypeDescriptor.GetConverter(this, true); } + public EventDescriptor GetDefaultEvent() + { return TypeDescriptor.GetDefaultEvent(this, true); } + public PropertyDescriptor GetDefaultProperty() + { return TypeDescriptor.GetDefaultProperty(this, true); } + public object GetEditor(Type editorBaseType) + { return TypeDescriptor.GetEditor(this, editorBaseType, true); } + public EventDescriptorCollection GetEvents(Attribute[] attributes) + { return TypeDescriptor.GetEvents(this, attributes, true); } + public EventDescriptorCollection GetEvents() + { return TypeDescriptor.GetEvents(this, true); } + public object GetPropertyOwner(PropertyDescriptor pd) + { return this; } + /// + /// Called to get the properties of this type. Returns properties with certain + /// attributes. this restriction is not implemented here. + /// + /// + /// + public PropertyDescriptorCollection GetProperties(Attribute[] attributes) + { return GetProperties(); } + /// + /// Called to get the properties of this type. + /// + /// + public PropertyDescriptorCollection GetProperties() + { + // Create a collection object to hold property descriptors + PropertyDescriptorCollection pds = new PropertyDescriptorCollection(null); + // Iterate the list + for (int i = 0; i < this.Items.Count; i++) + { + // Create a property descriptor for the item and add to the property descriptor collection + CheckInfoListPropertyDescriptor pd = new CheckInfoListPropertyDescriptor(this, i); + pds.Add(pd); + } + // return the property descriptor collection + return pds; + } + #endregion + } // Class + #region Property Descriptor + /// + /// Summary description for CollectionPropertyDescriptor. + /// + public partial class CheckInfoListPropertyDescriptor : vlnListPropertyDescriptor + { + private CheckInfo Item { get { return (CheckInfo)_Item; } } + public CheckInfoListPropertyDescriptor(CheckInfoList collection, int index) : base(collection, index) { ;} + } + #endregion + #region Converter + internal class CheckInfoListConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is CheckInfoList) + { + // Return department and department role separated by comma. + return ((CheckInfoList)value).Items.Count.ToString() + " Checks"; + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion +} // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/ContentInfo.cs b/PROMS/VEPROMS.CSLA.Library/Generated/ContentInfo.cs index 3e1848b0..0cd2bdaf 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/ContentInfo.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/ContentInfo.cs @@ -37,10 +37,8 @@ namespace VEPROMS.CSLA.Library private void OnChange(ContentInfo contentInfo) { if (Changed != null) - { Changed(this); - OnInfoChanged(this); - } + OnInfoChanged(this); } private void OnChange() { diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/Database.cs b/PROMS/VEPROMS.CSLA.Library/Generated/Database.cs index e7e27ad0..38a3538e 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/Database.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/Database.cs @@ -107,7 +107,8 @@ namespace VEPROMS.CSLA.Library string tmp = constr.Replace("{MENU}", "master"); SqlConnection cn = new SqlConnection(tmp); cn.Open(); - SqlDataAdapter da = new SqlDataAdapter("select name from sysdatabases where name like 'VEP%' order by name", cn); +// SqlDataAdapter da = new SqlDataAdapter("select name from sysdatabases where name like 'VEP%' order by name", cn); + SqlDataAdapter da = new SqlDataAdapter("select name,case when object_id(name + '..Revisions') is not null then 'Approval' when object_id(name + '..ContentAudits') is not null then 'Change Manager' else 'Original' end functionality from sysdatabases where name like 'VEP%' order by name", cn); DataSet ds = new DataSet(); da.Fill(ds); cn.Close(); @@ -119,7 +120,8 @@ namespace VEPROMS.CSLA.Library tsmi.Font = new System.Drawing.Font(tsmi.Font, System.Drawing.FontStyle.Bold); foreach (DataRow dr in ds.Tables[0].Rows) { - cms.Items.Add(dr["name"].ToString(), null, new EventHandler(Database_Click)); + if(dr["functionality"].ToString() == "Approval") + cms.Items.Add(dr["name"].ToString(), null, new EventHandler(Database_Click)); } while (_SelectedDatabase == null) { diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/Revision.cs b/PROMS/VEPROMS.CSLA.Library/Generated/Revision.cs new file mode 100644 index 00000000..29ed093d --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/Revision.cs @@ -0,0 +1,1272 @@ +// ======================================================================== +// 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 +{ + /// + /// Revision Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(RevisionConverter))] + public partial class Revision : BusinessBase, IDisposable, IVEHasBrokenRules + { + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Refresh + private List _RefreshRevisions = new List(); + private List _RefreshRevisionChecks = new List(); + private List _RefreshRevisionVersions = new List(); + private void AddToRefreshList(List refreshRevisions, List refreshRevisionChecks, List 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 BuildRefreshList() + { + _RefreshRevisions = new List(); + _RefreshRevisionChecks = new List(); + _RefreshRevisionVersions = new List(); + 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); + } + } + #endregion + #region Collection + private static List _CacheList = new List(); + 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> _CacheByPrimaryKey = new Dictionary>(); + 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(); // 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; + /// + /// Count of RevisionChecks for this Revision + /// + public int RevisionCheckCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("RevisionCheckCount", true); + return _RevisionCheckCount; + } + } + private RevisionChecks _RevisionChecks = null; + /// + /// Related Field + /// + [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; + /// + /// Count of RevisionVersions for this Revision + /// + public int RevisionVersionCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("RevisionVersionCount", true); + return _RevisionVersionCount; + } + } + private RevisionVersions _RevisionVersions = null; + /// + /// Related Field + /// + [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()); + } + } + public bool IsDirtyList(List 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()); } + } + public bool IsValidList(List 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 + /// + /// Overrides Base ToString + /// + /// A string representation of current Revision + //public override string ToString() + //{ + // return base.ToString(); + //} + // CSLATODO: Check Revision.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current Revision + 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, ""); + //AuthorizationRules.AllowRead(ItemID, ""); + //AuthorizationRules.AllowRead(TypeID, ""); + //AuthorizationRules.AllowRead(RevisionNumber, ""); + //AuthorizationRules.AllowRead(RevisionDate, ""); + //AuthorizationRules.AllowRead(Notes, ""); + //AuthorizationRules.AllowRead(Config, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowRead(UserID, ""); + //AuthorizationRules.AllowWrite(ItemID, ""); + //AuthorizationRules.AllowWrite(TypeID, ""); + //AuthorizationRules.AllowWrite(RevisionNumber, ""); + //AuthorizationRules.AllowWrite(RevisionDate, ""); + //AuthorizationRules.AllowWrite(Notes, ""); + //AuthorizationRules.AllowWrite(Config, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowWrite(UserID, ""); + _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; + } + /// + /// determines if related records (Foreign Keys) will keep this Item from being deleted + /// + 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); + } + public void Dispose() + { + RemoveFromDictionaries(); + } + private void RemoveFromDictionaries() + { + RemoveFromCache(this); + if (_CacheByPrimaryKey.ContainsKey(RevisionID.ToString())) + { + List 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(); + } + 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) + { + Revision tmp2 = tmp; + tmp = tmp2.Save(); + tmp2.Dispose(); + } + 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) + { + Revision tmp2 = tmp; + tmp = tmp2.Save(); + tmp2.Dispose(); + } + 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(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); + 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(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 Environment.UserName.ToUpper(); } + } + // 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, ""); +// } +// public new void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) +// { +// //rules.AllowInstanceRead(Dbid, ""); +// } +// 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 */); +// } +// } +// } +//} diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/RevisionCheck.cs b/PROMS/VEPROMS.CSLA.Library/Generated/RevisionCheck.cs new file mode 100644 index 00000000..86255a52 --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/RevisionCheck.cs @@ -0,0 +1,554 @@ +// ======================================================================== +// 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 +{ + /// + /// RevisionCheck Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(RevisionCheckConverter))] + public partial class RevisionCheck : BusinessBase, IVEHasBrokenRules + { + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _ErrorMessage; } + } + private int _CheckID; + [System.ComponentModel.DataObjectField(true, true)] + public int CheckID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("CheckID", true); + if (_MyCheck != null) _CheckID = _MyCheck.CheckID; + return _CheckID; + } + } + private Check _MyCheck; + [System.ComponentModel.DataObjectField(true, true)] + public Check MyCheck + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("MyCheck", true); + if (_MyCheck == null && _CheckID != 0) _MyCheck = Check.Get(_CheckID); + return _MyCheck; + } + } + private int _StageID; + public int StageID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("StageID", true); + if (_MyStage != null) _StageID = _MyStage.StageID; + return _StageID; + } + } + private Stage _MyStage; + public Stage MyStage + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("MyStage", true); + if (_MyStage == null && _StageID != 0) _MyStage = Stage.Get(_StageID); + return _MyStage; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + CanWriteProperty("MyStage", true); + if (_MyStage != value) + { + _MyStage = value; + _StageID = value.StageID;// Update underlying data field + PropertyHasChanged(); + } + } + } + private string _ConsistencyChecks = string.Empty; + public string ConsistencyChecks + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("ConsistencyChecks", true); + return _ConsistencyChecks; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + CanWriteProperty("ConsistencyChecks", true); + if (value == null) value = string.Empty; + if (_ConsistencyChecks != value) + { + _ConsistencyChecks = 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 string _Stage_Name = string.Empty; + public string Stage_Name + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("Stage_Name", true); + return _Stage_Name; + } + } + private string _Stage_Description = string.Empty; + public string Stage_Description + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("Stage_Description", true); + return _Stage_Description; + } + } + private int _Stage_IsApproved; + public int Stage_IsApproved + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("Stage_IsApproved", true); + return _Stage_IsApproved; + } + } + private DateTime _Stage_DTS = new DateTime(); + public DateTime Stage_DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("Stage_DTS", true); + return _Stage_DTS; + } + } + private string _Stage_UserID = string.Empty; + public string Stage_UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("Stage_UserID", true); + return _Stage_UserID; + } + } + // CSLATODO: Check RevisionCheck.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current RevisionCheck + protected override object GetIdValue() + { + return MyRevisionCheckUnique; // Absolutely Unique ID + } + // CSLATODO: Replace base RevisionCheck.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current RevisionCheck + //public override string ToString() + //{ + // return base.ToString(); + //} + public override bool IsDirty + { + get + { + if ( base.IsDirty ) + return true; + return IsDirtyList(new List()); + } + } + public bool IsDirtyList(List list) + { + if (base.IsDirty || list.Contains(this)) + return base.IsDirty; + list.Add(this); + return base.IsDirty || (_MyStage == null ? false : _MyStage.IsDirtyList(list)); + } + public override bool IsValid + { + get { return IsValidList(new List()); } + } + public bool IsValidList(List list) + { + if(list.Contains(this)) + return (IsNew && !IsDirty) ? true : base.IsValid; + list.Add(this); + return ((IsNew && !IsDirty) ? true : base.IsValid) && (_MyStage == null ? true : _MyStage.IsValidList(list)); + } + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if (BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + if (_MyStage != null && (hasBrokenRules = _MyStage.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(MyStageRequired, "MyStage"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("ConsistencyChecks", 1073741823)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UserID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); + // CSLATODO: Add other validation rules + } + private static bool MyStageRequired(RevisionCheck target, Csla.Validation.RuleArgs e) + { + if (target._StageID == 0 && target._MyStage == null) // Required field missing + { + e.Description = "Required"; + return false; + } + return true; + } + // 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(CheckID, ""); + //AuthorizationRules.AllowRead(StageID, ""); + //AuthorizationRules.AllowWrite(StageID, ""); + //AuthorizationRules.AllowRead(ConsistencyChecks, ""); + //AuthorizationRules.AllowWrite(ConsistencyChecks, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowRead(UserID, ""); + //AuthorizationRules.AllowWrite(UserID, ""); + } + 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; + } + 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 _RevisionCheckUnique = 0; + private static int RevisionCheckUnique + { get { return ++_RevisionCheckUnique; } } + private int _MyRevisionCheckUnique = RevisionCheckUnique; + public int MyRevisionCheckUnique // Absolutely Unique ID - Editable FK + { get { return _MyRevisionCheckUnique; } } + internal static RevisionCheck New(Stage myStage) + { + return new RevisionCheck(myStage); + } + internal static RevisionCheck Get(SafeDataReader dr) + { + return new RevisionCheck(dr); + } + public RevisionCheck() + { + MarkAsChild(); + _CheckID = Check.NextCheckID; + _DTS = _RevisionCheckExtension.DefaultDTS; + _UserID = _RevisionCheckExtension.DefaultUserID; + ValidationRules.CheckRules(); + } + private RevisionCheck(Stage myStage) + { + MarkAsChild(); + // CSLATODO: Add any initialization & defaults + _CheckID = Check.NextCheckID; + _DTS = _RevisionCheckExtension.DefaultDTS; + _UserID = _RevisionCheckExtension.DefaultUserID; + _MyStage = myStage; + ValidationRules.CheckRules(); + } + internal RevisionCheck(SafeDataReader dr) + { + MarkAsChild(); + Fetch(dr); + } + #endregion + #region Data Access Portal + private void Fetch(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RevisionCheck.FetchDR", GetHashCode()); + try + { + _CheckID = dr.GetInt32("CheckID"); + _StageID = dr.GetInt32("StageID"); + _ConsistencyChecks = dr.GetString("ConsistencyChecks"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + _Stage_Name = dr.GetString("Stage_Name"); + _Stage_Description = dr.GetString("Stage_Description"); + _Stage_IsApproved = dr.GetInt32("Stage_IsApproved"); + _Stage_DTS = dr.GetDateTime("Stage_DTS"); + _Stage_UserID = dr.GetString("Stage_UserID"); + } + catch (Exception ex) // FKItem Fetch + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("RevisionCheck.FetchDR", ex); + throw new DbCslaException("RevisionCheck.Fetch", ex); + } + MarkOld(); + } + internal void Insert(Revision myRevision) + { + // if we're not dirty then don't update the database + if (!this.IsDirty) return; + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + _LastChanged = Check.Add(cn, ref _CheckID, myRevision, _MyStage, _ConsistencyChecks, _DTS, _UserID); + MarkOld(); + } + internal void Update(Revision myRevision) + { + // if we're not dirty then don't update the database + if (!this.IsDirty) return; + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + _LastChanged = Check.Update(cn, ref _CheckID, myRevision.RevisionID, _StageID, _ConsistencyChecks, _DTS, _UserID, ref _LastChanged); + MarkOld(); + } + internal void DeleteSelf(Revision myRevision) + { + // if we're not dirty then don't update the database + if (!this.IsDirty) return; + // if we're new then don't update the database + if (this.IsNew) return; + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + Check.Remove(cn, _CheckID); + MarkNew(); + } + #endregion + // Standard Default Code + #region extension + RevisionCheckExtension _RevisionCheckExtension = new RevisionCheckExtension(); + [Serializable()] + partial class RevisionCheckExtension : extensionBase + { + } + [Serializable()] + class extensionBase + { + // Default Values + public virtual DateTime DefaultDTS + { + get { return DateTime.Now; } + } + public virtual string DefaultUserID + { + get { return Environment.UserName.ToUpper(); } + } + // 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 RevisionCheckConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is RevisionCheck) + { + // Return the ToString value + return ((RevisionCheck)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion +} // Namespace + + +//// The following is a sample Extension File. You can use it to create RevisionCheckExt.cs +//using System; +//using System.Collections.Generic; +//using System.Text; +//using Csla; + +//namespace VEPROMS.CSLA.Library +//{ +// public partial class RevisionCheck +// { +// partial class RevisionCheckExtension : extensionBase +// { +// // CSLATODO: Override automatic defaults +// 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, ""); +// } +// public new void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) +// { +// //rules.AllowInstanceRead(Dbid, ""); +// } +// 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 */); +// } +// } +// } +//} diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/RevisionChecks.cs b/PROMS/VEPROMS.CSLA.Library/Generated/RevisionChecks.cs new file mode 100644 index 00000000..4e9547cd --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/RevisionChecks.cs @@ -0,0 +1,322 @@ +// ======================================================================== +// 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 +{ + /// + /// RevisionChecks Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(RevisionChecksConverter))] + public partial class RevisionChecks : BusinessListBase, ICustomTypeDescriptor, IVEHasBrokenRules + { + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _ErrorMessage; } + } + // One To Many + public RevisionCheck this[Check myCheck] + { + get + { + foreach (RevisionCheck check in this) + if (check.CheckID == myCheck.CheckID) + return check; + return null; + } + } + public new System.Collections.Generic.IList Items + { + get { return base.Items; } + } + public RevisionCheck GetItem(Check myCheck) + { + foreach (RevisionCheck check in this) + if (check.CheckID == myCheck.CheckID) + return check; + return null; + } + public RevisionCheck Add(Stage myStage) // One to Many + { + RevisionCheck check = RevisionCheck.New(myStage); + this.Add(check); + return check; + } + public void Remove(Check myCheck) + { + foreach (RevisionCheck check in this) + { + if (check.CheckID == myCheck.CheckID) + { + Remove(check); + break; + } + } + } + public bool Contains(Check myCheck) + { + foreach (RevisionCheck check in this) + if (check.CheckID == myCheck.CheckID) + return true; + return false; + } + public bool ContainsDeleted(Check myCheck) + { + foreach (RevisionCheck check in DeletedList) + if (check.CheckID == myCheck.CheckID) + return true; + return false; + } + public bool IsDirtyList(List list) + { + // any non-new deletions make us dirty + foreach (RevisionCheck item in DeletedList) + if (!item.IsNew) + return true; + // run through all the child objects + // and if any are dirty then then + // collection is dirty + foreach (RevisionCheck child in this) + if (child.IsDirtyList(list)) + return true; + return false; + } + public override bool IsValid + { + get { return IsValidList(new List()); } + } + public bool IsValidList(List list) + { + // run through all the child objects + // and if any are invalid then the + // collection is invalid + foreach (RevisionCheck child in this) + if (!child.IsValidList(list)) + { + //Console.WriteLine("Valid {0} Child {1} - {2}", child.IsValid, child.GetType().Name,child.ToString()); + return false; + } + return true; + } + #endregion + #region ValidationRules + public IVEHasBrokenRules HasBrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = null; + foreach (RevisionCheck revisionCheck in this) + if ((hasBrokenRules = revisionCheck.HasBrokenRules) != null) return hasBrokenRules; + return hasBrokenRules; + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + #endregion + #region Factory Methods + internal static RevisionChecks New() + { + return new RevisionChecks(); + } + internal static RevisionChecks Get(SafeDataReader dr) + { + return new RevisionChecks(dr); + } + public static RevisionChecks GetByRevisionID(int revisionID) + { + try + { + return DataPortal.Fetch(new RevisionIDCriteria(revisionID)); + } + catch (Exception ex) + { + throw new DbCslaException("Error on RevisionChecks.GetByRevisionID", ex); + } + } + private RevisionChecks() + { + MarkAsChild(); + } + internal RevisionChecks(SafeDataReader dr) + { + MarkAsChild(); + Fetch(dr); + } + #endregion + #region Data Access Portal + // called to load data from the database + private void Fetch(SafeDataReader dr) + { + this.RaiseListChangedEvents = false; + while (dr.Read()) + this.Add(RevisionCheck.Get(dr)); + this.RaiseListChangedEvents = true; + } + [Serializable()] + private class RevisionIDCriteria + { + public RevisionIDCriteria(int revisionID) + { + _RevisionID = revisionID; + } + private int _RevisionID; + public int RevisionID + { + get { return _RevisionID; } + set { _RevisionID = value; } + } + } + private void DataPortal_Fetch(RevisionIDCriteria criteria) + { + this.RaiseListChangedEvents = false; + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RevisionChecks.DataPortal_FetchRevisionID", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getChecksByRevisionID"; + cm.Parameters.AddWithValue("@RevisionID", criteria.RevisionID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + while (dr.Read()) this.Add(new RevisionCheck(dr)); + } + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("RevisionChecks.DataPortal_FetchRevisionID", ex); + throw new DbCslaException("RevisionChecks.DataPortal_Fetch", ex); + } + this.RaiseListChangedEvents = true; + } + internal void Update(Revision revision) + { + this.RaiseListChangedEvents = false; + try + { + // update (thus deleting) any deleted child objects + foreach (RevisionCheck obj in DeletedList) + obj.DeleteSelf(revision);// Deletes related record + // now that they are deleted, remove them from memory too + DeletedList.Clear(); + // add/update any current child objects + foreach (RevisionCheck obj in this) + { + if (obj.IsNew) + obj.Insert(revision); + else + obj.Update(revision); + } + } + finally + { + this.RaiseListChangedEvents = true; + } + } + #endregion + #region ICustomTypeDescriptor impl + public String GetClassName() + { return TypeDescriptor.GetClassName(this, true); } + public AttributeCollection GetAttributes() + { return TypeDescriptor.GetAttributes(this, true); } + public String GetComponentName() + { return TypeDescriptor.GetComponentName(this, true); } + public TypeConverter GetConverter() + { return TypeDescriptor.GetConverter(this, true); } + public EventDescriptor GetDefaultEvent() + { return TypeDescriptor.GetDefaultEvent(this, true); } + public PropertyDescriptor GetDefaultProperty() + { return TypeDescriptor.GetDefaultProperty(this, true); } + public object GetEditor(Type editorBaseType) + { return TypeDescriptor.GetEditor(this, editorBaseType, true); } + public EventDescriptorCollection GetEvents(Attribute[] attributes) + { return TypeDescriptor.GetEvents(this, attributes, true); } + public EventDescriptorCollection GetEvents() + { return TypeDescriptor.GetEvents(this, true); } + public object GetPropertyOwner(PropertyDescriptor pd) + { return this; } + /// + /// Called to get the properties of this type. Returns properties with certain + /// attributes. this restriction is not implemented here. + /// + /// + /// + public PropertyDescriptorCollection GetProperties(Attribute[] attributes) + { return GetProperties(); } + /// + /// Called to get the properties of this type. + /// + /// + public PropertyDescriptorCollection GetProperties() + { + // Create a collection object to hold property descriptors + PropertyDescriptorCollection pds = new PropertyDescriptorCollection(null); + // Iterate the list + for (int i = 0; i < this.Items.Count; i++) + { + // Create a property descriptor for the item and add to the property descriptor collection + RevisionChecksPropertyDescriptor pd = new RevisionChecksPropertyDescriptor(this, i); + pds.Add(pd); + } + // return the property descriptor collection + return pds; + } + #endregion + } // Class + #region Property Descriptor + /// + /// Summary description for CollectionPropertyDescriptor. + /// + public partial class RevisionChecksPropertyDescriptor : vlnListPropertyDescriptor + { + private RevisionCheck Item { get { return (RevisionCheck)_Item; } } + public RevisionChecksPropertyDescriptor(RevisionChecks collection, int index) : base(collection, index) { ;} + } + #endregion + #region Converter + internal class RevisionChecksConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is RevisionChecks) + { + // Return department and department role separated by comma. + return ((RevisionChecks)value).Items.Count.ToString() + " Checks"; + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion +} // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/RevisionInfo.cs b/PROMS/VEPROMS.CSLA.Library/Generated/RevisionInfo.cs new file mode 100644 index 00000000..71fde3bb --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/RevisionInfo.cs @@ -0,0 +1,460 @@ +// ======================================================================== +// 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 RevisionInfoEvent(object sender); + /// + /// RevisionInfo Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(RevisionInfoConverter))] + public partial class RevisionInfo : ReadOnlyBase, IDisposable + { + public event RevisionInfoEvent 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 _CacheList = new List(); + protected static void AddToCache(RevisionInfo revisionInfo) + { + if (!_CacheList.Contains(revisionInfo)) _CacheList.Add(revisionInfo); // In AddToCache + } + protected static void RemoveFromCache(RevisionInfo revisionInfo) + { + while (_CacheList.Contains(revisionInfo)) _CacheList.Remove(revisionInfo); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + while (_CacheList.Count > 0) // Move RevisionInfo(s) from temporary _CacheList to _CacheByPrimaryKey + { + RevisionInfo tmp = _CacheList[0]; // Get the first RevisionInfo + string pKey = tmp.RevisionID.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 RevisionInfo + } + } + internal static void AddList(RevisionInfoList lst) + { + foreach (RevisionInfo item in lst) AddToCache(item); + } + protected static RevisionInfo 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; } + } + protected Revision _Editable; + private IVEHasBrokenRules HasBrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = null; + if (_Editable != null) + hasBrokenRules = _Editable.HasBrokenRules; + return hasBrokenRules; + } + } + 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; + } + } + private int _TypeID; + public int TypeID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("TypeID", true); + return _TypeID; + } + } + private string _RevisionNumber = string.Empty; + public string RevisionNumber + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("RevisionNumber", true); + return _RevisionNumber; + } + } + private DateTime? _RevisionDate; + public DateTime? RevisionDate + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("RevisionDate", true); + return _RevisionDate; + } + } + private string _Notes = string.Empty; + public string Notes + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("Notes", true); + return _Notes; + } + } + private string _Config = string.Empty; + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("Config", true); + return _Config; + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("DTS", true); + return _DTS; + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("UserID", true); + return _UserID; + } + } + private int _RevisionCheckCount = 0; + /// + /// Count of RevisionChecks for this Revision + /// + public int RevisionCheckCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("RevisionCheckCount", true); + if (_RevisionCheckCount < 0) + _RevisionCheckCount = RevisionChecks.Count; + return _RevisionCheckCount; + } + } + private CheckInfoList _RevisionChecks = null; + [TypeConverter(typeof(CheckInfoListConverter))] + public CheckInfoList RevisionChecks + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("RevisionChecks", true); + if (_RevisionCheckCount < 0 || (_RevisionCheckCount > 0 && _RevisionChecks == null)) + _RevisionChecks = CheckInfoList.GetByRevisionID(_RevisionID); + if (_RevisionCheckCount < 0) + _RevisionCheckCount = _RevisionChecks.Count; + return _RevisionChecks; + } + } + public void RefreshRevisionChecks() + { + _RevisionCheckCount = -1; + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(_RevisionID.ToString())) + foreach (RevisionInfo tmp in _CacheByPrimaryKey[_RevisionID.ToString()]) + tmp._RevisionCheckCount = -1; // This will cause the data to be requeried + } + private int _RevisionVersionCount = 0; + /// + /// Count of RevisionVersions for this Revision + /// + public int RevisionVersionCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("RevisionVersionCount", true); + if (_RevisionVersionCount < 0) + _RevisionVersionCount = RevisionVersions.Count; + return _RevisionVersionCount; + } + } + private VersionInfoList _RevisionVersions = null; + [TypeConverter(typeof(VersionInfoListConverter))] + public VersionInfoList RevisionVersions + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("RevisionVersions", true); + if (_RevisionVersionCount < 0 || (_RevisionVersionCount > 0 && _RevisionVersions == null)) + _RevisionVersions = VersionInfoList.GetByRevisionID(_RevisionID); + if (_RevisionVersionCount < 0) + _RevisionVersionCount = _RevisionVersions.Count; + return _RevisionVersions; + } + } + public void RefreshRevisionVersions() + { + _RevisionVersionCount = -1; + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(_RevisionID.ToString())) + foreach (RevisionInfo tmp in _CacheByPrimaryKey[_RevisionID.ToString()]) + tmp._RevisionVersionCount = -1; // This will cause the data to be requeried + } + // CSLATODO: Replace base RevisionInfo.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current RevisionInfo + //public override string ToString() + //{ + // return base.ToString(); + //} + // CSLATODO: Check RevisionInfo.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current RevisionInfo + protected override object GetIdValue() + { + return MyRevisionInfoUnique; // Absolutely Unique ID + } + #endregion + #region Factory Methods + private static int _RevisionInfoUnique = 0; + private static int RevisionInfoUnique + { get { return ++_RevisionInfoUnique; } } + private int _MyRevisionInfoUnique = RevisionInfoUnique; + public int MyRevisionInfoUnique // Absolutely Unique ID - Info + { get { return _MyRevisionInfoUnique; } } + protected RevisionInfo() + {/* require use of factory methods */ + AddToCache(this); + } + public void Dispose() + { + RemoveFromCache(this); + if (!_CacheByPrimaryKey.ContainsKey(RevisionID.ToString())) return; + List listRevisionInfo = _CacheByPrimaryKey[RevisionID.ToString()]; // Get the list of items + while (listRevisionInfo.Contains(this)) listRevisionInfo.Remove(this); // Remove the item from the list + if (listRevisionInfo.Count == 0) // If there are no items left in the list + _CacheByPrimaryKey.Remove(RevisionID.ToString()); // remove the list + } + public virtual Revision Get() + { + return _Editable = Revision.Get(_RevisionID); + } + public static void Refresh(Revision tmp) + { + string key = tmp.RevisionID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (RevisionInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(Revision tmp) + { + _ItemID = tmp.ItemID; + _TypeID = tmp.TypeID; + _RevisionNumber = tmp.RevisionNumber; + _RevisionDate = tmp.RevisionDate; + _Notes = tmp.Notes; + _Config = tmp.Config; + _DTS = tmp.DTS; + _UserID = tmp.UserID; + _RevisionInfoExtension.Refresh(this); + OnChange();// raise an event + } + public static RevisionInfo Get(int revisionID) + { + //if (!CanGetObject()) + // throw new System.Security.SecurityException("User not authorized to view a Revision"); + try + { + RevisionInfo tmp = GetCachedByPrimaryKey(revisionID); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(revisionID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up RevisionInfo + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on RevisionInfo.Get", ex); + } + } + #endregion + #region Data Access Portal + internal RevisionInfo(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RevisionInfo.Constructor", GetHashCode()); + try + { + ReadData(dr); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("RevisionInfo.Constructor", ex); + throw new DbCslaException("RevisionInfo.Constructor", ex); + } + } + [Serializable()] + protected class PKCriteria + { + private int _RevisionID; + public int RevisionID + { get { return _RevisionID; } } + public PKCriteria(int revisionID) + { + _RevisionID = revisionID; + } + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RevisionInfo.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"); + _RevisionCheckCount = dr.GetInt32("CheckCount"); + _RevisionVersionCount = dr.GetInt32("VersionCount"); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("RevisionInfo.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("RevisionInfo.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RevisionInfo.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); + 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("RevisionInfo.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("RevisionInfo.DataPortal_Fetch", ex); + } + } + #endregion + // Standard Refresh + #region extension + RevisionInfoExtension _RevisionInfoExtension = new RevisionInfoExtension(); + [Serializable()] + partial class RevisionInfoExtension : extensionBase { } + [Serializable()] + class extensionBase + { + // Default Refresh + public virtual void Refresh(RevisionInfo tmp) { } + } + #endregion + } // Class + #region Converter + internal class RevisionInfoConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is RevisionInfo) + { + // Return the ToString value + return ((RevisionInfo)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion +} // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/RevisionInfoList.cs b/PROMS/VEPROMS.CSLA.Library/Generated/RevisionInfoList.cs new file mode 100644 index 00000000..41b08e5e --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/RevisionInfoList.cs @@ -0,0 +1,205 @@ +// ======================================================================== +// 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 +{ + /// + /// RevisionInfoList Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(RevisionInfoListConverter))] + public partial class RevisionInfoList : ReadOnlyListBase, ICustomTypeDescriptor, IDisposable + { + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Business Methods + internal new IList Items + { get { return base.Items; } } + public void AddEvents() + { + foreach (RevisionInfo tmp in this) + { + tmp.Changed += new RevisionInfoEvent(tmp_Changed); + } + } + void tmp_Changed(object sender) + { + for (int i = 0; i < Count; i++) + { + if (base[i] == sender) + this.OnListChanged(new ListChangedEventArgs(ListChangedType.ItemChanged, i)); + } + } + public void Dispose() + { + foreach (RevisionInfo tmp in this) + { + tmp.Changed -= new RevisionInfoEvent(tmp_Changed); + } + } + #endregion + #region Factory Methods + public static RevisionInfoList _RevisionInfoList = null; + /// + /// Return a list of all RevisionInfo. + /// + public static RevisionInfoList Get() + { + try + { + if (_RevisionInfoList != null) + return _RevisionInfoList; + RevisionInfoList tmp = DataPortal.Fetch(); + RevisionInfo.AddList(tmp); + tmp.AddEvents(); + _RevisionInfoList = tmp; + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on RevisionInfoList.Get", ex); + } + } + /// + /// Reset the list of all RevisionInfo. + /// + public static void Reset() + { + _RevisionInfoList = null; + } + // CSLATODO: Add alternative gets - + //public static RevisionInfoList Get() + //{ + // try + // { + // return DataPortal.Fetch(new FilteredCriteria()); + // } + // catch (Exception ex) + // { + // throw new DbCslaException("Error on RevisionInfoList.Get", ex); + // } + //} + private RevisionInfoList() + { /* require use of factory methods */ } + #endregion + #region Data Access Portal + private void DataPortal_Fetch() + { + this.RaiseListChangedEvents = false; + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RevisionInfoList.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getRevisions"; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + IsReadOnly = false; + while (dr.Read()) this.Add(new RevisionInfo(dr)); + IsReadOnly = true; + } + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("RevisionInfoList.DataPortal_Fetch", ex); + throw new DbCslaException("RevisionInfoList.DataPortal_Fetch", ex); + } + this.RaiseListChangedEvents = true; + } + #endregion + #region ICustomTypeDescriptor impl + public String GetClassName() + { return TypeDescriptor.GetClassName(this, true); } + public AttributeCollection GetAttributes() + { return TypeDescriptor.GetAttributes(this, true); } + public String GetComponentName() + { return TypeDescriptor.GetComponentName(this, true); } + public TypeConverter GetConverter() + { return TypeDescriptor.GetConverter(this, true); } + public EventDescriptor GetDefaultEvent() + { return TypeDescriptor.GetDefaultEvent(this, true); } + public PropertyDescriptor GetDefaultProperty() + { return TypeDescriptor.GetDefaultProperty(this, true); } + public object GetEditor(Type editorBaseType) + { return TypeDescriptor.GetEditor(this, editorBaseType, true); } + public EventDescriptorCollection GetEvents(Attribute[] attributes) + { return TypeDescriptor.GetEvents(this, attributes, true); } + public EventDescriptorCollection GetEvents() + { return TypeDescriptor.GetEvents(this, true); } + public object GetPropertyOwner(PropertyDescriptor pd) + { return this; } + /// + /// Called to get the properties of this type. Returns properties with certain + /// attributes. this restriction is not implemented here. + /// + /// + /// + public PropertyDescriptorCollection GetProperties(Attribute[] attributes) + { return GetProperties(); } + /// + /// Called to get the properties of this type. + /// + /// + public PropertyDescriptorCollection GetProperties() + { + // Create a collection object to hold property descriptors + PropertyDescriptorCollection pds = new PropertyDescriptorCollection(null); + // Iterate the list + for (int i = 0; i < this.Items.Count; i++) + { + // Create a property descriptor for the item and add to the property descriptor collection + RevisionInfoListPropertyDescriptor pd = new RevisionInfoListPropertyDescriptor(this, i); + pds.Add(pd); + } + // return the property descriptor collection + return pds; + } + #endregion + } // Class + #region Property Descriptor + /// + /// Summary description for CollectionPropertyDescriptor. + /// + public partial class RevisionInfoListPropertyDescriptor : vlnListPropertyDescriptor + { + private RevisionInfo Item { get { return (RevisionInfo)_Item; } } + public RevisionInfoListPropertyDescriptor(RevisionInfoList collection, int index) : base(collection, index) { ;} + } + #endregion + #region Converter + internal class RevisionInfoListConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is RevisionInfoList) + { + // Return department and department role separated by comma. + return ((RevisionInfoList)value).Items.Count.ToString() + " Revisions"; + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion +} // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/RevisionVersion.cs b/PROMS/VEPROMS.CSLA.Library/Generated/RevisionVersion.cs new file mode 100644 index 00000000..fdfc0c81 --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/RevisionVersion.cs @@ -0,0 +1,557 @@ +// ======================================================================== +// 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 +{ + /// + /// RevisionVersion Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(RevisionVersionConverter))] + public partial class RevisionVersion : BusinessBase, IVEHasBrokenRules + { + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _ErrorMessage; } + } + private int _VersionID; + [System.ComponentModel.DataObjectField(true, true)] + public int VersionID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("VersionID", true); + if (_MyVersion != null) _VersionID = _MyVersion.VersionID; + return _VersionID; + } + } + private Version _MyVersion; + [System.ComponentModel.DataObjectField(true, true)] + public Version MyVersion + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("MyVersion", true); + if (_MyVersion == null && _VersionID != 0) _MyVersion = Version.Get(_VersionID); + return _MyVersion; + } + } + private int _StageID; + public int StageID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("StageID", true); + if (_MyStage != null) _StageID = _MyStage.StageID; + return _StageID; + } + } + private Stage _MyStage; + public Stage MyStage + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("MyStage", true); + if (_MyStage == null && _StageID != 0) _MyStage = Stage.Get(_StageID); + return _MyStage; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + CanWriteProperty("MyStage", true); + if (_MyStage != value) + { + _MyStage = value; + _StageID = value.StageID;// Update underlying data field + PropertyHasChanged(); + } + } + } + private byte[] _PDF; + public byte[] PDF + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("PDF", true); + return _PDF; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + CanWriteProperty("PDF", true); + if (_PDF != value) + { + _PDF = value; + PropertyHasChanged(); + } + } + } + private byte[] _SummaryPDF; + public byte[] SummaryPDF + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("SummaryPDF", true); + return _SummaryPDF; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + CanWriteProperty("SummaryPDF", true); + if (_SummaryPDF != value) + { + _SummaryPDF = 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 string _Stage_Name = string.Empty; + public string Stage_Name + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("Stage_Name", true); + return _Stage_Name; + } + } + private string _Stage_Description = string.Empty; + public string Stage_Description + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("Stage_Description", true); + return _Stage_Description; + } + } + private int _Stage_IsApproved; + public int Stage_IsApproved + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("Stage_IsApproved", true); + return _Stage_IsApproved; + } + } + private DateTime _Stage_DTS = new DateTime(); + public DateTime Stage_DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("Stage_DTS", true); + return _Stage_DTS; + } + } + private string _Stage_UserID = string.Empty; + public string Stage_UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("Stage_UserID", true); + return _Stage_UserID; + } + } + // CSLATODO: Check RevisionVersion.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current RevisionVersion + protected override object GetIdValue() + { + return MyRevisionVersionUnique; // Absolutely Unique ID + } + // CSLATODO: Replace base RevisionVersion.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current RevisionVersion + //public override string ToString() + //{ + // return base.ToString(); + //} + public override bool IsDirty + { + get + { + if ( base.IsDirty ) + return true; + return IsDirtyList(new List()); + } + } + public bool IsDirtyList(List list) + { + if (base.IsDirty || list.Contains(this)) + return base.IsDirty; + list.Add(this); + return base.IsDirty || (_MyStage == null ? false : _MyStage.IsDirtyList(list)); + } + public override bool IsValid + { + get { return IsValidList(new List()); } + } + public bool IsValidList(List list) + { + if(list.Contains(this)) + return (IsNew && !IsDirty) ? true : base.IsValid; + list.Add(this); + return ((IsNew && !IsDirty) ? true : base.IsValid) && (_MyStage == null ? true : _MyStage.IsValidList(list)); + } + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if (BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + if (_MyStage != null && (hasBrokenRules = _MyStage.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(MyStageRequired, "MyStage"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UserID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 200)); + // CSLATODO: Add other validation rules + } + private static bool MyStageRequired(RevisionVersion target, Csla.Validation.RuleArgs e) + { + if (target._StageID == 0 && target._MyStage == null) // Required field missing + { + e.Description = "Required"; + return false; + } + return true; + } + // 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(VersionID, ""); + //AuthorizationRules.AllowRead(StageID, ""); + //AuthorizationRules.AllowWrite(StageID, ""); + //AuthorizationRules.AllowRead(PDF, ""); + //AuthorizationRules.AllowWrite(PDF, ""); + //AuthorizationRules.AllowRead(SummaryPDF, ""); + //AuthorizationRules.AllowWrite(SummaryPDF, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowRead(UserID, ""); + //AuthorizationRules.AllowWrite(UserID, ""); + } + 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; + } + 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 _RevisionVersionUnique = 0; + private static int RevisionVersionUnique + { get { return ++_RevisionVersionUnique; } } + private int _MyRevisionVersionUnique = RevisionVersionUnique; + public int MyRevisionVersionUnique // Absolutely Unique ID - Editable FK + { get { return _MyRevisionVersionUnique; } } + internal static RevisionVersion New(Stage myStage, DateTime dts, string userID) + { + return new RevisionVersion(myStage, dts, userID); + } + internal static RevisionVersion Get(SafeDataReader dr) + { + return new RevisionVersion(dr); + } + public RevisionVersion() + { + MarkAsChild(); + _VersionID = Version.NextVersionID; + + ValidationRules.CheckRules(); + } + private RevisionVersion(Stage myStage, DateTime dts, string userID) + { + MarkAsChild(); + // CSLATODO: Add any initialization & defaults + _VersionID = Version.NextVersionID; + + _MyStage = myStage; + _DTS = dts; + _UserID = userID; + ValidationRules.CheckRules(); + } + internal RevisionVersion(SafeDataReader dr) + { + MarkAsChild(); + Fetch(dr); + } + #endregion + #region Data Access Portal + private void Fetch(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RevisionVersion.FetchDR", GetHashCode()); + try + { + _VersionID = dr.GetInt32("VersionID"); + _StageID = dr.GetInt32("StageID"); + _PDF = (byte[])dr.GetValue("PDF"); + _SummaryPDF = (byte[])dr.GetValue("SummaryPDF"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + _Stage_Name = dr.GetString("Stage_Name"); + _Stage_Description = dr.GetString("Stage_Description"); + _Stage_IsApproved = dr.GetInt32("Stage_IsApproved"); + _Stage_DTS = dr.GetDateTime("Stage_DTS"); + _Stage_UserID = dr.GetString("Stage_UserID"); + } + catch (Exception ex) // FKItem Fetch + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("RevisionVersion.FetchDR", ex); + throw new DbCslaException("RevisionVersion.Fetch", ex); + } + MarkOld(); + } + internal void Insert(Revision myRevision) + { + // if we're not dirty then don't update the database + if (!this.IsDirty) return; + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + _LastChanged = Version.Add(cn, ref _VersionID, myRevision, _MyStage, _PDF, _SummaryPDF, _DTS, _UserID); + MarkOld(); + } + internal void Update(Revision myRevision) + { + // if we're not dirty then don't update the database + if (!this.IsDirty) return; + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + _LastChanged = Version.Update(cn, ref _VersionID, myRevision.RevisionID, _StageID, _PDF, _SummaryPDF, _DTS, _UserID, ref _LastChanged); + MarkOld(); + } + internal void DeleteSelf(Revision myRevision) + { + // if we're not dirty then don't update the database + if (!this.IsDirty) return; + // if we're new then don't update the database + if (this.IsNew) return; + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + Version.Remove(cn, _VersionID); + MarkNew(); + } + #endregion + // Standard Default Code + #region extension + RevisionVersionExtension _RevisionVersionExtension = new RevisionVersionExtension(); + [Serializable()] + partial class RevisionVersionExtension : extensionBase + { + } + [Serializable()] + class extensionBase + { + // Default Values + // 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 RevisionVersionConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is RevisionVersion) + { + // Return the ToString value + return ((RevisionVersion)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion +} // Namespace + + +//// The following is a sample Extension File. You can use it to create RevisionVersionExt.cs +//using System; +//using System.Collections.Generic; +//using System.Text; +//using Csla; + +//namespace VEPROMS.CSLA.Library +//{ +// public partial class RevisionVersion +// { +// partial class RevisionVersionExtension : extensionBase +// { +// // CSLATODO: Override automatic defaults +// public new void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) +// { +// //rules.AllowRead(Dbid, ""); +// } +// public new void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) +// { +// //rules.AllowInstanceRead(Dbid, ""); +// } +// 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 */); +// } +// } +// } +//} diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/RevisionVersions.cs b/PROMS/VEPROMS.CSLA.Library/Generated/RevisionVersions.cs new file mode 100644 index 00000000..164ee026 --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/RevisionVersions.cs @@ -0,0 +1,322 @@ +// ======================================================================== +// 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 +{ + /// + /// RevisionVersions Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(RevisionVersionsConverter))] + public partial class RevisionVersions : BusinessListBase, ICustomTypeDescriptor, IVEHasBrokenRules + { + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _ErrorMessage; } + } + // One To Many + public RevisionVersion this[Version myVersion] + { + get + { + foreach (RevisionVersion version in this) + if (version.VersionID == myVersion.VersionID) + return version; + return null; + } + } + public new System.Collections.Generic.IList Items + { + get { return base.Items; } + } + public RevisionVersion GetItem(Version myVersion) + { + foreach (RevisionVersion version in this) + if (version.VersionID == myVersion.VersionID) + return version; + return null; + } + public RevisionVersion Add(Stage myStage, DateTime dts, string userID) // One to Many + { + RevisionVersion version = RevisionVersion.New(myStage, dts, userID); + this.Add(version); + return version; + } + public void Remove(Version myVersion) + { + foreach (RevisionVersion version in this) + { + if (version.VersionID == myVersion.VersionID) + { + Remove(version); + break; + } + } + } + public bool Contains(Version myVersion) + { + foreach (RevisionVersion version in this) + if (version.VersionID == myVersion.VersionID) + return true; + return false; + } + public bool ContainsDeleted(Version myVersion) + { + foreach (RevisionVersion version in DeletedList) + if (version.VersionID == myVersion.VersionID) + return true; + return false; + } + public bool IsDirtyList(List list) + { + // any non-new deletions make us dirty + foreach (RevisionVersion item in DeletedList) + if (!item.IsNew) + return true; + // run through all the child objects + // and if any are dirty then then + // collection is dirty + foreach (RevisionVersion child in this) + if (child.IsDirtyList(list)) + return true; + return false; + } + public override bool IsValid + { + get { return IsValidList(new List()); } + } + public bool IsValidList(List list) + { + // run through all the child objects + // and if any are invalid then the + // collection is invalid + foreach (RevisionVersion child in this) + if (!child.IsValidList(list)) + { + //Console.WriteLine("Valid {0} Child {1} - {2}", child.IsValid, child.GetType().Name,child.ToString()); + return false; + } + return true; + } + #endregion + #region ValidationRules + public IVEHasBrokenRules HasBrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = null; + foreach (RevisionVersion revisionVersion in this) + if ((hasBrokenRules = revisionVersion.HasBrokenRules) != null) return hasBrokenRules; + return hasBrokenRules; + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + #endregion + #region Factory Methods + internal static RevisionVersions New() + { + return new RevisionVersions(); + } + internal static RevisionVersions Get(SafeDataReader dr) + { + return new RevisionVersions(dr); + } + public static RevisionVersions GetByRevisionID(int revisionID) + { + try + { + return DataPortal.Fetch(new RevisionIDCriteria(revisionID)); + } + catch (Exception ex) + { + throw new DbCslaException("Error on RevisionVersions.GetByRevisionID", ex); + } + } + private RevisionVersions() + { + MarkAsChild(); + } + internal RevisionVersions(SafeDataReader dr) + { + MarkAsChild(); + Fetch(dr); + } + #endregion + #region Data Access Portal + // called to load data from the database + private void Fetch(SafeDataReader dr) + { + this.RaiseListChangedEvents = false; + while (dr.Read()) + this.Add(RevisionVersion.Get(dr)); + this.RaiseListChangedEvents = true; + } + [Serializable()] + private class RevisionIDCriteria + { + public RevisionIDCriteria(int revisionID) + { + _RevisionID = revisionID; + } + private int _RevisionID; + public int RevisionID + { + get { return _RevisionID; } + set { _RevisionID = value; } + } + } + private void DataPortal_Fetch(RevisionIDCriteria criteria) + { + this.RaiseListChangedEvents = false; + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RevisionVersions.DataPortal_FetchRevisionID", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getVersionsByRevisionID"; + cm.Parameters.AddWithValue("@RevisionID", criteria.RevisionID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + while (dr.Read()) this.Add(new RevisionVersion(dr)); + } + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("RevisionVersions.DataPortal_FetchRevisionID", ex); + throw new DbCslaException("RevisionVersions.DataPortal_Fetch", ex); + } + this.RaiseListChangedEvents = true; + } + internal void Update(Revision revision) + { + this.RaiseListChangedEvents = false; + try + { + // update (thus deleting) any deleted child objects + foreach (RevisionVersion obj in DeletedList) + obj.DeleteSelf(revision);// Deletes related record + // now that they are deleted, remove them from memory too + DeletedList.Clear(); + // add/update any current child objects + foreach (RevisionVersion obj in this) + { + if (obj.IsNew) + obj.Insert(revision); + else + obj.Update(revision); + } + } + finally + { + this.RaiseListChangedEvents = true; + } + } + #endregion + #region ICustomTypeDescriptor impl + public String GetClassName() + { return TypeDescriptor.GetClassName(this, true); } + public AttributeCollection GetAttributes() + { return TypeDescriptor.GetAttributes(this, true); } + public String GetComponentName() + { return TypeDescriptor.GetComponentName(this, true); } + public TypeConverter GetConverter() + { return TypeDescriptor.GetConverter(this, true); } + public EventDescriptor GetDefaultEvent() + { return TypeDescriptor.GetDefaultEvent(this, true); } + public PropertyDescriptor GetDefaultProperty() + { return TypeDescriptor.GetDefaultProperty(this, true); } + public object GetEditor(Type editorBaseType) + { return TypeDescriptor.GetEditor(this, editorBaseType, true); } + public EventDescriptorCollection GetEvents(Attribute[] attributes) + { return TypeDescriptor.GetEvents(this, attributes, true); } + public EventDescriptorCollection GetEvents() + { return TypeDescriptor.GetEvents(this, true); } + public object GetPropertyOwner(PropertyDescriptor pd) + { return this; } + /// + /// Called to get the properties of this type. Returns properties with certain + /// attributes. this restriction is not implemented here. + /// + /// + /// + public PropertyDescriptorCollection GetProperties(Attribute[] attributes) + { return GetProperties(); } + /// + /// Called to get the properties of this type. + /// + /// + public PropertyDescriptorCollection GetProperties() + { + // Create a collection object to hold property descriptors + PropertyDescriptorCollection pds = new PropertyDescriptorCollection(null); + // Iterate the list + for (int i = 0; i < this.Items.Count; i++) + { + // Create a property descriptor for the item and add to the property descriptor collection + RevisionVersionsPropertyDescriptor pd = new RevisionVersionsPropertyDescriptor(this, i); + pds.Add(pd); + } + // return the property descriptor collection + return pds; + } + #endregion + } // Class + #region Property Descriptor + /// + /// Summary description for CollectionPropertyDescriptor. + /// + public partial class RevisionVersionsPropertyDescriptor : vlnListPropertyDescriptor + { + private RevisionVersion Item { get { return (RevisionVersion)_Item; } } + public RevisionVersionsPropertyDescriptor(RevisionVersions collection, int index) : base(collection, index) { ;} + } + #endregion + #region Converter + internal class RevisionVersionsConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is RevisionVersions) + { + // Return department and department role separated by comma. + return ((RevisionVersions)value).Items.Count.ToString() + " Versions"; + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion +} // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/Stage.cs b/PROMS/VEPROMS.CSLA.Library/Generated/Stage.cs new file mode 100644 index 00000000..f9923734 --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/Stage.cs @@ -0,0 +1,1183 @@ +// ======================================================================== +// 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 +{ + /// + /// Stage Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(StageConverter))] + public partial class Stage : BusinessBase, IDisposable, IVEHasBrokenRules + { + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Refresh + private List _RefreshStages = new List(); + private List _RefreshStageChecks = new List(); + private List _RefreshStageVersions = new List(); + private void AddToRefreshList(List refreshStages, List refreshStageChecks, List refreshStageVersions) + { + if (IsDirty) + refreshStages.Add(this); + if (_StageChecks != null && _StageChecks.IsDirty) + { + foreach (StageCheck tmp in _StageChecks) + { + if (tmp.IsDirty) refreshStageChecks.Add(tmp); + } + } + if (_StageVersions != null && _StageVersions.IsDirty) + { + foreach (StageVersion tmp in _StageVersions) + { + if (tmp.IsDirty) refreshStageVersions.Add(tmp); + } + } + } + private void BuildRefreshList() + { + _RefreshStages = new List(); + _RefreshStageChecks = new List(); + _RefreshStageVersions = new List(); + AddToRefreshList(_RefreshStages, _RefreshStageChecks, _RefreshStageVersions); + } + private void ProcessRefreshList() + { + foreach (Stage tmp in _RefreshStages) + { + StageInfo.Refresh(tmp); + } + foreach (StageCheck tmp in _RefreshStageChecks) + { + CheckInfo.Refresh(tmp); + } + foreach (StageVersion tmp in _RefreshStageVersions) + { + VersionInfo.Refresh(tmp); + } + } + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(Stage stage) + { + if (!_CacheList.Contains(stage)) _CacheList.Add(stage); // In AddToCache + } + protected static void RemoveFromCache(Stage stage) + { + while (_CacheList.Contains(stage)) _CacheList.Remove(stage); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + while (_CacheList.Count > 0) // Move Stage(s) from temporary _CacheList to _CacheByPrimaryKey + { + Stage tmp = _CacheList[0]; // Get the first Stage + string pKey = tmp.StageID.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 Stage + } + } + protected static Stage GetCachedByPrimaryKey(int stageID) + { + ConvertListToDictionary(); + string key = stageID.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 _nextStageID = -1; + public static int NextStageID + { + get { return _nextStageID--; } + } + private int _StageID; + [System.ComponentModel.DataObjectField(true, true)] + public int StageID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("StageID", true); + return _StageID; + } + } + private string _Name = string.Empty; + public string Name + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("Name", true); + return _Name; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + CanWriteProperty("Name", true); + if (value == null) value = string.Empty; + if (_Name != value) + { + _Name = value; + PropertyHasChanged(); + } + } + } + private string _Description = string.Empty; + public string Description + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("Description", true); + return _Description; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + CanWriteProperty("Description", true); + if (value == null) value = string.Empty; + if (_Description != value) + { + _Description = value; + PropertyHasChanged(); + } + } + } + private int _IsApproved; + public int IsApproved + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("IsApproved", true); + return _IsApproved; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + CanWriteProperty("IsApproved", true); + if (_IsApproved != value) + { + _IsApproved = 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 _StageCheckCount = 0; + /// + /// Count of StageChecks for this Stage + /// + public int StageCheckCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("StageCheckCount", true); + return _StageCheckCount; + } + } + private StageChecks _StageChecks = null; + /// + /// Related Field + /// + [TypeConverter(typeof(StageChecksConverter))] + public StageChecks StageChecks + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("StageChecks", true); + if (_StageCheckCount < 0 || (_StageCheckCount > 0 && _StageChecks == null)) + _StageChecks = StageChecks.GetByStageID(StageID); + if (_StageCheckCount < 0 ) + _StageCheckCount = _StageChecks == null ? 0 : _StageChecks.Count; + if (_StageChecks == null) + _StageChecks = StageChecks.New(); + return _StageChecks; + } + } + public void Reset_StageChecks() + { + _StageCheckCount = -1; + } + private int _StageVersionCount = 0; + /// + /// Count of StageVersions for this Stage + /// + public int StageVersionCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("StageVersionCount", true); + return _StageVersionCount; + } + } + private StageVersions _StageVersions = null; + /// + /// Related Field + /// + [TypeConverter(typeof(StageVersionsConverter))] + public StageVersions StageVersions + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("StageVersions", true); + if (_StageVersionCount < 0 || (_StageVersionCount > 0 && _StageVersions == null)) + _StageVersions = StageVersions.GetByStageID(StageID); + if (_StageVersionCount < 0 ) + _StageVersionCount = _StageVersions == null ? 0 : _StageVersions.Count; + if (_StageVersions == null) + _StageVersions = StageVersions.New(); + return _StageVersions; + } + } + public void Reset_StageVersions() + { + _StageVersionCount = -1; + } + public override bool IsDirty + { + get + { + if ( base.IsDirty ) + return true; + return IsDirtyList(new List()); + } + } + public bool IsDirtyList(List list) + { + if (base.IsDirty || list.Contains(this)) + return base.IsDirty; + list.Add(this); + return base.IsDirty || (_StageChecks == null ? false : _StageChecks.IsDirtyList(list)) || (_StageVersions == null ? false : _StageVersions.IsDirtyList(list)); + } + public override bool IsValid + { + get { return IsValidList(new List()); } + } + public bool IsValidList(List list) + { + if(list.Contains(this)) + return (IsNew && !IsDirty) ? true : base.IsValid; + list.Add(this); + return ((IsNew && !IsDirty) ? true : base.IsValid) && (_StageChecks == null ? true : _StageChecks.IsValidList(list)) && (_StageVersions == null ? true : _StageVersions.IsValidList(list)); + } + // CSLATODO: Replace base Stage.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current Stage + //public override string ToString() + //{ + // return base.ToString(); + //} + // CSLATODO: Check Stage.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current Stage + protected override object GetIdValue() + { + return MyStageUnique; // 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 (_StageChecks != null && (hasBrokenRules = _StageChecks.HasBrokenRules) != null) return hasBrokenRules; + if (_StageVersions != null && (hasBrokenRules = _StageVersions.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.StringRequired, "Name"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 50)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Description", 200)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UserID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); + //ValidationRules.AddDependantProperty("x", "y"); + _StageExtension.AddValidationRules(ValidationRules); + // CSLATODO: Add other validation rules + } + protected override void AddInstanceBusinessRules() + { + _StageExtension.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(StageID, ""); + //AuthorizationRules.AllowRead(Name, ""); + //AuthorizationRules.AllowRead(Description, ""); + //AuthorizationRules.AllowRead(IsApproved, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowRead(UserID, ""); + //AuthorizationRules.AllowWrite(Name, ""); + //AuthorizationRules.AllowWrite(Description, ""); + //AuthorizationRules.AllowWrite(IsApproved, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowWrite(UserID, ""); + _StageExtension.AddAuthorizationRules(AuthorizationRules); + } + protected override void AddInstanceAuthorizationRules() + { + //CSLATODO: Who can read/write which fields + _StageExtension.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; + } + /// + /// determines if related records (Foreign Keys) will keep this Item from being deleted + /// + public bool CanDelete + { + get + { + // Check to make sure that there are not any related records + int usedByCount = 0; + usedByCount += _StageCheckCount; + usedByCount += _StageVersionCount; + 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 _StageUnique = 0; + protected static int StageUnique + { get { return ++_StageUnique; } } + private int _MyStageUnique = StageUnique; + public int MyStageUnique // Absolutely Unique ID - Editable + { get { return _MyStageUnique; } } + protected Stage() + {/* require use of factory methods */ + AddToCache(this); + } + public void Dispose() + { + RemoveFromDictionaries(); + } + private void RemoveFromDictionaries() + { + RemoveFromCache(this); + if (_CacheByPrimaryKey.ContainsKey(StageID.ToString())) + { + List listStage = _CacheByPrimaryKey[StageID.ToString()]; // Get the list of items + while (listStage.Contains(this)) listStage.Remove(this); // Remove the item from the list + if (listStage.Count == 0) //If there are no items left in the list + _CacheByPrimaryKey.Remove(StageID.ToString()); // remove the list + } + } + public static Stage New() + { + if (!CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a Stage"); + try + { + return DataPortal.Create(); + } + catch (Exception ex) + { + throw new DbCslaException("Error on Stage.New", ex); + } + } + public static Stage New(string name) + { + Stage tmp = Stage.New(); + tmp.Name = name; + return tmp; + } + public static Stage New(string name, string description, int isApproved, DateTime dts, string userID) + { + Stage tmp = Stage.New(); + tmp.Name = name; + tmp.Description = description; + tmp.IsApproved = isApproved; + tmp.DTS = dts; + tmp.UserID = userID; + return tmp; + } + public static Stage MakeStage(string name, string description, int isApproved, DateTime dts, string userID) + { + Stage tmp = Stage.New(name, description, isApproved, dts, userID); + if (tmp.IsSavable) + { + Stage tmp2 = tmp; + tmp = tmp2.Save(); + tmp2.Dispose(); + } + 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 Stage New(string name, string description) + { + Stage tmp = Stage.New(); + tmp.Name = name; + tmp.Description = description; + return tmp; + } + public static Stage MakeStage(string name, string description) + { + Stage tmp = Stage.New(name, description); + if (tmp.IsSavable) + { + Stage tmp2 = tmp; + tmp = tmp2.Save(); + tmp2.Dispose(); + } + 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 Stage Get(int stageID) + { + if (!CanGetObject()) + throw new System.Security.SecurityException("User not authorized to view a Stage"); + try + { + Stage tmp = GetCachedByPrimaryKey(stageID); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(stageID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up Stage + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on Stage.Get", ex); + } + } + public static Stage Get(SafeDataReader dr) + { + if (dr.Read()) return new Stage(dr); + return null; + } + internal Stage(SafeDataReader dr) + { + ReadData(dr); + } + public static void Delete(int stageID) + { + if (!CanDeleteObject()) + throw new System.Security.SecurityException("User not authorized to remove a Stage"); + try + { + DataPortal.Delete(new PKCriteria(stageID)); + } + catch (Exception ex) + { + throw new DbCslaException("Error on Stage.Delete", ex); + } + } + public override Stage Save() + { + if (IsDeleted && !CanDeleteObject()) + throw new System.Security.SecurityException("User not authorized to remove a Stage"); + else if (IsNew && !CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a Stage"); + else if (!CanEditObject()) + throw new System.Security.SecurityException("User not authorized to update a Stage"); + try + { + BuildRefreshList(); + Stage stage = base.Save(); + RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache + AddToCache(stage);//Refresh the item in AllList + ProcessRefreshList(); + return stage; + } + catch (Exception ex) + { + throw new DbCslaException("Error on CSLA Save", ex); + } + } + #endregion + #region Data Access Portal + [Serializable()] + protected class PKCriteria + { + private int _StageID; + public int StageID + { get { return _StageID; } } + public PKCriteria(int stageID) + { + _StageID = stageID; + } + } + // CSLATODO: If Create needs to access DB - It should not be marked RunLocal + [RunLocal()] + private new void DataPortal_Create() + { + _StageID = NextStageID; + // Database Defaults + _IsApproved = _StageExtension.DefaultIsApproved; + _DTS = _StageExtension.DefaultDTS; + _UserID = _StageExtension.DefaultUserID; + // CSLATODO: Add any defaults that are necessary + ValidationRules.CheckRules(); + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Stage.ReadData", GetHashCode()); + try + { + _StageID = dr.GetInt32("StageID"); + _Name = dr.GetString("Name"); + _Description = dr.GetString("Description"); + _IsApproved = dr.GetInt32("IsApproved"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + _StageCheckCount = dr.GetInt32("CheckCount"); + _StageVersionCount = dr.GetInt32("VersionCount"); + MarkOld(); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Stage.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Stage.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Stage.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 = "getStage"; + cm.Parameters.AddWithValue("@StageID", criteria.StageID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + // load child objects + dr.NextResult(); + _StageChecks = StageChecks.Get(dr); + // load child objects + dr.NextResult(); + _StageVersions = StageVersions.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("Stage.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Stage.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("Stage.DataPortal_Insert", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Stage.DataPortal_Insert", ex); + } + finally + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Stage.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 = "addStage"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@Name", _Name); + cm.Parameters.AddWithValue("@Description", _Description); + cm.Parameters.AddWithValue("@IsApproved", _IsApproved); + if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS); + cm.Parameters.AddWithValue("@UserID", _UserID); + // Output Calculated Columns + SqlParameter param_StageID = new SqlParameter("@newStageID", SqlDbType.Int); + param_StageID.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_StageID); + 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 + _StageID = (int)cm.Parameters["@newStageID"].Value; + _LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value; + } + MarkOld(); + // update child objects + if (_StageChecks != null) _StageChecks.Update(this); + if (_StageVersions != null) _StageVersions.Update(this); + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Stage.SQLInsert", GetHashCode()); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Stage.SQLInsert", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Stage.SQLInsert", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + public static byte[] Add(SqlConnection cn, ref int stageID, string name, string description, int isApproved, DateTime dts, string userID) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Stage.Add", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "addStage"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@Name", name); + cm.Parameters.AddWithValue("@Description", description); + cm.Parameters.AddWithValue("@IsApproved", isApproved); + if (dts.Year >= 1753 && dts.Year <= 9999) cm.Parameters.AddWithValue("@DTS", dts); + cm.Parameters.AddWithValue("@UserID", userID); + // Output Calculated Columns + SqlParameter param_StageID = new SqlParameter("@newStageID", SqlDbType.Int); + param_StageID.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_StageID); + 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 + stageID = (int)cm.Parameters["@newStageID"].Value; + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Stage.Add", ex); + throw new DbCslaException("Stage.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}] Stage.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("Stage.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}] Stage.SQLUpdate", GetHashCode()); + try + { + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + if (base.IsDirty) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "updateStage"; + // All Fields including Calculated Fields + cm.Parameters.AddWithValue("@StageID", _StageID); + cm.Parameters.AddWithValue("@Name", _Name); + cm.Parameters.AddWithValue("@Description", _Description); + cm.Parameters.AddWithValue("@IsApproved", _IsApproved); + 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 (_StageChecks != null) _StageChecks.Update(this); + if (_StageVersions != null) _StageVersions.Update(this); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Stage.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 = Stage.Add(cn, ref _StageID, _Name, _Description, _IsApproved, _DTS, _UserID); + else + _LastChanged = Stage.Update(cn, ref _StageID, _Name, _Description, _IsApproved, _DTS, _UserID, ref _LastChanged); + MarkOld(); + } + if (_StageChecks != null) _StageChecks.Update(this); + if (_StageVersions != null) _StageVersions.Update(this); + } + [Transactional(TransactionalTypes.TransactionScope)] + public static byte[] Update(SqlConnection cn, ref int stageID, string name, string description, int isApproved, DateTime dts, string userID, ref byte[] lastChanged) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Stage.Update", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "updateStage"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@StageID", stageID); + cm.Parameters.AddWithValue("@Name", name); + cm.Parameters.AddWithValue("@Description", description); + cm.Parameters.AddWithValue("@IsApproved", isApproved); + 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("Stage.Update", ex); + throw new DbCslaException("Stage.Update", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_DeleteSelf() + { + DataPortal_Delete(new PKCriteria(_StageID)); + } + [Transactional(TransactionalTypes.TransactionScope)] + private void DataPortal_Delete(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Stage.DataPortal_Delete", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "deleteStage"; + cm.Parameters.AddWithValue("@StageID", criteria.StageID); + cm.ExecuteNonQuery(); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Stage.DataPortal_Delete", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Stage.DataPortal_Delete", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + public static void Remove(SqlConnection cn, int stageID) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Stage.Remove", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "deleteStage"; + // Input PK Fields + cm.Parameters.AddWithValue("@StageID", stageID); + // CSLATODO: Define any additional output parameters + cm.ExecuteNonQuery(); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Stage.Remove", ex); + throw new DbCslaException("Stage.Remove", ex); + } + } + #endregion + #region Exists + public static bool Exists(int stageID) + { + ExistsCommand result; + try + { + result = DataPortal.Execute(new ExistsCommand(stageID)); + return result.Exists; + } + catch (Exception ex) + { + throw new DbCslaException("Error on Stage.Exists", ex); + } + } + [Serializable()] + private class ExistsCommand : CommandBase + { + private int _StageID; + private bool _exists; + public bool Exists + { + get { return _exists; } + } + public ExistsCommand(int stageID) + { + _StageID = stageID; + } + protected override void DataPortal_Execute() + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Stage.DataPortal_Execute", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + cn.Open(); + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "existsStage"; + cm.Parameters.AddWithValue("@StageID", _StageID); + int count = (int)cm.ExecuteScalar(); + _exists = (count > 0); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Stage.DataPortal_Execute", ex); + throw new DbCslaException("Stage.DataPortal_Execute", ex); + } + } + } + #endregion + // Standard Default Code + #region extension + StageExtension _StageExtension = new StageExtension(); + [Serializable()] + partial class StageExtension : extensionBase + { + } + [Serializable()] + class extensionBase + { + // Default Values + public virtual int DefaultIsApproved + { + get { return 0; } + } + public virtual DateTime DefaultDTS + { + get { return DateTime.Now; } + } + public virtual string DefaultUserID + { + get { return Environment.UserName.ToUpper(); } + } + // 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 StageConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is Stage) + { + // Return the ToString value + return ((Stage)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion +} // Namespace + + +//// The following is a sample Extension File. You can use it to create StageExt.cs +//using System; +//using System.Collections.Generic; +//using System.Text; +//using Csla; + +//namespace VEPROMS.CSLA.Library +//{ +// public partial class Stage +// { +// partial class StageExtension : extensionBase +// { +// // CSLATODO: Override automatic defaults +// public virtual int DefaultIsApproved +// { +// get { return 0; } +// } +// 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, ""); +// } +// public new void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) +// { +// //rules.AllowInstanceRead(Dbid, ""); +// } +// 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 */); +// } +// } +// } +//} diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/StageCheck.cs b/PROMS/VEPROMS.CSLA.Library/Generated/StageCheck.cs new file mode 100644 index 00000000..c53504ae --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/StageCheck.cs @@ -0,0 +1,587 @@ +// ======================================================================== +// 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 +{ + /// + /// StageCheck Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(StageCheckConverter))] + public partial class StageCheck : BusinessBase, IVEHasBrokenRules + { + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _ErrorMessage; } + } + private int _CheckID; + [System.ComponentModel.DataObjectField(true, true)] + public int CheckID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("CheckID", true); + if (_MyCheck != null) _CheckID = _MyCheck.CheckID; + return _CheckID; + } + } + private Check _MyCheck; + [System.ComponentModel.DataObjectField(true, true)] + public Check MyCheck + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("MyCheck", true); + if (_MyCheck == null && _CheckID != 0) _MyCheck = Check.Get(_CheckID); + return _MyCheck; + } + } + private int _RevisionID; + public int RevisionID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("RevisionID", true); + if (_MyRevision != null) _RevisionID = _MyRevision.RevisionID; + return _RevisionID; + } + } + private Revision _MyRevision; + public Revision MyRevision + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("MyRevision", true); + if (_MyRevision == null && _RevisionID != 0) _MyRevision = Revision.Get(_RevisionID); + return _MyRevision; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + CanWriteProperty("MyRevision", true); + if (_MyRevision != value) + { + _MyRevision = value; + _RevisionID = value.RevisionID;// Update underlying data field + PropertyHasChanged(); + } + } + } + private string _ConsistencyChecks = string.Empty; + public string ConsistencyChecks + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("ConsistencyChecks", true); + return _ConsistencyChecks; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + CanWriteProperty("ConsistencyChecks", true); + if (value == null) value = string.Empty; + if (_ConsistencyChecks != value) + { + _ConsistencyChecks = 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 _Revision_ItemID; + public int Revision_ItemID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("Revision_ItemID", true); + return _Revision_ItemID; + } + } + private int _Revision_TypeID; + public int Revision_TypeID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("Revision_TypeID", true); + return _Revision_TypeID; + } + } + private string _Revision_RevisionNumber = string.Empty; + public string Revision_RevisionNumber + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("Revision_RevisionNumber", true); + return _Revision_RevisionNumber; + } + } + private DateTime? _Revision_RevisionDate; + public DateTime? Revision_RevisionDate + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("Revision_RevisionDate", true); + return _Revision_RevisionDate; + } + } + private string _Revision_Notes = string.Empty; + public string Revision_Notes + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("Revision_Notes", true); + return _Revision_Notes; + } + } + private string _Revision_Config = string.Empty; + public string Revision_Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("Revision_Config", true); + return _Revision_Config; + } + } + private DateTime _Revision_DTS = new DateTime(); + public DateTime Revision_DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("Revision_DTS", true); + return _Revision_DTS; + } + } + private string _Revision_UserID = string.Empty; + public string Revision_UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("Revision_UserID", true); + return _Revision_UserID; + } + } + // CSLATODO: Check StageCheck.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current StageCheck + protected override object GetIdValue() + { + return MyStageCheckUnique; // Absolutely Unique ID + } + // CSLATODO: Replace base StageCheck.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current StageCheck + //public override string ToString() + //{ + // return base.ToString(); + //} + public override bool IsDirty + { + get + { + if ( base.IsDirty ) + return true; + return IsDirtyList(new List()); + } + } + public bool IsDirtyList(List list) + { + if (base.IsDirty || list.Contains(this)) + return base.IsDirty; + list.Add(this); + return base.IsDirty || (_MyRevision == null ? false : _MyRevision.IsDirtyList(list)); + } + public override bool IsValid + { + get { return IsValidList(new List()); } + } + public bool IsValidList(List list) + { + if(list.Contains(this)) + return (IsNew && !IsDirty) ? true : base.IsValid; + list.Add(this); + return ((IsNew && !IsDirty) ? true : base.IsValid) && (_MyRevision == null ? true : _MyRevision.IsValidList(list)); + } + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if (BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + if (_MyRevision != null && (hasBrokenRules = _MyRevision.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(MyRevisionRequired, "MyRevision"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("ConsistencyChecks", 1073741823)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UserID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); + // CSLATODO: Add other validation rules + } + private static bool MyRevisionRequired(StageCheck target, Csla.Validation.RuleArgs e) + { + if (target._RevisionID == 0 && target._MyRevision == null) // Required field missing + { + e.Description = "Required"; + return false; + } + return true; + } + // 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(CheckID, ""); + //AuthorizationRules.AllowRead(RevisionID, ""); + //AuthorizationRules.AllowWrite(RevisionID, ""); + //AuthorizationRules.AllowRead(ConsistencyChecks, ""); + //AuthorizationRules.AllowWrite(ConsistencyChecks, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowRead(UserID, ""); + //AuthorizationRules.AllowWrite(UserID, ""); + } + 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; + } + 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 _StageCheckUnique = 0; + private static int StageCheckUnique + { get { return ++_StageCheckUnique; } } + private int _MyStageCheckUnique = StageCheckUnique; + public int MyStageCheckUnique // Absolutely Unique ID - Editable FK + { get { return _MyStageCheckUnique; } } + internal static StageCheck New(Revision myRevision) + { + return new StageCheck(myRevision); + } + internal static StageCheck Get(SafeDataReader dr) + { + return new StageCheck(dr); + } + public StageCheck() + { + MarkAsChild(); + _CheckID = Check.NextCheckID; + _DTS = _StageCheckExtension.DefaultDTS; + _UserID = _StageCheckExtension.DefaultUserID; + ValidationRules.CheckRules(); + } + private StageCheck(Revision myRevision) + { + MarkAsChild(); + // CSLATODO: Add any initialization & defaults + _CheckID = Check.NextCheckID; + _DTS = _StageCheckExtension.DefaultDTS; + _UserID = _StageCheckExtension.DefaultUserID; + _MyRevision = myRevision; + ValidationRules.CheckRules(); + } + internal StageCheck(SafeDataReader dr) + { + MarkAsChild(); + Fetch(dr); + } + #endregion + #region Data Access Portal + private void Fetch(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] StageCheck.FetchDR", GetHashCode()); + try + { + _CheckID = dr.GetInt32("CheckID"); + _RevisionID = dr.GetInt32("RevisionID"); + _ConsistencyChecks = dr.GetString("ConsistencyChecks"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + _Revision_ItemID = dr.GetInt32("Revision_ItemID"); + _Revision_TypeID = dr.GetInt32("Revision_TypeID"); + _Revision_RevisionNumber = dr.GetString("Revision_RevisionNumber"); + if (!dr.IsDBNull(dr.GetOrdinal("Revision_RevisionDate"))) _Revision_RevisionDate = dr.GetDateTime("Revision_RevisionDate"); + _Revision_Notes = dr.GetString("Revision_Notes"); + _Revision_Config = dr.GetString("Revision_Config"); + _Revision_DTS = dr.GetDateTime("Revision_DTS"); + _Revision_UserID = dr.GetString("Revision_UserID"); + } + catch (Exception ex) // FKItem Fetch + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("StageCheck.FetchDR", ex); + throw new DbCslaException("StageCheck.Fetch", ex); + } + MarkOld(); + } + internal void Insert(Stage myStage) + { + // if we're not dirty then don't update the database + if (!this.IsDirty) return; + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + _LastChanged = Check.Add(cn, ref _CheckID, _MyRevision, myStage, _ConsistencyChecks, _DTS, _UserID); + MarkOld(); + } + internal void Update(Stage myStage) + { + // if we're not dirty then don't update the database + if (!this.IsDirty) return; + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + _LastChanged = Check.Update(cn, ref _CheckID, _RevisionID, myStage.StageID, _ConsistencyChecks, _DTS, _UserID, ref _LastChanged); + MarkOld(); + } + internal void DeleteSelf(Stage myStage) + { + // if we're not dirty then don't update the database + if (!this.IsDirty) return; + // if we're new then don't update the database + if (this.IsNew) return; + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + Check.Remove(cn, _CheckID); + MarkNew(); + } + #endregion + // Standard Default Code + #region extension + StageCheckExtension _StageCheckExtension = new StageCheckExtension(); + [Serializable()] + partial class StageCheckExtension : extensionBase + { + } + [Serializable()] + class extensionBase + { + // Default Values + public virtual DateTime DefaultDTS + { + get { return DateTime.Now; } + } + public virtual string DefaultUserID + { + get { return Environment.UserName.ToUpper(); } + } + // 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 StageCheckConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is StageCheck) + { + // Return the ToString value + return ((StageCheck)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion +} // Namespace + + +//// The following is a sample Extension File. You can use it to create StageCheckExt.cs +//using System; +//using System.Collections.Generic; +//using System.Text; +//using Csla; + +//namespace VEPROMS.CSLA.Library +//{ +// public partial class StageCheck +// { +// partial class StageCheckExtension : extensionBase +// { +// // CSLATODO: Override automatic defaults +// 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, ""); +// } +// public new void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) +// { +// //rules.AllowInstanceRead(Dbid, ""); +// } +// 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 */); +// } +// } +// } +//} diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/StageChecks.cs b/PROMS/VEPROMS.CSLA.Library/Generated/StageChecks.cs new file mode 100644 index 00000000..4f7dfbaf --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/StageChecks.cs @@ -0,0 +1,322 @@ +// ======================================================================== +// 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 +{ + /// + /// StageChecks Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(StageChecksConverter))] + public partial class StageChecks : BusinessListBase, ICustomTypeDescriptor, IVEHasBrokenRules + { + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _ErrorMessage; } + } + // One To Many + public StageCheck this[Check myCheck] + { + get + { + foreach (StageCheck check in this) + if (check.CheckID == myCheck.CheckID) + return check; + return null; + } + } + public new System.Collections.Generic.IList Items + { + get { return base.Items; } + } + public StageCheck GetItem(Check myCheck) + { + foreach (StageCheck check in this) + if (check.CheckID == myCheck.CheckID) + return check; + return null; + } + public StageCheck Add(Revision myRevision) // One to Many + { + StageCheck check = StageCheck.New(myRevision); + this.Add(check); + return check; + } + public void Remove(Check myCheck) + { + foreach (StageCheck check in this) + { + if (check.CheckID == myCheck.CheckID) + { + Remove(check); + break; + } + } + } + public bool Contains(Check myCheck) + { + foreach (StageCheck check in this) + if (check.CheckID == myCheck.CheckID) + return true; + return false; + } + public bool ContainsDeleted(Check myCheck) + { + foreach (StageCheck check in DeletedList) + if (check.CheckID == myCheck.CheckID) + return true; + return false; + } + public bool IsDirtyList(List list) + { + // any non-new deletions make us dirty + foreach (StageCheck item in DeletedList) + if (!item.IsNew) + return true; + // run through all the child objects + // and if any are dirty then then + // collection is dirty + foreach (StageCheck child in this) + if (child.IsDirtyList(list)) + return true; + return false; + } + public override bool IsValid + { + get { return IsValidList(new List()); } + } + public bool IsValidList(List list) + { + // run through all the child objects + // and if any are invalid then the + // collection is invalid + foreach (StageCheck child in this) + if (!child.IsValidList(list)) + { + //Console.WriteLine("Valid {0} Child {1} - {2}", child.IsValid, child.GetType().Name,child.ToString()); + return false; + } + return true; + } + #endregion + #region ValidationRules + public IVEHasBrokenRules HasBrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = null; + foreach (StageCheck stageCheck in this) + if ((hasBrokenRules = stageCheck.HasBrokenRules) != null) return hasBrokenRules; + return hasBrokenRules; + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + #endregion + #region Factory Methods + internal static StageChecks New() + { + return new StageChecks(); + } + internal static StageChecks Get(SafeDataReader dr) + { + return new StageChecks(dr); + } + public static StageChecks GetByStageID(int stageID) + { + try + { + return DataPortal.Fetch(new StageIDCriteria(stageID)); + } + catch (Exception ex) + { + throw new DbCslaException("Error on StageChecks.GetByStageID", ex); + } + } + private StageChecks() + { + MarkAsChild(); + } + internal StageChecks(SafeDataReader dr) + { + MarkAsChild(); + Fetch(dr); + } + #endregion + #region Data Access Portal + // called to load data from the database + private void Fetch(SafeDataReader dr) + { + this.RaiseListChangedEvents = false; + while (dr.Read()) + this.Add(StageCheck.Get(dr)); + this.RaiseListChangedEvents = true; + } + [Serializable()] + private class StageIDCriteria + { + public StageIDCriteria(int stageID) + { + _StageID = stageID; + } + private int _StageID; + public int StageID + { + get { return _StageID; } + set { _StageID = value; } + } + } + private void DataPortal_Fetch(StageIDCriteria criteria) + { + this.RaiseListChangedEvents = false; + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] StageChecks.DataPortal_FetchStageID", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getChecksByStageID"; + cm.Parameters.AddWithValue("@StageID", criteria.StageID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + while (dr.Read()) this.Add(new StageCheck(dr)); + } + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("StageChecks.DataPortal_FetchStageID", ex); + throw new DbCslaException("StageChecks.DataPortal_Fetch", ex); + } + this.RaiseListChangedEvents = true; + } + internal void Update(Stage stage) + { + this.RaiseListChangedEvents = false; + try + { + // update (thus deleting) any deleted child objects + foreach (StageCheck obj in DeletedList) + obj.DeleteSelf(stage);// Deletes related record + // now that they are deleted, remove them from memory too + DeletedList.Clear(); + // add/update any current child objects + foreach (StageCheck obj in this) + { + if (obj.IsNew) + obj.Insert(stage); + else + obj.Update(stage); + } + } + finally + { + this.RaiseListChangedEvents = true; + } + } + #endregion + #region ICustomTypeDescriptor impl + public String GetClassName() + { return TypeDescriptor.GetClassName(this, true); } + public AttributeCollection GetAttributes() + { return TypeDescriptor.GetAttributes(this, true); } + public String GetComponentName() + { return TypeDescriptor.GetComponentName(this, true); } + public TypeConverter GetConverter() + { return TypeDescriptor.GetConverter(this, true); } + public EventDescriptor GetDefaultEvent() + { return TypeDescriptor.GetDefaultEvent(this, true); } + public PropertyDescriptor GetDefaultProperty() + { return TypeDescriptor.GetDefaultProperty(this, true); } + public object GetEditor(Type editorBaseType) + { return TypeDescriptor.GetEditor(this, editorBaseType, true); } + public EventDescriptorCollection GetEvents(Attribute[] attributes) + { return TypeDescriptor.GetEvents(this, attributes, true); } + public EventDescriptorCollection GetEvents() + { return TypeDescriptor.GetEvents(this, true); } + public object GetPropertyOwner(PropertyDescriptor pd) + { return this; } + /// + /// Called to get the properties of this type. Returns properties with certain + /// attributes. this restriction is not implemented here. + /// + /// + /// + public PropertyDescriptorCollection GetProperties(Attribute[] attributes) + { return GetProperties(); } + /// + /// Called to get the properties of this type. + /// + /// + public PropertyDescriptorCollection GetProperties() + { + // Create a collection object to hold property descriptors + PropertyDescriptorCollection pds = new PropertyDescriptorCollection(null); + // Iterate the list + for (int i = 0; i < this.Items.Count; i++) + { + // Create a property descriptor for the item and add to the property descriptor collection + StageChecksPropertyDescriptor pd = new StageChecksPropertyDescriptor(this, i); + pds.Add(pd); + } + // return the property descriptor collection + return pds; + } + #endregion + } // Class + #region Property Descriptor + /// + /// Summary description for CollectionPropertyDescriptor. + /// + public partial class StageChecksPropertyDescriptor : vlnListPropertyDescriptor + { + private StageCheck Item { get { return (StageCheck)_Item; } } + public StageChecksPropertyDescriptor(StageChecks collection, int index) : base(collection, index) { ;} + } + #endregion + #region Converter + internal class StageChecksConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is StageChecks) + { + // Return department and department role separated by comma. + return ((StageChecks)value).Items.Count.ToString() + " Checks"; + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion +} // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/StageInfo.cs b/PROMS/VEPROMS.CSLA.Library/Generated/StageInfo.cs new file mode 100644 index 00000000..8d714235 --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/StageInfo.cs @@ -0,0 +1,424 @@ +// ======================================================================== +// 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 StageInfoEvent(object sender); + /// + /// StageInfo Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(StageInfoConverter))] + public partial class StageInfo : ReadOnlyBase, IDisposable + { + public event StageInfoEvent 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 _CacheList = new List(); + protected static void AddToCache(StageInfo stageInfo) + { + if (!_CacheList.Contains(stageInfo)) _CacheList.Add(stageInfo); // In AddToCache + } + protected static void RemoveFromCache(StageInfo stageInfo) + { + while (_CacheList.Contains(stageInfo)) _CacheList.Remove(stageInfo); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + while (_CacheList.Count > 0) // Move StageInfo(s) from temporary _CacheList to _CacheByPrimaryKey + { + StageInfo tmp = _CacheList[0]; // Get the first StageInfo + string pKey = tmp.StageID.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 StageInfo + } + } + internal static void AddList(StageInfoList lst) + { + foreach (StageInfo item in lst) AddToCache(item); + } + protected static StageInfo GetCachedByPrimaryKey(int stageID) + { + ConvertListToDictionary(); + string key = stageID.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 Stage _Editable; + private IVEHasBrokenRules HasBrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = null; + if (_Editable != null) + hasBrokenRules = _Editable.HasBrokenRules; + return hasBrokenRules; + } + } + private int _StageID; + [System.ComponentModel.DataObjectField(true, true)] + public int StageID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("StageID", true); + return _StageID; + } + } + private string _Name = string.Empty; + public string Name + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("Name", true); + return _Name; + } + } + private string _Description = string.Empty; + public string Description + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("Description", true); + return _Description; + } + } + private int _IsApproved; + public int IsApproved + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("IsApproved", true); + return _IsApproved; + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("DTS", true); + return _DTS; + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("UserID", true); + return _UserID; + } + } + private int _StageCheckCount = 0; + /// + /// Count of StageChecks for this Stage + /// + public int StageCheckCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("StageCheckCount", true); + if (_StageCheckCount < 0) + _StageCheckCount = StageChecks.Count; + return _StageCheckCount; + } + } + private CheckInfoList _StageChecks = null; + [TypeConverter(typeof(CheckInfoListConverter))] + public CheckInfoList StageChecks + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("StageChecks", true); + if (_StageCheckCount < 0 || (_StageCheckCount > 0 && _StageChecks == null)) + _StageChecks = CheckInfoList.GetByStageID(_StageID); + if (_StageCheckCount < 0) + _StageCheckCount = _StageChecks.Count; + return _StageChecks; + } + } + public void RefreshStageChecks() + { + _StageCheckCount = -1; + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(_StageID.ToString())) + foreach (StageInfo tmp in _CacheByPrimaryKey[_StageID.ToString()]) + tmp._StageCheckCount = -1; // This will cause the data to be requeried + } + private int _StageVersionCount = 0; + /// + /// Count of StageVersions for this Stage + /// + public int StageVersionCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("StageVersionCount", true); + if (_StageVersionCount < 0) + _StageVersionCount = StageVersions.Count; + return _StageVersionCount; + } + } + private VersionInfoList _StageVersions = null; + [TypeConverter(typeof(VersionInfoListConverter))] + public VersionInfoList StageVersions + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("StageVersions", true); + if (_StageVersionCount < 0 || (_StageVersionCount > 0 && _StageVersions == null)) + _StageVersions = VersionInfoList.GetByStageID(_StageID); + if (_StageVersionCount < 0) + _StageVersionCount = _StageVersions.Count; + return _StageVersions; + } + } + public void RefreshStageVersions() + { + _StageVersionCount = -1; + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(_StageID.ToString())) + foreach (StageInfo tmp in _CacheByPrimaryKey[_StageID.ToString()]) + tmp._StageVersionCount = -1; // This will cause the data to be requeried + } + // CSLATODO: Replace base StageInfo.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current StageInfo + //public override string ToString() + //{ + // return base.ToString(); + //} + // CSLATODO: Check StageInfo.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current StageInfo + protected override object GetIdValue() + { + return MyStageInfoUnique; // Absolutely Unique ID + } + #endregion + #region Factory Methods + private static int _StageInfoUnique = 0; + private static int StageInfoUnique + { get { return ++_StageInfoUnique; } } + private int _MyStageInfoUnique = StageInfoUnique; + public int MyStageInfoUnique // Absolutely Unique ID - Info + { get { return _MyStageInfoUnique; } } + protected StageInfo() + {/* require use of factory methods */ + AddToCache(this); + } + public void Dispose() + { + RemoveFromCache(this); + if (!_CacheByPrimaryKey.ContainsKey(StageID.ToString())) return; + List listStageInfo = _CacheByPrimaryKey[StageID.ToString()]; // Get the list of items + while (listStageInfo.Contains(this)) listStageInfo.Remove(this); // Remove the item from the list + if (listStageInfo.Count == 0) // If there are no items left in the list + _CacheByPrimaryKey.Remove(StageID.ToString()); // remove the list + } + public virtual Stage Get() + { + return _Editable = Stage.Get(_StageID); + } + public static void Refresh(Stage tmp) + { + string key = tmp.StageID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (StageInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(Stage tmp) + { + _Name = tmp.Name; + _Description = tmp.Description; + _IsApproved = tmp.IsApproved; + _DTS = tmp.DTS; + _UserID = tmp.UserID; + _StageInfoExtension.Refresh(this); + OnChange();// raise an event + } + public static StageInfo Get(int stageID) + { + //if (!CanGetObject()) + // throw new System.Security.SecurityException("User not authorized to view a Stage"); + try + { + StageInfo tmp = GetCachedByPrimaryKey(stageID); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(stageID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up StageInfo + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on StageInfo.Get", ex); + } + } + #endregion + #region Data Access Portal + internal StageInfo(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] StageInfo.Constructor", GetHashCode()); + try + { + ReadData(dr); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("StageInfo.Constructor", ex); + throw new DbCslaException("StageInfo.Constructor", ex); + } + } + [Serializable()] + protected class PKCriteria + { + private int _StageID; + public int StageID + { get { return _StageID; } } + public PKCriteria(int stageID) + { + _StageID = stageID; + } + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] StageInfo.ReadData", GetHashCode()); + try + { + _StageID = dr.GetInt32("StageID"); + _Name = dr.GetString("Name"); + _Description = dr.GetString("Description"); + _IsApproved = dr.GetInt32("IsApproved"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + _StageCheckCount = dr.GetInt32("CheckCount"); + _StageVersionCount = dr.GetInt32("VersionCount"); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("StageInfo.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("StageInfo.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] StageInfo.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 = "getStage"; + cm.Parameters.AddWithValue("@StageID", criteria.StageID); + 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("StageInfo.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("StageInfo.DataPortal_Fetch", ex); + } + } + #endregion + // Standard Refresh + #region extension + StageInfoExtension _StageInfoExtension = new StageInfoExtension(); + [Serializable()] + partial class StageInfoExtension : extensionBase { } + [Serializable()] + class extensionBase + { + // Default Refresh + public virtual void Refresh(StageInfo tmp) { } + } + #endregion + } // Class + #region Converter + internal class StageInfoConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is StageInfo) + { + // Return the ToString value + return ((StageInfo)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion +} // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/StageInfoList.cs b/PROMS/VEPROMS.CSLA.Library/Generated/StageInfoList.cs new file mode 100644 index 00000000..1d991e0e --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/StageInfoList.cs @@ -0,0 +1,205 @@ +// ======================================================================== +// 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 +{ + /// + /// StageInfoList Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(StageInfoListConverter))] + public partial class StageInfoList : ReadOnlyListBase, ICustomTypeDescriptor, IDisposable + { + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Business Methods + internal new IList Items + { get { return base.Items; } } + public void AddEvents() + { + foreach (StageInfo tmp in this) + { + tmp.Changed += new StageInfoEvent(tmp_Changed); + } + } + void tmp_Changed(object sender) + { + for (int i = 0; i < Count; i++) + { + if (base[i] == sender) + this.OnListChanged(new ListChangedEventArgs(ListChangedType.ItemChanged, i)); + } + } + public void Dispose() + { + foreach (StageInfo tmp in this) + { + tmp.Changed -= new StageInfoEvent(tmp_Changed); + } + } + #endregion + #region Factory Methods + public static StageInfoList _StageInfoList = null; + /// + /// Return a list of all StageInfo. + /// + public static StageInfoList Get() + { + try + { + if (_StageInfoList != null) + return _StageInfoList; + StageInfoList tmp = DataPortal.Fetch(); + StageInfo.AddList(tmp); + tmp.AddEvents(); + _StageInfoList = tmp; + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on StageInfoList.Get", ex); + } + } + /// + /// Reset the list of all StageInfo. + /// + public static void Reset() + { + _StageInfoList = null; + } + // CSLATODO: Add alternative gets - + //public static StageInfoList Get() + //{ + // try + // { + // return DataPortal.Fetch(new FilteredCriteria()); + // } + // catch (Exception ex) + // { + // throw new DbCslaException("Error on StageInfoList.Get", ex); + // } + //} + private StageInfoList() + { /* require use of factory methods */ } + #endregion + #region Data Access Portal + private void DataPortal_Fetch() + { + this.RaiseListChangedEvents = false; + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] StageInfoList.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getStages"; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + IsReadOnly = false; + while (dr.Read()) this.Add(new StageInfo(dr)); + IsReadOnly = true; + } + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("StageInfoList.DataPortal_Fetch", ex); + throw new DbCslaException("StageInfoList.DataPortal_Fetch", ex); + } + this.RaiseListChangedEvents = true; + } + #endregion + #region ICustomTypeDescriptor impl + public String GetClassName() + { return TypeDescriptor.GetClassName(this, true); } + public AttributeCollection GetAttributes() + { return TypeDescriptor.GetAttributes(this, true); } + public String GetComponentName() + { return TypeDescriptor.GetComponentName(this, true); } + public TypeConverter GetConverter() + { return TypeDescriptor.GetConverter(this, true); } + public EventDescriptor GetDefaultEvent() + { return TypeDescriptor.GetDefaultEvent(this, true); } + public PropertyDescriptor GetDefaultProperty() + { return TypeDescriptor.GetDefaultProperty(this, true); } + public object GetEditor(Type editorBaseType) + { return TypeDescriptor.GetEditor(this, editorBaseType, true); } + public EventDescriptorCollection GetEvents(Attribute[] attributes) + { return TypeDescriptor.GetEvents(this, attributes, true); } + public EventDescriptorCollection GetEvents() + { return TypeDescriptor.GetEvents(this, true); } + public object GetPropertyOwner(PropertyDescriptor pd) + { return this; } + /// + /// Called to get the properties of this type. Returns properties with certain + /// attributes. this restriction is not implemented here. + /// + /// + /// + public PropertyDescriptorCollection GetProperties(Attribute[] attributes) + { return GetProperties(); } + /// + /// Called to get the properties of this type. + /// + /// + public PropertyDescriptorCollection GetProperties() + { + // Create a collection object to hold property descriptors + PropertyDescriptorCollection pds = new PropertyDescriptorCollection(null); + // Iterate the list + for (int i = 0; i < this.Items.Count; i++) + { + // Create a property descriptor for the item and add to the property descriptor collection + StageInfoListPropertyDescriptor pd = new StageInfoListPropertyDescriptor(this, i); + pds.Add(pd); + } + // return the property descriptor collection + return pds; + } + #endregion + } // Class + #region Property Descriptor + /// + /// Summary description for CollectionPropertyDescriptor. + /// + public partial class StageInfoListPropertyDescriptor : vlnListPropertyDescriptor + { + private StageInfo Item { get { return (StageInfo)_Item; } } + public StageInfoListPropertyDescriptor(StageInfoList collection, int index) : base(collection, index) { ;} + } + #endregion + #region Converter + internal class StageInfoListConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is StageInfoList) + { + // Return department and department role separated by comma. + return ((StageInfoList)value).Items.Count.ToString() + " Stages"; + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion +} // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/StageVersion.cs b/PROMS/VEPROMS.CSLA.Library/Generated/StageVersion.cs new file mode 100644 index 00000000..7cb9784d --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/StageVersion.cs @@ -0,0 +1,590 @@ +// ======================================================================== +// 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 +{ + /// + /// StageVersion Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(StageVersionConverter))] + public partial class StageVersion : BusinessBase, IVEHasBrokenRules + { + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _ErrorMessage; } + } + private int _VersionID; + [System.ComponentModel.DataObjectField(true, true)] + public int VersionID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("VersionID", true); + if (_MyVersion != null) _VersionID = _MyVersion.VersionID; + return _VersionID; + } + } + private Version _MyVersion; + [System.ComponentModel.DataObjectField(true, true)] + public Version MyVersion + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("MyVersion", true); + if (_MyVersion == null && _VersionID != 0) _MyVersion = Version.Get(_VersionID); + return _MyVersion; + } + } + private int _RevisionID; + public int RevisionID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("RevisionID", true); + if (_MyRevision != null) _RevisionID = _MyRevision.RevisionID; + return _RevisionID; + } + } + private Revision _MyRevision; + public Revision MyRevision + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("MyRevision", true); + if (_MyRevision == null && _RevisionID != 0) _MyRevision = Revision.Get(_RevisionID); + return _MyRevision; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + CanWriteProperty("MyRevision", true); + if (_MyRevision != value) + { + _MyRevision = value; + _RevisionID = value.RevisionID;// Update underlying data field + PropertyHasChanged(); + } + } + } + private byte[] _PDF; + public byte[] PDF + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("PDF", true); + return _PDF; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + CanWriteProperty("PDF", true); + if (_PDF != value) + { + _PDF = value; + PropertyHasChanged(); + } + } + } + private byte[] _SummaryPDF; + public byte[] SummaryPDF + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("SummaryPDF", true); + return _SummaryPDF; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + CanWriteProperty("SummaryPDF", true); + if (_SummaryPDF != value) + { + _SummaryPDF = 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 _Revision_ItemID; + public int Revision_ItemID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("Revision_ItemID", true); + return _Revision_ItemID; + } + } + private int _Revision_TypeID; + public int Revision_TypeID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("Revision_TypeID", true); + return _Revision_TypeID; + } + } + private string _Revision_RevisionNumber = string.Empty; + public string Revision_RevisionNumber + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("Revision_RevisionNumber", true); + return _Revision_RevisionNumber; + } + } + private DateTime? _Revision_RevisionDate; + public DateTime? Revision_RevisionDate + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("Revision_RevisionDate", true); + return _Revision_RevisionDate; + } + } + private string _Revision_Notes = string.Empty; + public string Revision_Notes + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("Revision_Notes", true); + return _Revision_Notes; + } + } + private string _Revision_Config = string.Empty; + public string Revision_Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("Revision_Config", true); + return _Revision_Config; + } + } + private DateTime _Revision_DTS = new DateTime(); + public DateTime Revision_DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("Revision_DTS", true); + return _Revision_DTS; + } + } + private string _Revision_UserID = string.Empty; + public string Revision_UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("Revision_UserID", true); + return _Revision_UserID; + } + } + // CSLATODO: Check StageVersion.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current StageVersion + protected override object GetIdValue() + { + return MyStageVersionUnique; // Absolutely Unique ID + } + // CSLATODO: Replace base StageVersion.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current StageVersion + //public override string ToString() + //{ + // return base.ToString(); + //} + public override bool IsDirty + { + get + { + if ( base.IsDirty ) + return true; + return IsDirtyList(new List()); + } + } + public bool IsDirtyList(List list) + { + if (base.IsDirty || list.Contains(this)) + return base.IsDirty; + list.Add(this); + return base.IsDirty || (_MyRevision == null ? false : _MyRevision.IsDirtyList(list)); + } + public override bool IsValid + { + get { return IsValidList(new List()); } + } + public bool IsValidList(List list) + { + if(list.Contains(this)) + return (IsNew && !IsDirty) ? true : base.IsValid; + list.Add(this); + return ((IsNew && !IsDirty) ? true : base.IsValid) && (_MyRevision == null ? true : _MyRevision.IsValidList(list)); + } + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if (BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + if (_MyRevision != null && (hasBrokenRules = _MyRevision.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(MyRevisionRequired, "MyRevision"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UserID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 200)); + // CSLATODO: Add other validation rules + } + private static bool MyRevisionRequired(StageVersion target, Csla.Validation.RuleArgs e) + { + if (target._RevisionID == 0 && target._MyRevision == null) // Required field missing + { + e.Description = "Required"; + return false; + } + return true; + } + // 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(VersionID, ""); + //AuthorizationRules.AllowRead(RevisionID, ""); + //AuthorizationRules.AllowWrite(RevisionID, ""); + //AuthorizationRules.AllowRead(PDF, ""); + //AuthorizationRules.AllowWrite(PDF, ""); + //AuthorizationRules.AllowRead(SummaryPDF, ""); + //AuthorizationRules.AllowWrite(SummaryPDF, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowRead(UserID, ""); + //AuthorizationRules.AllowWrite(UserID, ""); + } + 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; + } + 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 _StageVersionUnique = 0; + private static int StageVersionUnique + { get { return ++_StageVersionUnique; } } + private int _MyStageVersionUnique = StageVersionUnique; + public int MyStageVersionUnique // Absolutely Unique ID - Editable FK + { get { return _MyStageVersionUnique; } } + internal static StageVersion New(Revision myRevision, DateTime dts, string userID) + { + return new StageVersion(myRevision, dts, userID); + } + internal static StageVersion Get(SafeDataReader dr) + { + return new StageVersion(dr); + } + public StageVersion() + { + MarkAsChild(); + _VersionID = Version.NextVersionID; + + ValidationRules.CheckRules(); + } + private StageVersion(Revision myRevision, DateTime dts, string userID) + { + MarkAsChild(); + // CSLATODO: Add any initialization & defaults + _VersionID = Version.NextVersionID; + + _MyRevision = myRevision; + _DTS = dts; + _UserID = userID; + ValidationRules.CheckRules(); + } + internal StageVersion(SafeDataReader dr) + { + MarkAsChild(); + Fetch(dr); + } + #endregion + #region Data Access Portal + private void Fetch(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] StageVersion.FetchDR", GetHashCode()); + try + { + _VersionID = dr.GetInt32("VersionID"); + _RevisionID = dr.GetInt32("RevisionID"); + _PDF = (byte[])dr.GetValue("PDF"); + _SummaryPDF = (byte[])dr.GetValue("SummaryPDF"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + _Revision_ItemID = dr.GetInt32("Revision_ItemID"); + _Revision_TypeID = dr.GetInt32("Revision_TypeID"); + _Revision_RevisionNumber = dr.GetString("Revision_RevisionNumber"); + if (!dr.IsDBNull(dr.GetOrdinal("Revision_RevisionDate"))) _Revision_RevisionDate = dr.GetDateTime("Revision_RevisionDate"); + _Revision_Notes = dr.GetString("Revision_Notes"); + _Revision_Config = dr.GetString("Revision_Config"); + _Revision_DTS = dr.GetDateTime("Revision_DTS"); + _Revision_UserID = dr.GetString("Revision_UserID"); + } + catch (Exception ex) // FKItem Fetch + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("StageVersion.FetchDR", ex); + throw new DbCslaException("StageVersion.Fetch", ex); + } + MarkOld(); + } + internal void Insert(Stage myStage) + { + // if we're not dirty then don't update the database + if (!this.IsDirty) return; + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + _LastChanged = Version.Add(cn, ref _VersionID, _MyRevision, myStage, _PDF, _SummaryPDF, _DTS, _UserID); + MarkOld(); + } + internal void Update(Stage myStage) + { + // if we're not dirty then don't update the database + if (!this.IsDirty) return; + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + _LastChanged = Version.Update(cn, ref _VersionID, _RevisionID, myStage.StageID, _PDF, _SummaryPDF, _DTS, _UserID, ref _LastChanged); + MarkOld(); + } + internal void DeleteSelf(Stage myStage) + { + // if we're not dirty then don't update the database + if (!this.IsDirty) return; + // if we're new then don't update the database + if (this.IsNew) return; + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + Version.Remove(cn, _VersionID); + MarkNew(); + } + #endregion + // Standard Default Code + #region extension + StageVersionExtension _StageVersionExtension = new StageVersionExtension(); + [Serializable()] + partial class StageVersionExtension : extensionBase + { + } + [Serializable()] + class extensionBase + { + // Default Values + // 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 StageVersionConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is StageVersion) + { + // Return the ToString value + return ((StageVersion)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion +} // Namespace + + +//// The following is a sample Extension File. You can use it to create StageVersionExt.cs +//using System; +//using System.Collections.Generic; +//using System.Text; +//using Csla; + +//namespace VEPROMS.CSLA.Library +//{ +// public partial class StageVersion +// { +// partial class StageVersionExtension : extensionBase +// { +// // CSLATODO: Override automatic defaults +// public new void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) +// { +// //rules.AllowRead(Dbid, ""); +// } +// public new void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) +// { +// //rules.AllowInstanceRead(Dbid, ""); +// } +// 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 */); +// } +// } +// } +//} diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/StageVersions.cs b/PROMS/VEPROMS.CSLA.Library/Generated/StageVersions.cs new file mode 100644 index 00000000..e8c3285c --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/StageVersions.cs @@ -0,0 +1,322 @@ +// ======================================================================== +// 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 +{ + /// + /// StageVersions Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(StageVersionsConverter))] + public partial class StageVersions : BusinessListBase, ICustomTypeDescriptor, IVEHasBrokenRules + { + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _ErrorMessage; } + } + // One To Many + public StageVersion this[Version myVersion] + { + get + { + foreach (StageVersion version in this) + if (version.VersionID == myVersion.VersionID) + return version; + return null; + } + } + public new System.Collections.Generic.IList Items + { + get { return base.Items; } + } + public StageVersion GetItem(Version myVersion) + { + foreach (StageVersion version in this) + if (version.VersionID == myVersion.VersionID) + return version; + return null; + } + public StageVersion Add(Revision myRevision, DateTime dts, string userID) // One to Many + { + StageVersion version = StageVersion.New(myRevision, dts, userID); + this.Add(version); + return version; + } + public void Remove(Version myVersion) + { + foreach (StageVersion version in this) + { + if (version.VersionID == myVersion.VersionID) + { + Remove(version); + break; + } + } + } + public bool Contains(Version myVersion) + { + foreach (StageVersion version in this) + if (version.VersionID == myVersion.VersionID) + return true; + return false; + } + public bool ContainsDeleted(Version myVersion) + { + foreach (StageVersion version in DeletedList) + if (version.VersionID == myVersion.VersionID) + return true; + return false; + } + public bool IsDirtyList(List list) + { + // any non-new deletions make us dirty + foreach (StageVersion item in DeletedList) + if (!item.IsNew) + return true; + // run through all the child objects + // and if any are dirty then then + // collection is dirty + foreach (StageVersion child in this) + if (child.IsDirtyList(list)) + return true; + return false; + } + public override bool IsValid + { + get { return IsValidList(new List()); } + } + public bool IsValidList(List list) + { + // run through all the child objects + // and if any are invalid then the + // collection is invalid + foreach (StageVersion child in this) + if (!child.IsValidList(list)) + { + //Console.WriteLine("Valid {0} Child {1} - {2}", child.IsValid, child.GetType().Name,child.ToString()); + return false; + } + return true; + } + #endregion + #region ValidationRules + public IVEHasBrokenRules HasBrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = null; + foreach (StageVersion stageVersion in this) + if ((hasBrokenRules = stageVersion.HasBrokenRules) != null) return hasBrokenRules; + return hasBrokenRules; + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + #endregion + #region Factory Methods + internal static StageVersions New() + { + return new StageVersions(); + } + internal static StageVersions Get(SafeDataReader dr) + { + return new StageVersions(dr); + } + public static StageVersions GetByStageID(int stageID) + { + try + { + return DataPortal.Fetch(new StageIDCriteria(stageID)); + } + catch (Exception ex) + { + throw new DbCslaException("Error on StageVersions.GetByStageID", ex); + } + } + private StageVersions() + { + MarkAsChild(); + } + internal StageVersions(SafeDataReader dr) + { + MarkAsChild(); + Fetch(dr); + } + #endregion + #region Data Access Portal + // called to load data from the database + private void Fetch(SafeDataReader dr) + { + this.RaiseListChangedEvents = false; + while (dr.Read()) + this.Add(StageVersion.Get(dr)); + this.RaiseListChangedEvents = true; + } + [Serializable()] + private class StageIDCriteria + { + public StageIDCriteria(int stageID) + { + _StageID = stageID; + } + private int _StageID; + public int StageID + { + get { return _StageID; } + set { _StageID = value; } + } + } + private void DataPortal_Fetch(StageIDCriteria criteria) + { + this.RaiseListChangedEvents = false; + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] StageVersions.DataPortal_FetchStageID", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getVersionsByStageID"; + cm.Parameters.AddWithValue("@StageID", criteria.StageID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + while (dr.Read()) this.Add(new StageVersion(dr)); + } + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("StageVersions.DataPortal_FetchStageID", ex); + throw new DbCslaException("StageVersions.DataPortal_Fetch", ex); + } + this.RaiseListChangedEvents = true; + } + internal void Update(Stage stage) + { + this.RaiseListChangedEvents = false; + try + { + // update (thus deleting) any deleted child objects + foreach (StageVersion obj in DeletedList) + obj.DeleteSelf(stage);// Deletes related record + // now that they are deleted, remove them from memory too + DeletedList.Clear(); + // add/update any current child objects + foreach (StageVersion obj in this) + { + if (obj.IsNew) + obj.Insert(stage); + else + obj.Update(stage); + } + } + finally + { + this.RaiseListChangedEvents = true; + } + } + #endregion + #region ICustomTypeDescriptor impl + public String GetClassName() + { return TypeDescriptor.GetClassName(this, true); } + public AttributeCollection GetAttributes() + { return TypeDescriptor.GetAttributes(this, true); } + public String GetComponentName() + { return TypeDescriptor.GetComponentName(this, true); } + public TypeConverter GetConverter() + { return TypeDescriptor.GetConverter(this, true); } + public EventDescriptor GetDefaultEvent() + { return TypeDescriptor.GetDefaultEvent(this, true); } + public PropertyDescriptor GetDefaultProperty() + { return TypeDescriptor.GetDefaultProperty(this, true); } + public object GetEditor(Type editorBaseType) + { return TypeDescriptor.GetEditor(this, editorBaseType, true); } + public EventDescriptorCollection GetEvents(Attribute[] attributes) + { return TypeDescriptor.GetEvents(this, attributes, true); } + public EventDescriptorCollection GetEvents() + { return TypeDescriptor.GetEvents(this, true); } + public object GetPropertyOwner(PropertyDescriptor pd) + { return this; } + /// + /// Called to get the properties of this type. Returns properties with certain + /// attributes. this restriction is not implemented here. + /// + /// + /// + public PropertyDescriptorCollection GetProperties(Attribute[] attributes) + { return GetProperties(); } + /// + /// Called to get the properties of this type. + /// + /// + public PropertyDescriptorCollection GetProperties() + { + // Create a collection object to hold property descriptors + PropertyDescriptorCollection pds = new PropertyDescriptorCollection(null); + // Iterate the list + for (int i = 0; i < this.Items.Count; i++) + { + // Create a property descriptor for the item and add to the property descriptor collection + StageVersionsPropertyDescriptor pd = new StageVersionsPropertyDescriptor(this, i); + pds.Add(pd); + } + // return the property descriptor collection + return pds; + } + #endregion + } // Class + #region Property Descriptor + /// + /// Summary description for CollectionPropertyDescriptor. + /// + public partial class StageVersionsPropertyDescriptor : vlnListPropertyDescriptor + { + private StageVersion Item { get { return (StageVersion)_Item; } } + public StageVersionsPropertyDescriptor(StageVersions collection, int index) : base(collection, index) { ;} + } + #endregion + #region Converter + internal class StageVersionsConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is StageVersions) + { + // Return department and department role separated by comma. + return ((StageVersions)value).Items.Count.ToString() + " Versions"; + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion +} // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/Version.cs b/PROMS/VEPROMS.CSLA.Library/Generated/Version.cs new file mode 100644 index 00000000..05a7ce0a --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/Version.cs @@ -0,0 +1,1075 @@ +// ======================================================================== +// 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 +{ + /// + /// Version Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(VersionConverter))] + public partial class Version : BusinessBase, IDisposable, IVEHasBrokenRules + { + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Refresh + private List _RefreshVersions = new List(); + private void AddToRefreshList(List refreshVersions) + { + if (IsDirty) + refreshVersions.Add(this); + } + private void BuildRefreshList() + { + _RefreshVersions = new List(); + AddToRefreshList(_RefreshVersions); + } + private void ProcessRefreshList() + { + foreach (Version tmp in _RefreshVersions) + { + VersionInfo.Refresh(tmp); + if (tmp._MyRevision != null) RevisionInfo.Refresh(tmp._MyRevision); + if (tmp._MyStage != null) StageInfo.Refresh(tmp._MyStage); + } + } + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(Version version) + { + if (!_CacheList.Contains(version)) _CacheList.Add(version); // In AddToCache + } + protected static void RemoveFromCache(Version version) + { + while (_CacheList.Contains(version)) _CacheList.Remove(version); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + while (_CacheList.Count > 0) // Move Version(s) from temporary _CacheList to _CacheByPrimaryKey + { + Version tmp = _CacheList[0]; // Get the first Version + string pKey = tmp.VersionID.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 Version + } + } + protected static Version GetCachedByPrimaryKey(int versionID) + { + ConvertListToDictionary(); + string key = versionID.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 _nextVersionID = -1; + public static int NextVersionID + { + get { return _nextVersionID--; } + } + private int _VersionID; + [System.ComponentModel.DataObjectField(true, true)] + public int VersionID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("VersionID", true); + return _VersionID; + } + } + private int _RevisionID; + public int RevisionID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("RevisionID", true); + if (_MyRevision != null) _RevisionID = _MyRevision.RevisionID; + return _RevisionID; + } + } + private Revision _MyRevision; + public Revision MyRevision + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("MyRevision", true); + if (_MyRevision == null && _RevisionID != 0) _MyRevision = Revision.Get(_RevisionID); + return _MyRevision; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + CanWriteProperty("MyRevision", true); + if (_MyRevision != value) + { + _MyRevision = value; + _RevisionID = value.RevisionID;// Update underlying data field + PropertyHasChanged(); + } + } + } + private int _StageID; + public int StageID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("StageID", true); + if (_MyStage != null) _StageID = _MyStage.StageID; + return _StageID; + } + } + private Stage _MyStage; + public Stage MyStage + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("MyStage", true); + if (_MyStage == null && _StageID != 0) _MyStage = Stage.Get(_StageID); + return _MyStage; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + CanWriteProperty("MyStage", true); + if (_MyStage != value) + { + _MyStage = value; + _StageID = value.StageID;// Update underlying data field + PropertyHasChanged(); + } + } + } + private byte[] _PDF; + public byte[] PDF + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("PDF", true); + return _PDF; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + CanWriteProperty("PDF", true); + if (_PDF != value) + { + _PDF = value; + PropertyHasChanged(); + } + } + } + private byte[] _SummaryPDF; + public byte[] SummaryPDF + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("SummaryPDF", true); + return _SummaryPDF; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + CanWriteProperty("SummaryPDF", true); + if (_SummaryPDF != value) + { + _SummaryPDF = 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 + public override bool IsDirty + { + get + { + if ( base.IsDirty ) + return true; + return IsDirtyList(new List()); + } + } + public bool IsDirtyList(List list) + { + if (base.IsDirty || list.Contains(this)) + return base.IsDirty; + list.Add(this); + return base.IsDirty || (_MyRevision == null ? false : _MyRevision.IsDirtyList(list)) || (_MyStage == null ? false : _MyStage.IsDirtyList(list)); + } + public override bool IsValid + { + get { return IsValidList(new List()); } + } + public bool IsValidList(List list) + { + if(list.Contains(this)) + return (IsNew && !IsDirty) ? true : base.IsValid; + list.Add(this); + return ((IsNew && !IsDirty) ? true : base.IsValid) && (_MyRevision == null ? true : _MyRevision.IsValidList(list)) && (_MyStage == null ? true : _MyStage.IsValidList(list)); + } + // CSLATODO: Replace base Version.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current Version + //public override string ToString() + //{ + // return base.ToString(); + //} + // CSLATODO: Check Version.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current Version + protected override object GetIdValue() + { + return MyVersionUnique; // 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 (_MyRevision != null && (hasBrokenRules = _MyRevision.HasBrokenRules) != null) return hasBrokenRules; + if (_MyStage != null && (hasBrokenRules = _MyStage.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(MyRevisionRequired, "MyRevision"); + ValidationRules.AddRule(MyStageRequired, "MyStage"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UserID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 200)); + //ValidationRules.AddDependantProperty("x", "y"); + _VersionExtension.AddValidationRules(ValidationRules); + // CSLATODO: Add other validation rules + } + protected override void AddInstanceBusinessRules() + { + _VersionExtension.AddInstanceValidationRules(ValidationRules); + // CSLATODO: Add other validation rules + } + private static bool MyRevisionRequired(Version target, Csla.Validation.RuleArgs e) + { + if (target._RevisionID == 0 && target._MyRevision == null) // Required field missing + { + e.Description = "Required"; + return false; + } + return true; + } + private static bool MyStageRequired(Version target, Csla.Validation.RuleArgs e) + { + if (target._StageID == 0 && target._MyStage == null) // Required field missing + { + e.Description = "Required"; + return false; + } + return true; + } + // 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(VersionID, ""); + //AuthorizationRules.AllowRead(RevisionID, ""); + //AuthorizationRules.AllowRead(StageID, ""); + //AuthorizationRules.AllowRead(PDF, ""); + //AuthorizationRules.AllowRead(SummaryPDF, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowRead(UserID, ""); + //AuthorizationRules.AllowWrite(RevisionID, ""); + //AuthorizationRules.AllowWrite(StageID, ""); + //AuthorizationRules.AllowWrite(PDF, ""); + //AuthorizationRules.AllowWrite(SummaryPDF, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowWrite(UserID, ""); + _VersionExtension.AddAuthorizationRules(AuthorizationRules); + } + protected override void AddInstanceAuthorizationRules() + { + //CSLATODO: Who can read/write which fields + _VersionExtension.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; + } + 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 _VersionUnique = 0; + protected static int VersionUnique + { get { return ++_VersionUnique; } } + private int _MyVersionUnique = VersionUnique; + public int MyVersionUnique // Absolutely Unique ID - Editable + { get { return _MyVersionUnique; } } + protected Version() + {/* require use of factory methods */ + AddToCache(this); + } + public void Dispose() + { + RemoveFromDictionaries(); + } + private void RemoveFromDictionaries() + { + RemoveFromCache(this); + if (_CacheByPrimaryKey.ContainsKey(VersionID.ToString())) + { + List listVersion = _CacheByPrimaryKey[VersionID.ToString()]; // Get the list of items + while (listVersion.Contains(this)) listVersion.Remove(this); // Remove the item from the list + if (listVersion.Count == 0) //If there are no items left in the list + _CacheByPrimaryKey.Remove(VersionID.ToString()); // remove the list + } + } + public static Version New() + { + if (!CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a Version"); + try + { + return DataPortal.Create(); + } + catch (Exception ex) + { + throw new DbCslaException("Error on Version.New", ex); + } + } + public static Version New(Revision myRevision, Stage myStage, DateTime dts, string userID) + { + Version tmp = Version.New(); + tmp.MyRevision = myRevision; + tmp.MyStage = myStage; + tmp.DTS = dts; + tmp.UserID = userID; + return tmp; + } + public static Version New(Revision myRevision, Stage myStage, byte[] pdf, byte[] summaryPDF, DateTime dts, string userID) + { + Version tmp = Version.New(); + tmp.MyRevision = myRevision; + tmp.MyStage = myStage; + tmp.PDF = pdf; + tmp.SummaryPDF = summaryPDF; + tmp.DTS = dts; + tmp.UserID = userID; + return tmp; + } + public static Version MakeVersion(Revision myRevision, Stage myStage, byte[] pdf, byte[] summaryPDF, DateTime dts, string userID) + { + Version tmp = Version.New(myRevision, myStage, pdf, summaryPDF, dts, userID); + if (tmp.IsSavable) + { + Version tmp2 = tmp; + tmp = tmp2.Save(); + tmp2.Dispose(); + } + 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 Version Get(int versionID) + { + if (!CanGetObject()) + throw new System.Security.SecurityException("User not authorized to view a Version"); + try + { + Version tmp = GetCachedByPrimaryKey(versionID); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(versionID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up Version + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on Version.Get", ex); + } + } + public static Version Get(SafeDataReader dr) + { + if (dr.Read()) return new Version(dr); + return null; + } + internal Version(SafeDataReader dr) + { + ReadData(dr); + } + public static void Delete(int versionID) + { + if (!CanDeleteObject()) + throw new System.Security.SecurityException("User not authorized to remove a Version"); + try + { + DataPortal.Delete(new PKCriteria(versionID)); + } + catch (Exception ex) + { + throw new DbCslaException("Error on Version.Delete", ex); + } + } + public override Version Save() + { + if (IsDeleted && !CanDeleteObject()) + throw new System.Security.SecurityException("User not authorized to remove a Version"); + else if (IsNew && !CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a Version"); + else if (!CanEditObject()) + throw new System.Security.SecurityException("User not authorized to update a Version"); + try + { + BuildRefreshList(); + Version version = base.Save(); + RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache + AddToCache(version);//Refresh the item in AllList + ProcessRefreshList(); + return version; + } + catch (Exception ex) + { + throw new DbCslaException("Error on CSLA Save", ex); + } + } + #endregion + #region Data Access Portal + [Serializable()] + protected class PKCriteria + { + private int _VersionID; + public int VersionID + { get { return _VersionID; } } + public PKCriteria(int versionID) + { + _VersionID = versionID; + } + } + // CSLATODO: If Create needs to access DB - It should not be marked RunLocal + [RunLocal()] + private new void DataPortal_Create() + { + _VersionID = NextVersionID; + // Database Defaults + + // CSLATODO: Add any defaults that are necessary + ValidationRules.CheckRules(); + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Version.ReadData", GetHashCode()); + try + { + _VersionID = dr.GetInt32("VersionID"); + _RevisionID = dr.GetInt32("RevisionID"); + _StageID = dr.GetInt32("StageID"); + _PDF = (byte[])dr.GetValue("PDF"); + _SummaryPDF = (byte[])dr.GetValue("SummaryPDF"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + MarkOld(); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Version.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Version.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Version.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 = "getVersion"; + cm.Parameters.AddWithValue("@VersionID", criteria.VersionID); + 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("Version.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Version.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("Version.DataPortal_Insert", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Version.DataPortal_Insert", ex); + } + finally + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Version.DataPortal_Insert", GetHashCode()); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + internal void SQLInsert() + { + if (!this.IsDirty) return; + try + { + if (_MyRevision != null) _MyRevision.Update(); + if (_MyStage != null) _MyStage.Update(); + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "addVersion"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@RevisionID", RevisionID); + cm.Parameters.AddWithValue("@StageID", StageID); + cm.Parameters.AddWithValue("@PDF", _PDF); + cm.Parameters.AddWithValue("@SummaryPDF", _SummaryPDF); + if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS); + cm.Parameters.AddWithValue("@UserID", _UserID); + // Output Calculated Columns + SqlParameter param_VersionID = new SqlParameter("@newVersionID", SqlDbType.Int); + param_VersionID.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_VersionID); + 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 + _VersionID = (int)cm.Parameters["@newVersionID"].Value; + _LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value; + } + MarkOld(); + // update child objects + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Version.SQLInsert", GetHashCode()); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Version.SQLInsert", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Version.SQLInsert", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + public static byte[] Add(SqlConnection cn, ref int versionID, Revision myRevision, Stage myStage, byte[] pdf, byte[] summaryPDF, DateTime dts, string userID) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Version.Add", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "addVersion"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@RevisionID", myRevision.RevisionID); + cm.Parameters.AddWithValue("@StageID", myStage.StageID); + cm.Parameters.AddWithValue("@PDF", pdf); + cm.Parameters.AddWithValue("@SummaryPDF", summaryPDF); + if (dts.Year >= 1753 && dts.Year <= 9999) cm.Parameters.AddWithValue("@DTS", dts); + cm.Parameters.AddWithValue("@UserID", userID); + // Output Calculated Columns + SqlParameter param_VersionID = new SqlParameter("@newVersionID", SqlDbType.Int); + param_VersionID.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_VersionID); + 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 + versionID = (int)cm.Parameters["@newVersionID"].Value; + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Version.Add", ex); + throw new DbCslaException("Version.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}] Version.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("Version.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}] Version.SQLUpdate", GetHashCode()); + try + { + if (_MyRevision != null) _MyRevision.Update(); + if (_MyStage != null) _MyStage.Update(); + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + if (base.IsDirty) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "updateVersion"; + // All Fields including Calculated Fields + cm.Parameters.AddWithValue("@VersionID", _VersionID); + cm.Parameters.AddWithValue("@RevisionID", RevisionID); + cm.Parameters.AddWithValue("@StageID", StageID); + cm.Parameters.AddWithValue("@PDF", _PDF); + cm.Parameters.AddWithValue("@SummaryPDF", _SummaryPDF); + 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 + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Version.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 = Version.Add(cn, ref _VersionID, _MyRevision, _MyStage, _PDF, _SummaryPDF, _DTS, _UserID); + else + _LastChanged = Version.Update(cn, ref _VersionID, _RevisionID, _StageID, _PDF, _SummaryPDF, _DTS, _UserID, ref _LastChanged); + MarkOld(); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + public static byte[] Update(SqlConnection cn, ref int versionID, int revisionID, int stageID, byte[] pdf, byte[] summaryPDF, DateTime dts, string userID, ref byte[] lastChanged) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Version.Update", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "updateVersion"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@VersionID", versionID); + cm.Parameters.AddWithValue("@RevisionID", revisionID); + cm.Parameters.AddWithValue("@StageID", stageID); + cm.Parameters.AddWithValue("@PDF", pdf); + cm.Parameters.AddWithValue("@SummaryPDF", summaryPDF); + 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("Version.Update", ex); + throw new DbCslaException("Version.Update", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_DeleteSelf() + { + DataPortal_Delete(new PKCriteria(_VersionID)); + } + [Transactional(TransactionalTypes.TransactionScope)] + private void DataPortal_Delete(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Version.DataPortal_Delete", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "deleteVersion"; + cm.Parameters.AddWithValue("@VersionID", criteria.VersionID); + cm.ExecuteNonQuery(); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Version.DataPortal_Delete", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Version.DataPortal_Delete", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + public static void Remove(SqlConnection cn, int versionID) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Version.Remove", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "deleteVersion"; + // Input PK Fields + cm.Parameters.AddWithValue("@VersionID", versionID); + // CSLATODO: Define any additional output parameters + cm.ExecuteNonQuery(); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Version.Remove", ex); + throw new DbCslaException("Version.Remove", ex); + } + } + #endregion + #region Exists + public static bool Exists(int versionID) + { + ExistsCommand result; + try + { + result = DataPortal.Execute(new ExistsCommand(versionID)); + return result.Exists; + } + catch (Exception ex) + { + throw new DbCslaException("Error on Version.Exists", ex); + } + } + [Serializable()] + private class ExistsCommand : CommandBase + { + private int _VersionID; + private bool _exists; + public bool Exists + { + get { return _exists; } + } + public ExistsCommand(int versionID) + { + _VersionID = versionID; + } + protected override void DataPortal_Execute() + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Version.DataPortal_Execute", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + cn.Open(); + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "existsVersion"; + cm.Parameters.AddWithValue("@VersionID", _VersionID); + int count = (int)cm.ExecuteScalar(); + _exists = (count > 0); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Version.DataPortal_Execute", ex); + throw new DbCslaException("Version.DataPortal_Execute", ex); + } + } + } + #endregion + // Standard Default Code + #region extension + VersionExtension _VersionExtension = new VersionExtension(); + [Serializable()] + partial class VersionExtension : extensionBase + { + } + [Serializable()] + class extensionBase + { + // Default Values + // 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 VersionConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is Version) + { + // Return the ToString value + return ((Version)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion +} // Namespace + + +//// The following is a sample Extension File. You can use it to create VersionExt.cs +//using System; +//using System.Collections.Generic; +//using System.Text; +//using Csla; + +//namespace VEPROMS.CSLA.Library +//{ +// public partial class Version +// { +// partial class VersionExtension : extensionBase +// { +// // CSLATODO: Override automatic defaults +// public new void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) +// { +// //rules.AllowRead(Dbid, ""); +// } +// public new void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) +// { +// //rules.AllowInstanceRead(Dbid, ""); +// } +// 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 */); +// } +// } +// } +//} diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/VersionInfo.cs b/PROMS/VEPROMS.CSLA.Library/Generated/VersionInfo.cs new file mode 100644 index 00000000..2b848d4c --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/VersionInfo.cs @@ -0,0 +1,490 @@ +// ======================================================================== +// 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 VersionInfoEvent(object sender); + /// + /// VersionInfo Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(VersionInfoConverter))] + public partial class VersionInfo : ReadOnlyBase, IDisposable + { + public event VersionInfoEvent 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 _CacheList = new List(); + protected static void AddToCache(VersionInfo versionInfo) + { + if (!_CacheList.Contains(versionInfo)) _CacheList.Add(versionInfo); // In AddToCache + } + protected static void RemoveFromCache(VersionInfo versionInfo) + { + while (_CacheList.Contains(versionInfo)) _CacheList.Remove(versionInfo); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + while (_CacheList.Count > 0) // Move VersionInfo(s) from temporary _CacheList to _CacheByPrimaryKey + { + VersionInfo tmp = _CacheList[0]; // Get the first VersionInfo + string pKey = tmp.VersionID.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 VersionInfo + } + } + internal static void AddList(VersionInfoList lst) + { + foreach (VersionInfo item in lst) AddToCache(item); + } + protected static VersionInfo GetCachedByPrimaryKey(int versionID) + { + ConvertListToDictionary(); + string key = versionID.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 Version _Editable; + private IVEHasBrokenRules HasBrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = null; + if (_Editable != null) + hasBrokenRules = _Editable.HasBrokenRules; + return hasBrokenRules; + } + } + private int _VersionID; + [System.ComponentModel.DataObjectField(true, true)] + public int VersionID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("VersionID", true); + return _VersionID; + } + } + private int _RevisionID; + public int RevisionID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("RevisionID", true); + if (_MyRevision != null) _RevisionID = _MyRevision.RevisionID; + return _RevisionID; + } + } + private RevisionInfo _MyRevision; + public RevisionInfo MyRevision + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("MyRevision", true); + if (_MyRevision == null && _RevisionID != 0) _MyRevision = RevisionInfo.Get(_RevisionID); + return _MyRevision; + } + } + private int _StageID; + public int StageID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("StageID", true); + if (_MyStage != null) _StageID = _MyStage.StageID; + return _StageID; + } + } + private StageInfo _MyStage; + public StageInfo MyStage + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("MyStage", true); + if (_MyStage == null && _StageID != 0) _MyStage = StageInfo.Get(_StageID); + return _MyStage; + } + } + private byte[] _PDF; + public byte[] PDF + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("PDF", true); + return _PDF; + } + } + private byte[] _SummaryPDF; + public byte[] SummaryPDF + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("SummaryPDF", true); + return _SummaryPDF; + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("DTS", true); + return _DTS; + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("UserID", true); + return _UserID; + } + } + // CSLATODO: Replace base VersionInfo.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current VersionInfo + //public override string ToString() + //{ + // return base.ToString(); + //} + // CSLATODO: Check VersionInfo.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current VersionInfo + protected override object GetIdValue() + { + return MyVersionInfoUnique; // Absolutely Unique ID + } + #endregion + #region Factory Methods + private static int _VersionInfoUnique = 0; + private static int VersionInfoUnique + { get { return ++_VersionInfoUnique; } } + private int _MyVersionInfoUnique = VersionInfoUnique; + public int MyVersionInfoUnique // Absolutely Unique ID - Info + { get { return _MyVersionInfoUnique; } } + protected VersionInfo() + {/* require use of factory methods */ + AddToCache(this); + } + public void Dispose() + { + RemoveFromCache(this); + if (!_CacheByPrimaryKey.ContainsKey(VersionID.ToString())) return; + List listVersionInfo = _CacheByPrimaryKey[VersionID.ToString()]; // Get the list of items + while (listVersionInfo.Contains(this)) listVersionInfo.Remove(this); // Remove the item from the list + if (listVersionInfo.Count == 0) // If there are no items left in the list + _CacheByPrimaryKey.Remove(VersionID.ToString()); // remove the list + } + public virtual Version Get() + { + return _Editable = Version.Get(_VersionID); + } + public static void Refresh(Version tmp) + { + string key = tmp.VersionID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (VersionInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(Version tmp) + { + if (_RevisionID != tmp.RevisionID) + { + if (MyRevision != null) MyRevision.RefreshRevisionVersions(); // Update List for old value + _RevisionID = tmp.RevisionID; // Update the value + } + _MyRevision = null; // Reset list so that the next line gets a new list + if (MyRevision != null) MyRevision.RefreshRevisionVersions(); // Update List for new value + if (_StageID != tmp.StageID) + { + if (MyStage != null) MyStage.RefreshStageVersions(); // Update List for old value + _StageID = tmp.StageID; // Update the value + } + _MyStage = null; // Reset list so that the next line gets a new list + if (MyStage != null) MyStage.RefreshStageVersions(); // Update List for new value + _PDF = tmp.PDF; + _SummaryPDF = tmp.SummaryPDF; + _DTS = tmp.DTS; + _UserID = tmp.UserID; + _VersionInfoExtension.Refresh(this); +//RHM Removed 20090724 - Duplicates function of code above. +// - Dispose caused error when a new step was added. +// - Resequence of transitions did not work properly. +// if(_MyRevision != null) +// { +// _MyRevision.Dispose();// Dispose related value +// _MyRevision = null;// Reset related value +// } +//RHM Removed 20090724 - Duplicates function of code above. +// - Dispose caused error when a new step was added. +// - Resequence of transitions did not work properly. +// if(_MyStage != null) +// { +// _MyStage.Dispose();// Dispose related value +// _MyStage = null;// Reset related value +// } + OnChange();// raise an event + } + public static void Refresh(RevisionVersion tmp) + { + string key = tmp.VersionID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (VersionInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(RevisionVersion tmp) + { + if (_StageID != tmp.StageID) + { + if (MyStage != null) MyStage.RefreshStageVersions(); // Update List for old value + _StageID = tmp.StageID; // Update the value + } + _MyStage = null; // Reset list so that the next line gets a new list + if (MyStage != null) MyStage.RefreshStageVersions(); // Update List for new value + _PDF = tmp.PDF; + _SummaryPDF = tmp.SummaryPDF; + _DTS = tmp.DTS; + _UserID = tmp.UserID; + _VersionInfoExtension.Refresh(this); +//RHM Removed 20090724 - Duplicates function of code above. +// - Dispose caused error when a new step was added. +// - Resequence of transitions did not work properly. +// if(_MyRevision != null) +// { +// _MyRevision.Dispose();// Dispose related value +// _MyRevision = null;// Reset related value +// } +//RHM Removed 20090724 - Duplicates function of code above. +// - Dispose caused error when a new step was added. +// - Resequence of transitions did not work properly. +// if(_MyStage != null) +// { +// _MyStage.Dispose();// Dispose related value +// _MyStage = null;// Reset related value +// } + OnChange();// raise an event + } + public static void Refresh(StageVersion tmp) + { + string key = tmp.VersionID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (VersionInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(StageVersion tmp) + { + if (_RevisionID != tmp.RevisionID) + { + if (MyRevision != null) MyRevision.RefreshRevisionVersions(); // Update List for old value + _RevisionID = tmp.RevisionID; // Update the value + } + _MyRevision = null; // Reset list so that the next line gets a new list + if (MyRevision != null) MyRevision.RefreshRevisionVersions(); // Update List for new value + _PDF = tmp.PDF; + _SummaryPDF = tmp.SummaryPDF; + _DTS = tmp.DTS; + _UserID = tmp.UserID; + _VersionInfoExtension.Refresh(this); +//RHM Removed 20090724 - Duplicates function of code above. +// - Dispose caused error when a new step was added. +// - Resequence of transitions did not work properly. +// if(_MyRevision != null) +// { +// _MyRevision.Dispose();// Dispose related value +// _MyRevision = null;// Reset related value +// } +//RHM Removed 20090724 - Duplicates function of code above. +// - Dispose caused error when a new step was added. +// - Resequence of transitions did not work properly. +// if(_MyStage != null) +// { +// _MyStage.Dispose();// Dispose related value +// _MyStage = null;// Reset related value +// } + OnChange();// raise an event + } + public static VersionInfo Get(int versionID) + { + //if (!CanGetObject()) + // throw new System.Security.SecurityException("User not authorized to view a Version"); + try + { + VersionInfo tmp = GetCachedByPrimaryKey(versionID); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(versionID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up VersionInfo + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on VersionInfo.Get", ex); + } + } + #endregion + #region Data Access Portal + internal VersionInfo(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] VersionInfo.Constructor", GetHashCode()); + try + { + ReadData(dr); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("VersionInfo.Constructor", ex); + throw new DbCslaException("VersionInfo.Constructor", ex); + } + } + [Serializable()] + protected class PKCriteria + { + private int _VersionID; + public int VersionID + { get { return _VersionID; } } + public PKCriteria(int versionID) + { + _VersionID = versionID; + } + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] VersionInfo.ReadData", GetHashCode()); + try + { + _VersionID = dr.GetInt32("VersionID"); + _RevisionID = dr.GetInt32("RevisionID"); + _StageID = dr.GetInt32("StageID"); + _PDF = (byte[])dr.GetValue("PDF"); + _SummaryPDF = (byte[])dr.GetValue("SummaryPDF"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("VersionInfo.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("VersionInfo.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] VersionInfo.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 = "getVersion"; + cm.Parameters.AddWithValue("@VersionID", criteria.VersionID); + 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("VersionInfo.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("VersionInfo.DataPortal_Fetch", ex); + } + } + #endregion + // Standard Refresh + #region extension + VersionInfoExtension _VersionInfoExtension = new VersionInfoExtension(); + [Serializable()] + partial class VersionInfoExtension : extensionBase { } + [Serializable()] + class extensionBase + { + // Default Refresh + public virtual void Refresh(VersionInfo tmp) { } + } + #endregion + } // Class + #region Converter + internal class VersionInfoConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is VersionInfo) + { + // Return the ToString value + return ((VersionInfo)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion +} // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/VersionInfoList.cs b/PROMS/VEPROMS.CSLA.Library/Generated/VersionInfoList.cs new file mode 100644 index 00000000..97fbc55b --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/VersionInfoList.cs @@ -0,0 +1,319 @@ +// ======================================================================== +// 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 +{ + /// + /// VersionInfoList Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(VersionInfoListConverter))] + public partial class VersionInfoList : ReadOnlyListBase, ICustomTypeDescriptor, IDisposable + { + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Business Methods + internal new IList Items + { get { return base.Items; } } + public void AddEvents() + { + foreach (VersionInfo tmp in this) + { + tmp.Changed += new VersionInfoEvent(tmp_Changed); + } + } + void tmp_Changed(object sender) + { + for (int i = 0; i < Count; i++) + { + if (base[i] == sender) + this.OnListChanged(new ListChangedEventArgs(ListChangedType.ItemChanged, i)); + } + } + public void Dispose() + { + foreach (VersionInfo tmp in this) + { + tmp.Changed -= new VersionInfoEvent(tmp_Changed); + } + } + #endregion + #region Factory Methods + public static VersionInfoList _VersionInfoList = null; + /// + /// Return a list of all VersionInfo. + /// + public static VersionInfoList Get() + { + try + { + if (_VersionInfoList != null) + return _VersionInfoList; + VersionInfoList tmp = DataPortal.Fetch(); + VersionInfo.AddList(tmp); + tmp.AddEvents(); + _VersionInfoList = tmp; + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on VersionInfoList.Get", ex); + } + } + /// + /// Reset the list of all VersionInfo. + /// + public static void Reset() + { + _VersionInfoList = null; + } + // CSLATODO: Add alternative gets - + //public static VersionInfoList Get() + //{ + // try + // { + // return DataPortal.Fetch(new FilteredCriteria()); + // } + // catch (Exception ex) + // { + // throw new DbCslaException("Error on VersionInfoList.Get", ex); + // } + //} + public static VersionInfoList GetByRevisionID(int revisionID) + { + try + { + VersionInfoList tmp = DataPortal.Fetch(new RevisionIDCriteria(revisionID)); + VersionInfo.AddList(tmp); + tmp.AddEvents(); + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on VersionInfoList.GetByRevisionID", ex); + } + } + public static VersionInfoList GetByStageID(int stageID) + { + try + { + VersionInfoList tmp = DataPortal.Fetch(new StageIDCriteria(stageID)); + VersionInfo.AddList(tmp); + tmp.AddEvents(); + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on VersionInfoList.GetByStageID", ex); + } + } + private VersionInfoList() + { /* require use of factory methods */ } + #endregion + #region Data Access Portal + private void DataPortal_Fetch() + { + this.RaiseListChangedEvents = false; + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] VersionInfoList.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getVersions"; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + IsReadOnly = false; + while (dr.Read()) this.Add(new VersionInfo(dr)); + IsReadOnly = true; + } + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("VersionInfoList.DataPortal_Fetch", ex); + throw new DbCslaException("VersionInfoList.DataPortal_Fetch", ex); + } + this.RaiseListChangedEvents = true; + } + [Serializable()] + private class RevisionIDCriteria + { + public RevisionIDCriteria(int revisionID) + { + _RevisionID = revisionID; + } + private int _RevisionID; + public int RevisionID + { + get { return _RevisionID; } + set { _RevisionID = value; } + } + } + private void DataPortal_Fetch(RevisionIDCriteria criteria) + { + this.RaiseListChangedEvents = false; + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] VersionInfoList.DataPortal_FetchRevisionID", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getVersionsByRevisionID"; + cm.Parameters.AddWithValue("@RevisionID", criteria.RevisionID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + IsReadOnly = false; + while (dr.Read()) this.Add(new VersionInfo(dr)); + IsReadOnly = true; + } + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("VersionInfoList.DataPortal_FetchRevisionID", ex); + throw new DbCslaException("VersionInfoList.DataPortal_Fetch", ex); + } + this.RaiseListChangedEvents = true; + } + [Serializable()] + private class StageIDCriteria + { + public StageIDCriteria(int stageID) + { + _StageID = stageID; + } + private int _StageID; + public int StageID + { + get { return _StageID; } + set { _StageID = value; } + } + } + private void DataPortal_Fetch(StageIDCriteria criteria) + { + this.RaiseListChangedEvents = false; + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] VersionInfoList.DataPortal_FetchStageID", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getVersionsByStageID"; + cm.Parameters.AddWithValue("@StageID", criteria.StageID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + IsReadOnly = false; + while (dr.Read()) this.Add(new VersionInfo(dr)); + IsReadOnly = true; + } + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("VersionInfoList.DataPortal_FetchStageID", ex); + throw new DbCslaException("VersionInfoList.DataPortal_Fetch", ex); + } + this.RaiseListChangedEvents = true; + } + #endregion + #region ICustomTypeDescriptor impl + public String GetClassName() + { return TypeDescriptor.GetClassName(this, true); } + public AttributeCollection GetAttributes() + { return TypeDescriptor.GetAttributes(this, true); } + public String GetComponentName() + { return TypeDescriptor.GetComponentName(this, true); } + public TypeConverter GetConverter() + { return TypeDescriptor.GetConverter(this, true); } + public EventDescriptor GetDefaultEvent() + { return TypeDescriptor.GetDefaultEvent(this, true); } + public PropertyDescriptor GetDefaultProperty() + { return TypeDescriptor.GetDefaultProperty(this, true); } + public object GetEditor(Type editorBaseType) + { return TypeDescriptor.GetEditor(this, editorBaseType, true); } + public EventDescriptorCollection GetEvents(Attribute[] attributes) + { return TypeDescriptor.GetEvents(this, attributes, true); } + public EventDescriptorCollection GetEvents() + { return TypeDescriptor.GetEvents(this, true); } + public object GetPropertyOwner(PropertyDescriptor pd) + { return this; } + /// + /// Called to get the properties of this type. Returns properties with certain + /// attributes. this restriction is not implemented here. + /// + /// + /// + public PropertyDescriptorCollection GetProperties(Attribute[] attributes) + { return GetProperties(); } + /// + /// Called to get the properties of this type. + /// + /// + public PropertyDescriptorCollection GetProperties() + { + // Create a collection object to hold property descriptors + PropertyDescriptorCollection pds = new PropertyDescriptorCollection(null); + // Iterate the list + for (int i = 0; i < this.Items.Count; i++) + { + // Create a property descriptor for the item and add to the property descriptor collection + VersionInfoListPropertyDescriptor pd = new VersionInfoListPropertyDescriptor(this, i); + pds.Add(pd); + } + // return the property descriptor collection + return pds; + } + #endregion + } // Class + #region Property Descriptor + /// + /// Summary description for CollectionPropertyDescriptor. + /// + public partial class VersionInfoListPropertyDescriptor : vlnListPropertyDescriptor + { + private VersionInfo Item { get { return (VersionInfo)_Item; } } + public VersionInfoListPropertyDescriptor(VersionInfoList collection, int index) : base(collection, index) { ;} + } + #endregion + #region Converter + internal class VersionInfoListConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is VersionInfoList) + { + // Return department and department role separated by comma. + return ((VersionInfoList)value).Items.Count.ToString() + " Versions"; + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion +} // Namespace