1279 lines
54 KiB
C#
1279 lines
54 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;
|
|
using System.Data.SqlClient;
|
|
using Csla;
|
|
using Csla.Data;
|
|
using System.ComponentModel;
|
|
using System.Collections.Generic;
|
|
using Csla.Validation;
|
|
namespace VEPROMS.CSLA.Library
|
|
{
|
|
/// <summary>
|
|
/// RODb Generated by MyGeneration using the CSLA Object Mapping template
|
|
/// </summary>
|
|
[Serializable()]
|
|
[TypeConverter(typeof(RODbConverter))]
|
|
public partial class RODb : BusinessBase<RODb>, IDisposable, IVEHasBrokenRules
|
|
{
|
|
#region Log4Net
|
|
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
|
|
#endregion
|
|
#region Refresh
|
|
private List<RODb> _RefreshRODbs = new List<RODb>();
|
|
private List<RODbDROUsage> _RefreshRODbDROUsages = new List<RODbDROUsage>();
|
|
private List<RODbROFst> _RefreshRODbROFsts = new List<RODbROFst>();
|
|
private List<RODbROImage> _RefreshRODbROImages = new List<RODbROImage>();
|
|
private List<RODbRoUsage> _RefreshRODbRoUsages = new List<RODbRoUsage>();
|
|
private void AddToRefreshList(List<RODb> refreshRODbs, List<RODbDROUsage> refreshRODbDROUsages, List<RODbROFst> refreshRODbROFsts, List<RODbROImage> refreshRODbROImages, List<RODbRoUsage> refreshRODbRoUsages)
|
|
{
|
|
if (IsDirty)
|
|
refreshRODbs.Add(this);
|
|
if (_RODbDROUsages != null && _RODbDROUsages.IsDirty)
|
|
{
|
|
foreach (RODbDROUsage tmp in _RODbDROUsages)
|
|
{
|
|
if (tmp.IsDirty) refreshRODbDROUsages.Add(tmp);
|
|
}
|
|
}
|
|
if (_RODbROFsts != null && _RODbROFsts.IsDirty)
|
|
{
|
|
foreach (RODbROFst tmp in _RODbROFsts)
|
|
{
|
|
if (tmp.IsDirty) refreshRODbROFsts.Add(tmp);
|
|
}
|
|
}
|
|
if (_RODbROImages != null && _RODbROImages.IsDirty)
|
|
{
|
|
foreach (RODbROImage tmp in _RODbROImages)
|
|
{
|
|
if (tmp.IsDirty) refreshRODbROImages.Add(tmp);
|
|
}
|
|
}
|
|
if (_RODbRoUsages != null && _RODbRoUsages.IsDirty)
|
|
{
|
|
foreach (RODbRoUsage tmp in _RODbRoUsages)
|
|
{
|
|
if (tmp.IsDirty) refreshRODbRoUsages.Add(tmp);
|
|
}
|
|
}
|
|
}
|
|
private void ClearRefreshList()
|
|
{
|
|
_RefreshRODbs = new List<RODb>();
|
|
_RefreshRODbDROUsages = new List<RODbDROUsage>();
|
|
_RefreshRODbROFsts = new List<RODbROFst>();
|
|
_RefreshRODbROImages = new List<RODbROImage>();
|
|
_RefreshRODbRoUsages = new List<RODbRoUsage>();
|
|
}
|
|
private void BuildRefreshList()
|
|
{
|
|
ClearRefreshList();
|
|
AddToRefreshList(_RefreshRODbs, _RefreshRODbDROUsages, _RefreshRODbROFsts, _RefreshRODbROImages, _RefreshRODbRoUsages);
|
|
}
|
|
private void ProcessRefreshList()
|
|
{
|
|
foreach (RODb tmp in _RefreshRODbs)
|
|
{
|
|
RODbInfo.Refresh(tmp);
|
|
}
|
|
foreach (RODbDROUsage tmp in _RefreshRODbDROUsages)
|
|
{
|
|
DROUsageInfo.Refresh(tmp);
|
|
}
|
|
foreach (RODbROFst tmp in _RefreshRODbROFsts)
|
|
{
|
|
ROFstInfo.Refresh(tmp);
|
|
}
|
|
foreach (RODbROImage tmp in _RefreshRODbROImages)
|
|
{
|
|
ROImageInfo.Refresh(tmp);
|
|
}
|
|
foreach (RODbRoUsage tmp in _RefreshRODbRoUsages)
|
|
{
|
|
RoUsageInfo.Refresh(tmp);
|
|
}
|
|
ClearRefreshList();
|
|
}
|
|
#endregion
|
|
#region Collection
|
|
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
|
|
private static List<RODb> _CacheList = new List<RODb>();
|
|
protected static void AddToCache(RODb rODb)
|
|
{
|
|
if (!_CacheList.Contains(rODb)) _CacheList.Add(rODb); // In AddToCache
|
|
}
|
|
protected static void RemoveFromCache(RODb rODb)
|
|
{
|
|
while (_CacheList.Contains(rODb)) _CacheList.Remove(rODb); // In RemoveFromCache
|
|
}
|
|
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
|
|
private static Dictionary<string, List<RODb>> _CacheByPrimaryKey = new Dictionary<string, List<RODb>>();
|
|
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
|
|
private static Dictionary<string, List<RODb>> _CacheByFolderPath = new Dictionary<string, List<RODb>>();
|
|
private static void ConvertListToDictionary()
|
|
{
|
|
while (_CacheList.Count > 0) // Move RODb(s) from temporary _CacheList to _CacheByPrimaryKey
|
|
{
|
|
RODb tmp = _CacheList[0]; // Get the first RODb
|
|
string pKey = tmp.RODbID.ToString();
|
|
if (!_CacheByPrimaryKey.ContainsKey(pKey))
|
|
{
|
|
_CacheByPrimaryKey[pKey] = new List<RODb>(); // Add new list for PrimaryKey
|
|
_CacheByFolderPath[tmp.FolderPath.ToString()] = new List<RODb>(); // Add new list for FolderPath
|
|
}
|
|
_CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list
|
|
_CacheByFolderPath[tmp.FolderPath.ToString()].Add(tmp); // Unique Index
|
|
_CacheList.RemoveAt(0); // Remove the first RODb
|
|
}
|
|
}
|
|
protected static RODb GetCachedByPrimaryKey(int rODbID)
|
|
{
|
|
ConvertListToDictionary();
|
|
string key = rODbID.ToString();
|
|
if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0];
|
|
return null;
|
|
}
|
|
protected static RODb GetCachedByFolderPath(string folderPath)
|
|
{
|
|
ConvertListToDictionary();
|
|
string key = folderPath.ToString();
|
|
if (_CacheByFolderPath.ContainsKey(key)) return _CacheByFolderPath[key][0];
|
|
return null;
|
|
}
|
|
#endregion
|
|
#region Business Methods
|
|
private string _ErrorMessage = string.Empty;
|
|
public string ErrorMessage => _ErrorMessage;
|
|
private static int _nextRODbID = -1;
|
|
public static int NextRODbID => _nextRODbID--;
|
|
private int _RODbID;
|
|
[System.ComponentModel.DataObjectField(true, true)]
|
|
public int RODbID
|
|
{
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
get
|
|
{
|
|
return _RODbID;
|
|
}
|
|
}
|
|
private string _ROName = string.Empty;
|
|
/// <summary>
|
|
/// Hook for future - to allow the user to select multiple RO Databases assocaiated with on DocVersion
|
|
/// </summary>
|
|
public string ROName
|
|
{
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
get
|
|
{
|
|
return _ROName;
|
|
}
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
set
|
|
{
|
|
if (value == null) value = string.Empty;
|
|
if (_ROName != value)
|
|
{
|
|
_ROName = value;
|
|
PropertyHasChanged();
|
|
}
|
|
}
|
|
}
|
|
private string _FolderPath = string.Empty;
|
|
/// <summary>
|
|
/// Path to the RO database
|
|
/// </summary>
|
|
public string FolderPath
|
|
{
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
get
|
|
{
|
|
return _FolderPath;
|
|
}
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
set
|
|
{
|
|
if (value == null) value = string.Empty;
|
|
if (_FolderPath != value)
|
|
{
|
|
_FolderPath = value;
|
|
PropertyHasChanged();
|
|
}
|
|
}
|
|
}
|
|
private string _DBConnectionString = string.Empty;
|
|
/// <summary>
|
|
/// Connection String - Default could just be the full path and name of the database
|
|
/// </summary>
|
|
public string DBConnectionString
|
|
{
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
get
|
|
{
|
|
return _DBConnectionString;
|
|
}
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
set
|
|
{
|
|
if (value == null) value = string.Empty;
|
|
if (_DBConnectionString != value)
|
|
{
|
|
_DBConnectionString = 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
|
|
private int _RODbDROUsageCount = 0;
|
|
/// <summary>
|
|
/// Count of RODbDROUsages for this RODb
|
|
/// </summary>
|
|
public int RODbDROUsageCount
|
|
{
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
get
|
|
{
|
|
return _RODbDROUsageCount;
|
|
}
|
|
}
|
|
private RODbDROUsages _RODbDROUsages = null;
|
|
/// <summary>
|
|
/// Related Field
|
|
/// </summary>
|
|
[TypeConverter(typeof(RODbDROUsagesConverter))]
|
|
public RODbDROUsages RODbDROUsages
|
|
{
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
get
|
|
{
|
|
if (_RODbDROUsageCount < 0 || (_RODbDROUsageCount > 0 && _RODbDROUsages == null))
|
|
_RODbDROUsages = RODbDROUsages.GetByRODbID(RODbID);
|
|
if (_RODbDROUsageCount < 0)
|
|
_RODbDROUsageCount = _RODbDROUsages == null ? 0 : _RODbDROUsages.Count;
|
|
if (_RODbDROUsages == null)
|
|
_RODbDROUsages = RODbDROUsages.New();
|
|
return _RODbDROUsages;
|
|
}
|
|
}
|
|
public void Reset_RODbDROUsages() => _RODbDROUsageCount = -1;
|
|
private int _RODbROFstCount = 0;
|
|
/// <summary>
|
|
/// Count of RODbROFsts for this RODb
|
|
/// </summary>
|
|
public int RODbROFstCount
|
|
{
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
get
|
|
{
|
|
return _RODbROFstCount;
|
|
}
|
|
}
|
|
private RODbROFsts _RODbROFsts = null;
|
|
/// <summary>
|
|
/// Related Field
|
|
/// </summary>
|
|
[TypeConverter(typeof(RODbROFstsConverter))]
|
|
public RODbROFsts RODbROFsts
|
|
{
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
get
|
|
{
|
|
if (_RODbROFstCount < 0 || (_RODbROFstCount > 0 && _RODbROFsts == null))
|
|
_RODbROFsts = RODbROFsts.GetByRODbID(RODbID);
|
|
if (_RODbROFstCount < 0)
|
|
_RODbROFstCount = _RODbROFsts == null ? 0 : _RODbROFsts.Count;
|
|
if (_RODbROFsts == null)
|
|
_RODbROFsts = RODbROFsts.New();
|
|
return _RODbROFsts;
|
|
}
|
|
}
|
|
public void Reset_RODbROFsts() => _RODbROFstCount = -1;
|
|
private int _RODbROImageCount = 0;
|
|
/// <summary>
|
|
/// Count of RODbROImages for this RODb
|
|
/// </summary>
|
|
public int RODbROImageCount
|
|
{
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
get
|
|
{
|
|
return _RODbROImageCount;
|
|
}
|
|
}
|
|
private RODbROImages _RODbROImages = null;
|
|
/// <summary>
|
|
/// Related Field
|
|
/// </summary>
|
|
[TypeConverter(typeof(RODbROImagesConverter))]
|
|
public RODbROImages RODbROImages
|
|
{
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
get
|
|
{
|
|
if (_RODbROImageCount < 0 || (_RODbROImageCount > 0 && _RODbROImages == null))
|
|
_RODbROImages = RODbROImages.GetByRODbID(RODbID);
|
|
if (_RODbROImageCount < 0)
|
|
_RODbROImageCount = _RODbROImages == null ? 0 : _RODbROImages.Count;
|
|
if (_RODbROImages == null)
|
|
_RODbROImages = RODbROImages.New();
|
|
return _RODbROImages;
|
|
}
|
|
}
|
|
public void Reset_RODbROImages() => _RODbROImageCount = -1;
|
|
private int _RODbRoUsageCount = 0;
|
|
/// <summary>
|
|
/// Count of RODbRoUsages for this RODb
|
|
/// </summary>
|
|
public int RODbRoUsageCount
|
|
{
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
get
|
|
{
|
|
return _RODbRoUsageCount;
|
|
}
|
|
}
|
|
private RODbRoUsages _RODbRoUsages = null;
|
|
/// <summary>
|
|
/// Related Field
|
|
/// </summary>
|
|
[TypeConverter(typeof(RODbRoUsagesConverter))]
|
|
public RODbRoUsages RODbRoUsages
|
|
{
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
get
|
|
{
|
|
if (_RODbRoUsageCount < 0 || (_RODbRoUsageCount > 0 && _RODbRoUsages == null))
|
|
_RODbRoUsages = RODbRoUsages.GetByRODbID(RODbID);
|
|
if (_RODbRoUsageCount < 0)
|
|
_RODbRoUsageCount = _RODbRoUsages == null ? 0 : _RODbRoUsages.Count;
|
|
if (_RODbRoUsages == null)
|
|
_RODbRoUsages = RODbRoUsages.New();
|
|
return _RODbRoUsages;
|
|
}
|
|
}
|
|
public void Reset_RODbRoUsages() => _RODbRoUsageCount = -1;
|
|
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 || (_RODbDROUsages != null && _RODbDROUsages.IsDirtyList(list)) || (_RODbROFsts != null && _RODbROFsts.IsDirtyList(list)) || (_RODbROImages != null && _RODbROImages.IsDirtyList(list)) || (_RODbRoUsages != null && _RODbRoUsages.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) && (_RODbDROUsages == null || _RODbDROUsages.IsValidList(list)) && (_RODbROFsts == null || _RODbROFsts.IsValidList(list)) && (_RODbROImages == null || _RODbROImages.IsValidList(list)) && (_RODbRoUsages == null || _RODbRoUsages.IsValidList(list));
|
|
}
|
|
// CSLATODO: Check RODb.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 RODb</returns>
|
|
protected override object GetIdValue() => MyRODbUnique; // Absolutely Unique ID
|
|
#endregion
|
|
#region ValidationRules
|
|
[NonSerialized]
|
|
private bool _CheckingBrokenRules = false;
|
|
public IVEHasBrokenRules HasBrokenRules
|
|
{
|
|
get
|
|
{
|
|
if (_CheckingBrokenRules) return null;
|
|
if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this;
|
|
try
|
|
{
|
|
_CheckingBrokenRules = true;
|
|
IVEHasBrokenRules hasBrokenRules = null;
|
|
if (_RODbRoUsages != null && (hasBrokenRules = _RODbRoUsages.HasBrokenRules) != null) return hasBrokenRules;
|
|
if (_RODbDROUsages != null && (hasBrokenRules = _RODbDROUsages.HasBrokenRules) != null) return hasBrokenRules;
|
|
if (_RODbROFsts != null && (hasBrokenRules = _RODbROFsts.HasBrokenRules) != null) return hasBrokenRules;
|
|
if (_RODbROImages != null && (hasBrokenRules = _RODbROImages.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(
|
|
Csla.Validation.CommonRules.StringRequired, "ROName");
|
|
ValidationRules.AddRule(
|
|
Csla.Validation.CommonRules.StringMaxLength,
|
|
new Csla.Validation.CommonRules.MaxLengthRuleArgs("ROName", 255));
|
|
ValidationRules.AddRule(
|
|
Csla.Validation.CommonRules.StringRequired, "FolderPath");
|
|
ValidationRules.AddRule(
|
|
Csla.Validation.CommonRules.StringMaxLength,
|
|
new Csla.Validation.CommonRules.MaxLengthRuleArgs("FolderPath", 255));
|
|
ValidationRules.AddRule(
|
|
Csla.Validation.CommonRules.StringRequired, "DBConnectionString");
|
|
ValidationRules.AddRule(
|
|
Csla.Validation.CommonRules.StringMaxLength,
|
|
new Csla.Validation.CommonRules.MaxLengthRuleArgs("DBConnectionString", 1073741823));
|
|
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));
|
|
//ValidationRules.AddDependantProperty("x", "y");
|
|
_RODbExtension.AddValidationRules(ValidationRules);
|
|
// CSLATODO: Add other validation rules
|
|
}
|
|
protected override void AddInstanceBusinessRules()
|
|
{
|
|
_RODbExtension.AddInstanceValidationRules(ValidationRules);
|
|
// CSLATODO: Add other validation rules
|
|
}
|
|
#endregion
|
|
#region Authorization Rules
|
|
protected override void AddAuthorizationRules()
|
|
{
|
|
//CSLATODO: Who can read/write which fields
|
|
_RODbExtension.AddAuthorizationRules(AuthorizationRules);
|
|
}
|
|
protected override void AddInstanceAuthorizationRules()
|
|
{
|
|
//CSLATODO: Who can read/write which fields
|
|
_RODbExtension.AddInstanceAuthorizationRules(AuthorizationRules);
|
|
}
|
|
#endregion
|
|
#region Factory Methods
|
|
public int CurrentEditLevel => EditLevel;
|
|
private static int _RODbUnique = 0;
|
|
protected static int RODbUnique => ++_RODbUnique;
|
|
private readonly int _MyRODbUnique = RODbUnique;
|
|
// Absolutely Unique ID - Editable
|
|
public int MyRODbUnique => _MyRODbUnique;
|
|
protected RODb()
|
|
{/* require use of factory methods */
|
|
AddToCache(this);
|
|
}
|
|
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;
|
|
~RODb()
|
|
{
|
|
_CountFinalized++;
|
|
}
|
|
public void Dispose()
|
|
{
|
|
if (_Disposed) return;
|
|
_CountDisposed++;
|
|
_Disposed = true;
|
|
RemoveFromDictionaries();
|
|
}
|
|
private void RemoveFromDictionaries()
|
|
{
|
|
RemoveFromCache(this);
|
|
if (_CacheByPrimaryKey.ContainsKey(RODbID.ToString()))
|
|
{
|
|
List<RODb> listRODb = _CacheByPrimaryKey[RODbID.ToString()]; // Get the list of items
|
|
while (listRODb.Contains(this)) listRODb.Remove(this); // Remove the item from the list
|
|
if (listRODb.Count == 0) //If there are no items left in the list
|
|
_CacheByPrimaryKey.Remove(RODbID.ToString()); // remove the list
|
|
}
|
|
string myKey;
|
|
myKey = null;
|
|
foreach (string key in _CacheByFolderPath.Keys)
|
|
if (_CacheByFolderPath[key].Contains(this))
|
|
myKey = key;
|
|
if (myKey != null)
|
|
{
|
|
List<RODb> listRODb = _CacheByFolderPath[myKey]; // Get the list of items
|
|
listRODb.Remove(this); // Remove the item from the list
|
|
if (listRODb.Count == 0) //If there are no items left in the list
|
|
_CacheByFolderPath.Remove(myKey); // remove the list
|
|
}
|
|
}
|
|
public static RODb New()
|
|
{
|
|
try
|
|
{
|
|
return DataPortal.Create<RODb>();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw new DbCslaException("Error on RODb.New", ex);
|
|
}
|
|
}
|
|
public static RODb New(string rOName, string folderPath, string dBConnectionString)
|
|
{
|
|
RODb tmp = RODb.New();
|
|
tmp.ROName = rOName;
|
|
tmp.FolderPath = folderPath;
|
|
tmp.DBConnectionString = dBConnectionString;
|
|
return tmp;
|
|
}
|
|
public static RODb New(string rOName, string folderPath, string dBConnectionString, string config, DateTime dts, string userID)
|
|
{
|
|
RODb tmp = RODb.New();
|
|
tmp.ROName = rOName;
|
|
tmp.FolderPath = folderPath;
|
|
tmp.DBConnectionString = dBConnectionString;
|
|
tmp.Config = config;
|
|
tmp.DTS = dts;
|
|
tmp.UserID = userID;
|
|
return tmp;
|
|
}
|
|
public static RODb MakeRODb(string rOName, string folderPath, string dBConnectionString, string config, DateTime dts, string userID)
|
|
{
|
|
RODb tmp = RODb.New(rOName, folderPath, dBConnectionString, config, dts, userID);
|
|
if (tmp.IsSavable)
|
|
tmp = tmp.Save();
|
|
else
|
|
{
|
|
Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules();
|
|
tmp._ErrorMessage = "Failed Validation:";
|
|
foreach (Csla.Validation.BrokenRule br in brc)
|
|
{
|
|
tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName;
|
|
}
|
|
}
|
|
return tmp;
|
|
}
|
|
public static RODb New(string rOName, string folderPath, string dBConnectionString, string config)
|
|
{
|
|
RODb tmp = RODb.New();
|
|
tmp.ROName = rOName;
|
|
tmp.FolderPath = folderPath;
|
|
tmp.DBConnectionString = dBConnectionString;
|
|
tmp.Config = config;
|
|
return tmp;
|
|
}
|
|
public static RODb MakeRODb(string rOName, string folderPath, string dBConnectionString, string config)
|
|
{
|
|
RODb tmp = RODb.New(rOName, folderPath, dBConnectionString, config);
|
|
if (tmp.IsSavable)
|
|
tmp = tmp.Save();
|
|
else
|
|
{
|
|
Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules();
|
|
tmp._ErrorMessage = "Failed Validation:";
|
|
foreach (Csla.Validation.BrokenRule br in brc)
|
|
{
|
|
tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName;
|
|
}
|
|
}
|
|
return tmp;
|
|
}
|
|
public static RODb Get(int rODbID)
|
|
{
|
|
try
|
|
{
|
|
RODb tmp = GetCachedByPrimaryKey(rODbID);
|
|
if (tmp == null)
|
|
{
|
|
tmp = DataPortal.Fetch<RODb>(new PKCriteria(rODbID));
|
|
AddToCache(tmp);
|
|
}
|
|
if (tmp.ErrorMessage == "No Record Found")
|
|
{
|
|
tmp.Dispose(); // Clean-up RODb
|
|
tmp = null;
|
|
}
|
|
return tmp;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw new DbCslaException("Error on RODb.Get", ex);
|
|
}
|
|
}
|
|
public static RODb GetByFolderPath(string folderPath)
|
|
{
|
|
try
|
|
{
|
|
RODb tmp = GetCachedByFolderPath(folderPath);
|
|
if (tmp == null)
|
|
{
|
|
tmp = DataPortal.Fetch<RODb>(new FolderPathCriteria(folderPath));
|
|
AddToCache(tmp);
|
|
}
|
|
if (tmp.ErrorMessage == "No Record Found")
|
|
{
|
|
tmp.Dispose(); // Clean-up RODb
|
|
tmp = null;
|
|
}
|
|
return tmp;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw new DbCslaException("Error on RODb.GetByFolderPath", ex);
|
|
}
|
|
}
|
|
public static RODb Get(SafeDataReader dr)
|
|
{
|
|
if (dr.Read()) return new RODb(dr);
|
|
return null;
|
|
}
|
|
internal RODb(SafeDataReader dr) => ReadData(dr);
|
|
public static void Delete(int rODbID)
|
|
{
|
|
try
|
|
{
|
|
DataPortal.Delete(new PKCriteria(rODbID));
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw new DbCslaException("Error on RODb.Delete", ex);
|
|
}
|
|
}
|
|
public override RODb Save()
|
|
{
|
|
try
|
|
{
|
|
BuildRefreshList();
|
|
RODb rODb = base.Save();
|
|
RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache
|
|
AddToCache(rODb);//Refresh the item in AllList
|
|
ProcessRefreshList();
|
|
return rODb;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw new DbCslaException("Error on CSLA Save", ex);
|
|
}
|
|
}
|
|
#endregion
|
|
#region Data Access Portal
|
|
[Serializable()]
|
|
protected class PKCriteria
|
|
{
|
|
private readonly int _RODbID;
|
|
public int RODbID => _RODbID;
|
|
public PKCriteria(int rODbID) => _RODbID = rODbID;
|
|
}
|
|
[Serializable()]
|
|
private class FolderPathCriteria
|
|
{
|
|
private readonly string _FolderPath;
|
|
public string FolderPath => _FolderPath;
|
|
public FolderPathCriteria(string folderPath) => _FolderPath = folderPath;
|
|
}
|
|
// CSLATODO: If Create needs to access DB - It should not be marked RunLocal
|
|
[RunLocal()]
|
|
private new void DataPortal_Create()
|
|
{
|
|
_RODbID = NextRODbID;
|
|
// Database Defaults
|
|
_DTS = _RODbExtension.DefaultDTS;
|
|
_UserID = _RODbExtension.DefaultUserID;
|
|
// CSLATODO: Add any defaults that are necessary
|
|
ValidationRules.CheckRules();
|
|
}
|
|
private void ReadData(SafeDataReader dr)
|
|
{
|
|
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RODb.ReadData", GetHashCode());
|
|
try
|
|
{
|
|
_RODbID = dr.GetInt32("RODbID");
|
|
_ROName = dr.GetString("ROName");
|
|
_FolderPath = dr.GetString("FolderPath");
|
|
_DBConnectionString = dr.GetString("DBConnectionString");
|
|
_Config = dr.GetString("Config");
|
|
_DTS = dr.GetDateTime("DTS");
|
|
_UserID = dr.GetString("UserID");
|
|
dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8);
|
|
_RODbDROUsageCount = dr.GetInt32("DROUsageCount");
|
|
_RODbROFstCount = dr.GetInt32("ROFstCount");
|
|
_RODbROImageCount = dr.GetInt32("ROImageCount");
|
|
_RODbRoUsageCount = dr.GetInt32("RoUsageCount");
|
|
MarkOld();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
if (_MyLog.IsErrorEnabled) _MyLog.Error("RODb.ReadData", ex);
|
|
_ErrorMessage = ex.Message;
|
|
throw new DbCslaException("RODb.ReadData", ex);
|
|
}
|
|
}
|
|
private void DataPortal_Fetch(PKCriteria criteria)
|
|
{
|
|
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RODb.DataPortal_Fetch", GetHashCode());
|
|
try
|
|
{
|
|
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
|
|
{
|
|
ApplicationContext.LocalContext["cn"] = cn;
|
|
using (SqlCommand cm = cn.CreateCommand())
|
|
{
|
|
cm.CommandType = CommandType.StoredProcedure;
|
|
cm.CommandText = "getRODb";
|
|
cm.Parameters.AddWithValue("@RODbID", criteria.RODbID);
|
|
cm.CommandTimeout = Database.DefaultTimeout;
|
|
using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader()))
|
|
{
|
|
if (!dr.Read())
|
|
{
|
|
_ErrorMessage = "No Record Found";
|
|
return;
|
|
}
|
|
ReadData(dr);
|
|
// load child objects
|
|
dr.NextResult();
|
|
_RODbDROUsages = RODbDROUsages.Get(dr);
|
|
// load child objects
|
|
dr.NextResult();
|
|
_RODbROFsts = RODbROFsts.Get(dr);
|
|
// load child objects
|
|
dr.NextResult();
|
|
_RODbROImages = RODbROImages.Get(dr);
|
|
// load child objects
|
|
dr.NextResult();
|
|
_RODbRoUsages = RODbRoUsages.Get(dr);
|
|
}
|
|
}
|
|
// removing of item only needed for local data portal
|
|
if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client)
|
|
ApplicationContext.LocalContext.Remove("cn");
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
if (_MyLog.IsErrorEnabled) _MyLog.Error("RODb.DataPortal_Fetch", ex);
|
|
_ErrorMessage = ex.Message;
|
|
throw new DbCslaException("RODb.DataPortal_Fetch", ex);
|
|
}
|
|
}
|
|
private void DataPortal_Fetch(FolderPathCriteria criteria)
|
|
{
|
|
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RODb.DataPortal_Fetch", GetHashCode());
|
|
try
|
|
{
|
|
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
|
|
{
|
|
ApplicationContext.LocalContext["cn"] = cn;
|
|
using (SqlCommand cm = cn.CreateCommand())
|
|
{
|
|
cm.CommandType = CommandType.StoredProcedure;
|
|
cm.CommandText = "getRODbByFolderPath";
|
|
cm.Parameters.AddWithValue("@FolderPath", criteria.FolderPath);
|
|
cm.CommandTimeout = Database.DefaultTimeout;
|
|
using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader()))
|
|
{
|
|
if (!dr.Read())
|
|
{
|
|
_ErrorMessage = "No Record Found";
|
|
return;
|
|
}
|
|
ReadData(dr);
|
|
}
|
|
}
|
|
// removing of item only needed for local data portal
|
|
if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client)
|
|
ApplicationContext.LocalContext.Remove("cn");
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
if (_MyLog.IsErrorEnabled) _MyLog.Error("RODb.DataPortal_Fetch", ex);
|
|
_ErrorMessage = ex.Message;
|
|
throw new DbCslaException("RODb.DataPortal_Fetch", ex);
|
|
}
|
|
}
|
|
[Transactional(TransactionalTypes.TransactionScope)]
|
|
protected override void DataPortal_Insert()
|
|
{
|
|
try
|
|
{
|
|
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
|
|
{
|
|
ApplicationContext.LocalContext["cn"] = cn;
|
|
SQLInsert();
|
|
// removing of item only needed for local data portal
|
|
if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client)
|
|
ApplicationContext.LocalContext.Remove("cn");
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
if (_MyLog.IsErrorEnabled) _MyLog.Error("RODb.DataPortal_Insert", ex);
|
|
_ErrorMessage = ex.Message;
|
|
throw new DbCslaException("RODb.DataPortal_Insert", ex);
|
|
}
|
|
finally
|
|
{
|
|
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RODb.DataPortal_Insert", GetHashCode());
|
|
}
|
|
}
|
|
[Transactional(TransactionalTypes.TransactionScope)]
|
|
internal void SQLInsert()
|
|
{
|
|
if (!IsDirty) return;
|
|
try
|
|
{
|
|
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
|
|
{
|
|
using (SqlCommand cm = cn.CreateCommand())
|
|
{
|
|
cm.CommandType = CommandType.StoredProcedure;
|
|
cm.CommandTimeout = Database.SQLTimeout;
|
|
cm.CommandText = "addRODb";
|
|
// Input All Fields - Except Calculated Columns
|
|
cm.Parameters.AddWithValue("@ROName", _ROName);
|
|
cm.Parameters.AddWithValue("@FolderPath", _FolderPath);
|
|
cm.Parameters.AddWithValue("@DBConnectionString", _DBConnectionString);
|
|
cm.Parameters.AddWithValue("@Config", _Config);
|
|
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
|
|
cm.Parameters.AddWithValue("@UserID", _UserID);
|
|
// Output Calculated Columns
|
|
SqlParameter param_RODbID = new SqlParameter("@newRODbID", SqlDbType.Int)
|
|
{
|
|
Direction = ParameterDirection.Output
|
|
};
|
|
cm.Parameters.Add(param_RODbID);
|
|
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp)
|
|
{
|
|
Direction = ParameterDirection.Output
|
|
};
|
|
cm.Parameters.Add(param_LastChanged);
|
|
// CSLATODO: Define any additional output parameters
|
|
cm.ExecuteNonQuery();
|
|
// Save all values being returned from the Procedure
|
|
_RODbID = (int)cm.Parameters["@newRODbID"].Value;
|
|
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
|
|
}
|
|
}
|
|
|
|
MarkOld();
|
|
// update child objects
|
|
_RODbRoUsages?.Update(this);
|
|
_RODbDROUsages?.Update(this);
|
|
_RODbROFsts?.Update(this);
|
|
_RODbROImages?.Update(this);
|
|
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RODb.SQLInsert", GetHashCode());
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
if (_MyLog.IsErrorEnabled) _MyLog.Error("RODb.SQLInsert", ex);
|
|
_ErrorMessage = ex.Message;
|
|
throw new DbCslaException("RODb.SQLInsert", ex);
|
|
}
|
|
}
|
|
[Transactional(TransactionalTypes.TransactionScope)]
|
|
public static byte[] Add(SqlConnection cn, ref int rODbID, string rOName, string folderPath, string dBConnectionString, string config, DateTime dts, string userID)
|
|
{
|
|
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RODb.Add", 0);
|
|
try
|
|
{
|
|
using (SqlCommand cm = cn.CreateCommand())
|
|
{
|
|
cm.CommandType = CommandType.StoredProcedure;
|
|
cm.CommandTimeout = Database.SQLTimeout;
|
|
cm.CommandText = "addRODb";
|
|
// Input All Fields - Except Calculated Columns
|
|
cm.Parameters.AddWithValue("@ROName", rOName);
|
|
cm.Parameters.AddWithValue("@FolderPath", folderPath);
|
|
cm.Parameters.AddWithValue("@DBConnectionString", dBConnectionString);
|
|
cm.Parameters.AddWithValue("@Config", config);
|
|
if (dts.Year >= 1753 && dts.Year <= 9999) cm.Parameters.AddWithValue("@DTS", dts);
|
|
cm.Parameters.AddWithValue("@UserID", userID);
|
|
// Output Calculated Columns
|
|
SqlParameter param_RODbID = new SqlParameter("@newRODbID", SqlDbType.Int)
|
|
{
|
|
Direction = ParameterDirection.Output
|
|
};
|
|
cm.Parameters.Add(param_RODbID);
|
|
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp)
|
|
{
|
|
Direction = ParameterDirection.Output
|
|
};
|
|
cm.Parameters.Add(param_LastChanged);
|
|
// CSLATODO: Define any additional output parameters
|
|
cm.ExecuteNonQuery();
|
|
// Save all values being returned from the Procedure
|
|
rODbID = (int)cm.Parameters["@newRODbID"].Value;
|
|
return (byte[])cm.Parameters["@newLastChanged"].Value;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
if (_MyLog.IsErrorEnabled) _MyLog.Error("RODb.Add", ex);
|
|
throw new DbCslaException("RODb.Add", ex);
|
|
}
|
|
}
|
|
[Transactional(TransactionalTypes.TransactionScope)]
|
|
protected override void DataPortal_Update()
|
|
{
|
|
if (!IsDirty) return; // If not dirty - nothing to do
|
|
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RODb.DataPortal_Update", GetHashCode());
|
|
try
|
|
{
|
|
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
|
|
{
|
|
ApplicationContext.LocalContext["cn"] = cn;
|
|
SQLUpdate();
|
|
// removing of item only needed for local data portal
|
|
if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client)
|
|
ApplicationContext.LocalContext.Remove("cn");
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
if (_MyLog.IsErrorEnabled) _MyLog.Error("RODb.DataPortal_Update", ex);
|
|
_ErrorMessage = ex.Message;
|
|
if (!ex.Message.EndsWith("has been edited by another user.")) throw ex;
|
|
}
|
|
}
|
|
[Transactional(TransactionalTypes.TransactionScope)]
|
|
internal void SQLUpdate()
|
|
{
|
|
if (!IsDirty) return; // If not dirty - nothing to do
|
|
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RODb.SQLUpdate", GetHashCode());
|
|
try
|
|
{
|
|
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
|
|
{
|
|
if (base.IsDirty)
|
|
{
|
|
using (SqlCommand cm = cn.CreateCommand())
|
|
{
|
|
cm.CommandType = CommandType.StoredProcedure;
|
|
cm.CommandTimeout = Database.SQLTimeout;
|
|
cm.CommandText = "updateRODb";
|
|
// All Fields including Calculated Fields
|
|
cm.Parameters.AddWithValue("@RODbID", _RODbID);
|
|
cm.Parameters.AddWithValue("@ROName", _ROName);
|
|
cm.Parameters.AddWithValue("@FolderPath", _FolderPath);
|
|
cm.Parameters.AddWithValue("@DBConnectionString", _DBConnectionString);
|
|
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("@LastChanged", _LastChanged);
|
|
// Output Calculated Columns
|
|
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp)
|
|
{
|
|
Direction = ParameterDirection.Output
|
|
};
|
|
cm.Parameters.Add(param_LastChanged);
|
|
// CSLATODO: Define any additional output parameters
|
|
cm.ExecuteNonQuery();
|
|
// Save all values being returned from the Procedure
|
|
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
|
|
}
|
|
}
|
|
}
|
|
|
|
MarkOld();
|
|
// use the open connection to update child objects
|
|
_RODbRoUsages?.Update(this);
|
|
_RODbDROUsages?.Update(this);
|
|
_RODbROFsts?.Update(this);
|
|
_RODbROImages?.Update(this);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
if (_MyLog.IsErrorEnabled) _MyLog.Error("RODb.SQLUpdate", ex);
|
|
_ErrorMessage = ex.Message;
|
|
if (!ex.Message.EndsWith("has been edited by another user.")) throw ex;
|
|
}
|
|
}
|
|
internal void Update()
|
|
{
|
|
if (!IsDirty) return;
|
|
if (base.IsDirty)
|
|
{
|
|
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
|
|
{
|
|
if (IsNew)
|
|
_LastChanged = RODb.Add(cn, ref _RODbID, _ROName, _FolderPath, _DBConnectionString, _Config, _DTS, _UserID);
|
|
else
|
|
_LastChanged = RODb.Update(cn, ref _RODbID, _ROName, _FolderPath, _DBConnectionString, _Config, _DTS, _UserID, ref _LastChanged);
|
|
}
|
|
|
|
MarkOld();
|
|
}
|
|
_RODbRoUsages?.Update(this);
|
|
_RODbDROUsages?.Update(this);
|
|
_RODbROFsts?.Update(this);
|
|
_RODbROImages?.Update(this);
|
|
}
|
|
[Transactional(TransactionalTypes.TransactionScope)]
|
|
public static byte[] Update(SqlConnection cn, ref int rODbID, string rOName, string folderPath, string dBConnectionString, string config, DateTime dts, string userID, ref byte[] lastChanged)
|
|
{
|
|
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RODb.Update", 0);
|
|
try
|
|
{
|
|
using (SqlCommand cm = cn.CreateCommand())
|
|
{
|
|
cm.CommandType = CommandType.StoredProcedure;
|
|
cm.CommandTimeout = Database.SQLTimeout;
|
|
cm.CommandText = "updateRODb";
|
|
// Input All Fields - Except Calculated Columns
|
|
cm.Parameters.AddWithValue("@RODbID", rODbID);
|
|
cm.Parameters.AddWithValue("@ROName", rOName);
|
|
cm.Parameters.AddWithValue("@FolderPath", folderPath);
|
|
cm.Parameters.AddWithValue("@DBConnectionString", dBConnectionString);
|
|
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("@LastChanged", lastChanged);
|
|
// Output Calculated Columns
|
|
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp)
|
|
{
|
|
Direction = ParameterDirection.Output
|
|
};
|
|
cm.Parameters.Add(param_LastChanged);
|
|
// CSLATODO: Define any additional output parameters
|
|
cm.ExecuteNonQuery();
|
|
// Save all values being returned from the Procedure
|
|
return (byte[])cm.Parameters["@newLastChanged"].Value;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
if (_MyLog.IsErrorEnabled) _MyLog.Error("RODb.Update", ex);
|
|
throw new DbCslaException("RODb.Update", ex);
|
|
}
|
|
}
|
|
[Transactional(TransactionalTypes.TransactionScope)]
|
|
protected override void DataPortal_DeleteSelf()
|
|
{
|
|
DataPortal_Delete(new PKCriteria(_RODbID));
|
|
}
|
|
[Transactional(TransactionalTypes.TransactionScope)]
|
|
private void DataPortal_Delete(PKCriteria criteria)
|
|
{
|
|
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RODb.DataPortal_Delete", GetHashCode());
|
|
try
|
|
{
|
|
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
|
|
{
|
|
using (SqlCommand cm = cn.CreateCommand())
|
|
{
|
|
cm.CommandType = CommandType.StoredProcedure;
|
|
cm.CommandTimeout = Database.SQLTimeout;
|
|
cm.CommandText = "deleteRODb";
|
|
cm.Parameters.AddWithValue("@RODbID", criteria.RODbID);
|
|
cm.ExecuteNonQuery();
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
if (_MyLog.IsErrorEnabled) _MyLog.Error("RODb.DataPortal_Delete", ex);
|
|
_ErrorMessage = ex.Message;
|
|
throw new DbCslaException("RODb.DataPortal_Delete", ex);
|
|
}
|
|
}
|
|
[Transactional(TransactionalTypes.TransactionScope)]
|
|
public static void Remove(SqlConnection cn, int rODbID)
|
|
{
|
|
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RODb.Remove", 0);
|
|
try
|
|
{
|
|
using (SqlCommand cm = cn.CreateCommand())
|
|
{
|
|
cm.CommandType = CommandType.StoredProcedure;
|
|
cm.CommandTimeout = Database.SQLTimeout;
|
|
cm.CommandText = "deleteRODb";
|
|
// Input PK Fields
|
|
cm.Parameters.AddWithValue("@RODbID", rODbID);
|
|
// CSLATODO: Define any additional output parameters
|
|
cm.ExecuteNonQuery();
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
if (_MyLog.IsErrorEnabled) _MyLog.Error("RODb.Remove", ex);
|
|
throw new DbCslaException("RODb.Remove", ex);
|
|
}
|
|
}
|
|
#endregion
|
|
#region Exists
|
|
public static bool Exists(int rODbID)
|
|
{
|
|
ExistsCommand result;
|
|
try
|
|
{
|
|
result = DataPortal.Execute<ExistsCommand>(new ExistsCommand(rODbID));
|
|
return result.Exists;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw new DbCslaException("Error on RODb.Exists", ex);
|
|
}
|
|
}
|
|
[Serializable()]
|
|
private class ExistsCommand : CommandBase
|
|
{
|
|
private readonly int _RODbID;
|
|
private bool _exists;
|
|
public bool Exists => _exists;
|
|
public ExistsCommand(int rODbID) => _RODbID = rODbID;
|
|
protected override void DataPortal_Execute()
|
|
{
|
|
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RODb.DataPortal_Execute", GetHashCode());
|
|
try
|
|
{
|
|
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
|
|
{
|
|
cn.Open();
|
|
using (SqlCommand cm = cn.CreateCommand())
|
|
{
|
|
cm.CommandType = CommandType.StoredProcedure;
|
|
cm.CommandTimeout = Database.SQLTimeout;
|
|
cm.CommandText = "existsRODb";
|
|
cm.Parameters.AddWithValue("@RODbID", _RODbID);
|
|
int count = (int)cm.ExecuteScalar();
|
|
_exists = count > 0;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
if (_MyLog.IsErrorEnabled) _MyLog.Error("RODb.DataPortal_Execute", ex);
|
|
throw new DbCslaException("RODb.DataPortal_Execute", ex);
|
|
}
|
|
}
|
|
}
|
|
#endregion
|
|
// Standard Default Code
|
|
#region extension
|
|
readonly RODbExtension _RODbExtension = new RODbExtension();
|
|
[Serializable()]
|
|
partial class RODbExtension : 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 RODbConverter : ExpandableObjectConverter
|
|
{
|
|
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
|
|
{
|
|
if (destType == typeof(string) && value is RODb db)
|
|
{
|
|
// Return the ToString value
|
|
return db.ToString();
|
|
}
|
|
return base.ConvertTo(context, culture, value, destType);
|
|
}
|
|
}
|
|
#endregion
|
|
} // Namespace
|