This commit is contained in:
2009-01-27 15:45:38 +00:00
parent a95b610d3f
commit 258b503bed
21 changed files with 9137 additions and 14 deletions

View File

@@ -48,6 +48,7 @@ namespace VEPROMS.CSLA.Library
{
RoUsageInfo.Refresh(tmp);
if (tmp._MyContent != null) ContentInfo.Refresh(tmp._MyContent);
if (tmp._MyRODb != null) RODbInfo.Refresh(tmp._MyRODb);
}
}
#endregion
@@ -223,13 +224,45 @@ namespace VEPROMS.CSLA.Library
}
}
private byte[] _LastChanged = new byte[8];//timestamp
private int _RODbID;
public int RODbID
{
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty("RODbID", true);
if (_MyRODb != null) _RODbID = _MyRODb.RODbID;
return _RODbID;
}
}
private RODb _MyRODb;
public RODb MyRODb
{
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty("MyRODb", true);
if (_MyRODb == null && _RODbID != 0) _MyRODb = RODb.Get(_RODbID);
return _MyRODb;
}
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
set
{
CanWriteProperty("MyRODb", true);
if (_MyRODb != value)
{
_MyRODb = value;
PropertyHasChanged();
}
}
}
public override bool IsDirty
{
get { return base.IsDirty || (_MyContent == null ? false : _MyContent.IsDirty); }
get { return base.IsDirty || (_MyContent == null ? false : _MyContent.IsDirty) || (_MyRODb == null ? false : _MyRODb.IsDirty); }
}
public override bool IsValid
{
get { return (IsNew && !IsDirty ? true : base.IsValid) && (_MyContent == null ? true : _MyContent.IsValid); }
get { return (IsNew && !IsDirty ? true : base.IsValid) && (_MyContent == null ? true : _MyContent.IsValid) && (_MyRODb == null ? true : _MyRODb.IsValid); }
}
// TODO: Replace base RoUsage.ToString function as necessary
/// <summary>
@@ -264,6 +297,7 @@ namespace VEPROMS.CSLA.Library
_CheckingBrokenRules = true;
IVEHasBrokenRules hasBrokenRules = null;
if (_MyContent != null && (hasBrokenRules = _MyContent.HasBrokenRules) != null) return hasBrokenRules;
if (_MyRODb != null && (hasBrokenRules = _MyRODb.HasBrokenRules) != null) return hasBrokenRules;
return hasBrokenRules;
}
finally
@@ -297,6 +331,7 @@ namespace VEPROMS.CSLA.Library
ValidationRules.AddRule(
Csla.Validation.CommonRules.StringMaxLength,
new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100));
ValidationRules.AddRule<RoUsage>(MyRODbRequired, "MyRODb");
//ValidationRules.AddDependantProperty("x", "y");
_RoUsageExtension.AddValidationRules(ValidationRules);
// TODO: Add other validation rules
@@ -315,6 +350,15 @@ namespace VEPROMS.CSLA.Library
}
return true;
}
private static bool MyRODbRequired(RoUsage target, Csla.Validation.RuleArgs e)
{
if (target._RODbID == 0 && target._MyRODb == null) // Required field missing
{
e.Description = "Required";
return false;
}
return true;
}
// Sample data comparison validation rule
//private bool StartDateGTEndDate(object target, Csla.Validation.RuleArgs e)
//{
@@ -337,11 +381,13 @@ namespace VEPROMS.CSLA.Library
//AuthorizationRules.AllowRead(Config, "<Role(s)>");
//AuthorizationRules.AllowRead(DTS, "<Role(s)>");
//AuthorizationRules.AllowRead(UserID, "<Role(s)>");
//AuthorizationRules.AllowRead(RODbID, "<Role(s)>");
//AuthorizationRules.AllowWrite(ContentID, "<Role(s)>");
//AuthorizationRules.AllowWrite(ROID, "<Role(s)>");
//AuthorizationRules.AllowWrite(Config, "<Role(s)>");
//AuthorizationRules.AllowWrite(DTS, "<Role(s)>");
//AuthorizationRules.AllowWrite(UserID, "<Role(s)>");
//AuthorizationRules.AllowWrite(RODbID, "<Role(s)>");
_RoUsageExtension.AddAuthorizationRules(AuthorizationRules);
}
protected override void AddInstanceAuthorizationRules()
@@ -417,13 +463,14 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Error on RoUsage.New", ex);
}
}
public static RoUsage New(string roid)
public static RoUsage New(string roid, RODb myRODb)
{
RoUsage tmp = RoUsage.New();
tmp.ROID = roid;
tmp.MyRODb = myRODb;
return tmp;
}
public static RoUsage New(Content myContent, string roid, string config, DateTime dts, string userID)
public static RoUsage New(Content myContent, string roid, string config, DateTime dts, string userID, RODb myRODb)
{
RoUsage tmp = RoUsage.New();
tmp.MyContent = myContent;
@@ -431,11 +478,12 @@ namespace VEPROMS.CSLA.Library
tmp.Config = config;
tmp.DTS = dts;
tmp.UserID = userID;
tmp.MyRODb = myRODb;
return tmp;
}
public static RoUsage MakeRoUsage(Content myContent, string roid, string config, DateTime dts, string userID)
public static RoUsage MakeRoUsage(Content myContent, string roid, string config, DateTime dts, string userID, RODb myRODb)
{
RoUsage tmp = RoUsage.New(myContent, roid, config, dts, userID);
RoUsage tmp = RoUsage.New(myContent, roid, config, dts, userID, myRODb);
if (tmp.IsSavable)
{
RoUsage tmp2 = tmp;
@@ -453,17 +501,18 @@ namespace VEPROMS.CSLA.Library
}
return tmp;
}
public static RoUsage New(Content myContent, string roid, string config)
public static RoUsage New(Content myContent, string roid, string config, RODb myRODb)
{
RoUsage tmp = RoUsage.New();
tmp.MyContent = myContent;
tmp.ROID = roid;
tmp.Config = config;
tmp.MyRODb = myRODb;
return tmp;
}
public static RoUsage MakeRoUsage(Content myContent, string roid, string config)
public static RoUsage MakeRoUsage(Content myContent, string roid, string config, RODb myRODb)
{
RoUsage tmp = RoUsage.New(myContent, roid, config);
RoUsage tmp = RoUsage.New(myContent, roid, config, myRODb);
if (tmp.IsSavable)
{
RoUsage tmp2 = tmp;
@@ -586,6 +635,7 @@ namespace VEPROMS.CSLA.Library
_DTS = dr.GetDateTime("DTS");
_UserID = dr.GetString("UserID");
dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8);
_RODbID = dr.GetInt32("RODbID");
MarkOld();
}
catch (Exception ex)
@@ -662,6 +712,7 @@ namespace VEPROMS.CSLA.Library
try
{
if (_MyContent != null) _MyContent.Update();
if (_MyRODb != null) _MyRODb.Update();
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
using (SqlCommand cm = cn.CreateCommand())
{
@@ -673,6 +724,7 @@ namespace VEPROMS.CSLA.Library
cm.Parameters.AddWithValue("@Config", _Config);
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
cm.Parameters.AddWithValue("@UserID", _UserID);
cm.Parameters.AddWithValue("@RODbID", RODbID);
// Output Calculated Columns
SqlParameter param_ROUsageID = new SqlParameter("@newROUsageID", SqlDbType.Int);
param_ROUsageID.Direction = ParameterDirection.Output;
@@ -698,7 +750,7 @@ namespace VEPROMS.CSLA.Library
}
}
[Transactional(TransactionalTypes.TransactionScope)]
public static byte[] Add(SqlConnection cn, ref int rOUsageID, Content myContent, string roid, string config, DateTime dts, string userID)
public static byte[] Add(SqlConnection cn, ref int rOUsageID, Content myContent, string roid, string config, DateTime dts, string userID, RODb myRODb)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RoUsage.Add", 0);
try
@@ -713,6 +765,7 @@ namespace VEPROMS.CSLA.Library
cm.Parameters.AddWithValue("@Config", config);
if (dts.Year >= 1753 && dts.Year <= 9999) cm.Parameters.AddWithValue("@DTS", dts);
cm.Parameters.AddWithValue("@UserID", userID);
cm.Parameters.AddWithValue("@RODbID", myRODb.RODbID);
// Output Calculated Columns
SqlParameter param_ROUsageID = new SqlParameter("@newROUsageID", SqlDbType.Int);
param_ROUsageID.Direction = ParameterDirection.Output;
@@ -764,6 +817,7 @@ namespace VEPROMS.CSLA.Library
try
{
if (_MyContent != null) _MyContent.Update();
if (_MyRODb != null) _MyRODb.Update();
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
if (base.IsDirty)
{
@@ -779,6 +833,7 @@ namespace VEPROMS.CSLA.Library
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
cm.Parameters.AddWithValue("@UserID", _UserID);
cm.Parameters.AddWithValue("@LastChanged", _LastChanged);
cm.Parameters.AddWithValue("@RODbID", RODbID);
// Output Calculated Columns
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp);
param_LastChanged.Direction = ParameterDirection.Output;
@@ -806,14 +861,14 @@ namespace VEPROMS.CSLA.Library
{
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
if (IsNew)
_LastChanged = RoUsage.Add(cn, ref _ROUsageID, _MyContent, _ROID, _Config, _DTS, _UserID);
_LastChanged = RoUsage.Add(cn, ref _ROUsageID, _MyContent, _ROID, _Config, _DTS, _UserID, _MyRODb);
else
_LastChanged = RoUsage.Update(cn, ref _ROUsageID, _MyContent, _ROID, _Config, _DTS, _UserID, ref _LastChanged);
_LastChanged = RoUsage.Update(cn, ref _ROUsageID, _MyContent, _ROID, _Config, _DTS, _UserID, ref _LastChanged, _MyRODb);
MarkOld();
}
}
[Transactional(TransactionalTypes.TransactionScope)]
public static byte[] Update(SqlConnection cn, ref int rOUsageID, Content myContent, string roid, string config, DateTime dts, string userID, ref byte[] lastChanged)
public static byte[] Update(SqlConnection cn, ref int rOUsageID, Content myContent, string roid, string config, DateTime dts, string userID, ref byte[] lastChanged, RODb myRODb)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RoUsage.Update", 0);
try
@@ -830,6 +885,7 @@ namespace VEPROMS.CSLA.Library
if (dts.Year >= 1753 && dts.Year <= 9999) cm.Parameters.AddWithValue("@DTS", dts);
cm.Parameters.AddWithValue("@UserID", userID);
cm.Parameters.AddWithValue("@LastChanged", lastChanged);
cm.Parameters.AddWithValue("@RODbID", myRODb.RODbID);
// Output Calculated Columns
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp);
param_LastChanged.Direction = ParameterDirection.Output;