532 lines
15 KiB
C#
532 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;
|
|
using System.Data.SqlClient;
|
|
using Csla;
|
|
using Csla.Data;
|
|
using System.Configuration;
|
|
using System.IO;
|
|
using System.ComponentModel;
|
|
using System.Collections.Generic;
|
|
namespace VEPROMS.CSLA.Library
|
|
{
|
|
public delegate void FolderInfoEvent(object sender);
|
|
/// <summary>
|
|
/// FolderInfo Generated by MyGeneration using the CSLA Object Mapping template
|
|
/// </summary>
|
|
[Serializable()]
|
|
[TypeConverter(typeof(FolderInfoConverter))]
|
|
public partial class FolderInfo : ReadOnlyBase<FolderInfo>, IDisposable
|
|
{
|
|
public event FolderInfoEvent Changed;
|
|
private void OnChange()
|
|
{
|
|
if (Changed != null) Changed(this);
|
|
}
|
|
#region Log4Net
|
|
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
|
|
#endregion
|
|
#region Collection
|
|
protected static List<FolderInfo> _AllList = new List<FolderInfo>();
|
|
private static Dictionary<string, FolderInfo> _AllByPrimaryKey = new Dictionary<string, FolderInfo>();
|
|
private static void ConvertListToDictionary()
|
|
{
|
|
List<FolderInfo> remove = new List<FolderInfo>();
|
|
foreach (FolderInfo tmp in _AllList)
|
|
{
|
|
_AllByPrimaryKey[tmp.FolderID.ToString()]=tmp; // Primary Key
|
|
remove.Add(tmp);
|
|
}
|
|
foreach (FolderInfo tmp in remove)
|
|
_AllList.Remove(tmp);
|
|
}
|
|
internal static void AddList(FolderInfoList lst)
|
|
{
|
|
foreach (FolderInfo item in lst) _AllList.Add(item);
|
|
}
|
|
public static FolderInfo GetExistingByPrimaryKey(int folderID)
|
|
{
|
|
ConvertListToDictionary();
|
|
string key = folderID.ToString();
|
|
if (_AllByPrimaryKey.ContainsKey(key)) return _AllByPrimaryKey[key];
|
|
return null;
|
|
}
|
|
#endregion
|
|
#region Business Methods
|
|
private string _ErrorMessage = string.Empty;
|
|
public string ErrorMessage
|
|
{
|
|
get { return _ErrorMessage; }
|
|
}
|
|
protected Folder _Editable;
|
|
private IVEHasBrokenRules HasBrokenRules
|
|
{
|
|
get
|
|
{
|
|
IVEHasBrokenRules hasBrokenRules = null;
|
|
if (_Editable != null)
|
|
hasBrokenRules = _Editable.HasBrokenRules;
|
|
return hasBrokenRules;
|
|
}
|
|
}
|
|
private int _FolderID;
|
|
[System.ComponentModel.DataObjectField(true, true)]
|
|
public int FolderID
|
|
{
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
get
|
|
{
|
|
CanReadProperty("FolderID",true);
|
|
return _FolderID;
|
|
}
|
|
}
|
|
private int _ParentID;
|
|
public int ParentID
|
|
{
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
get
|
|
{
|
|
CanReadProperty("ParentID",true);
|
|
if (_MyParent != null) _ParentID = _MyParent.FolderID;
|
|
return _ParentID;
|
|
}
|
|
}
|
|
private FolderInfo _MyParent;
|
|
public FolderInfo MyParent
|
|
{
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
get
|
|
{
|
|
CanReadProperty("MyParent",true);
|
|
if (_MyParent == null && _ParentID != _FolderID) _MyParent = FolderInfo.Get(_ParentID);
|
|
return _MyParent;
|
|
}
|
|
}
|
|
private int _DBID;
|
|
public int DBID
|
|
{
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
get
|
|
{
|
|
CanReadProperty("DBID",true);
|
|
if (_MyConnection != null) _DBID = _MyConnection.DBID;
|
|
return _DBID;
|
|
}
|
|
}
|
|
private ConnectionInfo _MyConnection;
|
|
public ConnectionInfo MyConnection
|
|
{
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
get
|
|
{
|
|
CanReadProperty("MyConnection",true);
|
|
if (_MyConnection == null && _DBID != 0) _MyConnection = ConnectionInfo.Get(_DBID);
|
|
return _MyConnection;
|
|
}
|
|
}
|
|
private string _Name = string.Empty;
|
|
public string Name
|
|
{
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
get
|
|
{
|
|
CanReadProperty("Name",true);
|
|
return _Name;
|
|
}
|
|
}
|
|
private string _Title = string.Empty;
|
|
public string Title
|
|
{
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
get
|
|
{
|
|
CanReadProperty("Title",true);
|
|
return _Title;
|
|
}
|
|
}
|
|
private string _ShortName = string.Empty;
|
|
public string ShortName
|
|
{
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
get
|
|
{
|
|
CanReadProperty("ShortName",true);
|
|
return _ShortName;
|
|
}
|
|
}
|
|
private int? _FormatID;
|
|
public int? FormatID
|
|
{
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
get
|
|
{
|
|
CanReadProperty("FormatID",true);
|
|
if (_MyFormat != null) _FormatID = _MyFormat.FormatID;
|
|
return _FormatID;
|
|
}
|
|
}
|
|
private FormatInfo _MyFormat;
|
|
public FormatInfo MyFormat
|
|
{
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
get
|
|
{
|
|
CanReadProperty("MyFormat",true);
|
|
if (_MyFormat == null && _FormatID != null) _MyFormat = FormatInfo.Get((int)_FormatID);
|
|
return _MyFormat;
|
|
}
|
|
}
|
|
private string _Config = string.Empty;
|
|
public string Config
|
|
{
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
get
|
|
{
|
|
CanReadProperty("Config",true);
|
|
return _Config;
|
|
}
|
|
}
|
|
private DateTime _DTS = new DateTime();
|
|
public DateTime DTS
|
|
{
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
get
|
|
{
|
|
CanReadProperty("DTS",true);
|
|
return _DTS;
|
|
}
|
|
}
|
|
private string _UsrID = string.Empty;
|
|
public string UsrID
|
|
{
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
get
|
|
{
|
|
CanReadProperty("UsrID",true);
|
|
return _UsrID;
|
|
}
|
|
}
|
|
private int _FolderAssignmentCount = 0;
|
|
/// <summary>
|
|
/// Count of FolderAssignments for this Folder
|
|
/// </summary>
|
|
public int FolderAssignmentCount
|
|
{
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
get
|
|
{
|
|
CanReadProperty("FolderAssignmentCount",true);
|
|
return _FolderAssignmentCount;
|
|
}
|
|
}
|
|
private AssignmentInfoList _FolderAssignments = null;
|
|
[TypeConverter(typeof(AssignmentInfoListConverter))]
|
|
public AssignmentInfoList FolderAssignments
|
|
{
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
get
|
|
{
|
|
CanReadProperty("FolderAssignments",true);
|
|
if (_FolderAssignmentCount > 0 && _FolderAssignments == null)
|
|
_FolderAssignments = AssignmentInfoList.GetByFolderID(_FolderID);
|
|
return _FolderAssignments;
|
|
}
|
|
}
|
|
private int _FolderDocVersionCount = 0;
|
|
/// <summary>
|
|
/// Count of FolderDocVersions for this Folder
|
|
/// </summary>
|
|
public int FolderDocVersionCount
|
|
{
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
get
|
|
{
|
|
CanReadProperty("FolderDocVersionCount",true);
|
|
return _FolderDocVersionCount;
|
|
}
|
|
}
|
|
private DocVersionInfoList _FolderDocVersions = null;
|
|
[TypeConverter(typeof(DocVersionInfoListConverter))]
|
|
public DocVersionInfoList FolderDocVersions
|
|
{
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
get
|
|
{
|
|
CanReadProperty("FolderDocVersions",true);
|
|
if (_FolderDocVersionCount > 0 && _FolderDocVersions == null)
|
|
_FolderDocVersions = DocVersionInfoList.GetByFolderID(_FolderID);
|
|
return _FolderDocVersions;
|
|
}
|
|
}
|
|
private int _ChildFolderCount = 0;
|
|
/// <summary>
|
|
/// Count of ChildFolders for this Folder
|
|
/// </summary>
|
|
public int ChildFolderCount
|
|
{
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
get
|
|
{
|
|
CanReadProperty("ChildFolderCount",true);
|
|
return _ChildFolderCount;
|
|
}
|
|
}
|
|
private FolderInfoList _ChildFolders = null;
|
|
[TypeConverter(typeof(FolderInfoListConverter))]
|
|
public FolderInfoList ChildFolders
|
|
{
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
get
|
|
{
|
|
CanReadProperty("ChildFolders",true);
|
|
if (_ChildFolderCount > 0 && _ChildFolders == null)
|
|
_ChildFolders = FolderInfoList.GetChildren(_FolderID);
|
|
return _ChildFolders;
|
|
}
|
|
}
|
|
// TODO: Replace base FolderInfo.ToString function as necessary
|
|
/// <summary>
|
|
/// Overrides Base ToString
|
|
/// </summary>
|
|
/// <returns>A string representation of current FolderInfo</returns>
|
|
//public override string ToString()
|
|
//{
|
|
// return base.ToString();
|
|
//}
|
|
// TODO: Check FolderInfo.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 FolderInfo</returns>
|
|
protected override object GetIdValue()
|
|
{
|
|
return _FolderID;
|
|
}
|
|
#endregion
|
|
#region Factory Methods
|
|
private FolderInfo()
|
|
{/* require use of factory methods */
|
|
_AllList.Add(this);
|
|
}
|
|
public void Dispose()
|
|
{
|
|
_AllList.Remove(this);
|
|
_AllByPrimaryKey.Remove(FolderID.ToString());
|
|
}
|
|
public virtual Folder Get()
|
|
{
|
|
return _Editable = Folder.Get(_FolderID);
|
|
}
|
|
public static void Refresh(Folder tmp)
|
|
{
|
|
FolderInfo tmpInfo = GetExistingByPrimaryKey(tmp.FolderID);
|
|
if (tmpInfo == null) return;
|
|
tmpInfo.RefreshFields(tmp);
|
|
}
|
|
private void RefreshFields(Folder tmp)
|
|
{
|
|
_ParentID = tmp.ParentID;
|
|
_DBID = tmp.DBID;
|
|
_Name = tmp.Name;
|
|
_Title = tmp.Title;
|
|
_ShortName = tmp.ShortName;
|
|
_FormatID = tmp.FormatID;
|
|
_Config = tmp.Config;
|
|
_DTS = tmp.DTS;
|
|
_UsrID = tmp.UsrID;
|
|
_FolderInfoExtension.Refresh(this);
|
|
_MyParent = null;
|
|
_MyConnection = null;
|
|
_MyFormat = null;
|
|
OnChange();// raise an event
|
|
}
|
|
public static void Refresh(ConnectionFolder tmp)
|
|
{
|
|
FolderInfo tmpInfo = GetExistingByPrimaryKey(tmp.FolderID);
|
|
if (tmpInfo == null) return;
|
|
tmpInfo.RefreshFields(tmp);
|
|
}
|
|
private void RefreshFields(ConnectionFolder tmp)
|
|
{
|
|
_ParentID = tmp.ParentID;
|
|
_Name = tmp.Name;
|
|
_Title = tmp.Title;
|
|
_ShortName = tmp.ShortName;
|
|
_FormatID = tmp.FormatID;
|
|
_Config = tmp.Config;
|
|
_DTS = tmp.DTS;
|
|
_UsrID = tmp.UsrID;
|
|
_FolderInfoExtension.Refresh(this);
|
|
_MyParent = null;
|
|
_MyConnection = null;
|
|
_MyFormat = null;
|
|
OnChange();// raise an event
|
|
}
|
|
public static void Refresh(FormatFolder tmp)
|
|
{
|
|
FolderInfo tmpInfo = GetExistingByPrimaryKey(tmp.FolderID);
|
|
if (tmpInfo == null) return;
|
|
tmpInfo.RefreshFields(tmp);
|
|
}
|
|
private void RefreshFields(FormatFolder tmp)
|
|
{
|
|
_ParentID = tmp.ParentID;
|
|
_DBID = tmp.DBID;
|
|
_Name = tmp.Name;
|
|
_Title = tmp.Title;
|
|
_ShortName = tmp.ShortName;
|
|
_Config = tmp.Config;
|
|
_DTS = tmp.DTS;
|
|
_UsrID = tmp.UsrID;
|
|
_FolderInfoExtension.Refresh(this);
|
|
_MyParent = null;
|
|
_MyConnection = null;
|
|
_MyFormat = null;
|
|
OnChange();// raise an event
|
|
}
|
|
public static FolderInfo Get(int folderID)
|
|
{
|
|
//if (!CanGetObject())
|
|
// throw new System.Security.SecurityException("User not authorized to view a Folder");
|
|
try
|
|
{
|
|
FolderInfo tmp = GetExistingByPrimaryKey(folderID);
|
|
if (tmp == null)
|
|
{
|
|
tmp = DataPortal.Fetch<FolderInfo>(new PKCriteria(folderID));
|
|
_AllList.Add(tmp);
|
|
}
|
|
if (tmp.ErrorMessage == "No Record Found") tmp = null;
|
|
return tmp;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw new DbCslaException("Error on FolderInfo.Get", ex);
|
|
}
|
|
}
|
|
#endregion
|
|
#region Data Access Portal
|
|
internal FolderInfo(SafeDataReader dr)
|
|
{
|
|
if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] FolderInfo.Constructor", GetHashCode());
|
|
try
|
|
{
|
|
ReadData(dr);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
if(_MyLog.IsErrorEnabled)_MyLog.Error("FolderInfo.Constructor", ex);
|
|
throw new DbCslaException("FolderInfo.Constructor", ex);
|
|
}
|
|
}
|
|
[Serializable()]
|
|
protected class PKCriteria
|
|
{
|
|
private int _FolderID;
|
|
public int FolderID
|
|
{ get { return _FolderID; } }
|
|
public PKCriteria(int folderID)
|
|
{
|
|
_FolderID = folderID;
|
|
}
|
|
}
|
|
private void ReadData(SafeDataReader dr)
|
|
{
|
|
if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] FolderInfo.ReadData", GetHashCode());
|
|
try
|
|
{
|
|
_FolderID = dr.GetInt32("FolderID");
|
|
_ParentID = dr.GetInt32("ParentID");
|
|
_DBID = dr.GetInt32("DBID");
|
|
_Name = dr.GetString("Name");
|
|
_Title = dr.GetString("Title");
|
|
_ShortName = dr.GetString("ShortName");
|
|
_FormatID = (int?)dr.GetValue("FormatID");
|
|
_Config = dr.GetString("Config");
|
|
_DTS = dr.GetDateTime("DTS");
|
|
_UsrID = dr.GetString("UsrID");
|
|
_FolderAssignmentCount = dr.GetInt32("AssignmentCount");
|
|
_FolderDocVersionCount = dr.GetInt32("DocVersionCount");
|
|
_ChildFolderCount = dr.GetInt32("ChildCount");
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
if(_MyLog.IsErrorEnabled)_MyLog.Error("FolderInfo.ReadData", ex);
|
|
_ErrorMessage = ex.Message;
|
|
throw new DbCslaException("FolderInfo.ReadData", ex);
|
|
}
|
|
}
|
|
private void DataPortal_Fetch(PKCriteria criteria)
|
|
{
|
|
if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] FolderInfo.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 = "getFolder";
|
|
cm.Parameters.AddWithValue("@FolderID", criteria.FolderID);
|
|
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("FolderInfo.DataPortal_Fetch", ex);
|
|
_ErrorMessage = ex.Message;
|
|
throw new DbCslaException("FolderInfo.DataPortal_Fetch", ex);
|
|
}
|
|
}
|
|
#endregion
|
|
// Standard Refresh
|
|
#region extension
|
|
FolderInfoExtension _FolderInfoExtension = new FolderInfoExtension();
|
|
[Serializable()]
|
|
partial class FolderInfoExtension : extensionBase {}
|
|
[Serializable()]
|
|
class extensionBase
|
|
{
|
|
// Default Refresh
|
|
public virtual void Refresh(FolderInfo tmp) { }
|
|
}
|
|
#endregion
|
|
} // Class
|
|
#region Converter
|
|
internal class FolderInfoConverter : ExpandableObjectConverter
|
|
{
|
|
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
|
|
{
|
|
if (destType == typeof(string) && value is FolderInfo)
|
|
{
|
|
// Return the ToString value
|
|
return ((FolderInfo)value).ToString();
|
|
}
|
|
return base.ConvertTo(context, culture, value, destType);
|
|
}
|
|
}
|
|
#endregion
|
|
} // Namespace
|