285 lines
8.7 KiB
C#
285 lines
8.7 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 ZTransitionInfoEvent(object sender);
|
|
/// <summary>
|
|
/// ZTransitionInfo Generated by MyGeneration using the CSLA Object Mapping template
|
|
/// </summary>
|
|
[Serializable()]
|
|
[TypeConverter(typeof(ZTransitionInfoConverter))]
|
|
public partial class ZTransitionInfo : ReadOnlyBase<ZTransitionInfo>, IDisposable
|
|
{
|
|
public event ZTransitionInfoEvent 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<ZTransitionInfo> _AllList = new List<ZTransitionInfo>();
|
|
private static Dictionary<string, ZTransitionInfo> _AllByPrimaryKey = new Dictionary<string, ZTransitionInfo>();
|
|
private static void ConvertListToDictionary()
|
|
{
|
|
List<ZTransitionInfo> remove = new List<ZTransitionInfo>();
|
|
foreach (ZTransitionInfo tmp in _AllList)
|
|
{
|
|
_AllByPrimaryKey[tmp.TransitionID.ToString()]=tmp; // Primary Key
|
|
remove.Add(tmp);
|
|
}
|
|
foreach (ZTransitionInfo tmp in remove)
|
|
_AllList.Remove(tmp);
|
|
}
|
|
public static ZTransitionInfo GetExistingByPrimaryKey(int transitionID)
|
|
{
|
|
ConvertListToDictionary();
|
|
string key = transitionID.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 ZTransition _Editable;
|
|
private IVEHasBrokenRules HasBrokenRules
|
|
{
|
|
get
|
|
{
|
|
IVEHasBrokenRules hasBrokenRules = null;
|
|
if (_Editable != null)
|
|
hasBrokenRules = _Editable.HasBrokenRules;
|
|
return hasBrokenRules;
|
|
}
|
|
}
|
|
private int _TransitionID;
|
|
[System.ComponentModel.DataObjectField(true, true)]
|
|
public int TransitionID
|
|
{
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
get
|
|
{
|
|
CanReadProperty("TransitionID",true);
|
|
if (_MyTransition != null) _TransitionID = _MyTransition.TransitionID;
|
|
return _TransitionID;
|
|
}
|
|
}
|
|
private TransitionInfo _MyTransition;
|
|
[System.ComponentModel.DataObjectField(true, true)]
|
|
public TransitionInfo MyTransition
|
|
{
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
get
|
|
{
|
|
CanReadProperty("MyTransition",true);
|
|
if (_MyTransition == null && _TransitionID != 0) _MyTransition = TransitionInfo.Get(_TransitionID);
|
|
return _MyTransition;
|
|
}
|
|
}
|
|
private string _Oldto = string.Empty;
|
|
public string Oldto
|
|
{
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
get
|
|
{
|
|
CanReadProperty("Oldto",true);
|
|
return _Oldto;
|
|
}
|
|
}
|
|
// TODO: Replace base ZTransitionInfo.ToString function as necessary
|
|
/// <summary>
|
|
/// Overrides Base ToString
|
|
/// </summary>
|
|
/// <returns>A string representation of current ZTransitionInfo</returns>
|
|
//public override string ToString()
|
|
//{
|
|
// return base.ToString();
|
|
//}
|
|
// TODO: Check ZTransitionInfo.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 ZTransitionInfo</returns>
|
|
protected override object GetIdValue()
|
|
{
|
|
return _TransitionID;
|
|
}
|
|
#endregion
|
|
#region Factory Methods
|
|
private ZTransitionInfo()
|
|
{/* require use of factory methods */
|
|
_AllList.Add(this);
|
|
}
|
|
public void Dispose()
|
|
{
|
|
_AllList.Remove(this);
|
|
_AllByPrimaryKey.Remove(TransitionID.ToString());
|
|
}
|
|
public virtual ZTransition Get()
|
|
{
|
|
return _Editable = ZTransition.Get(_TransitionID);
|
|
}
|
|
public static void Refresh(ZTransition tmp)
|
|
{
|
|
ZTransitionInfo tmpInfo = GetExistingByPrimaryKey(tmp.TransitionID);
|
|
if (tmpInfo == null) return;
|
|
tmpInfo.RefreshFields(tmp);
|
|
}
|
|
private void RefreshFields(ZTransition tmp)
|
|
{
|
|
_Oldto = tmp.Oldto;
|
|
_ZTransitionInfoExtension.Refresh(this);
|
|
_MyTransition = null;
|
|
OnChange();// raise an event
|
|
}
|
|
public static ZTransitionInfo Get(int transitionID)
|
|
{
|
|
//if (!CanGetObject())
|
|
// throw new System.Security.SecurityException("User not authorized to view a ZTransition");
|
|
try
|
|
{
|
|
ZTransitionInfo tmp = GetExistingByPrimaryKey(transitionID);
|
|
if (tmp == null)
|
|
{
|
|
tmp = DataPortal.Fetch<ZTransitionInfo>(new PKCriteria(transitionID));
|
|
_AllList.Add(tmp);
|
|
}
|
|
if (tmp.ErrorMessage == "No Record Found")
|
|
{
|
|
tmp._TransitionID = transitionID;
|
|
}
|
|
return tmp;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw new DbCslaException("Error on ZTransitionInfo.Get", ex);
|
|
}
|
|
}
|
|
#endregion
|
|
#region Data Access Portal
|
|
internal ZTransitionInfo(SafeDataReader dr)
|
|
{
|
|
if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] ZTransitionInfo.Constructor", GetHashCode());
|
|
try
|
|
{
|
|
ReadData(dr);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
if(_MyLog.IsErrorEnabled)_MyLog.Error("ZTransitionInfo.Constructor", ex);
|
|
throw new DbCslaException("ZTransitionInfo.Constructor", ex);
|
|
}
|
|
}
|
|
[Serializable()]
|
|
protected class PKCriteria
|
|
{
|
|
private int _TransitionID;
|
|
public int TransitionID
|
|
{ get { return _TransitionID; } }
|
|
public PKCriteria(int transitionID)
|
|
{
|
|
_TransitionID = transitionID;
|
|
}
|
|
}
|
|
private void ReadData(SafeDataReader dr)
|
|
{
|
|
if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] ZTransitionInfo.ReadData", GetHashCode());
|
|
try
|
|
{
|
|
_TransitionID = dr.GetInt32("TransitionID");
|
|
_Oldto = dr.GetString("oldto");
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
if(_MyLog.IsErrorEnabled)_MyLog.Error("ZTransitionInfo.ReadData", ex);
|
|
_ErrorMessage = ex.Message;
|
|
throw new DbCslaException("ZTransitionInfo.ReadData", ex);
|
|
}
|
|
}
|
|
private void DataPortal_Fetch(PKCriteria criteria)
|
|
{
|
|
if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] ZTransitionInfo.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 = "getZTransition";
|
|
cm.Parameters.AddWithValue("@TransitionID", criteria.TransitionID);
|
|
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("ZTransitionInfo.DataPortal_Fetch", ex);
|
|
_ErrorMessage = ex.Message;
|
|
throw new DbCslaException("ZTransitionInfo.DataPortal_Fetch", ex);
|
|
}
|
|
}
|
|
#endregion
|
|
// Standard Refresh
|
|
#region extension
|
|
ZTransitionInfoExtension _ZTransitionInfoExtension = new ZTransitionInfoExtension();
|
|
[Serializable()]
|
|
partial class ZTransitionInfoExtension : extensionBase {}
|
|
[Serializable()]
|
|
class extensionBase
|
|
{
|
|
// Default Refresh
|
|
public virtual void Refresh(ZTransitionInfo tmp) { }
|
|
}
|
|
#endregion
|
|
} // Class
|
|
#region Converter
|
|
internal class ZTransitionInfoConverter : ExpandableObjectConverter
|
|
{
|
|
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
|
|
{
|
|
if (destType == typeof(string) && value is ZTransitionInfo)
|
|
{
|
|
// Return the ToString value
|
|
return ((ZTransitionInfo)value).ToString();
|
|
}
|
|
return base.ConvertTo(context, culture, value, destType);
|
|
}
|
|
}
|
|
#endregion
|
|
} // Namespace
|