CSLA - Is
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;
|
||||
@@ -133,6 +131,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<Item> _CacheList = new List<Item>();
|
||||
protected static void AddToCache(Item item)
|
||||
{
|
||||
@@ -142,6 +141,7 @@ namespace VEPROMS.CSLA.Library
|
||||
{
|
||||
while (_CacheList.Contains(item)) _CacheList.Remove(item); // In RemoveFromCache
|
||||
}
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
|
||||
private static Dictionary<string, List<Item>> _CacheByPrimaryKey = new Dictionary<string, List<Item>>();
|
||||
private static void ConvertListToDictionary()
|
||||
{
|
||||
@@ -167,15 +167,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 _nextItemID = -1;
|
||||
public static int NextItemID
|
||||
{
|
||||
get { return _nextItemID--; }
|
||||
}
|
||||
public static int NextItemID => _nextItemID--;
|
||||
private int _ItemID;
|
||||
[System.ComponentModel.DataObjectField(true, true)]
|
||||
public int ItemID
|
||||
@@ -315,10 +309,7 @@ namespace VEPROMS.CSLA.Library
|
||||
return _ItemAnnotations;
|
||||
}
|
||||
}
|
||||
public void Reset_ItemAnnotations()
|
||||
{
|
||||
_ItemAnnotationCount = -1;
|
||||
}
|
||||
public void Reset_ItemAnnotations() => _ItemAnnotationCount = -1;
|
||||
private int _ItemDocVersionCount = 0;
|
||||
/// <summary>
|
||||
/// Count of ItemDocVersions for this Item
|
||||
@@ -350,10 +341,7 @@ namespace VEPROMS.CSLA.Library
|
||||
return _ItemDocVersions;
|
||||
}
|
||||
}
|
||||
public void Reset_ItemDocVersions()
|
||||
{
|
||||
_ItemDocVersionCount = -1;
|
||||
}
|
||||
public void Reset_ItemDocVersions() => _ItemDocVersionCount = -1;
|
||||
private int _NextItemCount = 0;
|
||||
/// <summary>
|
||||
/// Count of NextItems for this Item
|
||||
@@ -385,10 +373,7 @@ namespace VEPROMS.CSLA.Library
|
||||
return _NextItems;
|
||||
}
|
||||
}
|
||||
public void Reset_NextItems()
|
||||
{
|
||||
_NextItemCount = -1;
|
||||
}
|
||||
public void Reset_NextItems() => _NextItemCount = -1;
|
||||
private int _ItemPartCount = 0;
|
||||
/// <summary>
|
||||
/// Count of ItemParts for this Item
|
||||
@@ -420,10 +405,7 @@ namespace VEPROMS.CSLA.Library
|
||||
return _ItemParts;
|
||||
}
|
||||
}
|
||||
public void Reset_ItemParts()
|
||||
{
|
||||
_ItemPartCount = -1;
|
||||
}
|
||||
public void Reset_ItemParts() => _ItemPartCount = -1;
|
||||
private int _ItemTransition_RangeIDCount = 0;
|
||||
/// <summary>
|
||||
/// Count of ItemTransitions for this Item
|
||||
@@ -455,10 +437,7 @@ namespace VEPROMS.CSLA.Library
|
||||
return _ItemTransitions_RangeID;
|
||||
}
|
||||
}
|
||||
public void Reset_ItemTransitions_RangeID()
|
||||
{
|
||||
_ItemTransition_RangeIDCount = -1;
|
||||
}
|
||||
public void Reset_ItemTransitions_RangeID() => _ItemTransition_RangeIDCount = -1;
|
||||
private int _ItemTransition_ToIDCount = 0;
|
||||
/// <summary>
|
||||
/// Count of ItemTransitions for this Item
|
||||
@@ -490,10 +469,7 @@ namespace VEPROMS.CSLA.Library
|
||||
return _ItemTransitions_ToID;
|
||||
}
|
||||
}
|
||||
public void Reset_ItemTransitions_ToID()
|
||||
{
|
||||
_ItemTransition_ToIDCount = -1;
|
||||
}
|
||||
public void Reset_ItemTransitions_ToID() => _ItemTransition_ToIDCount = -1;
|
||||
public override bool IsDirty
|
||||
{
|
||||
get
|
||||
@@ -508,37 +484,22 @@ namespace VEPROMS.CSLA.Library
|
||||
if (base.IsDirty || list.Contains(this))
|
||||
return base.IsDirty;
|
||||
list.Add(this);
|
||||
return base.IsDirty || (_ItemAnnotations == null ? false : _ItemAnnotations.IsDirtyList(list)) || (_ItemDocVersions == null ? false : _ItemDocVersions.IsDirtyList(list)) || (_NextItems == null ? false : _NextItems.IsDirtyList(list)) || (_ItemParts == null ? false : _ItemParts.IsDirtyList(list)) || (_ItemTransitions_RangeID == null ? false : _ItemTransitions_RangeID.IsDirtyList(list)) || (_ItemTransitions_ToID == null ? false : _ItemTransitions_ToID.IsDirtyList(list)) || (_MyContent == null ? false : _MyContent.IsDirtyList(list));
|
||||
}
|
||||
public override bool IsValid
|
||||
{
|
||||
get { return IsValidList(new List<object>()); }
|
||||
return base.IsDirty || (_ItemAnnotations != null && _ItemAnnotations.IsDirtyList(list)) || (_ItemDocVersions != null && _ItemDocVersions.IsDirtyList(list)) || (_NextItems != null && _NextItems.IsDirtyList(list)) || (_ItemParts != null && _ItemParts.IsDirtyList(list)) || (_ItemTransitions_RangeID != null && _ItemTransitions_RangeID.IsDirtyList(list)) || (_ItemTransitions_ToID != null && _ItemTransitions_ToID.IsDirtyList(list)) || (_MyContent != null && _MyContent.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) && (_ItemAnnotations == null ? true : _ItemAnnotations.IsValidList(list)) && (_ItemDocVersions == null ? true : _ItemDocVersions.IsValidList(list)) && (_NextItems == null ? true : _NextItems.IsValidList(list)) && (_ItemParts == null ? true : _ItemParts.IsValidList(list)) && (_ItemTransitions_RangeID == null ? true : _ItemTransitions_RangeID.IsValidList(list)) && (_ItemTransitions_ToID == null ? true : _ItemTransitions_ToID.IsValidList(list)) && (_MyContent == null ? true : _MyContent.IsValidList(list));
|
||||
return ((IsNew && !IsDirty) || base.IsValid) && (_ItemAnnotations == null || _ItemAnnotations.IsValidList(list)) && (_ItemDocVersions == null || _ItemDocVersions.IsValidList(list)) && (_NextItems == null || _NextItems.IsValidList(list)) && (_ItemParts == null || _ItemParts.IsValidList(list)) && (_ItemTransitions_RangeID == null || _ItemTransitions_RangeID.IsValidList(list)) && (_ItemTransitions_ToID == null || _ItemTransitions_ToID.IsValidList(list)) && (_MyContent == null || _MyContent.IsValidList(list));
|
||||
}
|
||||
// CSLATODO: Replace base Item.ToString function as necessary
|
||||
/// <summary>
|
||||
/// Overrides Base ToString
|
||||
/// </summary>
|
||||
/// <returns>A string representation of current Item</returns>
|
||||
//public override string ToString()
|
||||
//{
|
||||
// return base.ToString();
|
||||
//}
|
||||
// CSLATODO: Check Item.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 Item</returns>
|
||||
protected override object GetIdValue()
|
||||
{
|
||||
return MyItemUnique; // Absolutely Unique ID
|
||||
}
|
||||
protected override object GetIdValue() => MyItemUnique; // Absolutely Unique ID
|
||||
#endregion
|
||||
#region ValidationRules
|
||||
[NonSerialized]
|
||||
@@ -573,8 +534,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()
|
||||
@@ -603,31 +564,11 @@ namespace VEPROMS.CSLA.Library
|
||||
}
|
||||
return true;
|
||||
}
|
||||
// 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(ItemID, "<Role(s)>");
|
||||
//AuthorizationRules.AllowRead(PreviousID, "<Role(s)>");
|
||||
//AuthorizationRules.AllowRead(ContentID, "<Role(s)>");
|
||||
//AuthorizationRules.AllowRead(DTS, "<Role(s)>");
|
||||
//AuthorizationRules.AllowRead(UserID, "<Role(s)>");
|
||||
//AuthorizationRules.AllowWrite(PreviousID, "<Role(s)>");
|
||||
//AuthorizationRules.AllowWrite(ContentID, "<Role(s)>");
|
||||
//AuthorizationRules.AllowWrite(DTS, "<Role(s)>");
|
||||
//AuthorizationRules.AllowWrite(UserID, "<Role(s)>");
|
||||
_ItemExtension.AddAuthorizationRules(AuthorizationRules);
|
||||
}
|
||||
protected override void AddInstanceAuthorizationRules()
|
||||
@@ -635,60 +576,14 @@ namespace VEPROMS.CSLA.Library
|
||||
//CSLATODO: Who can read/write which fields
|
||||
_ItemExtension.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 += _ItemAnnotationCount;
|
||||
usedByCount += _ItemDocVersionCount;
|
||||
usedByCount += _ItemPartCount;
|
||||
usedByCount += _ItemTransition_RangeIDCount;
|
||||
usedByCount += _ItemTransition_ToIDCount;
|
||||
usedByCount += _NextItemCount;
|
||||
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 _ItemUnique = 0;
|
||||
protected static int ItemUnique
|
||||
{ get { return ++_ItemUnique; } }
|
||||
private int _MyItemUnique = ItemUnique;
|
||||
public int MyItemUnique // Absolutely Unique ID - Editable
|
||||
{ get { return _MyItemUnique; } }
|
||||
protected static int ItemUnique => ++_ItemUnique;
|
||||
private readonly int _MyItemUnique = ItemUnique;
|
||||
// Absolutely Unique ID - Editable
|
||||
public int MyItemUnique => _MyItemUnique;
|
||||
protected Item()
|
||||
{/* require use of factory methods */
|
||||
AddToCache(this);
|
||||
@@ -697,15 +592,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;
|
||||
~Item()
|
||||
{
|
||||
_CountFinalized++;
|
||||
@@ -732,16 +623,6 @@ namespace VEPROMS.CSLA.Library
|
||||
_ItemTransitions_RangeID = null;
|
||||
if (_ItemTransitions_ToID != null)
|
||||
_ItemTransitions_ToID = null;
|
||||
//if (_MyPrevious != null)
|
||||
// _MyPrevious = null;
|
||||
//if (_NextItems != null)
|
||||
// _NextItems = null;
|
||||
//if (_ItemAnnotations != null)
|
||||
// _ItemAnnotations.Dispose();
|
||||
//if (_ItemDocVersions != null)
|
||||
// _ItemDocVersions = null;
|
||||
//if (_ItemParts != null)
|
||||
// _ItemParts = null;
|
||||
}
|
||||
private void RemoveFromDictionaries()
|
||||
{
|
||||
@@ -756,8 +637,6 @@ namespace VEPROMS.CSLA.Library
|
||||
}
|
||||
public static Item New()
|
||||
{
|
||||
if (!CanAddObject())
|
||||
throw new System.Security.SecurityException("User not authorized to add a Item");
|
||||
try
|
||||
{
|
||||
return DataPortal.Create<Item>();
|
||||
@@ -823,8 +702,6 @@ namespace VEPROMS.CSLA.Library
|
||||
}
|
||||
public static Item Get(int itemID)
|
||||
{
|
||||
if (!CanGetObject())
|
||||
throw new System.Security.SecurityException("User not authorized to view a Item");
|
||||
try
|
||||
{
|
||||
Item tmp = GetCachedByPrimaryKey(itemID);
|
||||
@@ -850,15 +727,14 @@ namespace VEPROMS.CSLA.Library
|
||||
if (dr.Read()) return new Item(dr, previous);
|
||||
return null;
|
||||
}
|
||||
internal Item(SafeDataReader dr)
|
||||
{
|
||||
ReadData(dr);
|
||||
}
|
||||
internal Item(SafeDataReader dr) => ReadData(dr);
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Keeping until replace CSLA")]
|
||||
private Item(SafeDataReader dr, Item previous)
|
||||
{
|
||||
ReadData(dr);
|
||||
MarkAsChild();
|
||||
}
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Keeping until replace CSLA")]
|
||||
internal Item(SafeDataReader dr, int parentID)
|
||||
{
|
||||
ReadData(dr);
|
||||
@@ -866,8 +742,6 @@ namespace VEPROMS.CSLA.Library
|
||||
}
|
||||
public static void Delete(int itemID)
|
||||
{
|
||||
if (!CanDeleteObject())
|
||||
throw new System.Security.SecurityException("User not authorized to remove a Item");
|
||||
try
|
||||
{
|
||||
DataPortal.Delete(new PKCriteria(itemID));
|
||||
@@ -879,12 +753,6 @@ namespace VEPROMS.CSLA.Library
|
||||
}
|
||||
public override Item Save()
|
||||
{
|
||||
if (IsDeleted && !CanDeleteObject())
|
||||
throw new System.Security.SecurityException("User not authorized to remove a Item");
|
||||
else if (IsNew && !CanAddObject())
|
||||
throw new System.Security.SecurityException("User not authorized to add a Item");
|
||||
else if (!CanEditObject())
|
||||
throw new System.Security.SecurityException("User not authorized to update a Item");
|
||||
try
|
||||
{
|
||||
BuildRefreshList();
|
||||
@@ -904,13 +772,9 @@ namespace VEPROMS.CSLA.Library
|
||||
[Serializable()]
|
||||
protected class PKCriteria
|
||||
{
|
||||
private int _ItemID;
|
||||
public int ItemID
|
||||
{ get { return _ItemID; } }
|
||||
public PKCriteria(int itemID)
|
||||
{
|
||||
_ItemID = itemID;
|
||||
}
|
||||
private readonly int _ItemID;
|
||||
public int ItemID => _ItemID;
|
||||
public PKCriteria(int itemID) => _ItemID = itemID;
|
||||
}
|
||||
// CSLATODO: If Create needs to access DB - It should not be marked RunLocal
|
||||
[RunLocal()]
|
||||
@@ -1028,42 +892,49 @@ namespace VEPROMS.CSLA.Library
|
||||
[Transactional(TransactionalTypes.TransactionScope)]
|
||||
internal void SQLInsert()
|
||||
{
|
||||
if (!this.IsDirty) return;
|
||||
if (!IsDirty) return;
|
||||
try
|
||||
{
|
||||
if (_MyContent != null) _MyContent.Update();
|
||||
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
|
||||
using (SqlCommand cm = cn.CreateCommand())
|
||||
_MyContent?.Update();
|
||||
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
|
||||
{
|
||||
cm.CommandType = CommandType.StoredProcedure;
|
||||
cm.CommandTimeout = Database.SQLTimeout;
|
||||
cm.CommandText = "addItem";
|
||||
// Input All Fields - Except Calculated Columns
|
||||
cm.Parameters.AddWithValue("@PreviousID", PreviousID);
|
||||
cm.Parameters.AddWithValue("@ContentID", ContentID);
|
||||
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
|
||||
cm.Parameters.AddWithValue("@UserID", _UserID);
|
||||
// Output Calculated Columns
|
||||
SqlParameter param_ItemID = new SqlParameter("@newItemID", SqlDbType.Int);
|
||||
param_ItemID.Direction = ParameterDirection.Output;
|
||||
cm.Parameters.Add(param_ItemID);
|
||||
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
|
||||
_ItemID = (int)cm.Parameters["@newItemID"].Value;
|
||||
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
|
||||
using (SqlCommand cm = cn.CreateCommand())
|
||||
{
|
||||
cm.CommandType = CommandType.StoredProcedure;
|
||||
cm.CommandTimeout = Database.SQLTimeout;
|
||||
cm.CommandText = "addItem";
|
||||
// Input All Fields - Except Calculated Columns
|
||||
cm.Parameters.AddWithValue("@PreviousID", PreviousID);
|
||||
cm.Parameters.AddWithValue("@ContentID", ContentID);
|
||||
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
|
||||
cm.Parameters.AddWithValue("@UserID", _UserID);
|
||||
// Output Calculated Columns
|
||||
SqlParameter param_ItemID = new SqlParameter("@newItemID", SqlDbType.Int)
|
||||
{
|
||||
Direction = ParameterDirection.Output
|
||||
};
|
||||
cm.Parameters.Add(param_ItemID);
|
||||
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
|
||||
_ItemID = (int)cm.Parameters["@newItemID"].Value;
|
||||
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
|
||||
}
|
||||
}
|
||||
|
||||
MarkOld();
|
||||
// update child objects
|
||||
if (_ItemAnnotations != null) _ItemAnnotations.Update(this);
|
||||
if (_ItemDocVersions != null) _ItemDocVersions.Update(this);
|
||||
if (_NextItems != null) _NextItems.Update(this);
|
||||
if (_ItemParts != null) _ItemParts.Update(this);
|
||||
if (_ItemTransitions_RangeID != null) _ItemTransitions_RangeID.Update(this);
|
||||
if (_ItemTransitions_ToID != null) _ItemTransitions_ToID.Update(this);
|
||||
_ItemAnnotations?.Update(this);
|
||||
_ItemDocVersions?.Update(this);
|
||||
_NextItems?.Update(this);
|
||||
_ItemParts?.Update(this);
|
||||
_ItemTransitions_RangeID?.Update(this);
|
||||
_ItemTransitions_ToID?.Update(this);
|
||||
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Item.SQLInsert", GetHashCode());
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -1090,11 +961,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_ItemID = new SqlParameter("@newItemID", SqlDbType.Int);
|
||||
param_ItemID.Direction = ParameterDirection.Output;
|
||||
SqlParameter param_ItemID = new SqlParameter("@newItemID", SqlDbType.Int)
|
||||
{
|
||||
Direction = ParameterDirection.Output
|
||||
};
|
||||
cm.Parameters.Add(param_ItemID);
|
||||
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();
|
||||
@@ -1178,7 +1053,7 @@ namespace VEPROMS.CSLA.Library
|
||||
return dt;
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
catch (Exception)
|
||||
{
|
||||
//B2025-004
|
||||
//if it fails loading previously open tabs, simply treat it as if no tabs were open
|
||||
@@ -1219,40 +1094,45 @@ namespace VEPROMS.CSLA.Library
|
||||
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Item.SQLUpdate", GetHashCode());
|
||||
try
|
||||
{
|
||||
if (_MyContent != null) _MyContent.Update();
|
||||
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
|
||||
if (base.IsDirty)
|
||||
_MyContent?.Update();
|
||||
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 = "updateItem";
|
||||
// All Fields including Calculated Fields
|
||||
cm.Parameters.AddWithValue("@ItemID", _ItemID);
|
||||
cm.Parameters.AddWithValue("@PreviousID", PreviousID);
|
||||
cm.Parameters.AddWithValue("@ContentID", ContentID);
|
||||
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 = "updateItem";
|
||||
// All Fields including Calculated Fields
|
||||
cm.Parameters.AddWithValue("@ItemID", _ItemID);
|
||||
cm.Parameters.AddWithValue("@PreviousID", PreviousID);
|
||||
cm.Parameters.AddWithValue("@ContentID", ContentID);
|
||||
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 (_ItemAnnotations != null) _ItemAnnotations.Update(this);
|
||||
if (_ItemDocVersions != null) _ItemDocVersions.Update(this);
|
||||
if (_NextItems != null) _NextItems.Update(this);
|
||||
if (_ItemParts != null) _ItemParts.Update(this);
|
||||
if (_ItemTransitions_RangeID != null) _ItemTransitions_RangeID.Update(this);
|
||||
if (_ItemTransitions_ToID != null) _ItemTransitions_ToID.Update(this);
|
||||
_ItemAnnotations?.Update(this);
|
||||
_ItemDocVersions?.Update(this);
|
||||
_NextItems?.Update(this);
|
||||
_ItemParts?.Update(this);
|
||||
_ItemTransitions_RangeID?.Update(this);
|
||||
_ItemTransitions_ToID?.Update(this);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -1263,31 +1143,38 @@ 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 = Item.Add(cn, ref _ItemID, _MyPrevious, _MyContent, _DTS, _UserID);
|
||||
else
|
||||
_LastChanged = Item.Update(cn, ref _ItemID, _PreviousID, _ContentID, _DTS, _UserID, ref _LastChanged);
|
||||
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
|
||||
{
|
||||
if (IsNew)
|
||||
_LastChanged = Item.Add(cn, ref _ItemID, _MyPrevious, _MyContent, _DTS, _UserID);
|
||||
else
|
||||
_LastChanged = Item.Update(cn, ref _ItemID, _PreviousID, _ContentID, _DTS, _UserID, ref _LastChanged);
|
||||
}
|
||||
|
||||
MarkOld();
|
||||
}
|
||||
if (_ItemAnnotations != null) _ItemAnnotations.Update(this);
|
||||
if (_ItemDocVersions != null) _ItemDocVersions.Update(this);
|
||||
if (_NextItems != null) _NextItems.Update(this);
|
||||
if (_ItemParts != null) _ItemParts.Update(this);
|
||||
if (_ItemTransitions_RangeID != null) _ItemTransitions_RangeID.Update(this);
|
||||
if (_ItemTransitions_ToID != null) _ItemTransitions_ToID.Update(this);
|
||||
_ItemAnnotations?.Update(this);
|
||||
_ItemDocVersions?.Update(this);
|
||||
_NextItems?.Update(this);
|
||||
_ItemParts?.Update(this);
|
||||
_ItemTransitions_RangeID?.Update(this);
|
||||
_ItemTransitions_ToID?.Update(this);
|
||||
}
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Keeping until replace CSLA")]
|
||||
internal void DeleteSelf(Item item)
|
||||
{
|
||||
// if we're not dirty then don't update the database
|
||||
if (!this.IsDirty) return;
|
||||
if (!IsDirty) return;
|
||||
// if we're new then don't update the database
|
||||
if (this.IsNew) return;
|
||||
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
|
||||
Item.Remove(cn, _ItemID);
|
||||
if (IsNew) return;
|
||||
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
|
||||
{
|
||||
Item.Remove(cn, _ItemID);
|
||||
}
|
||||
|
||||
MarkNew();
|
||||
}
|
||||
[Transactional(TransactionalTypes.TransactionScope)]
|
||||
@@ -1309,8 +1196,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();
|
||||
@@ -1395,16 +1284,10 @@ namespace VEPROMS.CSLA.Library
|
||||
[Serializable()]
|
||||
private class ExistsCommand : CommandBase
|
||||
{
|
||||
private int _ItemID;
|
||||
private readonly int _ItemID;
|
||||
private bool _exists;
|
||||
public bool Exists
|
||||
{
|
||||
get { return _exists; }
|
||||
}
|
||||
public ExistsCommand(int itemID)
|
||||
{
|
||||
_ItemID = itemID;
|
||||
}
|
||||
public bool Exists => _exists;
|
||||
public ExistsCommand(int itemID) => _ItemID = itemID;
|
||||
protected override void DataPortal_Execute()
|
||||
{
|
||||
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Item.DataPortal_Execute", GetHashCode());
|
||||
@@ -1434,7 +1317,7 @@ namespace VEPROMS.CSLA.Library
|
||||
#endregion
|
||||
// Standard Default Code
|
||||
#region extension
|
||||
ItemExtension _ItemExtension = new ItemExtension();
|
||||
readonly ItemExtension _ItemExtension = new ItemExtension();
|
||||
[Serializable()]
|
||||
partial class ItemExtension : extensionBase
|
||||
{
|
||||
@@ -1443,14 +1326,8 @@ namespace VEPROMS.CSLA.Library
|
||||
class extensionBase
|
||||
{
|
||||
// Default Values
|
||||
public virtual DateTime DefaultDTS
|
||||
{
|
||||
get { return DateTime.Now; }
|
||||
}
|
||||
public virtual string DefaultUserID
|
||||
{
|
||||
get { return Volian.Base.Library.VlnSettings.UserID; }
|
||||
}
|
||||
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)
|
||||
{
|
||||
@@ -1479,57 +1356,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 Item)
|
||||
if (destType == typeof(string) && value is Item myitem)
|
||||
{
|
||||
// Return the ToString value
|
||||
return ((Item)value).ToString();
|
||||
return myitem.ToString();
|
||||
}
|
||||
return base.ConvertTo(context, culture, value, destType);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
} // Namespace
|
||||
|
||||
|
||||
//// The following is a sample Extension File. You can use it to create ItemExt.cs
|
||||
//using System;
|
||||
//using System.Collections.Generic;
|
||||
//using System.Text;
|
||||
//using Csla;
|
||||
|
||||
//namespace VEPROMS.CSLA.Library
|
||||
//{
|
||||
// public partial class Item
|
||||
// {
|
||||
// partial class ItemExtension : extensionBase
|
||||
// {
|
||||
// // CSLATODO: Override automatic defaults
|
||||
// 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