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

512 lines
14 KiB
C#

using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
namespace VEPROMS.CSLA.Library
{
public partial class AnnotationInfo
{
public override string ToString() => _SearchText;
#region JCB Annotation Status
private bool _IsAnnotationNew = false;
public bool IsAnnotationNew
{
get
{
ProcedureInfo pi = this.MyItem.MyProcedure;
if (pi != null)
//todo figure out audit count
_IsAnnotationNew = (this.DTS > pi.DTS);
return _IsAnnotationNew;
}
}
private bool _IsAnnotationChanged;
public bool IsAnnotationChanged
{
get
{
ProcedureInfo pi = this.MyItem.MyProcedure;
if (pi != null)
{
//todo figure out audit count
_IsAnnotationChanged = (this.DTS > pi.DTS);
}
return _IsAnnotationChanged;
}
}
#endregion
}
public partial class AnnotationType
{
public override string ToString() => _Name;
[NonSerialized]
private AnnotationTypeConfig _AnnotationTypeConfig;
public AnnotationTypeConfig AnnotationTypeConfig
{
get
{
if (_AnnotationTypeConfig == null)
{
_AnnotationTypeConfig = new AnnotationTypeConfig(this);
}
return _AnnotationTypeConfig;
}
}
}
public partial class AnnotationTypeInfo
{
[NonSerialized]
private AnnotationTypeConfig _AnnotationTypeConfig;
public AnnotationTypeConfig AnnotationTypeConfig
{
get
{
if (_AnnotationTypeConfig == null)
{
_AnnotationTypeConfig = new AnnotationTypeConfig(this);
}
return _AnnotationTypeConfig;
}
}
public static List<AnnotationTypeInfo> AllList() => AnnotationTypeInfo._CacheList;
public override string ToString() => _Name;
public static AnnotationTypeInfo GetByName(string name)
{
try
{
AnnotationTypeInfo tmp = DataPortal.Fetch<AnnotationTypeInfo>(new GetByNameCriteria(name));
if (tmp.ErrorMessage == "No Record Found")
{
tmp.Dispose(); // Clean-up AnnotationTypeInfo
tmp = null;
}
return tmp;
}
catch (Exception ex)
{
throw new DbCslaException("Error on AnnotationTypeInfo.GetByName", ex);
}
}
[Serializable()]
protected class GetByNameCriteria
{
private readonly string _Name;
public string Name => _Name;
public GetByNameCriteria(string name) => _Name = name;
}
private void DataPortal_Fetch(GetByNameCriteria criteria)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] AnnotationTypeInfo.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 = "getAnnotationTypeByName";
cm.CommandTimeout = Database.SQLTimeout;
cm.Parameters.AddWithValue("@Name", criteria.Name);
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("AnnotationTypeInfo.DataPortal_Fetch", ex);
_ErrorMessage = ex.Message;
throw new DbCslaException("AnnotationTypeInfo.DataPortal_Fetch", ex);
}
}
}
public partial class AnnotationTypeInfoList
{
public static void Refresh()
{
Reset();
_AnnotationTypeInfoList = Get();
}
}
public partial class Annotation
{
/// <summary>
/// Change the annotation type and update the Annotation record
/// </summary>
/// <param name="anotypeid"></param>
public void Update(int anotypeid)
{
if (_TypeID != anotypeid)
{
_TypeID = anotypeid;
MarkDirty(); // force the record update
Save();
}
}
public void CommitChanges()
{
MarkDirty(); // force the record update
Save(true);
}
public static void DeleteAnnotation(AnnotationInfo obj)
{
try
{
DataPortal.Delete(new DeleteCriteria(obj.AnnotationID, Volian.Base.Library.VlnSettings.UserID));
AnnotationInfo.StaticOnInfoChanged();
}
catch (Exception ex)
{
System.Data.SqlClient.SqlException exSQL = SqlException(ex);
if (exSQL != null && exSQL.Message.Contains("###Cannot Delete Item###"))
throw exSQL;
Console.WriteLine("AnnotationExt: Stacktrace = {0}", ex.StackTrace);
throw new DbCslaException("Error on Annotation.Delete", ex);
}
}
public static void DeleteAnnotationProcByType(int typID, string procList)
{
try
{
DataPortal.Delete(new DeleteAnnotationProcByTypeCriteria(typID, procList));
AnnotationInfo.StaticOnInfoChanged();
}
catch (Exception ex)
{
System.Data.SqlClient.SqlException exSQL = SqlException(ex);
if (exSQL != null && exSQL.Message.Contains("###Cannot Delete Item###"))
throw exSQL;
Console.WriteLine("AnnotationExt: Stacktrace = {0}", ex.StackTrace);
throw new DbCslaException("Error on Annotation.Delete", ex);
}
}
public static void DeleteAnnotationDocvByType(int typID, string versionID)
{
try
{
DataPortal.Delete(new DeleteAnnotationDocvByTypeCriteria(typID, versionID));
AnnotationInfo.StaticOnInfoChanged();
}
catch (Exception ex)
{
System.Data.SqlClient.SqlException exSQL = SqlException(ex);
if (exSQL != null && exSQL.Message.Contains("###Cannot Delete Item###"))
throw exSQL;
Console.WriteLine("AnnotationExt: Stacktrace = {0}", ex.StackTrace);
throw new DbCslaException("Error on Annotation.Delete", ex);
}
}
public static int getAnnotationProcCnt(int typID, string procList)
{
try
{
Annotation ProcCnt = DataPortal.Fetch<Annotation>(new getAnnotationCountProcCriteria(typID, procList));
AnnotationInfo.StaticOnInfoChanged();
return Annotation.ProcCnt;
//return Int32.Parse(ProcCnt);
}
catch (Exception ex)
{
System.Data.SqlClient.SqlException exSQL = SqlException(ex);
if (exSQL != null && exSQL.Message.Contains("###Cannot retrieve Item###"))
throw exSQL;
Console.WriteLine("AnnotationExt: Stacktrace = {0}", ex.StackTrace);
throw new DbCslaException("Error on getAnnotationCountProcCriteria", ex);
}
}
public static int getAnnotationCountDocv(int typID, string procList)
{
try
{
Annotation DocvCnt = DataPortal.Fetch<Annotation>(new getAnnotationCountDocvCriteria(typID, procList));
AnnotationInfo.StaticOnInfoChanged();
return Annotation.DocvCnt;
}
catch (Exception ex)
{
System.Data.SqlClient.SqlException exSQL = SqlException(ex);
if (exSQL != null && exSQL.Message.Contains("###Cannot retrieve Item###"))
throw exSQL;
Console.WriteLine("AnnotationExt: Stacktrace = {0}", ex.StackTrace);
throw new DbCslaException("Error on getAnnotationCountDocvCriteria", ex);
}
}
private static System.Data.SqlClient.SqlException SqlException(Exception ex)
{
Type sqlExType = typeof(System.Data.SqlClient.SqlException);
while (ex != null)
{
if (ex.GetType() == sqlExType) return ex as System.Data.SqlClient.SqlException;
ex = ex.InnerException;
}
return null;
}
[Serializable()]
protected class DeleteCriteria
{
private readonly int _AnnotationID;
public int AnnotationID => _AnnotationID;
private string _UserID;
public string UserID
{
get { return _UserID; }
set { _UserID = value; }
}
public DeleteCriteria(int annotationID, String userID)
{
_AnnotationID = annotationID;
_UserID = userID;
}
}
[Transactional(TransactionalTypes.TransactionScope)]
private void DataPortal_Delete(DeleteCriteria criteria)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Item.DataPortal_Delete", GetHashCode());
try
{
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "deleteAnnotationWithUserID";
cm.Parameters.AddWithValue("@AnnotationID", criteria.AnnotationID);
cm.Parameters.AddWithValue("@UserID", criteria.UserID);
cm.ExecuteNonQuery();
}
}
}
catch (Exception ex)
{
if (_MyLog.IsErrorEnabled) _MyLog.Error("Item.DataPortal_Delete", ex);
_ErrorMessage = ex.Message;
throw new DbCslaException("Item.DataPortal_Delete", ex);
}
}
[Serializable()]
protected class DeleteAnnotationProcByTypeCriteria
{
private readonly int _typeID;
public int TypeID => _typeID;
private readonly string _procList;
public string ProcList => _procList;
public DeleteAnnotationProcByTypeCriteria(int typeID, string procList)
{
_typeID = typeID;
_procList = procList;
}
}
[Transactional(TransactionalTypes.TransactionScope)]
private void DataPortal_Delete(DeleteAnnotationProcByTypeCriteria criteria)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Item.DataPortal_Delete", GetHashCode());
try
{
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "deleteAnnotationsProcByType";
cm.Parameters.AddWithValue("@typeid", criteria.TypeID);
cm.Parameters.AddWithValue("@procList", criteria.ProcList);
cm.ExecuteNonQuery();
}
}
}
catch (Exception ex)
{
if (_MyLog.IsErrorEnabled) _MyLog.Error("Item.DataPortal_Delete", ex);
_ErrorMessage = ex.Message;
throw new DbCslaException("Item.DataPortal_Delete Annotations by group", ex);
}
}
[Serializable()]
protected class DeleteAnnotationDocvByTypeCriteria
{
private readonly int _typeID;
public int TypeID => _typeID;
private readonly string _versionID;
public string VersionID => _versionID;
public DeleteAnnotationDocvByTypeCriteria(int typeID, string versionID)
{
_typeID = typeID;
_versionID = versionID;
}
}
[Transactional(TransactionalTypes.TransactionScope)]
private void DataPortal_Delete(DeleteAnnotationDocvByTypeCriteria criteria)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Delete Annotations by Type Docv", GetHashCode());
try
{
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "deleteAnnotationsDocvByType";
cm.Parameters.AddWithValue("@typeid", criteria.TypeID);
cm.Parameters.AddWithValue("@docvList", criteria.VersionID);
cm.ExecuteNonQuery();
}
}
}
catch (Exception ex)
{
if (_MyLog.IsErrorEnabled) _MyLog.Error("Item.DataPortal_Delete", ex);
_ErrorMessage = ex.Message;
throw new DbCslaException("Item.DataPortal_Delete Annotations by type Docv", ex);
}
}
private static int _procCnt;
public static int ProcCnt
{
get { return _procCnt; }
set { _procCnt = value; }
}
[Serializable()]
protected class getAnnotationCountProcCriteria
{
private int _procCnt;
public int ProcCnt
{
get { return _procCnt; }
set { _procCnt = value; }
}
private readonly int _typeID;
public int TypeID => _typeID;
private readonly string _procList;
public string ProcList => _procList;
public getAnnotationCountProcCriteria(int typeID, string procList, int procCnt = 0)
{
_typeID = typeID;
_procList = procList;
_procCnt = procCnt;
}
}
[Transactional(TransactionalTypes.TransactionScope)]
private getAnnotationCountProcCriteria DataPortal_Fetch(getAnnotationCountProcCriteria criteria)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Item.DataPortal_Fetch", GetHashCode());
try
{
//int ProcCnt;
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "getAnnotationProcCount";
cm.Parameters.AddWithValue("@procList", criteria.ProcList);
cm.Parameters.AddWithValue("@typeid", criteria.TypeID);
Annotation.ProcCnt = (int)cm.ExecuteScalar();
}
}
return criteria; //_procCnt.ToString();
}
catch (Exception ex)
{
if (_MyLog.IsErrorEnabled) _MyLog.Error("Annotation.GetAnnotationProcCnt", ex);
_ErrorMessage = ex.Message;
throw new DbCslaException("Annotation.GetAnnotationProcCnt by group", ex);
}
}
private static int _docvCnt;
public static int DocvCnt
{ get { return _docvCnt; }
set { _docvCnt = value; }
}
[Serializable()]
protected class getAnnotationCountDocvCriteria
{
private int _docvCnt;
public int DocvCnt
{
get { return _docvCnt; }
set { _docvCnt = value; }
}
private readonly int _TypeID;
public int TypeID => _TypeID;
private readonly string _docvList;
public string DocvList => _docvList;
public getAnnotationCountDocvCriteria(int typeID, string docvList, int docvCnt = 0)
{
_TypeID = typeID;
_docvList = docvList;
_docvCnt = docvCnt;
}
}
[Transactional(TransactionalTypes.TransactionScope)]
private getAnnotationCountDocvCriteria DataPortal_Fetch(getAnnotationCountDocvCriteria criteria)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Annotation.DataPortal_Fetch", GetHashCode());
try
{
//int ProcCnt;
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "getAnnotationDocvCount";
cm.Parameters.AddWithValue("@typeid", criteria.TypeID);
cm.Parameters.AddWithValue("@DocvList", criteria.DocvList);
Annotation.DocvCnt = (int)cm.ExecuteScalar();
}
return criteria;
}
}
catch (Exception ex)
{
if (_MyLog.IsErrorEnabled) _MyLog.Error("Item.DataPortal_Delete", ex);
_ErrorMessage = ex.Message;
throw new DbCslaException("Item.DataPortal_Delete Annotations by group", ex);
}
}
}
}