410 lines
15 KiB
C#
410 lines
15 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>
|
|
/// ContentPart Generated by MyGeneration using the CSLA Object Mapping template
|
|
/// </summary>
|
|
[Serializable()]
|
|
[TypeConverter(typeof(ContentPartConverter))]
|
|
public partial class ContentPart : BusinessBase<ContentPart>, 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 _FromType;
|
|
[System.ComponentModel.DataObjectField(true, true)]
|
|
public int FromType
|
|
{
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
get
|
|
{
|
|
return _FromType;
|
|
}
|
|
}
|
|
private int _ItemID;
|
|
public int ItemID
|
|
{
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
get
|
|
{
|
|
if (_MyItem != null) _ItemID = _MyItem.ItemID;
|
|
return _ItemID;
|
|
}
|
|
}
|
|
private Item _MyItem;
|
|
public Item MyItem
|
|
{
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
get
|
|
{
|
|
if (_MyItem == null && _ItemID != 0) _MyItem = Item.Get(_ItemID);
|
|
return _MyItem;
|
|
}
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
set
|
|
{
|
|
if (_MyItem != value)
|
|
{
|
|
_MyItem = value;
|
|
_ItemID = value.ItemID;// Update underlying data field
|
|
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? _Item_PreviousID;
|
|
public int? Item_PreviousID
|
|
{
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
get
|
|
{
|
|
return _Item_PreviousID;
|
|
}
|
|
}
|
|
private int _Item_ContentID;
|
|
public int Item_ContentID
|
|
{
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
get
|
|
{
|
|
return _Item_ContentID;
|
|
}
|
|
}
|
|
private DateTime _Item_DTS = new DateTime();
|
|
public DateTime Item_DTS
|
|
{
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
get
|
|
{
|
|
return _Item_DTS;
|
|
}
|
|
}
|
|
private string _Item_UserID = string.Empty;
|
|
public string Item_UserID
|
|
{
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
get
|
|
{
|
|
return _Item_UserID;
|
|
}
|
|
}
|
|
// CSLATODO: Check ContentPart.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 ContentPart</returns>
|
|
protected override object GetIdValue() => MyContentPartUnique; // Absolutely Unique ID
|
|
// CSLATODO: Replace base ContentPart.ToString function as necessary
|
|
/// <summary>
|
|
/// Overrides Base ToString
|
|
/// </summary>
|
|
/// <returns>A string representation of current ContentPart</returns>
|
|
//public override string ToString()
|
|
//{
|
|
// return base.ToString();
|
|
//}
|
|
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 || (_MyItem != null && _MyItem.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) && (_MyItem == null || _MyItem.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 (_MyItem != null && (hasBrokenRules = _MyItem.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<ContentPart>(MyItemRequired, "MyItem");
|
|
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 MyItemRequired(ContentPart target, Csla.Validation.RuleArgs e)
|
|
{
|
|
if (target._ItemID == 0 && target._MyItem == null) // Required field missing
|
|
{
|
|
e.Description = "Required";
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
#endregion
|
|
#region Authorization Rules
|
|
protected override void AddAuthorizationRules()
|
|
{
|
|
}
|
|
#endregion
|
|
#region Factory Methods
|
|
public int CurrentEditLevel => EditLevel;
|
|
private static int _ContentPartUnique = 0;
|
|
private static int ContentPartUnique => ++_ContentPartUnique;
|
|
private readonly int _MyContentPartUnique = ContentPartUnique;
|
|
// Absolutely Unique ID - Editable FK
|
|
public int MyContentPartUnique => _MyContentPartUnique;
|
|
internal static ContentPart New(int fromType, Item myItem) => new ContentPart(fromType, myItem);
|
|
internal static ContentPart Get(SafeDataReader dr) => new ContentPart(dr);
|
|
public ContentPart()
|
|
{
|
|
MarkAsChild();
|
|
|
|
_DTS = _ContentPartExtension.DefaultDTS;
|
|
_UserID = _ContentPartExtension.DefaultUserID;
|
|
ValidationRules.CheckRules();
|
|
}
|
|
private ContentPart(int fromType, Item myItem)
|
|
{
|
|
MarkAsChild();
|
|
// CSLATODO: Add any initialization & defaults
|
|
_DTS = _ContentPartExtension.DefaultDTS;
|
|
_UserID = _ContentPartExtension.DefaultUserID;
|
|
_FromType = fromType;
|
|
_MyItem = myItem;
|
|
ValidationRules.CheckRules();
|
|
}
|
|
internal ContentPart(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;
|
|
~ContentPart()
|
|
{
|
|
_CountFinalized++;
|
|
}
|
|
public void Dispose()
|
|
{
|
|
if (_Disposed) return;
|
|
_CountDisposed++;
|
|
_Disposed = true;
|
|
if (_MyItem != null)
|
|
{
|
|
_MyItem.Dispose();
|
|
_MyItem = null;
|
|
}
|
|
}
|
|
#endregion
|
|
#region Data Access Portal
|
|
private void Fetch(SafeDataReader dr)
|
|
{
|
|
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ContentPart.FetchDR", GetHashCode());
|
|
try
|
|
{
|
|
_FromType = dr.GetInt32("FromType");
|
|
_ItemID = dr.GetInt32("ItemID");
|
|
_DTS = dr.GetDateTime("DTS");
|
|
_UserID = dr.GetString("UserID");
|
|
dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8);
|
|
_Item_PreviousID = (int?)dr.GetValue("Item_PreviousID");
|
|
_Item_ContentID = dr.GetInt32("Item_ContentID");
|
|
_Item_DTS = dr.GetDateTime("Item_DTS");
|
|
_Item_UserID = dr.GetString("Item_UserID");
|
|
}
|
|
catch (Exception ex) // FKItem Fetch
|
|
{
|
|
if (_MyLog.IsErrorEnabled) _MyLog.Error("ContentPart.FetchDR", ex);
|
|
throw new DbCslaException("ContentPart.Fetch", ex);
|
|
}
|
|
MarkOld();
|
|
}
|
|
internal void Insert(Content myContent)
|
|
{
|
|
// if we're not dirty then don't update the database
|
|
if (!IsDirty) return;
|
|
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
|
|
{
|
|
_LastChanged = Part.Add(cn, myContent, _FromType, _MyItem, _DTS, _UserID);
|
|
}
|
|
|
|
MarkOld();
|
|
}
|
|
internal void Update(Content myContent)
|
|
{
|
|
// if we're not dirty then don't update the database
|
|
if (!IsDirty) return;
|
|
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
|
|
{
|
|
_LastChanged = Part.Update(cn, myContent.ContentID, _FromType, _ItemID, _DTS, _UserID, ref _LastChanged);
|
|
}
|
|
|
|
MarkOld();
|
|
}
|
|
internal void DeleteSelf(Content myContent)
|
|
{
|
|
// 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"])
|
|
{
|
|
Part.Remove(cn, myContent.ContentID, _FromType);
|
|
}
|
|
|
|
MarkNew();
|
|
}
|
|
#endregion
|
|
// Standard Default Code
|
|
#region extension
|
|
readonly ContentPartExtension _ContentPartExtension = new ContentPartExtension();
|
|
[Serializable()]
|
|
partial class ContentPartExtension : 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 ContentPartConverter : ExpandableObjectConverter
|
|
{
|
|
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
|
|
{
|
|
if (destType == typeof(string) && value is ContentPart part)
|
|
{
|
|
// Return the ToString value
|
|
return part.ToString();
|
|
}
|
|
return base.ConvertTo(context, culture, value, destType);
|
|
}
|
|
}
|
|
#endregion
|
|
} // Namespace
|