This commit is contained in:
@@ -37,13 +37,17 @@ namespace VEPROMS.CSLA.Library
|
||||
#endregion
|
||||
#region Collection
|
||||
protected static List<DocumentInfo> _AllList = new List<DocumentInfo>();
|
||||
private static Dictionary<string, DocumentInfo> _AllByPrimaryKey = new Dictionary<string, DocumentInfo>();
|
||||
private static Dictionary<string, List<DocumentInfo>> _AllByPrimaryKey = new Dictionary<string, List<DocumentInfo>>();
|
||||
private static void ConvertListToDictionary()
|
||||
{
|
||||
List<DocumentInfo> remove = new List<DocumentInfo>();
|
||||
foreach (DocumentInfo tmp in _AllList)
|
||||
{
|
||||
_AllByPrimaryKey[tmp.DocID.ToString()]=tmp; // Primary Key
|
||||
if (!_AllByPrimaryKey.ContainsKey(tmp.DocID.ToString()))
|
||||
{
|
||||
_AllByPrimaryKey[tmp.DocID.ToString()] = new List<DocumentInfo>(); // Add new list for PrimaryKey
|
||||
}
|
||||
_AllByPrimaryKey[tmp.DocID.ToString()].Add(tmp); // Add to Primary Key list
|
||||
remove.Add(tmp);
|
||||
}
|
||||
foreach (DocumentInfo tmp in remove)
|
||||
@@ -57,7 +61,7 @@ namespace VEPROMS.CSLA.Library
|
||||
{
|
||||
ConvertListToDictionary();
|
||||
string key = docID.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("DocID",true);
|
||||
CanReadProperty("DocID", true);
|
||||
return _DocID;
|
||||
}
|
||||
}
|
||||
@@ -95,7 +99,7 @@ namespace VEPROMS.CSLA.Library
|
||||
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
||||
get
|
||||
{
|
||||
CanReadProperty("LibTitle",true);
|
||||
CanReadProperty("LibTitle", true);
|
||||
return _LibTitle;
|
||||
}
|
||||
}
|
||||
@@ -108,7 +112,7 @@ namespace VEPROMS.CSLA.Library
|
||||
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
||||
get
|
||||
{
|
||||
CanReadProperty("DocContent",true);
|
||||
CanReadProperty("DocContent", true);
|
||||
return _DocContent;
|
||||
}
|
||||
}
|
||||
@@ -121,7 +125,7 @@ namespace VEPROMS.CSLA.Library
|
||||
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
||||
get
|
||||
{
|
||||
CanReadProperty("DocAscii",true);
|
||||
CanReadProperty("DocAscii", true);
|
||||
return _DocAscii;
|
||||
}
|
||||
}
|
||||
@@ -131,7 +135,7 @@ namespace VEPROMS.CSLA.Library
|
||||
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
||||
get
|
||||
{
|
||||
CanReadProperty("Config",true);
|
||||
CanReadProperty("Config", true);
|
||||
return _Config;
|
||||
}
|
||||
}
|
||||
@@ -141,7 +145,7 @@ namespace VEPROMS.CSLA.Library
|
||||
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
||||
get
|
||||
{
|
||||
CanReadProperty("DTS",true);
|
||||
CanReadProperty("DTS", true);
|
||||
return _DTS;
|
||||
}
|
||||
}
|
||||
@@ -151,7 +155,7 @@ namespace VEPROMS.CSLA.Library
|
||||
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
||||
get
|
||||
{
|
||||
CanReadProperty("UserID",true);
|
||||
CanReadProperty("UserID", true);
|
||||
return _UserID;
|
||||
}
|
||||
}
|
||||
@@ -164,7 +168,7 @@ namespace VEPROMS.CSLA.Library
|
||||
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
||||
get
|
||||
{
|
||||
CanReadProperty("DocumentEntryCount",true);
|
||||
CanReadProperty("DocumentEntryCount", true);
|
||||
return _DocumentEntryCount;
|
||||
}
|
||||
}
|
||||
@@ -175,7 +179,7 @@ namespace VEPROMS.CSLA.Library
|
||||
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
||||
get
|
||||
{
|
||||
CanReadProperty("DocumentEntries",true);
|
||||
CanReadProperty("DocumentEntries", true);
|
||||
if (_DocumentEntryCount < 0 || (_DocumentEntryCount > 0 && _DocumentEntries == null))
|
||||
_DocumentEntries = EntryInfoList.GetByDocID(_DocID);
|
||||
if (_DocumentEntryCount < 0)
|
||||
@@ -185,7 +189,10 @@ namespace VEPROMS.CSLA.Library
|
||||
}
|
||||
internal void RefreshDocumentEntries()
|
||||
{
|
||||
_DocumentEntryCount = -1; // This will cause the data to be requeried
|
||||
ConvertListToDictionary();
|
||||
if (_AllByPrimaryKey.ContainsKey(_DocID.ToString()))
|
||||
foreach (DocumentInfo tmp in _AllByPrimaryKey[_DocID.ToString()])
|
||||
tmp._DocumentEntryCount = -1; // This will cause the data to be requeried
|
||||
}
|
||||
// TODO: Replace base DocumentInfo.ToString function as necessary
|
||||
/// <summary>
|
||||
@@ -207,14 +214,25 @@ namespace VEPROMS.CSLA.Library
|
||||
}
|
||||
#endregion
|
||||
#region Factory Methods
|
||||
private static int _DocumentInfoUnique = 0;
|
||||
private int _MyDocumentInfoUnique;
|
||||
public int MyDocumentInfoUnique
|
||||
{
|
||||
get { return _MyDocumentInfoUnique; }
|
||||
}
|
||||
private DocumentInfo()
|
||||
{/* require use of factory methods */
|
||||
_MyDocumentInfoUnique = ++_DocumentInfoUnique;
|
||||
_AllList.Add(this);
|
||||
}
|
||||
public void Dispose()
|
||||
{
|
||||
_AllList.Remove(this);
|
||||
_AllByPrimaryKey.Remove(DocID.ToString());
|
||||
if (!_AllByPrimaryKey.ContainsKey(DocID.ToString())) return;
|
||||
List<DocumentInfo> listDocumentInfo = _AllByPrimaryKey[DocID.ToString()]; // Get the list of items
|
||||
listDocumentInfo.Remove(this); // Remove the item from the list
|
||||
if (listDocumentInfo.Count == 0) // If there are no items left in the list
|
||||
_AllByPrimaryKey.Remove(DocID.ToString()); // remove the list
|
||||
}
|
||||
public virtual Document Get()
|
||||
{
|
||||
@@ -222,9 +240,11 @@ namespace VEPROMS.CSLA.Library
|
||||
}
|
||||
public static void Refresh(Document tmp)
|
||||
{
|
||||
DocumentInfo tmpInfo = GetExistingByPrimaryKey(tmp.DocID);
|
||||
if (tmpInfo == null) return;
|
||||
tmpInfo.RefreshFields(tmp);
|
||||
string key = tmp.DocID.ToString();
|
||||
ConvertListToDictionary();
|
||||
if (_AllByPrimaryKey.ContainsKey(key))
|
||||
foreach (DocumentInfo tmpInfo in _AllByPrimaryKey[key])
|
||||
tmpInfo.RefreshFields(tmp);
|
||||
}
|
||||
private void RefreshFields(Document tmp)
|
||||
{
|
||||
@@ -247,7 +267,7 @@ namespace VEPROMS.CSLA.Library
|
||||
if (tmp == null)
|
||||
{
|
||||
tmp = DataPortal.Fetch<DocumentInfo>(new PKCriteria(docID));
|
||||
_AllList.Add(tmp);
|
||||
if (!_AllList.Contains(tmp)) _AllList.Add(tmp);
|
||||
}
|
||||
if (tmp.ErrorMessage == "No Record Found") tmp = null;
|
||||
return tmp;
|
||||
@@ -261,14 +281,15 @@ namespace VEPROMS.CSLA.Library
|
||||
#region Data Access Portal
|
||||
internal DocumentInfo(SafeDataReader dr)
|
||||
{
|
||||
if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] DocumentInfo.Constructor", GetHashCode());
|
||||
_MyDocumentInfoUnique = ++_DocumentInfoUnique;
|
||||
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocumentInfo.Constructor", GetHashCode());
|
||||
try
|
||||
{
|
||||
ReadData(dr);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if(_MyLog.IsErrorEnabled)_MyLog.Error("DocumentInfo.Constructor", ex);
|
||||
if (_MyLog.IsErrorEnabled) _MyLog.Error("DocumentInfo.Constructor", ex);
|
||||
throw new DbCslaException("DocumentInfo.Constructor", ex);
|
||||
}
|
||||
}
|
||||
@@ -285,7 +306,7 @@ namespace VEPROMS.CSLA.Library
|
||||
}
|
||||
private void ReadData(SafeDataReader dr)
|
||||
{
|
||||
if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] DocumentInfo.ReadData", GetHashCode());
|
||||
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocumentInfo.ReadData", GetHashCode());
|
||||
try
|
||||
{
|
||||
_DocID = dr.GetInt32("DocID");
|
||||
@@ -299,14 +320,14 @@ namespace VEPROMS.CSLA.Library
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if(_MyLog.IsErrorEnabled)_MyLog.Error("DocumentInfo.ReadData", ex);
|
||||
if (_MyLog.IsErrorEnabled) _MyLog.Error("DocumentInfo.ReadData", ex);
|
||||
_ErrorMessage = ex.Message;
|
||||
throw new DbCslaException("DocumentInfo.ReadData", ex);
|
||||
}
|
||||
}
|
||||
private void DataPortal_Fetch(PKCriteria criteria)
|
||||
{
|
||||
if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] DocumentInfo.DataPortal_Fetch", GetHashCode());
|
||||
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocumentInfo.DataPortal_Fetch", GetHashCode());
|
||||
try
|
||||
{
|
||||
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
|
||||
@@ -334,7 +355,7 @@ namespace VEPROMS.CSLA.Library
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if(_MyLog.IsErrorEnabled)_MyLog.Error("DocumentInfo.DataPortal_Fetch", ex);
|
||||
if (_MyLog.IsErrorEnabled) _MyLog.Error("DocumentInfo.DataPortal_Fetch", ex);
|
||||
_ErrorMessage = ex.Message;
|
||||
throw new DbCslaException("DocumentInfo.DataPortal_Fetch", ex);
|
||||
}
|
||||
@@ -344,7 +365,7 @@ namespace VEPROMS.CSLA.Library
|
||||
#region extension
|
||||
DocumentInfoExtension _DocumentInfoExtension = new DocumentInfoExtension();
|
||||
[Serializable()]
|
||||
partial class DocumentInfoExtension : extensionBase {}
|
||||
partial class DocumentInfoExtension : extensionBase { }
|
||||
[Serializable()]
|
||||
class extensionBase
|
||||
{
|
||||
|
Reference in New Issue
Block a user