// ======================================================================== // 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 { /// /// RODbROFst Generated by MyGeneration using the CSLA Object Mapping template /// [Serializable()] [TypeConverter(typeof(RODbROFstConverter))] public partial class RODbROFst : BusinessBase, 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 _ROFstID; [System.ComponentModel.DataObjectField(true, true)] public int ROFstID { [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] get { if (_MyROFst != null) _ROFstID = _MyROFst.ROFstID; return _ROFstID; } } private ROFst _MyROFst; [System.ComponentModel.DataObjectField(true, true)] public ROFst MyROFst { [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] get { if (_MyROFst == null && _ROFstID != 0) _MyROFst = ROFst.Get(_ROFstID); return _MyROFst; } } private byte[] _ROLookup; public byte[] ROLookup { [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] get { return _ROLookup; } [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] set { if (_ROLookup != value) { _ROLookup = value; PropertyHasChanged(); } } } private string _Config = string.Empty; public string Config { [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] get { return _Config; } [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] set { if (value == null) value = string.Empty; if (_Config != value) { _Config = 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 // CSLATODO: Check RODbROFst.GetIdValue to assure that the ID returned is unique /// /// Overrides Base GetIdValue - Used internally by CSLA to determine equality /// /// A Unique ID for the current RODbROFst protected override object GetIdValue() => MyRODbROFstUnique; // Absolutely Unique ID public override bool IsDirty => base.IsDirty; [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Keeping until replace CSLA")] public bool IsDirtyList(List list) => base.IsDirty; public override bool IsValid => (IsNew && !IsDirty) || base.IsValid; [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Keeping until replace CSLA")] public bool IsValidList(List list) => (IsNew && !IsDirty) || base.IsValid; #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; 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( Csla.Validation.CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); ValidationRules.AddRule( Csla.Validation.CommonRules.StringRequired, "UserID"); ValidationRules.AddRule( Csla.Validation.CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); // CSLATODO: Add other validation rules } #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 _RODbROFstUnique = 0; private static int RODbROFstUnique => ++_RODbROFstUnique; private readonly int _MyRODbROFstUnique = RODbROFstUnique; // Absolutely Unique ID - Editable FK public int MyRODbROFstUnique => _MyRODbROFstUnique; internal static RODbROFst New(byte[] rOLookup) => new RODbROFst(rOLookup); internal static RODbROFst Get(SafeDataReader dr) => new RODbROFst(dr); public RODbROFst() { MarkAsChild(); _ROFstID = ROFst.NextROFstID; _DTS = _RODbROFstExtension.DefaultDTS; _UserID = _RODbROFstExtension.DefaultUserID; ValidationRules.CheckRules(); } private RODbROFst(byte[] rOLookup) { MarkAsChild(); // CSLATODO: Add any initialization & defaults _ROFstID = ROFst.NextROFstID; _DTS = _RODbROFstExtension.DefaultDTS; _UserID = _RODbROFstExtension.DefaultUserID; _ROLookup = rOLookup; ValidationRules.CheckRules(); } internal RODbROFst(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; ~RODbROFst() { _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}] RODbROFst.FetchDR", GetHashCode()); try { _ROFstID = dr.GetInt32("ROFstID"); _ROLookup = (byte[])dr.GetValue("ROLookup"); _Config = dr.GetString("Config"); _DTS = dr.GetDateTime("DTS"); _UserID = dr.GetString("UserID"); dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); } catch (Exception ex) // FKItem Fetch { if (_MyLog.IsErrorEnabled) _MyLog.Error("RODbROFst.FetchDR", ex); throw new DbCslaException("RODbROFst.Fetch", ex); } MarkOld(); } internal void Insert(RODb myRODb) { // if we're not dirty then don't update the database if (!IsDirty) return; using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]) { cn.Open(); _LastChanged = ROFst.Add(cn, ref _ROFstID, myRODb, _ROLookup, _Config, _DTS, _UserID); } MarkOld(); } internal void Update(RODb myRODb) { // if we're not dirty then don't update the database if (!IsDirty) return; using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]) { cn.Open(); _LastChanged = ROFst.Update(cn, ref _ROFstID, myRODb.RODbID, _ROLookup, _Config, _DTS, _UserID, ref _LastChanged); } MarkOld(); } [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Keeping until replace CSLA")] internal void DeleteSelf(RODb myRODb) { // 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 = (SqlConnection)ApplicationContext.LocalContext["cn"]) { cn.Open(); ROFst.Remove(cn, _ROFstID); } MarkNew(); } #endregion // Standard Default Code #region extension readonly RODbROFstExtension _RODbROFstExtension = new RODbROFstExtension(); [Serializable()] partial class RODbROFstExtension : extensionBase { } [Serializable()] class extensionBase { // Default Values 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) { // 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 RODbROFstConverter : ExpandableObjectConverter { public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) { if (destType == typeof(string) && value is RODbROFst fst) { // Return the ToString value return fst.ToString(); } return base.ConvertTo(context, culture, value, destType); } } #endregion } // Namespace