From 1d910db31a38170ac12e1efc12d42fb6e76670f7 Mon Sep 17 00:00:00 2001 From: Rich Date: Mon, 1 Aug 2011 20:18:58 +0000 Subject: [PATCH] Change Manager --- .../Generated/AnnotationAudit.cs | 1090 +++++++++++++++++ .../Generated/AnnotationAuditInfo.cs | 394 ++++++ .../Generated/AnnotationAuditInfoList.cs | 205 ++++ .../Generated/ContentAudit.cs | 1035 ++++++++++++++++ .../Generated/ContentAuditInfo.cs | 394 ++++++ .../Generated/ContentAuditInfoList.cs | 205 ++++ .../Generated/DocumentAudit.cs | 1070 ++++++++++++++++ .../Generated/DocumentAuditInfo.cs | 406 ++++++ .../Generated/DocumentAuditInfoList.cs | 205 ++++ .../Generated/EntryAudit.cs | 902 ++++++++++++++ .../Generated/EntryAuditInfo.cs | 346 ++++++ .../Generated/EntryAuditInfoList.cs | 205 ++++ .../Generated/GridAudit.cs | 1070 ++++++++++++++++ .../Generated/GridAuditInfo.cs | 370 ++++++ .../Generated/GridAuditInfoList.cs | 205 ++++ .../Generated/ImageAudit.cs | 1008 +++++++++++++++ .../Generated/ImageAuditInfo.cs | 382 ++++++ .../Generated/ImageAuditInfoList.cs | 205 ++++ .../Generated/ItemAudit.cs | 940 ++++++++++++++ .../Generated/ItemAuditInfo.cs | 358 ++++++ .../Generated/ItemAuditInfoList.cs | 205 ++++ .../Generated/PartAudit.cs | 930 ++++++++++++++ .../Generated/PartAuditInfo.cs | 358 ++++++ .../Generated/PartAuditInfoList.cs | 205 ++++ 24 files changed, 12693 insertions(+) create mode 100644 PROMS/VEPROMS.CSLA.Library/Generated/AnnotationAudit.cs create mode 100644 PROMS/VEPROMS.CSLA.Library/Generated/AnnotationAuditInfo.cs create mode 100644 PROMS/VEPROMS.CSLA.Library/Generated/AnnotationAuditInfoList.cs create mode 100644 PROMS/VEPROMS.CSLA.Library/Generated/ContentAudit.cs create mode 100644 PROMS/VEPROMS.CSLA.Library/Generated/ContentAuditInfo.cs create mode 100644 PROMS/VEPROMS.CSLA.Library/Generated/ContentAuditInfoList.cs create mode 100644 PROMS/VEPROMS.CSLA.Library/Generated/DocumentAudit.cs create mode 100644 PROMS/VEPROMS.CSLA.Library/Generated/DocumentAuditInfo.cs create mode 100644 PROMS/VEPROMS.CSLA.Library/Generated/DocumentAuditInfoList.cs create mode 100644 PROMS/VEPROMS.CSLA.Library/Generated/EntryAudit.cs create mode 100644 PROMS/VEPROMS.CSLA.Library/Generated/EntryAuditInfo.cs create mode 100644 PROMS/VEPROMS.CSLA.Library/Generated/EntryAuditInfoList.cs create mode 100644 PROMS/VEPROMS.CSLA.Library/Generated/GridAudit.cs create mode 100644 PROMS/VEPROMS.CSLA.Library/Generated/GridAuditInfo.cs create mode 100644 PROMS/VEPROMS.CSLA.Library/Generated/GridAuditInfoList.cs create mode 100644 PROMS/VEPROMS.CSLA.Library/Generated/ImageAudit.cs create mode 100644 PROMS/VEPROMS.CSLA.Library/Generated/ImageAuditInfo.cs create mode 100644 PROMS/VEPROMS.CSLA.Library/Generated/ImageAuditInfoList.cs create mode 100644 PROMS/VEPROMS.CSLA.Library/Generated/ItemAudit.cs create mode 100644 PROMS/VEPROMS.CSLA.Library/Generated/ItemAuditInfo.cs create mode 100644 PROMS/VEPROMS.CSLA.Library/Generated/ItemAuditInfoList.cs create mode 100644 PROMS/VEPROMS.CSLA.Library/Generated/PartAudit.cs create mode 100644 PROMS/VEPROMS.CSLA.Library/Generated/PartAuditInfo.cs create mode 100644 PROMS/VEPROMS.CSLA.Library/Generated/PartAuditInfoList.cs diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/AnnotationAudit.cs b/PROMS/VEPROMS.CSLA.Library/Generated/AnnotationAudit.cs new file mode 100644 index 00000000..760fdd4a --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/AnnotationAudit.cs @@ -0,0 +1,1090 @@ +// ======================================================================== +// 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 +{ + /// + /// AnnotationAudit Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(AnnotationAuditConverter))] + public partial class AnnotationAudit : BusinessBase, IDisposable, IVEHasBrokenRules + { + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Refresh + private List _RefreshAnnotationAudits = new List(); + private void AddToRefreshList(List refreshAnnotationAudits) + { + if (IsDirty) + refreshAnnotationAudits.Add(this); + } + private void BuildRefreshList() + { + _RefreshAnnotationAudits = new List(); + AddToRefreshList(_RefreshAnnotationAudits); + } + private void ProcessRefreshList() + { + foreach (AnnotationAudit tmp in _RefreshAnnotationAudits) + { + AnnotationAuditInfo.Refresh(tmp); + } + } + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(AnnotationAudit annotationAudit) + { + if (!_CacheList.Contains(annotationAudit)) _CacheList.Add(annotationAudit); // In AddToCache + } + protected static void RemoveFromCache(AnnotationAudit annotationAudit) + { + while (_CacheList.Contains(annotationAudit)) _CacheList.Remove(annotationAudit); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + while (_CacheList.Count > 0) // Move AnnotationAudit(s) from temporary _CacheList to _CacheByPrimaryKey + { + AnnotationAudit tmp = _CacheList[0]; // Get the first AnnotationAudit + string pKey = tmp.AuditID.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 AnnotationAudit + } + } + protected static AnnotationAudit GetCachedByPrimaryKey(long auditID) + { + ConvertListToDictionary(); + string key = auditID.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 _nextAuditID = -1; + public static int NextAuditID + { + get { return _nextAuditID--; } + } + private long _AuditID; + [System.ComponentModel.DataObjectField(true, true)] + public long AuditID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("AuditID", true); + return _AuditID; + } + } + private int _AnnotationID; + public int AnnotationID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("AnnotationID", true); + return _AnnotationID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + CanWriteProperty("AnnotationID", true); + if (_AnnotationID != value) + { + _AnnotationID = value; + PropertyHasChanged(); + } + } + } + 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 _RtfText = string.Empty; + public string RtfText + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("RtfText", true); + return _RtfText; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + CanWriteProperty("RtfText", true); + if (value == null) value = string.Empty; + if (_RtfText != value) + { + _RtfText = value; + PropertyHasChanged(); + } + } + } + private string _SearchText = string.Empty; + public string SearchText + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("SearchText", true); + return _SearchText; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + CanWriteProperty("SearchText", true); + if (value == null) value = string.Empty; + if (_SearchText != value) + { + _SearchText = 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 int _DeleteStatus; + public int DeleteStatus + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("DeleteStatus", true); + return _DeleteStatus; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + CanWriteProperty("DeleteStatus", true); + if (_DeleteStatus != value) + { + _DeleteStatus = value; + PropertyHasChanged(); + } + } + } + public override bool IsDirty + { + get { return base.IsDirty; } + } + public bool IsDirtyList(List list) + { + return base.IsDirty; + } + public override bool IsValid + { + get { return (IsNew && !IsDirty) ? true : base.IsValid; } + } + public bool IsValidList(List list) + { + return (IsNew && !IsDirty) ? true : base.IsValid; + } + // CSLATODO: Replace base AnnotationAudit.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current AnnotationAudit + //public override string ToString() + //{ + // return base.ToString(); + //} + // CSLATODO: Check AnnotationAudit.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 AnnotationAudit + protected override object GetIdValue() + { + return MyAnnotationAuditUnique; // 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; + 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("RtfText", 1073741823)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("SearchText", 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", 200)); + //ValidationRules.AddDependantProperty("x", "y"); + _AnnotationAuditExtension.AddValidationRules(ValidationRules); + // CSLATODO: Add other validation rules + } + protected override void AddInstanceBusinessRules() + { + _AnnotationAuditExtension.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(AuditID, ""); + //AuthorizationRules.AllowRead(AnnotationID, ""); + //AuthorizationRules.AllowRead(ItemID, ""); + //AuthorizationRules.AllowRead(TypeID, ""); + //AuthorizationRules.AllowRead(RtfText, ""); + //AuthorizationRules.AllowRead(SearchText, ""); + //AuthorizationRules.AllowRead(Config, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowRead(UserID, ""); + //AuthorizationRules.AllowRead(DeleteStatus, ""); + //AuthorizationRules.AllowWrite(AnnotationID, ""); + //AuthorizationRules.AllowWrite(ItemID, ""); + //AuthorizationRules.AllowWrite(TypeID, ""); + //AuthorizationRules.AllowWrite(RtfText, ""); + //AuthorizationRules.AllowWrite(SearchText, ""); + //AuthorizationRules.AllowWrite(Config, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowWrite(UserID, ""); + //AuthorizationRules.AllowWrite(DeleteStatus, ""); + _AnnotationAuditExtension.AddAuthorizationRules(AuthorizationRules); + } + protected override void AddInstanceAuthorizationRules() + { + //CSLATODO: Who can read/write which fields + _AnnotationAuditExtension.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 _AnnotationAuditUnique = 0; + protected static int AnnotationAuditUnique + { get { return ++_AnnotationAuditUnique; } } + private int _MyAnnotationAuditUnique = AnnotationAuditUnique; + public int MyAnnotationAuditUnique // Absolutely Unique ID - Editable + { get { return _MyAnnotationAuditUnique; } } + protected AnnotationAudit() + {/* require use of factory methods */ + AddToCache(this); + } + public void Dispose() + { + RemoveFromDictionaries(); + } + private void RemoveFromDictionaries() + { + RemoveFromCache(this); + if (_CacheByPrimaryKey.ContainsKey(AuditID.ToString())) + { + List listAnnotationAudit = _CacheByPrimaryKey[AuditID.ToString()]; // Get the list of items + while (listAnnotationAudit.Contains(this)) listAnnotationAudit.Remove(this); // Remove the item from the list + if (listAnnotationAudit.Count == 0) //If there are no items left in the list + _CacheByPrimaryKey.Remove(AuditID.ToString()); // remove the list + } + } + public static AnnotationAudit New() + { + if (!CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a AnnotationAudit"); + try + { + return DataPortal.Create(); + } + catch (Exception ex) + { + throw new DbCslaException("Error on AnnotationAudit.New", ex); + } + } + public static AnnotationAudit New(int annotationID, int itemID, int typeID, DateTime dts, string userID, int deleteStatus) + { + AnnotationAudit tmp = AnnotationAudit.New(); + tmp.AnnotationID = annotationID; + tmp.ItemID = itemID; + tmp.TypeID = typeID; + tmp.DTS = dts; + tmp.UserID = userID; + tmp.DeleteStatus = deleteStatus; + return tmp; + } + public static AnnotationAudit New(int annotationID, int itemID, int typeID, string rtfText, string searchText, string config, DateTime dts, string userID, int deleteStatus) + { + AnnotationAudit tmp = AnnotationAudit.New(); + tmp.AnnotationID = annotationID; + tmp.ItemID = itemID; + tmp.TypeID = typeID; + tmp.RtfText = rtfText; + tmp.SearchText = searchText; + tmp.Config = config; + tmp.DTS = dts; + tmp.UserID = userID; + tmp.DeleteStatus = deleteStatus; + return tmp; + } + public static AnnotationAudit MakeAnnotationAudit(int annotationID, int itemID, int typeID, string rtfText, string searchText, string config, DateTime dts, string userID, int deleteStatus) + { + AnnotationAudit tmp = AnnotationAudit.New(annotationID, itemID, typeID, rtfText, searchText, config, dts, userID, deleteStatus); + if (tmp.IsSavable) + { + AnnotationAudit 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 AnnotationAudit Get(long auditID) + { + if (!CanGetObject()) + throw new System.Security.SecurityException("User not authorized to view a AnnotationAudit"); + try + { + AnnotationAudit tmp = GetCachedByPrimaryKey(auditID); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(auditID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up AnnotationAudit + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on AnnotationAudit.Get", ex); + } + } + public static AnnotationAudit Get(SafeDataReader dr) + { + if (dr.Read()) return new AnnotationAudit(dr); + return null; + } + internal AnnotationAudit(SafeDataReader dr) + { + ReadData(dr); + } + public static void Delete(long auditID) + { + if (!CanDeleteObject()) + throw new System.Security.SecurityException("User not authorized to remove a AnnotationAudit"); + try + { + DataPortal.Delete(new PKCriteria(auditID)); + } + catch (Exception ex) + { + throw new DbCslaException("Error on AnnotationAudit.Delete", ex); + } + } + public override AnnotationAudit Save() + { + if (IsDeleted && !CanDeleteObject()) + throw new System.Security.SecurityException("User not authorized to remove a AnnotationAudit"); + else if (IsNew && !CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a AnnotationAudit"); + else if (!CanEditObject()) + throw new System.Security.SecurityException("User not authorized to update a AnnotationAudit"); + try + { + BuildRefreshList(); + AnnotationAudit annotationAudit = base.Save(); + RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache + AddToCache(annotationAudit);//Refresh the item in AllList + ProcessRefreshList(); + return annotationAudit; + } + catch (Exception ex) + { + throw new DbCslaException("Error on CSLA Save", ex); + } + } + #endregion + #region Data Access Portal + [Serializable()] + protected class PKCriteria + { + private long _AuditID; + public long AuditID + { get { return _AuditID; } } + public PKCriteria(long auditID) + { + _AuditID = auditID; + } + } + // CSLATODO: If Create needs to access DB - It should not be marked RunLocal + [RunLocal()] + private new void DataPortal_Create() + { + _AuditID = NextAuditID; + // Database Defaults + + // CSLATODO: Add any defaults that are necessary + ValidationRules.CheckRules(); + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] AnnotationAudit.ReadData", GetHashCode()); + try + { + _AuditID = dr.GetInt64("AuditID"); + _AnnotationID = dr.GetInt32("AnnotationID"); + _ItemID = dr.GetInt32("ItemID"); + _TypeID = dr.GetInt32("TypeID"); + _RtfText = dr.GetString("RtfText"); + _SearchText = dr.GetString("SearchText"); + _Config = dr.GetString("Config"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + _DeleteStatus = dr.GetInt32("DeleteStatus"); + MarkOld(); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("AnnotationAudit.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("AnnotationAudit.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] AnnotationAudit.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 = "getAnnotationAudit"; + cm.Parameters.AddWithValue("@AuditID", criteria.AuditID); + 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("AnnotationAudit.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("AnnotationAudit.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("AnnotationAudit.DataPortal_Insert", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("AnnotationAudit.DataPortal_Insert", ex); + } + finally + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] AnnotationAudit.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 = "addAnnotationAudit"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@AnnotationID", _AnnotationID); + cm.Parameters.AddWithValue("@ItemID", _ItemID); + cm.Parameters.AddWithValue("@TypeID", _TypeID); + cm.Parameters.AddWithValue("@RtfText", _RtfText); + cm.Parameters.AddWithValue("@SearchText", _SearchText); + 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("@DeleteStatus", _DeleteStatus); + // Output Calculated Columns + SqlParameter param_AuditID = new SqlParameter("@newAuditID", SqlDbType.BigInt); + param_AuditID.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_AuditID); + // CSLATODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + _AuditID = (long)cm.Parameters["@newAuditID"].Value; + } + MarkOld(); + // update child objects + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] AnnotationAudit.SQLInsert", GetHashCode()); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("AnnotationAudit.SQLInsert", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("AnnotationAudit.SQLInsert", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + public static void Add(SqlConnection cn, ref long auditID, int annotationID, int itemID, int typeID, string rtfText, string searchText, string config, DateTime dts, string userID, int deleteStatus) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] AnnotationAudit.Add", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "addAnnotationAudit"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@AnnotationID", annotationID); + cm.Parameters.AddWithValue("@ItemID", itemID); + cm.Parameters.AddWithValue("@TypeID", typeID); + cm.Parameters.AddWithValue("@RtfText", rtfText); + cm.Parameters.AddWithValue("@SearchText", searchText); + 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("@DeleteStatus", deleteStatus); + // Output Calculated Columns + SqlParameter param_AuditID = new SqlParameter("@newAuditID", SqlDbType.BigInt); + param_AuditID.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_AuditID); + // CSLATODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + auditID = (long)cm.Parameters["@newAuditID"].Value; + // No Timestamp value to return + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("AnnotationAudit.Add", ex); + throw new DbCslaException("AnnotationAudit.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}] AnnotationAudit.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("AnnotationAudit.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}] AnnotationAudit.SQLUpdate", GetHashCode()); + try + { + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + if (base.IsDirty) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "updateAnnotationAudit"; + // All Fields including Calculated Fields + cm.Parameters.AddWithValue("@AuditID", _AuditID); + cm.Parameters.AddWithValue("@AnnotationID", _AnnotationID); + cm.Parameters.AddWithValue("@ItemID", _ItemID); + cm.Parameters.AddWithValue("@TypeID", _TypeID); + cm.Parameters.AddWithValue("@RtfText", _RtfText); + cm.Parameters.AddWithValue("@SearchText", _SearchText); + 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("@DeleteStatus", _DeleteStatus); + // Output Calculated Columns + // CSLATODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + } + } + MarkOld(); + // use the open connection to update child objects + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("AnnotationAudit.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) + AnnotationAudit.Add(cn, ref _AuditID, _AnnotationID, _ItemID, _TypeID, _RtfText, _SearchText, _Config, _DTS, _UserID, _DeleteStatus); + else + AnnotationAudit.Update(cn, ref _AuditID, _AnnotationID, _ItemID, _TypeID, _RtfText, _SearchText, _Config, _DTS, _UserID, _DeleteStatus); + MarkOld(); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + public static void Update(SqlConnection cn, ref long auditID, int annotationID, int itemID, int typeID, string rtfText, string searchText, string config, DateTime dts, string userID, int deleteStatus) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] AnnotationAudit.Update", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "updateAnnotationAudit"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@AuditID", auditID); + cm.Parameters.AddWithValue("@AnnotationID", annotationID); + cm.Parameters.AddWithValue("@ItemID", itemID); + cm.Parameters.AddWithValue("@TypeID", typeID); + cm.Parameters.AddWithValue("@RtfText", rtfText); + cm.Parameters.AddWithValue("@SearchText", searchText); + 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("@DeleteStatus", deleteStatus); + // Output Calculated Columns + // CSLATODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + // No Timestamp value to return + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("AnnotationAudit.Update", ex); + throw new DbCslaException("AnnotationAudit.Update", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_DeleteSelf() + { + DataPortal_Delete(new PKCriteria(_AuditID)); + } + [Transactional(TransactionalTypes.TransactionScope)] + private void DataPortal_Delete(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] AnnotationAudit.DataPortal_Delete", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "deleteAnnotationAudit"; + cm.Parameters.AddWithValue("@AuditID", criteria.AuditID); + cm.ExecuteNonQuery(); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("AnnotationAudit.DataPortal_Delete", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("AnnotationAudit.DataPortal_Delete", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + public static void Remove(SqlConnection cn, long auditID) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] AnnotationAudit.Remove", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "deleteAnnotationAudit"; + // Input PK Fields + cm.Parameters.AddWithValue("@AuditID", auditID); + // CSLATODO: Define any additional output parameters + cm.ExecuteNonQuery(); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("AnnotationAudit.Remove", ex); + throw new DbCslaException("AnnotationAudit.Remove", ex); + } + } + #endregion + #region Exists + public static bool Exists(long auditID) + { + ExistsCommand result; + try + { + result = DataPortal.Execute(new ExistsCommand(auditID)); + return result.Exists; + } + catch (Exception ex) + { + throw new DbCslaException("Error on AnnotationAudit.Exists", ex); + } + } + [Serializable()] + private class ExistsCommand : CommandBase + { + private long _AuditID; + private bool _exists; + public bool Exists + { + get { return _exists; } + } + public ExistsCommand(long auditID) + { + _AuditID = auditID; + } + protected override void DataPortal_Execute() + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] AnnotationAudit.DataPortal_Execute", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + cn.Open(); + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "existsAnnotationAudit"; + cm.Parameters.AddWithValue("@AuditID", _AuditID); + int count = (int)cm.ExecuteScalar(); + _exists = (count > 0); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("AnnotationAudit.DataPortal_Execute", ex); + throw new DbCslaException("AnnotationAudit.DataPortal_Execute", ex); + } + } + } + #endregion + // Standard Default Code + #region extension + AnnotationAuditExtension _AnnotationAuditExtension = new AnnotationAuditExtension(); + [Serializable()] + partial class AnnotationAuditExtension : 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 AnnotationAuditConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is AnnotationAudit) + { + // Return the ToString value + return ((AnnotationAudit)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion +} // Namespace + + +//// The following is a sample Extension File. You can use it to create AnnotationAuditExt.cs +//using System; +//using System.Collections.Generic; +//using System.Text; +//using Csla; + +//namespace VEPROMS.CSLA.Library +//{ +// public partial class AnnotationAudit +// { +// partial class AnnotationAuditExtension : 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/AnnotationAuditInfo.cs b/PROMS/VEPROMS.CSLA.Library/Generated/AnnotationAuditInfo.cs new file mode 100644 index 00000000..f6a346ab --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/AnnotationAuditInfo.cs @@ -0,0 +1,394 @@ +// ======================================================================== +// 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 AnnotationAuditInfoEvent(object sender); + /// + /// AnnotationAuditInfo Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(AnnotationAuditInfoConverter))] + public partial class AnnotationAuditInfo : ReadOnlyBase, IDisposable + { + public event AnnotationAuditInfoEvent 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(AnnotationAuditInfo annotationAuditInfo) + { + if (!_CacheList.Contains(annotationAuditInfo)) _CacheList.Add(annotationAuditInfo); // In AddToCache + } + protected static void RemoveFromCache(AnnotationAuditInfo annotationAuditInfo) + { + while (_CacheList.Contains(annotationAuditInfo)) _CacheList.Remove(annotationAuditInfo); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + while (_CacheList.Count > 0) // Move AnnotationAuditInfo(s) from temporary _CacheList to _CacheByPrimaryKey + { + AnnotationAuditInfo tmp = _CacheList[0]; // Get the first AnnotationAuditInfo + string pKey = tmp.AuditID.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 AnnotationAuditInfo + } + } + internal static void AddList(AnnotationAuditInfoList lst) + { + foreach (AnnotationAuditInfo item in lst) AddToCache(item); + } + protected static AnnotationAuditInfo GetCachedByPrimaryKey(long auditID) + { + ConvertListToDictionary(); + string key = auditID.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 AnnotationAudit _Editable; + private IVEHasBrokenRules HasBrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = null; + if (_Editable != null) + hasBrokenRules = _Editable.HasBrokenRules; + return hasBrokenRules; + } + } + private long _AuditID; + [System.ComponentModel.DataObjectField(true, true)] + public long AuditID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("AuditID", true); + return _AuditID; + } + } + private int _AnnotationID; + public int AnnotationID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("AnnotationID", true); + return _AnnotationID; + } + } + 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 _RtfText = string.Empty; + public string RtfText + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("RtfText", true); + return _RtfText; + } + } + private string _SearchText = string.Empty; + public string SearchText + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("SearchText", true); + return _SearchText; + } + } + 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 _DeleteStatus; + public int DeleteStatus + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("DeleteStatus", true); + return _DeleteStatus; + } + } + // CSLATODO: Replace base AnnotationAuditInfo.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current AnnotationAuditInfo + //public override string ToString() + //{ + // return base.ToString(); + //} + // CSLATODO: Check AnnotationAuditInfo.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 AnnotationAuditInfo + protected override object GetIdValue() + { + return MyAnnotationAuditInfoUnique; // Absolutely Unique ID + } + #endregion + #region Factory Methods + private static int _AnnotationAuditInfoUnique = 0; + private static int AnnotationAuditInfoUnique + { get { return ++_AnnotationAuditInfoUnique; } } + private int _MyAnnotationAuditInfoUnique = AnnotationAuditInfoUnique; + public int MyAnnotationAuditInfoUnique // Absolutely Unique ID - Info + { get { return _MyAnnotationAuditInfoUnique; } } + protected AnnotationAuditInfo() + {/* require use of factory methods */ + AddToCache(this); + } + public void Dispose() + { + RemoveFromCache(this); + if (!_CacheByPrimaryKey.ContainsKey(AuditID.ToString())) return; + List listAnnotationAuditInfo = _CacheByPrimaryKey[AuditID.ToString()]; // Get the list of items + while (listAnnotationAuditInfo.Contains(this)) listAnnotationAuditInfo.Remove(this); // Remove the item from the list + if (listAnnotationAuditInfo.Count == 0) // If there are no items left in the list + _CacheByPrimaryKey.Remove(AuditID.ToString()); // remove the list + } + public virtual AnnotationAudit Get() + { + return _Editable = AnnotationAudit.Get(_AuditID); + } + public static void Refresh(AnnotationAudit tmp) + { + string key = tmp.AuditID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (AnnotationAuditInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(AnnotationAudit tmp) + { + _AnnotationID = tmp.AnnotationID; + _ItemID = tmp.ItemID; + _TypeID = tmp.TypeID; + _RtfText = tmp.RtfText; + _SearchText = tmp.SearchText; + _Config = tmp.Config; + _DTS = tmp.DTS; + _UserID = tmp.UserID; + _DeleteStatus = tmp.DeleteStatus; + _AnnotationAuditInfoExtension.Refresh(this); + OnChange();// raise an event + } + public static AnnotationAuditInfo Get(long auditID) + { + //if (!CanGetObject()) + // throw new System.Security.SecurityException("User not authorized to view a AnnotationAudit"); + try + { + AnnotationAuditInfo tmp = GetCachedByPrimaryKey(auditID); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(auditID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up AnnotationAuditInfo + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on AnnotationAuditInfo.Get", ex); + } + } + #endregion + #region Data Access Portal + internal AnnotationAuditInfo(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] AnnotationAuditInfo.Constructor", GetHashCode()); + try + { + ReadData(dr); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("AnnotationAuditInfo.Constructor", ex); + throw new DbCslaException("AnnotationAuditInfo.Constructor", ex); + } + } + [Serializable()] + protected class PKCriteria + { + private long _AuditID; + public long AuditID + { get { return _AuditID; } } + public PKCriteria(long auditID) + { + _AuditID = auditID; + } + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] AnnotationAuditInfo.ReadData", GetHashCode()); + try + { + _AuditID = dr.GetInt64("AuditID"); + _AnnotationID = dr.GetInt32("AnnotationID"); + _ItemID = dr.GetInt32("ItemID"); + _TypeID = dr.GetInt32("TypeID"); + _RtfText = dr.GetString("RtfText"); + _SearchText = dr.GetString("SearchText"); + _Config = dr.GetString("Config"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + _DeleteStatus = dr.GetInt32("DeleteStatus"); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("AnnotationAuditInfo.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("AnnotationAuditInfo.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] AnnotationAuditInfo.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 = "getAnnotationAudit"; + cm.Parameters.AddWithValue("@AuditID", criteria.AuditID); + 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("AnnotationAuditInfo.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("AnnotationAuditInfo.DataPortal_Fetch", ex); + } + } + #endregion + // Standard Refresh + #region extension + AnnotationAuditInfoExtension _AnnotationAuditInfoExtension = new AnnotationAuditInfoExtension(); + [Serializable()] + partial class AnnotationAuditInfoExtension : extensionBase { } + [Serializable()] + class extensionBase + { + // Default Refresh + public virtual void Refresh(AnnotationAuditInfo tmp) { } + } + #endregion + } // Class + #region Converter + internal class AnnotationAuditInfoConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is AnnotationAuditInfo) + { + // Return the ToString value + return ((AnnotationAuditInfo)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion +} // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/AnnotationAuditInfoList.cs b/PROMS/VEPROMS.CSLA.Library/Generated/AnnotationAuditInfoList.cs new file mode 100644 index 00000000..ccd56d4d --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/AnnotationAuditInfoList.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 +{ + /// + /// AnnotationAuditInfoList Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(AnnotationAuditInfoListConverter))] + public partial class AnnotationAuditInfoList : 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 (AnnotationAuditInfo tmp in this) + { + tmp.Changed += new AnnotationAuditInfoEvent(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 (AnnotationAuditInfo tmp in this) + { + tmp.Changed -= new AnnotationAuditInfoEvent(tmp_Changed); + } + } + #endregion + #region Factory Methods + public static AnnotationAuditInfoList _AnnotationAuditInfoList = null; + /// + /// Return a list of all AnnotationAuditInfo. + /// + public static AnnotationAuditInfoList Get() + { + try + { + if (_AnnotationAuditInfoList != null) + return _AnnotationAuditInfoList; + AnnotationAuditInfoList tmp = DataPortal.Fetch(); + AnnotationAuditInfo.AddList(tmp); + tmp.AddEvents(); + _AnnotationAuditInfoList = tmp; + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on AnnotationAuditInfoList.Get", ex); + } + } + /// + /// Reset the list of all AnnotationAuditInfo. + /// + public static void Reset() + { + _AnnotationAuditInfoList = null; + } + // CSLATODO: Add alternative gets - + //public static AnnotationAuditInfoList Get() + //{ + // try + // { + // return DataPortal.Fetch(new FilteredCriteria()); + // } + // catch (Exception ex) + // { + // throw new DbCslaException("Error on AnnotationAuditInfoList.Get", ex); + // } + //} + private AnnotationAuditInfoList() + { /* require use of factory methods */ } + #endregion + #region Data Access Portal + private void DataPortal_Fetch() + { + this.RaiseListChangedEvents = false; + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] AnnotationAuditInfoList.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getAnnotationAudits"; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + IsReadOnly = false; + while (dr.Read()) this.Add(new AnnotationAuditInfo(dr)); + IsReadOnly = true; + } + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("AnnotationAuditInfoList.DataPortal_Fetch", ex); + throw new DbCslaException("AnnotationAuditInfoList.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 + AnnotationAuditInfoListPropertyDescriptor pd = new AnnotationAuditInfoListPropertyDescriptor(this, i); + pds.Add(pd); + } + // return the property descriptor collection + return pds; + } + #endregion + } // Class + #region Property Descriptor + /// + /// Summary description for CollectionPropertyDescriptor. + /// + public partial class AnnotationAuditInfoListPropertyDescriptor : vlnListPropertyDescriptor + { + private AnnotationAuditInfo Item { get { return (AnnotationAuditInfo)_Item; } } + public AnnotationAuditInfoListPropertyDescriptor(AnnotationAuditInfoList collection, int index) : base(collection, index) { ;} + } + #endregion + #region Converter + internal class AnnotationAuditInfoListConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is AnnotationAuditInfoList) + { + // Return department and department role separated by comma. + return ((AnnotationAuditInfoList)value).Items.Count.ToString() + " AnnotationAudits"; + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion +} // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/ContentAudit.cs b/PROMS/VEPROMS.CSLA.Library/Generated/ContentAudit.cs new file mode 100644 index 00000000..832073ea --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/ContentAudit.cs @@ -0,0 +1,1035 @@ +// ======================================================================== +// 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 +{ + /// + /// ContentAudit Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(ContentAuditConverter))] + public partial class ContentAudit : BusinessBase, IDisposable, IVEHasBrokenRules + { + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Refresh + private List _RefreshContentAudits = new List(); + private void AddToRefreshList(List refreshContentAudits) + { + if (IsDirty) + refreshContentAudits.Add(this); + } + private void BuildRefreshList() + { + _RefreshContentAudits = new List(); + AddToRefreshList(_RefreshContentAudits); + } + private void ProcessRefreshList() + { + foreach (ContentAudit tmp in _RefreshContentAudits) + { + ContentAuditInfo.Refresh(tmp); + } + } + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(ContentAudit contentAudit) + { + if (!_CacheList.Contains(contentAudit)) _CacheList.Add(contentAudit); // In AddToCache + } + protected static void RemoveFromCache(ContentAudit contentAudit) + { + while (_CacheList.Contains(contentAudit)) _CacheList.Remove(contentAudit); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + while (_CacheList.Count > 0) // Move ContentAudit(s) from temporary _CacheList to _CacheByPrimaryKey + { + ContentAudit tmp = _CacheList[0]; // Get the first ContentAudit + string pKey = tmp.AuditID.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 ContentAudit + } + } + protected static ContentAudit GetCachedByPrimaryKey(long auditID) + { + ConvertListToDictionary(); + string key = auditID.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 _nextAuditID = -1; + public static int NextAuditID + { + get { return _nextAuditID--; } + } + private long _AuditID; + [System.ComponentModel.DataObjectField(true, true)] + public long AuditID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("AuditID", true); + return _AuditID; + } + } + private int _ContentID; + public int ContentID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("ContentID", true); + return _ContentID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + CanWriteProperty("ContentID", true); + if (_ContentID != value) + { + _ContentID = value; + PropertyHasChanged(); + } + } + } + private string _Number = string.Empty; + public string Number + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("Number", true); + return _Number; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + CanWriteProperty("Number", true); + if (value == null) value = string.Empty; + if (_Number != value) + { + _Number = value; + PropertyHasChanged(); + } + } + } + private string _Text = string.Empty; + public string Text + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("Text", true); + return _Text; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + CanWriteProperty("Text", true); + if (value == null) value = string.Empty; + if (_Text != value) + { + _Text = value; + PropertyHasChanged(); + } + } + } + private int? _Type; + public int? Type + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("Type", true); + return _Type; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + CanWriteProperty("Type", true); + if (_Type != value) + { + _Type = value; + PropertyHasChanged(); + } + } + } + private int? _FormatID; + public int? FormatID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("FormatID", true); + return _FormatID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + CanWriteProperty("FormatID", true); + if (_FormatID != value) + { + _FormatID = 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 int _DeleteStatus; + public int DeleteStatus + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("DeleteStatus", true); + return _DeleteStatus; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + CanWriteProperty("DeleteStatus", true); + if (_DeleteStatus != value) + { + _DeleteStatus = value; + PropertyHasChanged(); + } + } + } + public override bool IsDirty + { + get { return base.IsDirty; } + } + public bool IsDirtyList(List list) + { + return base.IsDirty; + } + public override bool IsValid + { + get { return (IsNew && !IsDirty) ? true : base.IsValid; } + } + public bool IsValidList(List list) + { + return (IsNew && !IsDirty) ? true : base.IsValid; + } + // CSLATODO: Replace base ContentAudit.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current ContentAudit + //public override string ToString() + //{ + // return base.ToString(); + //} + // CSLATODO: Check ContentAudit.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 ContentAudit + protected override object GetIdValue() + { + return MyContentAuditUnique; // 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; + 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("Number", 512)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Text", 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", 200)); + //ValidationRules.AddDependantProperty("x", "y"); + _ContentAuditExtension.AddValidationRules(ValidationRules); + // CSLATODO: Add other validation rules + } + protected override void AddInstanceBusinessRules() + { + _ContentAuditExtension.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(AuditID, ""); + //AuthorizationRules.AllowRead(ContentID, ""); + //AuthorizationRules.AllowRead(Number, ""); + //AuthorizationRules.AllowRead(Text, ""); + //AuthorizationRules.AllowRead(Type, ""); + //AuthorizationRules.AllowRead(FormatID, ""); + //AuthorizationRules.AllowRead(Config, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowRead(UserID, ""); + //AuthorizationRules.AllowRead(DeleteStatus, ""); + //AuthorizationRules.AllowWrite(ContentID, ""); + //AuthorizationRules.AllowWrite(Number, ""); + //AuthorizationRules.AllowWrite(Text, ""); + //AuthorizationRules.AllowWrite(Type, ""); + //AuthorizationRules.AllowWrite(FormatID, ""); + //AuthorizationRules.AllowWrite(Config, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowWrite(UserID, ""); + //AuthorizationRules.AllowWrite(DeleteStatus, ""); + _ContentAuditExtension.AddAuthorizationRules(AuthorizationRules); + } + protected override void AddInstanceAuthorizationRules() + { + //CSLATODO: Who can read/write which fields + _ContentAuditExtension.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 _ContentAuditUnique = 0; + protected static int ContentAuditUnique + { get { return ++_ContentAuditUnique; } } + private int _MyContentAuditUnique = ContentAuditUnique; + public int MyContentAuditUnique // Absolutely Unique ID - Editable + { get { return _MyContentAuditUnique; } } + protected ContentAudit() + {/* require use of factory methods */ + AddToCache(this); + } + public void Dispose() + { + RemoveFromDictionaries(); + } + private void RemoveFromDictionaries() + { + RemoveFromCache(this); + if (_CacheByPrimaryKey.ContainsKey(AuditID.ToString())) + { + List listContentAudit = _CacheByPrimaryKey[AuditID.ToString()]; // Get the list of items + while (listContentAudit.Contains(this)) listContentAudit.Remove(this); // Remove the item from the list + if (listContentAudit.Count == 0) //If there are no items left in the list + _CacheByPrimaryKey.Remove(AuditID.ToString()); // remove the list + } + } + public static ContentAudit New() + { + if (!CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a ContentAudit"); + try + { + return DataPortal.Create(); + } + catch (Exception ex) + { + throw new DbCslaException("Error on ContentAudit.New", ex); + } + } + public static ContentAudit New(int contentID, DateTime dts, string userID, int deleteStatus) + { + ContentAudit tmp = ContentAudit.New(); + tmp.ContentID = contentID; + tmp.DTS = dts; + tmp.UserID = userID; + tmp.DeleteStatus = deleteStatus; + return tmp; + } + public static ContentAudit New(int contentID, string number, string text, int? type, int? formatID, string config, DateTime dts, string userID, int deleteStatus) + { + ContentAudit tmp = ContentAudit.New(); + tmp.ContentID = contentID; + tmp.Number = number; + tmp.Text = text; + tmp.Type = type; + tmp.FormatID = formatID; + tmp.Config = config; + tmp.DTS = dts; + tmp.UserID = userID; + tmp.DeleteStatus = deleteStatus; + return tmp; + } + public static ContentAudit MakeContentAudit(int contentID, string number, string text, int? type, int? formatID, string config, DateTime dts, string userID, int deleteStatus) + { + ContentAudit tmp = ContentAudit.New(contentID, number, text, type, formatID, config, dts, userID, deleteStatus); + if (tmp.IsSavable) + { + ContentAudit 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 ContentAudit Get(long auditID) + { + if (!CanGetObject()) + throw new System.Security.SecurityException("User not authorized to view a ContentAudit"); + try + { + ContentAudit tmp = GetCachedByPrimaryKey(auditID); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(auditID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up ContentAudit + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on ContentAudit.Get", ex); + } + } + public static ContentAudit Get(SafeDataReader dr) + { + if (dr.Read()) return new ContentAudit(dr); + return null; + } + internal ContentAudit(SafeDataReader dr) + { + ReadData(dr); + } + public static void Delete(long auditID) + { + if (!CanDeleteObject()) + throw new System.Security.SecurityException("User not authorized to remove a ContentAudit"); + try + { + DataPortal.Delete(new PKCriteria(auditID)); + } + catch (Exception ex) + { + throw new DbCslaException("Error on ContentAudit.Delete", ex); + } + } + public override ContentAudit Save() + { + if (IsDeleted && !CanDeleteObject()) + throw new System.Security.SecurityException("User not authorized to remove a ContentAudit"); + else if (IsNew && !CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a ContentAudit"); + else if (!CanEditObject()) + throw new System.Security.SecurityException("User not authorized to update a ContentAudit"); + try + { + BuildRefreshList(); + ContentAudit contentAudit = base.Save(); + RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache + AddToCache(contentAudit);//Refresh the item in AllList + ProcessRefreshList(); + return contentAudit; + } + catch (Exception ex) + { + throw new DbCslaException("Error on CSLA Save", ex); + } + } + #endregion + #region Data Access Portal + [Serializable()] + protected class PKCriteria + { + private long _AuditID; + public long AuditID + { get { return _AuditID; } } + public PKCriteria(long auditID) + { + _AuditID = auditID; + } + } + // CSLATODO: If Create needs to access DB - It should not be marked RunLocal + [RunLocal()] + private new void DataPortal_Create() + { + _AuditID = NextAuditID; + // Database Defaults + + // CSLATODO: Add any defaults that are necessary + ValidationRules.CheckRules(); + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ContentAudit.ReadData", GetHashCode()); + try + { + _AuditID = dr.GetInt64("AuditID"); + _ContentID = dr.GetInt32("ContentID"); + _Number = dr.GetString("Number"); + _Text = dr.GetString("Text"); + _Type = (int?)dr.GetValue("Type"); + _FormatID = (int?)dr.GetValue("FormatID"); + _Config = dr.GetString("Config"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + _DeleteStatus = dr.GetInt32("DeleteStatus"); + MarkOld(); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ContentAudit.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("ContentAudit.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ContentAudit.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 = "getContentAudit"; + cm.Parameters.AddWithValue("@AuditID", criteria.AuditID); + 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("ContentAudit.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("ContentAudit.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("ContentAudit.DataPortal_Insert", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("ContentAudit.DataPortal_Insert", ex); + } + finally + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ContentAudit.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 = "addContentAudit"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@ContentID", _ContentID); + cm.Parameters.AddWithValue("@Number", _Number); + cm.Parameters.AddWithValue("@Text", _Text); + cm.Parameters.AddWithValue("@Type", _Type); + cm.Parameters.AddWithValue("@FormatID", _FormatID); + 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("@DeleteStatus", _DeleteStatus); + // Output Calculated Columns + SqlParameter param_AuditID = new SqlParameter("@newAuditID", SqlDbType.BigInt); + param_AuditID.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_AuditID); + // CSLATODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + _AuditID = (long)cm.Parameters["@newAuditID"].Value; + } + MarkOld(); + // update child objects + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ContentAudit.SQLInsert", GetHashCode()); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ContentAudit.SQLInsert", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("ContentAudit.SQLInsert", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + public static void Add(SqlConnection cn, ref long auditID, int contentID, string number, string text, int? type, int? formatID, string config, DateTime dts, string userID, int deleteStatus) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ContentAudit.Add", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "addContentAudit"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@ContentID", contentID); + cm.Parameters.AddWithValue("@Number", number); + cm.Parameters.AddWithValue("@Text", text); + cm.Parameters.AddWithValue("@Type", type); + cm.Parameters.AddWithValue("@FormatID", formatID); + 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("@DeleteStatus", deleteStatus); + // Output Calculated Columns + SqlParameter param_AuditID = new SqlParameter("@newAuditID", SqlDbType.BigInt); + param_AuditID.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_AuditID); + // CSLATODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + auditID = (long)cm.Parameters["@newAuditID"].Value; + // No Timestamp value to return + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ContentAudit.Add", ex); + throw new DbCslaException("ContentAudit.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}] ContentAudit.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("ContentAudit.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}] ContentAudit.SQLUpdate", GetHashCode()); + try + { + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + if (base.IsDirty) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "updateContentAudit"; + // All Fields including Calculated Fields + cm.Parameters.AddWithValue("@AuditID", _AuditID); + cm.Parameters.AddWithValue("@ContentID", _ContentID); + cm.Parameters.AddWithValue("@Number", _Number); + cm.Parameters.AddWithValue("@Text", _Text); + cm.Parameters.AddWithValue("@Type", _Type); + cm.Parameters.AddWithValue("@FormatID", _FormatID); + 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("@DeleteStatus", _DeleteStatus); + // Output Calculated Columns + // CSLATODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + } + } + MarkOld(); + // use the open connection to update child objects + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ContentAudit.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) + ContentAudit.Add(cn, ref _AuditID, _ContentID, _Number, _Text, _Type, _FormatID, _Config, _DTS, _UserID, _DeleteStatus); + else + ContentAudit.Update(cn, ref _AuditID, _ContentID, _Number, _Text, _Type, _FormatID, _Config, _DTS, _UserID, _DeleteStatus); + MarkOld(); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + public static void Update(SqlConnection cn, ref long auditID, int contentID, string number, string text, int? type, int? formatID, string config, DateTime dts, string userID, int deleteStatus) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ContentAudit.Update", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "updateContentAudit"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@AuditID", auditID); + cm.Parameters.AddWithValue("@ContentID", contentID); + cm.Parameters.AddWithValue("@Number", number); + cm.Parameters.AddWithValue("@Text", text); + cm.Parameters.AddWithValue("@Type", type); + cm.Parameters.AddWithValue("@FormatID", formatID); + 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("@DeleteStatus", deleteStatus); + // Output Calculated Columns + // CSLATODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + // No Timestamp value to return + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ContentAudit.Update", ex); + throw new DbCslaException("ContentAudit.Update", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_DeleteSelf() + { + DataPortal_Delete(new PKCriteria(_AuditID)); + } + [Transactional(TransactionalTypes.TransactionScope)] + private void DataPortal_Delete(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ContentAudit.DataPortal_Delete", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "deleteContentAudit"; + cm.Parameters.AddWithValue("@AuditID", criteria.AuditID); + cm.ExecuteNonQuery(); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ContentAudit.DataPortal_Delete", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("ContentAudit.DataPortal_Delete", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + public static void Remove(SqlConnection cn, long auditID) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ContentAudit.Remove", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "deleteContentAudit"; + // Input PK Fields + cm.Parameters.AddWithValue("@AuditID", auditID); + // CSLATODO: Define any additional output parameters + cm.ExecuteNonQuery(); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ContentAudit.Remove", ex); + throw new DbCslaException("ContentAudit.Remove", ex); + } + } + #endregion + // Standard Default Code + #region extension + ContentAuditExtension _ContentAuditExtension = new ContentAuditExtension(); + [Serializable()] + partial class ContentAuditExtension : 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 ContentAuditConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is ContentAudit) + { + // Return the ToString value + return ((ContentAudit)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion +} // Namespace + + +//// The following is a sample Extension File. You can use it to create ContentAuditExt.cs +//using System; +//using System.Collections.Generic; +//using System.Text; +//using Csla; + +//namespace VEPROMS.CSLA.Library +//{ +// public partial class ContentAudit +// { +// partial class ContentAuditExtension : 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/ContentAuditInfo.cs b/PROMS/VEPROMS.CSLA.Library/Generated/ContentAuditInfo.cs new file mode 100644 index 00000000..af2bea2b --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/ContentAuditInfo.cs @@ -0,0 +1,394 @@ +// ======================================================================== +// 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 ContentAuditInfoEvent(object sender); + /// + /// ContentAuditInfo Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(ContentAuditInfoConverter))] + public partial class ContentAuditInfo : ReadOnlyBase, IDisposable + { + public event ContentAuditInfoEvent 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(ContentAuditInfo contentAuditInfo) + { + if (!_CacheList.Contains(contentAuditInfo)) _CacheList.Add(contentAuditInfo); // In AddToCache + } + protected static void RemoveFromCache(ContentAuditInfo contentAuditInfo) + { + while (_CacheList.Contains(contentAuditInfo)) _CacheList.Remove(contentAuditInfo); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + while (_CacheList.Count > 0) // Move ContentAuditInfo(s) from temporary _CacheList to _CacheByPrimaryKey + { + ContentAuditInfo tmp = _CacheList[0]; // Get the first ContentAuditInfo + string pKey = tmp.AuditID.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 ContentAuditInfo + } + } + internal static void AddList(ContentAuditInfoList lst) + { + foreach (ContentAuditInfo item in lst) AddToCache(item); + } + protected static ContentAuditInfo GetCachedByPrimaryKey(long auditID) + { + ConvertListToDictionary(); + string key = auditID.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 ContentAudit _Editable; + private IVEHasBrokenRules HasBrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = null; + if (_Editable != null) + hasBrokenRules = _Editable.HasBrokenRules; + return hasBrokenRules; + } + } + private long _AuditID; + [System.ComponentModel.DataObjectField(true, true)] + public long AuditID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("AuditID", true); + return _AuditID; + } + } + private int _ContentID; + public int ContentID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("ContentID", true); + return _ContentID; + } + } + private string _Number = string.Empty; + public string Number + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("Number", true); + return _Number; + } + } + private string _Text = string.Empty; + public string Text + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("Text", true); + return _Text; + } + } + private int? _Type; + public int? Type + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("Type", true); + return _Type; + } + } + private int? _FormatID; + public int? FormatID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("FormatID", true); + return _FormatID; + } + } + 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 _DeleteStatus; + public int DeleteStatus + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("DeleteStatus", true); + return _DeleteStatus; + } + } + // CSLATODO: Replace base ContentAuditInfo.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current ContentAuditInfo + //public override string ToString() + //{ + // return base.ToString(); + //} + // CSLATODO: Check ContentAuditInfo.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 ContentAuditInfo + protected override object GetIdValue() + { + return MyContentAuditInfoUnique; // Absolutely Unique ID + } + #endregion + #region Factory Methods + private static int _ContentAuditInfoUnique = 0; + private static int ContentAuditInfoUnique + { get { return ++_ContentAuditInfoUnique; } } + private int _MyContentAuditInfoUnique = ContentAuditInfoUnique; + public int MyContentAuditInfoUnique // Absolutely Unique ID - Info + { get { return _MyContentAuditInfoUnique; } } + protected ContentAuditInfo() + {/* require use of factory methods */ + AddToCache(this); + } + public void Dispose() + { + RemoveFromCache(this); + if (!_CacheByPrimaryKey.ContainsKey(AuditID.ToString())) return; + List listContentAuditInfo = _CacheByPrimaryKey[AuditID.ToString()]; // Get the list of items + while (listContentAuditInfo.Contains(this)) listContentAuditInfo.Remove(this); // Remove the item from the list + if (listContentAuditInfo.Count == 0) // If there are no items left in the list + _CacheByPrimaryKey.Remove(AuditID.ToString()); // remove the list + } + public virtual ContentAudit Get() + { + return _Editable = ContentAudit.Get(_AuditID); + } + public static void Refresh(ContentAudit tmp) + { + string key = tmp.AuditID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (ContentAuditInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(ContentAudit tmp) + { + _ContentID = tmp.ContentID; + _Number = tmp.Number; + _Text = tmp.Text; + _Type = tmp.Type; + _FormatID = tmp.FormatID; + _Config = tmp.Config; + _DTS = tmp.DTS; + _UserID = tmp.UserID; + _DeleteStatus = tmp.DeleteStatus; + _ContentAuditInfoExtension.Refresh(this); + OnChange();// raise an event + } + public static ContentAuditInfo Get(long auditID) + { + //if (!CanGetObject()) + // throw new System.Security.SecurityException("User not authorized to view a ContentAudit"); + try + { + ContentAuditInfo tmp = GetCachedByPrimaryKey(auditID); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(auditID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up ContentAuditInfo + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on ContentAuditInfo.Get", ex); + } + } + #endregion + #region Data Access Portal + internal ContentAuditInfo(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ContentAuditInfo.Constructor", GetHashCode()); + try + { + ReadData(dr); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ContentAuditInfo.Constructor", ex); + throw new DbCslaException("ContentAuditInfo.Constructor", ex); + } + } + [Serializable()] + protected class PKCriteria + { + private long _AuditID; + public long AuditID + { get { return _AuditID; } } + public PKCriteria(long auditID) + { + _AuditID = auditID; + } + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ContentAuditInfo.ReadData", GetHashCode()); + try + { + _AuditID = dr.GetInt64("AuditID"); + _ContentID = dr.GetInt32("ContentID"); + _Number = dr.GetString("Number"); + _Text = dr.GetString("Text"); + _Type = (int?)dr.GetValue("Type"); + _FormatID = (int?)dr.GetValue("FormatID"); + _Config = dr.GetString("Config"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + _DeleteStatus = dr.GetInt32("DeleteStatus"); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ContentAuditInfo.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("ContentAuditInfo.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ContentAuditInfo.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 = "getContentAudit"; + cm.Parameters.AddWithValue("@AuditID", criteria.AuditID); + 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("ContentAuditInfo.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("ContentAuditInfo.DataPortal_Fetch", ex); + } + } + #endregion + // Standard Refresh + #region extension + ContentAuditInfoExtension _ContentAuditInfoExtension = new ContentAuditInfoExtension(); + [Serializable()] + partial class ContentAuditInfoExtension : extensionBase { } + [Serializable()] + class extensionBase + { + // Default Refresh + public virtual void Refresh(ContentAuditInfo tmp) { } + } + #endregion + } // Class + #region Converter + internal class ContentAuditInfoConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is ContentAuditInfo) + { + // Return the ToString value + return ((ContentAuditInfo)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion +} // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/ContentAuditInfoList.cs b/PROMS/VEPROMS.CSLA.Library/Generated/ContentAuditInfoList.cs new file mode 100644 index 00000000..048c26df --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/ContentAuditInfoList.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 +{ + /// + /// ContentAuditInfoList Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(ContentAuditInfoListConverter))] + public partial class ContentAuditInfoList : 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 (ContentAuditInfo tmp in this) + { + tmp.Changed += new ContentAuditInfoEvent(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 (ContentAuditInfo tmp in this) + { + tmp.Changed -= new ContentAuditInfoEvent(tmp_Changed); + } + } + #endregion + #region Factory Methods + public static ContentAuditInfoList _ContentAuditInfoList = null; + /// + /// Return a list of all ContentAuditInfo. + /// + public static ContentAuditInfoList Get() + { + try + { + if (_ContentAuditInfoList != null) + return _ContentAuditInfoList; + ContentAuditInfoList tmp = DataPortal.Fetch(); + ContentAuditInfo.AddList(tmp); + tmp.AddEvents(); + _ContentAuditInfoList = tmp; + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on ContentAuditInfoList.Get", ex); + } + } + /// + /// Reset the list of all ContentAuditInfo. + /// + public static void Reset() + { + _ContentAuditInfoList = null; + } + // CSLATODO: Add alternative gets - + //public static ContentAuditInfoList Get() + //{ + // try + // { + // return DataPortal.Fetch(new FilteredCriteria()); + // } + // catch (Exception ex) + // { + // throw new DbCslaException("Error on ContentAuditInfoList.Get", ex); + // } + //} + private ContentAuditInfoList() + { /* require use of factory methods */ } + #endregion + #region Data Access Portal + private void DataPortal_Fetch() + { + this.RaiseListChangedEvents = false; + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ContentAuditInfoList.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getContentAudits"; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + IsReadOnly = false; + while (dr.Read()) this.Add(new ContentAuditInfo(dr)); + IsReadOnly = true; + } + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ContentAuditInfoList.DataPortal_Fetch", ex); + throw new DbCslaException("ContentAuditInfoList.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 + ContentAuditInfoListPropertyDescriptor pd = new ContentAuditInfoListPropertyDescriptor(this, i); + pds.Add(pd); + } + // return the property descriptor collection + return pds; + } + #endregion + } // Class + #region Property Descriptor + /// + /// Summary description for CollectionPropertyDescriptor. + /// + public partial class ContentAuditInfoListPropertyDescriptor : vlnListPropertyDescriptor + { + private ContentAuditInfo Item { get { return (ContentAuditInfo)_Item; } } + public ContentAuditInfoListPropertyDescriptor(ContentAuditInfoList collection, int index) : base(collection, index) { ;} + } + #endregion + #region Converter + internal class ContentAuditInfoListConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is ContentAuditInfoList) + { + // Return department and department role separated by comma. + return ((ContentAuditInfoList)value).Items.Count.ToString() + " ContentAudits"; + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion +} // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/DocumentAudit.cs b/PROMS/VEPROMS.CSLA.Library/Generated/DocumentAudit.cs new file mode 100644 index 00000000..d6d142c3 --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/DocumentAudit.cs @@ -0,0 +1,1070 @@ +// ======================================================================== +// 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 +{ + /// + /// DocumentAudit Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(DocumentAuditConverter))] + public partial class DocumentAudit : BusinessBase, IDisposable, IVEHasBrokenRules + { + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Refresh + private List _RefreshDocumentAudits = new List(); + private void AddToRefreshList(List refreshDocumentAudits) + { + if (IsDirty) + refreshDocumentAudits.Add(this); + } + private void BuildRefreshList() + { + _RefreshDocumentAudits = new List(); + AddToRefreshList(_RefreshDocumentAudits); + } + private void ProcessRefreshList() + { + foreach (DocumentAudit tmp in _RefreshDocumentAudits) + { + DocumentAuditInfo.Refresh(tmp); + } + } + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(DocumentAudit documentAudit) + { + if (!_CacheList.Contains(documentAudit)) _CacheList.Add(documentAudit); // In AddToCache + } + protected static void RemoveFromCache(DocumentAudit documentAudit) + { + while (_CacheList.Contains(documentAudit)) _CacheList.Remove(documentAudit); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + while (_CacheList.Count > 0) // Move DocumentAudit(s) from temporary _CacheList to _CacheByPrimaryKey + { + DocumentAudit tmp = _CacheList[0]; // Get the first DocumentAudit + string pKey = tmp.AuditID.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 DocumentAudit + } + } + protected static DocumentAudit GetCachedByPrimaryKey(long auditID) + { + ConvertListToDictionary(); + string key = auditID.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 _nextAuditID = -1; + public static int NextAuditID + { + get { return _nextAuditID--; } + } + private long _AuditID; + [System.ComponentModel.DataObjectField(true, true)] + public long AuditID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("AuditID", true); + return _AuditID; + } + } + private int _DocID; + public int DocID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("DocID", true); + return _DocID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + CanWriteProperty("DocID", true); + if (_DocID != value) + { + _DocID = value; + PropertyHasChanged(); + } + } + } + private string _LibTitle = string.Empty; + public string LibTitle + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("LibTitle", true); + return _LibTitle; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + CanWriteProperty("LibTitle", true); + if (value == null) value = string.Empty; + if (_LibTitle != value) + { + _LibTitle = value; + PropertyHasChanged(); + } + } + } + private byte[] _DocContent; + public byte[] DocContent + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("DocContent", true); + return _DocContent; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + CanWriteProperty("DocContent", true); + if (_DocContent != value) + { + _DocContent = value; + PropertyHasChanged(); + } + } + } + private string _DocAscii = string.Empty; + public string DocAscii + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("DocAscii", true); + return _DocAscii; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + CanWriteProperty("DocAscii", true); + if (value == null) value = string.Empty; + if (_DocAscii != value) + { + _DocAscii = 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 string _FileExtension = string.Empty; + public string FileExtension + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("FileExtension", true); + return _FileExtension; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + CanWriteProperty("FileExtension", true); + if (value == null) value = string.Empty; + if (_FileExtension != value) + { + _FileExtension = value; + PropertyHasChanged(); + } + } + } + private byte[] _DocPdf; + public byte[] DocPdf + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("DocPdf", true); + return _DocPdf; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + CanWriteProperty("DocPdf", true); + if (_DocPdf != value) + { + _DocPdf = value; + PropertyHasChanged(); + } + } + } + private int _DeleteStatus; + public int DeleteStatus + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("DeleteStatus", true); + return _DeleteStatus; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + CanWriteProperty("DeleteStatus", true); + if (_DeleteStatus != value) + { + _DeleteStatus = value; + PropertyHasChanged(); + } + } + } + public override bool IsDirty + { + get { return base.IsDirty; } + } + public bool IsDirtyList(List list) + { + return base.IsDirty; + } + public override bool IsValid + { + get { return (IsNew && !IsDirty) ? true : base.IsValid; } + } + public bool IsValidList(List list) + { + return (IsNew && !IsDirty) ? true : base.IsValid; + } + // CSLATODO: Replace base DocumentAudit.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current DocumentAudit + //public override string ToString() + //{ + // return base.ToString(); + //} + // CSLATODO: Check DocumentAudit.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 DocumentAudit + protected override object GetIdValue() + { + return MyDocumentAuditUnique; // 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; + 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("LibTitle", 2048)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("DocAscii", 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", 200)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "FileExtension"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("FileExtension", 20)); + //ValidationRules.AddDependantProperty("x", "y"); + _DocumentAuditExtension.AddValidationRules(ValidationRules); + // CSLATODO: Add other validation rules + } + protected override void AddInstanceBusinessRules() + { + _DocumentAuditExtension.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(AuditID, ""); + //AuthorizationRules.AllowRead(DocID, ""); + //AuthorizationRules.AllowRead(LibTitle, ""); + //AuthorizationRules.AllowRead(DocContent, ""); + //AuthorizationRules.AllowRead(DocAscii, ""); + //AuthorizationRules.AllowRead(Config, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowRead(UserID, ""); + //AuthorizationRules.AllowRead(FileExtension, ""); + //AuthorizationRules.AllowRead(DocPdf, ""); + //AuthorizationRules.AllowRead(DeleteStatus, ""); + //AuthorizationRules.AllowWrite(DocID, ""); + //AuthorizationRules.AllowWrite(LibTitle, ""); + //AuthorizationRules.AllowWrite(DocContent, ""); + //AuthorizationRules.AllowWrite(DocAscii, ""); + //AuthorizationRules.AllowWrite(Config, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowWrite(UserID, ""); + //AuthorizationRules.AllowWrite(FileExtension, ""); + //AuthorizationRules.AllowWrite(DocPdf, ""); + //AuthorizationRules.AllowWrite(DeleteStatus, ""); + _DocumentAuditExtension.AddAuthorizationRules(AuthorizationRules); + } + protected override void AddInstanceAuthorizationRules() + { + //CSLATODO: Who can read/write which fields + _DocumentAuditExtension.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 _DocumentAuditUnique = 0; + protected static int DocumentAuditUnique + { get { return ++_DocumentAuditUnique; } } + private int _MyDocumentAuditUnique = DocumentAuditUnique; + public int MyDocumentAuditUnique // Absolutely Unique ID - Editable + { get { return _MyDocumentAuditUnique; } } + protected DocumentAudit() + {/* require use of factory methods */ + AddToCache(this); + } + public void Dispose() + { + RemoveFromDictionaries(); + } + private void RemoveFromDictionaries() + { + RemoveFromCache(this); + if (_CacheByPrimaryKey.ContainsKey(AuditID.ToString())) + { + List listDocumentAudit = _CacheByPrimaryKey[AuditID.ToString()]; // Get the list of items + while (listDocumentAudit.Contains(this)) listDocumentAudit.Remove(this); // Remove the item from the list + if (listDocumentAudit.Count == 0) //If there are no items left in the list + _CacheByPrimaryKey.Remove(AuditID.ToString()); // remove the list + } + } + public static DocumentAudit New() + { + if (!CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a DocumentAudit"); + try + { + return DataPortal.Create(); + } + catch (Exception ex) + { + throw new DbCslaException("Error on DocumentAudit.New", ex); + } + } + public static DocumentAudit New(int docID, DateTime dts, string userID, string fileExtension, int deleteStatus) + { + DocumentAudit tmp = DocumentAudit.New(); + tmp.DocID = docID; + tmp.DTS = dts; + tmp.UserID = userID; + tmp.FileExtension = fileExtension; + tmp.DeleteStatus = deleteStatus; + return tmp; + } + public static DocumentAudit New(int docID, string libTitle, byte[] docContent, string docAscii, string config, DateTime dts, string userID, string fileExtension, byte[] docPdf, int deleteStatus) + { + DocumentAudit tmp = DocumentAudit.New(); + tmp.DocID = docID; + tmp.LibTitle = libTitle; + tmp.DocContent = docContent; + tmp.DocAscii = docAscii; + tmp.Config = config; + tmp.DTS = dts; + tmp.UserID = userID; + tmp.FileExtension = fileExtension; + tmp.DocPdf = docPdf; + tmp.DeleteStatus = deleteStatus; + return tmp; + } + public static DocumentAudit MakeDocumentAudit(int docID, string libTitle, byte[] docContent, string docAscii, string config, DateTime dts, string userID, string fileExtension, byte[] docPdf, int deleteStatus) + { + DocumentAudit tmp = DocumentAudit.New(docID, libTitle, docContent, docAscii, config, dts, userID, fileExtension, docPdf, deleteStatus); + if (tmp.IsSavable) + { + DocumentAudit 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 DocumentAudit Get(long auditID) + { + if (!CanGetObject()) + throw new System.Security.SecurityException("User not authorized to view a DocumentAudit"); + try + { + DocumentAudit tmp = GetCachedByPrimaryKey(auditID); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(auditID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up DocumentAudit + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on DocumentAudit.Get", ex); + } + } + public static DocumentAudit Get(SafeDataReader dr) + { + if (dr.Read()) return new DocumentAudit(dr); + return null; + } + internal DocumentAudit(SafeDataReader dr) + { + ReadData(dr); + } + public static void Delete(long auditID) + { + if (!CanDeleteObject()) + throw new System.Security.SecurityException("User not authorized to remove a DocumentAudit"); + try + { + DataPortal.Delete(new PKCriteria(auditID)); + } + catch (Exception ex) + { + throw new DbCslaException("Error on DocumentAudit.Delete", ex); + } + } + public override DocumentAudit Save() + { + if (IsDeleted && !CanDeleteObject()) + throw new System.Security.SecurityException("User not authorized to remove a DocumentAudit"); + else if (IsNew && !CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a DocumentAudit"); + else if (!CanEditObject()) + throw new System.Security.SecurityException("User not authorized to update a DocumentAudit"); + try + { + BuildRefreshList(); + DocumentAudit documentAudit = base.Save(); + RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache + AddToCache(documentAudit);//Refresh the item in AllList + ProcessRefreshList(); + return documentAudit; + } + catch (Exception ex) + { + throw new DbCslaException("Error on CSLA Save", ex); + } + } + #endregion + #region Data Access Portal + [Serializable()] + protected class PKCriteria + { + private long _AuditID; + public long AuditID + { get { return _AuditID; } } + public PKCriteria(long auditID) + { + _AuditID = auditID; + } + } + // CSLATODO: If Create needs to access DB - It should not be marked RunLocal + [RunLocal()] + private new void DataPortal_Create() + { + _AuditID = NextAuditID; + // Database Defaults + + // CSLATODO: Add any defaults that are necessary + ValidationRules.CheckRules(); + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocumentAudit.ReadData", GetHashCode()); + try + { + _AuditID = dr.GetInt64("AuditID"); + _DocID = dr.GetInt32("DocID"); + _LibTitle = dr.GetString("LibTitle"); + _DocContent = (byte[])dr.GetValue("DocContent"); + _DocAscii = dr.GetString("DocAscii"); + _Config = dr.GetString("Config"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + _FileExtension = dr.GetString("FileExtension"); + _DocPdf = (byte[])dr.GetValue("DocPdf"); + _DeleteStatus = dr.GetInt32("DeleteStatus"); + MarkOld(); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("DocumentAudit.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("DocumentAudit.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocumentAudit.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 = "getDocumentAudit"; + cm.Parameters.AddWithValue("@AuditID", criteria.AuditID); + 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("DocumentAudit.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("DocumentAudit.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("DocumentAudit.DataPortal_Insert", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("DocumentAudit.DataPortal_Insert", ex); + } + finally + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocumentAudit.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 = "addDocumentAudit"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@DocID", _DocID); + cm.Parameters.AddWithValue("@LibTitle", _LibTitle); + cm.Parameters.AddWithValue("@DocContent", _DocContent); + cm.Parameters.AddWithValue("@DocAscii", _DocAscii); + 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("@FileExtension", _FileExtension); + cm.Parameters.AddWithValue("@DocPdf", _DocPdf); + cm.Parameters.AddWithValue("@DeleteStatus", _DeleteStatus); + // Output Calculated Columns + SqlParameter param_AuditID = new SqlParameter("@newAuditID", SqlDbType.BigInt); + param_AuditID.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_AuditID); + // CSLATODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + _AuditID = (long)cm.Parameters["@newAuditID"].Value; + } + MarkOld(); + // update child objects + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocumentAudit.SQLInsert", GetHashCode()); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("DocumentAudit.SQLInsert", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("DocumentAudit.SQLInsert", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + public static void Add(SqlConnection cn, ref long auditID, int docID, string libTitle, byte[] docContent, string docAscii, string config, DateTime dts, string userID, string fileExtension, byte[] docPdf, int deleteStatus) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocumentAudit.Add", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "addDocumentAudit"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@DocID", docID); + cm.Parameters.AddWithValue("@LibTitle", libTitle); + cm.Parameters.AddWithValue("@DocContent", docContent); + cm.Parameters.AddWithValue("@DocAscii", docAscii); + 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("@FileExtension", fileExtension); + cm.Parameters.AddWithValue("@DocPdf", docPdf); + cm.Parameters.AddWithValue("@DeleteStatus", deleteStatus); + // Output Calculated Columns + SqlParameter param_AuditID = new SqlParameter("@newAuditID", SqlDbType.BigInt); + param_AuditID.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_AuditID); + // CSLATODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + auditID = (long)cm.Parameters["@newAuditID"].Value; + // No Timestamp value to return + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("DocumentAudit.Add", ex); + throw new DbCslaException("DocumentAudit.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}] DocumentAudit.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("DocumentAudit.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}] DocumentAudit.SQLUpdate", GetHashCode()); + try + { + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + if (base.IsDirty) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "updateDocumentAudit"; + // All Fields including Calculated Fields + cm.Parameters.AddWithValue("@AuditID", _AuditID); + cm.Parameters.AddWithValue("@DocID", _DocID); + cm.Parameters.AddWithValue("@LibTitle", _LibTitle); + cm.Parameters.AddWithValue("@DocContent", _DocContent); + cm.Parameters.AddWithValue("@DocAscii", _DocAscii); + 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("@FileExtension", _FileExtension); + cm.Parameters.AddWithValue("@DocPdf", _DocPdf); + cm.Parameters.AddWithValue("@DeleteStatus", _DeleteStatus); + // Output Calculated Columns + // CSLATODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + } + } + MarkOld(); + // use the open connection to update child objects + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("DocumentAudit.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) + DocumentAudit.Add(cn, ref _AuditID, _DocID, _LibTitle, _DocContent, _DocAscii, _Config, _DTS, _UserID, _FileExtension, _DocPdf, _DeleteStatus); + else + DocumentAudit.Update(cn, ref _AuditID, _DocID, _LibTitle, _DocContent, _DocAscii, _Config, _DTS, _UserID, _FileExtension, _DocPdf, _DeleteStatus); + MarkOld(); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + public static void Update(SqlConnection cn, ref long auditID, int docID, string libTitle, byte[] docContent, string docAscii, string config, DateTime dts, string userID, string fileExtension, byte[] docPdf, int deleteStatus) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocumentAudit.Update", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "updateDocumentAudit"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@AuditID", auditID); + cm.Parameters.AddWithValue("@DocID", docID); + cm.Parameters.AddWithValue("@LibTitle", libTitle); + cm.Parameters.AddWithValue("@DocContent", docContent); + cm.Parameters.AddWithValue("@DocAscii", docAscii); + 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("@FileExtension", fileExtension); + cm.Parameters.AddWithValue("@DocPdf", docPdf); + cm.Parameters.AddWithValue("@DeleteStatus", deleteStatus); + // Output Calculated Columns + // CSLATODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + // No Timestamp value to return + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("DocumentAudit.Update", ex); + throw new DbCslaException("DocumentAudit.Update", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_DeleteSelf() + { + DataPortal_Delete(new PKCriteria(_AuditID)); + } + [Transactional(TransactionalTypes.TransactionScope)] + private void DataPortal_Delete(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocumentAudit.DataPortal_Delete", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "deleteDocumentAudit"; + cm.Parameters.AddWithValue("@AuditID", criteria.AuditID); + cm.ExecuteNonQuery(); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("DocumentAudit.DataPortal_Delete", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("DocumentAudit.DataPortal_Delete", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + public static void Remove(SqlConnection cn, long auditID) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocumentAudit.Remove", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "deleteDocumentAudit"; + // Input PK Fields + cm.Parameters.AddWithValue("@AuditID", auditID); + // CSLATODO: Define any additional output parameters + cm.ExecuteNonQuery(); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("DocumentAudit.Remove", ex); + throw new DbCslaException("DocumentAudit.Remove", ex); + } + } + #endregion + // Standard Default Code + #region extension + DocumentAuditExtension _DocumentAuditExtension = new DocumentAuditExtension(); + [Serializable()] + partial class DocumentAuditExtension : 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 DocumentAuditConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is DocumentAudit) + { + // Return the ToString value + return ((DocumentAudit)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion +} // Namespace + + +//// The following is a sample Extension File. You can use it to create DocumentAuditExt.cs +//using System; +//using System.Collections.Generic; +//using System.Text; +//using Csla; + +//namespace VEPROMS.CSLA.Library +//{ +// public partial class DocumentAudit +// { +// partial class DocumentAuditExtension : 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/DocumentAuditInfo.cs b/PROMS/VEPROMS.CSLA.Library/Generated/DocumentAuditInfo.cs new file mode 100644 index 00000000..094837d6 --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/DocumentAuditInfo.cs @@ -0,0 +1,406 @@ +// ======================================================================== +// 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 DocumentAuditInfoEvent(object sender); + /// + /// DocumentAuditInfo Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(DocumentAuditInfoConverter))] + public partial class DocumentAuditInfo : ReadOnlyBase, IDisposable + { + public event DocumentAuditInfoEvent 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(DocumentAuditInfo documentAuditInfo) + { + if (!_CacheList.Contains(documentAuditInfo)) _CacheList.Add(documentAuditInfo); // In AddToCache + } + protected static void RemoveFromCache(DocumentAuditInfo documentAuditInfo) + { + while (_CacheList.Contains(documentAuditInfo)) _CacheList.Remove(documentAuditInfo); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + while (_CacheList.Count > 0) // Move DocumentAuditInfo(s) from temporary _CacheList to _CacheByPrimaryKey + { + DocumentAuditInfo tmp = _CacheList[0]; // Get the first DocumentAuditInfo + string pKey = tmp.AuditID.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 DocumentAuditInfo + } + } + internal static void AddList(DocumentAuditInfoList lst) + { + foreach (DocumentAuditInfo item in lst) AddToCache(item); + } + protected static DocumentAuditInfo GetCachedByPrimaryKey(long auditID) + { + ConvertListToDictionary(); + string key = auditID.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 DocumentAudit _Editable; + private IVEHasBrokenRules HasBrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = null; + if (_Editable != null) + hasBrokenRules = _Editable.HasBrokenRules; + return hasBrokenRules; + } + } + private long _AuditID; + [System.ComponentModel.DataObjectField(true, true)] + public long AuditID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("AuditID", true); + return _AuditID; + } + } + private int _DocID; + public int DocID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("DocID", true); + return _DocID; + } + } + private string _LibTitle = string.Empty; + public string LibTitle + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("LibTitle", true); + return _LibTitle; + } + } + private byte[] _DocContent; + public byte[] DocContent + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("DocContent", true); + return _DocContent; + } + } + private string _DocAscii = string.Empty; + public string DocAscii + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("DocAscii", true); + return _DocAscii; + } + } + 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 string _FileExtension = string.Empty; + public string FileExtension + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("FileExtension", true); + return _FileExtension; + } + } + private byte[] _DocPdf; + public byte[] DocPdf + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("DocPdf", true); + return _DocPdf; + } + } + private int _DeleteStatus; + public int DeleteStatus + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("DeleteStatus", true); + return _DeleteStatus; + } + } + // CSLATODO: Replace base DocumentAuditInfo.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current DocumentAuditInfo + //public override string ToString() + //{ + // return base.ToString(); + //} + // CSLATODO: Check DocumentAuditInfo.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 DocumentAuditInfo + protected override object GetIdValue() + { + return MyDocumentAuditInfoUnique; // Absolutely Unique ID + } + #endregion + #region Factory Methods + private static int _DocumentAuditInfoUnique = 0; + private static int DocumentAuditInfoUnique + { get { return ++_DocumentAuditInfoUnique; } } + private int _MyDocumentAuditInfoUnique = DocumentAuditInfoUnique; + public int MyDocumentAuditInfoUnique // Absolutely Unique ID - Info + { get { return _MyDocumentAuditInfoUnique; } } + protected DocumentAuditInfo() + {/* require use of factory methods */ + AddToCache(this); + } + public void Dispose() + { + RemoveFromCache(this); + if (!_CacheByPrimaryKey.ContainsKey(AuditID.ToString())) return; + List listDocumentAuditInfo = _CacheByPrimaryKey[AuditID.ToString()]; // Get the list of items + while (listDocumentAuditInfo.Contains(this)) listDocumentAuditInfo.Remove(this); // Remove the item from the list + if (listDocumentAuditInfo.Count == 0) // If there are no items left in the list + _CacheByPrimaryKey.Remove(AuditID.ToString()); // remove the list + } + public virtual DocumentAudit Get() + { + return _Editable = DocumentAudit.Get(_AuditID); + } + public static void Refresh(DocumentAudit tmp) + { + string key = tmp.AuditID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (DocumentAuditInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(DocumentAudit tmp) + { + _DocID = tmp.DocID; + _LibTitle = tmp.LibTitle; + _DocContent = tmp.DocContent; + _DocAscii = tmp.DocAscii; + _Config = tmp.Config; + _DTS = tmp.DTS; + _UserID = tmp.UserID; + _FileExtension = tmp.FileExtension; + _DocPdf = tmp.DocPdf; + _DeleteStatus = tmp.DeleteStatus; + _DocumentAuditInfoExtension.Refresh(this); + OnChange();// raise an event + } + public static DocumentAuditInfo Get(long auditID) + { + //if (!CanGetObject()) + // throw new System.Security.SecurityException("User not authorized to view a DocumentAudit"); + try + { + DocumentAuditInfo tmp = GetCachedByPrimaryKey(auditID); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(auditID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up DocumentAuditInfo + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on DocumentAuditInfo.Get", ex); + } + } + #endregion + #region Data Access Portal + internal DocumentAuditInfo(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocumentAuditInfo.Constructor", GetHashCode()); + try + { + ReadData(dr); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("DocumentAuditInfo.Constructor", ex); + throw new DbCslaException("DocumentAuditInfo.Constructor", ex); + } + } + [Serializable()] + protected class PKCriteria + { + private long _AuditID; + public long AuditID + { get { return _AuditID; } } + public PKCriteria(long auditID) + { + _AuditID = auditID; + } + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocumentAuditInfo.ReadData", GetHashCode()); + try + { + _AuditID = dr.GetInt64("AuditID"); + _DocID = dr.GetInt32("DocID"); + _LibTitle = dr.GetString("LibTitle"); + _DocContent = (byte[])dr.GetValue("DocContent"); + _DocAscii = dr.GetString("DocAscii"); + _Config = dr.GetString("Config"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + _FileExtension = dr.GetString("FileExtension"); + _DocPdf = (byte[])dr.GetValue("DocPdf"); + _DeleteStatus = dr.GetInt32("DeleteStatus"); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("DocumentAuditInfo.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("DocumentAuditInfo.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocumentAuditInfo.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 = "getDocumentAudit"; + cm.Parameters.AddWithValue("@AuditID", criteria.AuditID); + 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("DocumentAuditInfo.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("DocumentAuditInfo.DataPortal_Fetch", ex); + } + } + #endregion + // Standard Refresh + #region extension + DocumentAuditInfoExtension _DocumentAuditInfoExtension = new DocumentAuditInfoExtension(); + [Serializable()] + partial class DocumentAuditInfoExtension : extensionBase { } + [Serializable()] + class extensionBase + { + // Default Refresh + public virtual void Refresh(DocumentAuditInfo tmp) { } + } + #endregion + } // Class + #region Converter + internal class DocumentAuditInfoConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is DocumentAuditInfo) + { + // Return the ToString value + return ((DocumentAuditInfo)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion +} // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/DocumentAuditInfoList.cs b/PROMS/VEPROMS.CSLA.Library/Generated/DocumentAuditInfoList.cs new file mode 100644 index 00000000..24119f8d --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/DocumentAuditInfoList.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 +{ + /// + /// DocumentAuditInfoList Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(DocumentAuditInfoListConverter))] + public partial class DocumentAuditInfoList : 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 (DocumentAuditInfo tmp in this) + { + tmp.Changed += new DocumentAuditInfoEvent(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 (DocumentAuditInfo tmp in this) + { + tmp.Changed -= new DocumentAuditInfoEvent(tmp_Changed); + } + } + #endregion + #region Factory Methods + public static DocumentAuditInfoList _DocumentAuditInfoList = null; + /// + /// Return a list of all DocumentAuditInfo. + /// + public static DocumentAuditInfoList Get() + { + try + { + if (_DocumentAuditInfoList != null) + return _DocumentAuditInfoList; + DocumentAuditInfoList tmp = DataPortal.Fetch(); + DocumentAuditInfo.AddList(tmp); + tmp.AddEvents(); + _DocumentAuditInfoList = tmp; + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on DocumentAuditInfoList.Get", ex); + } + } + /// + /// Reset the list of all DocumentAuditInfo. + /// + public static void Reset() + { + _DocumentAuditInfoList = null; + } + // CSLATODO: Add alternative gets - + //public static DocumentAuditInfoList Get() + //{ + // try + // { + // return DataPortal.Fetch(new FilteredCriteria()); + // } + // catch (Exception ex) + // { + // throw new DbCslaException("Error on DocumentAuditInfoList.Get", ex); + // } + //} + private DocumentAuditInfoList() + { /* require use of factory methods */ } + #endregion + #region Data Access Portal + private void DataPortal_Fetch() + { + this.RaiseListChangedEvents = false; + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocumentAuditInfoList.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getDocumentAudits"; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + IsReadOnly = false; + while (dr.Read()) this.Add(new DocumentAuditInfo(dr)); + IsReadOnly = true; + } + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("DocumentAuditInfoList.DataPortal_Fetch", ex); + throw new DbCslaException("DocumentAuditInfoList.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 + DocumentAuditInfoListPropertyDescriptor pd = new DocumentAuditInfoListPropertyDescriptor(this, i); + pds.Add(pd); + } + // return the property descriptor collection + return pds; + } + #endregion + } // Class + #region Property Descriptor + /// + /// Summary description for CollectionPropertyDescriptor. + /// + public partial class DocumentAuditInfoListPropertyDescriptor : vlnListPropertyDescriptor + { + private DocumentAuditInfo Item { get { return (DocumentAuditInfo)_Item; } } + public DocumentAuditInfoListPropertyDescriptor(DocumentAuditInfoList collection, int index) : base(collection, index) { ;} + } + #endregion + #region Converter + internal class DocumentAuditInfoListConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is DocumentAuditInfoList) + { + // Return department and department role separated by comma. + return ((DocumentAuditInfoList)value).Items.Count.ToString() + " DocumentAudits"; + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion +} // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/EntryAudit.cs b/PROMS/VEPROMS.CSLA.Library/Generated/EntryAudit.cs new file mode 100644 index 00000000..8df68a2f --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/EntryAudit.cs @@ -0,0 +1,902 @@ +// ======================================================================== +// 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 +{ + /// + /// EntryAudit Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(EntryAuditConverter))] + public partial class EntryAudit : BusinessBase, IDisposable, IVEHasBrokenRules + { + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Refresh + private List _RefreshEntryAudits = new List(); + private void AddToRefreshList(List refreshEntryAudits) + { + if (IsDirty) + refreshEntryAudits.Add(this); + } + private void BuildRefreshList() + { + _RefreshEntryAudits = new List(); + AddToRefreshList(_RefreshEntryAudits); + } + private void ProcessRefreshList() + { + foreach (EntryAudit tmp in _RefreshEntryAudits) + { + EntryAuditInfo.Refresh(tmp); + } + } + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(EntryAudit entryAudit) + { + if (!_CacheList.Contains(entryAudit)) _CacheList.Add(entryAudit); // In AddToCache + } + protected static void RemoveFromCache(EntryAudit entryAudit) + { + while (_CacheList.Contains(entryAudit)) _CacheList.Remove(entryAudit); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + while (_CacheList.Count > 0) // Move EntryAudit(s) from temporary _CacheList to _CacheByPrimaryKey + { + EntryAudit tmp = _CacheList[0]; // Get the first EntryAudit + string pKey = tmp.AuditID.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 EntryAudit + } + } + protected static EntryAudit GetCachedByPrimaryKey(long auditID) + { + ConvertListToDictionary(); + string key = auditID.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 _nextAuditID = -1; + public static int NextAuditID + { + get { return _nextAuditID--; } + } + private long _AuditID; + [System.ComponentModel.DataObjectField(true, true)] + public long AuditID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("AuditID", true); + return _AuditID; + } + } + private int _ContentID; + public int ContentID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("ContentID", true); + return _ContentID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + CanWriteProperty("ContentID", true); + if (_ContentID != value) + { + _ContentID = value; + PropertyHasChanged(); + } + } + } + private int _DocID; + public int DocID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("DocID", true); + return _DocID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + CanWriteProperty("DocID", true); + if (_DocID != value) + { + _DocID = 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 int _DeleteStatus; + public int DeleteStatus + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("DeleteStatus", true); + return _DeleteStatus; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + CanWriteProperty("DeleteStatus", true); + if (_DeleteStatus != value) + { + _DeleteStatus = value; + PropertyHasChanged(); + } + } + } + public override bool IsDirty + { + get { return base.IsDirty; } + } + public bool IsDirtyList(List list) + { + return base.IsDirty; + } + public override bool IsValid + { + get { return (IsNew && !IsDirty) ? true : base.IsValid; } + } + public bool IsValidList(List list) + { + return (IsNew && !IsDirty) ? true : base.IsValid; + } + // CSLATODO: Replace base EntryAudit.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current EntryAudit + //public override string ToString() + //{ + // return base.ToString(); + //} + // CSLATODO: Check EntryAudit.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 EntryAudit + protected override object GetIdValue() + { + return MyEntryAuditUnique; // 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; + 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, "UserID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 200)); + //ValidationRules.AddDependantProperty("x", "y"); + _EntryAuditExtension.AddValidationRules(ValidationRules); + // CSLATODO: Add other validation rules + } + protected override void AddInstanceBusinessRules() + { + _EntryAuditExtension.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(AuditID, ""); + //AuthorizationRules.AllowRead(ContentID, ""); + //AuthorizationRules.AllowRead(DocID, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowRead(UserID, ""); + //AuthorizationRules.AllowRead(DeleteStatus, ""); + //AuthorizationRules.AllowWrite(ContentID, ""); + //AuthorizationRules.AllowWrite(DocID, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowWrite(UserID, ""); + //AuthorizationRules.AllowWrite(DeleteStatus, ""); + _EntryAuditExtension.AddAuthorizationRules(AuthorizationRules); + } + protected override void AddInstanceAuthorizationRules() + { + //CSLATODO: Who can read/write which fields + _EntryAuditExtension.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 _EntryAuditUnique = 0; + protected static int EntryAuditUnique + { get { return ++_EntryAuditUnique; } } + private int _MyEntryAuditUnique = EntryAuditUnique; + public int MyEntryAuditUnique // Absolutely Unique ID - Editable + { get { return _MyEntryAuditUnique; } } + protected EntryAudit() + {/* require use of factory methods */ + AddToCache(this); + } + public void Dispose() + { + RemoveFromDictionaries(); + } + private void RemoveFromDictionaries() + { + RemoveFromCache(this); + if (_CacheByPrimaryKey.ContainsKey(AuditID.ToString())) + { + List listEntryAudit = _CacheByPrimaryKey[AuditID.ToString()]; // Get the list of items + while (listEntryAudit.Contains(this)) listEntryAudit.Remove(this); // Remove the item from the list + if (listEntryAudit.Count == 0) //If there are no items left in the list + _CacheByPrimaryKey.Remove(AuditID.ToString()); // remove the list + } + } + public static EntryAudit New() + { + if (!CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a EntryAudit"); + try + { + return DataPortal.Create(); + } + catch (Exception ex) + { + throw new DbCslaException("Error on EntryAudit.New", ex); + } + } + public static EntryAudit New(int contentID, int docID, DateTime dts, string userID, int deleteStatus) + { + EntryAudit tmp = EntryAudit.New(); + tmp.ContentID = contentID; + tmp.DocID = docID; + tmp.DTS = dts; + tmp.UserID = userID; + tmp.DeleteStatus = deleteStatus; + return tmp; + } + public static EntryAudit MakeEntryAudit(int contentID, int docID, DateTime dts, string userID, int deleteStatus) + { + EntryAudit tmp = EntryAudit.New(contentID, docID, dts, userID, deleteStatus); + if (tmp.IsSavable) + { + EntryAudit 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 EntryAudit Get(long auditID) + { + if (!CanGetObject()) + throw new System.Security.SecurityException("User not authorized to view a EntryAudit"); + try + { + EntryAudit tmp = GetCachedByPrimaryKey(auditID); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(auditID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up EntryAudit + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on EntryAudit.Get", ex); + } + } + public static EntryAudit Get(SafeDataReader dr) + { + if (dr.Read()) return new EntryAudit(dr); + return null; + } + internal EntryAudit(SafeDataReader dr) + { + ReadData(dr); + } + public static void Delete(long auditID) + { + if (!CanDeleteObject()) + throw new System.Security.SecurityException("User not authorized to remove a EntryAudit"); + try + { + DataPortal.Delete(new PKCriteria(auditID)); + } + catch (Exception ex) + { + throw new DbCslaException("Error on EntryAudit.Delete", ex); + } + } + public override EntryAudit Save() + { + if (IsDeleted && !CanDeleteObject()) + throw new System.Security.SecurityException("User not authorized to remove a EntryAudit"); + else if (IsNew && !CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a EntryAudit"); + else if (!CanEditObject()) + throw new System.Security.SecurityException("User not authorized to update a EntryAudit"); + try + { + BuildRefreshList(); + EntryAudit entryAudit = base.Save(); + RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache + AddToCache(entryAudit);//Refresh the item in AllList + ProcessRefreshList(); + return entryAudit; + } + catch (Exception ex) + { + throw new DbCslaException("Error on CSLA Save", ex); + } + } + #endregion + #region Data Access Portal + [Serializable()] + protected class PKCriteria + { + private long _AuditID; + public long AuditID + { get { return _AuditID; } } + public PKCriteria(long auditID) + { + _AuditID = auditID; + } + } + // CSLATODO: If Create needs to access DB - It should not be marked RunLocal + [RunLocal()] + private new void DataPortal_Create() + { + _AuditID = NextAuditID; + // Database Defaults + + // CSLATODO: Add any defaults that are necessary + ValidationRules.CheckRules(); + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] EntryAudit.ReadData", GetHashCode()); + try + { + _AuditID = dr.GetInt64("AuditID"); + _ContentID = dr.GetInt32("ContentID"); + _DocID = dr.GetInt32("DocID"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + _DeleteStatus = dr.GetInt32("DeleteStatus"); + MarkOld(); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("EntryAudit.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("EntryAudit.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] EntryAudit.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 = "getEntryAudit"; + cm.Parameters.AddWithValue("@AuditID", criteria.AuditID); + 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("EntryAudit.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("EntryAudit.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("EntryAudit.DataPortal_Insert", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("EntryAudit.DataPortal_Insert", ex); + } + finally + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] EntryAudit.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 = "addEntryAudit"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@ContentID", _ContentID); + cm.Parameters.AddWithValue("@DocID", _DocID); + if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS); + cm.Parameters.AddWithValue("@UserID", _UserID); + cm.Parameters.AddWithValue("@DeleteStatus", _DeleteStatus); + // Output Calculated Columns + SqlParameter param_AuditID = new SqlParameter("@newAuditID", SqlDbType.BigInt); + param_AuditID.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_AuditID); + // CSLATODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + _AuditID = (long)cm.Parameters["@newAuditID"].Value; + } + MarkOld(); + // update child objects + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] EntryAudit.SQLInsert", GetHashCode()); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("EntryAudit.SQLInsert", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("EntryAudit.SQLInsert", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + public static void Add(SqlConnection cn, ref long auditID, int contentID, int docID, DateTime dts, string userID, int deleteStatus) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] EntryAudit.Add", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "addEntryAudit"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@ContentID", contentID); + cm.Parameters.AddWithValue("@DocID", docID); + if (dts.Year >= 1753 && dts.Year <= 9999) cm.Parameters.AddWithValue("@DTS", dts); + cm.Parameters.AddWithValue("@UserID", userID); + cm.Parameters.AddWithValue("@DeleteStatus", deleteStatus); + // Output Calculated Columns + SqlParameter param_AuditID = new SqlParameter("@newAuditID", SqlDbType.BigInt); + param_AuditID.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_AuditID); + // CSLATODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + auditID = (long)cm.Parameters["@newAuditID"].Value; + // No Timestamp value to return + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("EntryAudit.Add", ex); + throw new DbCslaException("EntryAudit.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}] EntryAudit.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("EntryAudit.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}] EntryAudit.SQLUpdate", GetHashCode()); + try + { + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + if (base.IsDirty) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "updateEntryAudit"; + // All Fields including Calculated Fields + cm.Parameters.AddWithValue("@AuditID", _AuditID); + cm.Parameters.AddWithValue("@ContentID", _ContentID); + cm.Parameters.AddWithValue("@DocID", _DocID); + if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS); + cm.Parameters.AddWithValue("@UserID", _UserID); + cm.Parameters.AddWithValue("@DeleteStatus", _DeleteStatus); + // Output Calculated Columns + // CSLATODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + } + } + MarkOld(); + // use the open connection to update child objects + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("EntryAudit.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) + EntryAudit.Add(cn, ref _AuditID, _ContentID, _DocID, _DTS, _UserID, _DeleteStatus); + else + EntryAudit.Update(cn, ref _AuditID, _ContentID, _DocID, _DTS, _UserID, _DeleteStatus); + MarkOld(); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + public static void Update(SqlConnection cn, ref long auditID, int contentID, int docID, DateTime dts, string userID, int deleteStatus) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] EntryAudit.Update", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "updateEntryAudit"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@AuditID", auditID); + cm.Parameters.AddWithValue("@ContentID", contentID); + cm.Parameters.AddWithValue("@DocID", docID); + if (dts.Year >= 1753 && dts.Year <= 9999) cm.Parameters.AddWithValue("@DTS", dts); + cm.Parameters.AddWithValue("@UserID", userID); + cm.Parameters.AddWithValue("@DeleteStatus", deleteStatus); + // Output Calculated Columns + // CSLATODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + // No Timestamp value to return + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("EntryAudit.Update", ex); + throw new DbCslaException("EntryAudit.Update", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_DeleteSelf() + { + DataPortal_Delete(new PKCriteria(_AuditID)); + } + [Transactional(TransactionalTypes.TransactionScope)] + private void DataPortal_Delete(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] EntryAudit.DataPortal_Delete", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "deleteEntryAudit"; + cm.Parameters.AddWithValue("@AuditID", criteria.AuditID); + cm.ExecuteNonQuery(); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("EntryAudit.DataPortal_Delete", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("EntryAudit.DataPortal_Delete", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + public static void Remove(SqlConnection cn, long auditID) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] EntryAudit.Remove", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "deleteEntryAudit"; + // Input PK Fields + cm.Parameters.AddWithValue("@AuditID", auditID); + // CSLATODO: Define any additional output parameters + cm.ExecuteNonQuery(); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("EntryAudit.Remove", ex); + throw new DbCslaException("EntryAudit.Remove", ex); + } + } + #endregion + // Standard Default Code + #region extension + EntryAuditExtension _EntryAuditExtension = new EntryAuditExtension(); + [Serializable()] + partial class EntryAuditExtension : 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 EntryAuditConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is EntryAudit) + { + // Return the ToString value + return ((EntryAudit)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion +} // Namespace + + +//// The following is a sample Extension File. You can use it to create EntryAuditExt.cs +//using System; +//using System.Collections.Generic; +//using System.Text; +//using Csla; + +//namespace VEPROMS.CSLA.Library +//{ +// public partial class EntryAudit +// { +// partial class EntryAuditExtension : 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/EntryAuditInfo.cs b/PROMS/VEPROMS.CSLA.Library/Generated/EntryAuditInfo.cs new file mode 100644 index 00000000..add93ba7 --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/EntryAuditInfo.cs @@ -0,0 +1,346 @@ +// ======================================================================== +// 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 EntryAuditInfoEvent(object sender); + /// + /// EntryAuditInfo Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(EntryAuditInfoConverter))] + public partial class EntryAuditInfo : ReadOnlyBase, IDisposable + { + public event EntryAuditInfoEvent 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(EntryAuditInfo entryAuditInfo) + { + if (!_CacheList.Contains(entryAuditInfo)) _CacheList.Add(entryAuditInfo); // In AddToCache + } + protected static void RemoveFromCache(EntryAuditInfo entryAuditInfo) + { + while (_CacheList.Contains(entryAuditInfo)) _CacheList.Remove(entryAuditInfo); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + while (_CacheList.Count > 0) // Move EntryAuditInfo(s) from temporary _CacheList to _CacheByPrimaryKey + { + EntryAuditInfo tmp = _CacheList[0]; // Get the first EntryAuditInfo + string pKey = tmp.AuditID.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 EntryAuditInfo + } + } + internal static void AddList(EntryAuditInfoList lst) + { + foreach (EntryAuditInfo item in lst) AddToCache(item); + } + protected static EntryAuditInfo GetCachedByPrimaryKey(long auditID) + { + ConvertListToDictionary(); + string key = auditID.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 EntryAudit _Editable; + private IVEHasBrokenRules HasBrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = null; + if (_Editable != null) + hasBrokenRules = _Editable.HasBrokenRules; + return hasBrokenRules; + } + } + private long _AuditID; + [System.ComponentModel.DataObjectField(true, true)] + public long AuditID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("AuditID", true); + return _AuditID; + } + } + private int _ContentID; + public int ContentID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("ContentID", true); + return _ContentID; + } + } + private int _DocID; + public int DocID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("DocID", true); + return _DocID; + } + } + 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 _DeleteStatus; + public int DeleteStatus + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("DeleteStatus", true); + return _DeleteStatus; + } + } + // CSLATODO: Replace base EntryAuditInfo.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current EntryAuditInfo + //public override string ToString() + //{ + // return base.ToString(); + //} + // CSLATODO: Check EntryAuditInfo.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 EntryAuditInfo + protected override object GetIdValue() + { + return MyEntryAuditInfoUnique; // Absolutely Unique ID + } + #endregion + #region Factory Methods + private static int _EntryAuditInfoUnique = 0; + private static int EntryAuditInfoUnique + { get { return ++_EntryAuditInfoUnique; } } + private int _MyEntryAuditInfoUnique = EntryAuditInfoUnique; + public int MyEntryAuditInfoUnique // Absolutely Unique ID - Info + { get { return _MyEntryAuditInfoUnique; } } + protected EntryAuditInfo() + {/* require use of factory methods */ + AddToCache(this); + } + public void Dispose() + { + RemoveFromCache(this); + if (!_CacheByPrimaryKey.ContainsKey(AuditID.ToString())) return; + List listEntryAuditInfo = _CacheByPrimaryKey[AuditID.ToString()]; // Get the list of items + while (listEntryAuditInfo.Contains(this)) listEntryAuditInfo.Remove(this); // Remove the item from the list + if (listEntryAuditInfo.Count == 0) // If there are no items left in the list + _CacheByPrimaryKey.Remove(AuditID.ToString()); // remove the list + } + public virtual EntryAudit Get() + { + return _Editable = EntryAudit.Get(_AuditID); + } + public static void Refresh(EntryAudit tmp) + { + string key = tmp.AuditID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (EntryAuditInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(EntryAudit tmp) + { + _ContentID = tmp.ContentID; + _DocID = tmp.DocID; + _DTS = tmp.DTS; + _UserID = tmp.UserID; + _DeleteStatus = tmp.DeleteStatus; + _EntryAuditInfoExtension.Refresh(this); + OnChange();// raise an event + } + public static EntryAuditInfo Get(long auditID) + { + //if (!CanGetObject()) + // throw new System.Security.SecurityException("User not authorized to view a EntryAudit"); + try + { + EntryAuditInfo tmp = GetCachedByPrimaryKey(auditID); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(auditID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up EntryAuditInfo + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on EntryAuditInfo.Get", ex); + } + } + #endregion + #region Data Access Portal + internal EntryAuditInfo(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] EntryAuditInfo.Constructor", GetHashCode()); + try + { + ReadData(dr); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("EntryAuditInfo.Constructor", ex); + throw new DbCslaException("EntryAuditInfo.Constructor", ex); + } + } + [Serializable()] + protected class PKCriteria + { + private long _AuditID; + public long AuditID + { get { return _AuditID; } } + public PKCriteria(long auditID) + { + _AuditID = auditID; + } + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] EntryAuditInfo.ReadData", GetHashCode()); + try + { + _AuditID = dr.GetInt64("AuditID"); + _ContentID = dr.GetInt32("ContentID"); + _DocID = dr.GetInt32("DocID"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + _DeleteStatus = dr.GetInt32("DeleteStatus"); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("EntryAuditInfo.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("EntryAuditInfo.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] EntryAuditInfo.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 = "getEntryAudit"; + cm.Parameters.AddWithValue("@AuditID", criteria.AuditID); + 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("EntryAuditInfo.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("EntryAuditInfo.DataPortal_Fetch", ex); + } + } + #endregion + // Standard Refresh + #region extension + EntryAuditInfoExtension _EntryAuditInfoExtension = new EntryAuditInfoExtension(); + [Serializable()] + partial class EntryAuditInfoExtension : extensionBase { } + [Serializable()] + class extensionBase + { + // Default Refresh + public virtual void Refresh(EntryAuditInfo tmp) { } + } + #endregion + } // Class + #region Converter + internal class EntryAuditInfoConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is EntryAuditInfo) + { + // Return the ToString value + return ((EntryAuditInfo)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion +} // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/EntryAuditInfoList.cs b/PROMS/VEPROMS.CSLA.Library/Generated/EntryAuditInfoList.cs new file mode 100644 index 00000000..16291dcf --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/EntryAuditInfoList.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 +{ + /// + /// EntryAuditInfoList Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(EntryAuditInfoListConverter))] + public partial class EntryAuditInfoList : 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 (EntryAuditInfo tmp in this) + { + tmp.Changed += new EntryAuditInfoEvent(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 (EntryAuditInfo tmp in this) + { + tmp.Changed -= new EntryAuditInfoEvent(tmp_Changed); + } + } + #endregion + #region Factory Methods + public static EntryAuditInfoList _EntryAuditInfoList = null; + /// + /// Return a list of all EntryAuditInfo. + /// + public static EntryAuditInfoList Get() + { + try + { + if (_EntryAuditInfoList != null) + return _EntryAuditInfoList; + EntryAuditInfoList tmp = DataPortal.Fetch(); + EntryAuditInfo.AddList(tmp); + tmp.AddEvents(); + _EntryAuditInfoList = tmp; + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on EntryAuditInfoList.Get", ex); + } + } + /// + /// Reset the list of all EntryAuditInfo. + /// + public static void Reset() + { + _EntryAuditInfoList = null; + } + // CSLATODO: Add alternative gets - + //public static EntryAuditInfoList Get() + //{ + // try + // { + // return DataPortal.Fetch(new FilteredCriteria()); + // } + // catch (Exception ex) + // { + // throw new DbCslaException("Error on EntryAuditInfoList.Get", ex); + // } + //} + private EntryAuditInfoList() + { /* require use of factory methods */ } + #endregion + #region Data Access Portal + private void DataPortal_Fetch() + { + this.RaiseListChangedEvents = false; + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] EntryAuditInfoList.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getEntryAudits"; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + IsReadOnly = false; + while (dr.Read()) this.Add(new EntryAuditInfo(dr)); + IsReadOnly = true; + } + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("EntryAuditInfoList.DataPortal_Fetch", ex); + throw new DbCslaException("EntryAuditInfoList.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 + EntryAuditInfoListPropertyDescriptor pd = new EntryAuditInfoListPropertyDescriptor(this, i); + pds.Add(pd); + } + // return the property descriptor collection + return pds; + } + #endregion + } // Class + #region Property Descriptor + /// + /// Summary description for CollectionPropertyDescriptor. + /// + public partial class EntryAuditInfoListPropertyDescriptor : vlnListPropertyDescriptor + { + private EntryAuditInfo Item { get { return (EntryAuditInfo)_Item; } } + public EntryAuditInfoListPropertyDescriptor(EntryAuditInfoList collection, int index) : base(collection, index) { ;} + } + #endregion + #region Converter + internal class EntryAuditInfoListConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is EntryAuditInfoList) + { + // Return department and department role separated by comma. + return ((EntryAuditInfoList)value).Items.Count.ToString() + " EntryAudits"; + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion +} // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/GridAudit.cs b/PROMS/VEPROMS.CSLA.Library/Generated/GridAudit.cs new file mode 100644 index 00000000..d4e6af6a --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/GridAudit.cs @@ -0,0 +1,1070 @@ +// ======================================================================== +// 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 +{ + /// + /// GridAudit Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(GridAuditConverter))] + public partial class GridAudit : BusinessBase, IDisposable, IVEHasBrokenRules + { + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Refresh + private List _RefreshGridAudits = new List(); + private void AddToRefreshList(List refreshGridAudits) + { + if (IsDirty) + refreshGridAudits.Add(this); + } + private void BuildRefreshList() + { + _RefreshGridAudits = new List(); + AddToRefreshList(_RefreshGridAudits); + } + private void ProcessRefreshList() + { + foreach (GridAudit tmp in _RefreshGridAudits) + { + GridAuditInfo.Refresh(tmp); + } + } + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(GridAudit gridAudit) + { + if (!_CacheList.Contains(gridAudit)) _CacheList.Add(gridAudit); // In AddToCache + } + protected static void RemoveFromCache(GridAudit gridAudit) + { + while (_CacheList.Contains(gridAudit)) _CacheList.Remove(gridAudit); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + while (_CacheList.Count > 0) // Move GridAudit(s) from temporary _CacheList to _CacheByPrimaryKey + { + GridAudit tmp = _CacheList[0]; // Get the first GridAudit + string pKey = tmp.AuditID.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 GridAudit + } + } + protected static GridAudit GetCachedByPrimaryKey(long auditID) + { + ConvertListToDictionary(); + string key = auditID.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 _nextAuditID = -1; + public static int NextAuditID + { + get { return _nextAuditID--; } + } + private long _AuditID; + [System.ComponentModel.DataObjectField(true, true)] + public long AuditID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("AuditID", true); + return _AuditID; + } + } + private int _ContentID; + public int ContentID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("ContentID", true); + return _ContentID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + CanWriteProperty("ContentID", true); + if (_ContentID != value) + { + _ContentID = value; + PropertyHasChanged(); + } + } + } + private string _Data = string.Empty; + public string Data + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("Data", true); + return _Data; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + CanWriteProperty("Data", true); + if (value == null) value = string.Empty; + if (_Data != value) + { + _Data = 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 int _DeleteStatus; + public int DeleteStatus + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("DeleteStatus", true); + return _DeleteStatus; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + CanWriteProperty("DeleteStatus", true); + if (_DeleteStatus != value) + { + _DeleteStatus = value; + PropertyHasChanged(); + } + } + } + private long _ContentAuditID; + public long ContentAuditID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("ContentAuditID", true); + return _ContentAuditID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + CanWriteProperty("ContentAuditID", true); + if (_ContentAuditID != value) + { + _ContentAuditID = value; + PropertyHasChanged(); + } + } + } + public override bool IsDirty + { + get { return base.IsDirty; } + } + public bool IsDirtyList(List list) + { + return base.IsDirty; + } + public override bool IsValid + { + get { return (IsNew && !IsDirty) ? true : base.IsValid; } + } + public bool IsValidList(List list) + { + return (IsNew && !IsDirty) ? true : base.IsValid; + } + // CSLATODO: Replace base GridAudit.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current GridAudit + //public override string ToString() + //{ + // return base.ToString(); + //} + // CSLATODO: Check GridAudit.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 GridAudit + protected override object GetIdValue() + { + return MyGridAuditUnique; // 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; + 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, "Data"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Data", 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", 200)); + //ValidationRules.AddDependantProperty("x", "y"); + _GridAuditExtension.AddValidationRules(ValidationRules); + // CSLATODO: Add other validation rules + } + protected override void AddInstanceBusinessRules() + { + _GridAuditExtension.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(AuditID, ""); + //AuthorizationRules.AllowRead(ContentID, ""); + //AuthorizationRules.AllowRead(Data, ""); + //AuthorizationRules.AllowRead(Config, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowRead(UserID, ""); + //AuthorizationRules.AllowRead(DeleteStatus, ""); + //AuthorizationRules.AllowRead(ContentAuditID, ""); + //AuthorizationRules.AllowWrite(ContentID, ""); + //AuthorizationRules.AllowWrite(Data, ""); + //AuthorizationRules.AllowWrite(Config, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowWrite(UserID, ""); + //AuthorizationRules.AllowWrite(DeleteStatus, ""); + //AuthorizationRules.AllowWrite(ContentAuditID, ""); + _GridAuditExtension.AddAuthorizationRules(AuthorizationRules); + } + protected override void AddInstanceAuthorizationRules() + { + //CSLATODO: Who can read/write which fields + _GridAuditExtension.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 _GridAuditUnique = 0; + protected static int GridAuditUnique + { get { return ++_GridAuditUnique; } } + private int _MyGridAuditUnique = GridAuditUnique; + public int MyGridAuditUnique // Absolutely Unique ID - Editable + { get { return _MyGridAuditUnique; } } + protected GridAudit() + {/* require use of factory methods */ + AddToCache(this); + } + public void Dispose() + { + RemoveFromDictionaries(); + } + private void RemoveFromDictionaries() + { + RemoveFromCache(this); + if (_CacheByPrimaryKey.ContainsKey(AuditID.ToString())) + { + List listGridAudit = _CacheByPrimaryKey[AuditID.ToString()]; // Get the list of items + while (listGridAudit.Contains(this)) listGridAudit.Remove(this); // Remove the item from the list + if (listGridAudit.Count == 0) //If there are no items left in the list + _CacheByPrimaryKey.Remove(AuditID.ToString()); // remove the list + } + } + public static GridAudit New() + { + if (!CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a GridAudit"); + try + { + return DataPortal.Create(); + } + catch (Exception ex) + { + throw new DbCslaException("Error on GridAudit.New", ex); + } + } + public static GridAudit New(int contentID, string data, DateTime dts, string userID, int deleteStatus) + { + GridAudit tmp = GridAudit.New(); + tmp.ContentID = contentID; + tmp.Data = data; + tmp.DTS = dts; + tmp.UserID = userID; + tmp.DeleteStatus = deleteStatus; + return tmp; + } + public static GridAudit New(int contentID, string data, string config, DateTime dts, string userID, int deleteStatus, long contentAuditID) + { + GridAudit tmp = GridAudit.New(); + tmp.ContentID = contentID; + tmp.Data = data; + tmp.Config = config; + tmp.DTS = dts; + tmp.UserID = userID; + tmp.DeleteStatus = deleteStatus; + tmp.ContentAuditID = contentAuditID; + return tmp; + } + public static GridAudit MakeGridAudit(int contentID, string data, string config, DateTime dts, string userID, int deleteStatus, long contentAuditID) + { + GridAudit tmp = GridAudit.New(contentID, data, config, dts, userID, deleteStatus, contentAuditID); + if (tmp.IsSavable) + { + GridAudit 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 GridAudit New(int contentID, string data, string config, DateTime dts, string userID, int deleteStatus) + { + GridAudit tmp = GridAudit.New(); + tmp.ContentID = contentID; + tmp.Data = data; + tmp.Config = config; + tmp.DTS = dts; + tmp.UserID = userID; + tmp.DeleteStatus = deleteStatus; + return tmp; + } + public static GridAudit MakeGridAudit(int contentID, string data, string config, DateTime dts, string userID, int deleteStatus) + { + GridAudit tmp = GridAudit.New(contentID, data, config, dts, userID, deleteStatus); + if (tmp.IsSavable) + { + GridAudit 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 GridAudit Get(long auditID) + { + if (!CanGetObject()) + throw new System.Security.SecurityException("User not authorized to view a GridAudit"); + try + { + GridAudit tmp = GetCachedByPrimaryKey(auditID); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(auditID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up GridAudit + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on GridAudit.Get", ex); + } + } + public static GridAudit Get(SafeDataReader dr) + { + if (dr.Read()) return new GridAudit(dr); + return null; + } + internal GridAudit(SafeDataReader dr) + { + ReadData(dr); + } + public static void Delete(long auditID) + { + if (!CanDeleteObject()) + throw new System.Security.SecurityException("User not authorized to remove a GridAudit"); + try + { + DataPortal.Delete(new PKCriteria(auditID)); + } + catch (Exception ex) + { + throw new DbCslaException("Error on GridAudit.Delete", ex); + } + } + public override GridAudit Save() + { + if (IsDeleted && !CanDeleteObject()) + throw new System.Security.SecurityException("User not authorized to remove a GridAudit"); + else if (IsNew && !CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a GridAudit"); + else if (!CanEditObject()) + throw new System.Security.SecurityException("User not authorized to update a GridAudit"); + try + { + BuildRefreshList(); + GridAudit gridAudit = base.Save(); + RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache + AddToCache(gridAudit);//Refresh the item in AllList + ProcessRefreshList(); + return gridAudit; + } + catch (Exception ex) + { + throw new DbCslaException("Error on CSLA Save", ex); + } + } + #endregion + #region Data Access Portal + [Serializable()] + protected class PKCriteria + { + private long _AuditID; + public long AuditID + { get { return _AuditID; } } + public PKCriteria(long auditID) + { + _AuditID = auditID; + } + } + // CSLATODO: If Create needs to access DB - It should not be marked RunLocal + [RunLocal()] + private new void DataPortal_Create() + { + _AuditID = NextAuditID; + // Database Defaults + _ContentAuditID = _GridAuditExtension.DefaultContentAuditID; + // CSLATODO: Add any defaults that are necessary + ValidationRules.CheckRules(); + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] GridAudit.ReadData", GetHashCode()); + try + { + _AuditID = dr.GetInt64("AuditID"); + _ContentID = dr.GetInt32("ContentID"); + _Data = dr.GetString("Data"); + _Config = dr.GetString("Config"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + _DeleteStatus = dr.GetInt32("DeleteStatus"); + _ContentAuditID = dr.GetInt64("ContentAuditID"); + MarkOld(); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("GridAudit.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("GridAudit.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] GridAudit.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 = "getGridAudit"; + cm.Parameters.AddWithValue("@AuditID", criteria.AuditID); + 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("GridAudit.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("GridAudit.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("GridAudit.DataPortal_Insert", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("GridAudit.DataPortal_Insert", ex); + } + finally + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] GridAudit.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 = "addGridAudit"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@ContentID", _ContentID); + cm.Parameters.AddWithValue("@Data", _Data); + 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("@DeleteStatus", _DeleteStatus); + cm.Parameters.AddWithValue("@ContentAuditID", _ContentAuditID); + // Output Calculated Columns + SqlParameter param_AuditID = new SqlParameter("@newAuditID", SqlDbType.BigInt); + param_AuditID.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_AuditID); + // CSLATODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + _AuditID = (long)cm.Parameters["@newAuditID"].Value; + } + MarkOld(); + // update child objects + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] GridAudit.SQLInsert", GetHashCode()); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("GridAudit.SQLInsert", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("GridAudit.SQLInsert", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + public static void Add(SqlConnection cn, ref long auditID, int contentID, string data, string config, DateTime dts, string userID, int deleteStatus, long contentAuditID) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] GridAudit.Add", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "addGridAudit"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@ContentID", contentID); + cm.Parameters.AddWithValue("@Data", data); + 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("@DeleteStatus", deleteStatus); + cm.Parameters.AddWithValue("@ContentAuditID", contentAuditID); + // Output Calculated Columns + SqlParameter param_AuditID = new SqlParameter("@newAuditID", SqlDbType.BigInt); + param_AuditID.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_AuditID); + // CSLATODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + auditID = (long)cm.Parameters["@newAuditID"].Value; + // No Timestamp value to return + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("GridAudit.Add", ex); + throw new DbCslaException("GridAudit.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}] GridAudit.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("GridAudit.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}] GridAudit.SQLUpdate", GetHashCode()); + try + { + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + if (base.IsDirty) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "updateGridAudit"; + // All Fields including Calculated Fields + cm.Parameters.AddWithValue("@AuditID", _AuditID); + cm.Parameters.AddWithValue("@ContentID", _ContentID); + cm.Parameters.AddWithValue("@Data", _Data); + 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("@DeleteStatus", _DeleteStatus); + cm.Parameters.AddWithValue("@ContentAuditID", _ContentAuditID); + // Output Calculated Columns + // CSLATODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + } + } + MarkOld(); + // use the open connection to update child objects + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("GridAudit.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) + GridAudit.Add(cn, ref _AuditID, _ContentID, _Data, _Config, _DTS, _UserID, _DeleteStatus, _ContentAuditID); + else + GridAudit.Update(cn, ref _AuditID, _ContentID, _Data, _Config, _DTS, _UserID, _DeleteStatus, _ContentAuditID); + MarkOld(); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + public static void Update(SqlConnection cn, ref long auditID, int contentID, string data, string config, DateTime dts, string userID, int deleteStatus, long contentAuditID) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] GridAudit.Update", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "updateGridAudit"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@AuditID", auditID); + cm.Parameters.AddWithValue("@ContentID", contentID); + cm.Parameters.AddWithValue("@Data", data); + 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("@DeleteStatus", deleteStatus); + cm.Parameters.AddWithValue("@ContentAuditID", contentAuditID); + // Output Calculated Columns + // CSLATODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + // No Timestamp value to return + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("GridAudit.Update", ex); + throw new DbCslaException("GridAudit.Update", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_DeleteSelf() + { + DataPortal_Delete(new PKCriteria(_AuditID)); + } + [Transactional(TransactionalTypes.TransactionScope)] + private void DataPortal_Delete(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] GridAudit.DataPortal_Delete", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "deleteGridAudit"; + cm.Parameters.AddWithValue("@AuditID", criteria.AuditID); + cm.ExecuteNonQuery(); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("GridAudit.DataPortal_Delete", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("GridAudit.DataPortal_Delete", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + public static void Remove(SqlConnection cn, long auditID) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] GridAudit.Remove", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "deleteGridAudit"; + // Input PK Fields + cm.Parameters.AddWithValue("@AuditID", auditID); + // CSLATODO: Define any additional output parameters + cm.ExecuteNonQuery(); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("GridAudit.Remove", ex); + throw new DbCslaException("GridAudit.Remove", ex); + } + } + #endregion + #region Exists + public static bool Exists(long auditID) + { + ExistsCommand result; + try + { + result = DataPortal.Execute(new ExistsCommand(auditID)); + return result.Exists; + } + catch (Exception ex) + { + throw new DbCslaException("Error on GridAudit.Exists", ex); + } + } + [Serializable()] + private class ExistsCommand : CommandBase + { + private long _AuditID; + private bool _exists; + public bool Exists + { + get { return _exists; } + } + public ExistsCommand(long auditID) + { + _AuditID = auditID; + } + protected override void DataPortal_Execute() + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] GridAudit.DataPortal_Execute", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + cn.Open(); + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "existsGridAudit"; + cm.Parameters.AddWithValue("@AuditID", _AuditID); + int count = (int)cm.ExecuteScalar(); + _exists = (count > 0); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("GridAudit.DataPortal_Execute", ex); + throw new DbCslaException("GridAudit.DataPortal_Execute", ex); + } + } + } + #endregion + // Standard Default Code + #region extension + GridAuditExtension _GridAuditExtension = new GridAuditExtension(); + [Serializable()] + partial class GridAuditExtension : extensionBase + { + } + [Serializable()] + class extensionBase + { + // Default Values + public virtual long DefaultContentAuditID + { + get { return 0; } + } + // 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 GridAuditConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is GridAudit) + { + // Return the ToString value + return ((GridAudit)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion +} // Namespace + + +//// The following is a sample Extension File. You can use it to create GridAuditExt.cs +//using System; +//using System.Collections.Generic; +//using System.Text; +//using Csla; + +//namespace VEPROMS.CSLA.Library +//{ +// public partial class GridAudit +// { +// partial class GridAuditExtension : extensionBase +// { +// // CSLATODO: Override automatic defaults +// public virtual long DefaultContentAuditID +// { +// get { return 0; } +// } +// 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/GridAuditInfo.cs b/PROMS/VEPROMS.CSLA.Library/Generated/GridAuditInfo.cs new file mode 100644 index 00000000..13e6f8de --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/GridAuditInfo.cs @@ -0,0 +1,370 @@ +// ======================================================================== +// 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 GridAuditInfoEvent(object sender); + /// + /// GridAuditInfo Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(GridAuditInfoConverter))] + public partial class GridAuditInfo : ReadOnlyBase, IDisposable + { + public event GridAuditInfoEvent 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(GridAuditInfo gridAuditInfo) + { + if (!_CacheList.Contains(gridAuditInfo)) _CacheList.Add(gridAuditInfo); // In AddToCache + } + protected static void RemoveFromCache(GridAuditInfo gridAuditInfo) + { + while (_CacheList.Contains(gridAuditInfo)) _CacheList.Remove(gridAuditInfo); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + while (_CacheList.Count > 0) // Move GridAuditInfo(s) from temporary _CacheList to _CacheByPrimaryKey + { + GridAuditInfo tmp = _CacheList[0]; // Get the first GridAuditInfo + string pKey = tmp.AuditID.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 GridAuditInfo + } + } + internal static void AddList(GridAuditInfoList lst) + { + foreach (GridAuditInfo item in lst) AddToCache(item); + } + protected static GridAuditInfo GetCachedByPrimaryKey(long auditID) + { + ConvertListToDictionary(); + string key = auditID.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 GridAudit _Editable; + private IVEHasBrokenRules HasBrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = null; + if (_Editable != null) + hasBrokenRules = _Editable.HasBrokenRules; + return hasBrokenRules; + } + } + private long _AuditID; + [System.ComponentModel.DataObjectField(true, true)] + public long AuditID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("AuditID", true); + return _AuditID; + } + } + private int _ContentID; + public int ContentID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("ContentID", true); + return _ContentID; + } + } + private string _Data = string.Empty; + public string Data + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("Data", true); + return _Data; + } + } + 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 _DeleteStatus; + public int DeleteStatus + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("DeleteStatus", true); + return _DeleteStatus; + } + } + private long _ContentAuditID; + public long ContentAuditID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("ContentAuditID", true); + return _ContentAuditID; + } + } + // CSLATODO: Replace base GridAuditInfo.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current GridAuditInfo + //public override string ToString() + //{ + // return base.ToString(); + //} + // CSLATODO: Check GridAuditInfo.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 GridAuditInfo + protected override object GetIdValue() + { + return MyGridAuditInfoUnique; // Absolutely Unique ID + } + #endregion + #region Factory Methods + private static int _GridAuditInfoUnique = 0; + private static int GridAuditInfoUnique + { get { return ++_GridAuditInfoUnique; } } + private int _MyGridAuditInfoUnique = GridAuditInfoUnique; + public int MyGridAuditInfoUnique // Absolutely Unique ID - Info + { get { return _MyGridAuditInfoUnique; } } + protected GridAuditInfo() + {/* require use of factory methods */ + AddToCache(this); + } + public void Dispose() + { + RemoveFromCache(this); + if (!_CacheByPrimaryKey.ContainsKey(AuditID.ToString())) return; + List listGridAuditInfo = _CacheByPrimaryKey[AuditID.ToString()]; // Get the list of items + while (listGridAuditInfo.Contains(this)) listGridAuditInfo.Remove(this); // Remove the item from the list + if (listGridAuditInfo.Count == 0) // If there are no items left in the list + _CacheByPrimaryKey.Remove(AuditID.ToString()); // remove the list + } + public virtual GridAudit Get() + { + return _Editable = GridAudit.Get(_AuditID); + } + public static void Refresh(GridAudit tmp) + { + string key = tmp.AuditID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (GridAuditInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(GridAudit tmp) + { + _ContentID = tmp.ContentID; + _Data = tmp.Data; + _Config = tmp.Config; + _DTS = tmp.DTS; + _UserID = tmp.UserID; + _DeleteStatus = tmp.DeleteStatus; + _ContentAuditID = tmp.ContentAuditID; + _GridAuditInfoExtension.Refresh(this); + OnChange();// raise an event + } + public static GridAuditInfo Get(long auditID) + { + //if (!CanGetObject()) + // throw new System.Security.SecurityException("User not authorized to view a GridAudit"); + try + { + GridAuditInfo tmp = GetCachedByPrimaryKey(auditID); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(auditID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up GridAuditInfo + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on GridAuditInfo.Get", ex); + } + } + #endregion + #region Data Access Portal + internal GridAuditInfo(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] GridAuditInfo.Constructor", GetHashCode()); + try + { + ReadData(dr); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("GridAuditInfo.Constructor", ex); + throw new DbCslaException("GridAuditInfo.Constructor", ex); + } + } + [Serializable()] + protected class PKCriteria + { + private long _AuditID; + public long AuditID + { get { return _AuditID; } } + public PKCriteria(long auditID) + { + _AuditID = auditID; + } + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] GridAuditInfo.ReadData", GetHashCode()); + try + { + _AuditID = dr.GetInt64("AuditID"); + _ContentID = dr.GetInt32("ContentID"); + _Data = dr.GetString("Data"); + _Config = dr.GetString("Config"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + _DeleteStatus = dr.GetInt32("DeleteStatus"); + _ContentAuditID = dr.GetInt64("ContentAuditID"); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("GridAuditInfo.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("GridAuditInfo.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] GridAuditInfo.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 = "getGridAudit"; + cm.Parameters.AddWithValue("@AuditID", criteria.AuditID); + 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("GridAuditInfo.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("GridAuditInfo.DataPortal_Fetch", ex); + } + } + #endregion + // Standard Refresh + #region extension + GridAuditInfoExtension _GridAuditInfoExtension = new GridAuditInfoExtension(); + [Serializable()] + partial class GridAuditInfoExtension : extensionBase { } + [Serializable()] + class extensionBase + { + // Default Refresh + public virtual void Refresh(GridAuditInfo tmp) { } + } + #endregion + } // Class + #region Converter + internal class GridAuditInfoConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is GridAuditInfo) + { + // Return the ToString value + return ((GridAuditInfo)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion +} // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/GridAuditInfoList.cs b/PROMS/VEPROMS.CSLA.Library/Generated/GridAuditInfoList.cs new file mode 100644 index 00000000..64f6c76f --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/GridAuditInfoList.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 +{ + /// + /// GridAuditInfoList Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(GridAuditInfoListConverter))] + public partial class GridAuditInfoList : 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 (GridAuditInfo tmp in this) + { + tmp.Changed += new GridAuditInfoEvent(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 (GridAuditInfo tmp in this) + { + tmp.Changed -= new GridAuditInfoEvent(tmp_Changed); + } + } + #endregion + #region Factory Methods + public static GridAuditInfoList _GridAuditInfoList = null; + /// + /// Return a list of all GridAuditInfo. + /// + public static GridAuditInfoList Get() + { + try + { + if (_GridAuditInfoList != null) + return _GridAuditInfoList; + GridAuditInfoList tmp = DataPortal.Fetch(); + GridAuditInfo.AddList(tmp); + tmp.AddEvents(); + _GridAuditInfoList = tmp; + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on GridAuditInfoList.Get", ex); + } + } + /// + /// Reset the list of all GridAuditInfo. + /// + public static void Reset() + { + _GridAuditInfoList = null; + } + // CSLATODO: Add alternative gets - + //public static GridAuditInfoList Get() + //{ + // try + // { + // return DataPortal.Fetch(new FilteredCriteria()); + // } + // catch (Exception ex) + // { + // throw new DbCslaException("Error on GridAuditInfoList.Get", ex); + // } + //} + private GridAuditInfoList() + { /* require use of factory methods */ } + #endregion + #region Data Access Portal + private void DataPortal_Fetch() + { + this.RaiseListChangedEvents = false; + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] GridAuditInfoList.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getGridAudits"; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + IsReadOnly = false; + while (dr.Read()) this.Add(new GridAuditInfo(dr)); + IsReadOnly = true; + } + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("GridAuditInfoList.DataPortal_Fetch", ex); + throw new DbCslaException("GridAuditInfoList.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 + GridAuditInfoListPropertyDescriptor pd = new GridAuditInfoListPropertyDescriptor(this, i); + pds.Add(pd); + } + // return the property descriptor collection + return pds; + } + #endregion + } // Class + #region Property Descriptor + /// + /// Summary description for CollectionPropertyDescriptor. + /// + public partial class GridAuditInfoListPropertyDescriptor : vlnListPropertyDescriptor + { + private GridAuditInfo Item { get { return (GridAuditInfo)_Item; } } + public GridAuditInfoListPropertyDescriptor(GridAuditInfoList collection, int index) : base(collection, index) { ;} + } + #endregion + #region Converter + internal class GridAuditInfoListConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is GridAuditInfoList) + { + // Return department and department role separated by comma. + return ((GridAuditInfoList)value).Items.Count.ToString() + " GridAudits"; + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion +} // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/ImageAudit.cs b/PROMS/VEPROMS.CSLA.Library/Generated/ImageAudit.cs new file mode 100644 index 00000000..390d839c --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/ImageAudit.cs @@ -0,0 +1,1008 @@ +// ======================================================================== +// 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 +{ + /// + /// ImageAudit Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(ImageAuditConverter))] + public partial class ImageAudit : BusinessBase, IDisposable, IVEHasBrokenRules + { + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Refresh + private List _RefreshImageAudits = new List(); + private void AddToRefreshList(List refreshImageAudits) + { + if (IsDirty) + refreshImageAudits.Add(this); + } + private void BuildRefreshList() + { + _RefreshImageAudits = new List(); + AddToRefreshList(_RefreshImageAudits); + } + private void ProcessRefreshList() + { + foreach (ImageAudit tmp in _RefreshImageAudits) + { + ImageAuditInfo.Refresh(tmp); + } + } + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(ImageAudit imageAudit) + { + if (!_CacheList.Contains(imageAudit)) _CacheList.Add(imageAudit); // In AddToCache + } + protected static void RemoveFromCache(ImageAudit imageAudit) + { + while (_CacheList.Contains(imageAudit)) _CacheList.Remove(imageAudit); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + while (_CacheList.Count > 0) // Move ImageAudit(s) from temporary _CacheList to _CacheByPrimaryKey + { + ImageAudit tmp = _CacheList[0]; // Get the first ImageAudit + string pKey = tmp.AuditID.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 ImageAudit + } + } + protected static ImageAudit GetCachedByPrimaryKey(long auditID) + { + ConvertListToDictionary(); + string key = auditID.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 _nextAuditID = -1; + public static int NextAuditID + { + get { return _nextAuditID--; } + } + private long _AuditID; + [System.ComponentModel.DataObjectField(true, true)] + public long AuditID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("AuditID", true); + return _AuditID; + } + } + private int _ContentID; + public int ContentID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("ContentID", true); + return _ContentID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + CanWriteProperty("ContentID", true); + if (_ContentID != value) + { + _ContentID = value; + PropertyHasChanged(); + } + } + } + private int _ImageType; + public int ImageType + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("ImageType", true); + return _ImageType; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + CanWriteProperty("ImageType", true); + if (_ImageType != value) + { + _ImageType = value; + PropertyHasChanged(); + } + } + } + private string _FileName = string.Empty; + public string FileName + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("FileName", true); + return _FileName; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + CanWriteProperty("FileName", true); + if (value == null) value = string.Empty; + if (_FileName != value) + { + _FileName = value; + PropertyHasChanged(); + } + } + } + private byte[] _Data; + public byte[] Data + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("Data", true); + return _Data; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + CanWriteProperty("Data", true); + if (_Data != value) + { + _Data = 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 int _DeleteStatus; + public int DeleteStatus + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("DeleteStatus", true); + return _DeleteStatus; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + CanWriteProperty("DeleteStatus", true); + if (_DeleteStatus != value) + { + _DeleteStatus = value; + PropertyHasChanged(); + } + } + } + public override bool IsDirty + { + get { return base.IsDirty; } + } + public bool IsDirtyList(List list) + { + return base.IsDirty; + } + public override bool IsValid + { + get { return (IsNew && !IsDirty) ? true : base.IsValid; } + } + public bool IsValidList(List list) + { + return (IsNew && !IsDirty) ? true : base.IsValid; + } + // CSLATODO: Replace base ImageAudit.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current ImageAudit + //public override string ToString() + //{ + // return base.ToString(); + //} + // CSLATODO: Check ImageAudit.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 ImageAudit + protected override object GetIdValue() + { + return MyImageAuditUnique; // 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; + 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, "FileName"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("FileName", 510)); + 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", 200)); + //ValidationRules.AddDependantProperty("x", "y"); + _ImageAuditExtension.AddValidationRules(ValidationRules); + // CSLATODO: Add other validation rules + } + protected override void AddInstanceBusinessRules() + { + _ImageAuditExtension.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(AuditID, ""); + //AuthorizationRules.AllowRead(ContentID, ""); + //AuthorizationRules.AllowRead(ImageType, ""); + //AuthorizationRules.AllowRead(FileName, ""); + //AuthorizationRules.AllowRead(Data, ""); + //AuthorizationRules.AllowRead(Config, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowRead(UserID, ""); + //AuthorizationRules.AllowRead(DeleteStatus, ""); + //AuthorizationRules.AllowWrite(ContentID, ""); + //AuthorizationRules.AllowWrite(ImageType, ""); + //AuthorizationRules.AllowWrite(FileName, ""); + //AuthorizationRules.AllowWrite(Data, ""); + //AuthorizationRules.AllowWrite(Config, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowWrite(UserID, ""); + //AuthorizationRules.AllowWrite(DeleteStatus, ""); + _ImageAuditExtension.AddAuthorizationRules(AuthorizationRules); + } + protected override void AddInstanceAuthorizationRules() + { + //CSLATODO: Who can read/write which fields + _ImageAuditExtension.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 _ImageAuditUnique = 0; + protected static int ImageAuditUnique + { get { return ++_ImageAuditUnique; } } + private int _MyImageAuditUnique = ImageAuditUnique; + public int MyImageAuditUnique // Absolutely Unique ID - Editable + { get { return _MyImageAuditUnique; } } + protected ImageAudit() + {/* require use of factory methods */ + AddToCache(this); + } + public void Dispose() + { + RemoveFromDictionaries(); + } + private void RemoveFromDictionaries() + { + RemoveFromCache(this); + if (_CacheByPrimaryKey.ContainsKey(AuditID.ToString())) + { + List listImageAudit = _CacheByPrimaryKey[AuditID.ToString()]; // Get the list of items + while (listImageAudit.Contains(this)) listImageAudit.Remove(this); // Remove the item from the list + if (listImageAudit.Count == 0) //If there are no items left in the list + _CacheByPrimaryKey.Remove(AuditID.ToString()); // remove the list + } + } + public static ImageAudit New() + { + if (!CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a ImageAudit"); + try + { + return DataPortal.Create(); + } + catch (Exception ex) + { + throw new DbCslaException("Error on ImageAudit.New", ex); + } + } + public static ImageAudit New(int contentID, int imageType, string fileName, byte[] data, DateTime dts, string userID, int deleteStatus) + { + ImageAudit tmp = ImageAudit.New(); + tmp.ContentID = contentID; + tmp.ImageType = imageType; + tmp.FileName = fileName; + tmp.Data = data; + tmp.DTS = dts; + tmp.UserID = userID; + tmp.DeleteStatus = deleteStatus; + return tmp; + } + public static ImageAudit New(int contentID, int imageType, string fileName, byte[] data, string config, DateTime dts, string userID, int deleteStatus) + { + ImageAudit tmp = ImageAudit.New(); + tmp.ContentID = contentID; + tmp.ImageType = imageType; + tmp.FileName = fileName; + tmp.Data = data; + tmp.Config = config; + tmp.DTS = dts; + tmp.UserID = userID; + tmp.DeleteStatus = deleteStatus; + return tmp; + } + public static ImageAudit MakeImageAudit(int contentID, int imageType, string fileName, byte[] data, string config, DateTime dts, string userID, int deleteStatus) + { + ImageAudit tmp = ImageAudit.New(contentID, imageType, fileName, data, config, dts, userID, deleteStatus); + if (tmp.IsSavable) + { + ImageAudit 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 ImageAudit Get(long auditID) + { + if (!CanGetObject()) + throw new System.Security.SecurityException("User not authorized to view a ImageAudit"); + try + { + ImageAudit tmp = GetCachedByPrimaryKey(auditID); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(auditID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up ImageAudit + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on ImageAudit.Get", ex); + } + } + public static ImageAudit Get(SafeDataReader dr) + { + if (dr.Read()) return new ImageAudit(dr); + return null; + } + internal ImageAudit(SafeDataReader dr) + { + ReadData(dr); + } + public static void Delete(long auditID) + { + if (!CanDeleteObject()) + throw new System.Security.SecurityException("User not authorized to remove a ImageAudit"); + try + { + DataPortal.Delete(new PKCriteria(auditID)); + } + catch (Exception ex) + { + throw new DbCslaException("Error on ImageAudit.Delete", ex); + } + } + public override ImageAudit Save() + { + if (IsDeleted && !CanDeleteObject()) + throw new System.Security.SecurityException("User not authorized to remove a ImageAudit"); + else if (IsNew && !CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a ImageAudit"); + else if (!CanEditObject()) + throw new System.Security.SecurityException("User not authorized to update a ImageAudit"); + try + { + BuildRefreshList(); + ImageAudit imageAudit = base.Save(); + RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache + AddToCache(imageAudit);//Refresh the item in AllList + ProcessRefreshList(); + return imageAudit; + } + catch (Exception ex) + { + throw new DbCslaException("Error on CSLA Save", ex); + } + } + #endregion + #region Data Access Portal + [Serializable()] + protected class PKCriteria + { + private long _AuditID; + public long AuditID + { get { return _AuditID; } } + public PKCriteria(long auditID) + { + _AuditID = auditID; + } + } + // CSLATODO: If Create needs to access DB - It should not be marked RunLocal + [RunLocal()] + private new void DataPortal_Create() + { + _AuditID = NextAuditID; + // Database Defaults + + // CSLATODO: Add any defaults that are necessary + ValidationRules.CheckRules(); + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ImageAudit.ReadData", GetHashCode()); + try + { + _AuditID = dr.GetInt64("AuditID"); + _ContentID = dr.GetInt32("ContentID"); + _ImageType = dr.GetInt32("ImageType"); + _FileName = dr.GetString("FileName"); + _Data = (byte[])dr.GetValue("Data"); + _Config = dr.GetString("Config"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + _DeleteStatus = dr.GetInt32("DeleteStatus"); + MarkOld(); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ImageAudit.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("ImageAudit.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ImageAudit.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 = "getImageAudit"; + cm.Parameters.AddWithValue("@AuditID", criteria.AuditID); + 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("ImageAudit.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("ImageAudit.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("ImageAudit.DataPortal_Insert", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("ImageAudit.DataPortal_Insert", ex); + } + finally + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ImageAudit.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 = "addImageAudit"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@ContentID", _ContentID); + cm.Parameters.AddWithValue("@ImageType", _ImageType); + cm.Parameters.AddWithValue("@FileName", _FileName); + cm.Parameters.AddWithValue("@Data", _Data); + 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("@DeleteStatus", _DeleteStatus); + // Output Calculated Columns + SqlParameter param_AuditID = new SqlParameter("@newAuditID", SqlDbType.BigInt); + param_AuditID.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_AuditID); + // CSLATODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + _AuditID = (long)cm.Parameters["@newAuditID"].Value; + } + MarkOld(); + // update child objects + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ImageAudit.SQLInsert", GetHashCode()); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ImageAudit.SQLInsert", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("ImageAudit.SQLInsert", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + public static void Add(SqlConnection cn, ref long auditID, int contentID, int imageType, string fileName, byte[] data, string config, DateTime dts, string userID, int deleteStatus) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ImageAudit.Add", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "addImageAudit"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@ContentID", contentID); + cm.Parameters.AddWithValue("@ImageType", imageType); + cm.Parameters.AddWithValue("@FileName", fileName); + cm.Parameters.AddWithValue("@Data", data); + 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("@DeleteStatus", deleteStatus); + // Output Calculated Columns + SqlParameter param_AuditID = new SqlParameter("@newAuditID", SqlDbType.BigInt); + param_AuditID.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_AuditID); + // CSLATODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + auditID = (long)cm.Parameters["@newAuditID"].Value; + // No Timestamp value to return + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ImageAudit.Add", ex); + throw new DbCslaException("ImageAudit.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}] ImageAudit.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("ImageAudit.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}] ImageAudit.SQLUpdate", GetHashCode()); + try + { + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + if (base.IsDirty) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "updateImageAudit"; + // All Fields including Calculated Fields + cm.Parameters.AddWithValue("@AuditID", _AuditID); + cm.Parameters.AddWithValue("@ContentID", _ContentID); + cm.Parameters.AddWithValue("@ImageType", _ImageType); + cm.Parameters.AddWithValue("@FileName", _FileName); + cm.Parameters.AddWithValue("@Data", _Data); + 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("@DeleteStatus", _DeleteStatus); + // Output Calculated Columns + // CSLATODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + } + } + MarkOld(); + // use the open connection to update child objects + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ImageAudit.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) + ImageAudit.Add(cn, ref _AuditID, _ContentID, _ImageType, _FileName, _Data, _Config, _DTS, _UserID, _DeleteStatus); + else + ImageAudit.Update(cn, ref _AuditID, _ContentID, _ImageType, _FileName, _Data, _Config, _DTS, _UserID, _DeleteStatus); + MarkOld(); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + public static void Update(SqlConnection cn, ref long auditID, int contentID, int imageType, string fileName, byte[] data, string config, DateTime dts, string userID, int deleteStatus) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ImageAudit.Update", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "updateImageAudit"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@AuditID", auditID); + cm.Parameters.AddWithValue("@ContentID", contentID); + cm.Parameters.AddWithValue("@ImageType", imageType); + cm.Parameters.AddWithValue("@FileName", fileName); + cm.Parameters.AddWithValue("@Data", data); + 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("@DeleteStatus", deleteStatus); + // Output Calculated Columns + // CSLATODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + // No Timestamp value to return + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ImageAudit.Update", ex); + throw new DbCslaException("ImageAudit.Update", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_DeleteSelf() + { + DataPortal_Delete(new PKCriteria(_AuditID)); + } + [Transactional(TransactionalTypes.TransactionScope)] + private void DataPortal_Delete(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ImageAudit.DataPortal_Delete", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "deleteImageAudit"; + cm.Parameters.AddWithValue("@AuditID", criteria.AuditID); + cm.ExecuteNonQuery(); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ImageAudit.DataPortal_Delete", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("ImageAudit.DataPortal_Delete", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + public static void Remove(SqlConnection cn, long auditID) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ImageAudit.Remove", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "deleteImageAudit"; + // Input PK Fields + cm.Parameters.AddWithValue("@AuditID", auditID); + // CSLATODO: Define any additional output parameters + cm.ExecuteNonQuery(); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ImageAudit.Remove", ex); + throw new DbCslaException("ImageAudit.Remove", ex); + } + } + #endregion + // Standard Default Code + #region extension + ImageAuditExtension _ImageAuditExtension = new ImageAuditExtension(); + [Serializable()] + partial class ImageAuditExtension : 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 ImageAuditConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is ImageAudit) + { + // Return the ToString value + return ((ImageAudit)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion +} // Namespace + + +//// The following is a sample Extension File. You can use it to create ImageAuditExt.cs +//using System; +//using System.Collections.Generic; +//using System.Text; +//using Csla; + +//namespace VEPROMS.CSLA.Library +//{ +// public partial class ImageAudit +// { +// partial class ImageAuditExtension : 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/ImageAuditInfo.cs b/PROMS/VEPROMS.CSLA.Library/Generated/ImageAuditInfo.cs new file mode 100644 index 00000000..1fcda2a1 --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/ImageAuditInfo.cs @@ -0,0 +1,382 @@ +// ======================================================================== +// 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 ImageAuditInfoEvent(object sender); + /// + /// ImageAuditInfo Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(ImageAuditInfoConverter))] + public partial class ImageAuditInfo : ReadOnlyBase, IDisposable + { + public event ImageAuditInfoEvent 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(ImageAuditInfo imageAuditInfo) + { + if (!_CacheList.Contains(imageAuditInfo)) _CacheList.Add(imageAuditInfo); // In AddToCache + } + protected static void RemoveFromCache(ImageAuditInfo imageAuditInfo) + { + while (_CacheList.Contains(imageAuditInfo)) _CacheList.Remove(imageAuditInfo); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + while (_CacheList.Count > 0) // Move ImageAuditInfo(s) from temporary _CacheList to _CacheByPrimaryKey + { + ImageAuditInfo tmp = _CacheList[0]; // Get the first ImageAuditInfo + string pKey = tmp.AuditID.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 ImageAuditInfo + } + } + internal static void AddList(ImageAuditInfoList lst) + { + foreach (ImageAuditInfo item in lst) AddToCache(item); + } + protected static ImageAuditInfo GetCachedByPrimaryKey(long auditID) + { + ConvertListToDictionary(); + string key = auditID.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 ImageAudit _Editable; + private IVEHasBrokenRules HasBrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = null; + if (_Editable != null) + hasBrokenRules = _Editable.HasBrokenRules; + return hasBrokenRules; + } + } + private long _AuditID; + [System.ComponentModel.DataObjectField(true, true)] + public long AuditID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("AuditID", true); + return _AuditID; + } + } + private int _ContentID; + public int ContentID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("ContentID", true); + return _ContentID; + } + } + private int _ImageType; + public int ImageType + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("ImageType", true); + return _ImageType; + } + } + private string _FileName = string.Empty; + public string FileName + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("FileName", true); + return _FileName; + } + } + private byte[] _Data; + public byte[] Data + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("Data", true); + return _Data; + } + } + 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 _DeleteStatus; + public int DeleteStatus + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("DeleteStatus", true); + return _DeleteStatus; + } + } + // CSLATODO: Replace base ImageAuditInfo.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current ImageAuditInfo + //public override string ToString() + //{ + // return base.ToString(); + //} + // CSLATODO: Check ImageAuditInfo.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 ImageAuditInfo + protected override object GetIdValue() + { + return MyImageAuditInfoUnique; // Absolutely Unique ID + } + #endregion + #region Factory Methods + private static int _ImageAuditInfoUnique = 0; + private static int ImageAuditInfoUnique + { get { return ++_ImageAuditInfoUnique; } } + private int _MyImageAuditInfoUnique = ImageAuditInfoUnique; + public int MyImageAuditInfoUnique // Absolutely Unique ID - Info + { get { return _MyImageAuditInfoUnique; } } + protected ImageAuditInfo() + {/* require use of factory methods */ + AddToCache(this); + } + public void Dispose() + { + RemoveFromCache(this); + if (!_CacheByPrimaryKey.ContainsKey(AuditID.ToString())) return; + List listImageAuditInfo = _CacheByPrimaryKey[AuditID.ToString()]; // Get the list of items + while (listImageAuditInfo.Contains(this)) listImageAuditInfo.Remove(this); // Remove the item from the list + if (listImageAuditInfo.Count == 0) // If there are no items left in the list + _CacheByPrimaryKey.Remove(AuditID.ToString()); // remove the list + } + public virtual ImageAudit Get() + { + return _Editable = ImageAudit.Get(_AuditID); + } + public static void Refresh(ImageAudit tmp) + { + string key = tmp.AuditID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (ImageAuditInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(ImageAudit tmp) + { + _ContentID = tmp.ContentID; + _ImageType = tmp.ImageType; + _FileName = tmp.FileName; + _Data = tmp.Data; + _Config = tmp.Config; + _DTS = tmp.DTS; + _UserID = tmp.UserID; + _DeleteStatus = tmp.DeleteStatus; + _ImageAuditInfoExtension.Refresh(this); + OnChange();// raise an event + } + public static ImageAuditInfo Get(long auditID) + { + //if (!CanGetObject()) + // throw new System.Security.SecurityException("User not authorized to view a ImageAudit"); + try + { + ImageAuditInfo tmp = GetCachedByPrimaryKey(auditID); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(auditID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up ImageAuditInfo + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on ImageAuditInfo.Get", ex); + } + } + #endregion + #region Data Access Portal + internal ImageAuditInfo(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ImageAuditInfo.Constructor", GetHashCode()); + try + { + ReadData(dr); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ImageAuditInfo.Constructor", ex); + throw new DbCslaException("ImageAuditInfo.Constructor", ex); + } + } + [Serializable()] + protected class PKCriteria + { + private long _AuditID; + public long AuditID + { get { return _AuditID; } } + public PKCriteria(long auditID) + { + _AuditID = auditID; + } + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ImageAuditInfo.ReadData", GetHashCode()); + try + { + _AuditID = dr.GetInt64("AuditID"); + _ContentID = dr.GetInt32("ContentID"); + _ImageType = dr.GetInt32("ImageType"); + _FileName = dr.GetString("FileName"); + _Data = (byte[])dr.GetValue("Data"); + _Config = dr.GetString("Config"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + _DeleteStatus = dr.GetInt32("DeleteStatus"); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ImageAuditInfo.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("ImageAuditInfo.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ImageAuditInfo.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 = "getImageAudit"; + cm.Parameters.AddWithValue("@AuditID", criteria.AuditID); + 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("ImageAuditInfo.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("ImageAuditInfo.DataPortal_Fetch", ex); + } + } + #endregion + // Standard Refresh + #region extension + ImageAuditInfoExtension _ImageAuditInfoExtension = new ImageAuditInfoExtension(); + [Serializable()] + partial class ImageAuditInfoExtension : extensionBase { } + [Serializable()] + class extensionBase + { + // Default Refresh + public virtual void Refresh(ImageAuditInfo tmp) { } + } + #endregion + } // Class + #region Converter + internal class ImageAuditInfoConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is ImageAuditInfo) + { + // Return the ToString value + return ((ImageAuditInfo)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion +} // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/ImageAuditInfoList.cs b/PROMS/VEPROMS.CSLA.Library/Generated/ImageAuditInfoList.cs new file mode 100644 index 00000000..b53ea99f --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/ImageAuditInfoList.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 +{ + /// + /// ImageAuditInfoList Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(ImageAuditInfoListConverter))] + public partial class ImageAuditInfoList : 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 (ImageAuditInfo tmp in this) + { + tmp.Changed += new ImageAuditInfoEvent(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 (ImageAuditInfo tmp in this) + { + tmp.Changed -= new ImageAuditInfoEvent(tmp_Changed); + } + } + #endregion + #region Factory Methods + public static ImageAuditInfoList _ImageAuditInfoList = null; + /// + /// Return a list of all ImageAuditInfo. + /// + public static ImageAuditInfoList Get() + { + try + { + if (_ImageAuditInfoList != null) + return _ImageAuditInfoList; + ImageAuditInfoList tmp = DataPortal.Fetch(); + ImageAuditInfo.AddList(tmp); + tmp.AddEvents(); + _ImageAuditInfoList = tmp; + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on ImageAuditInfoList.Get", ex); + } + } + /// + /// Reset the list of all ImageAuditInfo. + /// + public static void Reset() + { + _ImageAuditInfoList = null; + } + // CSLATODO: Add alternative gets - + //public static ImageAuditInfoList Get() + //{ + // try + // { + // return DataPortal.Fetch(new FilteredCriteria()); + // } + // catch (Exception ex) + // { + // throw new DbCslaException("Error on ImageAuditInfoList.Get", ex); + // } + //} + private ImageAuditInfoList() + { /* require use of factory methods */ } + #endregion + #region Data Access Portal + private void DataPortal_Fetch() + { + this.RaiseListChangedEvents = false; + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ImageAuditInfoList.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getImageAudits"; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + IsReadOnly = false; + while (dr.Read()) this.Add(new ImageAuditInfo(dr)); + IsReadOnly = true; + } + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ImageAuditInfoList.DataPortal_Fetch", ex); + throw new DbCslaException("ImageAuditInfoList.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 + ImageAuditInfoListPropertyDescriptor pd = new ImageAuditInfoListPropertyDescriptor(this, i); + pds.Add(pd); + } + // return the property descriptor collection + return pds; + } + #endregion + } // Class + #region Property Descriptor + /// + /// Summary description for CollectionPropertyDescriptor. + /// + public partial class ImageAuditInfoListPropertyDescriptor : vlnListPropertyDescriptor + { + private ImageAuditInfo Item { get { return (ImageAuditInfo)_Item; } } + public ImageAuditInfoListPropertyDescriptor(ImageAuditInfoList collection, int index) : base(collection, index) { ;} + } + #endregion + #region Converter + internal class ImageAuditInfoListConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is ImageAuditInfoList) + { + // Return department and department role separated by comma. + return ((ImageAuditInfoList)value).Items.Count.ToString() + " ImageAudits"; + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion +} // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/ItemAudit.cs b/PROMS/VEPROMS.CSLA.Library/Generated/ItemAudit.cs new file mode 100644 index 00000000..23737ce6 --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/ItemAudit.cs @@ -0,0 +1,940 @@ +// ======================================================================== +// 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 +{ + /// + /// ItemAudit Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(ItemAuditConverter))] + public partial class ItemAudit : BusinessBase, IDisposable, IVEHasBrokenRules + { + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Refresh + private List _RefreshItemAudits = new List(); + private void AddToRefreshList(List refreshItemAudits) + { + if (IsDirty) + refreshItemAudits.Add(this); + } + private void BuildRefreshList() + { + _RefreshItemAudits = new List(); + AddToRefreshList(_RefreshItemAudits); + } + private void ProcessRefreshList() + { + foreach (ItemAudit tmp in _RefreshItemAudits) + { + ItemAuditInfo.Refresh(tmp); + } + } + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(ItemAudit itemAudit) + { + if (!_CacheList.Contains(itemAudit)) _CacheList.Add(itemAudit); // In AddToCache + } + protected static void RemoveFromCache(ItemAudit itemAudit) + { + while (_CacheList.Contains(itemAudit)) _CacheList.Remove(itemAudit); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + while (_CacheList.Count > 0) // Move ItemAudit(s) from temporary _CacheList to _CacheByPrimaryKey + { + ItemAudit tmp = _CacheList[0]; // Get the first ItemAudit + string pKey = tmp.AuditID.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 ItemAudit + } + } + protected static ItemAudit GetCachedByPrimaryKey(long auditID) + { + ConvertListToDictionary(); + string key = auditID.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 _nextAuditID = -1; + public static int NextAuditID + { + get { return _nextAuditID--; } + } + private long _AuditID; + [System.ComponentModel.DataObjectField(true, true)] + public long AuditID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("AuditID", true); + return _AuditID; + } + } + 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? _PreviousID; + public int? PreviousID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("PreviousID", true); + return _PreviousID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + CanWriteProperty("PreviousID", true); + if (_PreviousID != value) + { + _PreviousID = value; + PropertyHasChanged(); + } + } + } + private int _ContentID; + public int ContentID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("ContentID", true); + return _ContentID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + CanWriteProperty("ContentID", true); + if (_ContentID != value) + { + _ContentID = 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 int _DeleteStatus; + public int DeleteStatus + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("DeleteStatus", true); + return _DeleteStatus; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + CanWriteProperty("DeleteStatus", true); + if (_DeleteStatus != value) + { + _DeleteStatus = value; + PropertyHasChanged(); + } + } + } + public override bool IsDirty + { + get { return base.IsDirty; } + } + public bool IsDirtyList(List list) + { + return base.IsDirty; + } + public override bool IsValid + { + get { return (IsNew && !IsDirty) ? true : base.IsValid; } + } + public bool IsValidList(List list) + { + return (IsNew && !IsDirty) ? true : base.IsValid; + } + // CSLATODO: Replace base ItemAudit.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current ItemAudit + //public override string ToString() + //{ + // return base.ToString(); + //} + // CSLATODO: Check ItemAudit.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 ItemAudit + protected override object GetIdValue() + { + return MyItemAuditUnique; // 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; + 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, "UserID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 200)); + //ValidationRules.AddDependantProperty("x", "y"); + _ItemAuditExtension.AddValidationRules(ValidationRules); + // CSLATODO: Add other validation rules + } + protected override void AddInstanceBusinessRules() + { + _ItemAuditExtension.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(AuditID, ""); + //AuthorizationRules.AllowRead(ItemID, ""); + //AuthorizationRules.AllowRead(PreviousID, ""); + //AuthorizationRules.AllowRead(ContentID, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowRead(UserID, ""); + //AuthorizationRules.AllowRead(DeleteStatus, ""); + //AuthorizationRules.AllowWrite(ItemID, ""); + //AuthorizationRules.AllowWrite(PreviousID, ""); + //AuthorizationRules.AllowWrite(ContentID, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowWrite(UserID, ""); + //AuthorizationRules.AllowWrite(DeleteStatus, ""); + _ItemAuditExtension.AddAuthorizationRules(AuthorizationRules); + } + protected override void AddInstanceAuthorizationRules() + { + //CSLATODO: Who can read/write which fields + _ItemAuditExtension.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 _ItemAuditUnique = 0; + protected static int ItemAuditUnique + { get { return ++_ItemAuditUnique; } } + private int _MyItemAuditUnique = ItemAuditUnique; + public int MyItemAuditUnique // Absolutely Unique ID - Editable + { get { return _MyItemAuditUnique; } } + protected ItemAudit() + {/* require use of factory methods */ + AddToCache(this); + } + public void Dispose() + { + RemoveFromDictionaries(); + } + private void RemoveFromDictionaries() + { + RemoveFromCache(this); + if (_CacheByPrimaryKey.ContainsKey(AuditID.ToString())) + { + List listItemAudit = _CacheByPrimaryKey[AuditID.ToString()]; // Get the list of items + while (listItemAudit.Contains(this)) listItemAudit.Remove(this); // Remove the item from the list + if (listItemAudit.Count == 0) //If there are no items left in the list + _CacheByPrimaryKey.Remove(AuditID.ToString()); // remove the list + } + } + public static ItemAudit New() + { + if (!CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a ItemAudit"); + try + { + return DataPortal.Create(); + } + catch (Exception ex) + { + throw new DbCslaException("Error on ItemAudit.New", ex); + } + } + public static ItemAudit New(int itemID, int contentID, DateTime dts, string userID, int deleteStatus) + { + ItemAudit tmp = ItemAudit.New(); + tmp.ItemID = itemID; + tmp.ContentID = contentID; + tmp.DTS = dts; + tmp.UserID = userID; + tmp.DeleteStatus = deleteStatus; + return tmp; + } + public static ItemAudit New(int itemID, int? previousID, int contentID, DateTime dts, string userID, int deleteStatus) + { + ItemAudit tmp = ItemAudit.New(); + tmp.ItemID = itemID; + tmp.PreviousID = previousID; + tmp.ContentID = contentID; + tmp.DTS = dts; + tmp.UserID = userID; + tmp.DeleteStatus = deleteStatus; + return tmp; + } + public static ItemAudit MakeItemAudit(int itemID, int? previousID, int contentID, DateTime dts, string userID, int deleteStatus) + { + ItemAudit tmp = ItemAudit.New(itemID, previousID, contentID, dts, userID, deleteStatus); + if (tmp.IsSavable) + { + ItemAudit 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 ItemAudit Get(long auditID) + { + if (!CanGetObject()) + throw new System.Security.SecurityException("User not authorized to view a ItemAudit"); + try + { + ItemAudit tmp = GetCachedByPrimaryKey(auditID); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(auditID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up ItemAudit + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on ItemAudit.Get", ex); + } + } + public static ItemAudit Get(SafeDataReader dr) + { + if (dr.Read()) return new ItemAudit(dr); + return null; + } + internal ItemAudit(SafeDataReader dr) + { + ReadData(dr); + } + public static void Delete(long auditID) + { + if (!CanDeleteObject()) + throw new System.Security.SecurityException("User not authorized to remove a ItemAudit"); + try + { + DataPortal.Delete(new PKCriteria(auditID)); + } + catch (Exception ex) + { + throw new DbCslaException("Error on ItemAudit.Delete", ex); + } + } + public override ItemAudit Save() + { + if (IsDeleted && !CanDeleteObject()) + throw new System.Security.SecurityException("User not authorized to remove a ItemAudit"); + else if (IsNew && !CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a ItemAudit"); + else if (!CanEditObject()) + throw new System.Security.SecurityException("User not authorized to update a ItemAudit"); + try + { + BuildRefreshList(); + ItemAudit itemAudit = base.Save(); + RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache + AddToCache(itemAudit);//Refresh the item in AllList + ProcessRefreshList(); + return itemAudit; + } + catch (Exception ex) + { + throw new DbCslaException("Error on CSLA Save", ex); + } + } + #endregion + #region Data Access Portal + [Serializable()] + protected class PKCriteria + { + private long _AuditID; + public long AuditID + { get { return _AuditID; } } + public PKCriteria(long auditID) + { + _AuditID = auditID; + } + } + // CSLATODO: If Create needs to access DB - It should not be marked RunLocal + [RunLocal()] + private new void DataPortal_Create() + { + _AuditID = NextAuditID; + // Database Defaults + + // CSLATODO: Add any defaults that are necessary + ValidationRules.CheckRules(); + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ItemAudit.ReadData", GetHashCode()); + try + { + _AuditID = dr.GetInt64("AuditID"); + _ItemID = dr.GetInt32("ItemID"); + _PreviousID = (int?)dr.GetValue("PreviousID"); + _ContentID = dr.GetInt32("ContentID"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + _DeleteStatus = dr.GetInt32("DeleteStatus"); + MarkOld(); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ItemAudit.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("ItemAudit.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ItemAudit.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 = "getItemAudit"; + cm.Parameters.AddWithValue("@AuditID", criteria.AuditID); + 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("ItemAudit.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("ItemAudit.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("ItemAudit.DataPortal_Insert", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("ItemAudit.DataPortal_Insert", ex); + } + finally + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ItemAudit.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 = "addItemAudit"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@ItemID", _ItemID); + cm.Parameters.AddWithValue("@PreviousID", _PreviousID); + cm.Parameters.AddWithValue("@ContentID", _ContentID); + if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS); + cm.Parameters.AddWithValue("@UserID", _UserID); + cm.Parameters.AddWithValue("@DeleteStatus", _DeleteStatus); + // Output Calculated Columns + SqlParameter param_AuditID = new SqlParameter("@newAuditID", SqlDbType.BigInt); + param_AuditID.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_AuditID); + // CSLATODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + _AuditID = (long)cm.Parameters["@newAuditID"].Value; + } + MarkOld(); + // update child objects + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ItemAudit.SQLInsert", GetHashCode()); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ItemAudit.SQLInsert", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("ItemAudit.SQLInsert", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + public static void Add(SqlConnection cn, ref long auditID, int itemID, int? previousID, int contentID, DateTime dts, string userID, int deleteStatus) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ItemAudit.Add", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "addItemAudit"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@ItemID", itemID); + cm.Parameters.AddWithValue("@PreviousID", previousID); + cm.Parameters.AddWithValue("@ContentID", contentID); + if (dts.Year >= 1753 && dts.Year <= 9999) cm.Parameters.AddWithValue("@DTS", dts); + cm.Parameters.AddWithValue("@UserID", userID); + cm.Parameters.AddWithValue("@DeleteStatus", deleteStatus); + // Output Calculated Columns + SqlParameter param_AuditID = new SqlParameter("@newAuditID", SqlDbType.BigInt); + param_AuditID.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_AuditID); + // CSLATODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + auditID = (long)cm.Parameters["@newAuditID"].Value; + // No Timestamp value to return + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ItemAudit.Add", ex); + throw new DbCslaException("ItemAudit.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}] ItemAudit.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("ItemAudit.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}] ItemAudit.SQLUpdate", GetHashCode()); + try + { + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + if (base.IsDirty) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "updateItemAudit"; + // All Fields including Calculated Fields + cm.Parameters.AddWithValue("@AuditID", _AuditID); + cm.Parameters.AddWithValue("@ItemID", _ItemID); + cm.Parameters.AddWithValue("@PreviousID", _PreviousID); + cm.Parameters.AddWithValue("@ContentID", _ContentID); + if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS); + cm.Parameters.AddWithValue("@UserID", _UserID); + cm.Parameters.AddWithValue("@DeleteStatus", _DeleteStatus); + // Output Calculated Columns + // CSLATODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + } + } + MarkOld(); + // use the open connection to update child objects + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ItemAudit.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) + ItemAudit.Add(cn, ref _AuditID, _ItemID, _PreviousID, _ContentID, _DTS, _UserID, _DeleteStatus); + else + ItemAudit.Update(cn, ref _AuditID, _ItemID, _PreviousID, _ContentID, _DTS, _UserID, _DeleteStatus); + MarkOld(); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + public static void Update(SqlConnection cn, ref long auditID, int itemID, int? previousID, int contentID, DateTime dts, string userID, int deleteStatus) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ItemAudit.Update", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "updateItemAudit"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@AuditID", auditID); + cm.Parameters.AddWithValue("@ItemID", itemID); + cm.Parameters.AddWithValue("@PreviousID", previousID); + cm.Parameters.AddWithValue("@ContentID", contentID); + if (dts.Year >= 1753 && dts.Year <= 9999) cm.Parameters.AddWithValue("@DTS", dts); + cm.Parameters.AddWithValue("@UserID", userID); + cm.Parameters.AddWithValue("@DeleteStatus", deleteStatus); + // Output Calculated Columns + // CSLATODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + // No Timestamp value to return + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ItemAudit.Update", ex); + throw new DbCslaException("ItemAudit.Update", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_DeleteSelf() + { + DataPortal_Delete(new PKCriteria(_AuditID)); + } + [Transactional(TransactionalTypes.TransactionScope)] + private void DataPortal_Delete(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ItemAudit.DataPortal_Delete", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "deleteItemAudit"; + cm.Parameters.AddWithValue("@AuditID", criteria.AuditID); + cm.ExecuteNonQuery(); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ItemAudit.DataPortal_Delete", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("ItemAudit.DataPortal_Delete", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + public static void Remove(SqlConnection cn, long auditID) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ItemAudit.Remove", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "deleteItemAudit"; + // Input PK Fields + cm.Parameters.AddWithValue("@AuditID", auditID); + // CSLATODO: Define any additional output parameters + cm.ExecuteNonQuery(); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ItemAudit.Remove", ex); + throw new DbCslaException("ItemAudit.Remove", ex); + } + } + #endregion + // Standard Default Code + #region extension + ItemAuditExtension _ItemAuditExtension = new ItemAuditExtension(); + [Serializable()] + partial class ItemAuditExtension : 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 ItemAuditConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is ItemAudit) + { + // Return the ToString value + return ((ItemAudit)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion +} // Namespace + + +//// The following is a sample Extension File. You can use it to create ItemAuditExt.cs +//using System; +//using System.Collections.Generic; +//using System.Text; +//using Csla; + +//namespace VEPROMS.CSLA.Library +//{ +// public partial class ItemAudit +// { +// partial class ItemAuditExtension : 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/ItemAuditInfo.cs b/PROMS/VEPROMS.CSLA.Library/Generated/ItemAuditInfo.cs new file mode 100644 index 00000000..c062661b --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/ItemAuditInfo.cs @@ -0,0 +1,358 @@ +// ======================================================================== +// 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 ItemAuditInfoEvent(object sender); + /// + /// ItemAuditInfo Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(ItemAuditInfoConverter))] + public partial class ItemAuditInfo : ReadOnlyBase, IDisposable + { + public event ItemAuditInfoEvent 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(ItemAuditInfo itemAuditInfo) + { + if (!_CacheList.Contains(itemAuditInfo)) _CacheList.Add(itemAuditInfo); // In AddToCache + } + protected static void RemoveFromCache(ItemAuditInfo itemAuditInfo) + { + while (_CacheList.Contains(itemAuditInfo)) _CacheList.Remove(itemAuditInfo); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + while (_CacheList.Count > 0) // Move ItemAuditInfo(s) from temporary _CacheList to _CacheByPrimaryKey + { + ItemAuditInfo tmp = _CacheList[0]; // Get the first ItemAuditInfo + string pKey = tmp.AuditID.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 ItemAuditInfo + } + } + internal static void AddList(ItemAuditInfoList lst) + { + foreach (ItemAuditInfo item in lst) AddToCache(item); + } + protected static ItemAuditInfo GetCachedByPrimaryKey(long auditID) + { + ConvertListToDictionary(); + string key = auditID.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 ItemAudit _Editable; + private IVEHasBrokenRules HasBrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = null; + if (_Editable != null) + hasBrokenRules = _Editable.HasBrokenRules; + return hasBrokenRules; + } + } + private long _AuditID; + [System.ComponentModel.DataObjectField(true, true)] + public long AuditID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("AuditID", true); + return _AuditID; + } + } + private int _ItemID; + public int ItemID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("ItemID", true); + return _ItemID; + } + } + private int? _PreviousID; + public int? PreviousID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("PreviousID", true); + return _PreviousID; + } + } + private int _ContentID; + public int ContentID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("ContentID", true); + return _ContentID; + } + } + 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 _DeleteStatus; + public int DeleteStatus + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("DeleteStatus", true); + return _DeleteStatus; + } + } + // CSLATODO: Replace base ItemAuditInfo.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current ItemAuditInfo + //public override string ToString() + //{ + // return base.ToString(); + //} + // CSLATODO: Check ItemAuditInfo.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 ItemAuditInfo + protected override object GetIdValue() + { + return MyItemAuditInfoUnique; // Absolutely Unique ID + } + #endregion + #region Factory Methods + private static int _ItemAuditInfoUnique = 0; + private static int ItemAuditInfoUnique + { get { return ++_ItemAuditInfoUnique; } } + private int _MyItemAuditInfoUnique = ItemAuditInfoUnique; + public int MyItemAuditInfoUnique // Absolutely Unique ID - Info + { get { return _MyItemAuditInfoUnique; } } + protected ItemAuditInfo() + {/* require use of factory methods */ + AddToCache(this); + } + public void Dispose() + { + RemoveFromCache(this); + if (!_CacheByPrimaryKey.ContainsKey(AuditID.ToString())) return; + List listItemAuditInfo = _CacheByPrimaryKey[AuditID.ToString()]; // Get the list of items + while (listItemAuditInfo.Contains(this)) listItemAuditInfo.Remove(this); // Remove the item from the list + if (listItemAuditInfo.Count == 0) // If there are no items left in the list + _CacheByPrimaryKey.Remove(AuditID.ToString()); // remove the list + } + public virtual ItemAudit Get() + { + return _Editable = ItemAudit.Get(_AuditID); + } + public static void Refresh(ItemAudit tmp) + { + string key = tmp.AuditID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (ItemAuditInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(ItemAudit tmp) + { + _ItemID = tmp.ItemID; + _PreviousID = tmp.PreviousID; + _ContentID = tmp.ContentID; + _DTS = tmp.DTS; + _UserID = tmp.UserID; + _DeleteStatus = tmp.DeleteStatus; + _ItemAuditInfoExtension.Refresh(this); + OnChange();// raise an event + } + public static ItemAuditInfo Get(long auditID) + { + //if (!CanGetObject()) + // throw new System.Security.SecurityException("User not authorized to view a ItemAudit"); + try + { + ItemAuditInfo tmp = GetCachedByPrimaryKey(auditID); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(auditID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up ItemAuditInfo + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on ItemAuditInfo.Get", ex); + } + } + #endregion + #region Data Access Portal + internal ItemAuditInfo(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ItemAuditInfo.Constructor", GetHashCode()); + try + { + ReadData(dr); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ItemAuditInfo.Constructor", ex); + throw new DbCslaException("ItemAuditInfo.Constructor", ex); + } + } + [Serializable()] + protected class PKCriteria + { + private long _AuditID; + public long AuditID + { get { return _AuditID; } } + public PKCriteria(long auditID) + { + _AuditID = auditID; + } + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ItemAuditInfo.ReadData", GetHashCode()); + try + { + _AuditID = dr.GetInt64("AuditID"); + _ItemID = dr.GetInt32("ItemID"); + _PreviousID = (int?)dr.GetValue("PreviousID"); + _ContentID = dr.GetInt32("ContentID"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + _DeleteStatus = dr.GetInt32("DeleteStatus"); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ItemAuditInfo.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("ItemAuditInfo.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ItemAuditInfo.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 = "getItemAudit"; + cm.Parameters.AddWithValue("@AuditID", criteria.AuditID); + 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("ItemAuditInfo.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("ItemAuditInfo.DataPortal_Fetch", ex); + } + } + #endregion + // Standard Refresh + #region extension + ItemAuditInfoExtension _ItemAuditInfoExtension = new ItemAuditInfoExtension(); + [Serializable()] + partial class ItemAuditInfoExtension : extensionBase { } + [Serializable()] + class extensionBase + { + // Default Refresh + public virtual void Refresh(ItemAuditInfo tmp) { } + } + #endregion + } // Class + #region Converter + internal class ItemAuditInfoConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is ItemAuditInfo) + { + // Return the ToString value + return ((ItemAuditInfo)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion +} // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/ItemAuditInfoList.cs b/PROMS/VEPROMS.CSLA.Library/Generated/ItemAuditInfoList.cs new file mode 100644 index 00000000..c33204c5 --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/ItemAuditInfoList.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 +{ + /// + /// ItemAuditInfoList Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(ItemAuditInfoListConverter))] + public partial class ItemAuditInfoList : 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 (ItemAuditInfo tmp in this) + { + tmp.Changed += new ItemAuditInfoEvent(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 (ItemAuditInfo tmp in this) + { + tmp.Changed -= new ItemAuditInfoEvent(tmp_Changed); + } + } + #endregion + #region Factory Methods + public static ItemAuditInfoList _ItemAuditInfoList = null; + /// + /// Return a list of all ItemAuditInfo. + /// + public static ItemAuditInfoList Get() + { + try + { + if (_ItemAuditInfoList != null) + return _ItemAuditInfoList; + ItemAuditInfoList tmp = DataPortal.Fetch(); + ItemAuditInfo.AddList(tmp); + tmp.AddEvents(); + _ItemAuditInfoList = tmp; + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on ItemAuditInfoList.Get", ex); + } + } + /// + /// Reset the list of all ItemAuditInfo. + /// + public static void Reset() + { + _ItemAuditInfoList = null; + } + // CSLATODO: Add alternative gets - + //public static ItemAuditInfoList Get() + //{ + // try + // { + // return DataPortal.Fetch(new FilteredCriteria()); + // } + // catch (Exception ex) + // { + // throw new DbCslaException("Error on ItemAuditInfoList.Get", ex); + // } + //} + private ItemAuditInfoList() + { /* require use of factory methods */ } + #endregion + #region Data Access Portal + private void DataPortal_Fetch() + { + this.RaiseListChangedEvents = false; + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ItemAuditInfoList.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getItemAudits"; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + IsReadOnly = false; + while (dr.Read()) this.Add(new ItemAuditInfo(dr)); + IsReadOnly = true; + } + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ItemAuditInfoList.DataPortal_Fetch", ex); + throw new DbCslaException("ItemAuditInfoList.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 + ItemAuditInfoListPropertyDescriptor pd = new ItemAuditInfoListPropertyDescriptor(this, i); + pds.Add(pd); + } + // return the property descriptor collection + return pds; + } + #endregion + } // Class + #region Property Descriptor + /// + /// Summary description for CollectionPropertyDescriptor. + /// + public partial class ItemAuditInfoListPropertyDescriptor : vlnListPropertyDescriptor + { + private ItemAuditInfo Item { get { return (ItemAuditInfo)_Item; } } + public ItemAuditInfoListPropertyDescriptor(ItemAuditInfoList collection, int index) : base(collection, index) { ;} + } + #endregion + #region Converter + internal class ItemAuditInfoListConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is ItemAuditInfoList) + { + // Return department and department role separated by comma. + return ((ItemAuditInfoList)value).Items.Count.ToString() + " ItemAudits"; + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion +} // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/PartAudit.cs b/PROMS/VEPROMS.CSLA.Library/Generated/PartAudit.cs new file mode 100644 index 00000000..6c9e8128 --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/PartAudit.cs @@ -0,0 +1,930 @@ +// ======================================================================== +// 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 +{ + /// + /// PartAudit Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(PartAuditConverter))] + public partial class PartAudit : BusinessBase, IDisposable, IVEHasBrokenRules + { + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Refresh + private List _RefreshPartAudits = new List(); + private void AddToRefreshList(List refreshPartAudits) + { + if (IsDirty) + refreshPartAudits.Add(this); + } + private void BuildRefreshList() + { + _RefreshPartAudits = new List(); + AddToRefreshList(_RefreshPartAudits); + } + private void ProcessRefreshList() + { + foreach (PartAudit tmp in _RefreshPartAudits) + { + PartAuditInfo.Refresh(tmp); + } + } + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(PartAudit partAudit) + { + if (!_CacheList.Contains(partAudit)) _CacheList.Add(partAudit); // In AddToCache + } + protected static void RemoveFromCache(PartAudit partAudit) + { + while (_CacheList.Contains(partAudit)) _CacheList.Remove(partAudit); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + while (_CacheList.Count > 0) // Move PartAudit(s) from temporary _CacheList to _CacheByPrimaryKey + { + PartAudit tmp = _CacheList[0]; // Get the first PartAudit + string pKey = tmp.AuditID.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 PartAudit + } + } + protected static PartAudit GetCachedByPrimaryKey(long auditID) + { + ConvertListToDictionary(); + string key = auditID.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 _nextAuditID = -1; + public static int NextAuditID + { + get { return _nextAuditID--; } + } + private long _AuditID; + [System.ComponentModel.DataObjectField(true, true)] + public long AuditID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("AuditID", true); + return _AuditID; + } + } + private int _ContentID; + public int ContentID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("ContentID", true); + return _ContentID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + CanWriteProperty("ContentID", true); + if (_ContentID != value) + { + _ContentID = value; + PropertyHasChanged(); + } + } + } + private int _FromType; + public int FromType + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("FromType", true); + return _FromType; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + CanWriteProperty("FromType", true); + if (_FromType != value) + { + _FromType = value; + PropertyHasChanged(); + } + } + } + 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 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 int _DeleteStatus; + public int DeleteStatus + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("DeleteStatus", true); + return _DeleteStatus; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + CanWriteProperty("DeleteStatus", true); + if (_DeleteStatus != value) + { + _DeleteStatus = value; + PropertyHasChanged(); + } + } + } + public override bool IsDirty + { + get { return base.IsDirty; } + } + public bool IsDirtyList(List list) + { + return base.IsDirty; + } + public override bool IsValid + { + get { return (IsNew && !IsDirty) ? true : base.IsValid; } + } + public bool IsValidList(List list) + { + return (IsNew && !IsDirty) ? true : base.IsValid; + } + // CSLATODO: Replace base PartAudit.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current PartAudit + //public override string ToString() + //{ + // return base.ToString(); + //} + // CSLATODO: Check PartAudit.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 PartAudit + protected override object GetIdValue() + { + return MyPartAuditUnique; // 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; + 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, "UserID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 200)); + //ValidationRules.AddDependantProperty("x", "y"); + _PartAuditExtension.AddValidationRules(ValidationRules); + // CSLATODO: Add other validation rules + } + protected override void AddInstanceBusinessRules() + { + _PartAuditExtension.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(AuditID, ""); + //AuthorizationRules.AllowRead(ContentID, ""); + //AuthorizationRules.AllowRead(FromType, ""); + //AuthorizationRules.AllowRead(ItemID, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowRead(UserID, ""); + //AuthorizationRules.AllowRead(DeleteStatus, ""); + //AuthorizationRules.AllowWrite(ContentID, ""); + //AuthorizationRules.AllowWrite(FromType, ""); + //AuthorizationRules.AllowWrite(ItemID, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowWrite(UserID, ""); + //AuthorizationRules.AllowWrite(DeleteStatus, ""); + _PartAuditExtension.AddAuthorizationRules(AuthorizationRules); + } + protected override void AddInstanceAuthorizationRules() + { + //CSLATODO: Who can read/write which fields + _PartAuditExtension.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 _PartAuditUnique = 0; + protected static int PartAuditUnique + { get { return ++_PartAuditUnique; } } + private int _MyPartAuditUnique = PartAuditUnique; + public int MyPartAuditUnique // Absolutely Unique ID - Editable + { get { return _MyPartAuditUnique; } } + protected PartAudit() + {/* require use of factory methods */ + AddToCache(this); + } + public void Dispose() + { + RemoveFromDictionaries(); + } + private void RemoveFromDictionaries() + { + RemoveFromCache(this); + if (_CacheByPrimaryKey.ContainsKey(AuditID.ToString())) + { + List listPartAudit = _CacheByPrimaryKey[AuditID.ToString()]; // Get the list of items + while (listPartAudit.Contains(this)) listPartAudit.Remove(this); // Remove the item from the list + if (listPartAudit.Count == 0) //If there are no items left in the list + _CacheByPrimaryKey.Remove(AuditID.ToString()); // remove the list + } + } + public static PartAudit New() + { + if (!CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a PartAudit"); + try + { + return DataPortal.Create(); + } + catch (Exception ex) + { + throw new DbCslaException("Error on PartAudit.New", ex); + } + } + public static PartAudit New(int contentID, int fromType, int itemID, DateTime dts, string userID, int deleteStatus) + { + PartAudit tmp = PartAudit.New(); + tmp.ContentID = contentID; + tmp.FromType = fromType; + tmp.ItemID = itemID; + tmp.DTS = dts; + tmp.UserID = userID; + tmp.DeleteStatus = deleteStatus; + return tmp; + } + public static PartAudit MakePartAudit(int contentID, int fromType, int itemID, DateTime dts, string userID, int deleteStatus) + { + PartAudit tmp = PartAudit.New(contentID, fromType, itemID, dts, userID, deleteStatus); + if (tmp.IsSavable) + { + PartAudit 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 PartAudit Get(long auditID) + { + if (!CanGetObject()) + throw new System.Security.SecurityException("User not authorized to view a PartAudit"); + try + { + PartAudit tmp = GetCachedByPrimaryKey(auditID); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(auditID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up PartAudit + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on PartAudit.Get", ex); + } + } + public static PartAudit Get(SafeDataReader dr) + { + if (dr.Read()) return new PartAudit(dr); + return null; + } + internal PartAudit(SafeDataReader dr) + { + ReadData(dr); + } + public static void Delete(long auditID) + { + if (!CanDeleteObject()) + throw new System.Security.SecurityException("User not authorized to remove a PartAudit"); + try + { + DataPortal.Delete(new PKCriteria(auditID)); + } + catch (Exception ex) + { + throw new DbCslaException("Error on PartAudit.Delete", ex); + } + } + public override PartAudit Save() + { + if (IsDeleted && !CanDeleteObject()) + throw new System.Security.SecurityException("User not authorized to remove a PartAudit"); + else if (IsNew && !CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a PartAudit"); + else if (!CanEditObject()) + throw new System.Security.SecurityException("User not authorized to update a PartAudit"); + try + { + BuildRefreshList(); + PartAudit partAudit = base.Save(); + RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache + AddToCache(partAudit);//Refresh the item in AllList + ProcessRefreshList(); + return partAudit; + } + catch (Exception ex) + { + throw new DbCslaException("Error on CSLA Save", ex); + } + } + #endregion + #region Data Access Portal + [Serializable()] + protected class PKCriteria + { + private long _AuditID; + public long AuditID + { get { return _AuditID; } } + public PKCriteria(long auditID) + { + _AuditID = auditID; + } + } + // CSLATODO: If Create needs to access DB - It should not be marked RunLocal + [RunLocal()] + private new void DataPortal_Create() + { + _AuditID = NextAuditID; + // Database Defaults + + // CSLATODO: Add any defaults that are necessary + ValidationRules.CheckRules(); + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] PartAudit.ReadData", GetHashCode()); + try + { + _AuditID = dr.GetInt64("AuditID"); + _ContentID = dr.GetInt32("ContentID"); + _FromType = dr.GetInt32("FromType"); + _ItemID = dr.GetInt32("ItemID"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + _DeleteStatus = dr.GetInt32("DeleteStatus"); + MarkOld(); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("PartAudit.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("PartAudit.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] PartAudit.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 = "getPartAudit"; + cm.Parameters.AddWithValue("@AuditID", criteria.AuditID); + 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("PartAudit.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("PartAudit.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("PartAudit.DataPortal_Insert", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("PartAudit.DataPortal_Insert", ex); + } + finally + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] PartAudit.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 = "addPartAudit"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@ContentID", _ContentID); + cm.Parameters.AddWithValue("@FromType", _FromType); + cm.Parameters.AddWithValue("@ItemID", _ItemID); + if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS); + cm.Parameters.AddWithValue("@UserID", _UserID); + cm.Parameters.AddWithValue("@DeleteStatus", _DeleteStatus); + // Output Calculated Columns + SqlParameter param_AuditID = new SqlParameter("@newAuditID", SqlDbType.BigInt); + param_AuditID.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_AuditID); + // CSLATODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + _AuditID = (long)cm.Parameters["@newAuditID"].Value; + } + MarkOld(); + // update child objects + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] PartAudit.SQLInsert", GetHashCode()); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("PartAudit.SQLInsert", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("PartAudit.SQLInsert", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + public static void Add(SqlConnection cn, ref long auditID, int contentID, int fromType, int itemID, DateTime dts, string userID, int deleteStatus) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] PartAudit.Add", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "addPartAudit"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@ContentID", contentID); + cm.Parameters.AddWithValue("@FromType", fromType); + cm.Parameters.AddWithValue("@ItemID", itemID); + if (dts.Year >= 1753 && dts.Year <= 9999) cm.Parameters.AddWithValue("@DTS", dts); + cm.Parameters.AddWithValue("@UserID", userID); + cm.Parameters.AddWithValue("@DeleteStatus", deleteStatus); + // Output Calculated Columns + SqlParameter param_AuditID = new SqlParameter("@newAuditID", SqlDbType.BigInt); + param_AuditID.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_AuditID); + // CSLATODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + auditID = (long)cm.Parameters["@newAuditID"].Value; + // No Timestamp value to return + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("PartAudit.Add", ex); + throw new DbCslaException("PartAudit.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}] PartAudit.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("PartAudit.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}] PartAudit.SQLUpdate", GetHashCode()); + try + { + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + if (base.IsDirty) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "updatePartAudit"; + // All Fields including Calculated Fields + cm.Parameters.AddWithValue("@AuditID", _AuditID); + cm.Parameters.AddWithValue("@ContentID", _ContentID); + cm.Parameters.AddWithValue("@FromType", _FromType); + cm.Parameters.AddWithValue("@ItemID", _ItemID); + if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS); + cm.Parameters.AddWithValue("@UserID", _UserID); + cm.Parameters.AddWithValue("@DeleteStatus", _DeleteStatus); + // Output Calculated Columns + // CSLATODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + } + } + MarkOld(); + // use the open connection to update child objects + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("PartAudit.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) + PartAudit.Add(cn, ref _AuditID, _ContentID, _FromType, _ItemID, _DTS, _UserID, _DeleteStatus); + else + PartAudit.Update(cn, ref _AuditID, _ContentID, _FromType, _ItemID, _DTS, _UserID, _DeleteStatus); + MarkOld(); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + public static void Update(SqlConnection cn, ref long auditID, int contentID, int fromType, int itemID, DateTime dts, string userID, int deleteStatus) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] PartAudit.Update", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "updatePartAudit"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@AuditID", auditID); + cm.Parameters.AddWithValue("@ContentID", contentID); + cm.Parameters.AddWithValue("@FromType", fromType); + cm.Parameters.AddWithValue("@ItemID", itemID); + if (dts.Year >= 1753 && dts.Year <= 9999) cm.Parameters.AddWithValue("@DTS", dts); + cm.Parameters.AddWithValue("@UserID", userID); + cm.Parameters.AddWithValue("@DeleteStatus", deleteStatus); + // Output Calculated Columns + // CSLATODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + // No Timestamp value to return + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("PartAudit.Update", ex); + throw new DbCslaException("PartAudit.Update", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_DeleteSelf() + { + DataPortal_Delete(new PKCriteria(_AuditID)); + } + [Transactional(TransactionalTypes.TransactionScope)] + private void DataPortal_Delete(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] PartAudit.DataPortal_Delete", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "deletePartAudit"; + cm.Parameters.AddWithValue("@AuditID", criteria.AuditID); + cm.ExecuteNonQuery(); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("PartAudit.DataPortal_Delete", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("PartAudit.DataPortal_Delete", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + public static void Remove(SqlConnection cn, long auditID) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] PartAudit.Remove", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "deletePartAudit"; + // Input PK Fields + cm.Parameters.AddWithValue("@AuditID", auditID); + // CSLATODO: Define any additional output parameters + cm.ExecuteNonQuery(); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("PartAudit.Remove", ex); + throw new DbCslaException("PartAudit.Remove", ex); + } + } + #endregion + // Standard Default Code + #region extension + PartAuditExtension _PartAuditExtension = new PartAuditExtension(); + [Serializable()] + partial class PartAuditExtension : 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 PartAuditConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is PartAudit) + { + // Return the ToString value + return ((PartAudit)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion +} // Namespace + + +//// The following is a sample Extension File. You can use it to create PartAuditExt.cs +//using System; +//using System.Collections.Generic; +//using System.Text; +//using Csla; + +//namespace VEPROMS.CSLA.Library +//{ +// public partial class PartAudit +// { +// partial class PartAuditExtension : 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/PartAuditInfo.cs b/PROMS/VEPROMS.CSLA.Library/Generated/PartAuditInfo.cs new file mode 100644 index 00000000..b8ae93fd --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/PartAuditInfo.cs @@ -0,0 +1,358 @@ +// ======================================================================== +// 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 PartAuditInfoEvent(object sender); + /// + /// PartAuditInfo Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(PartAuditInfoConverter))] + public partial class PartAuditInfo : ReadOnlyBase, IDisposable + { + public event PartAuditInfoEvent 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(PartAuditInfo partAuditInfo) + { + if (!_CacheList.Contains(partAuditInfo)) _CacheList.Add(partAuditInfo); // In AddToCache + } + protected static void RemoveFromCache(PartAuditInfo partAuditInfo) + { + while (_CacheList.Contains(partAuditInfo)) _CacheList.Remove(partAuditInfo); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + while (_CacheList.Count > 0) // Move PartAuditInfo(s) from temporary _CacheList to _CacheByPrimaryKey + { + PartAuditInfo tmp = _CacheList[0]; // Get the first PartAuditInfo + string pKey = tmp.AuditID.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 PartAuditInfo + } + } + internal static void AddList(PartAuditInfoList lst) + { + foreach (PartAuditInfo item in lst) AddToCache(item); + } + protected static PartAuditInfo GetCachedByPrimaryKey(long auditID) + { + ConvertListToDictionary(); + string key = auditID.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 PartAudit _Editable; + private IVEHasBrokenRules HasBrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = null; + if (_Editable != null) + hasBrokenRules = _Editable.HasBrokenRules; + return hasBrokenRules; + } + } + private long _AuditID; + [System.ComponentModel.DataObjectField(true, true)] + public long AuditID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("AuditID", true); + return _AuditID; + } + } + private int _ContentID; + public int ContentID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("ContentID", true); + return _ContentID; + } + } + private int _FromType; + public int FromType + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("FromType", true); + return _FromType; + } + } + private int _ItemID; + public int ItemID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("ItemID", true); + return _ItemID; + } + } + 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 _DeleteStatus; + public int DeleteStatus + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("DeleteStatus", true); + return _DeleteStatus; + } + } + // CSLATODO: Replace base PartAuditInfo.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current PartAuditInfo + //public override string ToString() + //{ + // return base.ToString(); + //} + // CSLATODO: Check PartAuditInfo.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 PartAuditInfo + protected override object GetIdValue() + { + return MyPartAuditInfoUnique; // Absolutely Unique ID + } + #endregion + #region Factory Methods + private static int _PartAuditInfoUnique = 0; + private static int PartAuditInfoUnique + { get { return ++_PartAuditInfoUnique; } } + private int _MyPartAuditInfoUnique = PartAuditInfoUnique; + public int MyPartAuditInfoUnique // Absolutely Unique ID - Info + { get { return _MyPartAuditInfoUnique; } } + protected PartAuditInfo() + {/* require use of factory methods */ + AddToCache(this); + } + public void Dispose() + { + RemoveFromCache(this); + if (!_CacheByPrimaryKey.ContainsKey(AuditID.ToString())) return; + List listPartAuditInfo = _CacheByPrimaryKey[AuditID.ToString()]; // Get the list of items + while (listPartAuditInfo.Contains(this)) listPartAuditInfo.Remove(this); // Remove the item from the list + if (listPartAuditInfo.Count == 0) // If there are no items left in the list + _CacheByPrimaryKey.Remove(AuditID.ToString()); // remove the list + } + public virtual PartAudit Get() + { + return _Editable = PartAudit.Get(_AuditID); + } + public static void Refresh(PartAudit tmp) + { + string key = tmp.AuditID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (PartAuditInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(PartAudit tmp) + { + _ContentID = tmp.ContentID; + _FromType = tmp.FromType; + _ItemID = tmp.ItemID; + _DTS = tmp.DTS; + _UserID = tmp.UserID; + _DeleteStatus = tmp.DeleteStatus; + _PartAuditInfoExtension.Refresh(this); + OnChange();// raise an event + } + public static PartAuditInfo Get(long auditID) + { + //if (!CanGetObject()) + // throw new System.Security.SecurityException("User not authorized to view a PartAudit"); + try + { + PartAuditInfo tmp = GetCachedByPrimaryKey(auditID); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(auditID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up PartAuditInfo + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on PartAuditInfo.Get", ex); + } + } + #endregion + #region Data Access Portal + internal PartAuditInfo(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] PartAuditInfo.Constructor", GetHashCode()); + try + { + ReadData(dr); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("PartAuditInfo.Constructor", ex); + throw new DbCslaException("PartAuditInfo.Constructor", ex); + } + } + [Serializable()] + protected class PKCriteria + { + private long _AuditID; + public long AuditID + { get { return _AuditID; } } + public PKCriteria(long auditID) + { + _AuditID = auditID; + } + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] PartAuditInfo.ReadData", GetHashCode()); + try + { + _AuditID = dr.GetInt64("AuditID"); + _ContentID = dr.GetInt32("ContentID"); + _FromType = dr.GetInt32("FromType"); + _ItemID = dr.GetInt32("ItemID"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + _DeleteStatus = dr.GetInt32("DeleteStatus"); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("PartAuditInfo.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("PartAuditInfo.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] PartAuditInfo.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 = "getPartAudit"; + cm.Parameters.AddWithValue("@AuditID", criteria.AuditID); + 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("PartAuditInfo.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("PartAuditInfo.DataPortal_Fetch", ex); + } + } + #endregion + // Standard Refresh + #region extension + PartAuditInfoExtension _PartAuditInfoExtension = new PartAuditInfoExtension(); + [Serializable()] + partial class PartAuditInfoExtension : extensionBase { } + [Serializable()] + class extensionBase + { + // Default Refresh + public virtual void Refresh(PartAuditInfo tmp) { } + } + #endregion + } // Class + #region Converter + internal class PartAuditInfoConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is PartAuditInfo) + { + // Return the ToString value + return ((PartAuditInfo)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion +} // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/PartAuditInfoList.cs b/PROMS/VEPROMS.CSLA.Library/Generated/PartAuditInfoList.cs new file mode 100644 index 00000000..f4235c6f --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Generated/PartAuditInfoList.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 +{ + /// + /// PartAuditInfoList Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(PartAuditInfoListConverter))] + public partial class PartAuditInfoList : 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 (PartAuditInfo tmp in this) + { + tmp.Changed += new PartAuditInfoEvent(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 (PartAuditInfo tmp in this) + { + tmp.Changed -= new PartAuditInfoEvent(tmp_Changed); + } + } + #endregion + #region Factory Methods + public static PartAuditInfoList _PartAuditInfoList = null; + /// + /// Return a list of all PartAuditInfo. + /// + public static PartAuditInfoList Get() + { + try + { + if (_PartAuditInfoList != null) + return _PartAuditInfoList; + PartAuditInfoList tmp = DataPortal.Fetch(); + PartAuditInfo.AddList(tmp); + tmp.AddEvents(); + _PartAuditInfoList = tmp; + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on PartAuditInfoList.Get", ex); + } + } + /// + /// Reset the list of all PartAuditInfo. + /// + public static void Reset() + { + _PartAuditInfoList = null; + } + // CSLATODO: Add alternative gets - + //public static PartAuditInfoList Get() + //{ + // try + // { + // return DataPortal.Fetch(new FilteredCriteria()); + // } + // catch (Exception ex) + // { + // throw new DbCslaException("Error on PartAuditInfoList.Get", ex); + // } + //} + private PartAuditInfoList() + { /* require use of factory methods */ } + #endregion + #region Data Access Portal + private void DataPortal_Fetch() + { + this.RaiseListChangedEvents = false; + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] PartAuditInfoList.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getPartAudits"; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + IsReadOnly = false; + while (dr.Read()) this.Add(new PartAuditInfo(dr)); + IsReadOnly = true; + } + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("PartAuditInfoList.DataPortal_Fetch", ex); + throw new DbCslaException("PartAuditInfoList.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 + PartAuditInfoListPropertyDescriptor pd = new PartAuditInfoListPropertyDescriptor(this, i); + pds.Add(pd); + } + // return the property descriptor collection + return pds; + } + #endregion + } // Class + #region Property Descriptor + /// + /// Summary description for CollectionPropertyDescriptor. + /// + public partial class PartAuditInfoListPropertyDescriptor : vlnListPropertyDescriptor + { + private PartAuditInfo Item { get { return (PartAuditInfo)_Item; } } + public PartAuditInfoListPropertyDescriptor(PartAuditInfoList collection, int index) : base(collection, index) { ;} + } + #endregion + #region Converter + internal class PartAuditInfoListConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is PartAuditInfoList) + { + // Return department and department role separated by comma. + return ((PartAuditInfoList)value).Items.Count.ToString() + " PartAudits"; + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion +} // Namespace