From 14e3e15537f6a690f020a2118b2c50ea80d09a0a Mon Sep 17 00:00:00 2001 From: Rich Date: Mon, 1 Aug 2011 20:16:23 +0000 Subject: [PATCH] Change Manager --- .../Extension/AnnotationExt.cs | 130 ++ .../Extension/AuditExt.cs | 1401 +++++++++++++++++ .../Extension/FormatExt.cs | 120 ++ .../VEPROMS.CSLA.Library/Extension/ItemExt.cs | 50 +- .../Extension/ItemInsertExt.cs | 7 + .../Extension/ROFSTExt.cs | 5 + .../Extension/TransitionExt.cs | 3 + .../VEPROMS.CSLA.Library/Generated/Content.cs | 1 + .../Generated/ContentInfo.cs | 11 +- 9 files changed, 1726 insertions(+), 2 deletions(-) create mode 100644 PROMS/VEPROMS.CSLA.Library/Extension/AuditExt.cs diff --git a/PROMS/VEPROMS.CSLA.Library/Extension/AnnotationExt.cs b/PROMS/VEPROMS.CSLA.Library/Extension/AnnotationExt.cs index 4296678b..93099383 100644 --- a/PROMS/VEPROMS.CSLA.Library/Extension/AnnotationExt.cs +++ b/PROMS/VEPROMS.CSLA.Library/Extension/AnnotationExt.cs @@ -1,6 +1,11 @@ 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 { @@ -10,6 +15,37 @@ namespace VEPROMS.CSLA.Library { 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 { @@ -52,6 +88,100 @@ namespace VEPROMS.CSLA.Library 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)); + // 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 //{ diff --git a/PROMS/VEPROMS.CSLA.Library/Extension/AuditExt.cs b/PROMS/VEPROMS.CSLA.Library/Extension/AuditExt.cs new file mode 100644 index 00000000..f2df83af --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Extension/AuditExt.cs @@ -0,0 +1,1401 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Csla; +using Csla.Data; +using Csla.Validation; +using System.Data.SqlClient; +using System.Data; + +namespace VEPROMS.CSLA.Library +{ + public partial class AnnotationAuditInfo + { + internal string _ActionWhat; + public string ActionWhat + { + get { return _ActionWhat; } + set { _ActionWhat = value; } + } + internal DateTime _ActionWhen; + public DateTime ActionWhen + { + get { return _ActionWhen; } + set { _ActionWhen = value; } + } + internal int _IContentID; + public int IContentID + { + get { return _IContentID; } + set { _IContentID = value; } + } + public override string ToString() + { + return string.Format("{0} by {1} on {2}", this.DeleteStatus == 0 ? "Changed" : "Deleted", this.UserID, this.DTS.ToString("MM/dd/yyyy @ HH:mm:ss")); + } + } + + public partial class ContentAuditInfo + { + internal string _ActionWhat; + public string ActionWhat + { + get { return _ActionWhat; } + set { _ActionWhat = value; } + } + internal DateTime _ActionWhen; + public DateTime ActionWhen + { + get { return _ActionWhen; } + set { _ActionWhen = value; } + } + internal string _Path; + public string Path + { + get { return _Path; } + set { _Path = value; } + } + internal int _ItemID; + public int ItemID + { + get { return _ItemID; } + set { _ItemID = value; } + } + public override string ToString() + { + return string.Format("{0} by {1} on {2}", this.ActionWhat, this.UserID, this.DTS.ToString("MM/dd/yyyy @ HH:mm:ss")); + //return string.Format("{0} by {1} on {2}", this.DeleteStatus == 0 ? "Changed" : "Deleted", this.UserID, this.DTS.ToString("MM/dd/yyyy @ HH:mm:ss")); + //return string.Format("{0} - {1} {2}", this.UserID, this.DTS, this.DeleteStatus == 0 ? "" : "Deleted"); + } + + } + + public partial class DocumentAuditInfo + { + public override string ToString() + { + return string.Format("{0} - {1} {2}", this.UserID, this.DTS, this.DeleteStatus == 0 ? "" : "Deleted"); + } + } + + public partial class EntryAuditInfo + { + public override string ToString() + { + return string.Format("{0} - {1} {2}", this.UserID, this.DTS, this.DeleteStatus == 0 ? "" : "Deleted"); + } + } + + public partial class GridAuditInfo + { + public override string ToString() + { + return string.Format("{0} by {1} on {2}", this.DeleteStatus == 0 ? "Changed" : "Deleted", this.UserID, this.DTS.ToString("MM/dd/yyyy @ HH:mm:ss")); + //return string.Format("{0} - {1} {2}", this.UserID, this.DTS, this.DeleteStatus == 0 ? "" : "Deleted"); + } + } + + public partial class ImageAuditInfo + { + public override string ToString() + { + return string.Format("{0} - {1} {2}", this.UserID, this.DTS, this.DeleteStatus == 0 ? "" : "Deleted"); + } + } + + public partial class ItemAuditInfo + { + public static bool IsChangeManagerVersion() + { + try + { + using (ItemAuditInfoList list = ItemAuditInfoList.Get()) + { + ; + } + } + catch (Exception ex1) + { + Exception ex = ex1; + while (ex.InnerException != null) + ex = ex.InnerException; + if (ex.Message.StartsWith("Could not find stored procedure")) + { + System.Windows.Forms.MessageBox.Show("Running Change Manager Code with Non-Change Manager Data", "Inconsistent Data", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error); + return false; + } + throw new Exception("Failed on check of Change Manager Data",ex1); + } + return true; + } + internal int _Level; + public int Level + { + get { return _Level; } + } + internal string _ItemType; + public string ItemType + { + get { return _ItemType; } + } + + public override string ToString() + { + return string.Format("{0}{1} deleted by {2} on {3} @ {4}", this.Level == 0 ? "Previous " : this.Level == 1 ? "Next " : "", this.ItemType, this.UserID, this.DTS.ToShortDateString(), this.DTS.ToShortTimeString()); +// return string.Format("Deleted by {0} on {1} @ {2}", this.UserID, this.DTS.ToShortDateString(), this.DTS.ToShortTimeString()); +// return string.Format("(ItemID: {4}, DeleteID: {5}, {0} by {1} on {2} Level: {3}", this.DeleteStatus == 0 ? "Changed" : "Deleted", this.UserID, this.DTS.ToString("MM/dd/yyyy @ HH:mm:ss"), Level.ToString(), this.ItemID.ToString(), this.DeleteStatus.ToString()); +// return string.Format("Level: {3}, {0} - {1} {2}", this.UserID, this.DTS, this.DeleteStatus == 0 ? "" : "Deleted", this.Level.ToString()); + } + } + + public partial class PartAuditInfo + { + public override string ToString() + { + return string.Format("{0} - {1} {2}", this.UserID, this.DTS, this.DeleteStatus == 0 ? "" : "Deleted"); + } + } + + public partial class AnnotationAuditInfoList + { + /// + /// Return a list of all AnnotationAuditInfo by ItemID. + /// + /// Selected ItemID for Annotation Audit Records + /// + public static AnnotationAuditInfoList GetByItemID(int itemID) + { + try + { + //if (_AnnotationAuditInfoList != null) + // return _AnnotationAuditInfoList; + AnnotationAuditInfoList tmp = DataPortal.Fetch(new ItemIDCriteria(itemID)); + //AnnotationAuditInfo.AddList(tmp); + //tmp.AddEvents(); + //_AnnotationAuditInfoList = tmp; + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on AnnotationAuditInfoList.GetByItemID", ex); + } + } + [Serializable()] + protected class ItemIDCriteria + { + private int _ItemID; + public int ItemID + { get { return _ItemID; } } + public ItemIDCriteria(int itemID) + { + _ItemID = itemID; + } + } + private void DataPortal_Fetch(ItemIDCriteria criteria) + { + this.RaiseListChangedEvents = false; + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] AnnotationAuditInfoList.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getAnnotationAuditsByItemID"; + cm.Parameters.AddWithValue("@ItemID", criteria.ItemID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + IsReadOnly = false; + while (dr.Read()) this.Add(new AnnotationAuditInfo(dr)); + IsReadOnly = true; + } + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("AnnotationAuditInfoList.DataPortal_Fetch", ex); + throw new DbCslaException("AnnotationAuditInfoList.DataPortal_Fetch", ex); + } + this.RaiseListChangedEvents = true; + } + + public static AnnotationAuditInfoList GetByAnnotationID(int annotationID) + { + try + { + //if (_AnnotationAuditInfoList != null) + // return _AnnotationAuditInfoList; + AnnotationAuditInfoList tmp = DataPortal.Fetch(new AnnotationIDCriteria(annotationID)); + //AnnotationAuditInfo.AddList(tmp); + //tmp.AddEvents(); + //_AnnotationAuditInfoList = tmp; + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on AnnotationAuditInfoList.GetByAnnotationID", ex); + } + } + [Serializable()] + protected class AnnotationIDCriteria + { + private int _AnnotationID; + public int AnnotationID + { get { return _AnnotationID; } } + public AnnotationIDCriteria(int annotationID) + { + _AnnotationID = annotationID; + } + } + private void DataPortal_Fetch(AnnotationIDCriteria criteria) + { + this.RaiseListChangedEvents = false; + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] AnnotationAuditInfoList.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getAnnotationAuditsByAnnotationID"; + cm.Parameters.AddWithValue("@AnnotationID", criteria.AnnotationID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + IsReadOnly = false; + while (dr.Read()) this.Add(new AnnotationAuditInfo(dr)); + IsReadOnly = true; + } + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("AnnotationAuditInfoList.DataPortal_Fetch", ex); + throw new DbCslaException("AnnotationAuditInfoList.DataPortal_Fetch", ex); + } + this.RaiseListChangedEvents = true; + } + + #region ChronologyReport + //chronology report + public static AnnotationAuditInfoList GetChronology(int @procItemID, int itemID) + { + try + { + AnnotationAuditInfoList tmp = DataPortal.Fetch(new ChronologyCriteria(procItemID, itemID)); + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on AnnotationAuditInfoList.GetChronology", ex); + } + } + [Serializable()] + protected class ChronologyCriteria + { + private int _procItemID; + public int ProcItemID + { + get { return _procItemID; } + } + private int _itemID; + public int ItemID + { + get { return _itemID; } + } + public ChronologyCriteria(int procItemID, int itemID) + { + _procItemID = procItemID; + _itemID = itemID; + } + } + private void DataPortal_Fetch(ChronologyCriteria criteria) + { + this.RaiseListChangedEvents = false; + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] AnnotationAuditInfoList.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getAnnotationAuditsChronologyByItemID"; + cm.Parameters.AddWithValue("@ProcItemID", criteria.ProcItemID); + cm.Parameters.AddWithValue("@ItemID", criteria.ItemID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + IsReadOnly = false; + while (dr.Read()) + { + AnnotationAuditInfo aai = new AnnotationAuditInfo(dr); + aai.ActionWhat = dr.GetString("ActionWhat"); + aai.ActionWhen = dr.GetDateTime("ActionWhen"); + aai.IContentID = dr.GetInt32("IContentID"); + this.Add(aai); + + } + IsReadOnly = true; + } + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("AnnotationAuditInfoList.DataPortal_Fetch", ex); + throw new DbCslaException("AnnotationAuditInfoList.DataPortal_Fetch", ex); + } + this.RaiseListChangedEvents = true; + } + #endregion + + } + + public partial class ContentAuditInfoList + { + /// + /// Return a list of all ContentAuditInfo by ContentID. + /// + /// Selected ContentID for Content Audit Records + /// + public static ContentAuditInfoList Get(int contentID) + { + try + { + //if (_ContentAuditInfoList != null) + // return _ContentAuditInfoList; + ContentAuditInfoList tmp = DataPortal.Fetch(new ContentIDCriteria(contentID)); + //ContentAuditInfo.AddList(tmp); + //tmp.AddEvents(); + //_ContentAuditInfoList = tmp; + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on ContentAuditInfoList.Get", ex); + } + } + [Serializable()] + protected class ContentIDCriteria + { + private int _ContentID; + public int ContentID + { get { return _ContentID; } } + public ContentIDCriteria(int contentID) + { + _ContentID = contentID; + } + } + private void DataPortal_Fetch(ContentIDCriteria criteria) + { + this.RaiseListChangedEvents = false; + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ContentAuditInfoList.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getContentAuditsByContentID"; + cm.Parameters.AddWithValue("@ContentID", criteria.ContentID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + IsReadOnly = false; + while (dr.Read()) + { + ContentAuditInfo cai = new ContentAuditInfo(dr); + cai.ActionWhat = dr.GetString("ActionWhat"); + this.Add(cai); +// this.Add(new ContentAuditInfo(dr)); + } + IsReadOnly = true; + } + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ContentAuditInfoList.DataPortal_Fetch", ex); + throw new DbCslaException("ContentAuditInfoList.DataPortal_Fetch", ex); + } + this.RaiseListChangedEvents = true; + } + //by delete status + public static ContentAuditInfoList GetByDeleteStatus(int deleteStatus) + { + try + { + //if (_ContentAuditInfoList != null) + // return _ContentAuditInfoList; + ContentAuditInfoList tmp = DataPortal.Fetch(new DeleteStatusCriteria(deleteStatus)); + //ContentAuditInfo.AddList(tmp); + //tmp.AddEvents(); + //_ContentAuditInfoList = tmp; + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on ContentAuditInfoList.GetByDeleteStatus", ex); + } + } + [Serializable()] + protected class DeleteStatusCriteria + { + private int _DeleteStatus; + public int DeleteStatus + { get { return _DeleteStatus; } } + public DeleteStatusCriteria(int deleteStatus) + { + _DeleteStatus = deleteStatus; + } + } + private void DataPortal_Fetch(DeleteStatusCriteria criteria) + { + this.RaiseListChangedEvents = false; + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ContentAuditInfoList.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getContentAuditsByDeleteStatus"; + cm.Parameters.AddWithValue("@DeleteStatus", criteria.DeleteStatus); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + IsReadOnly = false; + while (dr.Read()) this.Add(new ContentAuditInfo(dr)); + IsReadOnly = true; + } + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ContentAuditInfoList.DataPortal_Fetch", ex); + throw new DbCslaException("ContentAuditInfoList.DataPortal_Fetch", ex); + } + this.RaiseListChangedEvents = true; + } + + #region ChronologyReport + //chronology report + public static ContentAuditInfoList GetChronology(int procedureItemID, int currentItemID, bool includeDeletedChildren) + { + try + { + ContentAuditInfoList tmp = DataPortal.Fetch(new ChronologyCriteria(procedureItemID, currentItemID, includeDeletedChildren)); + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on ContentAuditInfoList.GetChronology", ex); + } + } + [Serializable()] + protected class ChronologyCriteria + { + private int _ProcedureItemID; + + public int ProcedureItemID + { + get { return _ProcedureItemID; } + } + private int _CurrentItemID; + + public int CurrentItemID + { + get { return _CurrentItemID; } + } + private bool _IncludeDeletedChildren; + + public bool IncludeDeletedChildren + { + get { return _IncludeDeletedChildren; } + } + + public ChronologyCriteria(int procedureItemID, int currentItemID, bool includeDeletedChildren) + { + _ProcedureItemID = procedureItemID; + _CurrentItemID = currentItemID; + _IncludeDeletedChildren = includeDeletedChildren; + } + } + private void DataPortal_Fetch(ChronologyCriteria criteria) + { + this.RaiseListChangedEvents = false; + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ContentAuditInfoList.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getContentAuditsChronologyByItemID"; + cm.Parameters.AddWithValue("@ProcedureItemID", criteria.ProcedureItemID); + cm.Parameters.AddWithValue("@SelectedItemID", criteria.CurrentItemID); + cm.Parameters.AddWithValue("@IncludeDeletedChildren", criteria.IncludeDeletedChildren ? 1 : 0); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + IsReadOnly = false; + while (dr.Read()) + { + ContentAuditInfo cai = new ContentAuditInfo(dr); + cai.ActionWhat = dr.GetString("ActionWhat"); + cai.ActionWhen = dr.GetDateTime("ActionWhen"); + cai.Path = dr.GetString("Path"); + cai.ItemID = dr.GetInt32("ItemID"); + this.Add(cai); + + } + IsReadOnly = true; + } + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ContentAuditInfoList.DataPortal_Fetch", ex); + throw new DbCslaException("ContentAuditInfoList.DataPortal_Fetch", ex); + } + this.RaiseListChangedEvents = true; + } + #endregion + + #region SummaryReport + //summary report + public static ContentAuditInfoList GetSummary(int procedureItemID, int currentItemID, bool includeDeletedChildren) + { + try + { + ContentAuditInfoList tmp = DataPortal.Fetch(new SummaryCriteria(procedureItemID, currentItemID, includeDeletedChildren)); + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on ContentAuditInfoList.GetSummary", ex); + } + } + [Serializable()] + protected class SummaryCriteria + { + private int _ProcedureItemID; + + public int ProcedureItemID + { + get { return _ProcedureItemID; } + } + private int _CurrentItemID; + + public int CurrentItemID + { + get { return _CurrentItemID; } + } + private bool _IncludeDeletedChildren; + + public bool IncludeDeletedChildren + { + get { return _IncludeDeletedChildren; } + } + + public SummaryCriteria(int procedureItemID, int currentItemID, bool includeDeletedChildren) + { + _ProcedureItemID = procedureItemID; + _CurrentItemID = currentItemID; + _IncludeDeletedChildren = includeDeletedChildren; + } + } + private void DataPortal_Fetch(SummaryCriteria criteria) + { + this.RaiseListChangedEvents = false; + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ContentAuditInfoList.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getContentAuditsSummaryByItemID"; + cm.Parameters.AddWithValue("@ProcedureItemID", criteria.ProcedureItemID); + cm.Parameters.AddWithValue("@SelectedItemID", criteria.CurrentItemID); + cm.Parameters.AddWithValue("@IncludeDeletedChildren", criteria.IncludeDeletedChildren ? 1 : 0); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + IsReadOnly = false; + while (dr.Read()) + { + ContentAuditInfo cai = new ContentAuditInfo(dr); + cai.ActionWhat = dr.GetString("ActionWhat"); + cai.ActionWhen = dr.GetDateTime("ActionWhen"); + cai.Path = dr.GetString("Path"); + cai.ItemID = dr.GetInt32("ItemID"); + this.Add(cai); + + } + IsReadOnly = true; + } + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ContentAuditInfoList.DataPortal_Fetch", ex); + throw new DbCslaException("ContentAuditInfoList.DataPortal_Fetch", ex); + } + this.RaiseListChangedEvents = true; + } + #endregion + + } + + public partial class DocumentAuditInfoList + { + /// + /// Return a list of all DocumentAuditInfo by DocID. + /// + /// Selected DocID for Document Audit Records + /// + public static DocumentAuditInfoList Get(int docID) + { + try + { + DocumentAuditInfoList tmp = DataPortal.Fetch(new DocumentIDCriteria(docID)); + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on DocumentAuditInfoList.Get", ex); + } + } + [Serializable()] + protected class DocumentIDCriteria + { + private int _DocID; + public int DocID + { get { return _DocID; } } + public DocumentIDCriteria(int docID) + { + _DocID = docID; + } + } + private void DataPortal_Fetch(DocumentIDCriteria criteria) + { + this.RaiseListChangedEvents = false; + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocumentAuditInfoList.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getDocumentAuditsByDocID"; + cm.Parameters.AddWithValue("@DocID", criteria.DocID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + IsReadOnly = false; + while (dr.Read()) this.Add(new DocumentAuditInfo(dr)); + IsReadOnly = true; + } + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("DocumentAuditInfoList.DataPortal_Fetch", ex); + throw new DbCslaException("DocumentAuditInfoList.DataPortal_Fetch", ex); + } + this.RaiseListChangedEvents = true; + } + } + + public partial class EntryAuditInfoList + { + /// + /// Return a list of all EntryAuditInfo by ContentID. + /// + /// Selected ContentID for Entry Audit Records + /// + public static EntryAuditInfoList Get(int contentID) + { + try + { + EntryAuditInfoList tmp = DataPortal.Fetch(new ContentIDCriteria(contentID)); + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on EntryAuditInfoList.Get", ex); + } + } + [Serializable()] + protected class ContentIDCriteria + { + private int _ContentID; + public int ContentID + { get { return _ContentID; } } + public ContentIDCriteria(int contentID) + { + _ContentID = contentID; + } + } + private void DataPortal_Fetch(ContentIDCriteria criteria) + { + this.RaiseListChangedEvents = false; + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] EntryAuditInfoList.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getEntryAuditsByContentID"; + cm.Parameters.AddWithValue("@ContentID", criteria.ContentID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + IsReadOnly = false; + while (dr.Read()) this.Add(new EntryAuditInfo(dr)); + IsReadOnly = true; + } + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("EntryAuditInfoList.DataPortal_Fetch", ex); + throw new DbCslaException("EntryAuditInfoList.DataPortal_Fetch", ex); + } + this.RaiseListChangedEvents = true; + } + } + + public partial class GridAuditInfoList + { + /// + /// Return a list of all GridAuditInfo by ContentID. + /// + /// Selected ContentID for Grid Audit Records + /// + public static GridAuditInfoList Get(int contentID) + { + try + { + GridAuditInfoList tmp = DataPortal.Fetch(new ContentIDCriteria(contentID)); + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on GridAuditInfoList.Get", ex); + } + } + [Serializable()] + protected class ContentIDCriteria + { + private int _ContentID; + public int ContentID + { get { return _ContentID; } } + public ContentIDCriteria(int contentID) + { + _ContentID = contentID; + } + } + private void DataPortal_Fetch(ContentIDCriteria criteria) + { + this.RaiseListChangedEvents = false; + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] GridAuditInfoList.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getGridAuditsByContentID"; + cm.Parameters.AddWithValue("@ContentID", criteria.ContentID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + IsReadOnly = false; + while (dr.Read()) this.Add(new GridAuditInfo(dr)); + IsReadOnly = true; + } + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("GridAuditInfoList.DataPortal_Fetch", ex); + throw new DbCslaException("GridAuditInfoList.DataPortal_Fetch", ex); + } + this.RaiseListChangedEvents = true; + } + } + + public partial class ImageAuditInfoList + { + /// + /// Return a list of all ImageAuditInfo by ContentID. + /// + /// Selected ContentID for Image Audit Records + /// + public static ImageAuditInfoList Get(int contentID) + { + try + { + ImageAuditInfoList tmp = DataPortal.Fetch(new ContentIDCriteria(contentID)); + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on ImageAuditInfoList.Get", ex); + } + } + [Serializable()] + protected class ContentIDCriteria + { + private int _ContentID; + public int ContentID + { get { return _ContentID; } } + public ContentIDCriteria(int contentID) + { + _ContentID = contentID; + } + } + private void DataPortal_Fetch(ContentIDCriteria criteria) + { + this.RaiseListChangedEvents = false; + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ImageAuditInfoList.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getImageAuditsByContentID"; + cm.Parameters.AddWithValue("@ContentID", criteria.ContentID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + IsReadOnly = false; + while (dr.Read()) this.Add(new ImageAuditInfo(dr)); + IsReadOnly = true; + } + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ImageAuditInfoList.DataPortal_Fetch", ex); + throw new DbCslaException("ImageAuditInfoList.DataPortal_Fetch", ex); + } + this.RaiseListChangedEvents = true; + } + } + + public partial class ItemAuditInfoList + { + /// + /// Return a list of all ItemAuditInfo by ItemID. + /// + /// Selected ItemID for Item Audit Records + /// + public static ItemAuditInfoList Get(int itemID) + { + try + { + ItemAuditInfoList tmp = DataPortal.Fetch(new ItemIDCriteria(itemID)); + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on ItemAuditInfoList.Get", ex); + } + } + [Serializable()] + protected class ItemIDCriteria + { + private int _ItemID; + public int ItemID + { get { return _ItemID; } } + public ItemIDCriteria(int itemID) + { + _ItemID = itemID; + } + } + private void DataPortal_Fetch(ItemIDCriteria criteria) + { + this.RaiseListChangedEvents = false; + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ItemAuditInfoList.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getItemAuditsByItemID"; + cm.Parameters.AddWithValue("@ItemID", criteria.ItemID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + IsReadOnly = false; + while (dr.Read()) + { + ItemAuditInfo iai = new ItemAuditInfo(dr); + iai._Level = dr.GetInt32("Level"); + iai._ItemType = dr.GetString("ItemType"); + this.Add(iai); + } + IsReadOnly = true; + } + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ItemAuditInfoList.DataPortal_Fetch", ex); + throw new DbCslaException("ItemAuditInfoList.DataPortal_Fetch", ex); + } + this.RaiseListChangedEvents = true; + } + + } + + public partial class PartAuditInfoList + { + /// + /// Return a list of all PartAuditInfo by ContentID. + /// + /// Selected ContentID for Part Audit Records + /// + public static PartAuditInfoList Get(int contentID) + { + try + { + PartAuditInfoList tmp = DataPortal.Fetch(new ContentIDCriteria(contentID)); + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on PartAuditInfoList.Get", ex); + } + } + [Serializable()] + protected class ContentIDCriteria + { + private int _ContentID; + public int ContentID + { get { return _ContentID; } } + public ContentIDCriteria(int contentID) + { + _ContentID = contentID; + } + } + private void DataPortal_Fetch(ContentIDCriteria criteria) + { + this.RaiseListChangedEvents = false; + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] PartAuditInfoList.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getPartAuditsByContentID"; + cm.Parameters.AddWithValue("@ContentID", criteria.ContentID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + IsReadOnly = false; + while (dr.Read()) this.Add(new PartAuditInfo(dr)); + IsReadOnly = true; + } + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("PartAuditInfoList.DataPortal_Fetch", ex); + throw new DbCslaException("PartAuditInfoList.DataPortal_Fetch", ex); + } + this.RaiseListChangedEvents = true; + } + + public static PartAuditInfoList GetByDeleteStatus(int deleteStatus) + { + try + { + PartAuditInfoList tmp = DataPortal.Fetch(new DeleteStatusCriteria(deleteStatus)); + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on PartAuditInfoList.GetByDeleteStatus", ex); + } + } + [Serializable()] + protected class DeleteStatusCriteria + { + private int _DeleteStatus; + public int DeleteStatus + { get { return _DeleteStatus; } } + public DeleteStatusCriteria(int deleteStatus) + { + _DeleteStatus = deleteStatus; + } + } + private void DataPortal_Fetch(DeleteStatusCriteria criteria) + { + this.RaiseListChangedEvents = false; + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] PartAuditInfoList.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getPartAuditsByDeleteStatus"; + cm.Parameters.AddWithValue("@DeleteStatus", criteria.DeleteStatus); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + IsReadOnly = false; + while (dr.Read()) this.Add(new PartAuditInfo(dr)); + IsReadOnly = true; + } + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("PartAuditInfoList.DataPortal_Fetch", ex); + throw new DbCslaException("PartAuditInfoList.DataPortal_Fetch", ex); + } + this.RaiseListChangedEvents = true; + } + + public static PartAuditInfoList GetByItemID(int itemID) + { + try + { + PartAuditInfoList tmp = DataPortal.Fetch(new ItemIDCriteria(itemID)); + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on PartAuditInfoList.GetByItemID", ex); + } + } + [Serializable()] + protected class ItemIDCriteria + { + private int _ItemID; + public int ItemID + { get { return _ItemID; } } + public ItemIDCriteria(int itemID) + { + _ItemID = itemID; + } + } + private void DataPortal_Fetch(ItemIDCriteria criteria) + { + this.RaiseListChangedEvents = false; + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] PartAuditInfoList.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getPartAuditsByItemID"; + cm.Parameters.AddWithValue("@ItemID", criteria.ItemID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + IsReadOnly = false; + while (dr.Read()) this.Add(new PartAuditInfo(dr)); + IsReadOnly = true; + } + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("PartAuditInfoList.DataPortal_Fetch", ex); + throw new DbCslaException("PartAuditInfoList.DataPortal_Fetch", ex); + } + this.RaiseListChangedEvents = true; + } + + } + + public partial class ItemInfo + { + public static event ItemInfoEvent InfoRestored; + private void OnInfoRestored(ItemInfo itemInfo) + { + if (InfoRestored != null) + InfoRestored(this); + } + public ItemInfo RestoreSibling(ItemAuditInfo iai) + { + if (iai.DeleteStatus == 0) + return null; + int nextID = iai.Level == 0 ? ItemID : NextItem == null ? 0 : NextItem.ItemID; + ItemInfo tmp = RestoreItem(iai); + if(nextID > 0) + using (Item item = Item.Get(nextID)) ItemInfo.Refresh(item); + if (iai.Level == 0) + OnNewSiblingBefore(new ItemInfoInsertEventArgs(tmp, EAddpingPart.Before)); + else + OnNewSiblingAfter(new ItemInfoInsertEventArgs(tmp, EAddpingPart.After)); + ((ItemInfo)ActiveParent).MyContent.RefreshContentParts(); + tmp.OnInfoRestored(tmp); + return tmp; + } + public ItemInfo RestoreItem(ItemAuditInfo iai) + { + try + { + ItemInfo tmp = DataPortal.Fetch(new RestoreCriteria(iai, this)); + AddToCache(tmp); + if (tmp.ErrorMessage == "No Record Found") tmp = null; + if(iai.Level == 2) + OnNewChild(new ItemInfoInsertEventArgs(tmp, EAddpingPart.Child)); + ItemInfo.RefreshPrevious(tmp.NextItem.ItemID, tmp.ItemID); + tmp.NextItem.ResetOrdinal(); + //tmp.UpdateTransitionText(); + if (tmp.MyContent.ContentTransitions != null) + { + foreach (TransitionInfo tran in tmp.MyContent.ContentTransitions) + { + if(tran.MyItemToID != null) + tran.MyItemToID.UpdateTransitionText(); + } + } + using (Content cont = tmp.MyContent.Get()) + { + if (cont.ContentTransitionCount > 0) + { + foreach (ContentTransition tran in cont.ContentTransitions) + { + cont.FixTransitionText(TransitionInfo.Get(tran.TransitionID)); + } + cont.Save(); + } + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on ItemInfo.RestoreItem", ex); + } + } + // Criteria to get Item and children + [Serializable()] + private class RestoreCriteria + { + public RestoreCriteria(ItemAuditInfo iai, ItemInfo ii) + { + _MyAudit = iai; + _MyInfo = ii; + } + private ItemAuditInfo _MyAudit; + public ItemAuditInfo MyAudit + { + get { return _MyAudit; } + set { _MyAudit = value; } + } + private ItemInfo _MyInfo; + public ItemInfo MyInfo + { + get { return _MyInfo; } + set { _MyInfo = value; } + } + } + private void DataPortal_Fetch(RestoreCriteria criteria) + { + ItemAuditInfo iai = criteria.MyAudit; + ItemInfo ii = criteria.MyInfo; + //if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ItemAuditInfoList.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "restoreDeletedItem"; + cm.Parameters.AddWithValue("@ItemID", iai.ItemID); + cm.Parameters.AddWithValue("@DeleteID", iai.DeleteStatus); + cm.Parameters.AddWithValue("@CurrentID", ii.ItemID); + cm.Parameters.AddWithValue("@Level", iai.Level); + cm.ExecuteNonQuery(); + } + } + } + catch (Exception ex) + { + //if (_MyLog.IsErrorEnabled) _MyLog.Error("ItemAuditInfoList.DataPortal_Fetch", ex); + //throw new DbCslaException("ItemAuditInfoList.DataPortal_Fetch", ex); + } + DataPortal_Fetch(new PKCriteria(iai.ItemID)); + } + } + + public partial class AnnotationInfo + { + public static AnnotationInfo RestoreAnnotation(AnnotationAuditInfo aai) + { + try + { + AnnotationInfo tmp = DataPortal.Fetch(new RestoreCriteria(aai)); + AddToCache(tmp); + if (tmp.ErrorMessage == "No Record Found") tmp = null; + tmp.MyItem.RefreshItemAnnotations(); + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on AnnotaionInfo.RestoreAnnotation", ex); + } + } + //criteria to get annotation + [Serializable] + private class RestoreCriteria + { + public RestoreCriteria(AnnotationAuditInfo aai) + { + _MyAudit = aai; + } + private AnnotationAuditInfo _MyAudit; + + public AnnotationAuditInfo MyAudit + { + get { return _MyAudit; } + set { _MyAudit = value; } + } + } + private void DataPortal_Fetch(RestoreCriteria criteria) + { + AnnotationAuditInfo aai = criteria.MyAudit; + if (aai.DeleteStatus == 0) + { + //if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ItemAuditInfoList.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "restoreChangedAnnotation"; + cm.Parameters.AddWithValue("@AuditID", aai.AuditID); + cm.ExecuteNonQuery(); + } + } + } + catch (Exception ex) + { + //if (_MyLog.IsErrorEnabled) _MyLog.Error("ItemAuditInfoList.DataPortal_Fetch", ex); + //throw new DbCslaException("ItemAuditInfoList.DataPortal_Fetch", ex); + } + } + else + { + //if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ItemAuditInfoList.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "restoreDeletedAnnotation"; + cm.Parameters.AddWithValue("@AnnotationID", aai.AnnotationID); + cm.ExecuteNonQuery(); + } + } + } + catch (Exception ex) + { + //if (_MyLog.IsErrorEnabled) _MyLog.Error("ItemAuditInfoList.DataPortal_Fetch", ex); + //throw new DbCslaException("ItemAuditInfoList.DataPortal_Fetch", ex); + } + } + DataPortal_Fetch(new PKCriteria(aai.AnnotationID)); + } + } + + public partial class ContentInfo + { + public static ContentInfo RestoreContent(ContentAuditInfo cai) + { + try + { + ContentInfo tmp = DataPortal.Fetch(new RestoreCriteria(cai)); + AddToCache(tmp); + if (tmp.ErrorMessage == "No Record Found") tmp = null; + tmp.RefreshContentDetails(); + tmp.RefreshContentItems(); + tmp.RefreshContentParts(); + tmp.RefreshContentRoUsages(); + tmp.RefreshContentTransitions(); + using (Content ctmp = tmp.Get()) + { + ContentInfo.Refresh(ctmp); + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on ContentInfo.RestoreContent", ex); + } + } + //criteria to get content + [Serializable] + private class RestoreCriteria + { + public RestoreCriteria(ContentAuditInfo cai) + { + _MyAudit = cai; + } + private ContentAuditInfo _MyAudit; + public ContentAuditInfo MyAudit + { + get { return _MyAudit; } + set { _MyAudit = value; } + } + } + private void DataPortal_Fetch(RestoreCriteria criteria) + { + ContentAuditInfo cai = criteria.MyAudit; + //if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ItemAuditInfoList.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "restoreChangedContent"; + cm.Parameters.AddWithValue("@AuditID", cai.AuditID); + cm.ExecuteNonQuery(); + } + } + } + catch (Exception ex) + { + //if (_MyLog.IsErrorEnabled) _MyLog.Error("ItemAuditInfoList.DataPortal_Fetch", ex); + //throw new DbCslaException("ItemAuditInfoList.DataPortal_Fetch", ex); + } + DataPortal_Fetch(new PKCriteria(cai.ContentID)); + } + } +} diff --git a/PROMS/VEPROMS.CSLA.Library/Extension/FormatExt.cs b/PROMS/VEPROMS.CSLA.Library/Extension/FormatExt.cs index b2dd841c..beb6e565 100644 --- a/PROMS/VEPROMS.CSLA.Library/Extension/FormatExt.cs +++ b/PROMS/VEPROMS.CSLA.Library/Extension/FormatExt.cs @@ -55,6 +55,126 @@ namespace VEPROMS.CSLA.Library } public partial class FormatInfo : IFormatOrFormatInfo { + public static bool HasLatestChanges() + { + if (!HasTopMargin()) return false; + if (!HasWCN2_MacroB9()) return false; + return true; + } + private static bool HasTopMargin() + { + using (FormatInfo fi = FormatInfo.Get("WCN2")) + { + XmlDocument xd = new XmlDocument(); + xd.LoadXml(fi.Data); + XmlNodeList xl = xd.SelectNodes("//DocStyle/Layout/@TopMargin"); + if (xl.Count == 0) + { + System.Windows.Forms.MessageBox.Show("DocStyle TopMargin is missing", "Inconsistent Format Files", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error); + return false; + } + return true; + } + } + private static bool HasWCN2_MacroB9() + { + using (FormatInfo fi = FormatInfo.Get("WCN2")) + { + XmlDocument xd = new XmlDocument(); + xd.LoadXml(fi.GenMac); + XmlNodeList xl = xd.SelectNodes("//*[@id='B9']"); + if (xl.Count == 0) + { + System.Windows.Forms.MessageBox.Show("B9 macro is missing in WCN2 GenMac","Inconsistent Format Files", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error ); + return false; + } + return true; + } + } + public static FormatInfo Get(string name) + { + try + { + FormatInfo tmp = DataPortal.Fetch(new NameCriteria(name)); + //AddToCache(tmp); + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up FormatInfo + tmp = null; + } + return tmp; + } + catch (Exception ex1) + { + Exception ex = ex1; + while (ex.InnerException != null) + ex = ex.InnerException; + if (ex.Message.StartsWith("Could not find stored procedure")) + { + int formatID = 0; + using (FormatInfoList fil = FormatInfoList.Get()) + { + foreach (FormatInfo fi in fil) + { + if (fi.Name == name) + { + formatID = fi.FormatID; + break; + } + } + } + if (formatID != 0) return FormatInfo.Get(formatID); + throw new DbCslaException("Format not found " + name, ex); + } + else + throw new DbCslaException("Error on FormatInfo.Get By Name", ex); + } + } + protected class NameCriteria + { + private string _Name; + public string Name + { get { return _Name; } } + public NameCriteria(string name) + { + _Name = name; + } + } + private void DataPortal_Fetch(NameCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] FormatInfo.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 = "getFormatByName"; + 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("FormatInfo.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("FormatInfo.DataPortal_Fetch", ex); + } + } #region PlantFormat [NonSerialized] private PlantFormat _PlantFormat; diff --git a/PROMS/VEPROMS.CSLA.Library/Extension/ItemExt.cs b/PROMS/VEPROMS.CSLA.Library/Extension/ItemExt.cs index 1954b402..4ffe9552 100644 --- a/PROMS/VEPROMS.CSLA.Library/Extension/ItemExt.cs +++ b/PROMS/VEPROMS.CSLA.Library/Extension/ItemExt.cs @@ -1702,6 +1702,8 @@ namespace VEPROMS.CSLA.Library ItemInfo tmp = this; while (tmp.ActiveParent != null && tmp.ActiveParent.GetType() != typeof(DocVersionInfo)) tmp = (ItemInfo)tmp.ActiveParent; + if (tmp is ProcedureInfo) + return tmp as ProcedureInfo; return ProcedureInfo.Get(tmp.ItemID); } } @@ -1842,7 +1844,29 @@ namespace VEPROMS.CSLA.Library //Console.WriteLine("Local {0}", (MyContent.MyFormat==null)?"MYformat is null": MyContent.MyFormat.Name); return MyContent.MyFormat; } } - private ConfigDynamicTypeDescriptor _MyConfig=null; + private bool _IsDeleted = false; + public bool IsDeleted + { + get { return _IsDeleted; } + set + { + _IsDeleted = value; + if (value == true) + UpdateCacheIsDeleted(ItemID); + } + } + private static void UpdateCacheIsDeleted(int itemID) + { + ConvertListToDictionary(); + string key = itemID.ToString(); + if (key != null && _CacheByPrimaryKey.ContainsKey(key)) + { + ItemInfo[] items = _CacheByPrimaryKey[key].ToArray(); + foreach (ItemInfo item in items) + item._IsDeleted = true; + } + } + private ConfigDynamicTypeDescriptor _MyConfig = null; public ConfigDynamicTypeDescriptor MyConfig { get @@ -2336,6 +2360,30 @@ namespace VEPROMS.CSLA.Library if (tmp.Count > 0) _MyMacros = tmp; } #endregion + #region JCB Item Status + private bool _IsItemNew = false; + public bool IsItemNew + { + get + { + ProcedureInfo pi = this.MyProcedure; + if (pi != null) + _IsItemNew = (this.DTS > pi.DTS); + return _IsItemNew; + } + } + private bool _IsItemChanged; + public bool IsItemChanged + { + get + { + ProcedureInfo pi = this.MyProcedure; + if (pi != null) + _IsItemChanged = (this.MyContent.DTS > pi.DTS); + return _IsItemChanged; + } + } + #endregion } #endregion ItemInfo #region Tab diff --git a/PROMS/VEPROMS.CSLA.Library/Extension/ItemInsertExt.cs b/PROMS/VEPROMS.CSLA.Library/Extension/ItemInsertExt.cs index 7ed20400..4f9b2848 100644 --- a/PROMS/VEPROMS.CSLA.Library/Extension/ItemInsertExt.cs +++ b/PROMS/VEPROMS.CSLA.Library/Extension/ItemInsertExt.cs @@ -179,10 +179,13 @@ namespace VEPROMS.CSLA.Library } } } + public static event ItemInfoEvent ItemDeleted; + public event ItemInfoEvent Deleted; internal void OnDeleted(object sender) { if (Deleted != null) Deleted(sender); + if (ItemDeleted != null) ItemDeleted(sender); if (MyParent != null) { MyParent.OnChildrenDeleted(sender); @@ -411,7 +414,10 @@ namespace VEPROMS.CSLA.Library { content.FixTransitionText(tran); if (content.IsDirty) + { + content.DTS = DateTime.Now; content.Save(); + } else // Update ContentInfo objects to reflect the change in the transition ContentInfo.Refresh(content); } @@ -776,6 +782,7 @@ namespace VEPROMS.CSLA.Library //Console.WriteLine("\r\n\r\n'Deleting Item {0}'\r\n{0}'Type ','ParentID','ParentUnique','ItemID','Unique'",itemID); foreach (ItemInfo item in items) { + item.IsDeleted = true; item.OnDeleted(item); item.DeleteItemInfoAndChildren(" "); } diff --git a/PROMS/VEPROMS.CSLA.Library/Extension/ROFSTExt.cs b/PROMS/VEPROMS.CSLA.Library/Extension/ROFSTExt.cs index 76454c4e..183be469 100644 --- a/PROMS/VEPROMS.CSLA.Library/Extension/ROFSTExt.cs +++ b/PROMS/VEPROMS.CSLA.Library/Extension/ROFSTExt.cs @@ -352,7 +352,12 @@ namespace VEPROMS.CSLA.Library { content.FixContentText(roUsg, roch, origROFstInfo); if (content.IsDirty) + { + // Update UserID and DTS when RO Value is updated. + content.UserID = Volian.Base.Library.VlnSettings.UserID; + content.DTS = DateTime.Now; content.Save(); + } } } } diff --git a/PROMS/VEPROMS.CSLA.Library/Extension/TransitionExt.cs b/PROMS/VEPROMS.CSLA.Library/Extension/TransitionExt.cs index 0ec6df79..b29474c2 100644 --- a/PROMS/VEPROMS.CSLA.Library/Extension/TransitionExt.cs +++ b/PROMS/VEPROMS.CSLA.Library/Extension/TransitionExt.cs @@ -30,6 +30,7 @@ namespace VEPROMS.CSLA.Library } public string ResolvePathTo() { + MyContent.RefreshContentItems(); ItemInfo item = MyContent.ContentItems[0]; //Console.WriteLine("Format = {0}", item.ActiveFormat); //Console.WriteLine("item = {0}", item.ItemID); @@ -387,6 +388,8 @@ namespace VEPROMS.CSLA.Library } public static string GetResolvedText(FormatInfo formatInfo, ItemInfo fromInfo, int tranType, ItemInfo toItem, ItemInfo rangeItem) { + if (toItem == null || rangeItem == null || toItem.IsDeleted || rangeItem.IsDeleted) + return "Invalid Transition Destination"; TransitionBuilder tb = SetupTransitionBuilder(formatInfo, fromInfo, tranType, toItem, toItem.ItemID==rangeItem.ItemID && !toItem.IsHigh?toItem.LastSibling:rangeItem); if(_AppendMethods==null) diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/Content.cs b/PROMS/VEPROMS.CSLA.Library/Generated/Content.cs index 690ed0d8..385ea577 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/Content.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/Content.cs @@ -1287,6 +1287,7 @@ namespace VEPROMS.CSLA.Library using (SqlCommand cm = cn.CreateCommand()) { cm.CommandType = CommandType.StoredProcedure; + //Volian.Base.Library.vlnStackTrace.ShowStackLocal("ContentID={0}", _ContentID.ToString()); cm.CommandText = "updateContent"; // All Fields including Calculated Fields cm.Parameters.AddWithValue("@ContentID", _ContentID); diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/ContentInfo.cs b/PROMS/VEPROMS.CSLA.Library/Generated/ContentInfo.cs index 4dc4de1a..3e1848b0 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/ContentInfo.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/ContentInfo.cs @@ -27,11 +27,20 @@ namespace VEPROMS.CSLA.Library [TypeConverter(typeof(ContentInfoConverter))] public partial class ContentInfo : ReadOnlyBase, IDisposable { + public static event ContentInfoEvent InfoChanged; + private void OnInfoChanged(ContentInfo contentInfo) + { + if (InfoChanged != null) + InfoChanged(this); + } public event ContentInfoEvent Changed; private void OnChange(ContentInfo contentInfo) { if (Changed != null) - Changed(this); + { + Changed(this); + OnInfoChanged(this); + } } private void OnChange() {