CSLA - R - Group 1
This commit is contained in:
@@ -13,8 +13,6 @@ using System.Data;
|
||||
using System.Data.SqlClient;
|
||||
using Csla;
|
||||
using Csla.Data;
|
||||
using System.Configuration;
|
||||
using System.IO;
|
||||
using System.ComponentModel;
|
||||
using System.Collections.Generic;
|
||||
using Csla.Validation;
|
||||
@@ -82,6 +80,7 @@ namespace VEPROMS.CSLA.Library
|
||||
}
|
||||
#endregion
|
||||
#region Collection
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
|
||||
private static List<Revision> _CacheList = new List<Revision>();
|
||||
protected static void AddToCache(Revision revision)
|
||||
{
|
||||
@@ -91,6 +90,7 @@ namespace VEPROMS.CSLA.Library
|
||||
{
|
||||
while (_CacheList.Contains(revision)) _CacheList.Remove(revision); // In RemoveFromCache
|
||||
}
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
|
||||
private static Dictionary<string, List<Revision>> _CacheByPrimaryKey = new Dictionary<string, List<Revision>>();
|
||||
private static void ConvertListToDictionary()
|
||||
{
|
||||
@@ -116,15 +116,9 @@ namespace VEPROMS.CSLA.Library
|
||||
#endregion
|
||||
#region Business Methods
|
||||
private string _ErrorMessage = string.Empty;
|
||||
public string ErrorMessage
|
||||
{
|
||||
get { return _ErrorMessage; }
|
||||
}
|
||||
public string ErrorMessage => _ErrorMessage;
|
||||
private static int _nextRevisionID = -1;
|
||||
public static int NextRevisionID
|
||||
{
|
||||
get { return _nextRevisionID--; }
|
||||
}
|
||||
public static int NextRevisionID => _nextRevisionID--;
|
||||
private int _RevisionID;
|
||||
[System.ComponentModel.DataObjectField(true, true)]
|
||||
public int RevisionID
|
||||
@@ -315,10 +309,7 @@ namespace VEPROMS.CSLA.Library
|
||||
return _RevisionChecks;
|
||||
}
|
||||
}
|
||||
public void Reset_RevisionChecks()
|
||||
{
|
||||
_RevisionCheckCount = -1;
|
||||
}
|
||||
public void Reset_RevisionChecks() => _RevisionCheckCount = -1;
|
||||
private int _RevisionVersionCount = 0;
|
||||
/// <summary>
|
||||
/// Count of RevisionVersions for this Revision
|
||||
@@ -350,10 +341,7 @@ namespace VEPROMS.CSLA.Library
|
||||
return _RevisionVersions;
|
||||
}
|
||||
}
|
||||
public void Reset_RevisionVersions()
|
||||
{
|
||||
_RevisionVersionCount = -1;
|
||||
}
|
||||
public void Reset_RevisionVersions() => _RevisionVersionCount = -1;
|
||||
public override bool IsDirty
|
||||
{
|
||||
get
|
||||
@@ -368,37 +356,22 @@ namespace VEPROMS.CSLA.Library
|
||||
if (base.IsDirty || list.Contains(this))
|
||||
return base.IsDirty;
|
||||
list.Add(this);
|
||||
return base.IsDirty || (_RevisionChecks == null ? false : _RevisionChecks.IsDirtyList(list)) || (_RevisionVersions == null ? false : _RevisionVersions.IsDirtyList(list));
|
||||
}
|
||||
public override bool IsValid
|
||||
{
|
||||
get { return IsValidList(new List<object>()); }
|
||||
return base.IsDirty || (_RevisionChecks != null && _RevisionChecks.IsDirtyList(list)) || (_RevisionVersions != null && _RevisionVersions.IsDirtyList(list));
|
||||
}
|
||||
public override bool IsValid => IsValidList(new List<object>());
|
||||
public bool IsValidList(List<object> list)
|
||||
{
|
||||
if (list.Contains(this))
|
||||
return (IsNew && !IsDirty) ? true : base.IsValid;
|
||||
return (IsNew && !IsDirty) || base.IsValid;
|
||||
list.Add(this);
|
||||
return ((IsNew && !IsDirty) ? true : base.IsValid) && (_RevisionChecks == null ? true : _RevisionChecks.IsValidList(list)) && (_RevisionVersions == null ? true : _RevisionVersions.IsValidList(list));
|
||||
return ((IsNew && !IsDirty) || base.IsValid) && (_RevisionChecks == null || _RevisionChecks.IsValidList(list)) && (_RevisionVersions == null || _RevisionVersions.IsValidList(list));
|
||||
}
|
||||
// CSLATODO: Replace base Revision.ToString function as necessary
|
||||
/// <summary>
|
||||
/// Overrides Base ToString
|
||||
/// </summary>
|
||||
/// <returns>A string representation of current Revision</returns>
|
||||
//public override string ToString()
|
||||
//{
|
||||
// return base.ToString();
|
||||
//}
|
||||
// CSLATODO: Check Revision.GetIdValue to assure that the ID returned is unique
|
||||
/// <summary>
|
||||
/// Overrides Base GetIdValue - Used internally by CSLA to determine equality
|
||||
/// </summary>
|
||||
/// <returns>A Unique ID for the current Revision</returns>
|
||||
protected override object GetIdValue()
|
||||
{
|
||||
return MyRevisionUnique; // Absolutely Unique ID
|
||||
}
|
||||
protected override object GetIdValue() => MyRevisionUnique; // Absolutely Unique ID
|
||||
#endregion
|
||||
#region ValidationRules
|
||||
[NonSerialized]
|
||||
@@ -428,8 +401,8 @@ namespace VEPROMS.CSLA.Library
|
||||
get
|
||||
{
|
||||
IVEHasBrokenRules hasBrokenRules = HasBrokenRules;
|
||||
if (this.Equals(hasBrokenRules)) return BrokenRulesCollection;
|
||||
return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null);
|
||||
if (Equals(hasBrokenRules)) return BrokenRulesCollection;
|
||||
return (hasBrokenRules?.BrokenRules);
|
||||
}
|
||||
}
|
||||
protected override void AddBusinessRules()
|
||||
@@ -457,39 +430,11 @@ namespace VEPROMS.CSLA.Library
|
||||
_RevisionExtension.AddInstanceValidationRules(ValidationRules);
|
||||
// CSLATODO: Add other validation rules
|
||||
}
|
||||
// Sample data comparison validation rule
|
||||
//private bool StartDateGTEndDate(object target, Csla.Validation.RuleArgs e)
|
||||
//{
|
||||
// if (_started > _ended)
|
||||
// {
|
||||
// e.Description = "Start date can't be after end date";
|
||||
// return false;
|
||||
// }
|
||||
// else
|
||||
// return true;
|
||||
//}
|
||||
#endregion
|
||||
#region Authorization Rules
|
||||
protected override void AddAuthorizationRules()
|
||||
{
|
||||
//CSLATODO: Who can read/write which fields
|
||||
//AuthorizationRules.AllowRead(RevisionID, "<Role(s)>");
|
||||
//AuthorizationRules.AllowRead(ItemID, "<Role(s)>");
|
||||
//AuthorizationRules.AllowRead(TypeID, "<Role(s)>");
|
||||
//AuthorizationRules.AllowRead(RevisionNumber, "<Role(s)>");
|
||||
//AuthorizationRules.AllowRead(RevisionDate, "<Role(s)>");
|
||||
//AuthorizationRules.AllowRead(Notes, "<Role(s)>");
|
||||
//AuthorizationRules.AllowRead(Config, "<Role(s)>");
|
||||
//AuthorizationRules.AllowRead(DTS, "<Role(s)>");
|
||||
//AuthorizationRules.AllowRead(UserID, "<Role(s)>");
|
||||
//AuthorizationRules.AllowWrite(ItemID, "<Role(s)>");
|
||||
//AuthorizationRules.AllowWrite(TypeID, "<Role(s)>");
|
||||
//AuthorizationRules.AllowWrite(RevisionNumber, "<Role(s)>");
|
||||
//AuthorizationRules.AllowWrite(RevisionDate, "<Role(s)>");
|
||||
//AuthorizationRules.AllowWrite(Notes, "<Role(s)>");
|
||||
//AuthorizationRules.AllowWrite(Config, "<Role(s)>");
|
||||
//AuthorizationRules.AllowWrite(DTS, "<Role(s)>");
|
||||
//AuthorizationRules.AllowWrite(UserID, "<Role(s)>");
|
||||
_RevisionExtension.AddAuthorizationRules(AuthorizationRules);
|
||||
}
|
||||
protected override void AddInstanceAuthorizationRules()
|
||||
@@ -497,56 +442,14 @@ namespace VEPROMS.CSLA.Library
|
||||
//CSLATODO: Who can read/write which fields
|
||||
_RevisionExtension.AddInstanceAuthorizationRules(AuthorizationRules);
|
||||
}
|
||||
public static bool CanAddObject()
|
||||
{
|
||||
// CSLATODO: Can Add Authorization
|
||||
//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
|
||||
return true;
|
||||
}
|
||||
public static bool CanGetObject()
|
||||
{
|
||||
// CSLATODO: CanGet Authorization
|
||||
return true;
|
||||
}
|
||||
public static bool CanDeleteObject()
|
||||
{
|
||||
// CSLATODO: CanDelete Authorization
|
||||
//bool result = false;
|
||||
//if (Csla.ApplicationContext.User.IsInRole("ProjectManager"))result = true;
|
||||
//if (Csla.ApplicationContext.User.IsInRole("Administrator"))result = true;
|
||||
//return result;
|
||||
return true;
|
||||
}
|
||||
/// <summary>
|
||||
/// determines if related records (Foreign Keys) will keep this Item from being deleted
|
||||
/// </summary>
|
||||
public bool CanDelete
|
||||
{
|
||||
get
|
||||
{
|
||||
// Check to make sure that there are not any related records
|
||||
int usedByCount = 0;
|
||||
usedByCount += _RevisionCheckCount;
|
||||
usedByCount += _RevisionVersionCount;
|
||||
return (usedByCount == 0);
|
||||
}
|
||||
}
|
||||
public static bool CanEditObject()
|
||||
{
|
||||
// CSLATODO: CanEdit Authorization
|
||||
//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
|
||||
return true;
|
||||
}
|
||||
#endregion
|
||||
#region Factory Methods
|
||||
public int CurrentEditLevel
|
||||
{ get { return EditLevel; } }
|
||||
public int CurrentEditLevel => EditLevel;
|
||||
private static int _RevisionUnique = 0;
|
||||
protected static int RevisionUnique
|
||||
{ get { return ++_RevisionUnique; } }
|
||||
private int _MyRevisionUnique = RevisionUnique;
|
||||
public int MyRevisionUnique // Absolutely Unique ID - Editable
|
||||
{ get { return _MyRevisionUnique; } }
|
||||
protected static int RevisionUnique => ++_RevisionUnique;
|
||||
private readonly int _MyRevisionUnique = RevisionUnique;
|
||||
// Absolutely Unique ID - Editable
|
||||
public int MyRevisionUnique => _MyRevisionUnique;
|
||||
protected Revision()
|
||||
{/* require use of factory methods */
|
||||
AddToCache(this);
|
||||
@@ -555,15 +458,11 @@ namespace VEPROMS.CSLA.Library
|
||||
private static int _CountCreated = 0;
|
||||
private static int _CountDisposed = 0;
|
||||
private static int _CountFinalized = 0;
|
||||
private static int IncrementCountCreated
|
||||
{ get { return ++_CountCreated; } }
|
||||
private int _CountWhenCreated = IncrementCountCreated;
|
||||
public static int CountCreated
|
||||
{ get { return _CountCreated; } }
|
||||
public static int CountNotDisposed
|
||||
{ get { return _CountCreated - _CountDisposed; } }
|
||||
public static int CountNotFinalized
|
||||
{ get { return _CountCreated - _CountFinalized; } }
|
||||
private static int IncrementCountCreated => ++_CountCreated;
|
||||
private readonly int _CountWhenCreated = IncrementCountCreated;
|
||||
public static int CountCreated => _CountCreated;
|
||||
public static int CountNotDisposed => _CountCreated - _CountDisposed;
|
||||
public static int CountNotFinalized => _CountCreated - _CountFinalized;
|
||||
~Revision()
|
||||
{
|
||||
_CountFinalized++;
|
||||
@@ -588,8 +487,6 @@ namespace VEPROMS.CSLA.Library
|
||||
}
|
||||
public static Revision New()
|
||||
{
|
||||
if (!CanAddObject())
|
||||
throw new System.Security.SecurityException("User not authorized to add a Revision");
|
||||
try
|
||||
{
|
||||
return DataPortal.Create<Revision>();
|
||||
@@ -662,8 +559,6 @@ namespace VEPROMS.CSLA.Library
|
||||
}
|
||||
public static Revision Get(int revisionID)
|
||||
{
|
||||
if (!CanGetObject())
|
||||
throw new System.Security.SecurityException("User not authorized to view a Revision");
|
||||
try
|
||||
{
|
||||
Revision tmp = GetCachedByPrimaryKey(revisionID);
|
||||
@@ -689,14 +584,9 @@ namespace VEPROMS.CSLA.Library
|
||||
if (dr.Read()) return new Revision(dr);
|
||||
return null;
|
||||
}
|
||||
internal Revision(SafeDataReader dr)
|
||||
{
|
||||
ReadData(dr);
|
||||
}
|
||||
internal Revision(SafeDataReader dr) => ReadData(dr);
|
||||
public static void Delete(int revisionID)
|
||||
{
|
||||
if (!CanDeleteObject())
|
||||
throw new System.Security.SecurityException("User not authorized to remove a Revision");
|
||||
try
|
||||
{
|
||||
DataPortal.Delete(new PKCriteria(revisionID));
|
||||
@@ -708,12 +598,6 @@ namespace VEPROMS.CSLA.Library
|
||||
}
|
||||
public override Revision Save()
|
||||
{
|
||||
if (IsDeleted && !CanDeleteObject())
|
||||
throw new System.Security.SecurityException("User not authorized to remove a Revision");
|
||||
else if (IsNew && !CanAddObject())
|
||||
throw new System.Security.SecurityException("User not authorized to add a Revision");
|
||||
else if (!CanEditObject())
|
||||
throw new System.Security.SecurityException("User not authorized to update a Revision");
|
||||
try
|
||||
{
|
||||
BuildRefreshList();
|
||||
@@ -733,13 +617,9 @@ namespace VEPROMS.CSLA.Library
|
||||
[Serializable()]
|
||||
protected class PKCriteria
|
||||
{
|
||||
private int _RevisionID;
|
||||
public int RevisionID
|
||||
{ get { return _RevisionID; } }
|
||||
public PKCriteria(int revisionID)
|
||||
{
|
||||
_RevisionID = revisionID;
|
||||
}
|
||||
private readonly int _RevisionID;
|
||||
public int RevisionID => _RevisionID;
|
||||
public PKCriteria(int revisionID) => _RevisionID = revisionID;
|
||||
}
|
||||
// CSLATODO: If Create needs to access DB - It should not be marked RunLocal
|
||||
[RunLocal()]
|
||||
@@ -849,41 +729,48 @@ namespace VEPROMS.CSLA.Library
|
||||
[Transactional(TransactionalTypes.TransactionScope)]
|
||||
internal void SQLInsert()
|
||||
{
|
||||
if (!this.IsDirty) return;
|
||||
if (!IsDirty) return;
|
||||
try
|
||||
{
|
||||
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
|
||||
using (SqlCommand cm = cn.CreateCommand())
|
||||
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
|
||||
{
|
||||
cm.CommandType = CommandType.StoredProcedure;
|
||||
cm.CommandTimeout = Database.SQLTimeout;
|
||||
cm.CommandText = "addRevision";
|
||||
// Input All Fields - Except Calculated Columns
|
||||
cm.Parameters.AddWithValue("@ItemID", _ItemID);
|
||||
cm.Parameters.AddWithValue("@TypeID", _TypeID);
|
||||
cm.Parameters.AddWithValue("@RevisionNumber", _RevisionNumber);
|
||||
if (_RevisionDate != null && ((DateTime)_RevisionDate).Year >= 1753 && ((DateTime)_RevisionDate).Year <= 9999) cm.Parameters.AddWithValue("@RevisionDate", _RevisionDate);
|
||||
cm.Parameters.AddWithValue("@Notes", _Notes);
|
||||
cm.Parameters.AddWithValue("@Config", _Config);
|
||||
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
|
||||
cm.Parameters.AddWithValue("@UserID", _UserID);
|
||||
// Output Calculated Columns
|
||||
SqlParameter param_RevisionID = new SqlParameter("@newRevisionID", SqlDbType.Int);
|
||||
param_RevisionID.Direction = ParameterDirection.Output;
|
||||
cm.Parameters.Add(param_RevisionID);
|
||||
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp);
|
||||
param_LastChanged.Direction = ParameterDirection.Output;
|
||||
cm.Parameters.Add(param_LastChanged);
|
||||
// CSLATODO: Define any additional output parameters
|
||||
cm.ExecuteNonQuery();
|
||||
// Save all values being returned from the Procedure
|
||||
_RevisionID = (int)cm.Parameters["@newRevisionID"].Value;
|
||||
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
|
||||
using (SqlCommand cm = cn.CreateCommand())
|
||||
{
|
||||
cm.CommandType = CommandType.StoredProcedure;
|
||||
cm.CommandTimeout = Database.SQLTimeout;
|
||||
cm.CommandText = "addRevision";
|
||||
// Input All Fields - Except Calculated Columns
|
||||
cm.Parameters.AddWithValue("@ItemID", _ItemID);
|
||||
cm.Parameters.AddWithValue("@TypeID", _TypeID);
|
||||
cm.Parameters.AddWithValue("@RevisionNumber", _RevisionNumber);
|
||||
if (_RevisionDate != null && ((DateTime)_RevisionDate).Year >= 1753 && ((DateTime)_RevisionDate).Year <= 9999) cm.Parameters.AddWithValue("@RevisionDate", _RevisionDate);
|
||||
cm.Parameters.AddWithValue("@Notes", _Notes);
|
||||
cm.Parameters.AddWithValue("@Config", _Config);
|
||||
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
|
||||
cm.Parameters.AddWithValue("@UserID", _UserID);
|
||||
// Output Calculated Columns
|
||||
SqlParameter param_RevisionID = new SqlParameter("@newRevisionID", SqlDbType.Int)
|
||||
{
|
||||
Direction = ParameterDirection.Output
|
||||
};
|
||||
cm.Parameters.Add(param_RevisionID);
|
||||
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp)
|
||||
{
|
||||
Direction = ParameterDirection.Output
|
||||
};
|
||||
cm.Parameters.Add(param_LastChanged);
|
||||
// CSLATODO: Define any additional output parameters
|
||||
cm.ExecuteNonQuery();
|
||||
// Save all values being returned from the Procedure
|
||||
_RevisionID = (int)cm.Parameters["@newRevisionID"].Value;
|
||||
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
|
||||
}
|
||||
}
|
||||
|
||||
MarkOld();
|
||||
// update child objects
|
||||
if (_RevisionChecks != null) _RevisionChecks.Update(this);
|
||||
if (_RevisionVersions != null) _RevisionVersions.Update(this);
|
||||
_RevisionChecks?.Update(this);
|
||||
_RevisionVersions?.Update(this);
|
||||
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Revision.SQLInsert", GetHashCode());
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -914,11 +801,15 @@ namespace VEPROMS.CSLA.Library
|
||||
if (dts.Year >= 1753 && dts.Year <= 9999) cm.Parameters.AddWithValue("@DTS", dts);
|
||||
cm.Parameters.AddWithValue("@UserID", userID);
|
||||
// Output Calculated Columns
|
||||
SqlParameter param_RevisionID = new SqlParameter("@newRevisionID", SqlDbType.Int);
|
||||
param_RevisionID.Direction = ParameterDirection.Output;
|
||||
SqlParameter param_RevisionID = new SqlParameter("@newRevisionID", SqlDbType.Int)
|
||||
{
|
||||
Direction = ParameterDirection.Output
|
||||
};
|
||||
cm.Parameters.Add(param_RevisionID);
|
||||
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp);
|
||||
param_LastChanged.Direction = ParameterDirection.Output;
|
||||
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp)
|
||||
{
|
||||
Direction = ParameterDirection.Output
|
||||
};
|
||||
cm.Parameters.Add(param_LastChanged);
|
||||
// CSLATODO: Define any additional output parameters
|
||||
cm.ExecuteNonQuery();
|
||||
@@ -963,39 +854,44 @@ namespace VEPROMS.CSLA.Library
|
||||
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Revision.SQLUpdate", GetHashCode());
|
||||
try
|
||||
{
|
||||
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
|
||||
if (base.IsDirty)
|
||||
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
|
||||
{
|
||||
using (SqlCommand cm = cn.CreateCommand())
|
||||
if (base.IsDirty)
|
||||
{
|
||||
cm.CommandType = CommandType.StoredProcedure;
|
||||
cm.CommandTimeout = Database.SQLTimeout;
|
||||
cm.CommandText = "updateRevision";
|
||||
// All Fields including Calculated Fields
|
||||
cm.Parameters.AddWithValue("@RevisionID", _RevisionID);
|
||||
cm.Parameters.AddWithValue("@ItemID", _ItemID);
|
||||
cm.Parameters.AddWithValue("@TypeID", _TypeID);
|
||||
cm.Parameters.AddWithValue("@RevisionNumber", _RevisionNumber);
|
||||
if (_RevisionDate != null && ((DateTime)_RevisionDate).Year >= 1753 && ((DateTime)_RevisionDate).Year <= 9999) cm.Parameters.AddWithValue("@RevisionDate", _RevisionDate);
|
||||
cm.Parameters.AddWithValue("@Notes", _Notes);
|
||||
cm.Parameters.AddWithValue("@Config", _Config);
|
||||
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
|
||||
cm.Parameters.AddWithValue("@UserID", _UserID);
|
||||
cm.Parameters.AddWithValue("@LastChanged", _LastChanged);
|
||||
// Output Calculated Columns
|
||||
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp);
|
||||
param_LastChanged.Direction = ParameterDirection.Output;
|
||||
cm.Parameters.Add(param_LastChanged);
|
||||
// CSLATODO: Define any additional output parameters
|
||||
cm.ExecuteNonQuery();
|
||||
// Save all values being returned from the Procedure
|
||||
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
|
||||
using (SqlCommand cm = cn.CreateCommand())
|
||||
{
|
||||
cm.CommandType = CommandType.StoredProcedure;
|
||||
cm.CommandTimeout = Database.SQLTimeout;
|
||||
cm.CommandText = "updateRevision";
|
||||
// All Fields including Calculated Fields
|
||||
cm.Parameters.AddWithValue("@RevisionID", _RevisionID);
|
||||
cm.Parameters.AddWithValue("@ItemID", _ItemID);
|
||||
cm.Parameters.AddWithValue("@TypeID", _TypeID);
|
||||
cm.Parameters.AddWithValue("@RevisionNumber", _RevisionNumber);
|
||||
if (_RevisionDate != null && ((DateTime)_RevisionDate).Year >= 1753 && ((DateTime)_RevisionDate).Year <= 9999) cm.Parameters.AddWithValue("@RevisionDate", _RevisionDate);
|
||||
cm.Parameters.AddWithValue("@Notes", _Notes);
|
||||
cm.Parameters.AddWithValue("@Config", _Config);
|
||||
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
|
||||
cm.Parameters.AddWithValue("@UserID", _UserID);
|
||||
cm.Parameters.AddWithValue("@LastChanged", _LastChanged);
|
||||
// Output Calculated Columns
|
||||
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp)
|
||||
{
|
||||
Direction = ParameterDirection.Output
|
||||
};
|
||||
cm.Parameters.Add(param_LastChanged);
|
||||
// CSLATODO: Define any additional output parameters
|
||||
cm.ExecuteNonQuery();
|
||||
// Save all values being returned from the Procedure
|
||||
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
MarkOld();
|
||||
// use the open connection to update child objects
|
||||
if (_RevisionChecks != null) _RevisionChecks.Update(this);
|
||||
if (_RevisionVersions != null) _RevisionVersions.Update(this);
|
||||
_RevisionChecks?.Update(this);
|
||||
_RevisionVersions?.Update(this);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -1006,18 +902,21 @@ namespace VEPROMS.CSLA.Library
|
||||
}
|
||||
internal void Update()
|
||||
{
|
||||
if (!this.IsDirty) return;
|
||||
if (!IsDirty) return;
|
||||
if (base.IsDirty)
|
||||
{
|
||||
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
|
||||
if (IsNew)
|
||||
_LastChanged = Revision.Add(cn, ref _RevisionID, _ItemID, _TypeID, _RevisionNumber, _RevisionDate, _Notes, _Config, _DTS, _UserID);
|
||||
else
|
||||
_LastChanged = Revision.Update(cn, ref _RevisionID, _ItemID, _TypeID, _RevisionNumber, _RevisionDate, _Notes, _Config, _DTS, _UserID, ref _LastChanged);
|
||||
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
|
||||
{
|
||||
if (IsNew)
|
||||
_LastChanged = Revision.Add(cn, ref _RevisionID, _ItemID, _TypeID, _RevisionNumber, _RevisionDate, _Notes, _Config, _DTS, _UserID);
|
||||
else
|
||||
_LastChanged = Revision.Update(cn, ref _RevisionID, _ItemID, _TypeID, _RevisionNumber, _RevisionDate, _Notes, _Config, _DTS, _UserID, ref _LastChanged);
|
||||
}
|
||||
|
||||
MarkOld();
|
||||
}
|
||||
if (_RevisionChecks != null) _RevisionChecks.Update(this);
|
||||
if (_RevisionVersions != null) _RevisionVersions.Update(this);
|
||||
_RevisionChecks?.Update(this);
|
||||
_RevisionVersions?.Update(this);
|
||||
}
|
||||
[Transactional(TransactionalTypes.TransactionScope)]
|
||||
public static byte[] Update(SqlConnection cn, ref int revisionID, int itemID, int typeID, string revisionNumber, DateTime? revisionDate, string notes, string config, DateTime dts, string userID, ref byte[] lastChanged)
|
||||
@@ -1042,8 +941,10 @@ namespace VEPROMS.CSLA.Library
|
||||
cm.Parameters.AddWithValue("@UserID", userID);
|
||||
cm.Parameters.AddWithValue("@LastChanged", lastChanged);
|
||||
// Output Calculated Columns
|
||||
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp);
|
||||
param_LastChanged.Direction = ParameterDirection.Output;
|
||||
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp)
|
||||
{
|
||||
Direction = ParameterDirection.Output
|
||||
};
|
||||
cm.Parameters.Add(param_LastChanged);
|
||||
// CSLATODO: Define any additional output parameters
|
||||
cm.ExecuteNonQuery();
|
||||
@@ -1128,16 +1029,10 @@ namespace VEPROMS.CSLA.Library
|
||||
[Serializable()]
|
||||
private class ExistsCommand : CommandBase
|
||||
{
|
||||
private int _RevisionID;
|
||||
private readonly int _RevisionID;
|
||||
private bool _exists;
|
||||
public bool Exists
|
||||
{
|
||||
get { return _exists; }
|
||||
}
|
||||
public ExistsCommand(int revisionID)
|
||||
{
|
||||
_RevisionID = revisionID;
|
||||
}
|
||||
public bool Exists => _exists;
|
||||
public ExistsCommand(int revisionID) => _RevisionID = revisionID;
|
||||
protected override void DataPortal_Execute()
|
||||
{
|
||||
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Revision.DataPortal_Execute", GetHashCode());
|
||||
@@ -1167,7 +1062,7 @@ namespace VEPROMS.CSLA.Library
|
||||
#endregion
|
||||
// Standard Default Code
|
||||
#region extension
|
||||
RevisionExtension _RevisionExtension = new RevisionExtension();
|
||||
readonly RevisionExtension _RevisionExtension = new RevisionExtension();
|
||||
[Serializable()]
|
||||
partial class RevisionExtension : extensionBase
|
||||
{
|
||||
@@ -1176,18 +1071,9 @@ namespace VEPROMS.CSLA.Library
|
||||
class extensionBase
|
||||
{
|
||||
// Default Values
|
||||
public virtual int DefaultTypeID
|
||||
{
|
||||
get { return 1; }
|
||||
}
|
||||
public virtual DateTime DefaultDTS
|
||||
{
|
||||
get { return DateTime.Now; }
|
||||
}
|
||||
public virtual string DefaultUserID
|
||||
{
|
||||
get { return Volian.Base.Library.VlnSettings.UserID; }
|
||||
}
|
||||
public virtual int DefaultTypeID => 1;
|
||||
public virtual DateTime DefaultDTS => DateTime.Now;
|
||||
public virtual string DefaultUserID => Volian.Base.Library.VlnSettings.UserID;
|
||||
// Authorization Rules
|
||||
public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules)
|
||||
{
|
||||
@@ -1216,61 +1102,13 @@ namespace VEPROMS.CSLA.Library
|
||||
{
|
||||
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
|
||||
{
|
||||
if (destType == typeof(string) && value is Revision)
|
||||
if (destType == typeof(string) && value is Revision revision)
|
||||
{
|
||||
// Return the ToString value
|
||||
return ((Revision)value).ToString();
|
||||
return revision.ToString();
|
||||
}
|
||||
return base.ConvertTo(context, culture, value, destType);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
} // Namespace
|
||||
|
||||
|
||||
//// The following is a sample Extension File. You can use it to create RevisionExt.cs
|
||||
//using System;
|
||||
//using System.Collections.Generic;
|
||||
//using System.Text;
|
||||
//using Csla;
|
||||
|
||||
//namespace VEPROMS.CSLA.Library
|
||||
//{
|
||||
// public partial class Revision
|
||||
// {
|
||||
// partial class RevisionExtension : extensionBase
|
||||
// {
|
||||
// // CSLATODO: Override automatic defaults
|
||||
// public virtual int DefaultTypeID
|
||||
// {
|
||||
// get { return 1; }
|
||||
// }
|
||||
// public virtual DateTime DefaultDTS
|
||||
// {
|
||||
// get { return DateTime.Now; }
|
||||
// }
|
||||
// public virtual string DefaultUserID
|
||||
// {
|
||||
// get { return Environment.UserName.ToUpper(); }
|
||||
// }
|
||||
// public new void AddAuthorizationRules(Csla.Security.AuthorizationRules rules)
|
||||
// {
|
||||
// //rules.AllowRead(Dbid, "<Role(s)>");
|
||||
// }
|
||||
// public new void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules)
|
||||
// {
|
||||
// //rules.AllowInstanceRead(Dbid, "<Role(s)>");
|
||||
// }
|
||||
// public new void AddValidationRules(Csla.Validation.ValidationRules rules)
|
||||
// {
|
||||
// rules.AddRule(
|
||||
// Csla.Validation.CommonRules.StringMaxLength,
|
||||
// new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100));
|
||||
// }
|
||||
// public new void AddInstanceValidationRules(Csla.Validation.ValidationRules rules)
|
||||
// {
|
||||
// rules.AddInstanceRule(/* Instance Validation Rule */);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
||||
Reference in New Issue
Block a user