456 lines
18 KiB
C#
456 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>
|
|
/// ROFstFigure Generated by MyGeneration using the CSLA Object Mapping template
|
|
/// </summary>
|
|
[Serializable()]
|
|
[TypeConverter(typeof(ROFstFigureConverter))]
|
|
public partial class ROFstFigure : BusinessBase<ROFstFigure>, 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 _FigureID;
|
|
[System.ComponentModel.DataObjectField(true, true)]
|
|
public int FigureID
|
|
{
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
get
|
|
{
|
|
if (_MyFigure != null) _FigureID = _MyFigure.FigureID;
|
|
return _FigureID;
|
|
}
|
|
}
|
|
private Figure _MyFigure;
|
|
[System.ComponentModel.DataObjectField(true, true)]
|
|
public Figure MyFigure
|
|
{
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
get
|
|
{
|
|
if (_MyFigure == null && _FigureID != 0) _MyFigure = Figure.Get(_FigureID);
|
|
return _MyFigure;
|
|
}
|
|
}
|
|
private int _ImageID;
|
|
public int ImageID
|
|
{
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
get
|
|
{
|
|
if (_MyROImage != null) _ImageID = _MyROImage.ImageID;
|
|
return _ImageID;
|
|
}
|
|
}
|
|
private ROImage _MyROImage;
|
|
public ROImage MyROImage
|
|
{
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
get
|
|
{
|
|
if (_MyROImage == null && _ImageID != 0) _MyROImage = ROImage.GetJustROImage(_ImageID);//Don't load figures or ROFST - Causing Memory Crash
|
|
return _MyROImage;
|
|
}
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
set
|
|
{
|
|
if (_MyROImage != value)
|
|
{
|
|
_MyROImage = value;
|
|
_ImageID = value.ImageID;// Update underlying data field
|
|
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
|
|
private int _ROImage_RODbID;
|
|
public int ROImage_RODbID
|
|
{
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
get
|
|
{
|
|
return _ROImage_RODbID;
|
|
}
|
|
}
|
|
private string _ROImage_FileName = string.Empty;
|
|
public string ROImage_FileName
|
|
{
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
get
|
|
{
|
|
return _ROImage_FileName;
|
|
}
|
|
}
|
|
private byte[] _ROImage_Content;
|
|
public byte[] ROImage_Content
|
|
{
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
get
|
|
{
|
|
return _ROImage_Content;
|
|
}
|
|
}
|
|
private string _ROImage_Config = string.Empty;
|
|
public string ROImage_Config
|
|
{
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
get
|
|
{
|
|
return _ROImage_Config;
|
|
}
|
|
}
|
|
private DateTime _ROImage_DTS = new DateTime();
|
|
public DateTime ROImage_DTS
|
|
{
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
get
|
|
{
|
|
return _ROImage_DTS;
|
|
}
|
|
}
|
|
private string _ROImage_UserID = string.Empty;
|
|
public string ROImage_UserID
|
|
{
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
get
|
|
{
|
|
return _ROImage_UserID;
|
|
}
|
|
}
|
|
// CSLATODO: Check ROFstFigure.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 ROFstFigure</returns>
|
|
protected override object GetIdValue() => MyROFstFigureUnique; // 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 || (_MyROImage != null && _MyROImage.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) && (_MyROImage == null || _MyROImage.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 (_MyROImage != null && (hasBrokenRules = _MyROImage.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<ROFstFigure>(MyROImageRequired, "MyROImage");
|
|
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
|
|
}
|
|
private static bool MyROImageRequired(ROFstFigure target, Csla.Validation.RuleArgs e)
|
|
{
|
|
if (target._ImageID == 0 && target._MyROImage == 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 _ROFstFigureUnique = 0;
|
|
private static int ROFstFigureUnique => ++_ROFstFigureUnique;
|
|
private readonly int _MyROFstFigureUnique = ROFstFigureUnique;
|
|
// Absolutely Unique ID - Editable FK
|
|
public int MyROFstFigureUnique => _MyROFstFigureUnique;
|
|
internal static ROFstFigure New(ROImage myROImage) => new ROFstFigure(myROImage);
|
|
internal static ROFstFigure Get(SafeDataReader dr) => new ROFstFigure(dr);
|
|
public ROFstFigure()
|
|
{
|
|
MarkAsChild();
|
|
_FigureID = Figure.NextFigureID;
|
|
_DTS = _ROFstFigureExtension.DefaultDTS;
|
|
_UserID = _ROFstFigureExtension.DefaultUserID;
|
|
ValidationRules.CheckRules();
|
|
}
|
|
private ROFstFigure(ROImage myROImage)
|
|
{
|
|
MarkAsChild();
|
|
// CSLATODO: Add any initialization & defaults
|
|
_FigureID = Figure.NextFigureID;
|
|
_DTS = _ROFstFigureExtension.DefaultDTS;
|
|
_UserID = _ROFstFigureExtension.DefaultUserID;
|
|
_MyROImage = myROImage;
|
|
ValidationRules.CheckRules();
|
|
}
|
|
internal ROFstFigure(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;
|
|
~ROFstFigure()
|
|
{
|
|
_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}] ROFstFigure.FetchDR", GetHashCode());
|
|
try
|
|
{
|
|
_FigureID = dr.GetInt32("FigureID");
|
|
_ImageID = dr.GetInt32("ImageID");
|
|
_Config = dr.GetString("Config");
|
|
_DTS = dr.GetDateTime("DTS");
|
|
_UserID = dr.GetString("UserID");
|
|
dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8);
|
|
_ROImage_RODbID = dr.GetInt32("ROImage_RODbID");
|
|
_ROImage_FileName = dr.GetString("ROImage_FileName");
|
|
_ROImage_Content = (byte[])dr.GetValue("ROImage_Content");
|
|
_ROImage_Config = dr.GetString("ROImage_Config");
|
|
_ROImage_DTS = dr.GetDateTime("ROImage_DTS");
|
|
_ROImage_UserID = dr.GetString("ROImage_UserID");
|
|
}
|
|
catch (Exception ex) // FKItem Fetch
|
|
{
|
|
if (_MyLog.IsErrorEnabled) _MyLog.Error("ROFstFigure.FetchDR", ex);
|
|
throw new DbCslaException("ROFstFigure.Fetch", ex);
|
|
}
|
|
MarkOld();
|
|
}
|
|
internal void Insert(ROFst myROFst)
|
|
{
|
|
// if we're not dirty then don't update the database
|
|
if (!IsDirty) return;
|
|
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
|
|
{
|
|
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
|
|
_LastChanged = Figure.Add(cn, ref _FigureID, myROFst, _MyROImage, _Config, _DTS, _UserID);
|
|
}
|
|
|
|
MarkOld();
|
|
}
|
|
internal void Update(ROFst myROFst)
|
|
{
|
|
// if we're not dirty then don't update the database
|
|
if (!IsDirty) return;
|
|
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
|
|
{
|
|
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
|
|
_LastChanged = Figure.Update(cn, ref _FigureID, myROFst.ROFstID, _ImageID, _Config, _DTS, _UserID, ref _LastChanged);
|
|
}
|
|
|
|
MarkOld();
|
|
}
|
|
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Keeping until replace CSLA")]
|
|
internal void DeleteSelf(ROFst myROFst)
|
|
{
|
|
// 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"])
|
|
{
|
|
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
|
|
Figure.Remove(cn, _FigureID);
|
|
}
|
|
|
|
MarkNew();
|
|
}
|
|
#endregion
|
|
// Standard Default Code
|
|
#region extension
|
|
readonly ROFstFigureExtension _ROFstFigureExtension = new ROFstFigureExtension();
|
|
[Serializable()]
|
|
partial class ROFstFigureExtension : 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 ROFstFigureConverter : ExpandableObjectConverter
|
|
{
|
|
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
|
|
{
|
|
if (destType == typeof(string) && value is ROFstFigure figure)
|
|
{
|
|
// Return the ToString value
|
|
return figure.ToString();
|
|
}
|
|
return base.ConvertTo(context, culture, value, destType);
|
|
}
|
|
}
|
|
#endregion
|
|
} // Namespace
|