1154 lines
		
	
	
		
			42 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			1154 lines
		
	
	
		
			42 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
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 TransitionInfo
 | 
						|
	{
 | 
						|
		private bool _NewTransToUnNumberedItem = false;
 | 
						|
		public bool NewTransToUnNumberedItem
 | 
						|
		{
 | 
						|
			get { return _NewTransToUnNumberedItem; }
 | 
						|
			set { _NewTransToUnNumberedItem = value; }
 | 
						|
		}
 | 
						|
		public string PathTo
 | 
						|
		{
 | 
						|
			get
 | 
						|
			{
 | 
						|
				return MyItemToID.Path;
 | 
						|
			}
 | 
						|
		}
 | 
						|
		public string PathFrom
 | 
						|
		{
 | 
						|
			get
 | 
						|
			{
 | 
						|
				return MyContent.ContentItems[0].Path;
 | 
						|
			}
 | 
						|
		}
 | 
						|
		[NonSerialized]
 | 
						|
		private TransitionConfig _TransitionConfig;
 | 
						|
		public TransitionConfig TransitionConfig
 | 
						|
		{
 | 
						|
			get
 | 
						|
			{
 | 
						|
				if (_TransitionConfig == null)
 | 
						|
				{
 | 
						|
					_TransitionConfig = new TransitionConfig(this);
 | 
						|
				}
 | 
						|
				return _TransitionConfig;
 | 
						|
			}
 | 
						|
		}
 | 
						|
		public bool HasPageNum
 | 
						|
		{
 | 
						|
			get
 | 
						|
			{
 | 
						|
				return TransitionConfig.Transition_Formatted.ToUpper() == "TRUE";
 | 
						|
			}
 | 
						|
		}
 | 
						|
		public string ResolvePathTo(FormatInfo fi, ItemInfo itminfo, int tranType, ItemInfo toitem, ItemInfo rangeitem, bool hasPageNum)
 | 
						|
		{
 | 
						|
			try
 | 
						|
			{
 | 
						|
				return TransitionText.GetResolvedText(fi, itminfo, tranType, toitem, rangeitem, HasPageNum);
 | 
						|
			}
 | 
						|
			catch (Exception ex)
 | 
						|
			{
 | 
						|
				if (tranType == 2 && ex.Message == "Cannot find Next Item")
 | 
						|
					return TransitionText.GetResolvedText(fi, itminfo, tranType, toitem, toitem, HasPageNum);
 | 
						|
				_MyLog.Error("Error Processing Transition Text", ex);
 | 
						|
				return "(Resolved Transition Text)";
 | 
						|
			}
 | 
						|
		}
 | 
						|
		public string ResolvePathTo(FormatInfo fi, ItemInfo itminfo, int tranType, ItemInfo toitem, ItemInfo rangeitem)
 | 
						|
		{
 | 
						|
			try
 | 
						|
			{
 | 
						|
				return TransitionText.GetResolvedText(fi, itminfo, tranType, toitem, rangeitem, HasPageNum);
 | 
						|
			}
 | 
						|
			catch (Exception ex)
 | 
						|
			{
 | 
						|
				if (tranType == 2 && ex.Message == "Cannot find Next Item")
 | 
						|
					return TransitionText.GetResolvedText(fi, itminfo, tranType, toitem, toitem, HasPageNum);
 | 
						|
				_MyLog.Error("Error Processing Transition Text", ex);
 | 
						|
				return "(Resolved Transition Text)";
 | 
						|
			}
 | 
						|
		}
 | 
						|
		public string ResolvePathTo()
 | 
						|
		{
 | 
						|
			MyContent.RefreshContentItems();
 | 
						|
			ItemInfo item = MyContent.ContentItems[0];
 | 
						|
			//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);
 | 
						|
		}
 | 
						|
		public string ResolvePathTo(TransitionLookup tranLookup)
 | 
						|
		{
 | 
						|
			MyContent.RefreshContentItems();
 | 
						|
			ItemInfo item = MyContent.ContentItems[0];
 | 
						|
			ItemInfo myItemToID = MyItemToID;
 | 
						|
			if (tranLookup.ContainsKey(item.ItemID)) item = tranLookup[item.ItemID];
 | 
						|
			bool hasPageNum = false;
 | 
						|
			if (item.ActiveFormat.PlantFormat.FormatData.TransData.UseTransitionModifier ||
 | 
						|
				item.ActiveFormat.PlantFormat.FormatData.TransData.UseSpecificTransitionModifier)
 | 
						|
			{
 | 
						|
				TransitionConfig tc = new TransitionConfig(Config);
 | 
						|
				if (tc != null && tc.Transition_Formatted.ToUpper() == "TRUE") hasPageNum = true;
 | 
						|
			}
 | 
						|
			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);
 | 
						|
				if (!tranLookup.MyLookups.ContainsKey(myItemToID.MyProcedure.ItemID))
 | 
						|
					tranLookup.AddProcLookup(myItemToID.MyProcedure.ItemID, ProcedureInfo.GetNewLookup(tranLookup, new TransitionLookupEventArgs(myItemToID.MyProcedure.ItemID, tranLookup.ApplicabilityUnit, MyItemToID.MyDocVersion, tranLookup)).MyLookup);
 | 
						|
				if (tranLookup.ContainsKey(ToID))
 | 
						|
					myItemToID = tranLookup[ToID];
 | 
						|
				else
 | 
						|
					_MyLog.WarnFormat("Invalid Unit Transition: from,to '{0}','{1}'", MyContent.ContentItems[0].ShortPath, myItemToID.ShortPath);
 | 
						|
			}
 | 
						|
			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);
 | 
						|
				if (!tranLookup.MyLookups.ContainsKey(MyItemRangeID.MyProcedure.ItemID))
 | 
						|
					tranLookup.AddProcLookup(MyItemRangeID.MyProcedure.ItemID, ProcedureInfo.GetNewLookup(tranLookup, new TransitionLookupEventArgs(MyItemRangeID.MyProcedure.ItemID, tranLookup.ApplicabilityUnit, MyItemRangeID.MyDocVersion, tranLookup)).MyLookup);
 | 
						|
				if (tranLookup.ContainsKey(RangeID))
 | 
						|
					myItemRangeID = tranLookup[RangeID];
 | 
						|
				else
 | 
						|
					if (myItemRangeID.ItemID != myItemToID.ItemID)
 | 
						|
						_MyLog.WarnFormat("Invalid Unit Range Transition: from,to '{0}','{1}'", MyContent.ContentItems[0].ShortPath, myItemRangeID.ShortPath);
 | 
						|
				//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, hasPageNum);
 | 
						|
		}
 | 
						|
	}
 | 
						|
	#region AffectedTransitons
 | 
						|
	public partial class TransitionInfoList
 | 
						|
	{
 | 
						|
		[Serializable()]
 | 
						|
		private class AffectedTransitonsCriteria
 | 
						|
		{
 | 
						|
			public AffectedTransitonsCriteria(int itemID)
 | 
						|
			{
 | 
						|
				_ItemID = itemID;
 | 
						|
			}
 | 
						|
			private int _ItemID;
 | 
						|
			public int ItemID
 | 
						|
			{
 | 
						|
				get { return _ItemID; }
 | 
						|
				set { _ItemID = value; }
 | 
						|
			}
 | 
						|
		}
 | 
						|
		public static TransitionInfoList GetAffected(int itemID)
 | 
						|
		{
 | 
						|
			try
 | 
						|
			{
 | 
						|
				TransitionInfoList tmp = DataPortal.Fetch<TransitionInfoList>(new AffectedTransitonsCriteria(itemID));
 | 
						|
				TransitionInfo.AddList(tmp);
 | 
						|
				tmp.AddEvents();
 | 
						|
				return tmp;
 | 
						|
			}
 | 
						|
			catch (Exception ex)
 | 
						|
			{
 | 
						|
				throw new DbCslaException("Error on TransitionInfoList.GetAffected", ex);
 | 
						|
			}
 | 
						|
		}
 | 
						|
		private void DataPortal_Fetch(AffectedTransitonsCriteria criteria)
 | 
						|
		{
 | 
						|
			this.RaiseListChangedEvents = false;
 | 
						|
			if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] TransitionInfoList.DataPortal_FetchAffected", GetHashCode());
 | 
						|
			try
 | 
						|
			{
 | 
						|
				using (SqlConnection cn = Database.VEPROMS_SqlConnection)
 | 
						|
				{
 | 
						|
					using (SqlCommand cm = cn.CreateCommand())
 | 
						|
					{
 | 
						|
						cm.CommandType = CommandType.StoredProcedure;
 | 
						|
						cm.CommandText = "getAffectedTransitions";
 | 
						|
						cm.Parameters.AddWithValue("@ItemID", criteria.ItemID);
 | 
						|
						cm.CommandTimeout = Database.DefaultTimeout;
 | 
						|
						using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader()))
 | 
						|
						{
 | 
						|
							IsReadOnly = false;
 | 
						|
							while (dr.Read()) this.Add(new TransitionInfo(dr));
 | 
						|
							IsReadOnly = true;
 | 
						|
						}
 | 
						|
					}
 | 
						|
				}
 | 
						|
			}
 | 
						|
			catch (Exception ex)
 | 
						|
			{
 | 
						|
				if (_MyLog.IsErrorEnabled) _MyLog.Error("TransitionInfoList.DataPortal_FetchAffected", ex);
 | 
						|
				throw new DbCslaException("TransitionInfoList.DataPortal_Fetch", ex);
 | 
						|
			}
 | 
						|
			this.RaiseListChangedEvents = true;
 | 
						|
		}
 | 
						|
		public string Summarize()
 | 
						|
		{
 | 
						|
			StringBuilder sb = new StringBuilder("");
 | 
						|
			foreach (TransitionInfo trans in this)
 | 
						|
				sb.Append("\r\n" + trans.PathFrom);
 | 
						|
			return sb.ToString();
 | 
						|
		}
 | 
						|
	#endregion
 | 
						|
		#region ExternalTransitionsToChildren
 | 
						|
		private class ExternalTransitionsToChildrenCriteria
 | 
						|
		{
 | 
						|
			public ExternalTransitionsToChildrenCriteria(int itemID)
 | 
						|
			{
 | 
						|
				_ItemID = itemID;
 | 
						|
			}
 | 
						|
			private int _ItemID;
 | 
						|
			public int ItemID
 | 
						|
			{
 | 
						|
				get { return _ItemID; }
 | 
						|
				set { _ItemID = value; }
 | 
						|
			}
 | 
						|
		}
 | 
						|
		public static TransitionInfoList GetExternalTransitionsToChildren(int itemID)
 | 
						|
		{
 | 
						|
			try
 | 
						|
			{
 | 
						|
				TransitionInfoList tmp = DataPortal.Fetch<TransitionInfoList>(new ExternalTransitionsToChildrenCriteria(itemID));
 | 
						|
				TransitionInfo.AddList(tmp);
 | 
						|
				tmp.AddEvents();
 | 
						|
				return tmp;
 | 
						|
			}
 | 
						|
			catch (Exception ex)
 | 
						|
			{
 | 
						|
				throw new DbCslaException("Error on TransitionInfoList.GetExternalTransitionsToChildren", ex);
 | 
						|
			}
 | 
						|
		}
 | 
						|
		private void DataPortal_Fetch(ExternalTransitionsToChildrenCriteria criteria)
 | 
						|
		{
 | 
						|
			this.RaiseListChangedEvents = false;
 | 
						|
			if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] TransitionInfoList.DataPortal_FetchExternalTransitionsToChildren", GetHashCode());
 | 
						|
			try
 | 
						|
			{
 | 
						|
				using (SqlConnection cn = Database.VEPROMS_SqlConnection)
 | 
						|
				{
 | 
						|
					using (SqlCommand cm = cn.CreateCommand())
 | 
						|
					{
 | 
						|
						cm.CommandType = CommandType.StoredProcedure;
 | 
						|
						cm.CommandText = "getExternalTransitionsToChildren";
 | 
						|
						cm.Parameters.AddWithValue("@ItemID", criteria.ItemID);
 | 
						|
						cm.CommandTimeout = Database.DefaultTimeout;
 | 
						|
						using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader()))
 | 
						|
						{
 | 
						|
							IsReadOnly = false;
 | 
						|
							while (dr.Read()) this.Add(new TransitionInfo(dr));
 | 
						|
							IsReadOnly = true;
 | 
						|
						}
 | 
						|
					}
 | 
						|
				}
 | 
						|
			}
 | 
						|
			catch (Exception ex)
 | 
						|
			{
 | 
						|
				if (_MyLog.IsErrorEnabled) _MyLog.Error("TransitionInfoList.DataPortal_FetchExternalTransitionsToChildren", ex);
 | 
						|
				throw new DbCslaException("TransitionInfoList.DataPortal_Fetch", ex);
 | 
						|
			}
 | 
						|
			this.RaiseListChangedEvents = true;
 | 
						|
		}
 | 
						|
		#endregion
 | 
						|
		#region ExternalTransitions
 | 
						|
		private class ExternalTransitionsCriteria
 | 
						|
		{
 | 
						|
			public ExternalTransitionsCriteria(int itemID)
 | 
						|
			{
 | 
						|
				_ItemID = itemID;
 | 
						|
			}
 | 
						|
			private int _ItemID;
 | 
						|
			public int ItemID
 | 
						|
			{
 | 
						|
				get { return _ItemID; }
 | 
						|
				set { _ItemID = value; }
 | 
						|
			}
 | 
						|
		}
 | 
						|
		public static TransitionInfoList GetExternalTransitions(int itemID)
 | 
						|
		{
 | 
						|
			try
 | 
						|
			{
 | 
						|
				TransitionInfoList tmp = DataPortal.Fetch<TransitionInfoList>(new ExternalTransitionsCriteria(itemID));
 | 
						|
				TransitionInfo.AddList(tmp);
 | 
						|
				tmp.AddEvents();
 | 
						|
				return tmp;
 | 
						|
			}
 | 
						|
			catch (Exception ex)
 | 
						|
			{
 | 
						|
				throw new DbCslaException("Error on TransitionInfoList.GetExternalTransitions", ex);
 | 
						|
			}
 | 
						|
		}
 | 
						|
		private void DataPortal_Fetch(ExternalTransitionsCriteria criteria)
 | 
						|
		{
 | 
						|
			this.RaiseListChangedEvents = false;
 | 
						|
			if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] TransitionInfoList.DataPortal_FetchExternalTransitions", GetHashCode());
 | 
						|
			try
 | 
						|
			{
 | 
						|
				using (SqlConnection cn = Database.VEPROMS_SqlConnection)
 | 
						|
				{
 | 
						|
					using (SqlCommand cm = cn.CreateCommand())
 | 
						|
					{
 | 
						|
						cm.CommandType = CommandType.StoredProcedure;
 | 
						|
						cm.CommandText = "getExternalTransitions";
 | 
						|
						cm.Parameters.AddWithValue("@ItemID", criteria.ItemID);
 | 
						|
						cm.CommandTimeout = Database.DefaultTimeout;
 | 
						|
						using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader()))
 | 
						|
						{
 | 
						|
							IsReadOnly = false;
 | 
						|
							while (dr.Read()) this.Add(new TransitionInfo(dr));
 | 
						|
							IsReadOnly = true;
 | 
						|
						}
 | 
						|
					}
 | 
						|
				}
 | 
						|
			}
 | 
						|
			catch (Exception ex)
 | 
						|
			{
 | 
						|
				if (_MyLog.IsErrorEnabled) _MyLog.Error("TransitionInfoList.DataPortal_FetchExternalTransitions", ex);
 | 
						|
				throw new DbCslaException("TransitionInfoList.DataPortal_Fetch", ex);
 | 
						|
			}
 | 
						|
			this.RaiseListChangedEvents = true;
 | 
						|
		}
 | 
						|
		#endregion
 | 
						|
		#region PastedAffectedTransitions
 | 
						|
		private class PastedAffectedTransitonsCriteria
 | 
						|
		{
 | 
						|
			public PastedAffectedTransitonsCriteria(int itemID)
 | 
						|
			{
 | 
						|
				_ItemID = itemID;
 | 
						|
			}
 | 
						|
			private int _ItemID;
 | 
						|
			public int ItemID
 | 
						|
			{
 | 
						|
				get { return _ItemID; }
 | 
						|
				set { _ItemID = value; }
 | 
						|
			}
 | 
						|
		}
 | 
						|
		internal static TransitionInfoList GetPastedAffected(int itemID)
 | 
						|
		{
 | 
						|
			try
 | 
						|
			{
 | 
						|
				TransitionInfoList tmp = DataPortal.Fetch<TransitionInfoList>(new PastedAffectedTransitonsCriteria(itemID));
 | 
						|
				TransitionInfo.AddList(tmp);
 | 
						|
				tmp.AddEvents();
 | 
						|
				return tmp;
 | 
						|
			}
 | 
						|
			catch (Exception ex)
 | 
						|
			{
 | 
						|
				throw new DbCslaException("Error on TransitionInfoList.GetPastedAffected", ex);
 | 
						|
			}
 | 
						|
		}
 | 
						|
		private void DataPortal_Fetch(PastedAffectedTransitonsCriteria criteria)
 | 
						|
		{
 | 
						|
			this.RaiseListChangedEvents = false;
 | 
						|
			if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] TransitionInfoList.DataPortal_FetchPastedAffected", GetHashCode());
 | 
						|
			try
 | 
						|
			{
 | 
						|
				using (SqlConnection cn = Database.VEPROMS_SqlConnection)
 | 
						|
				{
 | 
						|
					using (SqlCommand cm = cn.CreateCommand())
 | 
						|
					{
 | 
						|
						cm.CommandType = CommandType.StoredProcedure;
 | 
						|
						cm.CommandText = "getPastedAffectedTransitions";
 | 
						|
						cm.Parameters.AddWithValue("@ItemID", criteria.ItemID);
 | 
						|
						cm.CommandTimeout = Database.DefaultTimeout;
 | 
						|
						using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader()))
 | 
						|
						{
 | 
						|
							IsReadOnly = false;
 | 
						|
							while (dr.Read()) this.Add(new TransitionInfo(dr));
 | 
						|
							IsReadOnly = true;
 | 
						|
						}
 | 
						|
					}
 | 
						|
				}
 | 
						|
			}
 | 
						|
			catch (Exception ex)
 | 
						|
			{
 | 
						|
				if (_MyLog.IsErrorEnabled) _MyLog.Error("TransitionInfoList.DataPortal_FetchPastedAffected", ex);
 | 
						|
				throw new DbCslaException("TransitionInfoList.DataPortal_Fetch", ex);
 | 
						|
			}
 | 
						|
			this.RaiseListChangedEvents = true;
 | 
						|
		}
 | 
						|
		#endregion
 | 
						|
	}
 | 
						|
	public class TransitionBuilder
 | 
						|
	{
 | 
						|
		private StringBuilder _Results = new StringBuilder();
 | 
						|
		public FormatData _FormatData;
 | 
						|
		public string _TransFormat;
 | 
						|
		public E_TransUI _TransUI;
 | 
						|
		public ItemInfo _FromItem;
 | 
						|
		public int _TranType;
 | 
						|
		public ItemInfo _ToItem;
 | 
						|
		public ItemInfo _RangeItem;
 | 
						|
		public bool _UsedRangeAncestor;
 | 
						|
		private string _Token;
 | 
						|
		public bool SectNumWithStepNum;
 | 
						|
		public string Token
 | 
						|
		{
 | 
						|
			get { return _Token; }
 | 
						|
			set { _Token = value; }
 | 
						|
		}
 | 
						|
		private string _Prefix;
 | 
						|
		public string Prefix
 | 
						|
		{
 | 
						|
			get { return _Prefix; }
 | 
						|
			set { if(_Prefix==null)_Prefix = value; }
 | 
						|
		}
 | 
						|
		public void ResetPrefix(string str)
 | 
						|
		{
 | 
						|
			_Prefix = str;
 | 
						|
		}
 | 
						|
		public bool HasText
 | 
						|
		{
 | 
						|
			get
 | 
						|
			{
 | 
						|
				return _Results.Length > 0;
 | 
						|
			}
 | 
						|
		}
 | 
						|
		public StringBuilder Append(string str)
 | 
						|
		{
 | 
						|
			return _Results.Append(str);
 | 
						|
		}
 | 
						|
		public StringBuilder ReplaceToken(string str)
 | 
						|
		{
 | 
						|
			if (str == null || str == "") return _Results;
 | 
						|
			if (_FormatData.TransData.XchngTranSpForHard && str[0]!=',' && str[0] != ' ')
 | 
						|
			{
 | 
						|
				int indx = str.IndexOf(' ');	// 16 bit code only processes 1st occurance
 | 
						|
				if (indx > -1)					// Not a while loop in 16 bit. 
 | 
						|
				{								//  (see \promsnt\lib\edit\gettran.c:TransitionCat)
 | 
						|
					str = str.Remove(indx, 1);
 | 
						|
					str = str.Insert(indx, @"\u160?");
 | 
						|
				}
 | 
						|
			}
 | 
						|
			return _Results.Append(str);
 | 
						|
		}
 | 
						|
		public override string ToString()
 | 
						|
		{
 | 
						|
			return _Results.ToString();
 | 
						|
		}
 | 
						|
		public StringBuilder Remove(int startIndex, int length)
 | 
						|
		{
 | 
						|
			return _Results.Remove(startIndex, length);
 | 
						|
		}
 | 
						|
		public int Length
 | 
						|
		{
 | 
						|
			get { return _Results.Length; }
 | 
						|
		}
 | 
						|
		public void AppendPrefix()
 | 
						|
		{
 | 
						|
			if (HasText && Prefix != null)
 | 
						|
			{
 | 
						|
				if (!_Results.ToString().EndsWith(_Prefix))
 | 
						|
					_Results.Append(Prefix);
 | 
						|
				_Prefix = null;
 | 
						|
			}
 | 
						|
			else if (_TranType == 4 && _ToItem.MoreThanOneStepSection())
 | 
						|
			{
 | 
						|
				if (!HasText && Prefix != null && Prefix.ToUpper().StartsWith(", STEP"))
 | 
						|
				{
 | 
						|
					_Prefix = null;
 | 
						|
					return;
 | 
						|
				}
 | 
						|
				_Results.Append(Prefix);
 | 
						|
				_Prefix = null;
 | 
						|
			}
 | 
						|
			else if (_TranType == 5 && Prefix != null)
 | 
						|
			{
 | 
						|
				if (!HasText && Prefix.StartsWith(", "))
 | 
						|
					_Results.Append(Prefix.TrimStart(", ".ToCharArray()));
 | 
						|
				else
 | 
						|
					_Results.Append(Prefix);
 | 
						|
				_Prefix = null;
 | 
						|
			}
 | 
						|
			// If the prefix contains an open paren, we want to add the open paren regardless
 | 
						|
			// of whether there already is text in the resulting string.
 | 
						|
			else if (!HasText && Prefix != null && Prefix.Contains("("))
 | 
						|
			{
 | 
						|
				_Results.Append(Prefix.TrimStart(" ".ToCharArray()));   // since no text in result, trim starting space.
 | 
						|
			}
 | 
						|
		}
 | 
						|
		
 | 
						|
		public string OverridePrefix
 | 
						|
		{
 | 
						|
			set { _Prefix = value; }
 | 
						|
		}
 | 
						|
	}
 | 
						|
	public static class TransitionText
 | 
						|
	{
 | 
						|
		private delegate bool TransitionAppendFunction(TransitionBuilder tb);
 | 
						|
		
 | 
						|
		private static Dictionary<string, TransitionAppendFunction> _AppendMethods;
 | 
						|
		private static void SetupMethods()
 | 
						|
		{
 | 
						|
			_AppendMethods = new Dictionary<string, TransitionAppendFunction>();
 | 
						|
			_AppendMethods.Add("{Proc Num}", AddTransitionProcNum);
 | 
						|
			_AppendMethods.Add("{?.Proc Num}", AddOptionalTransitionProcNum);
 | 
						|
			_AppendMethods.Add("{Proc Title}", AddTransitionProcTitle);
 | 
						|
			_AppendMethods.Add("{?.Proc Title}", AddOptionalTransitionProcTitle);
 | 
						|
			_AppendMethods.Add("{First Step}", AddStepNumber);
 | 
						|
			_AppendMethods.Add("{Step Number}", AddStepNumber);				// WCN2, tran type 6
 | 
						|
			_AppendMethods.Add("{Last Step}", AddRangeStepNumber);
 | 
						|
			_AppendMethods.Add("{.}", AddIncludedStepNumber);
 | 
						|
			_AppendMethods.Add("{Sect Hdr}", AddTranGetSectionHdr);
 | 
						|
			_AppendMethods.Add("{?.Sect Hdr}", AddOptionalTranGetSectionHdr);
 | 
						|
			_AppendMethods.Add("{Sect Title}", AddTranGetSectionTitle);
 | 
						|
			_AppendMethods.Add("{?.Sect Title}", AddOptionalTranGetSectionTitle);
 | 
						|
			_AppendMethods.Add("{?.Sect Num}", AddOptionalTranGetSectionNum);
 | 
						|
			_AppendMethods.Add("{Sect Num}", AddTranGetSectionNumber);
 | 
						|
			_AppendMethods.Add("{Sect Number}", AddTranGetSectionNumber);   // WCN2, tran type 6
 | 
						|
			_AppendMethods.Add("{Page Num}", AddPageNumber);
 | 
						|
			_AppendMethods.Add("{Step Text}", AddStepText);
 | 
						|
		}
 | 
						|
		public static string GetResolvedText(ItemInfo fromInfo, int tranType, ItemInfo toItem, ItemInfo rangeItem, bool hasPageNum)
 | 
						|
		{
 | 
						|
			return GetResolvedText(fromInfo.ActiveFormat, fromInfo, tranType, toItem, rangeItem, hasPageNum);
 | 
						|
		}
 | 
						|
		public static string GetResolvedText(FormatInfo formatInfo, ItemInfo fromInfo, int tranType, ItemInfo toItem, ItemInfo rangeItem, bool pagenum)
 | 
						|
		{
 | 
						|
			if (!pagenum)
 | 
						|
			{
 | 
						|
				TransitionInfo ct = fromInfo.MyContent.ContentTransitionCount > 0 ? fromInfo.MyContent.ContentTransitions[0] : null;
 | 
						|
				int trIU = -1;
 | 
						|
				string cfg = string.Empty;
 | 
						|
				if (ct != null)
 | 
						|
				{
 | 
						|
					trIU = fromInfo.MyContent.ContentTransitions[0].MyTransitionInfoUnique;
 | 
						|
					cfg = fromInfo.MyContent.ContentTransitions[0].Config;
 | 
						|
				}
 | 
						|
				else
 | 
						|
				{
 | 
						|
          string pattern = string.Format(@"<START\]\\v0([^#]*)\\v #Link:Transition(|Range):[0-9]* <CTID=-[0-9]+>( [0-9]*){{1,2}}\[END>");
 | 
						|
          //string pattern = string.Format(@".*\\v <START\](\\[^v \\]+)*\\v0(\\[^v \\]+)* ([^#]*?)(\\[^v'? \\]+)*\\v(\\[^v \\]+)* #Link:Transition[^:]*?:[0-9]+ <CTID=-[0-9]+>( [0-9]*){{1,2}}\[END>");
 | 
						|
					Match m = Regex.Match(fromInfo.MyContent.Text, pattern);
 | 
						|
					if (m.Groups.Count > 1 && m.Groups[1].Value.Contains("(Page ~)"))
 | 
						|
						pagenum = true;
 | 
						|
				}
 | 
						|
			}
 | 
						|
			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 (pagenum && (tranType==1||tranType==2||tranType==4))
 | 
						|
			{
 | 
						|
				// if range transition, the page number token needs to go after the first step, else it's at the end:
 | 
						|
				if (tranType == 2 && tb._TransFormat.Contains("{First Step"))
 | 
						|
				{
 | 
						|
					tb._TransFormat = tb._TransFormat.Insert(tb._TransFormat.IndexOf("{First Step}")+12, " {Page Num}");
 | 
						|
				}
 | 
						|
				else
 | 
						|
					tb._TransFormat = tb._TransFormat + " {Page Num}";
 | 
						|
			}
 | 
						|
			if(_AppendMethods==null)
 | 
						|
				SetupMethods();
 | 
						|
			string retval = BuildString(tb);
 | 
						|
			// Added for transitions to un-numbered steps
 | 
						|
			if (retval == string.Empty)
 | 
						|
			{
 | 
						|
				retval = toItem.Ordinal.ToString();
 | 
						|
					fromInfo.NewTransToUnNumberedItem = true;
 | 
						|
				//Volian.Base.Library.vlnStackTrace.ShowStackLocal("Setting Flag", 3, 10);
 | 
						|
				//using (Item itm = fromInfo.Get())
 | 
						|
				//{
 | 
						|
				//    ItemAnnotation ia = itm.ItemAnnotations.Add(AnnotationType.GetByName("Verifcation Required"));
 | 
						|
				//    ia.SearchText = "Transition to Un-Numbered Step";
 | 
						|
				//itm.Save();
 | 
						|
				//}
 | 
						|
			}
 | 
						|
			return retval;
 | 
						|
 | 
						|
		}
 | 
						|
		private static TransitionBuilder SetupTransitionBuilder(FormatInfo formatInfo, ItemInfo fromInfo, int tranType, ItemInfo toItem, ItemInfo rangeItem)
 | 
						|
		{
 | 
						|
			TransitionBuilder tb = new TransitionBuilder();
 | 
						|
			tb._FormatData = formatInfo.PlantFormat.FormatData;
 | 
						|
			// get the format of the transition string based on this transition's index into the TransData part of 
 | 
						|
			// format....
 | 
						|
			if (tranType > tb._FormatData.TransData.TransTypeList.Count)
 | 
						|
				tranType = 0;
 | 
						|
			// Replace 3 tokens ", {.}, {.}, {.}" with a single token "{.}"
 | 
						|
			tb._TransFormat = tb._FormatData.TransData.TransTypeList[tranType].TransFormat.Replace(", {.}, {.}, {.}", "{.}");
 | 
						|
			if (formatInfo.PlantFormat.FormatData.TransData.UpcaseTranAnd) tb._TransFormat = tb._TransFormat.Replace("and", "AND");
 | 
						|
			tb._TransUI = (E_TransUI)tb._FormatData.TransData.TransTypeList[tranType].TransUI;
 | 
						|
			tb._FromItem = fromInfo;
 | 
						|
			tb._TranType = tranType;
 | 
						|
			tb._ToItem = toItem;
 | 
						|
			tb._RangeItem = rangeItem;
 | 
						|
			return tb;
 | 
						|
		}
 | 
						|
		private static string BuildString(TransitionBuilder tb)
 | 
						|
		{
 | 
						|
			//Invalid Transition Check
 | 
						|
			if (tb._ToItem.ActiveParent == null || tb._RangeItem.ActiveParent == null)
 | 
						|
				return "?";
 | 
						|
			int startIndex = 0;
 | 
						|
			int index = -1;
 | 
						|
			int rexIndex = -1;
 | 
						|
			string prefix = null;
 | 
						|
			string prevToken = null;
 | 
						|
			bool lastAdded = false;
 | 
						|
			MatchCollection mc = Regex.Matches(tb._TransFormat, @"{(Proc Num|\?\.Proc Num|Proc Title|\?\.Proc Title|" +
 | 
						|
				@"First Step|Step Number|Last Step|\.|Sect Hdr|\?\.Sect Hdr|Sect Title|\?\.Sect Title|\?\.Sect Num|Sect Num|" +
 | 
						|
				@"Sect Number|Page Num|Step Text)}");
 | 
						|
			foreach (Match m in mc)
 | 
						|
			{
 | 
						|
				string tmppref = prefix;
 | 
						|
				prefix = null;
 | 
						|
				rexIndex = m.Index;
 | 
						|
				int rexEndToken = m.Index + m.Length - 1;
 | 
						|
				if (rexIndex > startIndex) prefix = tb._TransFormat.Substring(startIndex, rexIndex - startIndex);
 | 
						|
				if (prefix == null) prevToken = null;
 | 
						|
				// if the last token did not add anything to the buffer, still want to put the text prefix in:
 | 
						|
				if (!lastAdded && prefix == null) prefix = tmppref;
 | 
						|
				if (startIndex == 0 && prefix != null && prefix.Length > 0)
 | 
						|
				{
 | 
						|
					tb.Append(prefix);
 | 
						|
					prefix = "";
 | 
						|
				}
 | 
						|
				string token = tb._TransFormat.Substring(rexIndex, rexEndToken - rexIndex + 1);
 | 
						|
				// we need to flag condition where the step number already has the section number in it.  For example, Wolf Creek
 | 
						|
				// using WCN2, has some sections whose section number is 'D' and the step number is 'D1', or 'D2'.  The resolved
 | 
						|
				// transition text was coming out as 'DD1'. The format's HLS tab format contains '{Section Prefix}' whose implementation
 | 
						|
				// adds the section number to the tab.
 | 
						|
				if (token.Contains("Sect Num") && tb._TransFormat.Length > rexEndToken + 1)
 | 
						|
				{
 | 
						|
					int nxtTokenS = tb._TransFormat.IndexOf("{", rexEndToken);
 | 
						|
					if (nxtTokenS > -1 && nxtTokenS == rexEndToken + 1)  // the {step} token has to immediately follow the section num token
 | 
						|
					{
 | 
						|
						int nxtTokenE = tb._TransFormat.IndexOf("}", nxtTokenS);
 | 
						|
						string nxtToken = tb._TransFormat.Substring(nxtTokenS, nxtTokenE - nxtTokenS + 1);
 | 
						|
						tb.SectNumWithStepNum = tb._ToItem.IsStep && nxtToken.Contains("Step")
 | 
						|
							&& tb._ToItem.MyHLS.FormatStepData.TabData.IdentPrint.Contains("{Section Prefix}");
 | 
						|
					}
 | 
						|
				}
 | 
						|
				if (token == "{.}" && tb._ToItem.ItemID == tb._RangeItem.ItemID)
 | 
						|
				{
 | 
						|
					startIndex = tb._TransFormat.Length;   // skip the rest of the trans format
 | 
						|
					break;
 | 
						|
				}
 | 
						|
				if (_AppendMethods.ContainsKey(token))
 | 
						|
				{
 | 
						|
					tb.Token = token;
 | 
						|
					if (token[1] == '?')	// If it's a conditional token, only update the prefix if the prefix is null
 | 
						|
						tb.Prefix = prefix;
 | 
						|
					else					// If not conditional, force the prefix to be updated
 | 
						|
						tb.OverridePrefix = prefix;
 | 
						|
					lastAdded = _AppendMethods[token](tb);
 | 
						|
				}
 | 
						|
				else
 | 
						|
					tb.Append("\\" + token.Substring(0, token.Length - 1) + "\\}");
 | 
						|
				startIndex = rexEndToken + 1;
 | 
						|
				prevToken = token;
 | 
						|
				if (startIndex >= tb._TransFormat.Length) break;
 | 
						|
			}
 | 
						|
			if ((startIndex < tb._TransFormat.Length) && lastAdded) tb.Append(tb._TransFormat.Substring(startIndex, tb._TransFormat.Length - startIndex));
 | 
						|
			return (tb.ToString());		
 | 
						|
		}
 | 
						|
		
 | 
						|
		// TODO: For hlp: LowerCaseTranNumber - lower case substep numbers in transitions
 | 
						|
		private static bool AddTransitionProcNum(TransitionBuilder tb) // Coded for HLP
 | 
						|
		{
 | 
						|
			string retstr = tb._ToItem.MyProcedure.MyContent.Number;
 | 
						|
			// start with UnitSpecific procedure number.
 | 
						|
			string unitnum = null;
 | 
						|
			if (tb._ToItem.MyDocVersion != null && tb._ToItem.MyDocVersion.DocVersionConfig != null)
 | 
						|
				unitnum = tb._ToItem.MyDocVersion.DocVersionConfig.Unit_ProcedureNumber;
 | 
						|
			if (unitnum != null && unitnum.Length > 0)
 | 
						|
			{
 | 
						|
				unitnum = unitnum.Replace("-", @"\u8209?");
 | 
						|
				retstr = unitnum.Replace("#", retstr);
 | 
						|
			}
 | 
						|
			// LATER: Format Flag TruncateProcNmAfter1stSpace  (dropped plants)
 | 
						|
			// LATER: Format Flag HardSpTranProcNumb (active plants)
 | 
						|
			tb.AppendPrefix();
 | 
						|
			if (tb._FormatData.TransData.HardSpTranProcNumb) retstr = retstr.Replace(" ", @"\u160?");
 | 
						|
			tb.ReplaceToken(retstr);
 | 
						|
			return (retstr != null && retstr != "");
 | 
						|
		}
 | 
						|
		private static bool AddOptionalTransitionProcNum(TransitionBuilder tb)
 | 
						|
		{
 | 
						|
			// token is passed in for future use, i.e. if text is placed between "?" and "." to
 | 
						|
			// request other processing.
 | 
						|
 | 
						|
			// for now the only test is to check if the toitem is in the current procedure.
 | 
						|
			if (tb._FromItem.MyProcedure.ItemID == tb._ToItem.MyProcedure.ItemID) return false; // tb.TextAdded;
 | 
						|
			return AddTransitionProcNum(tb);
 | 
						|
		}
 | 
						|
 | 
						|
		private static bool AddTransitionProcTitle(TransitionBuilder tb)// Coded for HLP
 | 
						|
		{
 | 
						|
			tb.AppendPrefix();
 | 
						|
 | 
						|
			// if can't find procedure, just put in a question mark.
 | 
						|
			if (tb._ToItem.PreviousID == null && tb._ToItem.ItemPartCount == 0 && tb._ToItem.ItemDocVersionCount == 0)
 | 
						|
			{
 | 
						|
				if (tb._ToItem.ActiveParent is ItemInfo && (tb._ToItem.ActiveParent as ItemInfo).Steps[0].ItemID == tb._ToItem.ItemID)
 | 
						|
				{
 | 
						|
					// If the transition is to the first applicable step, then use the location rather than outputting a question mark.
 | 
						|
				}
 | 
						|
				else
 | 
						|
				{
 | 
						|
					tb.Append("?");
 | 
						|
					return true; // (tb.TextAdded = true);
 | 
						|
				}
 | 
						|
			}
 | 
						|
			string parenstr = tb._ToItem.MyProcedure.MyContent.Text;
 | 
						|
			parenstr = parenstr.Replace("\\LINE ", " ").Replace("\r\n", " ");
 | 
						|
			StringBuilder lretstr = new StringBuilder();
 | 
						|
			// LATER:  For an else - Do I need to strip underlining here?  See promsnt\lib\edit\gettran.c
 | 
						|
			if (parenstr != "<NO TITLE>" || tb._FormatData.ProcData.PrintNoTitle)
 | 
						|
			{
 | 
						|
				lretstr.Append(tb._FormatData.TransData.DelimiterForTransitionTitle);
 | 
						|
				lretstr.Append(tb._FormatData.TransData.CapsTransitions ? parenstr.ToUpper().Replace(@"\U", @"\u") :
 | 
						|
					tb._FormatData.TransData.Cap1stCharTrans ? CapFirstLetterOnly(parenstr, 0) :
 | 
						|
					parenstr);
 | 
						|
				lretstr.Append(tb._FormatData.TransData.DelimiterForTransitionTitle);
 | 
						|
			}
 | 
						|
			tb.ReplaceToken(lretstr.ToString());
 | 
						|
			return (lretstr.Length != 0);
 | 
						|
		}
 | 
						|
		private static bool AddOptionalTransitionProcTitle(TransitionBuilder tb)
 | 
						|
		{
 | 
						|
			// token is passed in for future use, i.e. if text is placed between "?" and "." to
 | 
						|
			// request other processing.
 | 
						|
 | 
						|
			// for now the only test is to check if the toitem is in the current procedure.
 | 
						|
			if (tb._FromItem.MyProcedure.ItemID == tb._ToItem.MyProcedure.ItemID) return false; // tb.TextAdded;
 | 
						|
			return AddTransitionProcTitle(tb);
 | 
						|
		}
 | 
						|
		private static string Tab(ItemInfo item, bool doStep)
 | 
						|
		{
 | 
						|
			// if this section has the DSS_AddDotZeroStdHLS, then we need to account for this when
 | 
						|
			// concatenating text onto the tabs.
 | 
						|
			bool hasDotZero = (item.MyDocStyle.StructureStyle.Style & E_DocStructStyle.DSS_AddDotZeroStdHLS) == E_DocStructStyle.DSS_AddDotZeroStdHLS;
 | 
						|
			if (item == null) return "";
 | 
						|
			string sret = "";
 | 
						|
			switch (item.MyContent.Type / 10000)
 | 
						|
			{
 | 
						|
				case 0:  //procedure
 | 
						|
					sret = ProcedureInfo.Get(item.ItemID).MyTab.CleanText;
 | 
						|
					break;
 | 
						|
				case 1: // section
 | 
						|
					sret = SectionInfo.Get(item.ItemID).MyTab.CleanText;
 | 
						|
					break;
 | 
						|
				case 2:  // step
 | 
						|
					
 | 
						|
					ItemInfo pitem = item;
 | 
						|
					bool hasDelim = item.ActiveFormat.PlantFormat.FormatData.TransData.StepSubstepDelimeter != null;
 | 
						|
					List<string> DelimList = null;
 | 
						|
					if (!hasDelim)
 | 
						|
					{
 | 
						|
						DelimList = new List<string>();
 | 
						|
						SeqTabFmtList seqtabs = item.ActiveFormat.PlantFormat.FormatData.SectData.StepSectionData.SeqTabFmtList;
 | 
						|
						foreach (SeqTabFmt seqtab in seqtabs)
 | 
						|
						{
 | 
						|
							string delim = seqtab.PrintTabFormat.Replace("{seq}", "");
 | 
						|
							DelimList.Add(delim.Trim());
 | 
						|
						}
 | 
						|
					}
 | 
						|
					while (!pitem.IsHigh)
 | 
						|
					{
 | 
						|
						//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)
 | 
						|
						{
 | 
						|
							// get list of delimiters to remove from the format:
 | 
						|
							foreach (string rmvDelim in DelimList) thisTab = thisTab.Replace(rmvDelim, "");
 | 
						|
						}
 | 
						|
						if (pitem.IsRNOPart)
 | 
						|
						{
 | 
						|
							if (thisTab == null || thisTab == "")
 | 
						|
								sret = "RNO." + sret;
 | 
						|
							else
 | 
						|
							{
 | 
						|
								thisTab = thisTab.Trim(" ".ToCharArray());
 | 
						|
								sret = "RNO." + thisTab + sret;
 | 
						|
							}
 | 
						|
						}
 | 
						|
						else
 | 
						|
						{
 | 
						|
							if (thisTab != null && thisTab != "")
 | 
						|
							{
 | 
						|
								thisTab =   thisTab.Trim(" ".ToCharArray());
 | 
						|
								if (hasDelim && !thisTab.EndsWith(".") && !thisTab.EndsWith(")")) thisTab = thisTab + ".";
 | 
						|
								if (hasDotZero && thisTab.EndsWith(".0.")) thisTab = thisTab.Substring(0, thisTab.Length - 2);
 | 
						|
							}
 | 
						|
							// RHM 20130326 2039 - I added the logic to limit the addition of the section tab to 
 | 
						|
							// the existing tab if it starts the same.
 | 
						|
							// Westinghouse/System Procs/WRS-101/Add6/4.2.7  Transition to 4.2.5
 | 
						|
							if(sret == "" || !sret.StartsWith(thisTab)) sret = thisTab + sret;
 | 
						|
						}
 | 
						|
						pitem = pitem.ActiveParent as ItemInfo;
 | 
						|
						if (pitem == null) break;
 | 
						|
					}
 | 
						|
					// add hls tab if it's not already in the tab.  doStep was added to handle the TStepNoFlag
 | 
						|
					// which is used to define whether the step number is included in the range transition text
 | 
						|
					// if the 'to' transition is a substep.  Note that only skip the following if going to a substep
 | 
						|
					// thus change 'doStep' to true if the 'to' transition is a hls.
 | 
						|
					if (!doStep && item.IsHigh) doStep = true;
 | 
						|
					if (doStep && pitem.IsHigh)
 | 
						|
					{
 | 
						|
						Tab myTab = pitem.MyDocVersion.DocVersionConfig.SelectedSlave == 0 ? StepInfo.Get(pitem.ItemID).MyTab : pitem.MyTab;
 | 
						|
						string hlsTab = myTab.BasicTab ?? myTab.CleanTextNoSymbols; 
 | 
						|
						if (!sret.StartsWith(hlsTab.Trim(" ".ToCharArray())))
 | 
						|
						{
 | 
						|
							if (!hasDelim)
 | 
						|
								foreach (string rmvDelim in DelimList) hlsTab = hlsTab.Replace(rmvDelim, "");
 | 
						|
							hlsTab = hlsTab.Trim(" ".ToCharArray());
 | 
						|
							if (hasDelim && !hlsTab.EndsWith(".") && !hlsTab.EndsWith(")")) hlsTab = hlsTab + ".";
 | 
						|
							if (hasDotZero)
 | 
						|
							{
 | 
						|
								if (item.IsHigh)
 | 
						|
									hlsTab = hlsTab.Substring(0, hlsTab.Length - 1);
 | 
						|
								else if (hlsTab.EndsWith(".0.")) 
 | 
						|
									hlsTab = hlsTab.Substring(0, hlsTab.Length - 2);
 | 
						|
								if (sret == "" || !sret.StartsWith(hlsTab)) sret = hlsTab + sret;
 | 
						|
							}
 | 
						|
							else
 | 
						|
								sret = hlsTab + sret;
 | 
						|
						}
 | 
						|
					}
 | 
						|
					break;
 | 
						|
			}
 | 
						|
			sret = sret.Trim(" .)".ToCharArray());
 | 
						|
			return sret;
 | 
						|
		}
 | 
						|
		private static bool AddPageNumber(TransitionBuilder tb)
 | 
						|
		{
 | 
						|
			if (tb._ToItem.PageNumber != 0 && tb._FromItem.PageNumber != 0)
 | 
						|
			{
 | 
						|
				int pgoffset = tb._ToItem.PageNumber - tb._FromItem.PageNumber;
 | 
						|
				tb._ToItem.PageNumberUsed = tb._ToItem.PageNumber;
 | 
						|
				switch (pgoffset)
 | 
						|
				{
 | 
						|
					case 1:
 | 
						|
						tb.Append(" (Next Page)");
 | 
						|
						//Console.WriteLine("Next Page: {0}", tb._FromItem.ShortPath);
 | 
						|
						break;
 | 
						|
					case -1:
 | 
						|
						tb.Append(" (Previous Page)");
 | 
						|
						//Console.WriteLine("Prev Page: {0}", tb._FromItem.ShortPath);
 | 
						|
						break;
 | 
						|
					case 0:
 | 
						|
						break;
 | 
						|
					default:
 | 
						|
						tb.Append(string.Format(" (Page {0})", tb._ToItem.PageNumber + 1));
 | 
						|
						//Console.WriteLine("Page: {0}, {1}", tb._FromItem.ShortPath, tb._ToItem.PageNumber);
 | 
						|
						break;
 | 
						|
				}
 | 
						|
			}
 | 
						|
			else
 | 
						|
			{
 | 
						|
				tb.Append(" (Page ~)");
 | 
						|
			}
 | 
						|
			return true;
 | 
						|
		} 
 | 
						|
		private static bool AddStepNumber(TransitionBuilder tb)
 | 
						|
		{
 | 
						|
			// If we're on a step put out the step number.
 | 
						|
			ItemInfo secitm = TranGetSectionItem(tb._ToItem);
 | 
						|
			if ((!((tb._TransUI & E_TransUI.StepAllowNone) == E_TransUI.StepAllowNone)) || tb._ToItem.MyContent.Type > 20000)
 | 
						|
			{
 | 
						|
				if (tb.HasText)
 | 
						|
				{
 | 
						|
					// check for transition that goes to a procedure step section with title of 'Procedure steps' followed
 | 
						|
					// by ', Step'.  This should output as 'Procedure step xyz' rather than 'Procedure steps, step xyz'
 | 
						|
					// TODO: NEED TO USE A FORMAT VARIABLE TO CONTROL THE FOLLOWING
 | 
						|
					if ((tb._FormatData.TransData.AdjustStepTransitionText || tb._ToItem.ActiveFormat.Name.StartsWith("OHLP")) && !tb._TransFormat.Contains("{Last Step}") && tb.Prefix != null && tb.Prefix.ToUpper().Contains(", STEP") && tb.ToString().ToUpper().EndsWith("PROCEDURE STEPS"))
 | 
						|
					{
 | 
						|
						tb.Remove(tb.Length - 15, 15);  // remove "procedure steps"
 | 
						|
						tb.Append("procedure Step");
 | 
						|
						tb.ResetPrefix(" ");  // just setting = to a space wasn't resetting prefix.
 | 
						|
					}
 | 
						|
					string tmpStr = tb.ToString();
 | 
						|
					if (tmpStr.ToUpper().EndsWith(", STEP ") && (tb.Prefix.ToUpper().EndsWith(", STEP ")))
 | 
						|
						tb.Remove(tb.Length - 7, 7);  // 7 is length of ", Step "
 | 
						|
					tb.AppendPrefix();
 | 
						|
				}
 | 
						|
				//else if (tb._TranType == 4 && tb._ToItem.MoreThanOneStepSection())
 | 
						|
				else if (tb._TranType == 4 && tb._ToItem.MoreThanOneStepSection() || tb._TranType == 5)
 | 
						|
				{
 | 
						|
					tb.AppendPrefix();
 | 
						|
				}
 | 
						|
				if (tb._ToItem.PreviousID == null && tb._ToItem.ItemPartCount == 0 && tb._ToItem.ItemDocVersionCount == 0)
 | 
						|
				{
 | 
						|
					// Logic added for handling applicability.  If the first item is not applicable, then the second item will effectively become
 | 
						|
					// the first item but it's itempartcount  will be zero
 | 
						|
					if(tb._ToItem.ActiveParent is ItemInfo && (tb._ToItem.ActiveParent as ItemInfo).Steps[0].ItemID == tb._ToItem.ItemID) 
 | 
						|
						tb.ReplaceToken(Tab(tb._ToItem, true));
 | 
						|
					else
 | 
						|
					tb.Append("?");
 | 
						|
				}
 | 
						|
				else
 | 
						|
					tb.ReplaceToken(Tab(tb._ToItem, true));
 | 
						|
				return true;
 | 
						|
			}
 | 
						|
			else if ((tb._ToItem.IsSection || tb._ToItem.IsProcedure) && ((tb._TransUI & E_TransUI.StepAllowNone) == E_TransUI.StepAllowNone))
 | 
						|
			{
 | 
						|
				string tmpStr = tb.ToString();
 | 
						|
				if (tmpStr.ToUpper().EndsWith(", STEP ")) 
 | 
						|
					tb.Remove(tb.Length - 7, 7);  // 7 is length of ", Step "
 | 
						|
				else if (tb.Prefix != null && tb.Prefix.StartsWith(")") && (tb.ToString().IndexOf("(")>-1))
 | 
						|
					tb.Append(")");
 | 
						|
				return true;
 | 
						|
			}
 | 
						|
			else
 | 
						|
				return false;
 | 
						|
		}
 | 
						|
		private static bool AddRangeStepNumber(TransitionBuilder tb)
 | 
						|
		{
 | 
						|
			tb.AppendPrefix();
 | 
						|
			if (tb._RangeItem.PreviousID == null && tb._RangeItem.ItemPartCount == 0 && tb._RangeItem.ItemDocVersionCount == 0)
 | 
						|
				tb.Append("?");
 | 
						|
			else
 | 
						|
				tb.ReplaceToken(Tab(tb._RangeItem, tb._RangeItem.ActiveFormat.PlantFormat.FormatData.TransData.TStepNoFlag));
 | 
						|
			return true;
 | 
						|
		}
 | 
						|
		private static bool AddIncludedStepNumber(TransitionBuilder tb)
 | 
						|
		{
 | 
						|
			Dictionary<int, ItemInfo> rangeAncestors = GetAncestors(tb._RangeItem);
 | 
						|
			tb.AppendPrefix();
 | 
						|
			bool usedRangeAncestor = false;
 | 
						|
			ItemInfo next = GetNextItem(tb._ToItem, rangeAncestors, ref usedRangeAncestor);
 | 
						|
			string lastTab = Tab(tb._RangeItem, tb._RangeItem.ActiveFormat.PlantFormat.FormatData.TransData.TStepNoFlag);
 | 
						|
			while (next.ItemID != tb._RangeItem.ItemID)
 | 
						|
			{
 | 
						|
				string thisTab = Tab(next, tb._RangeItem.ActiveFormat.PlantFormat.FormatData.TransData.TStepNoFlag);
 | 
						|
				if (lastTab == thisTab) break;
 | 
						|
				tb.ReplaceToken(", " + thisTab);
 | 
						|
				next = GetNextItem(next, rangeAncestors, ref usedRangeAncestor);
 | 
						|
			}
 | 
						|
			tb._UsedRangeAncestor = usedRangeAncestor;
 | 
						|
			return true;
 | 
						|
		}
 | 
						|
		private static bool AddStepText(TransitionBuilder tb)
 | 
						|
		{
 | 
						|
			tb.AppendPrefix();
 | 
						|
			string txt = tb._ToItem.MyContent.Text;
 | 
						|
			tb.Append(txt);
 | 
						|
			return true;
 | 
						|
		}
 | 
						|
		private static Dictionary<int, ItemInfo> GetAncestors(ItemInfo itemInfo)
 | 
						|
		{
 | 
						|
			Dictionary<int, ItemInfo> retval = new Dictionary<int,ItemInfo>();
 | 
						|
			while (!itemInfo.IsHigh)
 | 
						|
			{
 | 
						|
				ItemInfo parent = itemInfo.MyActiveParent as ItemInfo;
 | 
						|
				retval.Add(parent.ItemID, itemInfo.FirstSibling);
 | 
						|
				itemInfo = parent;
 | 
						|
			}
 | 
						|
			return retval;
 | 
						|
		}
 | 
						|
		private static ItemInfo GetNextItem(ItemInfo next, Dictionary<int, ItemInfo> rangeAncestors, ref bool usedRangeAncestor)
 | 
						|
		{
 | 
						|
			if (rangeAncestors.ContainsKey(next.ItemID))
 | 
						|
				return rangeAncestors[next.ItemID];
 | 
						|
			while (next.GetNextItem() == null)
 | 
						|
			{
 | 
						|
				next = next.ActiveParent as ItemInfo;
 | 
						|
				if(next == null) throw(new Exception("Cannot find Next Item"));
 | 
						|
			}
 | 
						|
			return next.GetNextItem();
 | 
						|
		}
 | 
						|
		private static bool AddOptionalTranGetSectionHdr(TransitionBuilder tb)
 | 
						|
		{
 | 
						|
			// first handle 'to' non-step section.  Always add it.
 | 
						|
			if (tb._ToItem.IsSection && !tb._ToItem.IsStepSection) return AddTranGetSectionHdr(tb);
 | 
						|
			
 | 
						|
			int cntsect = 0;
 | 
						|
			ItemInfo sect = TranGetSectionItem(tb._ToItem);
 | 
						|
			if (tb._ToItem.MyProcedure.Sections == null)
 | 
						|
				tb._ToItem.MyProcedure.MyContent.RefreshContentParts();
 | 
						|
			foreach (ItemInfo ii in tb._ToItem.MyProcedure.Sections) if (ii.IsStepSection) cntsect++;
 | 
						|
			// If Procedure going to has only 1 step section, do not add it.
 | 
						|
			if (cntsect == 1) return false; // tb.TextAdded;
 | 
						|
 | 
						|
			// If procedure going to has more than 1 step section and is NOT same procedure 
 | 
						|
			//		and going to default section, do not add it.
 | 
						|
			if (tb._ToItem.MyProcedure.ItemID != tb._FromItem.MyProcedure.ItemID && sect != null &&
 | 
						|
				sect.IsDefaultSection) return false; // tb.TextAdded;
 | 
						|
 | 
						|
			// if in same procedure and same section do not add it.
 | 
						|
			if (tb._ToItem.MyProcedure.ItemID == tb._FromItem.MyProcedure.ItemID &&
 | 
						|
				sect == TranGetSectionItem(tb._FromItem) && 
 | 
						|
				! tb._ToItem.IsSection)
 | 
						|
				return false;
 | 
						|
			
 | 
						|
			// If a 'thru' range, only put out the section if it's to a different section 
 | 
						|
			// that is not the default section.
 | 
						|
			if (((tb._TransUI & E_TransUI.StepLast) == E_TransUI.StepLast) && ((tb._TransUI & E_TransUI.SectMenuStep) == E_TransUI.SectMenuStep))
 | 
						|
			{
 | 
						|
				ItemInfo fi = tb._FromItem;
 | 
						|
				while (!fi.IsSection)fi = fi.ActiveParent as ItemInfo;
 | 
						|
				ItemInfo ti = tb._ToItem;
 | 
						|
				while (!ti.IsSection) ti = ti.ActiveParent as ItemInfo;
 | 
						|
				if (fi.ItemID == ti.ItemID || ti.IsDefaultSection) return false; // tb.TextAdded;
 | 
						|
			}
 | 
						|
			return AddTranGetSectionHdr(tb);
 | 
						|
		}
 | 
						|
		private static bool AddTranGetSectionHdr(TransitionBuilder tb)
 | 
						|
		{
 | 
						|
			// output from 16-bit code looks like section header
 | 
						|
			// if this is a step section & the default section, just return
 | 
						|
			//if (TranGetSectionItem(itminfo).IsDefaultSection) return;
 | 
						|
			StringBuilder retstr = new StringBuilder();
 | 
						|
			retstr.Append(TranGetSectionNumber(tb._ToItem));
 | 
						|
			string txt;
 | 
						|
			if(retstr.Length > 0)
 | 
						|
				txt = TranGetSectionTitle(tb,tb._ToItem);
 | 
						|
			else
 | 
						|
				txt = TranGetSectionTitle(tb,tb._ToItem, true);
 | 
						|
			if (retstr.Length > 0 && (txt!=null && txt.Length > 0)) retstr.Append(", ");
 | 
						|
			retstr.Append(txt);
 | 
						|
			tb.AppendPrefix();
 | 
						|
			tb.ReplaceToken(retstr.ToString());
 | 
						|
			return (retstr.Length != 0);
 | 
						|
		}
 | 
						|
		private static bool AddOptionalTranGetSectionTitle(TransitionBuilder tb)
 | 
						|
		{
 | 
						|
			// token is passed in for future use, i.e. if text is placed between "?" and "." to
 | 
						|
			// request other processing.
 | 
						|
 | 
						|
			// for now the only test is to check if the toitem is in the current section.
 | 
						|
			if (TranGetSectionItem(tb._FromItem).ItemID == TranGetSectionItem(tb._ToItem).ItemID) return false; // tb.TextAdded;
 | 
						|
			tb.AppendPrefix();
 | 
						|
			string retstr = TranGetSectionTitle(tb,tb._ToItem);
 | 
						|
			tb.ReplaceToken(retstr);
 | 
						|
			return (retstr != null && retstr != "");
 | 
						|
		}
 | 
						|
		private static bool AddOptionalTranGetSectionNum(TransitionBuilder tb)
 | 
						|
		{
 | 
						|
			if (TranGetSectionItem(tb._FromItem).ItemID == TranGetSectionItem(tb._ToItem).ItemID) return false;
 | 
						|
			if (tb.SectNumWithStepNum) return false;
 | 
						|
			if (tb._ToItem.IsSection) return false;
 | 
						|
			tb.AppendPrefix();
 | 
						|
			string retstr = TranGetSectionNumber(tb._ToItem);
 | 
						|
			tb.ReplaceToken(retstr);
 | 
						|
			return (retstr != null && retstr != "");
 | 
						|
		}
 | 
						|
		private static bool AddTranGetSectionTitle(TransitionBuilder tb)
 | 
						|
		{
 | 
						|
			// LATER: Cap1stSectionTitle, CapFirstLetterOnly
 | 
						|
			if (tb._FormatData.TransData.UseSecTitles)
 | 
						|
			{
 | 
						|
				string retstr = TranGetSectionTitle(tb,tb._ToItem);
 | 
						|
				tb.AppendPrefix();
 | 
						|
				tb.ReplaceToken(retstr);
 | 
						|
				return (retstr != null && retstr != "");
 | 
						|
			}
 | 
						|
			return false;
 | 
						|
		}
 | 
						|
		private static bool AddTranGetSectionNumber(TransitionBuilder tb)
 | 
						|
		{
 | 
						|
			if (tb._TranType == 1 && tb._ToItem.ActiveSection.ItemID == tb._FromItem.ActiveSection.ItemID) return false;
 | 
						|
			if (tb.SectNumWithStepNum) return false;
 | 
						|
			if (tb._TranType == 0 && (tb._ToItem.IsSection || tb._ToItem.IsProcedure) && ((tb._TransUI & E_TransUI.StepAllowNone) == E_TransUI.StepAllowNone))
 | 
						|
			{
 | 
						|
				string tmpStr = tb.ToString();
 | 
						|
				if (tmpStr.ToUpper().EndsWith(", STEP ")) tb.Remove(tb.Length - 7, 7);  // 7 is length of ", Step "
 | 
						|
				else if (tb.Prefix != null && tb.Prefix.StartsWith(")"))
 | 
						|
					tb.Append(")");
 | 
						|
				return true;
 | 
						|
			}
 | 
						|
			string retstr = TranGetSectionNumber(tb._ToItem);
 | 
						|
			if (retstr != null && retstr != "")
 | 
						|
			{
 | 
						|
				int indx = retstr.IndexOf(' ');	// 16 bit code only processes 1st occurance
 | 
						|
				if (indx > -1)					// Not a while loop in 16 bit. 
 | 
						|
				{								//  (see \promsnt\lib\edit\gettran.c:TransitionCat)
 | 
						|
					retstr = retstr.Remove(indx, 1);
 | 
						|
					retstr = retstr.Insert(indx, @"\u160?");
 | 
						|
				}
 | 
						|
			}
 | 
						|
			// *** DO NOT DELETE - to fix a problem where the word ,step was appearing twice when there was no
 | 
						|
			// section tab.
 | 
						|
			//if (retstr!=null&&retstr!="") tb.AppendPrefix();   
 | 
						|
			tb.AppendPrefix();
 | 
						|
			tb.ReplaceToken(retstr);
 | 
						|
			return (retstr != null && retstr != "");
 | 
						|
		}
 | 
						|
		private static string FixTitleCase(Match m)
 | 
						|
		{
 | 
						|
			if (Regex.IsMatch(m.Value, @"^[A-Za-z]+\.?$"))
 | 
						|
			{
 | 
						|
				// don't title case "words" that have no vowles 
 | 
						|
				if (Regex.IsMatch(m.Value.ToUpper(), @"^[BCDFGHJKLMNPQRSTVWXZ]+\.?$"))
 | 
						|
					return m.Value;
 | 
						|
				string part1 = m.Value.Substring(0, 1);
 | 
						|
				string part2 = m.Value.Substring(1);
 | 
						|
				return part1.ToUpper() + part2.ToLower();
 | 
						|
			}
 | 
						|
			return m.Value;
 | 
						|
		}
 | 
						|
		private static string CapFirstLetterOnly(string retstr, int p)
 | 
						|
		{
 | 
						|
			// LATER:  write code to capitalize first letter (active plants)
 | 
						|
		string lretstr = Regex.Replace(retstr, @"([^ ,]+)", new MatchEvaluator(FixTitleCase));
 | 
						|
			return lretstr;
 | 
						|
		}
 | 
						|
		// TODO: Section methods are not complete....
 | 
						|
		private static ItemInfo TranGetSectionItem(ItemInfo itminfo)
 | 
						|
		{
 | 
						|
			ItemInfo tmpitm = itminfo;
 | 
						|
			while (tmpitm.MyContent.Type >= 20000) tmpitm = tmpitm.MyParent;
 | 
						|
			return tmpitm;
 | 
						|
		}
 | 
						|
		private static string TranGetSectionNumber(ItemInfo itminfo)
 | 
						|
		{
 | 
						|
			ItemInfo tmpitm = TranGetSectionItem(itminfo);
 | 
						|
			if (!tmpitm.IsSection) return "";
 | 
						|
			string str = tmpitm.MyContent.Number;
 | 
						|
			str = Regex.Replace(str, @"\<U\>", itminfo.MyDocVersion.DocVersionConfig.Unit_Number, RegexOptions.IgnoreCase );
 | 
						|
			str = Regex.Replace(str, @"\<ID\>", itminfo.MyDocVersion.DocVersionConfig.Unit_ID, RegexOptions.IgnoreCase);
 | 
						|
			return (str);
 | 
						|
		}
 | 
						|
		private static string TranGetSectionTitle(TransitionBuilder tb, ItemInfo itminfo)
 | 
						|
		{
 | 
						|
			// LATER: Cap1stSectionTitle, CapFirstLetterOnly
 | 
						|
			if (tb._FormatData.TransData.UseSecTitles)
 | 
						|
			{
 | 
						|
				ItemInfo tmpitm = TranGetSectionItem(itminfo);
 | 
						|
				string sectionTitle = tmpitm.MyContent.Text;
 | 
						|
			sectionTitle = (tb._FormatData.TransData.CapsTransitionsSection ? sectionTitle.ToUpper().Replace(@"\U", @"\u") :
 | 
						|
					tb._FormatData.TransData.Cap1stCharTransSection ? CapFirstLetterOnly(sectionTitle, 0) :
 | 
						|
					sectionTitle);
 | 
						|
				return (sectionTitle);
 | 
						|
			}
 | 
						|
			return null;
 | 
						|
		}
 | 
						|
		private static string TranGetSectionTitle(TransitionBuilder tb, ItemInfo itminfo, bool overRide)
 | 
						|
		{
 | 
						|
			// LATER: Cap1stSectionTitle, CapFirstLetterOnly
 | 
						|
			if (overRide)
 | 
						|
			{
 | 
						|
				ItemInfo tmpitm = TranGetSectionItem(itminfo);
 | 
						|
				string sectionTitle = tmpitm.MyContent.Text;
 | 
						|
				sectionTitle = (tb._FormatData.TransData.CapsTransitionsSection ? sectionTitle.ToUpper().Replace(@"\U", @"\u") :
 | 
						|
						tb._FormatData.TransData.Cap1stCharTransSection ? CapFirstLetterOnly(sectionTitle, 0) :
 | 
						|
						sectionTitle);
 | 
						|
				return (sectionTitle);
 | 
						|
			}
 | 
						|
			return null;
 | 
						|
		}
 | 
						|
	}
 | 
						|
}
 |