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

@@ -37,13 +37,17 @@ namespace VEPROMS.CSLA.Library
#endregion
#region Collection
protected static List<DetailInfo> _AllList = new List<DetailInfo>();
private static Dictionary<string, DetailInfo> _AllByPrimaryKey = new Dictionary<string, DetailInfo>();
private static Dictionary<string, List<DetailInfo>> _AllByPrimaryKey = new Dictionary<string, List<DetailInfo>>();
private static void ConvertListToDictionary()
{
List<DetailInfo> remove = new List<DetailInfo>();
foreach (DetailInfo tmp in _AllList)
{
_AllByPrimaryKey[tmp.DetailID.ToString()]=tmp; // Primary Key
if (!_AllByPrimaryKey.ContainsKey(tmp.DetailID.ToString()))
{
_AllByPrimaryKey[tmp.DetailID.ToString()] = new List<DetailInfo>(); // Add new list for PrimaryKey
}
_AllByPrimaryKey[tmp.DetailID.ToString()].Add(tmp); // Add to Primary Key list
remove.Add(tmp);
}
foreach (DetailInfo tmp in remove)
@@ -57,7 +61,7 @@ namespace VEPROMS.CSLA.Library
{
ConvertListToDictionary();
string key = detailID.ToString();
if (_AllByPrimaryKey.ContainsKey(key)) return _AllByPrimaryKey[key];
if (_AllByPrimaryKey.ContainsKey(key)) return _AllByPrimaryKey[key][0];
return null;
}
#endregion
@@ -85,7 +89,7 @@ namespace VEPROMS.CSLA.Library
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty("DetailID",true);
CanReadProperty("DetailID", true);
return _DetailID;
}
}
@@ -95,7 +99,7 @@ namespace VEPROMS.CSLA.Library
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty("ContentID",true);
CanReadProperty("ContentID", true);
if (_MyContent != null) _ContentID = _MyContent.ContentID;
return _ContentID;
}
@@ -106,7 +110,7 @@ namespace VEPROMS.CSLA.Library
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty("MyContent",true);
CanReadProperty("MyContent", true);
if (_MyContent == null && _ContentID != 0) _MyContent = ContentInfo.Get(_ContentID);
return _MyContent;
}
@@ -117,7 +121,7 @@ namespace VEPROMS.CSLA.Library
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty("ItemType",true);
CanReadProperty("ItemType", true);
return _ItemType;
}
}
@@ -127,7 +131,7 @@ namespace VEPROMS.CSLA.Library
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty("Text",true);
CanReadProperty("Text", true);
return _Text;
}
}
@@ -137,7 +141,7 @@ namespace VEPROMS.CSLA.Library
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty("Config",true);
CanReadProperty("Config", true);
return _Config;
}
}
@@ -147,7 +151,7 @@ namespace VEPROMS.CSLA.Library
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty("DTS",true);
CanReadProperty("DTS", true);
return _DTS;
}
}
@@ -157,7 +161,7 @@ namespace VEPROMS.CSLA.Library
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty("UserID",true);
CanReadProperty("UserID", true);
return _UserID;
}
}
@@ -181,14 +185,25 @@ namespace VEPROMS.CSLA.Library
}
#endregion
#region Factory Methods
private static int _DetailInfoUnique = 0;
private int _MyDetailInfoUnique;
public int MyDetailInfoUnique
{
get { return _MyDetailInfoUnique; }
}
private DetailInfo()
{/* require use of factory methods */
_MyDetailInfoUnique = ++_DetailInfoUnique;
_AllList.Add(this);
}
public void Dispose()
{
_AllList.Remove(this);
_AllByPrimaryKey.Remove(DetailID.ToString());
if (!_AllByPrimaryKey.ContainsKey(DetailID.ToString())) return;
List<DetailInfo> listDetailInfo = _AllByPrimaryKey[DetailID.ToString()]; // Get the list of items
listDetailInfo.Remove(this); // Remove the item from the list
if (listDetailInfo.Count == 0) // If there are no items left in the list
_AllByPrimaryKey.Remove(DetailID.ToString()); // remove the list
}
public virtual Detail Get()
{
@@ -196,9 +211,11 @@ namespace VEPROMS.CSLA.Library
}
public static void Refresh(Detail tmp)
{
DetailInfo tmpInfo = GetExistingByPrimaryKey(tmp.DetailID);
if (tmpInfo == null) return;
tmpInfo.RefreshFields(tmp);
string key = tmp.DetailID.ToString();
ConvertListToDictionary();
if (_AllByPrimaryKey.ContainsKey(key))
foreach (DetailInfo tmpInfo in _AllByPrimaryKey[key])
tmpInfo.RefreshFields(tmp);
}
private void RefreshFields(Detail tmp)
{
@@ -206,9 +223,9 @@ namespace VEPROMS.CSLA.Library
{
MyContent.RefreshContentDetails(); // Update List for old value
_ContentID = tmp.ContentID; // Update the value
_MyContent = null; // Reset list so that the next line gets a new list
MyContent.RefreshContentDetails(); // Update List for new value
}
_MyContent = null; // Reset list so that the next line gets a new list
if (MyContent != null) MyContent.RefreshContentDetails(); // Update List for new value
_ItemType = tmp.ItemType;
_Text = tmp.Text;
_Config = tmp.Config;
@@ -220,9 +237,11 @@ namespace VEPROMS.CSLA.Library
}
public static void Refresh(ContentDetail tmp)
{
DetailInfo tmpInfo = GetExistingByPrimaryKey(tmp.DetailID);
if (tmpInfo == null) return;
tmpInfo.RefreshFields(tmp);
string key = tmp.DetailID.ToString();
ConvertListToDictionary();
if (_AllByPrimaryKey.ContainsKey(key))
foreach (DetailInfo tmpInfo in _AllByPrimaryKey[key])
tmpInfo.RefreshFields(tmp);
}
private void RefreshFields(ContentDetail tmp)
{
@@ -245,7 +264,7 @@ namespace VEPROMS.CSLA.Library
if (tmp == null)
{
tmp = DataPortal.Fetch<DetailInfo>(new PKCriteria(detailID));
_AllList.Add(tmp);
if (!_AllList.Contains(tmp)) _AllList.Add(tmp);
}
if (tmp.ErrorMessage == "No Record Found") tmp = null;
return tmp;
@@ -259,14 +278,15 @@ namespace VEPROMS.CSLA.Library
#region Data Access Portal
internal DetailInfo(SafeDataReader dr)
{
if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] DetailInfo.Constructor", GetHashCode());
_MyDetailInfoUnique = ++_DetailInfoUnique;
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DetailInfo.Constructor", GetHashCode());
try
{
ReadData(dr);
}
catch (Exception ex)
{
if(_MyLog.IsErrorEnabled)_MyLog.Error("DetailInfo.Constructor", ex);
if (_MyLog.IsErrorEnabled) _MyLog.Error("DetailInfo.Constructor", ex);
throw new DbCslaException("DetailInfo.Constructor", ex);
}
}
@@ -283,7 +303,7 @@ namespace VEPROMS.CSLA.Library
}
private void ReadData(SafeDataReader dr)
{
if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] DetailInfo.ReadData", GetHashCode());
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DetailInfo.ReadData", GetHashCode());
try
{
_DetailID = dr.GetInt32("DetailID");
@@ -296,14 +316,14 @@ namespace VEPROMS.CSLA.Library
}
catch (Exception ex)
{
if(_MyLog.IsErrorEnabled)_MyLog.Error("DetailInfo.ReadData", ex);
if (_MyLog.IsErrorEnabled) _MyLog.Error("DetailInfo.ReadData", ex);
_ErrorMessage = ex.Message;
throw new DbCslaException("DetailInfo.ReadData", ex);
}
}
private void DataPortal_Fetch(PKCriteria criteria)
{
if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] DetailInfo.DataPortal_Fetch", GetHashCode());
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DetailInfo.DataPortal_Fetch", GetHashCode());
try
{
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
@@ -331,7 +351,7 @@ namespace VEPROMS.CSLA.Library
}
catch (Exception ex)
{
if(_MyLog.IsErrorEnabled)_MyLog.Error("DetailInfo.DataPortal_Fetch", ex);
if (_MyLog.IsErrorEnabled) _MyLog.Error("DetailInfo.DataPortal_Fetch", ex);
_ErrorMessage = ex.Message;
throw new DbCslaException("DetailInfo.DataPortal_Fetch", ex);
}
@@ -341,7 +361,7 @@ namespace VEPROMS.CSLA.Library
#region extension
DetailInfoExtension _DetailInfoExtension = new DetailInfoExtension();
[Serializable()]
partial class DetailInfoExtension : extensionBase {}
partial class DetailInfoExtension : extensionBase { }
[Serializable()]
class extensionBase
{