Files
SourceCode/PROMS/VEPROMS.CSLA.Library/Extension/RODbExt.cs
T
2026-09-01 08:21:41 -04:00

175 lines
5.1 KiB
C#

// ========================================================================
// Copyright 2006 - Volian Enterprises, Inc. All rights reserved.
// Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE
// ------------------------------------------------------------------------
// $Workfile: $ $Revision: $
// $Author: $ $Date: $
//
// $History: $
// ========================================================================
using System;
using Csla;
using Csla.Data;
using System.Data.SqlClient;
using System.Data;
namespace VEPROMS.CSLA.Library
{
public partial class RODbInfo
{
#region RODb Config
[NonSerialized]
private RODbConfig _RODbConfig;
public RODbConfig RODbConfig => _RODbConfig ?? (_RODbConfig = new RODbConfig(this));
#endregion
public static RODbInfo GetJustRODB(int rODbID)
{
try
{
RODbInfo tmp = GetCachedByPrimaryKey(rODbID);
if (tmp == null)
{
tmp = DataPortal.Fetch<RODbInfo>(new PKCriteriaJustRODB(rODbID));
AddToCache(tmp);
}
if (tmp.ErrorMessage == "No Record Found")
{
tmp.Dispose(); // Clean-up RODbInfo
tmp = null;
}
return tmp;
}
catch (Exception ex)
{
throw new DbCslaException("Error on RODbInfo.Get", ex);
}
}
[Serializable()]
protected class PKCriteriaJustRODB
{
private readonly int _RODbID;
public int RODbID => _RODbID;
public PKCriteriaJustRODB(int rODbID) => _RODbID = rODbID;
}
private void DataPortal_Fetch(PKCriteriaJustRODB criteria)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RODbInfo.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 = "getJustRODb";
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);
}
}
// 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("RODbInfo.DataPortal_Fetch", ex);
_ErrorMessage = ex.Message;
throw new DbCslaException("RODbInfo.DataPortal_Fetch", ex);
}
}
}
public partial class RODb
{
public static RODb GetJustRoDb(int rODbID)
{
try
{
RODb tmp = DataPortal.Fetch<RODb>(new PKCriteriaJustRoDb(rODbID));
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);
}
}
private void DataPortal_Fetch(PKCriteriaJustRoDb 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 = "getJustRODb";
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);
}
}
// 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);
}
}
[Serializable()]
protected class PKCriteriaJustRoDb
{
private readonly int _RODbID;
public int RODbID => _RODbID;
public PKCriteriaJustRoDb(int rODbID) => _RODbID = rODbID;
}
#region RODb Config
[NonSerialized]
private RODbConfig _RODbConfig;
public RODbConfig RODbConfig
{
get
{
if (_RODbConfig == null)
{
_RODbConfig = new RODbConfig(this);
_RODbConfig.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(_RODbConfig_PropertyChanged);
}
return _RODbConfig;
}
}
private void _RODbConfig_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) => Config = _RODbConfig.ToString();
#endregion
}
}