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

@@ -41,7 +41,7 @@ namespace VEPROMS.CSLA.Library
{
foreach (DocumentEntry tmp in _DocumentEntries)
{
if(tmp.IsDirty)refreshDocumentEntries.Add(tmp);
if (tmp.IsDirty) refreshDocumentEntries.Add(tmp);
}
}
}
@@ -65,13 +65,17 @@ namespace VEPROMS.CSLA.Library
#endregion
#region Collection
protected static List<Document> _AllList = new List<Document>();
private static Dictionary<string, Document> _AllByPrimaryKey = new Dictionary<string, Document>();
private static Dictionary<string, List<Document>> _AllByPrimaryKey = new Dictionary<string, List<Document>>();
private static void ConvertListToDictionary()
{
List<Document> remove = new List<Document>();
foreach (Document tmp in _AllList)
{
_AllByPrimaryKey[tmp.DocID.ToString()]=tmp; // Primary Key
if (!_AllByPrimaryKey.ContainsKey(tmp.DocID.ToString()))
{
_AllByPrimaryKey[tmp.DocID.ToString()] = new List<Document>(); // Add new list for PrimaryKey
}
_AllByPrimaryKey[tmp.DocID.ToString()].Add(tmp); // Add to Primary Key list
remove.Add(tmp);
}
foreach (Document tmp in remove)
@@ -81,7 +85,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
@@ -103,7 +107,7 @@ namespace VEPROMS.CSLA.Library
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty("DocID",true);
CanReadProperty("DocID", true);
return _DocID;
}
}
@@ -113,13 +117,13 @@ namespace VEPROMS.CSLA.Library
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty("LibTitle",true);
CanReadProperty("LibTitle", true);
return _LibTitle;
}
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
set
{
CanWriteProperty("LibTitle",true);
CanWriteProperty("LibTitle", true);
if (value == null) value = string.Empty;
if (_LibTitle != value)
{
@@ -137,13 +141,13 @@ namespace VEPROMS.CSLA.Library
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty("DocContent",true);
CanReadProperty("DocContent", true);
return _DocContent;
}
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
set
{
CanWriteProperty("DocContent",true);
CanWriteProperty("DocContent", true);
if (_DocContent != value)
{
_DocContent = value;
@@ -160,13 +164,13 @@ namespace VEPROMS.CSLA.Library
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty("DocAscii",true);
CanReadProperty("DocAscii", true);
return _DocAscii;
}
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
set
{
CanWriteProperty("DocAscii",true);
CanWriteProperty("DocAscii", true);
if (value == null) value = string.Empty;
if (_DocAscii != value)
{
@@ -181,13 +185,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)
{
@@ -202,13 +206,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;
@@ -222,13 +226,13 @@ namespace VEPROMS.CSLA.Library
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty("UserID",true);
CanReadProperty("UserID", true);
return _UserID;
}
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
set
{
CanWriteProperty("UserID",true);
CanWriteProperty("UserID", true);
if (value == null) value = string.Empty;
if (_UserID != value)
{
@@ -247,7 +251,7 @@ namespace VEPROMS.CSLA.Library
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty("DocumentEntryCount",true);
CanReadProperty("DocumentEntryCount", true);
return _DocumentEntryCount;
}
}
@@ -261,21 +265,21 @@ namespace VEPROMS.CSLA.Library
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty("DocumentEntries",true);
if(_DocumentEntryCount > 0 && _DocumentEntries == null)
CanReadProperty("DocumentEntries", true);
if (_DocumentEntryCount > 0 && _DocumentEntries == null)
_DocumentEntries = DocumentEntries.GetByDocID(DocID);
else if(_DocumentEntries == null)
else if (_DocumentEntries == null)
_DocumentEntries = DocumentEntries.New();
return _DocumentEntries;
}
}
public override bool IsDirty
{
get { return base.IsDirty || (_DocumentEntries == null? false : _DocumentEntries.IsDirty); }
get { return base.IsDirty || (_DocumentEntries == null ? false : _DocumentEntries.IsDirty); }
}
public override bool IsValid
{
get { return (IsNew && !IsDirty ? true : base.IsValid) && (_DocumentEntries == null? true : _DocumentEntries.IsValid); }
get { return (IsNew && !IsDirty ? true : base.IsValid) && (_DocumentEntries == null ? true : _DocumentEntries.IsValid); }
}
// TODO: Replace base Document.ToString function as necessary
/// <summary>
@@ -298,22 +302,23 @@ 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 (_DocumentEntries != null && (hasBrokenRules = _DocumentEntries.HasBrokenRules) != null) return hasBrokenRules;
if (_DocumentEntries != null && (hasBrokenRules = _DocumentEntries.HasBrokenRules) != null) return hasBrokenRules;
return hasBrokenRules;
}
finally
{
_CheckingBrokenRules=false;
_CheckingBrokenRules = false;
}
}
}
@@ -430,14 +435,25 @@ namespace VEPROMS.CSLA.Library
#region Factory Methods
public int CurrentEditLevel
{ get { return EditLevel; } }
private static int _DocumentUnique = 0;
private int _MyDocumentUnique;
public int MyDocumentUnique
{
get { return _MyDocumentUnique; }
}
protected Document()
{/* require use of factory methods */
_MyDocumentUnique = ++_DocumentUnique;
_AllList.Add(this);
}
public void Dispose()
{
_AllList.Remove(this);
_AllByPrimaryKey.Remove(DocID.ToString());
if (!_AllByPrimaryKey.ContainsKey(DocID.ToString())) return;
List<Document> listDocument = _AllByPrimaryKey[DocID.ToString()]; // Get the list of items
listDocument.Remove(this); // Remove the item from the list
if (listDocument.Count == 0) //If there are no items left in the list
_AllByPrimaryKey.Remove(DocID.ToString()); // remove the list
}
public static Document New()
{
@@ -514,7 +530,7 @@ namespace VEPROMS.CSLA.Library
if (tmp == null)
{
tmp = DataPortal.Fetch<Document>(new PKCriteria(docID));
_AllList.Add(tmp);
if (!_AllList.Contains(tmp)) _AllList.Add(tmp);
}
if (tmp.ErrorMessage == "No Record Found") tmp = null;
return tmp;
@@ -593,7 +609,7 @@ namespace VEPROMS.CSLA.Library
}
private void ReadData(SafeDataReader dr)
{
if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] Document.ReadData", GetHashCode());
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Document.ReadData", GetHashCode());
try
{
_DocID = dr.GetInt32("DocID");
@@ -609,14 +625,14 @@ namespace VEPROMS.CSLA.Library
}
catch (Exception ex)
{
if(_MyLog.IsErrorEnabled)_MyLog.Error("Document.ReadData", ex);
if (_MyLog.IsErrorEnabled) _MyLog.Error("Document.ReadData", ex);
_ErrorMessage = ex.Message;
throw new DbCslaException("Document.ReadData", ex);
}
}
private void DataPortal_Fetch(PKCriteria criteria)
{
if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] Document.DataPortal_Fetch", GetHashCode());
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Document.DataPortal_Fetch", GetHashCode());
try
{
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
@@ -647,7 +663,7 @@ namespace VEPROMS.CSLA.Library
}
catch (Exception ex)
{
if(_MyLog.IsErrorEnabled)_MyLog.Error("Document.DataPortal_Fetch", ex);
if (_MyLog.IsErrorEnabled) _MyLog.Error("Document.DataPortal_Fetch", ex);
_ErrorMessage = ex.Message;
throw new DbCslaException("Document.DataPortal_Fetch", ex);
}
@@ -668,13 +684,13 @@ namespace VEPROMS.CSLA.Library
}
catch (Exception ex)
{
if(_MyLog.IsErrorEnabled)_MyLog.Error("Document.DataPortal_Insert", ex);
if (_MyLog.IsErrorEnabled) _MyLog.Error("Document.DataPortal_Insert", ex);
_ErrorMessage = ex.Message;
throw new DbCslaException("Document.DataPortal_Insert", ex);
}
finally
{
if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] Document.DataPortal_Insert", GetHashCode());
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Document.DataPortal_Insert", GetHashCode());
}
}
[Transactional(TransactionalTypes.TransactionScope)]
@@ -711,11 +727,11 @@ namespace VEPROMS.CSLA.Library
MarkOld();
// update child objects
if (_DocumentEntries != null) _DocumentEntries.Update(this);
if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] Document.SQLInsert", GetHashCode());
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Document.SQLInsert", GetHashCode());
}
catch (Exception ex)
{
if(_MyLog.IsErrorEnabled)_MyLog.Error("Document.SQLInsert", ex);
if (_MyLog.IsErrorEnabled) _MyLog.Error("Document.SQLInsert", ex);
_ErrorMessage = ex.Message;
throw new DbCslaException("Document.SQLInsert", ex);
}
@@ -723,7 +739,7 @@ namespace VEPROMS.CSLA.Library
[Transactional(TransactionalTypes.TransactionScope)]
public static byte[] Add(SqlConnection cn, ref int docID, string libTitle, byte[] docContent, string docAscii, string config, DateTime dts, string userID)
{
if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] Document.Add", 0);
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Document.Add", 0);
try
{
using (SqlCommand cm = cn.CreateCommand())
@@ -753,7 +769,7 @@ namespace VEPROMS.CSLA.Library
}
catch (Exception ex)
{
if(_MyLog.IsErrorEnabled)_MyLog.Error("Document.Add", ex);
if (_MyLog.IsErrorEnabled) _MyLog.Error("Document.Add", ex);
throw new DbCslaException("Document.Add", ex);
}
}
@@ -761,7 +777,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}] Document.DataPortal_Update", GetHashCode());
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Document.DataPortal_Update", GetHashCode());
try
{
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
@@ -775,7 +791,7 @@ namespace VEPROMS.CSLA.Library
}
catch (Exception ex)
{
if(_MyLog.IsErrorEnabled)_MyLog.Error("Document.DataPortal_Update", ex);
if (_MyLog.IsErrorEnabled) _MyLog.Error("Document.DataPortal_Update", ex);
_ErrorMessage = ex.Message;
if (!ex.Message.EndsWith("has been edited by another user.")) throw ex;
}
@@ -784,7 +800,7 @@ namespace VEPROMS.CSLA.Library
internal void SQLUpdate()
{
if (!IsDirty) return; // If not dirty - nothing to do
if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] Document.SQLUpdate", GetHashCode());
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Document.SQLUpdate", GetHashCode());
try
{
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
@@ -819,7 +835,7 @@ namespace VEPROMS.CSLA.Library
}
catch (Exception ex)
{
if(_MyLog.IsErrorEnabled)_MyLog.Error("Document.SQLUpdate", ex);
if (_MyLog.IsErrorEnabled) _MyLog.Error("Document.SQLUpdate", ex);
_ErrorMessage = ex.Message;
if (!ex.Message.EndsWith("has been edited by another user.")) throw ex;
}
@@ -841,7 +857,7 @@ namespace VEPROMS.CSLA.Library
[Transactional(TransactionalTypes.TransactionScope)]
public static byte[] Update(SqlConnection cn, ref int docID, string libTitle, byte[] docContent, string docAscii, string config, DateTime dts, string userID, ref byte[] lastChanged)
{
if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] Document.Update", 0);
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Document.Update", 0);
try
{
using (SqlCommand cm = cn.CreateCommand())
@@ -869,7 +885,7 @@ namespace VEPROMS.CSLA.Library
}
catch (Exception ex)
{
if(_MyLog.IsErrorEnabled)_MyLog.Error("Document.Update", ex);
if (_MyLog.IsErrorEnabled) _MyLog.Error("Document.Update", ex);
throw new DbCslaException("Document.Update", ex);
}
}
@@ -881,7 +897,7 @@ namespace VEPROMS.CSLA.Library
[Transactional(TransactionalTypes.TransactionScope)]
private void DataPortal_Delete(PKCriteria criteria)
{
if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] Document.DataPortal_Delete", GetHashCode());
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Document.DataPortal_Delete", GetHashCode());
try
{
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
@@ -897,7 +913,7 @@ namespace VEPROMS.CSLA.Library
}
catch (Exception ex)
{
if(_MyLog.IsErrorEnabled)_MyLog.Error("Document.DataPortal_Delete", ex);
if (_MyLog.IsErrorEnabled) _MyLog.Error("Document.DataPortal_Delete", ex);
_ErrorMessage = ex.Message;
throw new DbCslaException("Document.DataPortal_Delete", ex);
}
@@ -905,7 +921,7 @@ namespace VEPROMS.CSLA.Library
[Transactional(TransactionalTypes.TransactionScope)]
public static void Remove(SqlConnection cn, int docID)
{
if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] Document.Remove", 0);
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Document.Remove", 0);
try
{
using (SqlCommand cm = cn.CreateCommand())
@@ -920,7 +936,7 @@ namespace VEPROMS.CSLA.Library
}
catch (Exception ex)
{
if(_MyLog.IsErrorEnabled)_MyLog.Error("Document.Remove", ex);
if (_MyLog.IsErrorEnabled) _MyLog.Error("Document.Remove", ex);
throw new DbCslaException("Document.Remove", ex);
}
}
@@ -954,7 +970,7 @@ namespace VEPROMS.CSLA.Library
}
protected override void DataPortal_Execute()
{
if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] Document.DataPortal_Execute", GetHashCode());
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Document.DataPortal_Execute", GetHashCode());
try
{
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
@@ -972,7 +988,7 @@ namespace VEPROMS.CSLA.Library
}
catch (Exception ex)
{
if(_MyLog.IsErrorEnabled)_MyLog.Error("Document.DataPortal_Execute", ex);
if (_MyLog.IsErrorEnabled) _MyLog.Error("Document.DataPortal_Execute", ex);
throw new DbCslaException("Document.DataPortal_Execute", ex);
}
}