This commit is contained in:
Jsj
2008-05-16 18:07:47 +00:00
parent 9d0b3cd543
commit cda0291dbd
116 changed files with 4257 additions and 3382 deletions

View File

@@ -47,20 +47,24 @@ namespace VEPROMS.CSLA.Library
foreach (Membership tmp in _RefreshMemberships)
{
MembershipInfo.Refresh(tmp);
if(tmp._MyGroup != null) GroupInfo.Refresh(tmp._MyGroup);
if(tmp._MyUser != null) UserInfo.Refresh(tmp._MyUser);
if (tmp._MyGroup != null) GroupInfo.Refresh(tmp._MyGroup);
if (tmp._MyUser != null) UserInfo.Refresh(tmp._MyUser);
}
}
#endregion
#region Collection
protected static List<Membership> _AllList = new List<Membership>();
private static Dictionary<string, Membership> _AllByPrimaryKey = new Dictionary<string, Membership>();
private static Dictionary<string, List<Membership>> _AllByPrimaryKey = new Dictionary<string, List<Membership>>();
private static void ConvertListToDictionary()
{
List<Membership> remove = new List<Membership>();
foreach (Membership tmp in _AllList)
{
_AllByPrimaryKey[tmp.UGID.ToString()]=tmp; // Primary Key
if (!_AllByPrimaryKey.ContainsKey(tmp.UGID.ToString()))
{
_AllByPrimaryKey[tmp.UGID.ToString()] = new List<Membership>(); // Add new list for PrimaryKey
}
_AllByPrimaryKey[tmp.UGID.ToString()].Add(tmp); // Add to Primary Key list
remove.Add(tmp);
}
foreach (Membership tmp in remove)
@@ -70,7 +74,7 @@ namespace VEPROMS.CSLA.Library
{
ConvertListToDictionary();
string key = ugid.ToString();
if (_AllByPrimaryKey.ContainsKey(key)) return _AllByPrimaryKey[key];
if (_AllByPrimaryKey.ContainsKey(key)) return _AllByPrimaryKey[key][0];
return null;
}
#endregion
@@ -92,7 +96,7 @@ namespace VEPROMS.CSLA.Library
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty("UGID",true);
CanReadProperty("UGID", true);
return _UGID;
}
}
@@ -102,7 +106,7 @@ namespace VEPROMS.CSLA.Library
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty("UID",true);
CanReadProperty("UID", true);
if (_MyUser != null) _UID = _MyUser.UID;
return _UID;
}
@@ -113,14 +117,14 @@ namespace VEPROMS.CSLA.Library
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty("MyUser",true);
CanReadProperty("MyUser", true);
if (_MyUser == null && _UID != 0) _MyUser = User.Get(_UID);
return _MyUser;
}
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
set
{
CanWriteProperty("MyUser",true);
CanWriteProperty("MyUser", true);
if (_MyUser != value)
{
_MyUser = value;
@@ -134,7 +138,7 @@ namespace VEPROMS.CSLA.Library
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty("GID",true);
CanReadProperty("GID", true);
if (_MyGroup != null) _GID = _MyGroup.GID;
return _GID;
}
@@ -145,14 +149,14 @@ namespace VEPROMS.CSLA.Library
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty("MyGroup",true);
CanReadProperty("MyGroup", true);
if (_MyGroup == null && _GID != 0) _MyGroup = Group.Get(_GID);
return _MyGroup;
}
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
set
{
CanWriteProperty("MyGroup",true);
CanWriteProperty("MyGroup", true);
if (_MyGroup != value)
{
_MyGroup = value;
@@ -166,13 +170,13 @@ namespace VEPROMS.CSLA.Library
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty("StartDate",true);
CanReadProperty("StartDate", true);
return _StartDate;
}
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
set
{
CanWriteProperty("StartDate",true);
CanWriteProperty("StartDate", true);
if (value == null) value = string.Empty;
_StartDate = value;
try
@@ -196,13 +200,13 @@ namespace VEPROMS.CSLA.Library
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty("EndDate",true);
CanReadProperty("EndDate", true);
return _EndDate;
}
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
set
{
CanWriteProperty("EndDate",true);
CanWriteProperty("EndDate", true);
if (value == null) value = string.Empty;
_EndDate = value;
try
@@ -226,13 +230,13 @@ namespace VEPROMS.CSLA.Library
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty("Config",true);
CanReadProperty("Config", true);
return _Config;
}
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
set
{
CanWriteProperty("Config",true);
CanWriteProperty("Config", true);
if (value == null) value = string.Empty;
if (_Config != value)
{
@@ -247,13 +251,13 @@ namespace VEPROMS.CSLA.Library
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty("DTS",true);
CanReadProperty("DTS", true);
return _DTS;
}
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
set
{
CanWriteProperty("DTS",true);
CanWriteProperty("DTS", true);
if (_DTS != value)
{
_DTS = value;
@@ -267,13 +271,13 @@ namespace VEPROMS.CSLA.Library
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty("UsrID",true);
CanReadProperty("UsrID", true);
return _UsrID;
}
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
set
{
CanWriteProperty("UsrID",true);
CanWriteProperty("UsrID", true);
if (value == null) value = string.Empty;
if (_UsrID != value)
{
@@ -285,11 +289,11 @@ namespace VEPROMS.CSLA.Library
private byte[] _LastChanged = new byte[8];//timestamp
public override bool IsDirty
{
get { return base.IsDirty || (_MyGroup == null? false : _MyGroup.IsDirty) || (_MyUser == null? false : _MyUser.IsDirty); }
get { return base.IsDirty || (_MyGroup == null ? false : _MyGroup.IsDirty) || (_MyUser == null ? false : _MyUser.IsDirty); }
}
public override bool IsValid
{
get { return (IsNew && !IsDirty ? true : base.IsValid) && (_MyGroup == null? true : _MyGroup.IsValid) && (_MyUser == null? true : _MyUser.IsValid); }
get { return (IsNew && !IsDirty ? true : base.IsValid) && (_MyGroup == null ? true : _MyGroup.IsValid) && (_MyUser == null ? true : _MyUser.IsValid); }
}
// TODO: Replace base Membership.ToString function as necessary
/// <summary>
@@ -312,23 +316,24 @@ namespace VEPROMS.CSLA.Library
#endregion
#region ValidationRules
[NonSerialized]
private bool _CheckingBrokenRules=false;
private bool _CheckingBrokenRules = false;
public IVEHasBrokenRules HasBrokenRules
{
get {
if(_CheckingBrokenRules)return null;
get
{
if (_CheckingBrokenRules) return null;
if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this;
try
{
_CheckingBrokenRules=true;
_CheckingBrokenRules = true;
IVEHasBrokenRules hasBrokenRules = null;
if (_MyUser != null && (hasBrokenRules = _MyUser.HasBrokenRules) != null) return hasBrokenRules;
if (_MyGroup != null && (hasBrokenRules = _MyGroup.HasBrokenRules) != null) return hasBrokenRules;
if (_MyUser != null && (hasBrokenRules = _MyUser.HasBrokenRules) != null) return hasBrokenRules;
if (_MyGroup != null && (hasBrokenRules = _MyGroup.HasBrokenRules) != null) return hasBrokenRules;
return hasBrokenRules;
}
finally
{
_CheckingBrokenRules=false;
_CheckingBrokenRules = false;
}
}
}
@@ -478,14 +483,25 @@ namespace VEPROMS.CSLA.Library
#region Factory Methods
public int CurrentEditLevel
{ get { return EditLevel; } }
private static int _MembershipUnique = 0;
private int _MyMembershipUnique;
public int MyMembershipUnique
{
get { return _MyMembershipUnique; }
}
protected Membership()
{/* require use of factory methods */
_MyMembershipUnique = ++_MembershipUnique;
_AllList.Add(this);
}
public void Dispose()
{
_AllList.Remove(this);
_AllByPrimaryKey.Remove(UGID.ToString());
if (!_AllByPrimaryKey.ContainsKey(UGID.ToString())) return;
List<Membership> listMembership = _AllByPrimaryKey[UGID.ToString()]; // Get the list of items
listMembership.Remove(this); // Remove the item from the list
if (listMembership.Count == 0) //If there are no items left in the list
_AllByPrimaryKey.Remove(UGID.ToString()); // remove the list
}
public static Membership New()
{
@@ -570,7 +586,7 @@ namespace VEPROMS.CSLA.Library
if (tmp == null)
{
tmp = DataPortal.Fetch<Membership>(new PKCriteria(ugid));
_AllList.Add(tmp);
if (!_AllList.Contains(tmp)) _AllList.Add(tmp);
}
if (tmp.ErrorMessage == "No Record Found") tmp = null;
return tmp;
@@ -650,7 +666,7 @@ namespace VEPROMS.CSLA.Library
}
private void ReadData(SafeDataReader dr)
{
if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] Membership.ReadData", GetHashCode());
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Membership.ReadData", GetHashCode());
try
{
_UGID = dr.GetInt32("UGID");
@@ -666,14 +682,14 @@ namespace VEPROMS.CSLA.Library
}
catch (Exception ex)
{
if(_MyLog.IsErrorEnabled)_MyLog.Error("Membership.ReadData", ex);
if (_MyLog.IsErrorEnabled) _MyLog.Error("Membership.ReadData", ex);
_ErrorMessage = ex.Message;
throw new DbCslaException("Membership.ReadData", ex);
}
}
private void DataPortal_Fetch(PKCriteria criteria)
{
if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] Membership.DataPortal_Fetch", GetHashCode());
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Membership.DataPortal_Fetch", GetHashCode());
try
{
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
@@ -701,7 +717,7 @@ namespace VEPROMS.CSLA.Library
}
catch (Exception ex)
{
if(_MyLog.IsErrorEnabled)_MyLog.Error("Membership.DataPortal_Fetch", ex);
if (_MyLog.IsErrorEnabled) _MyLog.Error("Membership.DataPortal_Fetch", ex);
_ErrorMessage = ex.Message;
throw new DbCslaException("Membership.DataPortal_Fetch", ex);
}
@@ -722,13 +738,13 @@ namespace VEPROMS.CSLA.Library
}
catch (Exception ex)
{
if(_MyLog.IsErrorEnabled)_MyLog.Error("Membership.DataPortal_Insert", ex);
if (_MyLog.IsErrorEnabled) _MyLog.Error("Membership.DataPortal_Insert", ex);
_ErrorMessage = ex.Message;
throw new DbCslaException("Membership.DataPortal_Insert", ex);
}
finally
{
if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] Membership.DataPortal_Insert", GetHashCode());
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Membership.DataPortal_Insert", GetHashCode());
}
}
[Transactional(TransactionalTypes.TransactionScope)]
@@ -737,8 +753,8 @@ namespace VEPROMS.CSLA.Library
if (!this.IsDirty) return;
try
{
if(_MyGroup != null) _MyGroup.Update();
if(_MyUser != null) _MyUser.Update();
if (_MyGroup != null) _MyGroup.Update();
if (_MyUser != null) _MyUser.Update();
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
using (SqlCommand cm = cn.CreateCommand())
{
@@ -767,11 +783,11 @@ namespace VEPROMS.CSLA.Library
}
MarkOld();
// update child objects
if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] Membership.SQLInsert", GetHashCode());
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Membership.SQLInsert", GetHashCode());
}
catch (Exception ex)
{
if(_MyLog.IsErrorEnabled)_MyLog.Error("Membership.SQLInsert", ex);
if (_MyLog.IsErrorEnabled) _MyLog.Error("Membership.SQLInsert", ex);
_ErrorMessage = ex.Message;
throw new DbCslaException("Membership.SQLInsert", ex);
}
@@ -779,7 +795,7 @@ namespace VEPROMS.CSLA.Library
[Transactional(TransactionalTypes.TransactionScope)]
public static byte[] Add(SqlConnection cn, ref int ugid, User myUser, Group myGroup, SmartDate startDate, SmartDate endDate, string config, DateTime dts, string usrID)
{
if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] Membership.Add", 0);
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Membership.Add", 0);
try
{
using (SqlCommand cm = cn.CreateCommand())
@@ -810,7 +826,7 @@ namespace VEPROMS.CSLA.Library
}
catch (Exception ex)
{
if(_MyLog.IsErrorEnabled)_MyLog.Error("Membership.Add", ex);
if (_MyLog.IsErrorEnabled) _MyLog.Error("Membership.Add", ex);
throw new DbCslaException("Membership.Add", ex);
}
}
@@ -818,7 +834,7 @@ namespace VEPROMS.CSLA.Library
protected override void DataPortal_Update()
{
if (!IsDirty) return; // If not dirty - nothing to do
if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] Membership.DataPortal_Update", GetHashCode());
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Membership.DataPortal_Update", GetHashCode());
try
{
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
@@ -832,7 +848,7 @@ namespace VEPROMS.CSLA.Library
}
catch (Exception ex)
{
if(_MyLog.IsErrorEnabled)_MyLog.Error("Membership.DataPortal_Update", ex);
if (_MyLog.IsErrorEnabled) _MyLog.Error("Membership.DataPortal_Update", ex);
_ErrorMessage = ex.Message;
if (!ex.Message.EndsWith("has been edited by another user.")) throw ex;
}
@@ -841,11 +857,11 @@ namespace VEPROMS.CSLA.Library
internal void SQLUpdate()
{
if (!IsDirty) return; // If not dirty - nothing to do
if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] Membership.SQLUpdate", GetHashCode());
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Membership.SQLUpdate", GetHashCode());
try
{
if(_MyGroup != null) _MyGroup.Update();
if(_MyUser != null) _MyUser.Update();
if (_MyGroup != null) _MyGroup.Update();
if (_MyUser != null) _MyUser.Update();
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
if (base.IsDirty)
{
@@ -878,7 +894,7 @@ namespace VEPROMS.CSLA.Library
}
catch (Exception ex)
{
if(_MyLog.IsErrorEnabled)_MyLog.Error("Membership.SQLUpdate", ex);
if (_MyLog.IsErrorEnabled) _MyLog.Error("Membership.SQLUpdate", ex);
_ErrorMessage = ex.Message;
if (!ex.Message.EndsWith("has been edited by another user.")) throw ex;
}
@@ -899,7 +915,7 @@ namespace VEPROMS.CSLA.Library
[Transactional(TransactionalTypes.TransactionScope)]
public static byte[] Update(SqlConnection cn, ref int ugid, User myUser, Group myGroup, SmartDate startDate, SmartDate endDate, string config, DateTime dts, string usrID, ref byte[] lastChanged)
{
if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] Membership.Update", 0);
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Membership.Update", 0);
try
{
using (SqlCommand cm = cn.CreateCommand())
@@ -928,7 +944,7 @@ namespace VEPROMS.CSLA.Library
}
catch (Exception ex)
{
if(_MyLog.IsErrorEnabled)_MyLog.Error("Membership.Update", ex);
if (_MyLog.IsErrorEnabled) _MyLog.Error("Membership.Update", ex);
throw new DbCslaException("Membership.Update", ex);
}
}
@@ -940,7 +956,7 @@ namespace VEPROMS.CSLA.Library
[Transactional(TransactionalTypes.TransactionScope)]
private void DataPortal_Delete(PKCriteria criteria)
{
if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] Membership.DataPortal_Delete", GetHashCode());
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Membership.DataPortal_Delete", GetHashCode());
try
{
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
@@ -956,7 +972,7 @@ namespace VEPROMS.CSLA.Library
}
catch (Exception ex)
{
if(_MyLog.IsErrorEnabled)_MyLog.Error("Membership.DataPortal_Delete", ex);
if (_MyLog.IsErrorEnabled) _MyLog.Error("Membership.DataPortal_Delete", ex);
_ErrorMessage = ex.Message;
throw new DbCslaException("Membership.DataPortal_Delete", ex);
}
@@ -964,7 +980,7 @@ namespace VEPROMS.CSLA.Library
[Transactional(TransactionalTypes.TransactionScope)]
public static void Remove(SqlConnection cn, int ugid)
{
if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] Membership.Remove", 0);
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Membership.Remove", 0);
try
{
using (SqlCommand cm = cn.CreateCommand())
@@ -979,7 +995,7 @@ namespace VEPROMS.CSLA.Library
}
catch (Exception ex)
{
if(_MyLog.IsErrorEnabled)_MyLog.Error("Membership.Remove", ex);
if (_MyLog.IsErrorEnabled) _MyLog.Error("Membership.Remove", ex);
throw new DbCslaException("Membership.Remove", ex);
}
}
@@ -1013,7 +1029,7 @@ namespace VEPROMS.CSLA.Library
}
protected override void DataPortal_Execute()
{
if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] Membership.DataPortal_Execute", GetHashCode());
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Membership.DataPortal_Execute", GetHashCode());
try
{
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
@@ -1031,7 +1047,7 @@ namespace VEPROMS.CSLA.Library
}
catch (Exception ex)
{
if(_MyLog.IsErrorEnabled)_MyLog.Error("Membership.DataPortal_Execute", ex);
if (_MyLog.IsErrorEnabled) _MyLog.Error("Membership.DataPortal_Execute", ex);
throw new DbCslaException("Membership.DataPortal_Execute", ex);
}
}