477 lines
18 KiB
C#
477 lines
18 KiB
C#
// ========================================================================
|
|
// Copyright 2007 - Volian Enterprises, Inc. All rights reserved.
|
|
// Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE
|
|
// ------------------------------------------------------------------------
|
|
// $Workfile: $ $Revision: $
|
|
// $Author: $ $Date: $
|
|
//
|
|
// $History: $
|
|
// ========================================================================
|
|
|
|
using System;
|
|
using System.Data.SqlClient;
|
|
using Csla;
|
|
using Csla.Data;
|
|
using System.ComponentModel;
|
|
using System.Collections.Generic;
|
|
using Csla.Validation;
|
|
namespace VEPROMS.CSLA.Library
|
|
{
|
|
/// <summary>
|
|
/// RevisionVersion Generated by MyGeneration using the CSLA Object Mapping template
|
|
/// </summary>
|
|
[Serializable()]
|
|
[TypeConverter(typeof(RevisionVersionConverter))]
|
|
public partial class RevisionVersion : BusinessBase<RevisionVersion>, IVEHasBrokenRules, IDisposable
|
|
{
|
|
#region Log4Net
|
|
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
|
|
#endregion
|
|
#region Business Methods
|
|
private readonly string _ErrorMessage = string.Empty;
|
|
public string ErrorMessage => _ErrorMessage;
|
|
private int _VersionID;
|
|
[System.ComponentModel.DataObjectField(true, true)]
|
|
public int VersionID
|
|
{
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
get
|
|
{
|
|
if (_MyVersion != null) _VersionID = _MyVersion.VersionID;
|
|
return _VersionID;
|
|
}
|
|
}
|
|
private Version _MyVersion;
|
|
[System.ComponentModel.DataObjectField(true, true)]
|
|
public Version MyVersion
|
|
{
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
get
|
|
{
|
|
if (_MyVersion == null && _VersionID != 0) _MyVersion = Version.Get(_VersionID);
|
|
return _MyVersion;
|
|
}
|
|
}
|
|
private int _StageID;
|
|
public int StageID
|
|
{
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
get
|
|
{
|
|
if (_MyStage != null) _StageID = _MyStage.StageID;
|
|
return _StageID;
|
|
}
|
|
}
|
|
private Stage _MyStage;
|
|
public Stage MyStage
|
|
{
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
get
|
|
{
|
|
if (_MyStage == null && _StageID != 0) _MyStage = Stage.GetJustStage(_StageID);
|
|
return _MyStage;
|
|
}
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
set
|
|
{
|
|
if (_MyStage != value)
|
|
{
|
|
_MyStage = value;
|
|
_StageID = value.StageID;// Update underlying data field
|
|
PropertyHasChanged();
|
|
}
|
|
}
|
|
}
|
|
private byte[] _PDF;
|
|
public byte[] PDF
|
|
{
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
get
|
|
{
|
|
return _PDF;
|
|
}
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
set
|
|
{
|
|
if (_PDF != value)
|
|
{
|
|
_PDF = value;
|
|
PropertyHasChanged();
|
|
}
|
|
}
|
|
}
|
|
private byte[] _SummaryPDF;
|
|
public byte[] SummaryPDF
|
|
{
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
get
|
|
{
|
|
return _SummaryPDF;
|
|
}
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
set
|
|
{
|
|
if (_SummaryPDF != value)
|
|
{
|
|
_SummaryPDF = value;
|
|
PropertyHasChanged();
|
|
}
|
|
}
|
|
}
|
|
private string _ApprovedXML;
|
|
public string ApprovedXML
|
|
{
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
get
|
|
{
|
|
return _ApprovedXML;
|
|
}
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
set
|
|
{
|
|
if (_ApprovedXML != value)
|
|
{
|
|
_ApprovedXML = value;
|
|
PropertyHasChanged();
|
|
}
|
|
}
|
|
}
|
|
private DateTime _DTS = new DateTime();
|
|
public DateTime DTS
|
|
{
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
get
|
|
{
|
|
return _DTS;
|
|
}
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
set
|
|
{
|
|
if (_DTS != value)
|
|
{
|
|
_DTS = value;
|
|
PropertyHasChanged();
|
|
}
|
|
}
|
|
}
|
|
private string _UserID = string.Empty;
|
|
public string UserID
|
|
{
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
get
|
|
{
|
|
return _UserID;
|
|
}
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
set
|
|
{
|
|
if (value == null) value = string.Empty;
|
|
if (_UserID != value)
|
|
{
|
|
_UserID = value;
|
|
PropertyHasChanged();
|
|
}
|
|
}
|
|
}
|
|
private byte[] _LastChanged = new byte[8];//timestamp
|
|
private string _Stage_Name = string.Empty;
|
|
public string Stage_Name
|
|
{
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
get
|
|
{
|
|
return _Stage_Name;
|
|
}
|
|
}
|
|
private string _Stage_Description = string.Empty;
|
|
public string Stage_Description
|
|
{
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
get
|
|
{
|
|
return _Stage_Description;
|
|
}
|
|
}
|
|
private int _Stage_IsApproved;
|
|
public int Stage_IsApproved
|
|
{
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
get
|
|
{
|
|
return _Stage_IsApproved;
|
|
}
|
|
}
|
|
private DateTime _Stage_DTS = new DateTime();
|
|
public DateTime Stage_DTS
|
|
{
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
get
|
|
{
|
|
return _Stage_DTS;
|
|
}
|
|
}
|
|
private string _Stage_UserID = string.Empty;
|
|
public string Stage_UserID
|
|
{
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
get
|
|
{
|
|
return _Stage_UserID;
|
|
}
|
|
}
|
|
// CSLATODO: Check RevisionVersion.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 RevisionVersion</returns>
|
|
protected override object GetIdValue() => MyRevisionVersionUnique; // Absolutely Unique ID
|
|
public override bool IsDirty
|
|
{
|
|
get
|
|
{
|
|
if (base.IsDirty)
|
|
return true;
|
|
return IsDirtyList(new List<object>());
|
|
}
|
|
}
|
|
public bool IsDirtyList(List<object> list)
|
|
{
|
|
if (base.IsDirty || list.Contains(this))
|
|
return base.IsDirty;
|
|
list.Add(this);
|
|
return base.IsDirty || (_MyStage != null && _MyStage.IsDirtyList(list));
|
|
}
|
|
public override bool IsValid => IsValidList(new List<object>());
|
|
public bool IsValidList(List<object> list)
|
|
{
|
|
if (list.Contains(this))
|
|
return (IsNew && !IsDirty) || base.IsValid;
|
|
list.Add(this);
|
|
return ((IsNew && !IsDirty) || base.IsValid) && (_MyStage == null || _MyStage.IsValidList(list));
|
|
}
|
|
#endregion
|
|
#region ValidationRules
|
|
[NonSerialized]
|
|
private bool _CheckingBrokenRules = false;
|
|
public IVEHasBrokenRules HasBrokenRules
|
|
{
|
|
get
|
|
{
|
|
if (_CheckingBrokenRules) return null;
|
|
if (BrokenRulesCollection.Count > 0) return this;
|
|
try
|
|
{
|
|
_CheckingBrokenRules = true;
|
|
IVEHasBrokenRules hasBrokenRules = null;
|
|
if (_MyStage != null && (hasBrokenRules = _MyStage.HasBrokenRules) != null) return hasBrokenRules;
|
|
return hasBrokenRules;
|
|
}
|
|
finally
|
|
{
|
|
_CheckingBrokenRules = false;
|
|
}
|
|
}
|
|
}
|
|
public BrokenRulesCollection BrokenRules
|
|
{
|
|
get
|
|
{
|
|
IVEHasBrokenRules hasBrokenRules = HasBrokenRules;
|
|
if (Equals(hasBrokenRules)) return BrokenRulesCollection;
|
|
return hasBrokenRules?.BrokenRules;
|
|
}
|
|
}
|
|
protected override void AddBusinessRules()
|
|
{
|
|
ValidationRules.AddRule<RevisionVersion>(MyStageRequired, "MyStage");
|
|
ValidationRules.AddRule(
|
|
Csla.Validation.CommonRules.StringRequired, "UserID");
|
|
ValidationRules.AddRule(
|
|
Csla.Validation.CommonRules.StringMaxLength,
|
|
new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 200));
|
|
// CSLATODO: Add other validation rules
|
|
}
|
|
private static bool MyStageRequired(RevisionVersion target, Csla.Validation.RuleArgs e)
|
|
{
|
|
if (target._StageID == 0 && target._MyStage == null) // Required field missing
|
|
{
|
|
e.Description = "Required";
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
#endregion
|
|
#region Authorization Rules
|
|
protected override void AddAuthorizationRules()
|
|
{
|
|
//CSLATODO: Who can read/write which fields
|
|
}
|
|
#endregion
|
|
#region Factory Methods
|
|
public int CurrentEditLevel => EditLevel;
|
|
private static int _RevisionVersionUnique = 0;
|
|
private static int RevisionVersionUnique => ++_RevisionVersionUnique;
|
|
private readonly int _MyRevisionVersionUnique = RevisionVersionUnique;
|
|
// Absolutely Unique ID - Editable FK
|
|
public int MyRevisionVersionUnique => _MyRevisionVersionUnique;
|
|
internal static RevisionVersion New(Stage myStage, DateTime dts, string userID) => new RevisionVersion(myStage, dts, userID);
|
|
internal static RevisionVersion Get(SafeDataReader dr) => new RevisionVersion(dr);
|
|
public RevisionVersion()
|
|
{
|
|
MarkAsChild();
|
|
_VersionID = Version.NextVersionID;
|
|
|
|
ValidationRules.CheckRules();
|
|
}
|
|
private RevisionVersion(Stage myStage, DateTime dts, string userID)
|
|
{
|
|
MarkAsChild();
|
|
// CSLATODO: Add any initialization & defaults
|
|
_VersionID = Version.NextVersionID;
|
|
|
|
_MyStage = myStage;
|
|
_DTS = dts;
|
|
_UserID = userID;
|
|
ValidationRules.CheckRules();
|
|
}
|
|
internal RevisionVersion(SafeDataReader dr)
|
|
{
|
|
MarkAsChild();
|
|
Fetch(dr);
|
|
}
|
|
private bool _Disposed = false;
|
|
private static int _CountCreated = 0;
|
|
private static int _CountDisposed = 0;
|
|
private static int _CountFinalized = 0;
|
|
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;
|
|
~RevisionVersion()
|
|
{
|
|
_CountFinalized++;
|
|
}
|
|
public void Dispose()
|
|
{
|
|
if (_Disposed) return;
|
|
_CountDisposed++;
|
|
_Disposed = true;
|
|
}
|
|
#endregion
|
|
#region Data Access Portal
|
|
private void Fetch(SafeDataReader dr)
|
|
{
|
|
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RevisionVersion.FetchDR", GetHashCode());
|
|
try
|
|
{
|
|
_VersionID = dr.GetInt32("VersionID");
|
|
_StageID = dr.GetInt32("StageID");
|
|
_PDF = (byte[])dr.GetValue("PDF");
|
|
_SummaryPDF = (byte[])dr.GetValue("SummaryPDF");
|
|
_DTS = dr.GetDateTime("DTS");
|
|
_UserID = dr.GetString("UserID");
|
|
dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8);
|
|
_Stage_Name = dr.GetString("Stage_Name");
|
|
_Stage_Description = dr.GetString("Stage_Description");
|
|
_Stage_IsApproved = dr.GetInt32("Stage_IsApproved");
|
|
_Stage_DTS = dr.GetDateTime("Stage_DTS");
|
|
_Stage_UserID = dr.GetString("Stage_UserID");
|
|
}
|
|
catch (Exception ex) // FKItem Fetch
|
|
{
|
|
if (_MyLog.IsErrorEnabled) _MyLog.Error("RevisionVersion.FetchDR", ex);
|
|
throw new DbCslaException("RevisionVersion.Fetch", ex);
|
|
}
|
|
MarkOld();
|
|
}
|
|
internal void Insert(Revision myRevision)
|
|
{
|
|
// if we're not dirty then don't update the database
|
|
if (!IsDirty) return;
|
|
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
|
|
{
|
|
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
|
|
_LastChanged = Version.Add(cn, ref _VersionID, myRevision, _MyStage, _PDF, _SummaryPDF, _ApprovedXML, _DTS, _UserID);
|
|
}
|
|
|
|
MarkOld();
|
|
}
|
|
internal void Update(Revision myRevision)
|
|
{
|
|
// if we're not dirty then don't update the database
|
|
if (!IsDirty) return;
|
|
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
|
|
{
|
|
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
|
|
_LastChanged = Version.Update(cn, ref _VersionID, myRevision.RevisionID, _StageID, _PDF, _SummaryPDF, _ApprovedXML, _DTS, _UserID, ref _LastChanged);
|
|
}
|
|
|
|
MarkOld();
|
|
}
|
|
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Keeping until replace CSLA")]
|
|
internal void DeleteSelf(Revision myRevision)
|
|
{
|
|
// if we're not dirty then don't update the database
|
|
if (!IsDirty) return;
|
|
// if we're new then don't update the database
|
|
if (IsNew) return;
|
|
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
|
|
{
|
|
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
|
|
Version.Remove(cn, _VersionID);
|
|
}
|
|
|
|
MarkNew();
|
|
}
|
|
#endregion
|
|
// Standard Default Code
|
|
#region extension
|
|
readonly RevisionVersionExtension _RevisionVersionExtension = new RevisionVersionExtension();
|
|
[Serializable()]
|
|
partial class RevisionVersionExtension : extensionBase
|
|
{
|
|
}
|
|
[Serializable()]
|
|
class extensionBase
|
|
{
|
|
// Default Values
|
|
// Authorization Rules
|
|
public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules)
|
|
{
|
|
// Needs to be overriden to add new authorization rules
|
|
}
|
|
// Instance Authorization Rules
|
|
public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules)
|
|
{
|
|
// Needs to be overriden to add new authorization rules
|
|
}
|
|
// Validation Rules
|
|
public virtual void AddValidationRules(Csla.Validation.ValidationRules rules)
|
|
{
|
|
// Needs to be overriden to add new validation rules
|
|
}
|
|
// InstanceValidation Rules
|
|
public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules)
|
|
{
|
|
// Needs to be overriden to add new validation rules
|
|
}
|
|
}
|
|
#endregion
|
|
} // Class
|
|
#region Converter
|
|
internal class RevisionVersionConverter : ExpandableObjectConverter
|
|
{
|
|
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
|
|
{
|
|
if (destType == typeof(string) && value is RevisionVersion version)
|
|
{
|
|
// Return the ToString value
|
|
return version.ToString();
|
|
}
|
|
return base.ConvertTo(context, culture, value, destType);
|
|
}
|
|
}
|
|
#endregion
|
|
} // Namespace
|