408 lines
12 KiB
C#
408 lines
12 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 AnnotationInfoEvent(object sender);
|
|
/// <summary>
|
|
/// AnnotationInfo Generated by MyGeneration using the CSLA Object Mapping template
|
|
/// </summary>
|
|
[Serializable()]
|
|
[TypeConverter(typeof(AnnotationInfoConverter))]
|
|
public partial class AnnotationInfo : ReadOnlyBase<AnnotationInfo>, IDisposable
|
|
{
|
|
public event AnnotationInfoEvent 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<AnnotationInfo> _AllList = new List<AnnotationInfo>();
|
|
private static Dictionary<string, AnnotationInfo> _AllByPrimaryKey = new Dictionary<string, AnnotationInfo>();
|
|
private static void ConvertListToDictionary()
|
|
{
|
|
List<AnnotationInfo> remove = new List<AnnotationInfo>();
|
|
foreach (AnnotationInfo tmp in _AllList)
|
|
{
|
|
_AllByPrimaryKey[tmp.AnnotationID.ToString()]=tmp; // Primary Key
|
|
remove.Add(tmp);
|
|
}
|
|
foreach (AnnotationInfo tmp in remove)
|
|
_AllList.Remove(tmp);
|
|
}
|
|
internal static void AddList(AnnotationInfoList lst)
|
|
{
|
|
foreach (AnnotationInfo item in lst) _AllList.Add(item);
|
|
}
|
|
public static AnnotationInfo GetExistingByPrimaryKey(int annotationID)
|
|
{
|
|
ConvertListToDictionary();
|
|
string key = annotationID.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 Annotation _Editable;
|
|
private IVEHasBrokenRules HasBrokenRules
|
|
{
|
|
get
|
|
{
|
|
IVEHasBrokenRules hasBrokenRules = null;
|
|
if (_Editable != null)
|
|
hasBrokenRules = _Editable.HasBrokenRules;
|
|
return hasBrokenRules;
|
|
}
|
|
}
|
|
private int _AnnotationID;
|
|
[System.ComponentModel.DataObjectField(true, true)]
|
|
public int AnnotationID
|
|
{
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
get
|
|
{
|
|
CanReadProperty("AnnotationID",true);
|
|
return _AnnotationID;
|
|
}
|
|
}
|
|
private int _ItemID;
|
|
public int ItemID
|
|
{
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
get
|
|
{
|
|
CanReadProperty("ItemID",true);
|
|
if (_MyItem != null) _ItemID = _MyItem.ItemID;
|
|
return _ItemID;
|
|
}
|
|
}
|
|
private ItemInfo _MyItem;
|
|
public ItemInfo MyItem
|
|
{
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
get
|
|
{
|
|
CanReadProperty("MyItem",true);
|
|
if (_MyItem == null && _ItemID != 0) _MyItem = ItemInfo.Get(_ItemID);
|
|
return _MyItem;
|
|
}
|
|
}
|
|
private int _TypeID;
|
|
public int TypeID
|
|
{
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
get
|
|
{
|
|
CanReadProperty("TypeID",true);
|
|
if (_MyAnnotationType != null) _TypeID = _MyAnnotationType.TypeID;
|
|
return _TypeID;
|
|
}
|
|
}
|
|
private AnnotationTypeInfo _MyAnnotationType;
|
|
public AnnotationTypeInfo MyAnnotationType
|
|
{
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
get
|
|
{
|
|
CanReadProperty("MyAnnotationType",true);
|
|
if (_MyAnnotationType == null && _TypeID != 0) _MyAnnotationType = AnnotationTypeInfo.Get(_TypeID);
|
|
return _MyAnnotationType;
|
|
}
|
|
}
|
|
private string _RtfText = string.Empty;
|
|
public string RtfText
|
|
{
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
get
|
|
{
|
|
CanReadProperty("RtfText",true);
|
|
return _RtfText;
|
|
}
|
|
}
|
|
private string _SearchText = string.Empty;
|
|
public string SearchText
|
|
{
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
get
|
|
{
|
|
CanReadProperty("SearchText",true);
|
|
return _SearchText;
|
|
}
|
|
}
|
|
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 _UserID = string.Empty;
|
|
public string UserID
|
|
{
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
get
|
|
{
|
|
CanReadProperty("UserID",true);
|
|
return _UserID;
|
|
}
|
|
}
|
|
// TODO: Replace base AnnotationInfo.ToString function as necessary
|
|
/// <summary>
|
|
/// Overrides Base ToString
|
|
/// </summary>
|
|
/// <returns>A string representation of current AnnotationInfo</returns>
|
|
//public override string ToString()
|
|
//{
|
|
// return base.ToString();
|
|
//}
|
|
// TODO: Check AnnotationInfo.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 AnnotationInfo</returns>
|
|
protected override object GetIdValue()
|
|
{
|
|
return _AnnotationID;
|
|
}
|
|
#endregion
|
|
#region Factory Methods
|
|
private AnnotationInfo()
|
|
{/* require use of factory methods */
|
|
_AllList.Add(this);
|
|
}
|
|
public void Dispose()
|
|
{
|
|
_AllList.Remove(this);
|
|
_AllByPrimaryKey.Remove(AnnotationID.ToString());
|
|
}
|
|
public virtual Annotation Get()
|
|
{
|
|
return _Editable = Annotation.Get(_AnnotationID);
|
|
}
|
|
public static void Refresh(Annotation tmp)
|
|
{
|
|
AnnotationInfo tmpInfo = GetExistingByPrimaryKey(tmp.AnnotationID);
|
|
if (tmpInfo == null) return;
|
|
tmpInfo.RefreshFields(tmp);
|
|
}
|
|
private void RefreshFields(Annotation tmp)
|
|
{
|
|
_ItemID = tmp.ItemID;
|
|
_TypeID = tmp.TypeID;
|
|
_RtfText = tmp.RtfText;
|
|
_SearchText = tmp.SearchText;
|
|
_Config = tmp.Config;
|
|
_DTS = tmp.DTS;
|
|
_UserID = tmp.UserID;
|
|
_AnnotationInfoExtension.Refresh(this);
|
|
_MyItem = null;
|
|
_MyAnnotationType = null;
|
|
OnChange();// raise an event
|
|
}
|
|
public static void Refresh(AnnotationTypeAnnotation tmp)
|
|
{
|
|
AnnotationInfo tmpInfo = GetExistingByPrimaryKey(tmp.AnnotationID);
|
|
if (tmpInfo == null) return;
|
|
tmpInfo.RefreshFields(tmp);
|
|
}
|
|
private void RefreshFields(AnnotationTypeAnnotation tmp)
|
|
{
|
|
_ItemID = tmp.ItemID;
|
|
_RtfText = tmp.RtfText;
|
|
_SearchText = tmp.SearchText;
|
|
_Config = tmp.Config;
|
|
_DTS = tmp.DTS;
|
|
_UserID = tmp.UserID;
|
|
_AnnotationInfoExtension.Refresh(this);
|
|
_MyItem = null;
|
|
_MyAnnotationType = null;
|
|
OnChange();// raise an event
|
|
}
|
|
public static void Refresh(ItemAnnotation tmp)
|
|
{
|
|
AnnotationInfo tmpInfo = GetExistingByPrimaryKey(tmp.AnnotationID);
|
|
if (tmpInfo == null) return;
|
|
tmpInfo.RefreshFields(tmp);
|
|
}
|
|
private void RefreshFields(ItemAnnotation tmp)
|
|
{
|
|
_TypeID = tmp.TypeID;
|
|
_RtfText = tmp.RtfText;
|
|
_SearchText = tmp.SearchText;
|
|
_Config = tmp.Config;
|
|
_DTS = tmp.DTS;
|
|
_UserID = tmp.UserID;
|
|
_AnnotationInfoExtension.Refresh(this);
|
|
_MyItem = null;
|
|
_MyAnnotationType = null;
|
|
OnChange();// raise an event
|
|
}
|
|
public static AnnotationInfo Get(int annotationID)
|
|
{
|
|
//if (!CanGetObject())
|
|
// throw new System.Security.SecurityException("User not authorized to view a Annotation");
|
|
try
|
|
{
|
|
AnnotationInfo tmp = GetExistingByPrimaryKey(annotationID);
|
|
if (tmp == null)
|
|
{
|
|
tmp = DataPortal.Fetch<AnnotationInfo>(new PKCriteria(annotationID));
|
|
_AllList.Add(tmp);
|
|
}
|
|
if (tmp.ErrorMessage == "No Record Found") tmp = null;
|
|
return tmp;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw new DbCslaException("Error on AnnotationInfo.Get", ex);
|
|
}
|
|
}
|
|
#endregion
|
|
#region Data Access Portal
|
|
internal AnnotationInfo(SafeDataReader dr)
|
|
{
|
|
if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] AnnotationInfo.Constructor", GetHashCode());
|
|
try
|
|
{
|
|
ReadData(dr);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
if(_MyLog.IsErrorEnabled)_MyLog.Error("AnnotationInfo.Constructor", ex);
|
|
throw new DbCslaException("AnnotationInfo.Constructor", ex);
|
|
}
|
|
}
|
|
[Serializable()]
|
|
protected class PKCriteria
|
|
{
|
|
private int _AnnotationID;
|
|
public int AnnotationID
|
|
{ get { return _AnnotationID; } }
|
|
public PKCriteria(int annotationID)
|
|
{
|
|
_AnnotationID = annotationID;
|
|
}
|
|
}
|
|
private void ReadData(SafeDataReader dr)
|
|
{
|
|
if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] AnnotationInfo.ReadData", GetHashCode());
|
|
try
|
|
{
|
|
_AnnotationID = dr.GetInt32("AnnotationID");
|
|
_ItemID = dr.GetInt32("ItemID");
|
|
_TypeID = dr.GetInt32("TypeID");
|
|
_RtfText = dr.GetString("RtfText");
|
|
_SearchText = dr.GetString("SearchText");
|
|
_Config = dr.GetString("Config");
|
|
_DTS = dr.GetDateTime("DTS");
|
|
_UserID = dr.GetString("UserID");
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
if(_MyLog.IsErrorEnabled)_MyLog.Error("AnnotationInfo.ReadData", ex);
|
|
_ErrorMessage = ex.Message;
|
|
throw new DbCslaException("AnnotationInfo.ReadData", ex);
|
|
}
|
|
}
|
|
private void DataPortal_Fetch(PKCriteria criteria)
|
|
{
|
|
if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] AnnotationInfo.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 = "getAnnotation";
|
|
cm.Parameters.AddWithValue("@AnnotationID", criteria.AnnotationID);
|
|
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("AnnotationInfo.DataPortal_Fetch", ex);
|
|
_ErrorMessage = ex.Message;
|
|
throw new DbCslaException("AnnotationInfo.DataPortal_Fetch", ex);
|
|
}
|
|
}
|
|
#endregion
|
|
// Standard Refresh
|
|
#region extension
|
|
AnnotationInfoExtension _AnnotationInfoExtension = new AnnotationInfoExtension();
|
|
[Serializable()]
|
|
partial class AnnotationInfoExtension : extensionBase {}
|
|
[Serializable()]
|
|
class extensionBase
|
|
{
|
|
// Default Refresh
|
|
public virtual void Refresh(AnnotationInfo tmp) { }
|
|
}
|
|
#endregion
|
|
} // Class
|
|
#region Converter
|
|
internal class AnnotationInfoConverter : ExpandableObjectConverter
|
|
{
|
|
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
|
|
{
|
|
if (destType == typeof(string) && value is AnnotationInfo)
|
|
{
|
|
// Return the ToString value
|
|
return ((AnnotationInfo)value).ToString();
|
|
}
|
|
return base.ConvertTo(context, culture, value, destType);
|
|
}
|
|
}
|
|
#endregion
|
|
} // Namespace
|