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 (Annotation tmp in _RefreshAnnotations)
{
AnnotationInfo.Refresh(tmp);
if(tmp._MyAnnotationType != null) AnnotationTypeInfo.Refresh(tmp._MyAnnotationType);
if(tmp._MyItem != null) ItemInfo.Refresh(tmp._MyItem);
if (tmp._MyAnnotationType != null) AnnotationTypeInfo.Refresh(tmp._MyAnnotationType);
if (tmp._MyItem != null) ItemInfo.Refresh(tmp._MyItem);
}
}
#endregion
#region Collection
protected static List<Annotation> _AllList = new List<Annotation>();
private static Dictionary<string, Annotation> _AllByPrimaryKey = new Dictionary<string, Annotation>();
private static Dictionary<string, List<Annotation>> _AllByPrimaryKey = new Dictionary<string, List<Annotation>>();
private static void ConvertListToDictionary()
{
List<Annotation> remove = new List<Annotation>();
foreach (Annotation tmp in _AllList)
{
_AllByPrimaryKey[tmp.AnnotationID.ToString()]=tmp; // Primary Key
if (!_AllByPrimaryKey.ContainsKey(tmp.AnnotationID.ToString()))
{
_AllByPrimaryKey[tmp.AnnotationID.ToString()] = new List<Annotation>(); // Add new list for PrimaryKey
}
_AllByPrimaryKey[tmp.AnnotationID.ToString()].Add(tmp); // Add to Primary Key list
remove.Add(tmp);
}
foreach (Annotation tmp in remove)
@@ -70,7 +74,7 @@ namespace VEPROMS.CSLA.Library
{
ConvertListToDictionary();
string key = annotationID.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("AnnotationID",true);
CanReadProperty("AnnotationID", true);
return _AnnotationID;
}
}
@@ -102,7 +106,7 @@ namespace VEPROMS.CSLA.Library
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty("ItemID",true);
CanReadProperty("ItemID", true);
if (_MyItem != null) _ItemID = _MyItem.ItemID;
return _ItemID;
}
@@ -113,14 +117,14 @@ namespace VEPROMS.CSLA.Library
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty("MyItem",true);
CanReadProperty("MyItem", true);
if (_MyItem == null && _ItemID != 0) _MyItem = Item.Get(_ItemID);
return _MyItem;
}
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
set
{
CanWriteProperty("MyItem",true);
CanWriteProperty("MyItem", true);
if (_MyItem != value)
{
_MyItem = value;
@@ -134,7 +138,7 @@ namespace VEPROMS.CSLA.Library
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty("TypeID",true);
CanReadProperty("TypeID", true);
if (_MyAnnotationType != null) _TypeID = _MyAnnotationType.TypeID;
return _TypeID;
}
@@ -145,14 +149,14 @@ namespace VEPROMS.CSLA.Library
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty("MyAnnotationType",true);
CanReadProperty("MyAnnotationType", true);
if (_MyAnnotationType == null && _TypeID != 0) _MyAnnotationType = AnnotationType.Get(_TypeID);
return _MyAnnotationType;
}
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
set
{
CanWriteProperty("MyAnnotationType",true);
CanWriteProperty("MyAnnotationType", true);
if (_MyAnnotationType != value)
{
_MyAnnotationType = value;
@@ -166,13 +170,13 @@ namespace VEPROMS.CSLA.Library
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty("RtfText",true);
CanReadProperty("RtfText", true);
return _RtfText;
}
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
set
{
CanWriteProperty("RtfText",true);
CanWriteProperty("RtfText", true);
if (value == null) value = string.Empty;
if (_RtfText != value)
{
@@ -187,13 +191,13 @@ namespace VEPROMS.CSLA.Library
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty("SearchText",true);
CanReadProperty("SearchText", true);
return _SearchText;
}
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
set
{
CanWriteProperty("SearchText",true);
CanWriteProperty("SearchText", true);
if (value == null) value = string.Empty;
if (_SearchText != value)
{
@@ -208,13 +212,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)
{
@@ -229,13 +233,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;
@@ -249,13 +253,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)
{
@@ -267,11 +271,11 @@ namespace VEPROMS.CSLA.Library
private byte[] _LastChanged = new byte[8];//timestamp
public override bool IsDirty
{
get { return base.IsDirty || (_MyAnnotationType == null? false : _MyAnnotationType.IsDirty) || (_MyItem == null? false : _MyItem.IsDirty); }
get { return base.IsDirty || (_MyAnnotationType == null ? false : _MyAnnotationType.IsDirty) || (_MyItem == null ? false : _MyItem.IsDirty); }
}
public override bool IsValid
{
get { return (IsNew && !IsDirty ? true : base.IsValid) && (_MyAnnotationType == null? true : _MyAnnotationType.IsValid) && (_MyItem == null? true : _MyItem.IsValid); }
get { return (IsNew && !IsDirty ? true : base.IsValid) && (_MyAnnotationType == null ? true : _MyAnnotationType.IsValid) && (_MyItem == null ? true : _MyItem.IsValid); }
}
// TODO: Replace base Annotation.ToString function as necessary
/// <summary>
@@ -294,23 +298,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 (_MyItem != null && (hasBrokenRules = _MyItem.HasBrokenRules) != null) return hasBrokenRules;
if (_MyAnnotationType != null && (hasBrokenRules = _MyAnnotationType.HasBrokenRules) != null) return hasBrokenRules;
if (_MyItem != null && (hasBrokenRules = _MyItem.HasBrokenRules) != null) return hasBrokenRules;
if (_MyAnnotationType != null && (hasBrokenRules = _MyAnnotationType.HasBrokenRules) != null) return hasBrokenRules;
return hasBrokenRules;
}
finally
{
_CheckingBrokenRules=false;
_CheckingBrokenRules = false;
}
}
}
@@ -436,14 +441,25 @@ namespace VEPROMS.CSLA.Library
#region Factory Methods
public int CurrentEditLevel
{ get { return EditLevel; } }
private static int _AnnotationUnique = 0;
private int _MyAnnotationUnique;
public int MyAnnotationUnique
{
get { return _MyAnnotationUnique; }
}
protected Annotation()
{/* require use of factory methods */
_MyAnnotationUnique = ++_AnnotationUnique;
_AllList.Add(this);
}
public void Dispose()
{
_AllList.Remove(this);
_AllByPrimaryKey.Remove(AnnotationID.ToString());
if (!_AllByPrimaryKey.ContainsKey(AnnotationID.ToString())) return;
List<Annotation> listAnnotation = _AllByPrimaryKey[AnnotationID.ToString()]; // Get the list of items
listAnnotation.Remove(this); // Remove the item from the list
if (listAnnotation.Count == 0) //If there are no items left in the list
_AllByPrimaryKey.Remove(AnnotationID.ToString()); // remove the list
}
public static Annotation New()
{
@@ -529,7 +545,7 @@ namespace VEPROMS.CSLA.Library
if (tmp == null)
{
tmp = DataPortal.Fetch<Annotation>(new PKCriteria(annotationID));
_AllList.Add(tmp);
if (!_AllList.Contains(tmp)) _AllList.Add(tmp);
}
if (tmp.ErrorMessage == "No Record Found") tmp = null;
return tmp;
@@ -608,7 +624,7 @@ namespace VEPROMS.CSLA.Library
}
private void ReadData(SafeDataReader dr)
{
if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] Annotation.ReadData", GetHashCode());
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Annotation.ReadData", GetHashCode());
try
{
_AnnotationID = dr.GetInt32("AnnotationID");
@@ -624,14 +640,14 @@ namespace VEPROMS.CSLA.Library
}
catch (Exception ex)
{
if(_MyLog.IsErrorEnabled)_MyLog.Error("Annotation.ReadData", ex);
if (_MyLog.IsErrorEnabled) _MyLog.Error("Annotation.ReadData", ex);
_ErrorMessage = ex.Message;
throw new DbCslaException("Annotation.ReadData", ex);
}
}
private void DataPortal_Fetch(PKCriteria criteria)
{
if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] Annotation.DataPortal_Fetch", GetHashCode());
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Annotation.DataPortal_Fetch", GetHashCode());
try
{
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
@@ -659,7 +675,7 @@ namespace VEPROMS.CSLA.Library
}
catch (Exception ex)
{
if(_MyLog.IsErrorEnabled)_MyLog.Error("Annotation.DataPortal_Fetch", ex);
if (_MyLog.IsErrorEnabled) _MyLog.Error("Annotation.DataPortal_Fetch", ex);
_ErrorMessage = ex.Message;
throw new DbCslaException("Annotation.DataPortal_Fetch", ex);
}
@@ -680,13 +696,13 @@ namespace VEPROMS.CSLA.Library
}
catch (Exception ex)
{
if(_MyLog.IsErrorEnabled)_MyLog.Error("Annotation.DataPortal_Insert", ex);
if (_MyLog.IsErrorEnabled) _MyLog.Error("Annotation.DataPortal_Insert", ex);
_ErrorMessage = ex.Message;
throw new DbCslaException("Annotation.DataPortal_Insert", ex);
}
finally
{
if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] Annotation.DataPortal_Insert", GetHashCode());
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Annotation.DataPortal_Insert", GetHashCode());
}
}
[Transactional(TransactionalTypes.TransactionScope)]
@@ -695,8 +711,8 @@ namespace VEPROMS.CSLA.Library
if (!this.IsDirty) return;
try
{
if(_MyAnnotationType != null) _MyAnnotationType.Update();
if(_MyItem != null) _MyItem.Update();
if (_MyAnnotationType != null) _MyAnnotationType.Update();
if (_MyItem != null) _MyItem.Update();
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
using (SqlCommand cm = cn.CreateCommand())
{
@@ -725,11 +741,11 @@ namespace VEPROMS.CSLA.Library
}
MarkOld();
// update child objects
if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] Annotation.SQLInsert", GetHashCode());
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Annotation.SQLInsert", GetHashCode());
}
catch (Exception ex)
{
if(_MyLog.IsErrorEnabled)_MyLog.Error("Annotation.SQLInsert", ex);
if (_MyLog.IsErrorEnabled) _MyLog.Error("Annotation.SQLInsert", ex);
_ErrorMessage = ex.Message;
throw new DbCslaException("Annotation.SQLInsert", ex);
}
@@ -737,7 +753,7 @@ namespace VEPROMS.CSLA.Library
[Transactional(TransactionalTypes.TransactionScope)]
public static byte[] Add(SqlConnection cn, ref int annotationID, Item myItem, AnnotationType myAnnotationType, string rtfText, string searchText, string config, DateTime dts, string userID)
{
if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] Annotation.Add", 0);
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Annotation.Add", 0);
try
{
using (SqlCommand cm = cn.CreateCommand())
@@ -768,7 +784,7 @@ namespace VEPROMS.CSLA.Library
}
catch (Exception ex)
{
if(_MyLog.IsErrorEnabled)_MyLog.Error("Annotation.Add", ex);
if (_MyLog.IsErrorEnabled) _MyLog.Error("Annotation.Add", ex);
throw new DbCslaException("Annotation.Add", ex);
}
}
@@ -776,7 +792,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}] Annotation.DataPortal_Update", GetHashCode());
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Annotation.DataPortal_Update", GetHashCode());
try
{
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
@@ -790,7 +806,7 @@ namespace VEPROMS.CSLA.Library
}
catch (Exception ex)
{
if(_MyLog.IsErrorEnabled)_MyLog.Error("Annotation.DataPortal_Update", ex);
if (_MyLog.IsErrorEnabled) _MyLog.Error("Annotation.DataPortal_Update", ex);
_ErrorMessage = ex.Message;
if (!ex.Message.EndsWith("has been edited by another user.")) throw ex;
}
@@ -799,11 +815,11 @@ namespace VEPROMS.CSLA.Library
internal void SQLUpdate()
{
if (!IsDirty) return; // If not dirty - nothing to do
if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] Annotation.SQLUpdate", GetHashCode());
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Annotation.SQLUpdate", GetHashCode());
try
{
if(_MyAnnotationType != null) _MyAnnotationType.Update();
if(_MyItem != null) _MyItem.Update();
if (_MyAnnotationType != null) _MyAnnotationType.Update();
if (_MyItem != null) _MyItem.Update();
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
if (base.IsDirty)
{
@@ -836,7 +852,7 @@ namespace VEPROMS.CSLA.Library
}
catch (Exception ex)
{
if(_MyLog.IsErrorEnabled)_MyLog.Error("Annotation.SQLUpdate", ex);
if (_MyLog.IsErrorEnabled) _MyLog.Error("Annotation.SQLUpdate", ex);
_ErrorMessage = ex.Message;
if (!ex.Message.EndsWith("has been edited by another user.")) throw ex;
}
@@ -857,7 +873,7 @@ namespace VEPROMS.CSLA.Library
[Transactional(TransactionalTypes.TransactionScope)]
public static byte[] Update(SqlConnection cn, ref int annotationID, Item myItem, AnnotationType myAnnotationType, string rtfText, string searchText, string config, DateTime dts, string userID, ref byte[] lastChanged)
{
if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] Annotation.Update", 0);
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Annotation.Update", 0);
try
{
using (SqlCommand cm = cn.CreateCommand())
@@ -886,7 +902,7 @@ namespace VEPROMS.CSLA.Library
}
catch (Exception ex)
{
if(_MyLog.IsErrorEnabled)_MyLog.Error("Annotation.Update", ex);
if (_MyLog.IsErrorEnabled) _MyLog.Error("Annotation.Update", ex);
throw new DbCslaException("Annotation.Update", ex);
}
}
@@ -898,7 +914,7 @@ namespace VEPROMS.CSLA.Library
[Transactional(TransactionalTypes.TransactionScope)]
private void DataPortal_Delete(PKCriteria criteria)
{
if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] Annotation.DataPortal_Delete", GetHashCode());
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Annotation.DataPortal_Delete", GetHashCode());
try
{
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
@@ -914,7 +930,7 @@ namespace VEPROMS.CSLA.Library
}
catch (Exception ex)
{
if(_MyLog.IsErrorEnabled)_MyLog.Error("Annotation.DataPortal_Delete", ex);
if (_MyLog.IsErrorEnabled) _MyLog.Error("Annotation.DataPortal_Delete", ex);
_ErrorMessage = ex.Message;
throw new DbCslaException("Annotation.DataPortal_Delete", ex);
}
@@ -922,7 +938,7 @@ namespace VEPROMS.CSLA.Library
[Transactional(TransactionalTypes.TransactionScope)]
public static void Remove(SqlConnection cn, int annotationID)
{
if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] Annotation.Remove", 0);
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Annotation.Remove", 0);
try
{
using (SqlCommand cm = cn.CreateCommand())
@@ -937,7 +953,7 @@ namespace VEPROMS.CSLA.Library
}
catch (Exception ex)
{
if(_MyLog.IsErrorEnabled)_MyLog.Error("Annotation.Remove", ex);
if (_MyLog.IsErrorEnabled) _MyLog.Error("Annotation.Remove", ex);
throw new DbCslaException("Annotation.Remove", ex);
}
}
@@ -971,7 +987,7 @@ namespace VEPROMS.CSLA.Library
}
protected override void DataPortal_Execute()
{
if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] Annotation.DataPortal_Execute", GetHashCode());
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Annotation.DataPortal_Execute", GetHashCode());
try
{
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
@@ -989,7 +1005,7 @@ namespace VEPROMS.CSLA.Library
}
catch (Exception ex)
{
if(_MyLog.IsErrorEnabled)_MyLog.Error("Annotation.DataPortal_Execute", ex);
if (_MyLog.IsErrorEnabled) _MyLog.Error("Annotation.DataPortal_Execute", ex);
throw new DbCslaException("Annotation.DataPortal_Execute", ex);
}
}