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

@@ -52,13 +52,17 @@ namespace VEPROMS.CSLA.Library
#endregion
#region Collection
protected static List<ZTransition> _AllList = new List<ZTransition>();
private static Dictionary<string, ZTransition> _AllByPrimaryKey = new Dictionary<string, ZTransition>();
private static Dictionary<string, List<ZTransition>> _AllByPrimaryKey = new Dictionary<string, List<ZTransition>>();
private static void ConvertListToDictionary()
{
List<ZTransition> remove = new List<ZTransition>();
foreach (ZTransition tmp in _AllList)
{
_AllByPrimaryKey[tmp.TransitionID.ToString()]=tmp; // Primary Key
if (!_AllByPrimaryKey.ContainsKey(tmp.TransitionID.ToString()))
{
_AllByPrimaryKey[tmp.TransitionID.ToString()] = new List<ZTransition>(); // Add new list for PrimaryKey
}
_AllByPrimaryKey[tmp.TransitionID.ToString()].Add(tmp); // Add to Primary Key list
remove.Add(tmp);
}
foreach (ZTransition tmp in remove)
@@ -68,7 +72,7 @@ namespace VEPROMS.CSLA.Library
{
ConvertListToDictionary();
string key = transitionID.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("TransitionID",true);
CanReadProperty("TransitionID", true);
if (_MyTransition != null) _TransitionID = _MyTransition.TransitionID;
return _TransitionID;
}
@@ -97,7 +101,7 @@ namespace VEPROMS.CSLA.Library
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty("MyTransition",true);
CanReadProperty("MyTransition", true);
if (_MyTransition == null && _TransitionID != 0) _MyTransition = Transition.Get(_TransitionID);
return _MyTransition;
}
@@ -108,13 +112,13 @@ namespace VEPROMS.CSLA.Library
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty("Oldto",true);
CanReadProperty("Oldto", true);
return _Oldto;
}
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
set
{
CanWriteProperty("Oldto",true);
CanWriteProperty("Oldto", true);
if (value == null) value = string.Empty;
if (_Oldto != value)
{
@@ -149,21 +153,22 @@ 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;
return hasBrokenRules;
}
finally
{
_CheckingBrokenRules=false;
_CheckingBrokenRules = false;
}
}
}
@@ -248,14 +253,25 @@ namespace VEPROMS.CSLA.Library
#region Factory Methods
public int CurrentEditLevel
{ get { return EditLevel; } }
private static int _ZTransitionUnique = 0;
private int _MyZTransitionUnique;
public int MyZTransitionUnique
{
get { return _MyZTransitionUnique; }
}
protected ZTransition()
{/* require use of factory methods */
_MyZTransitionUnique = ++_ZTransitionUnique;
_AllList.Add(this);
}
public void Dispose()
{
_AllList.Remove(this);
_AllByPrimaryKey.Remove(TransitionID.ToString());
if (!_AllByPrimaryKey.ContainsKey(TransitionID.ToString())) return;
List<ZTransition> listZTransition = _AllByPrimaryKey[TransitionID.ToString()]; // Get the list of items
listZTransition.Remove(this); // Remove the item from the list
if (listZTransition.Count == 0) //If there are no items left in the list
_AllByPrimaryKey.Remove(TransitionID.ToString()); // remove the list
}
public static ZTransition New()
{
@@ -311,7 +327,7 @@ namespace VEPROMS.CSLA.Library
if (tmp == null)
{
tmp = DataPortal.Fetch<ZTransition>(new PKCriteria(transitionID));
_AllList.Add(tmp);
if (!_AllList.Contains(tmp)) _AllList.Add(tmp);
}
if (tmp.ErrorMessage == "No Record Found") tmp = null;
return tmp;
@@ -389,7 +405,7 @@ namespace VEPROMS.CSLA.Library
}
private void ReadData(SafeDataReader dr)
{
if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] ZTransition.ReadData", GetHashCode());
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ZTransition.ReadData", GetHashCode());
try
{
_TransitionID = dr.GetInt32("TransitionID");
@@ -399,14 +415,14 @@ namespace VEPROMS.CSLA.Library
}
catch (Exception ex)
{
if(_MyLog.IsErrorEnabled)_MyLog.Error("ZTransition.ReadData", ex);
if (_MyLog.IsErrorEnabled) _MyLog.Error("ZTransition.ReadData", ex);
_ErrorMessage = ex.Message;
throw new DbCslaException("ZTransition.ReadData", ex);
}
}
private void DataPortal_Fetch(PKCriteria criteria)
{
if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] ZTransition.DataPortal_Fetch", GetHashCode());
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ZTransition.DataPortal_Fetch", GetHashCode());
try
{
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
@@ -434,7 +450,7 @@ namespace VEPROMS.CSLA.Library
}
catch (Exception ex)
{
if(_MyLog.IsErrorEnabled)_MyLog.Error("ZTransition.DataPortal_Fetch", ex);
if (_MyLog.IsErrorEnabled) _MyLog.Error("ZTransition.DataPortal_Fetch", ex);
_ErrorMessage = ex.Message;
throw new DbCslaException("ZTransition.DataPortal_Fetch", ex);
}
@@ -455,13 +471,13 @@ namespace VEPROMS.CSLA.Library
}
catch (Exception ex)
{
if(_MyLog.IsErrorEnabled)_MyLog.Error("ZTransition.DataPortal_Insert", ex);
if (_MyLog.IsErrorEnabled) _MyLog.Error("ZTransition.DataPortal_Insert", ex);
_ErrorMessage = ex.Message;
throw new DbCslaException("ZTransition.DataPortal_Insert", ex);
}
finally
{
if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] ZTransition.DataPortal_Insert", GetHashCode());
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ZTransition.DataPortal_Insert", GetHashCode());
}
}
[Transactional(TransactionalTypes.TransactionScope)]
@@ -489,11 +505,11 @@ namespace VEPROMS.CSLA.Library
}
MarkOld();
// update child objects
if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] ZTransition.SQLInsert", GetHashCode());
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ZTransition.SQLInsert", GetHashCode());
}
catch (Exception ex)
{
if(_MyLog.IsErrorEnabled)_MyLog.Error("ZTransition.SQLInsert", ex);
if (_MyLog.IsErrorEnabled) _MyLog.Error("ZTransition.SQLInsert", ex);
_ErrorMessage = ex.Message;
throw new DbCslaException("ZTransition.SQLInsert", ex);
}
@@ -501,7 +517,7 @@ namespace VEPROMS.CSLA.Library
[Transactional(TransactionalTypes.TransactionScope)]
public static byte[] Add(SqlConnection cn, Transition myTransition, string oldto)
{
if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] ZTransition.Add", 0);
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ZTransition.Add", 0);
try
{
using (SqlCommand cm = cn.CreateCommand())
@@ -523,7 +539,7 @@ namespace VEPROMS.CSLA.Library
}
catch (Exception ex)
{
if(_MyLog.IsErrorEnabled)_MyLog.Error("ZTransition.Add", ex);
if (_MyLog.IsErrorEnabled) _MyLog.Error("ZTransition.Add", ex);
throw new DbCslaException("ZTransition.Add", ex);
}
}
@@ -531,7 +547,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}] ZTransition.DataPortal_Update", GetHashCode());
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ZTransition.DataPortal_Update", GetHashCode());
try
{
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
@@ -545,7 +561,7 @@ namespace VEPROMS.CSLA.Library
}
catch (Exception ex)
{
if(_MyLog.IsErrorEnabled)_MyLog.Error("ZTransition.DataPortal_Update", ex);
if (_MyLog.IsErrorEnabled) _MyLog.Error("ZTransition.DataPortal_Update", ex);
_ErrorMessage = ex.Message;
if (!ex.Message.EndsWith("has been edited by another user.")) throw ex;
}
@@ -554,7 +570,7 @@ namespace VEPROMS.CSLA.Library
internal void SQLUpdate()
{
if (!IsDirty) return; // If not dirty - nothing to do
if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] ZTransition.SQLUpdate", GetHashCode());
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ZTransition.SQLUpdate", GetHashCode());
try
{
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
@@ -583,7 +599,7 @@ namespace VEPROMS.CSLA.Library
}
catch (Exception ex)
{
if(_MyLog.IsErrorEnabled)_MyLog.Error("ZTransition.SQLUpdate", ex);
if (_MyLog.IsErrorEnabled) _MyLog.Error("ZTransition.SQLUpdate", ex);
_ErrorMessage = ex.Message;
if (!ex.Message.EndsWith("has been edited by another user.")) throw ex;
}
@@ -593,18 +609,18 @@ namespace VEPROMS.CSLA.Library
if (!this.IsDirty) return;
if (base.IsDirty)
{
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
if (IsNew)
_LastChanged = ZTransition.Add(cn, transition, _Oldto);
else
_LastChanged = ZTransition.Update(cn, transition, _Oldto, ref _LastChanged);
MarkOld();
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
if (IsNew)
_LastChanged = ZTransition.Add(cn, transition, _Oldto);
else
_LastChanged = ZTransition.Update(cn, transition, _Oldto, ref _LastChanged);
MarkOld();
}
}
[Transactional(TransactionalTypes.TransactionScope)]
public static byte[] Update(SqlConnection cn, Transition myTransition, string oldto, ref byte[] lastChanged)
{
if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] ZTransition.Update", 0);
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ZTransition.Update", 0);
try
{
using (SqlCommand cm = cn.CreateCommand())
@@ -627,7 +643,7 @@ namespace VEPROMS.CSLA.Library
}
catch (Exception ex)
{
if(_MyLog.IsErrorEnabled)_MyLog.Error("ZTransition.Update", ex);
if (_MyLog.IsErrorEnabled) _MyLog.Error("ZTransition.Update", ex);
throw new DbCslaException("ZTransition.Update", ex);
}
}
@@ -639,7 +655,7 @@ namespace VEPROMS.CSLA.Library
[Transactional(TransactionalTypes.TransactionScope)]
private void DataPortal_Delete(PKCriteria criteria)
{
if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] ZTransition.DataPortal_Delete", GetHashCode());
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ZTransition.DataPortal_Delete", GetHashCode());
try
{
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
@@ -655,7 +671,7 @@ namespace VEPROMS.CSLA.Library
}
catch (Exception ex)
{
if(_MyLog.IsErrorEnabled)_MyLog.Error("ZTransition.DataPortal_Delete", ex);
if (_MyLog.IsErrorEnabled) _MyLog.Error("ZTransition.DataPortal_Delete", ex);
_ErrorMessage = ex.Message;
throw new DbCslaException("ZTransition.DataPortal_Delete", ex);
}
@@ -663,7 +679,7 @@ namespace VEPROMS.CSLA.Library
[Transactional(TransactionalTypes.TransactionScope)]
public static void Remove(SqlConnection cn, int transitionID)
{
if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] ZTransition.Remove", 0);
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ZTransition.Remove", 0);
try
{
using (SqlCommand cm = cn.CreateCommand())
@@ -678,7 +694,7 @@ namespace VEPROMS.CSLA.Library
}
catch (Exception ex)
{
if(_MyLog.IsErrorEnabled)_MyLog.Error("ZTransition.Remove", ex);
if (_MyLog.IsErrorEnabled) _MyLog.Error("ZTransition.Remove", ex);
throw new DbCslaException("ZTransition.Remove", ex);
}
}
@@ -712,7 +728,7 @@ namespace VEPROMS.CSLA.Library
}
protected override void DataPortal_Execute()
{
if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] ZTransition.DataPortal_Execute", GetHashCode());
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ZTransition.DataPortal_Execute", GetHashCode());
try
{
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
@@ -730,7 +746,7 @@ namespace VEPROMS.CSLA.Library
}
catch (Exception ex)
{
if(_MyLog.IsErrorEnabled)_MyLog.Error("ZTransition.DataPortal_Execute", ex);
if (_MyLog.IsErrorEnabled) _MyLog.Error("ZTransition.DataPortal_Execute", ex);
throw new DbCslaException("ZTransition.DataPortal_Execute", ex);
}
}