diff --git a/PROMS/VEPROMS.CSLA.Library/Extension/FormatExt.cs b/PROMS/VEPROMS.CSLA.Library/Extension/FormatExt.cs index 007c724b..a2ddcd21 100644 --- a/PROMS/VEPROMS.CSLA.Library/Extension/FormatExt.cs +++ b/PROMS/VEPROMS.CSLA.Library/Extension/FormatExt.cs @@ -324,6 +324,61 @@ namespace VEPROMS.CSLA.Library } public partial class FormatInfo : IFormatOrFormatInfo { + //transition report stuff + private static Dictionary _TransitionTypes; + public static Dictionary GetTransitionTypesByFormatID(int formatID) + { + try + { + DataPortal.Fetch(new FormatIDCriteria(formatID)); + return _TransitionTypes; + } + catch (Exception ex) + { + throw new DbCslaException("Error on FormatInfo.GetTransitionTypesByFormatID", ex); + } + } + [Serializable()] + private class FormatIDCriteria + { + private int _FormatID; + public int FormatID { get { return _FormatID; } } + public FormatIDCriteria(int formatID) + { + _FormatID = formatID; + } + } + private void DataPortal_Fetch(FormatIDCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] TransitionInfoList.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "vesp_GetTranTypesByFormatID"; + cm.Parameters.AddWithValue("@FormatID", criteria.FormatID); + cm.CommandTimeout = Database.DefaultTimeout; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + _TransitionTypes = new Dictionary(); + while (dr.Read()) + { + _TransitionTypes.Add(dr.GetInt32(0), dr.GetString(1)); + } + } + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("FormatInfo.DataPortal_Fetch", ex); + throw new DbCslaException("FormatInfo.DataPortal_Fetch", ex); + } + } + //end transition report stuff public virtual Format GetJustFormat() { return _Editable = Format.GetJustFormat(_FormatID); @@ -480,4 +535,61 @@ namespace VEPROMS.CSLA.Library } } } + public class FormatVersion + { + private string _Title; + public string Title { get { return _Title; } } + private int _FormatID; + public int FormatID { get { return _FormatID; } } + private int _VersionID; + public int VersionID { get { return _VersionID; } } + public FormatVersion(string title, int formatID, int versionID) + { + _Title = title; + _FormatID = formatID; + _VersionID = versionID; + } + } + public class FormatVersionList : List + { + public static FormatVersionList GetFormatVersions() + { + try + { + FormatVersionList fvl = DataPortal.Fetch(); + return fvl; + } + catch (Exception ex) + { + throw new DbCslaException("FormatVersionList.DataPortal_Fetch GetFormatVersions", ex); + } + } + private void DataPortal_Fetch() + { + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "vesp_GetFormatVersions"; + cm.CommandTimeout = Database.DefaultTimeout; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + while (dr.Read()) + { + this.Add(new FormatVersion(dr.GetString(0), dr.GetInt32(1), dr.GetInt32(2))); + } + } + } + } + } + catch (Exception ex) + { + Database.LogException("FormatVersionList.DataPortal_Fetch", ex); + throw new DbCslaException("FormatVersionList.DataPortal_Fetch", ex); + } + } + } } diff --git a/PROMS/VEPROMS.CSLA.Library/Extension/ItemExt.cs b/PROMS/VEPROMS.CSLA.Library/Extension/ItemExt.cs index ad2dd9e7..721bf31e 100644 --- a/PROMS/VEPROMS.CSLA.Library/Extension/ItemExt.cs +++ b/PROMS/VEPROMS.CSLA.Library/Extension/ItemExt.cs @@ -548,8 +548,111 @@ namespace VEPROMS.CSLA.Library } } return null; + } + public static void ResetTranCounters() + { + TranCheckCount = 0; + TranFixCount = 0; + } + public static int TranCheckCount = 0; + public static int TranFixCount = 0; + internal static void MyRefreshTransitions(ItemInfo itemInfo, IVEDrillDownReadOnly itemParent, SectionInfo sectionInfo, ProcedureInfo procInfo, DocVersionInfo docVersionInfo, TransitionLookup tranLookup) + { + //TransitionInfoList til = TransitionInfoList.GetByFromID(itemInfo.ItemID); + //Console.WriteLine("Procedure: {0}, transitions: {1}", (itemInfo as ProcedureInfo).DisplayNumber, til.Count); + //foreach (TransitionInfo traninfo in til) + //{ + // string oldText = itemInfo.MyContent.Text; + // itemInfo.MyContent.FixTransitionText(traninfo, tranLookup); + // string newText = itemInfo.MyContent.Text; + // if (newText != oldText) + // { + // Content content = Content.Get(itemInfo.MyContent.ContentID); + // content.FixTransitionText(traninfo); + // content.Save(); + // } + //} + if (itemInfo.MyContent.ContentPartCount > 0) + foreach (PartInfo pi in itemInfo.MyContent.ContentParts) + foreach (ItemInfo ii in pi.MyItems) + MyRefreshTransitions(ii, itemInfo, (itemInfo as SectionInfo) ?? sectionInfo, procInfo, docVersionInfo, tranLookup); + if (itemInfo.MyContent.ContentTransitionCount > 0) + { + itemInfo.ResetOrdinal(); + foreach (TransitionInfo traninfo in itemInfo.MyContent.ContentTransitions) + { + TranCheckCount++; + string oldText = itemInfo.MyContent.Text; + itemInfo.MyContent.FixTransitionText(traninfo, itemInfo); + string newText = itemInfo.MyContent.Text; + if (newText != oldText) + { + TranFixCount++; + Content content = Content.Get(itemInfo.MyContent.ContentID); + content.FixTransitionText(traninfo); + content.Save(); + } + } + } + } + public static void ResetROCounters() + { + ROCheckCount = 0; + ROFixCount = 0; + } + public static int ROCheckCount = 0; + public static int ROFixCount = 0; + private static AnnotationType _VolianCommentType = null; // Using this to flag ro value issues with byron to braidwood + public static AnnotationType VolianCommentType + { + get + { + if (_VolianCommentType == null) + _VolianCommentType = AnnotationType.GetByName("Volian Comment"); + if (_VolianCommentType == null) + _VolianCommentType = AnnotationType.MakeAnnotationType("Volian Comment", null); + return _VolianCommentType; + } } - internal static void SetParentSectionAndDocVersionPageNum(ItemInfo itemInfo, IVEDrillDownReadOnly itemParent, SectionInfo sectionInfo, ProcedureInfo procInfo, DocVersionInfo docVersionInfo, TransitionLookup tranLookup) + internal static void MyRefreshReferenceObjects(ItemInfo itemInfo, IVEDrillDownReadOnly itemParent, SectionInfo sectionInfo, DocVersionInfo docVersionInfo) + { + if (itemInfo.MyContent.ContentPartCount > 0) + foreach (PartInfo pi in itemInfo.MyContent.ContentParts) + foreach (ItemInfo ii in pi.MyItems) + MyRefreshReferenceObjects(ii, itemInfo, (itemInfo as SectionInfo) ?? sectionInfo, docVersionInfo); + ROFstInfo rofstinfo = docVersionInfo.DocVersionAssociations[0].MyROFst; + ROFSTLookup lookup = rofstinfo.GetROFSTLookup(docVersionInfo); + lookup.MyDocVersionInfo = docVersionInfo; + if (itemInfo.MyContent.ContentRoUsageCount > 0) + { + foreach (RoUsageInfo rousage in itemInfo.MyContent.ContentRoUsages) + { + if (sectionInfo != null) + { + ROCheckCount++; + string oldText = itemInfo.MyContent.Text; + string roval = lookup.GetTranslatedRoValue(rousage.ROID, sectionInfo.ActiveFormat.PlantFormat.FormatData.SectData.ConvertCaretToDelta); + ROFSTLookup.rochild roch = lookup.GetRoChild(rousage.ROID); + itemInfo.MyContent.FixContentText(rousage, roval, roch.type, rofstinfo, itemInfo); + string newText = itemInfo.MyContent.Text; + if (newText != oldText) + { + ROFixCount++; + Content content = Content.Get(itemInfo.MyContent.ContentID); + if (roval == "?") + { + oldText = content.ConvertROToText(rousage, roval, roch.type, rofstinfo); + //Annotation.MakeAnnotation(content.ContentItems[0].MyItem, VolianCommentType, "", string.Format("RO value ({0}) converted to text" + sameMsg, ItemInfo.ConvertToDisplayText(oldText)), null); + } + else + content.FixContentText(rousage, roval, roch.type, rofstinfo); + content.Save(); + } + } + } + } + } + internal static void SetParentSectionAndDocVersionPageNum(ItemInfo itemInfo, IVEDrillDownReadOnly itemParent, SectionInfo sectionInfo, ProcedureInfo procInfo, DocVersionInfo docVersionInfo, TransitionLookup tranLookup) { if (itemInfo.MyContent.ContentPartCount > 0) { @@ -565,7 +668,7 @@ namespace VEPROMS.CSLA.Library { foreach (TransitionInfo traninfo in itemInfo.MyContent.ContentTransitions) { - itemInfo.MyContent.FixTransitionText(traninfo, tranLookup); + itemInfo.MyContent.FixTransitionText(traninfo, tranLookup, itemInfo); } } } @@ -630,7 +733,7 @@ namespace VEPROMS.CSLA.Library { string roval = lookup.GetTranslatedRoValue(rousage.ROID, sectionInfo.ActiveFormat.PlantFormat.FormatData.SectData.ConvertCaretToDelta); ROFSTLookup.rochild roch = lookup.GetRoChild(rousage.ROID); - itemInfo.MyContent.FixContentText(rousage, roval, roch.type, rofstinfo); + itemInfo.MyContent.FixContentText(rousage, roval, roch.type, rofstinfo, itemInfo); } } } @@ -661,7 +764,7 @@ namespace VEPROMS.CSLA.Library foreach (TransitionInfo traninfo in itemInfo.MyContent.ContentTransitions) { //itemInfo.UpdateTransitionText(); - itemInfo.MyContent.FixTransitionText(traninfo, tranLookup); + itemInfo.MyContent.FixTransitionText(traninfo, tranLookup, itemInfo); } } //ts = DateTime.Now.Subtract(dts); @@ -738,7 +841,7 @@ namespace VEPROMS.CSLA.Library foreach (ItemInfo item in _CacheByPrimaryKey[key]) myCache.Add(item); foreach (ItemInfo item in myCache) item.OnOrdinalChange(); - } + } } public bool IsFirstSubStep { @@ -1413,10 +1516,10 @@ namespace VEPROMS.CSLA.Library if (MyContent.Type / 10000 != 2) _IsHigh = false; else { - ItemInfo parent = ActiveParent as ItemInfo; + ItemInfo parent = ActiveParent as ItemInfo; if (parent == null) _IsHigh = false; - // IsHigh was returning true if this item is a caution or note off of a section.. - // from the (parent.MyContent.Type / 1000) == 1. + // IsHigh was returning true if this item is a caution or note off of a section.. + // from the (parent.MyContent.Type / 1000) == 1. else if ((parent.MyContent.Type / 10000) != 1) _IsHigh = false; else if (IsCaution || IsNote) _IsHigh = false; @@ -1795,7 +1898,7 @@ namespace VEPROMS.CSLA.Library return false; } } - private E_FromType ItemType + private E_FromType ItemType { get { @@ -3567,10 +3670,10 @@ namespace VEPROMS.CSLA.Library // For calvert formats, if all tabs are null or empty, then don't add a bullet in. bool allnull = ActiveFormat.PlantFormat.FormatData.PrintData.SpecialCaseCalvert && (tbformat == null || tbformat == "") && (nextTbFormat == null || tbformat == "") && (prevTbFormat == null || prevTbFormat == ""); if (!allnull && (tbformat == nextTbFormat || tbformat == prevTbFormat)) - { - tbformat = ActiveFormat.PlantFormat.FormatData.SectData.StepSectionData.IdentB; - TabToIdentBAdjustFont(); - } + { + tbformat = ActiveFormat.PlantFormat.FormatData.SectData.StepSectionData.IdentB; + TabToIdentBAdjustFont(); + } else if ((nextTbFormat == null || tbformat != nextTbFormat) && (prevTbFormat == null || tbformat != prevTbFormat)) { tbformat = ""; @@ -3855,13 +3958,13 @@ namespace VEPROMS.CSLA.Library ItemInfo pi = ActiveParent as ItemInfo; if (pi != null) { - if (!pi.IsStep) // only steps are in template - _TemplateColumnMode = -1; - else if (pi.FormatStepData.UseOldTemplate) - _TemplateColumnMode = pi.TemplateChildColumnMode; - else - _TemplateColumnMode = pi.TemplateColumnMode; // go up parents until find of columnmode or section - } + if (!pi.IsStep) // only steps are in template + _TemplateColumnMode = -1; + else if (pi.FormatStepData.UseOldTemplate) + _TemplateColumnMode = pi.TemplateChildColumnMode; + else + _TemplateColumnMode = pi.TemplateColumnMode; // go up parents until find of columnmode or section + } } return _TemplateColumnMode ?? -1; } @@ -4189,6 +4292,10 @@ namespace VEPROMS.CSLA.Library { AddItem(itemInfo); } + public void AddItemInfo(ItemInfo ii) + { + AddItem(ii); + } public static ItemInfoList GetMoveItem(int? itemID, int index) { try @@ -4944,6 +5051,89 @@ namespace VEPROMS.CSLA.Library this.RaiseListChangedEvents = true; } #endregion + #region Transition Search + public static ItemInfoList GetListFromTransitionSearch(string docVersionList, int tranType, string tranCategory) + { + try + { + ItemInfoList tmp = DataPortal.Fetch(new ItemListTransitionSearchCriteria(docVersionList, tranType, tranCategory)); + ItemInfo.AddList(tmp); + tmp.AddEvents(); + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on ItemInfoList.GetListFromTransitionSearch", ex); + } + } + [Serializable()] + private class ItemListTransitionSearchCriteria + { + private string _DocVersionList; + public string DocVersionList { get { return _DocVersionList; } } + private int _TranType; + public int TranType { get { return _TranType; } } + private string _TranCategory; + public string TranCategory { get { return _TranCategory; } } + public ItemListTransitionSearchCriteria(string docVersionList, int tranType, string tranCategory) + { + _DocVersionList = docVersionList; + _TranType = tranType; + _TranCategory = tranCategory; + } + } + private void DataPortal_Fetch(ItemListTransitionSearchCriteria criteria) + { + this.RaiseListChangedEvents = false; + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "vesp_SearchTransitions"; + cm.Parameters.AddWithValue("@DocVersionList", criteria.DocVersionList); + cm.Parameters.AddWithValue("@TranType", criteria.TranType); + cm.Parameters.AddWithValue("@TranCategory", criteria.TranCategory); + cm.CommandTimeout = Database.DefaultTimeout; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + while (dr.Read()) + { + ItemInfo itemInfo = null; + int itemType = dr.GetInt32("Type") / 10000; + switch (itemType) + { + case 0: + itemInfo = new ProcedureInfo(dr); + break; + case 1: + itemInfo = new SectionInfo(dr); + break; + default: + itemInfo = new StepInfo(dr); + break; + } + itemInfo.AddContent(dr); + itemInfo._SearchDVPath = dr.GetString("DVPath"); + //itemInfo._SearchPath = dr.GetString("Path"); + IsReadOnly = false; + this.Add(itemInfo); + IsReadOnly = true; + } + } + } + } + } + catch (Exception ex) + { + Database.LogException("ItemInfoList.DataPortal_Fetch", ex); + throw new DbCslaException("ItemInfoList.DataPortal_Fetch", ex); + } + this.RaiseListChangedEvents = true; + } + #endregion #region RO Reports public static ItemInfoList GetListFromROReport(string docVersionList, string stepTypeList, string roSearchString, string unitPrefix) { @@ -5226,8 +5416,21 @@ namespace VEPROMS.CSLA.Library public new Procedure Get() { return (Procedure)(_Editable = Procedure.Get(ItemID)); - } - public static void RefreshPageNumTransitions(ProcedureInfo tmp) + } + public static void RefreshTransitions(ProcedureInfo tmp) + { + TransitionLookup tranLookup = new TransitionLookup(0, tmp.ItemID, tmp.MyLookup); + tranLookup.ApplicabilityUnit = tmp.MyDocVersion.DocVersionConfig.SelectedSlave; + tranLookup.NewLookupNeeded += new TransitionLookupEvent(GetNewLookup); + if (tmp.MyDocVersion.DocVersionConfig.SelectedSlave <= 0) + MyRefreshTransitions(tmp, tmp.MyDocVersion, null, tmp, tmp.MyDocVersion, tranLookup); + } + public static void RefreshReferenceObjects(ProcedureInfo tmp) + { + if (tmp.MyDocVersion.DocVersionConfig.SelectedSlave <= 0) + MyRefreshReferenceObjects(tmp, tmp.MyDocVersion, null, tmp.MyDocVersion); + } + public static void RefreshPageNumTransitions(ProcedureInfo tmp) { TransitionLookup tranLookup = new TransitionLookup(0, tmp.ItemID, tmp.MyLookup); tranLookup.ApplicabilityUnit = tmp.MyDocVersion.DocVersionConfig.SelectedSlave; @@ -5512,9 +5715,60 @@ namespace VEPROMS.CSLA.Library { Database.LogException("ItemInfoList.DataPortal_Fetch", ex); throw new DbCslaException("ItemInfoList.DataPortal_Fetch", ex); + } + MyLookup = lookup; + } + } + [Serializable()] + public class ProcedureTransitionsCountCommand : CommandBase + { + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + private int _ProcedureTransitionsCount; + public int ProcedureTransitionsCount + { + get { return _ProcedureTransitionsCount; } + } + private int _ItemID; + public int ItemID + { + get { return _ItemID; } + set { _ItemID = value; } + } + #region Factory Methods + public static int Execute(int itemID) + { + ProcedureTransitionsCountCommand cmd = new ProcedureTransitionsCountCommand(); + cmd.ItemID = itemID; + cmd = DataPortal.Execute(cmd); + return cmd.ProcedureTransitionsCount; + } + private ProcedureTransitionsCountCommand() + { /* require use of factory methods */ } + #endregion + #region Server-Side code + protected override void DataPortal_Execute() + { + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cmd = new SqlCommand("vesp_ProcedureTransitionsCount", cn)) + { + cmd.CommandType = CommandType.StoredProcedure; + cmd.Parameters.AddWithValue("ItemID", _ItemID); + _ProcedureTransitionsCount = (int)cmd.ExecuteScalar(); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ProcedureTransitionsCountCommand Error", ex); + throw new ApplicationException("Failure on ProcedureTransitionsCountCommand", ex); } } + #endregion } + #endregion #region Procedure [Serializable()] diff --git a/PROMS/VEPROMS.CSLA.Library/Extension/TransitionExt.cs b/PROMS/VEPROMS.CSLA.Library/Extension/TransitionExt.cs index dc15acce..78ae2384 100644 --- a/PROMS/VEPROMS.CSLA.Library/Extension/TransitionExt.cs +++ b/PROMS/VEPROMS.CSLA.Library/Extension/TransitionExt.cs @@ -11,6 +11,14 @@ namespace VEPROMS.CSLA.Library { public partial class TransitionInfo { + //for transition search + private int _Level = 0; + public int Level + { + get { return _Level; } + set { _Level = value; } + } + //end for transition search private bool _NewTransToUnNumberedItem = false; public bool NewTransToUnNumberedItem { @@ -144,6 +152,75 @@ namespace VEPROMS.CSLA.Library #region AffectedTransitons public partial class TransitionInfoList { + //transition report stuff + public static TransitionInfoList GetTransitionReportData(int versionID, int procedureID) + { + try + { + TransitionInfoList tmp = DataPortal.Fetch(new TransitionReportDataCriteria(versionID, procedureID)); + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on TransitionInfoList.GetTransitionReportData", ex); + } + } + [Serializable()] + protected class TransitionReportDataCriteria + { + private int _VersionID; + public int VersionID + { + get { return _VersionID; } + } + private int _ProcedureID; + public int ProcedureID + { + get { return _ProcedureID; } + } + public TransitionReportDataCriteria(int versionID, int procedureID) + { + _VersionID = versionID; + _ProcedureID = procedureID; + } + } + private void DataPortal_Fetch(TransitionReportDataCriteria criteria) + { + this.RaiseListChangedEvents = false; + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] TransitionInfoList.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "vesp_GetTransitionReportData"; + cm.Parameters.AddWithValue("@VersionID", criteria.VersionID); + cm.Parameters.AddWithValue("@ProcedureID", criteria.ProcedureID); + cm.CommandTimeout = Database.DefaultTimeout; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + IsReadOnly = false; + while (dr.Read()) + { + TransitionInfo ti = new TransitionInfo(dr); + ti.Level = dr.GetInt32("level"); + this.Add(ti); + } + IsReadOnly = true; + } + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("TransitionInfoList.DataPortal_Fetch", ex); + throw new DbCslaException("TransitionInfoList.DataPortal_Fetch", ex); + } + this.RaiseListChangedEvents = true; + } + //end transition report stuff [Serializable()] private class AffectedTransitonsCriteria {