CSLA - Generated - Batch - As
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;
|
||||
@@ -57,9 +55,10 @@ namespace VEPROMS.CSLA.Library
|
||||
}
|
||||
ClearRefreshList();
|
||||
}
|
||||
#endregion
|
||||
#region Collection
|
||||
private static List<Assignment> _CacheList = new List<Assignment>();
|
||||
#endregion
|
||||
#region Collection
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
|
||||
private static List<Assignment> _CacheList = new List<Assignment>();
|
||||
protected static void AddToCache(Assignment assignment)
|
||||
{
|
||||
if (!_CacheList.Contains(assignment)) _CacheList.Add(assignment); // In AddToCache
|
||||
@@ -68,7 +67,8 @@ namespace VEPROMS.CSLA.Library
|
||||
{
|
||||
while (_CacheList.Contains(assignment)) _CacheList.Remove(assignment); // In RemoveFromCache
|
||||
}
|
||||
private static Dictionary<string, List<Assignment>> _CacheByPrimaryKey = new Dictionary<string, List<Assignment>>();
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
|
||||
private static Dictionary<string, List<Assignment>> _CacheByPrimaryKey = new Dictionary<string, List<Assignment>>();
|
||||
private static void ConvertListToDictionary()
|
||||
{
|
||||
while (_CacheList.Count > 0) // Move Assignment(s) from temporary _CacheList to _CacheByPrimaryKey
|
||||
@@ -93,16 +93,10 @@ namespace VEPROMS.CSLA.Library
|
||||
#endregion
|
||||
#region Business Methods
|
||||
private string _ErrorMessage = string.Empty;
|
||||
public string ErrorMessage
|
||||
{
|
||||
get { return _ErrorMessage; }
|
||||
}
|
||||
private static int _nextAID = -1;
|
||||
public static int NextAID
|
||||
{
|
||||
get { return _nextAID--; }
|
||||
}
|
||||
private int _AID;
|
||||
public string ErrorMessage => _ErrorMessage;
|
||||
private static int _nextAID = -1;
|
||||
public static int NextAID => _nextAID--;
|
||||
private int _AID;
|
||||
[System.ComponentModel.DataObjectField(true, true)]
|
||||
public int AID
|
||||
{
|
||||
@@ -310,40 +304,17 @@ namespace VEPROMS.CSLA.Library
|
||||
if (base.IsDirty || list.Contains(this))
|
||||
return base.IsDirty;
|
||||
list.Add(this);
|
||||
return base.IsDirty || (_MyFolder == null ? false : _MyFolder.IsDirtyList(list)) || (_MyGroup == null ? false : _MyGroup.IsDirtyList(list)) || (_MyRole == null ? false : _MyRole.IsDirtyList(list));
|
||||
return base.IsDirty || (_MyFolder != null && _MyFolder.IsDirtyList(list)) || (_MyGroup != null && _MyGroup.IsDirtyList(list)) || (_MyRole != null && _MyRole.IsDirtyList(list));
|
||||
}
|
||||
public override bool IsValid
|
||||
{
|
||||
get { return IsValidList(new List<object>()); }
|
||||
}
|
||||
public bool IsValidList(List<object> list)
|
||||
{
|
||||
if(list.Contains(this))
|
||||
return (IsNew && !IsDirty) ? true : base.IsValid;
|
||||
list.Add(this);
|
||||
return ((IsNew && !IsDirty) ? true : base.IsValid) && (_MyFolder == null ? true : _MyFolder.IsValidList(list)) && (_MyGroup == null ? true : _MyGroup.IsValidList(list)) && (_MyRole == null ? true : _MyRole.IsValidList(list));
|
||||
}
|
||||
// CSLATODO: Replace base Assignment.ToString function as necessary
|
||||
/// <summary>
|
||||
/// Overrides Base ToString
|
||||
/// </summary>
|
||||
/// <returns>A string representation of current Assignment</returns>
|
||||
//public override string ToString()
|
||||
//{
|
||||
// return base.ToString();
|
||||
//}
|
||||
// CSLATODO: Check Assignment.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 Assignment</returns>
|
||||
protected override object GetIdValue()
|
||||
{
|
||||
return MyAssignmentUnique; // Absolutely Unique ID
|
||||
}
|
||||
#endregion
|
||||
#region ValidationRules
|
||||
[NonSerialized]
|
||||
// CSLATODO: Check Assignment.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 Assignment</returns>
|
||||
protected override object GetIdValue() => MyAssignmentUnique; // Absolutely Unique ID
|
||||
#endregion
|
||||
#region ValidationRules
|
||||
[NonSerialized]
|
||||
private bool _CheckingBrokenRules = false;
|
||||
public IVEHasBrokenRules HasBrokenRules
|
||||
{
|
||||
@@ -371,8 +342,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()
|
||||
@@ -389,16 +360,11 @@ namespace VEPROMS.CSLA.Library
|
||||
ValidationRules.AddRule(
|
||||
Csla.Validation.CommonRules.StringMaxLength,
|
||||
new Csla.Validation.CommonRules.MaxLengthRuleArgs("UsrID", 100));
|
||||
//ValidationRules.AddDependantProperty("x", "y");
|
||||
_AssignmentExtension.AddValidationRules(ValidationRules);
|
||||
// CSLATODO: Add other validation rules
|
||||
}
|
||||
protected override void AddInstanceBusinessRules()
|
||||
{
|
||||
_AssignmentExtension.AddInstanceValidationRules(ValidationRules);
|
||||
// CSLATODO: Add other validation rules
|
||||
}
|
||||
private static bool StartDateValid(Assignment target, Csla.Validation.RuleArgs e)
|
||||
protected override void AddInstanceBusinessRules() => _AssignmentExtension.AddInstanceValidationRules(ValidationRules);
|
||||
private static bool StartDateValid(Assignment target, Csla.Validation.RuleArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -451,80 +417,14 @@ 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(AID, "<Role(s)>");
|
||||
//AuthorizationRules.AllowRead(GID, "<Role(s)>");
|
||||
//AuthorizationRules.AllowRead(RID, "<Role(s)>");
|
||||
//AuthorizationRules.AllowRead(FolderID, "<Role(s)>");
|
||||
//AuthorizationRules.AllowRead(StartDate, "<Role(s)>");
|
||||
//AuthorizationRules.AllowRead(EndDate, "<Role(s)>");
|
||||
//AuthorizationRules.AllowRead(DTS, "<Role(s)>");
|
||||
//AuthorizationRules.AllowRead(UsrID, "<Role(s)>");
|
||||
//AuthorizationRules.AllowWrite(GID, "<Role(s)>");
|
||||
//AuthorizationRules.AllowWrite(RID, "<Role(s)>");
|
||||
//AuthorizationRules.AllowWrite(FolderID, "<Role(s)>");
|
||||
//AuthorizationRules.AllowWrite(StartDate, "<Role(s)>");
|
||||
//AuthorizationRules.AllowWrite(EndDate, "<Role(s)>");
|
||||
//AuthorizationRules.AllowWrite(DTS, "<Role(s)>");
|
||||
//AuthorizationRules.AllowWrite(UsrID, "<Role(s)>");
|
||||
_AssignmentExtension.AddAuthorizationRules(AuthorizationRules);
|
||||
}
|
||||
protected override void AddInstanceAuthorizationRules()
|
||||
{
|
||||
//CSLATODO: Who can read/write which fields
|
||||
_AssignmentExtension.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;
|
||||
}
|
||||
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; } }
|
||||
private static int _AssignmentUnique = 0;
|
||||
protected static int AssignmentUnique
|
||||
{ get { return ++_AssignmentUnique; } }
|
||||
private int _MyAssignmentUnique = AssignmentUnique;
|
||||
public int MyAssignmentUnique // Absolutely Unique ID - Editable
|
||||
{ get { return _MyAssignmentUnique; } }
|
||||
#endregion
|
||||
#region Factory Methods
|
||||
public int CurrentEditLevel => EditLevel;
|
||||
private static int _AssignmentUnique = 0;
|
||||
protected static int AssignmentUnique => ++_AssignmentUnique;
|
||||
private readonly int _MyAssignmentUnique = AssignmentUnique;
|
||||
// Absolutely Unique ID - Editable
|
||||
public int MyAssignmentUnique => _MyAssignmentUnique;
|
||||
protected Assignment()
|
||||
{/* require use of factory methods */
|
||||
AddToCache(this);
|
||||
@@ -533,16 +433,12 @@ 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; } }
|
||||
~Assignment()
|
||||
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;
|
||||
~Assignment()
|
||||
{
|
||||
_CountFinalized++;
|
||||
}
|
||||
@@ -566,8 +462,6 @@ namespace VEPROMS.CSLA.Library
|
||||
}
|
||||
public static Assignment New()
|
||||
{
|
||||
if (!CanAddObject())
|
||||
throw new System.Security.SecurityException("User not authorized to add a Assignment");
|
||||
try
|
||||
{
|
||||
return DataPortal.Create<Assignment>();
|
||||
@@ -640,8 +534,6 @@ namespace VEPROMS.CSLA.Library
|
||||
}
|
||||
public static Assignment Get(int aid)
|
||||
{
|
||||
if (!CanGetObject())
|
||||
throw new System.Security.SecurityException("User not authorized to view a Assignment");
|
||||
try
|
||||
{
|
||||
Assignment tmp = GetCachedByPrimaryKey(aid);
|
||||
@@ -667,14 +559,9 @@ namespace VEPROMS.CSLA.Library
|
||||
if (dr.Read()) return new Assignment(dr);
|
||||
return null;
|
||||
}
|
||||
internal Assignment(SafeDataReader dr)
|
||||
internal Assignment(SafeDataReader dr) => ReadData(dr);
|
||||
public static void Delete(int aid)
|
||||
{
|
||||
ReadData(dr);
|
||||
}
|
||||
public static void Delete(int aid)
|
||||
{
|
||||
if (!CanDeleteObject())
|
||||
throw new System.Security.SecurityException("User not authorized to remove a Assignment");
|
||||
try
|
||||
{
|
||||
DataPortal.Delete(new PKCriteria(aid));
|
||||
@@ -686,12 +573,6 @@ namespace VEPROMS.CSLA.Library
|
||||
}
|
||||
public override Assignment Save()
|
||||
{
|
||||
if (IsDeleted && !CanDeleteObject())
|
||||
throw new System.Security.SecurityException("User not authorized to remove a Assignment");
|
||||
else if (IsNew && !CanAddObject())
|
||||
throw new System.Security.SecurityException("User not authorized to add a Assignment");
|
||||
else if (!CanEditObject())
|
||||
throw new System.Security.SecurityException("User not authorized to update a Assignment");
|
||||
try
|
||||
{
|
||||
BuildRefreshList();
|
||||
@@ -711,14 +592,10 @@ namespace VEPROMS.CSLA.Library
|
||||
[Serializable()]
|
||||
protected class PKCriteria
|
||||
{
|
||||
private int _AID;
|
||||
public int AID
|
||||
{ get { return _AID; } }
|
||||
public PKCriteria(int aid)
|
||||
{
|
||||
_AID = aid;
|
||||
}
|
||||
}
|
||||
private readonly int _AID;
|
||||
public int AID => _AID;
|
||||
public PKCriteria(int aid) => _AID = aid;
|
||||
}
|
||||
// CSLATODO: If Create needs to access DB - It should not be marked RunLocal
|
||||
[RunLocal()]
|
||||
private new void DataPortal_Create()
|
||||
@@ -818,44 +695,51 @@ namespace VEPROMS.CSLA.Library
|
||||
[Transactional(TransactionalTypes.TransactionScope)]
|
||||
internal void SQLInsert()
|
||||
{
|
||||
if (!this.IsDirty) return;
|
||||
if (!IsDirty) return;
|
||||
try
|
||||
{
|
||||
if (_MyFolder != null) _MyFolder.Update();
|
||||
if (_MyGroup != null) _MyGroup.Update();
|
||||
if (_MyRole != null) _MyRole.Update();
|
||||
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
|
||||
using (SqlCommand cm = cn.CreateCommand())
|
||||
{
|
||||
cm.CommandType = CommandType.StoredProcedure;
|
||||
cm.CommandTimeout = Database.SQLTimeout;
|
||||
cm.CommandText = "addAssignment";
|
||||
// Input All Fields - Except Calculated Columns
|
||||
cm.Parameters.AddWithValue("@GID", GID);
|
||||
cm.Parameters.AddWithValue("@RID", RID);
|
||||
cm.Parameters.AddWithValue("@FolderID", FolderID);
|
||||
cm.Parameters.AddWithValue("@StartDate", new SmartDate(_StartDate).DBValue);
|
||||
cm.Parameters.AddWithValue("@EndDate", new SmartDate(_EndDate).DBValue);
|
||||
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
|
||||
cm.Parameters.AddWithValue("@UsrID", _UsrID);
|
||||
// Output Calculated Columns
|
||||
SqlParameter param_AID = new SqlParameter("@newAID", SqlDbType.Int);
|
||||
param_AID.Direction = ParameterDirection.Output;
|
||||
cm.Parameters.Add(param_AID);
|
||||
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
|
||||
_AID = (int)cm.Parameters["@newAID"].Value;
|
||||
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
|
||||
}
|
||||
MarkOld();
|
||||
// update child objects
|
||||
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Assignment.SQLInsert", GetHashCode());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_MyFolder?.Update();
|
||||
_MyGroup?.Update();
|
||||
_MyRole?.Update();
|
||||
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
|
||||
{
|
||||
using (SqlCommand cm = cn.CreateCommand())
|
||||
{
|
||||
cm.CommandType = CommandType.StoredProcedure;
|
||||
cm.CommandTimeout = Database.SQLTimeout;
|
||||
cm.CommandText = "addAssignment";
|
||||
// Input All Fields - Except Calculated Columns
|
||||
cm.Parameters.AddWithValue("@GID", GID);
|
||||
cm.Parameters.AddWithValue("@RID", RID);
|
||||
cm.Parameters.AddWithValue("@FolderID", FolderID);
|
||||
cm.Parameters.AddWithValue("@StartDate", new SmartDate(_StartDate).DBValue);
|
||||
cm.Parameters.AddWithValue("@EndDate", new SmartDate(_EndDate).DBValue);
|
||||
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
|
||||
cm.Parameters.AddWithValue("@UsrID", _UsrID);
|
||||
// Output Calculated Columns
|
||||
SqlParameter param_AID = new SqlParameter("@newAID", SqlDbType.Int)
|
||||
{
|
||||
Direction = ParameterDirection.Output
|
||||
};
|
||||
cm.Parameters.Add(param_AID);
|
||||
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
|
||||
_AID = (int)cm.Parameters["@newAID"].Value;
|
||||
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
|
||||
}
|
||||
}
|
||||
|
||||
MarkOld();
|
||||
// update child objects
|
||||
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Assignment.SQLInsert", GetHashCode());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (_MyLog.IsErrorEnabled) _MyLog.Error("Assignment.SQLInsert", ex);
|
||||
_ErrorMessage = ex.Message;
|
||||
@@ -881,13 +765,17 @@ namespace VEPROMS.CSLA.Library
|
||||
cm.Parameters.AddWithValue("@EndDate", endDate.DBValue);
|
||||
if (dts.Year >= 1753 && dts.Year <= 9999) cm.Parameters.AddWithValue("@DTS", dts);
|
||||
cm.Parameters.AddWithValue("@UsrID", usrID);
|
||||
// Output Calculated Columns
|
||||
SqlParameter param_AID = new SqlParameter("@newAID", SqlDbType.Int);
|
||||
param_AID.Direction = ParameterDirection.Output;
|
||||
cm.Parameters.Add(param_AID);
|
||||
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp);
|
||||
param_LastChanged.Direction = ParameterDirection.Output;
|
||||
cm.Parameters.Add(param_LastChanged);
|
||||
// Output Calculated Columns
|
||||
SqlParameter param_AID = new SqlParameter("@newAID", SqlDbType.Int)
|
||||
{
|
||||
Direction = ParameterDirection.Output
|
||||
};
|
||||
cm.Parameters.Add(param_AID);
|
||||
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
|
||||
@@ -930,42 +818,47 @@ namespace VEPROMS.CSLA.Library
|
||||
if (!IsDirty) return; // If not dirty - nothing to do
|
||||
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Assignment.SQLUpdate", GetHashCode());
|
||||
try
|
||||
{
|
||||
if (_MyFolder != null) _MyFolder.Update();
|
||||
if (_MyGroup != null) _MyGroup.Update();
|
||||
if (_MyRole != null) _MyRole.Update();
|
||||
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
|
||||
if (base.IsDirty)
|
||||
{
|
||||
using (SqlCommand cm = cn.CreateCommand())
|
||||
{
|
||||
cm.CommandType = CommandType.StoredProcedure;
|
||||
cm.CommandTimeout = Database.SQLTimeout;
|
||||
cm.CommandText = "updateAssignment";
|
||||
// All Fields including Calculated Fields
|
||||
cm.Parameters.AddWithValue("@AID", _AID);
|
||||
cm.Parameters.AddWithValue("@GID", GID);
|
||||
cm.Parameters.AddWithValue("@RID", RID);
|
||||
cm.Parameters.AddWithValue("@FolderID", FolderID);
|
||||
cm.Parameters.AddWithValue("@StartDate", new SmartDate(_StartDate).DBValue);
|
||||
cm.Parameters.AddWithValue("@EndDate", new SmartDate(_EndDate).DBValue);
|
||||
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
|
||||
cm.Parameters.AddWithValue("@UsrID", _UsrID);
|
||||
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;
|
||||
}
|
||||
}
|
||||
MarkOld();
|
||||
// use the open connection to update child objects
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_MyFolder?.Update();
|
||||
_MyGroup?.Update();
|
||||
_MyRole?.Update();
|
||||
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
|
||||
{
|
||||
if (base.IsDirty)
|
||||
{
|
||||
using (SqlCommand cm = cn.CreateCommand())
|
||||
{
|
||||
cm.CommandType = CommandType.StoredProcedure;
|
||||
cm.CommandTimeout = Database.SQLTimeout;
|
||||
cm.CommandText = "updateAssignment";
|
||||
// All Fields including Calculated Fields
|
||||
cm.Parameters.AddWithValue("@AID", _AID);
|
||||
cm.Parameters.AddWithValue("@GID", GID);
|
||||
cm.Parameters.AddWithValue("@RID", RID);
|
||||
cm.Parameters.AddWithValue("@FolderID", FolderID);
|
||||
cm.Parameters.AddWithValue("@StartDate", new SmartDate(_StartDate).DBValue);
|
||||
cm.Parameters.AddWithValue("@EndDate", new SmartDate(_EndDate).DBValue);
|
||||
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
|
||||
cm.Parameters.AddWithValue("@UsrID", _UsrID);
|
||||
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
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (_MyLog.IsErrorEnabled) _MyLog.Error("Assignment.SQLUpdate", ex);
|
||||
_ErrorMessage = ex.Message;
|
||||
@@ -974,17 +867,20 @@ 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 = Assignment.Add(cn, ref _AID, _MyGroup, _MyRole, _MyFolder, new SmartDate(_StartDate), new SmartDate(_EndDate), _DTS, _UsrID);
|
||||
else
|
||||
_LastChanged = Assignment.Update(cn, ref _AID, _GID, _RID, _FolderID, new SmartDate(_StartDate), new SmartDate(_EndDate), _DTS, _UsrID, ref _LastChanged);
|
||||
MarkOld();
|
||||
}
|
||||
}
|
||||
{
|
||||
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
|
||||
{
|
||||
if (IsNew)
|
||||
_LastChanged = Assignment.Add(cn, ref _AID, _MyGroup, _MyRole, _MyFolder, new SmartDate(_StartDate), new SmartDate(_EndDate), _DTS, _UsrID);
|
||||
else
|
||||
_LastChanged = Assignment.Update(cn, ref _AID, _GID, _RID, _FolderID, new SmartDate(_StartDate), new SmartDate(_EndDate), _DTS, _UsrID, ref _LastChanged);
|
||||
}
|
||||
|
||||
MarkOld();
|
||||
}
|
||||
}
|
||||
[Transactional(TransactionalTypes.TransactionScope)]
|
||||
public static byte[] Update(SqlConnection cn, ref int aid, int gid, int rid, int folderID, SmartDate startDate, SmartDate endDate, DateTime dts, string usrID, ref byte[] lastChanged)
|
||||
{
|
||||
@@ -1006,10 +902,12 @@ namespace VEPROMS.CSLA.Library
|
||||
if (dts.Year >= 1753 && dts.Year <= 9999) cm.Parameters.AddWithValue("@DTS", dts);
|
||||
cm.Parameters.AddWithValue("@UsrID", usrID);
|
||||
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);
|
||||
// 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
|
||||
@@ -1022,12 +920,9 @@ namespace VEPROMS.CSLA.Library
|
||||
throw new DbCslaException("Assignment.Update", ex);
|
||||
}
|
||||
}
|
||||
[Transactional(TransactionalTypes.TransactionScope)]
|
||||
protected override void DataPortal_DeleteSelf()
|
||||
{
|
||||
DataPortal_Delete(new PKCriteria(_AID));
|
||||
}
|
||||
[Transactional(TransactionalTypes.TransactionScope)]
|
||||
[Transactional(TransactionalTypes.TransactionScope)]
|
||||
protected override void DataPortal_DeleteSelf() => DataPortal_Delete(new PKCriteria(_AID));
|
||||
[Transactional(TransactionalTypes.TransactionScope)]
|
||||
private void DataPortal_Delete(PKCriteria criteria)
|
||||
{
|
||||
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Assignment.DataPortal_Delete", GetHashCode());
|
||||
@@ -1093,17 +988,11 @@ namespace VEPROMS.CSLA.Library
|
||||
[Serializable()]
|
||||
private class ExistsCommand : CommandBase
|
||||
{
|
||||
private int _AID;
|
||||
private readonly int _AID;
|
||||
private bool _exists;
|
||||
public bool Exists
|
||||
{
|
||||
get { return _exists; }
|
||||
}
|
||||
public ExistsCommand(int aid)
|
||||
{
|
||||
_AID = aid;
|
||||
}
|
||||
protected override void DataPortal_Execute()
|
||||
public bool Exists => _exists;
|
||||
public ExistsCommand(int aid) => _AID = aid;
|
||||
protected override void DataPortal_Execute()
|
||||
{
|
||||
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Assignment.DataPortal_Execute", GetHashCode());
|
||||
try
|
||||
@@ -1129,10 +1018,10 @@ namespace VEPROMS.CSLA.Library
|
||||
}
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
// Standard Default Code
|
||||
#region extension
|
||||
AssignmentExtension _AssignmentExtension = new AssignmentExtension();
|
||||
#endregion
|
||||
// Standard Default Code
|
||||
#region extension
|
||||
readonly AssignmentExtension _AssignmentExtension = new AssignmentExtension();
|
||||
[Serializable()]
|
||||
partial class AssignmentExtension : extensionBase
|
||||
{
|
||||
@@ -1140,21 +1029,12 @@ namespace VEPROMS.CSLA.Library
|
||||
[Serializable()]
|
||||
class extensionBase
|
||||
{
|
||||
// Default Values
|
||||
public virtual string DefaultStartDate
|
||||
{
|
||||
get { return DateTime.Now.ToShortDateString(); }
|
||||
}
|
||||
public virtual DateTime DefaultDTS
|
||||
{
|
||||
get { return DateTime.Now; }
|
||||
}
|
||||
public virtual string DefaultUsrID
|
||||
{
|
||||
get { return Volian.Base.Library.VlnSettings.UserID; }
|
||||
}
|
||||
// Authorization Rules
|
||||
public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules)
|
||||
// Default Values
|
||||
public virtual string DefaultStartDate => DateTime.Now.ToShortDateString();
|
||||
public virtual DateTime DefaultDTS => DateTime.Now;
|
||||
public virtual string DefaultUsrID => Volian.Base.Library.VlnSettings.UserID;
|
||||
// Authorization Rules
|
||||
public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules)
|
||||
{
|
||||
// Needs to be overriden to add new authorization rules
|
||||
}
|
||||
@@ -1181,61 +1061,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 Assignment)
|
||||
if (destType == typeof(string) && value is Assignment assignmnt)
|
||||
{
|
||||
// Return the ToString value
|
||||
return ((Assignment)value).ToString();
|
||||
return assignmnt.ToString();
|
||||
}
|
||||
return base.ConvertTo(context, culture, value, destType);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
} // Namespace
|
||||
|
||||
|
||||
//// The following is a sample Extension File. You can use it to create AssignmentExt.cs
|
||||
//using System;
|
||||
//using System.Collections.Generic;
|
||||
//using System.Text;
|
||||
//using Csla;
|
||||
|
||||
//namespace VEPROMS.CSLA.Library
|
||||
//{
|
||||
// public partial class Assignment
|
||||
// {
|
||||
// partial class AssignmentExtension : extensionBase
|
||||
// {
|
||||
// // CSLATODO: Override automatic defaults
|
||||
// public virtual SmartDate DefaultStartDate
|
||||
// {
|
||||
// get { return DateTime.Now.ToShortDateString(); }
|
||||
// }
|
||||
// public virtual DateTime DefaultDTS
|
||||
// {
|
||||
// get { return DateTime.Now; }
|
||||
// }
|
||||
// public virtual string DefaultUsrID
|
||||
// {
|
||||
// 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