175 lines
4.8 KiB
C#
175 lines
4.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
using System.Data;
|
|
using System.Data.SqlClient;
|
|
using Csla;
|
|
using Csla.Data;
|
|
using System.ComponentModel;
|
|
|
|
namespace VEPROMS.CSLA.Library
|
|
{
|
|
// B2022-047 - refresh the Content/Text field for table. Get all grids in database.
|
|
public class CriteriaAllGridIds
|
|
{
|
|
bool _AllGridIds;
|
|
public bool AllGridIds
|
|
{
|
|
get { return _AllGridIds; }
|
|
set { _AllGridIds = value; }
|
|
}
|
|
public CriteriaAllGridIds(bool allGridIds)
|
|
{
|
|
_AllGridIds = allGridIds;
|
|
}
|
|
}
|
|
[Serializable()]
|
|
[TypeConverter(typeof(FormatInfoListConverter))]
|
|
public partial class GridInfoList : ReadOnlyListBase<GridInfoList, GridInfo>
|
|
{
|
|
#region Log4Net
|
|
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
|
|
#endregion
|
|
internal new IList<GridInfo> Items
|
|
{ get { return base.Items; } }
|
|
private bool _Disposed = false;
|
|
private static int _CountCreated = 0;
|
|
private static int _CountDisposed = 0;
|
|
private static int _CountFinalized = 0;
|
|
private static int IncrementCountCreated
|
|
{ get { return ++_CountCreated; } }
|
|
private int _CountWhenCreated = IncrementCountCreated;
|
|
public static int CountCreated
|
|
{ get { return _CountCreated; } }
|
|
public static int CountNotDisposed
|
|
{ get { return _CountCreated - _CountDisposed; } }
|
|
public static int CountNotFinalized
|
|
{ get { return _CountCreated - _CountFinalized; } }
|
|
~GridInfoList()
|
|
{
|
|
_CountFinalized++;
|
|
}
|
|
public void Dispose()
|
|
{
|
|
if (_Disposed) return;
|
|
_CountDisposed++;
|
|
_Disposed = true;
|
|
}
|
|
public static GridInfoList _GridInfoList = null;
|
|
/// <summary>
|
|
/// Return a list of all GridInfo. Commented out - GridInfoList was added to fix B2022-047. Have this code here in
|
|
/// case it is needed in the future.
|
|
/// </summary>
|
|
//public static GridInfoList Get()
|
|
//{
|
|
// try
|
|
// {
|
|
// if (_GridInfoList != null)
|
|
// return _GridInfoList;
|
|
// GridInfoList tmp = DataPortal.Fetch<GridInfoList>();
|
|
// _GridInfoList = tmp;
|
|
// return tmp;
|
|
// }
|
|
// catch (Exception ex)
|
|
// {
|
|
// throw new DbCslaException("Error on FormatInfoList.Get", ex);
|
|
// }
|
|
//}
|
|
public static List<int> GetIds()
|
|
{
|
|
try
|
|
{
|
|
List<int> _GridInfoIdList = new List<int>();
|
|
try
|
|
{
|
|
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
|
|
{
|
|
using (SqlCommand cm = cn.CreateCommand())
|
|
{
|
|
cm.CommandType = CommandType.StoredProcedure;
|
|
cm.CommandText = "getGridIds";
|
|
cm.CommandTimeout = Database.DefaultTimeout;
|
|
using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader()))
|
|
{
|
|
while (dr.Read()) _GridInfoIdList.Add(dr.GetInt32("ContentID"));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
if (_MyLog.IsErrorEnabled) _MyLog.Error("CriteriaAllGridIds.DataPortal_Fetch", ex);
|
|
throw new DbCslaException("CriteriaAllGridIds.DataPortal_Fetch", ex);
|
|
}
|
|
return _GridInfoIdList;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw new DbCslaException("Error on GridInfoList.Get", ex);
|
|
}
|
|
}
|
|
// Commented out - GridInfoList was added to fix B2022-047. Have this code here in
|
|
// case it is needed in the future. The associated query 'getGrids' does not exist.
|
|
//private void DataPortal_Fetch()
|
|
//{
|
|
// this.RaiseListChangedEvents = false;
|
|
// if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] GridInfoList.DataPortal_Fetch", GetHashCode());
|
|
// try
|
|
// {
|
|
// using (SqlConnection cn = Database.VEPROMS_SqlConnection)
|
|
// {
|
|
// using (SqlCommand cm = cn.CreateCommand())
|
|
// {
|
|
// cm.CommandType = CommandType.StoredProcedure;
|
|
// cm.CommandText = "getGrids";
|
|
// cm.CommandTimeout = Database.DefaultTimeout;
|
|
// using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader()))
|
|
// {
|
|
// IsReadOnly = false;
|
|
// while (dr.Read()) this.Add(new GridInfo(dr));
|
|
// IsReadOnly = true;
|
|
// }
|
|
// }
|
|
// }
|
|
// }
|
|
// catch (Exception ex)
|
|
// {
|
|
// if (_MyLog.IsErrorEnabled) _MyLog.Error("GridInfoList.DataPortal_Fetch", ex);
|
|
// throw new DbCslaException("GridInfoList.DataPortal_Fetch", ex);
|
|
// }
|
|
// this.RaiseListChangedEvents = true;
|
|
//}
|
|
}
|
|
public partial class GridInfo
|
|
{
|
|
public void ResetContent(Grid myGrid)
|
|
{
|
|
RefreshFields(myGrid);
|
|
}
|
|
public void SetData(string myData)
|
|
{
|
|
_Data = myData;
|
|
RemoveFromCache(this);
|
|
}
|
|
public static GridInfo GetNonCached(int contentID)
|
|
{
|
|
//if (!CanGetObject())
|
|
// throw new System.Security.SecurityException("User not authorized to view a Grid");
|
|
try
|
|
{
|
|
GridInfo tmp = DataPortal.Fetch<GridInfo>(new PKCriteria(contentID));
|
|
if (tmp.ErrorMessage == "No Record Found")
|
|
{
|
|
tmp.Dispose(); // Clean-up GridInfo
|
|
tmp = null;
|
|
}
|
|
return tmp;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw new DbCslaException("Error on GridInfo.Get", ex);
|
|
}
|
|
}
|
|
}
|
|
}
|