Inserting New Items, FixTransition Text

This commit is contained in:
Rich 2009-07-30 19:00:35 +00:00
parent 9859b74db8
commit e70ffda937
2 changed files with 368 additions and 236 deletions

View File

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Text.RegularExpressions;
using Csla;
using Csla.Data;
@ -125,6 +126,11 @@ namespace VEPROMS.CSLA.Library
public ItemInfo InsertSiblingBefore(string text, string number)
{
ItemInfo tmp = DataPortal.Fetch<ItemInfo>(new AddingPartCriteria(ItemID, EAddpingPart.Before, number, text, null, null, null, null, DateTime.Now, Environment.UserName));
// this item is updated in SQL so we have to manually force the iteminfo updates
// Refresh ItemInfo to update Previous
using (Item item = Get()) ItemInfo.Refresh(item);
// Update all of the content records that have transitions that point to the Siblings or Sibling Children of the new item
tmp.UpdateTransitionText();
return tmp;
}
#endregion
@ -140,8 +146,31 @@ namespace VEPROMS.CSLA.Library
public ItemInfo InsertSiblingAfter(string text, string number, int? type)
{
ItemInfo tmp = DataPortal.Fetch<ItemInfo>(new AddingPartCriteria(ItemID, EAddpingPart.After, number, text, type, null, null, null, DateTime.Now, Environment.UserName));
// if next exists, it is updated in SQL so we have to manually force the iteminfo updates
// Refresh ItemInfo to update PreviousID field
if (tmp.NextItem != null) using (Item item = tmp.NextItem.Get()) ItemInfo.Refresh(item);
// Update all of the content records that have transitions that point to the Siblings or Sibling Children of the new item
tmp.UpdateTransitionText();
return tmp;
}
public void UpdateTransitionText()
{
// Update Ordinals from here down
ResetOrdinal();
// This returns a list of all of the transitions that may have been affected
using(TransitionInfoList trans = TransitionInfoList.GetAffected(this.ItemID))
{
foreach (TransitionInfo tran in trans)
{
using (Content content = tran.MyContent.Get())
{
content.FixTransitionText(tran);
if (content.IsDirty)
content.Save();
}
}
}
}
#endregion
#region Insert Child
public ItemInfo InsertChild(E_FromType fromType, int type, string text)
@ -151,6 +180,11 @@ namespace VEPROMS.CSLA.Library
public ItemInfo InsertChild(E_FromType fromType, int type, string text, string number)
{
ItemInfo tmp = DataPortal.Fetch<ItemInfo>(new AddingPartCriteria(ItemID, EAddpingPart.Child, number, text, type, (int?) fromType, null, null, DateTime.Now, Environment.UserName));
// if next exists, it is updated in SQL so we have to manually force the iteminfo updates
// Refresh ItemInfo to update PreviousID field
if (tmp.NextItem != null) using (Item item = tmp.NextItem.Get()) ItemInfo.Refresh(item);
// Update all of the content records that have transitions that point to the Siblings or Sibling Children of the new item
tmp.UpdateTransitionText();
return tmp;
}
#endregion
@ -312,27 +346,23 @@ namespace VEPROMS.CSLA.Library
}
private static void ResetOrdinal(int itemID)
{
bool first = true;
ConvertListToDictionary();
string key = itemID.ToString();
if (_CacheByPrimaryKey.ContainsKey(key))
while (key != null && _CacheByPrimaryKey.ContainsKey(key))
{
foreach (ItemInfo itm in _CacheByPrimaryKey[key])
ItemInfo[] items = _CacheByPrimaryKey[key].ToArray();
key = null;
foreach (ItemInfo item in items)
{
itm._Ordinal = null;
//Console.WriteLine("Ordinal {0},{1}",key,itm.MyPrevious == null ? 0 : itm.MyPrevious._Ordinal);
if (first && itm.NextItem != null)
{
ResetOrdinal(itm.NextItem.ItemID);
first = false;
}
//Console.WriteLine("item = {0}, ordinal = {1}",item,item.Ordinal);
item._Ordinal = null;
if (key == null && item.NextItem != null)
key = item.NextItem.ItemID.ToString();
}
}
}
private void ResetOrdinal()
{
//_Ordinal = null;
//Console.WriteLine("Ordinal {0},{1}",ItemID,MyPrevious == null ? 0 : MyPrevious.Ordinal);
ResetOrdinal(ItemID);
}
}

View File

@ -1,234 +1,15 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
namespace VEPROMS.CSLA.Library
{
public partial class TransitionInfo
{
private StringBuilder retstr;
private FormatData _MyFormatData = null;
private ItemInfo _MyFromItemInfo = null;
public string ResolvePathTo(FormatInfo fi, ItemInfo itminfo, ItemInfo toitem, ItemInfo rangeitem)
{
retstr = new StringBuilder();
// get the format of the transition string based on this transition's index into the TransData part of
// format....
_MyFormatData = fi.PlantFormat.FormatData;
_MyFromItemInfo = itminfo;
string tranformat = _MyFormatData.TransData.TransTypeList[TranType].TransFormat;
E_TransUI etm = (E_TransUI)_MyFormatData.TransData.TransTypeList[TranType].TransUI;
int startIndex = 0;
int index = -1;
string nontoken = null;
bool addedtxt = false;
while ((index = tranformat.IndexOf("{", startIndex))>-1)
{
if (index > startIndex) nontoken = tranformat.Substring(startIndex, index - startIndex);
int endtokn = tranformat.IndexOf("}", index);
string token = tranformat.Substring(index, endtokn - index + 1);
switch (token)
{
case "{Proc Num}": // Coded for HLP
addedtxt = AddTransitionProcNum(addedtxt, nontoken, toitem);
break;
case "{?.Proc Num}":
addedtxt = AddOptionalTransitionProcNum(addedtxt, token, nontoken, toitem);
break;
case "{Proc Title}": // Coded for HLP
addedtxt = AddTransitionProcTitle(addedtxt, nontoken, toitem);
break;
case "{?.Proc Title}":
addedtxt = AddOptionalTransitionProcTitle(addedtxt, token, nontoken, toitem);
break;
case "{First Step}": // TODO: For hlp: LowerCaseTranNumber - lower case substep numbers in transitions
// If we're on a step put out the step number.
ItemInfo secitm = TranGetSectionItem(toitem);
if ((!((etm & E_TransUI.StepAllowNone) == E_TransUI.StepAllowNone)) || toitem.MyContent.Type > 20000)
{
if (addedtxt) Append(nontoken, false);
Append(toitem.Ordinal.ToString(), true);
addedtxt = true;
}
break;
case "{Last Step}": // TODO: TStepNoFlag, i.e. include step number in range items.
if (addedtxt) Append(nontoken, false);
Append(rangeitem.Ordinal.ToString(), true);
addedtxt = true;
break;
case "{.}": // TODO: TStepNoFlag, i.e. include step number in range items.
if (addedtxt) Append(nontoken, false);
Append("#", true); // TODO: Intermediate Range.
addedtxt = true;
break;
case "{Sect Hdr}":
addedtxt = AddTranGetSectionHdr(addedtxt, nontoken, toitem);
break;
case "{?.Sect Hdr}":
addedtxt = AddOptionalTranGetSectionHdr(addedtxt, token, nontoken, toitem);
break;
case "{Sect Title}":
// output from 16-bit code looks like section header
addedtxt = AddTranGetSectionHdr(addedtxt, nontoken, toitem);
//AddTranGetSectionTitle(nontoken, toitem);
break;
case "{?.Sect Title}":
// output from 16-bit code looks like section header
addedtxt = AddOptionalTranGetSectionHdr(addedtxt, token, nontoken, toitem);
//AddOptionalTranGetSectionTitle(token, nontoken, toitem);
break;
}
startIndex = endtokn+1;
if (startIndex >= tranformat.Length) break;
}
if (startIndex < tranformat.Length) Append(tranformat.Substring(startIndex, tranformat.Length - startIndex - 1), false);
return (retstr.ToString());
}
private void Append(string str, bool doflags)
{
if (str == null || str == "") return;
if (doflags && _MyFormatData.TransData.XchngTranSpForHard)
{
int indx = str.IndexOf(' ');
if (indx > -1)
{
str.Remove(indx, 1);
str.Insert(indx, @"\u160?");
}
}
retstr.Append(str);
}
private bool AddTransitionProcTitle(bool addedtxt, string nontoken, ItemInfo toitem)
{
string parenstr = toitem.MyProcedure.MyContent.Text;
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>" || _MyFormatData.ProcData.PrintNoTitle)
{
lretstr.Append(_MyFormatData.TransData.DelimiterForTransitionTitle);
lretstr.Append(_MyFormatData.TransData.CapsTransitions ? parenstr.ToUpper() :
_MyFormatData.TransData.Cap1stCharTrans ? CapFirstLetterOnly(parenstr, 0) :
parenstr);
lretstr.Append(_MyFormatData.TransData.DelimiterForTransitionTitle);
}
// LATER: if (DoSectionTransitions && GetSTepNO(TSeq1)) TransitionCat(AddCommaStep", Step"));
if (addedtxt) Append(nontoken, false);
Append(lretstr.ToString(), true);
if (lretstr.Length != 0) return true;
return false;
}
private string CapFirstLetterOnly(string retstr, int p)
{
string lretstr = retstr;
// LATER: write code to capitalize first letter (active plants)
return lretstr;
}
private bool AddOptionalTransitionProcTitle(bool addedtxt, string token, string nontoken, ItemInfo toitem)
{
// 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 (_MyFromItemInfo.MyProcedure.ItemID == toitem.MyProcedure.ItemID) return addedtxt?true:false;
return AddTransitionProcTitle(addedtxt, nontoken, toitem);
}
private bool AddTransitionProcNum(bool addedtxt, string nontoken, ItemInfo toitem)
{
string retstr = toitem.MyProcedure.MyContent.Number;
// LATER: start with UnitSpecific procedure number.
// LATER: Format Flag TruncateProcNmAfter1stSpace (dropped plants)
// LATER: Format Flag HardSpTranProcNumb (active plants)
if (addedtxt) Append(nontoken, false);
Append(retstr, true);
if (retstr != null && retstr != "") return true;
return false;
}
private bool AddOptionalTransitionProcNum(bool addedtxt, string token, string nontoken, ItemInfo toitem)
{
// 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 (_MyFromItemInfo.MyProcedure.ItemID == toitem.MyProcedure.ItemID) return addedtxt ? true : false;
return AddTransitionProcNum(addedtxt, nontoken, toitem);
}
// TODO: Section methods are not complete....
private ItemInfo TranGetSectionItem(ItemInfo itminfo)
{
ItemInfo tmpitm = itminfo;
while (tmpitm.MyContent.Type >= 20000) tmpitm = tmpitm.MyParent;
return tmpitm;
}
private bool AddTranGetSectionHdr(bool addedtxt, string nontoken, ItemInfo itminfo)
{
// if this is a step section & the default section, just return
//if (TranGetSectionItem(itminfo).IsDefaultSection) return;
StringBuilder retstr = new StringBuilder();
retstr.Append(TranGetSectionNumber(itminfo));
string txt = TranGetSectionTitle(itminfo);
if (retstr.Length>0 && txt.Length>0) retstr.Append(", ");
retstr.Append(txt);
if (addedtxt) Append(nontoken, false);
Append(retstr.ToString(), true);
if (retstr.Length != 0) return true;
return false;
}
private bool AddOptionalTranGetSectionHdr(bool addedtxt, string token, string nontoken, ItemInfo toitem)
{
// token is passed in for future use, i.e. if text is placed between "?" and "." to
// request other processing.
// If in same procedure, the section header is put out if not in the same section.
// If in a different procedure, the section header is put out if the 'to' item is not the
// default (or start) section.
if (_MyFromItemInfo.MyProcedure.ItemID == toitem.MyProcedure.ItemID)
{
if (TranGetSectionItem(_MyFromItemInfo).ItemID == TranGetSectionItem(toitem).ItemID) return addedtxt ? true : false;
}
else if (TranGetSectionItem(toitem).IsDefaultSection) return addedtxt ? true : false;
return AddTranGetSectionHdr(addedtxt, nontoken, toitem);
}
private string TranGetSectionNumber(ItemInfo itminfo)
{
ItemInfo tmpitm = TranGetSectionItem(itminfo);
return (tmpitm.MyContent.Number);
}
private string TranGetSectionTitle(ItemInfo itminfo)
{
// LATER: Cap1stSectionTitle, CapFirstLetterOnly
if (_MyFormatData.TransData.UseSecTitles)
{
ItemInfo tmpitm = TranGetSectionItem(itminfo);
return (tmpitm.MyContent.Text);
}
return null;
}
private bool AddOptionalTranGetSectionTitle(bool addedtxt, string token, string nontoken, ItemInfo toitem)
{
// 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(_MyFromItemInfo).ItemID == TranGetSectionItem(toitem).ItemID) return addedtxt ? true : false;
if (addedtxt) Append(nontoken, false);
string retstr = TranGetSectionTitle(toitem);
Append(retstr, true);
if (retstr != null && retstr != "") return true;
return false;
}
private bool AddTranGetSectionTitle(bool addedtxt, string nontoken, ItemInfo itminfo)
{
// LATER: Cap1stSectionTitle, CapFirstLetterOnly
if (_MyFormatData.TransData.UseSecTitles)
{
string retstr = TranGetSectionTitle(itminfo);
if (addedtxt)Append(nontoken, false);
Append(retstr, true);
if (retstr != null && retstr != "") return true;
}
return false;
}
public string PathTo
{
get
@ -240,9 +21,330 @@ namespace VEPROMS.CSLA.Library
{
get
{
//return "From " + MyContent.ContentItems[0].Path;
return MyContent.ContentItems[0].Path;
}
}
public string ResolvePathTo(FormatInfo fi, ItemInfo itminfo, int tranType, ItemInfo toitem, ItemInfo rangeitem)
{
return TransitionText.GetResolvedText(fi, itminfo, tranType, toitem, rangeitem);
}
public string ResolvePathTo()
{
ItemInfo item = MyContent.ContentItems[0];
return ResolvePathTo(item.ActiveFormat, item, TranType, MyItemToID, MyItemRangeID);
}
}
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_FetchFromID", 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);
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 static class TransitionText
{
private delegate bool TransitionAppendFunction(bool textAdded, TransitionBuilder tb, string token, string nonToken);
private struct TransitionBuilder
{
public StringBuilder _Results;
public FormatData _FormatData;
public string _TransFormat;
public E_TransUI _TransUI;
public ItemInfo _FromItem;
public int _TranType;
public ItemInfo _ToItem;
public ItemInfo _RangeItem;
}
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("{Last Step}", AddRangeStepNumber);
_AppendMethods.Add("{.}", AddIncludedStepNumber);
_AppendMethods.Add("{Sect Hdr}", AddTranGetSectionHdr);
_AppendMethods.Add("{?.Sect Hdr}", AddOptionalTranGetSectionHdr);
_AppendMethods.Add("{Sect Title}", AddTranGetSectionHdr);
_AppendMethods.Add("{?.Sect Title}", AddOptionalTranGetSectionHdr);
}
public static string GetResolvedText(ItemInfo fromInfo, int tranType, ItemInfo toItem, ItemInfo rangeItem)
{
return GetResolvedText(fromInfo.ActiveFormat, fromInfo, tranType, toItem, rangeItem);
}
public static string GetResolvedText(FormatInfo formatInfo, ItemInfo fromInfo, int tranType, ItemInfo toItem, ItemInfo rangeItem)
{
TransitionBuilder tb = SetupTransitionBuilder(formatInfo, fromInfo, tranType, toItem, rangeItem);
if(_AppendMethods==null)
SetupMethods();
return BuildString(tb);
}
private static TransitionBuilder SetupTransitionBuilder(FormatInfo formatInfo, ItemInfo fromInfo, int tranType, ItemInfo toItem, ItemInfo rangeItem)
{
TransitionBuilder tb;
tb._Results = new StringBuilder();
tb._FormatData = formatInfo.PlantFormat.FormatData;
// get the format of the transition string based on this transition's index into the TransData part of
// format....
tb._TransFormat = tb._FormatData.TransData.TransTypeList[tranType].TransFormat;
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)
{
int startIndex = 0;
int index = -1;
string nonToken = null;
bool textAdded = false;
while ((index = tb._TransFormat.IndexOf("{", startIndex)) > -1)
{
if (index > startIndex) nonToken = tb._TransFormat.Substring(startIndex, index - startIndex);
int endtokn = tb._TransFormat.IndexOf("}", index);
string token = tb._TransFormat.Substring(index, endtokn - index + 1);
if (_AppendMethods.ContainsKey(token))
textAdded = _AppendMethods[token](textAdded, tb, token, nonToken);
startIndex = endtokn + 1;
if (startIndex >= tb._TransFormat.Length) break;
}
if (startIndex < tb._TransFormat.Length) Append(tb, tb._TransFormat.Substring(startIndex, tb._TransFormat.Length - startIndex - 1), false);
return (tb._Results.ToString());
}
private static void Append(TransitionBuilder tb, string str, bool doflags)
{
if (str == null || str == "") return;
if (doflags && tb._FormatData.TransData.XchngTranSpForHard)
{
int indx = str.IndexOf(' ');
if (indx > -1)
{
str.Remove(indx, 1);
str.Insert(indx, @"\u160?");
}
}
tb._Results.Append(str);
}
// TODO: TStepNoFlag, i.e. include step number in range items.
// TODO: TStepNoFlag, i.e. include step number in range items.
// TODO: For hlp: LowerCaseTranNumber - lower case substep numbers in transitions
private static bool AddTransitionProcNum(bool textAdded, TransitionBuilder tb, string token, string nonToken) // Coded for HLP
{
string retstr = tb._ToItem.MyProcedure.MyContent.Number;
// LATER: start with UnitSpecific procedure number.
// LATER: Format Flag TruncateProcNmAfter1stSpace (dropped plants)
// LATER: Format Flag HardSpTranProcNumb (active plants)
if (textAdded) Append(tb, nonToken, false);
Append(tb, retstr, true);
if (retstr != null && retstr != "") return true;
return false;
}
private static bool AddOptionalTransitionProcNum(bool textAdded, TransitionBuilder tb, string token, string nonToken)
{
// 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 textAdded ? true : false;
return AddTransitionProcNum(textAdded, tb, token, nonToken);
}
private static bool AddTransitionProcTitle(bool textAdded, TransitionBuilder tb, string token, string nonToken)// Coded for HLP
{
string parenstr = tb._ToItem.MyProcedure.MyContent.Text;
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() :
tb._FormatData.TransData.Cap1stCharTrans ? CapFirstLetterOnly(parenstr, 0) :
parenstr);
lretstr.Append(tb._FormatData.TransData.DelimiterForTransitionTitle);
}
// LATER: if (DoSectionTransitions && GetSTepNO(TSeq1)) TransitionCat(AddCommaStep", Step"));
if (textAdded) Append(tb, nonToken, false);
Append(tb, lretstr.ToString(), true);
if (lretstr.Length != 0) return true;
return false;
}
private static bool AddOptionalTransitionProcTitle(bool textAdded, TransitionBuilder tb, string token, string nonToken)
{
// 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 textAdded ? true : false;
return AddTransitionProcTitle(textAdded, tb, token, nonToken);
}
private static bool AddStepNumber(bool textAdded, TransitionBuilder tb, string token, string nonToken)
{
// 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 (textAdded) Append(tb, nonToken, false);
//Console.WriteLine("NEW - ItemID={0},Ordinal={1}", tb._ToItem.ItemID, tb._ToItem.Ordinal);
Append(tb, tb._ToItem.Ordinal.ToString(), true);
textAdded = true;
}
return textAdded;
}
private static bool AddRangeStepNumber(bool textAdded, TransitionBuilder tb, string token, string nonToken)
{
if (textAdded) Append(tb, nonToken, false);
Append(tb, tb._RangeItem.Ordinal.ToString(), true);
textAdded = true;
return textAdded;
}
private static bool AddIncludedStepNumber(bool textAdded, TransitionBuilder tb, string token, string nonToken)
{
if (textAdded) Append(tb, nonToken, false);
Append(tb, "#", true); // TODO: Intermediate Range.
textAdded = true;
return textAdded;
}
private static bool AddOptionalTranGetSectionHdr(bool textAdded, TransitionBuilder tb, string token, string nonToken)
{
// output from 16-bit code looks like section header
// token is passed in for future use, i.e. if text is placed between "?" and "." to
// request other processing.
// If in same procedure, the section header is put out if not in the same section.
// If in a different procedure, the section header is put out if the 'to' item is not the
// default (or start) section.
if (tb._FromItem.MyProcedure.ItemID == tb._ToItem.MyProcedure.ItemID)
{
if (TranGetSectionItem(tb._FromItem).ItemID == TranGetSectionItem(tb._ToItem).ItemID) return textAdded ? true : false;
}
else if (TranGetSectionItem(tb._ToItem).IsDefaultSection) return textAdded ? true : false;
return AddTranGetSectionHdr(textAdded, tb, token, nonToken);
}
private static bool AddTranGetSectionHdr(bool textAdded, TransitionBuilder tb, string token, string nonToken)
{
// 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 = TranGetSectionTitle(tb,tb._ToItem);
if (retstr.Length > 0 && txt.Length > 0) retstr.Append(", ");
retstr.Append(txt);
if (textAdded) Append(tb, nonToken, false);
Append(tb, retstr.ToString(), true);
if (retstr.Length != 0) return true;
return false;
}
private static bool AddOptionalTranGetSectionTitle(bool textAdded, TransitionBuilder tb, string token, string nonToken)
{
// 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 textAdded ? true : false;
if (textAdded) Append(tb, nonToken, false);
string retstr = TranGetSectionTitle(tb,tb._ToItem);
Append(tb, retstr, true);
if (retstr != null && retstr != "") return true;
return false;
}
private static bool AddTranGetSectionTitle(bool textAdded, TransitionBuilder tb, string token, string nonToken)
{
// LATER: Cap1stSectionTitle, CapFirstLetterOnly
if (tb._FormatData.TransData.UseSecTitles)
{
string retstr = TranGetSectionTitle(tb,tb._FromItem);
if (textAdded) Append(tb, nonToken, false);
Append(tb, retstr, true);
if (retstr != null && retstr != "") return true;
}
return false;
}
private static string CapFirstLetterOnly(string retstr, int p)
{
string lretstr = retstr;
// LATER: write code to capitalize first letter (active plants)
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);
return (tmpitm.MyContent.Number);
}
private static string TranGetSectionTitle(TransitionBuilder tb, ItemInfo itminfo)
{
// LATER: Cap1stSectionTitle, CapFirstLetterOnly
if (tb._FormatData.TransData.UseSecTitles)
{
ItemInfo tmpitm = TranGetSectionItem(itminfo);
return (tmpitm.MyContent.Text);
}
return null;
}
}
}