using System; using System.Collections.Generic; using System.Text; using System.Data; using System.Data.SqlClient; using System.Text.RegularExpressions; using Csla; using Csla.Data; namespace VEPROMS.CSLA.Library { public partial class AnnotationInfo { public override string ToString() { return _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() { return _Name; } public static AnnotationType GetByName2(string name) { try { AnnotationType tmp = DataPortal.Fetch(new GetByNameCriteria(name)); if (tmp.ErrorMessage == "No Record Found") { tmp.Dispose(); // Clean-up AnnotationType tmp = null; } return tmp; } catch (Exception ex) { throw new DbCslaException("Error on AnnotationType.GetByName", ex); } } [Serializable()] protected class GetByNameCriteria { private string _Name; public string Name { get { return _Name; } } public GetByNameCriteria(string name) { _Name = name; } } private void DataPortal_Fetch(GetByNameCriteria criteria) { if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] AnnotationType.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.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("AnnotationType.DataPortal_Fetch", ex); _ErrorMessage = ex.Message; throw new DbCslaException("AnnotationType.DataPortal_Fetch", ex); } } } public partial class AnnotationTypeInfo { public static List AllList() { //return _AllList; return AnnotationTypeInfo._CacheList; } public override string ToString() { return _Name; } public static AnnotationTypeInfo GetByName(string name) { try { AnnotationTypeInfo tmp = DataPortal.Fetch(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 string _Name; public string Name { get { return _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.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 { /// /// Change the annotation type and update the Annotation record /// /// public void Update(int anotypeid) { if (_TypeID != anotypeid) { _TypeID = anotypeid; MarkDirty(); // force the record update Save(); //Update(); // commit record to database } } public void CommitChanges() { MarkDirty(); // force the record update Save(true); //Update(); } public static void DeleteAnnotation(AnnotationInfo obj) { if (!CanDeleteObject()) throw new System.Security.SecurityException("User not authorized to remove a Annotation"); try { // ItemInfo nextItem = item.NextItem; // ItemInfo prevItem = item.MyPrevious; // item.OnBeforeDelete(); DataPortal.Delete(new DeleteCriteria(obj.AnnotationID, Volian.Base.Library.VlnSettings.UserID)); AnnotationInfo.StaticOnInfoChanged(); // if (nextItem != null) // Adjust PreviousID for NextItem // { // ItemInfo.RefreshPrevious(nextItem.ItemID, item.PreviousID); // // The order of the next two methods was required to fix a null reference // // when getting myparent. This bug was found when deleting a node from the // // tree when the RTBItem was not open (i.e. in the step editor window). // nextItem.RefreshItemParts(); // //nextItem.ResetOrdinal(); - UpdateTransitionText calls ResetOrdinal // nextItem.UpdateTransitionText(); // } // else if (prevItem != null) // { // prevItem.RefreshNextItems(); // if (prevItem.IsCaution || prevItem.IsNote) prevItem.ResetOrdinal(); // prevItem.UpdateTransitionText(); // } // ItemInfo.DeleteItemInfoAndChildren(item.ItemID); // Dispose ItemInfo and Children } catch (Exception ex) { Console.WriteLine("AnnotationExt: Stacktrace = {0}", ex.StackTrace); System.Data.SqlClient.SqlException exSQL = SqlException(ex); if (exSQL != null && exSQL.Message.Contains("###Cannot Delete Item###")) //return false; throw exSQL; else throw new DbCslaException("Error on Annotation.Delete", 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 int _AnnotationID; public int AnnotationID { get { return _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.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); } } } //public partial class AnnotationTypeAnnotations //{ // public static int GetAnnotationID() // { // return AnnotationTypeAnnotat // } //} }