diff --git a/PROMS/VEPROMS.CSLA.Library/Extension/ROFSTExt.cs b/PROMS/VEPROMS.CSLA.Library/Extension/ROFSTExt.cs index 477165b9..9a875d73 100644 --- a/PROMS/VEPROMS.CSLA.Library/Extension/ROFSTExt.cs +++ b/PROMS/VEPROMS.CSLA.Library/Extension/ROFSTExt.cs @@ -138,15 +138,16 @@ namespace VEPROMS.CSLA.Library private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); #endregion #region PropertiesAndData - private DocVersion _docVer; - public DocVersion docVer + private DocVersionInfo _docVer; + public DocVersionInfo docVer { get { if (_docVer == null) { if (ROFstAssociations.Count == 0) return null; - _docVer = DocVersion.Get(this.ROFstAssociations[0].MyDocVersion.VersionID); +// _docVer = DocVersion.Get(this.ROFstAssociations[0].MyDocVersion.VersionID); + _docVer = this.ROFstAssociations[0].MyDocVersion; } return _docVer; } @@ -557,15 +558,15 @@ namespace VEPROMS.CSLA.Library { using (Figure figure = Figure.GetByROFstID_ImageID(this.ROFstID, roImg.ImageID)) { - if (figure != null) return; + if (figure != null) return; Figure.MakeFigure(rofst, roImg, null).Dispose(); - myAddedROImages.Add(key); - } - } + myAddedROImages.Add(key); } } } } + } + } private int FindExisting(Dictionary myExistingROImages, string imgname, string imgfile, byte[] cmpFileContents, byte[] fileContents) { diff --git a/PROMS/VEPROMS.CSLA.Library/Extension/RevisionInfoExt.cs b/PROMS/VEPROMS.CSLA.Library/Extension/RevisionInfoExt.cs index ac0c5988..fd8a0ec5 100644 --- a/PROMS/VEPROMS.CSLA.Library/Extension/RevisionInfoExt.cs +++ b/PROMS/VEPROMS.CSLA.Library/Extension/RevisionInfoExt.cs @@ -432,6 +432,94 @@ namespace VEPROMS.CSLA.Library throw new DbCslaException("Revision.DataPortal_Fetch", ex); } } + //jcb 20120625 + public static Revision GetByItemIDAndRevisionNumberAndUnitID(int itemID, string revisionNumber, int unitID) + { + if (!CanGetObject()) + throw new System.Security.SecurityException("User not authorized to view a Revision"); + try + { + //Revision tmp = GetCachedByPrimaryKey(revisionID); + //if (tmp == null) + //{ + Revision tmp = DataPortal.Fetch(new UnitItemRevisionNumberCriteria(itemID, revisionNumber, unitID)); + // AddToCache(tmp); + //} + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up Revision + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on Revision.GetByItemIDAndRevisionNumber", ex); + } + } + [Serializable()] + protected class UnitItemRevisionNumberCriteria + { + private int _ItemID; + public int ItemID + { get { return _ItemID; } } + private string _RevisionNumber; + public string RevisionNumber + { get { return _RevisionNumber; } } + private int _UnitID; + public int UnitID + { get { return _UnitID; } } + public UnitItemRevisionNumberCriteria(int itemID, string revisionNumber, int unitID) + { + _ItemID = itemID; + _RevisionNumber = revisionNumber; + _UnitID = unitID; + } + } + private void DataPortal_Fetch(UnitItemRevisionNumberCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Revision.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 = "getRevisionByItemIDandRevisionNumberAndUnitID"; + cm.Parameters.AddWithValue("@ItemID", criteria.ItemID); + cm.Parameters.AddWithValue("@RevisionNumber", criteria.RevisionNumber); + cm.Parameters.AddWithValue("@UnitID", criteria.UnitID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + // load child objects + dr.NextResult(); + _RevisionChecks = RevisionChecks.Get(dr); + // load child objects + dr.NextResult(); + _RevisionVersions = RevisionVersions.Get(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("Revision.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Revision.DataPortal_Fetch", ex); + } + } + //end jcb 20120625 } public partial class RevisionInfoList { @@ -493,6 +581,70 @@ namespace VEPROMS.CSLA.Library } this.RaiseListChangedEvents = true; } + //jcb 20120626 + public static RevisionInfoList GetByItemIDandUnitID(int itemID, int unitID) + { + try + { + //if (_RevisionInfoList != null) + // return _RevisionInfoList; + RevisionInfoList tmp = DataPortal.Fetch(new ItemUnitCriteria(itemID, unitID)); + RevisionInfo.AddList(tmp); + tmp.AddEvents(); + //_RevisionInfoList = tmp; + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on RevisionInfoList.GetByItemID", ex); + } + } + [Serializable()] + protected class ItemUnitCriteria + { + private int _ItemID; + public int ItemID + { get { return _ItemID; } } + private int _UnitID; + public int UnitID + { get { return _UnitID; } } + public ItemUnitCriteria(int itemID, int unitID) + { + _ItemID = itemID; + _UnitID = unitID; + } + } + private void DataPortal_Fetch(ItemUnitCriteria criteria) + { + this.RaiseListChangedEvents = false; + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RevisionInfoList.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getRevisionsByItemIDandUnitID"; + cm.Parameters.AddWithValue("@ItemID", criteria.ItemID); + cm.Parameters.AddWithValue("@UnitID", criteria.UnitID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + IsReadOnly = false; + while (dr.Read()) this.Add(new RevisionInfo(dr)); + IsReadOnly = true; + } + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("RevisionInfoList.DataPortal_Fetch", ex); + throw new DbCslaException("RevisionInfoList.DataPortal_Fetch", ex); + } + this.RaiseListChangedEvents = true; + } + //end jcb 20120626 } public partial class RevisionInfo { @@ -517,6 +669,12 @@ namespace VEPROMS.CSLA.Library { _ItemID = itemID; } + private int _UnitID = 0; + public int UnitID + { + get{return _UnitID;} + set{_UnitID = value;} + } } [Serializable()] protected class CurrentItemCriteria : ItemCriteria @@ -527,6 +685,15 @@ namespace VEPROMS.CSLA.Library } } [Serializable()] + protected class CurrentItemUnitCriteria : ItemCriteria + { + public CurrentItemUnitCriteria(int itemID, int unitID) + : base(itemID) + { + UnitID = unitID; + } + } + [Serializable()] protected class PreviousItemCriteria : ItemCriteria { public PreviousItemCriteria(int itemID) @@ -557,6 +724,23 @@ namespace VEPROMS.CSLA.Library throw new DbCslaException("Error on RevisionInfo.GetCurrentByItemID", ex); } } + public static RevisionInfo GetCurrentByItemIDandUnitID(int itemID, int unitID) + { + try + { + RevisionInfo tmp = DataPortal.Fetch(new CurrentItemUnitCriteria(itemID, unitID)); + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up RevisionInfo + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on RevisionInfo.GetCurrentByItemID", ex); + } + } public static RevisionInfo GetPreviousByItemID(int itemID) { try @@ -652,6 +836,42 @@ namespace VEPROMS.CSLA.Library throw new DbCslaException("RevisionInfo.DataPortal_Fetch", ex); } } + private void DataPortal_Fetch(CurrentItemUnitCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RevisionInfo.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 = "getCurrentRevisionByItemIDandUnitID"; + cm.Parameters.AddWithValue("@ItemID", criteria.ItemID); + cm.Parameters.AddWithValue("@UnitID", criteria.UnitID); + 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("RevisionInfo.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("RevisionInfo.DataPortal_Fetch", ex); + } + } #endregion //jcb stuff public VersionInfo LatestVersion @@ -698,10 +918,12 @@ namespace VEPROMS.CSLA.Library myROIDs.Add(myRO.ROID.ToUpper()); //create checkro record for each roid //_MyTimer.ActiveProcess = "Get DocVersionInfo"; - DocVersionInfo dbi = proc.ActiveParent as DocVersionInfo; +// DocVersionInfo dbi = proc.ActiveParent as DocVersionInfo; + DocVersionInfo dvi = proc.MyDocVersion; //_MyTimer.ActiveProcess = "Get MyROFst"; - ROFstInfo rofst = ROFstInfo.GetJustROFst(dbi.DocVersionAssociations[0].ROFstID); + ROFstInfo rofst = ROFstInfo.GetJustROFst(dvi.DocVersionAssociations[0].ROFstID); //_MyTimer.ActiveProcess = "Get ROFst Lookup"; + rofst.docVer = dvi; ROFSTLookup lookup = rofst.ROFSTLookup; //_MyTimer.ActiveProcess = "Populating RevisionChecksXML table"; cc.ROConsistency.ROFstDate = rofst.DTS; diff --git a/PROMS/VEPROMS.CSLA.Library/Extension/TransitionExt.cs b/PROMS/VEPROMS.CSLA.Library/Extension/TransitionExt.cs index 5f605e0c..77b79cf8 100644 --- a/PROMS/VEPROMS.CSLA.Library/Extension/TransitionExt.cs +++ b/PROMS/VEPROMS.CSLA.Library/Extension/TransitionExt.cs @@ -43,10 +43,42 @@ namespace VEPROMS.CSLA.Library //Console.WriteLine("TranType = {0}", TranType); //Console.WriteLine("MyItemToID = {0}", MyItemToID); //Console.WriteLine("MyItemRangeID = {0}", MyItemRangeID); - string retval = ResolvePathTo(item.ActiveFormat, item, TranType, MyItemToID, MyItemRangeID); - if (item.NewTransToUnNumberedItem) - NewTransToUnNumberedItem = true; - return retval; + return ResolvePathTo(item.ActiveFormat, item, TranType, MyItemToID, MyItemRangeID); + } + public string ResolvePathTo(TransitionLookup tranLookup) + { + MyContent.RefreshContentItems(); + ItemInfo item = MyContent.ContentItems[0]; + ItemInfo myItemToID = MyItemToID; + if (tranLookup.ContainsKey(ToID)) + myItemToID = tranLookup[ToID]; + else + { + //different proc + //_MyLog.WarnFormat("Transition May Not Be Correct at Location From {0} To {1}", item.SearchPath, myItemToID.SearchPath); + tranLookup.AddProcLookup(myItemToID.MyProcedure.ItemID, ProcedureInfo.GetNewLookup(tranLookup, new TransitionLookupEventArgs(ToID, tranLookup.ApplicabilityUnit, MyItemToID.MyDocVersion, tranLookup)).MyLookup); + if (tranLookup.ContainsKey(ToID)) + myItemToID = tranLookup[ToID]; + //Console.WriteLine("Transition May Not Be Correct at Location"); + } + ItemInfo myItemRangeID = MyItemRangeID; + if (tranLookup.ContainsKey(RangeID)) + myItemRangeID = tranLookup[RangeID]; + else + { + //different proc + //_MyLog.WarnFormat("Transition May Not Be Correct at Location From {0} To {1}", item.SearchPath, myItemRangeID.SearchPath); + tranLookup.AddProcLookup(MyItemRangeID.MyProcedure.ItemID, ProcedureInfo.GetNewLookup(tranLookup, new TransitionLookupEventArgs(RangeID, tranLookup.ApplicabilityUnit,MyItemRangeID.MyDocVersion, tranLookup)).MyLookup); + if (tranLookup.ContainsKey(RangeID)) + myItemRangeID = tranLookup[RangeID]; + //Console.WriteLine("Transition May Not Be Correct at Location"); + //Console.WriteLine("Format = {0}", item.ActiveFormat); + //Console.WriteLine("item = {0}", item.ItemID); + //Console.WriteLine("TranType = {0}", TranType); + //Console.WriteLine("MyItemToID = {0}", MyItemToID); + //Console.WriteLine("MyItemRangeID = {0}", MyItemRangeID); + } + return ResolvePathTo(item.ActiveFormat, item, TranType, myItemToID, myItemRangeID); } } #region AffectedTransitons @@ -372,7 +404,7 @@ namespace VEPROMS.CSLA.Library { _Results.Append(Prefix); _Prefix = null; - } + } } @@ -606,7 +638,8 @@ namespace VEPROMS.CSLA.Library while (!pitem.IsHigh) { - string thisTab = StepInfo.Get(pitem.ItemID).MyTab.CleanText; + //string thisTab = StepInfo.Get(pitem.ItemID).MyTab.CleanText; + string thisTab = pitem.MyTab.CleanText;// StepInfo.Get(pitem.ItemID).MyTab.CleanText; // remove delimiters of '.' and ')' in tab. if (!hasDelim) {