CSLA - E & F
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;
|
||||
@@ -102,6 +100,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<Format> _CacheList = new List<Format>();
|
||||
protected static void AddToCache(Format format)
|
||||
{
|
||||
@@ -111,7 +110,9 @@ namespace VEPROMS.CSLA.Library
|
||||
{
|
||||
while (_CacheList.Contains(format)) _CacheList.Remove(format); // In RemoveFromCache
|
||||
}
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
|
||||
private static Dictionary<string, List<Format>> _CacheByPrimaryKey = new Dictionary<string, List<Format>>();
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
|
||||
private static Dictionary<string, List<Format>> _CacheByParentID_Name = new Dictionary<string, List<Format>>();
|
||||
private static void ConvertListToDictionary()
|
||||
{
|
||||
@@ -154,15 +155,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 _nextFormatID = -1;
|
||||
public static int NextFormatID
|
||||
{
|
||||
get { return _nextFormatID--; }
|
||||
}
|
||||
public static int NextFormatID => _nextFormatID--;
|
||||
private int _FormatID;
|
||||
[System.ComponentModel.DataObjectField(true, true)]
|
||||
public int FormatID
|
||||
@@ -367,10 +362,7 @@ namespace VEPROMS.CSLA.Library
|
||||
return _FormatContents;
|
||||
}
|
||||
}
|
||||
public void Reset_FormatContents()
|
||||
{
|
||||
_FormatContentCount = -1;
|
||||
}
|
||||
public void Reset_FormatContents() => _FormatContentCount = -1;
|
||||
private int _FormatDocVersionCount = 0;
|
||||
/// <summary>
|
||||
/// Count of FormatDocVersions for this Format
|
||||
@@ -402,10 +394,7 @@ namespace VEPROMS.CSLA.Library
|
||||
return _FormatDocVersions;
|
||||
}
|
||||
}
|
||||
public void Reset_FormatDocVersions()
|
||||
{
|
||||
_FormatDocVersionCount = -1;
|
||||
}
|
||||
public void Reset_FormatDocVersions() => _FormatDocVersionCount = -1;
|
||||
private int _FormatFolderCount = 0;
|
||||
/// <summary>
|
||||
/// Count of FormatFolders for this Format
|
||||
@@ -472,10 +461,7 @@ namespace VEPROMS.CSLA.Library
|
||||
return _ChildFormats;
|
||||
}
|
||||
}
|
||||
public void Reset_ChildFormats()
|
||||
{
|
||||
_ChildFormatCount = -1;
|
||||
}
|
||||
public void Reset_ChildFormats() => _ChildFormatCount = -1;
|
||||
public override bool IsDirty
|
||||
{
|
||||
get
|
||||
@@ -490,37 +476,22 @@ namespace VEPROMS.CSLA.Library
|
||||
if (base.IsDirty || list.Contains(this))
|
||||
return base.IsDirty;
|
||||
list.Add(this);
|
||||
return base.IsDirty || (_FormatContents == null ? false : _FormatContents.IsDirtyList(list)) || (_FormatDocVersions == null ? false : _FormatDocVersions.IsDirtyList(list)) || (_FormatFolders == null ? false : _FormatFolders.IsDirtyList(list)) || (_ChildFormats == null ? false : _ChildFormats.IsDirtyList(list));
|
||||
}
|
||||
public override bool IsValid
|
||||
{
|
||||
get { return IsValidList(new List<object>()); }
|
||||
return base.IsDirty || (_FormatContents != null && _FormatContents.IsDirtyList(list)) || (_FormatDocVersions != null && _FormatDocVersions.IsDirtyList(list)) || (_FormatFolders != null && _FormatFolders.IsDirtyList(list)) || (_ChildFormats != null && _ChildFormats.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) && (_FormatContents == null ? true : _FormatContents.IsValidList(list)) && (_FormatDocVersions == null ? true : _FormatDocVersions.IsValidList(list)) && (_FormatFolders == null ? true : _FormatFolders.IsValidList(list)) && (_ChildFormats == null ? true : _ChildFormats.IsValidList(list));
|
||||
return ((IsNew && !IsDirty) || base.IsValid) && (_FormatContents == null || _FormatContents.IsValidList(list)) && (_FormatDocVersions == null || _FormatDocVersions.IsValidList(list)) && (_FormatFolders == null || _FormatFolders.IsValidList(list)) && (_ChildFormats == null || _ChildFormats.IsValidList(list));
|
||||
}
|
||||
// CSLATODO: Replace base Format.ToString function as necessary
|
||||
/// <summary>
|
||||
/// Overrides Base ToString
|
||||
/// </summary>
|
||||
/// <returns>A string representation of current Format</returns>
|
||||
//public override string ToString()
|
||||
//{
|
||||
// return base.ToString();
|
||||
//}
|
||||
// CSLATODO: Check Format.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 Format</returns>
|
||||
protected override object GetIdValue()
|
||||
{
|
||||
return MyFormatUnique; // Absolutely Unique ID
|
||||
}
|
||||
protected override object GetIdValue() => MyFormatUnique; // Absolutely Unique ID
|
||||
#endregion
|
||||
#region ValidationRules
|
||||
[NonSerialized]
|
||||
@@ -552,8 +523,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()
|
||||
@@ -566,8 +537,6 @@ namespace VEPROMS.CSLA.Library
|
||||
ValidationRules.AddRule(
|
||||
Csla.Validation.CommonRules.StringMaxLength,
|
||||
new Csla.Validation.CommonRules.MaxLengthRuleArgs("Description", 250));
|
||||
//ValidationRules.AddRule(
|
||||
// Csla.Validation.CommonRules.StringRequired, "Data");
|
||||
ValidationRules.AddRule(
|
||||
Csla.Validation.CommonRules.StringMaxLength,
|
||||
new Csla.Validation.CommonRules.MaxLengthRuleArgs("Data", 1073741823));
|
||||
@@ -591,37 +560,11 @@ namespace VEPROMS.CSLA.Library
|
||||
_FormatExtension.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(FormatID, "<Role(s)>");
|
||||
//AuthorizationRules.AllowRead(ParentID, "<Role(s)>");
|
||||
//AuthorizationRules.AllowRead(Name, "<Role(s)>");
|
||||
//AuthorizationRules.AllowRead(Description, "<Role(s)>");
|
||||
//AuthorizationRules.AllowRead(Data, "<Role(s)>");
|
||||
//AuthorizationRules.AllowRead(GenMac, "<Role(s)>");
|
||||
//AuthorizationRules.AllowRead(DTS, "<Role(s)>");
|
||||
//AuthorizationRules.AllowRead(UserID, "<Role(s)>");
|
||||
//AuthorizationRules.AllowWrite(ParentID, "<Role(s)>");
|
||||
//AuthorizationRules.AllowWrite(Name, "<Role(s)>");
|
||||
//AuthorizationRules.AllowWrite(Description, "<Role(s)>");
|
||||
//AuthorizationRules.AllowWrite(Data, "<Role(s)>");
|
||||
//AuthorizationRules.AllowWrite(GenMac, "<Role(s)>");
|
||||
//AuthorizationRules.AllowWrite(DTS, "<Role(s)>");
|
||||
//AuthorizationRules.AllowWrite(UserID, "<Role(s)>");
|
||||
_FormatExtension.AddAuthorizationRules(AuthorizationRules);
|
||||
}
|
||||
protected override void AddInstanceAuthorizationRules()
|
||||
@@ -629,58 +572,14 @@ namespace VEPROMS.CSLA.Library
|
||||
//CSLATODO: Who can read/write which fields
|
||||
_FormatExtension.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 += _FormatContentCount;
|
||||
usedByCount += _FormatDocVersionCount;
|
||||
usedByCount += _FormatFolderCount;
|
||||
usedByCount += _ChildFormatCount;
|
||||
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 _FormatUnique = 0;
|
||||
protected static int FormatUnique
|
||||
{ get { return ++_FormatUnique; } }
|
||||
private int _MyFormatUnique = FormatUnique;
|
||||
public int MyFormatUnique // Absolutely Unique ID - Editable
|
||||
{ get { return _MyFormatUnique; } }
|
||||
protected static int FormatUnique => ++_FormatUnique;
|
||||
private readonly int _MyFormatUnique = FormatUnique;
|
||||
// Absolutely Unique ID - Editable
|
||||
public int MyFormatUnique => _MyFormatUnique;
|
||||
protected Format()
|
||||
{/* require use of factory methods */
|
||||
AddToCache(this);
|
||||
@@ -689,15 +588,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;
|
||||
~Format()
|
||||
{
|
||||
_CountFinalized++;
|
||||
@@ -734,8 +629,6 @@ namespace VEPROMS.CSLA.Library
|
||||
}
|
||||
public static Format New()
|
||||
{
|
||||
if (!CanAddObject())
|
||||
throw new System.Security.SecurityException("User not authorized to add a Format");
|
||||
try
|
||||
{
|
||||
return DataPortal.Create<Format>();
|
||||
@@ -811,8 +704,6 @@ namespace VEPROMS.CSLA.Library
|
||||
}
|
||||
public static Format Get(int formatID)
|
||||
{
|
||||
if (!CanGetObject())
|
||||
throw new System.Security.SecurityException("User not authorized to view a Format");
|
||||
try
|
||||
{
|
||||
Format tmp = GetCachedByPrimaryKey(formatID);
|
||||
@@ -835,8 +726,6 @@ namespace VEPROMS.CSLA.Library
|
||||
}
|
||||
public static Format GetByParentID_Name(int parentID, string name)
|
||||
{
|
||||
if (!CanGetObject())
|
||||
throw new System.Security.SecurityException("User not authorized to view a Format");
|
||||
try
|
||||
{
|
||||
Format tmp = GetCachedByParentID_Name(parentID, name);
|
||||
@@ -862,15 +751,14 @@ namespace VEPROMS.CSLA.Library
|
||||
if (dr.Read()) return new Format(dr, parent);
|
||||
return null;
|
||||
}
|
||||
internal Format(SafeDataReader dr)
|
||||
{
|
||||
ReadData(dr);
|
||||
}
|
||||
internal Format(SafeDataReader dr) => ReadData(dr);
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Keeping until replace CSLA")]
|
||||
private Format(SafeDataReader dr, Format parent)
|
||||
{
|
||||
ReadData(dr);
|
||||
MarkAsChild();
|
||||
}
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Keeping until replace CSLA")]
|
||||
internal Format(SafeDataReader dr, int parentID)
|
||||
{
|
||||
ReadData(dr);
|
||||
@@ -878,8 +766,6 @@ namespace VEPROMS.CSLA.Library
|
||||
}
|
||||
public static void Delete(int formatID)
|
||||
{
|
||||
if (!CanDeleteObject())
|
||||
throw new System.Security.SecurityException("User not authorized to remove a Format");
|
||||
try
|
||||
{
|
||||
DataPortal.Delete(new PKCriteria(formatID));
|
||||
@@ -891,12 +777,6 @@ namespace VEPROMS.CSLA.Library
|
||||
}
|
||||
public override Format Save()
|
||||
{
|
||||
if (IsDeleted && !CanDeleteObject())
|
||||
throw new System.Security.SecurityException("User not authorized to remove a Format");
|
||||
else if (IsNew && !CanAddObject())
|
||||
throw new System.Security.SecurityException("User not authorized to add a Format");
|
||||
else if (!CanEditObject())
|
||||
throw new System.Security.SecurityException("User not authorized to update a Format");
|
||||
try
|
||||
{
|
||||
BuildRefreshList();
|
||||
@@ -916,23 +796,17 @@ namespace VEPROMS.CSLA.Library
|
||||
[Serializable()]
|
||||
protected class PKCriteria
|
||||
{
|
||||
private int _FormatID;
|
||||
public int FormatID
|
||||
{ get { return _FormatID; } }
|
||||
public PKCriteria(int formatID)
|
||||
{
|
||||
_FormatID = formatID;
|
||||
}
|
||||
private readonly int _FormatID;
|
||||
public int FormatID => _FormatID;
|
||||
public PKCriteria(int formatID) => _FormatID = formatID;
|
||||
}
|
||||
[Serializable()]
|
||||
private class ParentID_NameCriteria
|
||||
{
|
||||
private int _ParentID;
|
||||
public int ParentID
|
||||
{ get { return _ParentID; } }
|
||||
private string _Name;
|
||||
public string Name
|
||||
{ get { return _Name; } }
|
||||
private readonly int _ParentID;
|
||||
public int ParentID => _ParentID;
|
||||
private readonly string _Name;
|
||||
public string Name => _Name;
|
||||
public ParentID_NameCriteria(int parentID, string name)
|
||||
{
|
||||
_ParentID = parentID;
|
||||
@@ -1104,43 +978,50 @@ 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 = "addFormat";
|
||||
// Input All Fields - Except Calculated Columns
|
||||
cm.Parameters.AddWithValue("@ParentID", ParentID);
|
||||
cm.Parameters.AddWithValue("@Name", _Name);
|
||||
cm.Parameters.AddWithValue("@Description", _Description);
|
||||
cm.Parameters.AddWithValue("@Data", _Data);
|
||||
cm.Parameters.AddWithValue("@Config", _Config);
|
||||
cm.Parameters.AddWithValue("@GenMac", _GenMac);
|
||||
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
|
||||
cm.Parameters.AddWithValue("@UserID", _UserID);
|
||||
// Output Calculated Columns
|
||||
SqlParameter param_FormatID = new SqlParameter("@newFormatID", SqlDbType.Int);
|
||||
param_FormatID.Direction = ParameterDirection.Output;
|
||||
cm.Parameters.Add(param_FormatID);
|
||||
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
|
||||
_FormatID = (int)cm.Parameters["@newFormatID"].Value;
|
||||
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
|
||||
using (SqlCommand cm = cn.CreateCommand())
|
||||
{
|
||||
cm.CommandType = CommandType.StoredProcedure;
|
||||
cm.CommandTimeout = Database.SQLTimeout;
|
||||
cm.CommandText = "addFormat";
|
||||
// Input All Fields - Except Calculated Columns
|
||||
cm.Parameters.AddWithValue("@ParentID", ParentID);
|
||||
cm.Parameters.AddWithValue("@Name", _Name);
|
||||
cm.Parameters.AddWithValue("@Description", _Description);
|
||||
cm.Parameters.AddWithValue("@Data", _Data);
|
||||
cm.Parameters.AddWithValue("@Config", _Config);
|
||||
cm.Parameters.AddWithValue("@GenMac", _GenMac);
|
||||
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
|
||||
cm.Parameters.AddWithValue("@UserID", _UserID);
|
||||
// Output Calculated Columns
|
||||
SqlParameter param_FormatID = new SqlParameter("@newFormatID", SqlDbType.Int)
|
||||
{
|
||||
Direction = ParameterDirection.Output
|
||||
};
|
||||
cm.Parameters.Add(param_FormatID);
|
||||
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
|
||||
_FormatID = (int)cm.Parameters["@newFormatID"].Value;
|
||||
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
|
||||
}
|
||||
}
|
||||
|
||||
MarkOld();
|
||||
// update child objects
|
||||
if (_FormatFolders != null) _FormatFolders.Update(this);
|
||||
if (_FormatContents != null) _FormatContents.Update(this);
|
||||
if (_FormatDocVersions != null) _FormatDocVersions.Update(this);
|
||||
if (_ChildFormats != null) _ChildFormats.Update(this);
|
||||
_FormatFolders?.Update(this);
|
||||
_FormatContents?.Update(this);
|
||||
_FormatDocVersions?.Update(this);
|
||||
_ChildFormats?.Update(this);
|
||||
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Format.SQLInsert", GetHashCode());
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -1171,11 +1052,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_FormatID = new SqlParameter("@newFormatID", SqlDbType.Int);
|
||||
param_FormatID.Direction = ParameterDirection.Output;
|
||||
SqlParameter param_FormatID = new SqlParameter("@newFormatID", SqlDbType.Int)
|
||||
{
|
||||
Direction = ParameterDirection.Output
|
||||
};
|
||||
cm.Parameters.Add(param_FormatID);
|
||||
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();
|
||||
@@ -1220,41 +1105,46 @@ namespace VEPROMS.CSLA.Library
|
||||
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Format.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 = "updateFormat";
|
||||
// All Fields including Calculated Fields
|
||||
cm.Parameters.AddWithValue("@FormatID", _FormatID);
|
||||
cm.Parameters.AddWithValue("@ParentID", ParentID);
|
||||
cm.Parameters.AddWithValue("@Name", _Name);
|
||||
cm.Parameters.AddWithValue("@Description", _Description);
|
||||
cm.Parameters.AddWithValue("@Data", _Data);
|
||||
cm.Parameters.AddWithValue("@Config", _Config);
|
||||
cm.Parameters.AddWithValue("@GenMac", _GenMac);
|
||||
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 = "updateFormat";
|
||||
// All Fields including Calculated Fields
|
||||
cm.Parameters.AddWithValue("@FormatID", _FormatID);
|
||||
cm.Parameters.AddWithValue("@ParentID", ParentID);
|
||||
cm.Parameters.AddWithValue("@Name", _Name);
|
||||
cm.Parameters.AddWithValue("@Description", _Description);
|
||||
cm.Parameters.AddWithValue("@Data", _Data);
|
||||
cm.Parameters.AddWithValue("@Config", _Config);
|
||||
cm.Parameters.AddWithValue("@GenMac", _GenMac);
|
||||
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 (_FormatFolders != null) _FormatFolders.Update(this);
|
||||
if (_FormatContents != null) _FormatContents.Update(this);
|
||||
if (_FormatDocVersions != null) _FormatDocVersions.Update(this);
|
||||
if (_ChildFormats != null) _ChildFormats.Update(this);
|
||||
_FormatFolders?.Update(this);
|
||||
_FormatContents?.Update(this);
|
||||
_FormatDocVersions?.Update(this);
|
||||
_ChildFormats?.Update(this);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -1265,29 +1155,36 @@ 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 = Format.Add(cn, ref _FormatID, _MyParent, _Name, _Description, _Data, _Config, _GenMac, _DTS, _UserID);
|
||||
else
|
||||
_LastChanged = Format.Update(cn, ref _FormatID, _ParentID, _Name, _Description, _Data, _Config, _GenMac, _DTS, _UserID, ref _LastChanged);
|
||||
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
|
||||
{
|
||||
if (IsNew)
|
||||
_LastChanged = Format.Add(cn, ref _FormatID, _MyParent, _Name, _Description, _Data, _Config, _GenMac, _DTS, _UserID);
|
||||
else
|
||||
_LastChanged = Format.Update(cn, ref _FormatID, _ParentID, _Name, _Description, _Data, _Config, _GenMac, _DTS, _UserID, ref _LastChanged);
|
||||
}
|
||||
|
||||
MarkOld();
|
||||
}
|
||||
if (_FormatFolders != null) _FormatFolders.Update(this);
|
||||
if (_FormatContents != null) _FormatContents.Update(this);
|
||||
if (_FormatDocVersions != null) _FormatDocVersions.Update(this);
|
||||
if (_ChildFormats != null) _ChildFormats.Update(this);
|
||||
_FormatFolders?.Update(this);
|
||||
_FormatContents?.Update(this);
|
||||
_FormatDocVersions?.Update(this);
|
||||
_ChildFormats?.Update(this);
|
||||
}
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Keeping until replace CSLA")]
|
||||
internal void DeleteSelf(Format format)
|
||||
{
|
||||
// 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"];
|
||||
Format.Remove(cn, _FormatID);
|
||||
if (IsNew) return;
|
||||
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
|
||||
{
|
||||
Format.Remove(cn, _FormatID);
|
||||
}
|
||||
|
||||
MarkNew();
|
||||
}
|
||||
[Transactional(TransactionalTypes.TransactionScope)]
|
||||
@@ -1313,8 +1210,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();
|
||||
@@ -1399,16 +1298,10 @@ namespace VEPROMS.CSLA.Library
|
||||
[Serializable()]
|
||||
private class ExistsCommand : CommandBase
|
||||
{
|
||||
private int _FormatID;
|
||||
private readonly int _FormatID;
|
||||
private bool _exists;
|
||||
public bool Exists
|
||||
{
|
||||
get { return _exists; }
|
||||
}
|
||||
public ExistsCommand(int formatID)
|
||||
{
|
||||
_FormatID = formatID;
|
||||
}
|
||||
public bool Exists => _exists;
|
||||
public ExistsCommand(int formatID) => _FormatID = formatID;
|
||||
protected override void DataPortal_Execute()
|
||||
{
|
||||
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Format.DataPortal_Execute", GetHashCode());
|
||||
@@ -1438,7 +1331,7 @@ namespace VEPROMS.CSLA.Library
|
||||
#endregion
|
||||
// Standard Default Code
|
||||
#region extension
|
||||
FormatExtension _FormatExtension = new FormatExtension();
|
||||
readonly FormatExtension _FormatExtension = new FormatExtension();
|
||||
[Serializable()]
|
||||
partial class FormatExtension : extensionBase
|
||||
{
|
||||
@@ -1447,18 +1340,9 @@ namespace VEPROMS.CSLA.Library
|
||||
class extensionBase
|
||||
{
|
||||
// Default Values
|
||||
public virtual int DefaultParentID
|
||||
{
|
||||
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 DefaultParentID => 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)
|
||||
{
|
||||
@@ -1487,61 +1371,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 Format)
|
||||
if (destType == typeof(string) && value is Format format)
|
||||
{
|
||||
// Return the ToString value
|
||||
return ((Format)value).ToString();
|
||||
return format.ToString();
|
||||
}
|
||||
return base.ConvertTo(context, culture, value, destType);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
} // Namespace
|
||||
|
||||
|
||||
//// The following is a sample Extension File. You can use it to create FormatExt.cs
|
||||
//using System;
|
||||
//using System.Collections.Generic;
|
||||
//using System.Text;
|
||||
//using Csla;
|
||||
|
||||
//namespace VEPROMS.CSLA.Library
|
||||
//{
|
||||
// public partial class Format
|
||||
// {
|
||||
// partial class FormatExtension : extensionBase
|
||||
// {
|
||||
// // CSLATODO: Override automatic defaults
|
||||
// public virtual int DefaultParentID
|
||||
// {
|
||||
// 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