Use ‘GetJustStage’ for Stage & StageInfo gets of data.

Provide methods to use ‘GetJustStage’ from application
Use ‘GetJustFormat’ for format infos
This commit is contained in:
2015-02-17 17:30:47 +00:00
parent 9671a394be
commit 3053c892a1
10 changed files with 191 additions and 13 deletions

View File

@@ -0,0 +1,177 @@
// ========================================================================
// Copyright 2015 - Volian Enterprises, Inc. All rights reserved.
// Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE
// ------------------------------------------------------------------------
// $Workfile: $ $Revision: $
// $Author: $ $Date: $
//
// $History: $
// ========================================================================
using System;
//using System.Collections.Generic;
//using System.Collections.Specialized;
//using System.Text;
//using System.IO;
//using System.Xml.Serialization;
//using System.Xml;
//using System.Xml.XPath;
using Csla;
using Csla.Data;
using System.Data.SqlClient;
using System.Data;
namespace VEPROMS.CSLA.Library
{
public partial class StageInfo
{
public static StageInfo GetJustStage(int stageID)
{
try
{
StageInfo tmp = GetCachedByPrimaryKey(stageID);
if (tmp == null)
{
tmp = DataPortal.Fetch<StageInfo>(new PKCriteriaJustStage(stageID));
AddToCache(tmp);
}
if (tmp.ErrorMessage == "No Record Found")
{
tmp.Dispose(); // Clean-up StageInfo
tmp = null;
}
return tmp;
}
catch (Exception ex)
{
throw new DbCslaException("Error on StageInfo.GetJustStage", ex);
}
}
[Serializable()]
protected class PKCriteriaJustStage
{
private int _StageID;
public int StageID
{ get { return _StageID; } }
public PKCriteriaJustStage(int stageID)
{
_StageID = stageID;
}
}
private void DataPortal_Fetch(PKCriteriaJustStage criteria)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] StageInfo.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 = "getJustStage";
cm.Parameters.AddWithValue("@StageID", criteria.StageID);
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("StageInfo.DataPortal_Fetch", ex);
_ErrorMessage = ex.Message;
throw new DbCslaException("StageInfo.DataPortal_Fetch", ex);
}
}
}
public partial class Stage
{
public static Stage GetJustStage(int stageID)
{
if (!CanGetObject())
throw new System.Security.SecurityException("User not authorized to view a Stage");
try
{
Stage tmp = DataPortal.Fetch<Stage>(new PKCriteriaJustStage(stageID));
if (tmp.ErrorMessage == "No Record Found")
{
tmp.Dispose(); // Clean-up Stage
tmp = null;
}
return tmp;
}
catch (Exception ex)
{
throw new DbCslaException("Error on Stage.GetJustStage", ex);
}
}
private void DataPortal_Fetch(PKCriteriaJustStage 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 = "getJustStage";
cm.Parameters.AddWithValue("@StageID", criteria.StageID);
cm.CommandTimeout = Database.DefaultTimeout;
using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader()))
{
if (!dr.Read())
{
_ErrorMessage = "No Record Found";
return;
}
ReadData(dr);
// Don't load child objects
//dr.NextResult();
//_StageChecks = StageChecks.Get(dr);
// load child objects
//dr.NextResult();
//_StageVersions = StageVersions.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("Stage.DataPortal_Fetch", ex);
_ErrorMessage = ex.Message;
throw new DbCslaException("Stage.DataPortal_Fetch", ex);
}
}
[Serializable()]
protected class PKCriteriaJustStage
{
private int _StageID;
public int StageID
{ get { return _StageID; } }
public PKCriteriaJustStage(int stageID)
{
_StageID = stageID;
}
}
#region Log4Net
private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion
}
}

View File

@@ -163,7 +163,7 @@ namespace VEPROMS.CSLA.Library
get
{
CanReadProperty("MyStage", true);
if (_MyStage == null && _StageID != 0) _MyStage = Stage.Get(_StageID);
if (_MyStage == null && _StageID != 0) _MyStage = Stage.GetJustStage(_StageID);
return _MyStage;
}
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]

View File

@@ -140,7 +140,7 @@ namespace VEPROMS.CSLA.Library
get
{
CanReadProperty("MyStage", true);
if (_MyStage == null && _StageID != 0) _MyStage = StageInfo.Get(_StageID);
if (_MyStage == null && _StageID != 0) _MyStage = StageInfo.GetJustStage(_StageID);
return _MyStage;
}
}

View File

@@ -509,7 +509,7 @@ namespace VEPROMS.CSLA.Library
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandText = "getFormat";
cm.CommandText = "getJustFormat";
cm.Parameters.AddWithValue("@FormatID", criteria.FormatID);
cm.CommandTimeout = Database.DefaultTimeout;
using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader()))

View File

@@ -78,7 +78,7 @@ namespace VEPROMS.CSLA.Library
get
{
CanReadProperty("MyStage", true);
if (_MyStage == null && _StageID != 0) _MyStage = Stage.Get(_StageID);
if (_MyStage == null && _StageID != 0) _MyStage = Stage.GetJustStage(_StageID);
return _MyStage;
}
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]

View File

@@ -78,7 +78,7 @@ namespace VEPROMS.CSLA.Library
get
{
CanReadProperty("MyStage", true);
if (_MyStage == null && _StageID != 0) _MyStage = Stage.Get(_StageID);
if (_MyStage == null && _StageID != 0) _MyStage = Stage.GetJustStage(_StageID);
return _MyStage;
}
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]

View File

@@ -287,7 +287,7 @@ namespace VEPROMS.CSLA.Library
}
public virtual Stage Get()
{
return _Editable = Stage.Get(_StageID);
return _Editable = Stage.GetJustStage(_StageID);
}
public static void Refresh(Stage tmp)
{
@@ -400,6 +400,7 @@ namespace VEPROMS.CSLA.Library
return;
}
ReadData(dr);
}
}
// removing of item only needed for local data portal

View File

@@ -163,7 +163,7 @@ namespace VEPROMS.CSLA.Library
get
{
CanReadProperty("MyStage", true);
if (_MyStage == null && _StageID != 0) _MyStage = Stage.Get(_StageID);
if (_MyStage == null && _StageID != 0) _MyStage = Stage.GetJustStage(_StageID);
return _MyStage;
}
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]

View File

@@ -140,7 +140,7 @@ namespace VEPROMS.CSLA.Library
get
{
CanReadProperty("MyStage", true);
if (_MyStage == null && _StageID != 0) _MyStage = StageInfo.Get(_StageID);
if (_MyStage == null && _StageID != 0) _MyStage = StageInfo.GetJustStage(_StageID);
return _MyStage;
}
}