
Settings for Builders Group Demo Event handler for Search Results Report and Resolution User Interface Added code to make DataLoader and PDF generation faster Added ToolTip Property to ItemInfo Added code to handle "AND Range" Transitions Changed comment Sorts ROs by value
3131 lines
88 KiB
C#
3131 lines
88 KiB
C#
#define ItemWithContent
|
||
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.Text;
|
||
using Csla;
|
||
using Csla.Data;
|
||
using System.Data;
|
||
using System.Data.SqlClient;
|
||
using System.Xml;
|
||
using System.Drawing;
|
||
using System.Text.RegularExpressions;
|
||
|
||
namespace VEPROMS.CSLA.Library
|
||
{
|
||
#region Item
|
||
public partial class Item : IVEDrillDown
|
||
{
|
||
public string DisplayNumber
|
||
{
|
||
get { return ItemInfo.ConvertToDisplayText(MyContent.Number); }
|
||
}
|
||
public ItemInfo MyItemInfo /* Return Info version of the current Item */
|
||
{ get { return ItemInfo.Get(ItemID); } }
|
||
public static void ShowAllocated(string title)
|
||
{
|
||
Console.WriteLine("{0} - {1} Items in the dictionary", title, _CacheByPrimaryKey.Count);
|
||
foreach (List<Item> itmlst in _CacheByPrimaryKey.Values)
|
||
foreach(Item itm in itmlst)
|
||
Console.WriteLine("Item {0} UniqueID {1}", itm.ItemID, itm.MyItemUnique);
|
||
Console.WriteLine("- - - - - -");
|
||
}
|
||
|
||
public override string ToString()
|
||
{
|
||
return string.Format("{0} {1}", MyContent.Number, MyContent.Text).Trim();
|
||
}
|
||
// TODO: Move to ItemInfo Extension
|
||
|
||
#region IVEDrillDown
|
||
//public System.Collections.IList GetChildren()
|
||
//{
|
||
// return this.MyContent.ContentParts;
|
||
//}
|
||
//public bool HasChildren
|
||
//{
|
||
// get { return this.MyContent.ContentPartCount > 0; }
|
||
//}
|
||
//public Item MyProcedure
|
||
//{
|
||
// get
|
||
// {
|
||
// // Walk up active parents until the parent is not an item
|
||
// Item tmp = this;
|
||
// while (tmp.ActiveParent.GetType() != typeof(DocVersion)) tmp = (Item)tmp.ActiveParent;
|
||
// return tmp;
|
||
// }
|
||
//}
|
||
//private IVEDrillDown _ActiveParent = null;
|
||
//public IVEDrillDown ActiveParent
|
||
//{
|
||
// get
|
||
// {
|
||
// if (_ActiveParent == null)
|
||
// {
|
||
// if (MyPrevious != null)
|
||
// _ActiveParent = _MyPrevious.ActiveParent;
|
||
// else
|
||
// {
|
||
// if (ItemDocVersionCount > 0)
|
||
// _ActiveParent = this.ItemDocVersions[0].MyDocVersion;
|
||
// else
|
||
// {
|
||
// if (this.ItemParts == null || this.ItemPartCount == 0)
|
||
// _ActiveParent = this;
|
||
// else
|
||
// _ActiveParent = this.ItemParts[0].MyContent.ContentItems[0].MyItem;
|
||
// }
|
||
// }
|
||
// }
|
||
// return _ActiveParent == this ? null : _ActiveParent;
|
||
// }
|
||
//}
|
||
//private Format _ActiveFormat = null;// Added to cache ActiveFormat
|
||
//public Format ActiveFormat
|
||
//{
|
||
// get
|
||
// {
|
||
// if (_ActiveFormat == null)
|
||
// _ActiveFormat = (LocalFormat != null ? LocalFormat : ActiveParent.ActiveFormat);
|
||
// return _ActiveFormat;
|
||
// }
|
||
// set
|
||
// {
|
||
// _ActiveFormat = null; // Reset
|
||
// }
|
||
//}
|
||
//public Format LocalFormat
|
||
//{
|
||
// get { return MyContent.MyFormat; }
|
||
//}
|
||
public ConfigDynamicTypeDescriptor MyConfig
|
||
{
|
||
get { return null; }
|
||
}
|
||
#endregion
|
||
public void MoveItem(IVEDrillDownReadOnly pInfo, int index)
|
||
{
|
||
bool wasfirstchild = false;
|
||
ItemInfo parentInfo = pInfo as ItemInfo;
|
||
DocVersionInfo parentInfoDV = pInfo as DocVersionInfo;
|
||
IList<ItemInfo> children = null;
|
||
E_FromType partType = 0; // this is needed later to determine sub-group type.
|
||
if (parentInfo != null)
|
||
{
|
||
// this may have subgroups, need to use part type to get children list...
|
||
ItemInfo thisinfo = ItemInfo.Get(ItemID);
|
||
partType = thisinfo.FirstSibling.ItemParts[0].PartType;
|
||
children = (IList<ItemInfo>)parentInfo.Lookup((int)partType);
|
||
}
|
||
else
|
||
children = (IList<ItemInfo>)parentInfoDV.GetChildren();
|
||
int numChild = children.Count;
|
||
|
||
if (this.MyPrevious == null) wasfirstchild = true;
|
||
Item origNextItem = null;
|
||
|
||
// First, remove from this item from its list. To do this, get the current item's next point and redirect it's myprevious
|
||
// to this item's previous...
|
||
if (NextItems != null && NextItems.Count > 0)
|
||
{
|
||
origNextItem = NextItems.Items[0];
|
||
origNextItem.MyPrevious = this.MyPrevious;
|
||
this.Save();
|
||
}
|
||
|
||
// check to see if the item is being moved into the middle of some items. newPreviousItem is the item defined
|
||
// by index-1, i.e. inserting below newPreviousItem.
|
||
ItemInfo newPreviousInfo = (index == 0) ? null : children[index - 1];
|
||
ItemInfo newNextInfo = (index == children.Count) ? null : children[index];
|
||
|
||
// Adjust the new next proc to be me.
|
||
if (newNextInfo != null)
|
||
{
|
||
using (Item newNextItem = newNextInfo.Get())
|
||
{
|
||
newNextItem.MyPrevious = this;
|
||
newNextItem.Save().Dispose();
|
||
}
|
||
}
|
||
|
||
// adjust the previous node, i.e. may either be at same level or, if first in list, adjust the parent...
|
||
// if 'newPreviousItem' isn't null, then adding to the middle of the list.
|
||
if (newPreviousInfo != null)
|
||
{
|
||
using (Item newPreviousItem = newPreviousInfo.Get())
|
||
{
|
||
MyPrevious = newPreviousItem;
|
||
Save();
|
||
}
|
||
}
|
||
// newPreviousInfo == null if moving into first child, and wasfirstchild == true if moving out of first child.
|
||
// This will require adjusting the DocVersion to point to the correct first child if a procedure is moved.
|
||
if (newPreviousInfo == null || wasfirstchild)
|
||
{
|
||
if (parentInfo != null) // Moving Item within procedure, i.e. moving a section or step
|
||
{
|
||
using (Item parentItem = parentInfo.Get())
|
||
{
|
||
// moving first child out... reset parent to point to the original next item
|
||
if (wasfirstchild)
|
||
parentItem.MyContent.ContentParts[(int)partType].MyItem = origNextItem;
|
||
else
|
||
parentItem.MyContent.ContentParts[(int)partType].MyItem = this;
|
||
parentItem.Save().Dispose();
|
||
}
|
||
}
|
||
else if (parentInfoDV != null) // Moving Item (Procedure) within DocVersion
|
||
{
|
||
using (DocVersion parentItemDV = parentInfoDV.Get())
|
||
{
|
||
ItemInfo firstinfo = parentInfoDV.FirstChild();
|
||
parentItemDV.MyItem = wasfirstchild?parentInfoDV.Procedures[1].Get():this;
|
||
parentItemDV.Save().Dispose();
|
||
if (!wasfirstchild && firstinfo != null)
|
||
{
|
||
using (Item firstchild = firstinfo.Get())
|
||
{
|
||
firstchild.MyPrevious = this;
|
||
firstchild.Save().Dispose();
|
||
}
|
||
}
|
||
}
|
||
}
|
||
if (!wasfirstchild)
|
||
{
|
||
this.MyPrevious = null;
|
||
this.Save();
|
||
}
|
||
if (origNextItem != null) origNextItem.Dispose();
|
||
if (parentInfo != null)
|
||
parentInfo.MyContent.RefreshContentParts();
|
||
if (parentInfoDV != null)
|
||
parentInfoDV.ResetProcedures();
|
||
}
|
||
|
||
}
|
||
protected static int MakeNewItem(IVEDrillDownReadOnly parentInfoDD, ItemInfo previousInfo, string number, string title, int type, E_FromType partType)
|
||
{
|
||
int newitemid = 0;
|
||
if (parentInfoDD == null)
|
||
parentInfoDD = previousInfo.ActiveParent;
|
||
ItemInfo parentInfo = parentInfoDD as ItemInfo;
|
||
DocVersionInfo parentInfoDV = parentInfoDD as DocVersionInfo;
|
||
using (Content cont = Content.New(number, title, type, null, null))
|
||
{
|
||
using (Item fromitem = previousInfo == null ? null : previousInfo.Get())
|
||
{
|
||
ItemInfo nextInfo = null; // Check to see if the item is being inserted in the middle of some items.
|
||
if (previousInfo != null && previousInfo.NextItems != null && previousInfo.NextItems.Count > 0)
|
||
nextInfo = previousInfo.NextItems[0];
|
||
using (Item itm = Item.MakeItem(fromitem, cont))
|
||
{
|
||
newitemid = itm.ItemID;
|
||
if (nextInfo != null)
|
||
{
|
||
using (Item nextItem = nextInfo.Get())
|
||
{
|
||
nextItem.MyPrevious = itm;// Aim the next item back at the new item.
|
||
nextItem.Save().Dispose();
|
||
}
|
||
}
|
||
if (fromitem == null)
|
||
{
|
||
if (parentInfo != null) // Adding Item to Procedure, Section or Step
|
||
{
|
||
using (Item parentItem = parentInfo.Get())
|
||
{
|
||
ItemInfo firstinfo = parentInfo.FirstChild(partType);
|
||
if (firstinfo != null)
|
||
{
|
||
using (Item firstchild = firstinfo.Get())
|
||
{
|
||
parentItem.MyContent.ContentParts[(int)partType].MyItem = itm;// First update the parent to point to the new first child
|
||
parentItem.Save().Dispose();
|
||
firstchild.MyPrevious = itm;// Aim the old first child to point to the new first child.
|
||
firstchild.Save().Dispose();
|
||
}
|
||
}
|
||
else
|
||
{
|
||
parentItem.MyContent.ContentParts.Add((int)partType, itm);// update the parent to point to the new first child
|
||
parentItem.Save().Dispose();
|
||
}
|
||
}
|
||
}
|
||
if (parentInfoDV != null) // Adding Item (Procedure) to DocVersion
|
||
{
|
||
using (DocVersion parentItemDV = parentInfoDV.Get())
|
||
{
|
||
ItemInfo firstinfo = parentInfoDV.FirstChild();
|
||
parentItemDV.MyItem = itm;// First update the parent to point to the new first child
|
||
parentItemDV.Save().Dispose();
|
||
if (firstinfo != null)
|
||
{
|
||
using (Item firstchild = firstinfo.Get())
|
||
{
|
||
firstchild.MyPrevious = itm;// Aim the old first child to point to the new first child.
|
||
firstchild.Save().Dispose();
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
}
|
||
}
|
||
}
|
||
}
|
||
if (parentInfo != null)
|
||
parentInfo.MyContent.RefreshContentParts();
|
||
if (parentInfoDV != null)
|
||
parentInfoDV.ResetProcedures();
|
||
return newitemid;
|
||
}
|
||
}
|
||
#endregion
|
||
#region ItemInfo
|
||
public partial class ItemInfo:IVEDrillDownReadOnly
|
||
{
|
||
public bool IsFirstSubStep
|
||
{
|
||
get
|
||
{
|
||
if (!IsStepPart) return false;
|
||
if (IsHigh) return false;
|
||
return (MyPrevious == null);
|
||
}
|
||
}
|
||
#region StepLevel
|
||
private int _StepLevel = -2;// Not yet calculated
|
||
public int StepLevel
|
||
{
|
||
get
|
||
{
|
||
if (_StepLevel == -2)
|
||
{
|
||
_StepLevel = CalcStepLevel(this);
|
||
//ItemInfo parent = ActiveParent as ItemInfo;
|
||
//Console.WriteLine("{0},{1},{2},{3},{4},{5},{6}",ItemID, DBSequence, _StepLevel, MyContent.Type % 10000, parent.MyContent.Type % 10000,HasCautionOrNote ? 1 : 0, parent.Cautions == null? 0 : 1);
|
||
}
|
||
return _StepLevel;
|
||
}
|
||
set { _StepLevel = value; }
|
||
}
|
||
public string ToolTip
|
||
{
|
||
get
|
||
{
|
||
if (IsStep)
|
||
return FormatStepData.Type;
|
||
else if (IsSection)
|
||
return MyDocStyle.Name;
|
||
return "Procedure Title";
|
||
}
|
||
}
|
||
public bool HasCautionOrNote
|
||
{
|
||
get { return Cautions != null || Notes != null; }
|
||
}
|
||
private static Regex regexDBSeqPass1 = new Regex("([^.]*)[.]S([^.]*)[.]S([0-9]*)[.](.*)");
|
||
private static Regex regexDBSeqPass2 = new Regex("[.](.)([^.]*)[.]");
|
||
public string DBSequence
|
||
{
|
||
get
|
||
{
|
||
Match m1 = regexDBSeqPass1.Match(ShortPath);
|
||
MatchCollection m2s = regexDBSeqPass2.Matches(m1.Groups[4].Value);
|
||
StringBuilder retval = new StringBuilder(string.Format("'{0}','{1}',{2},'", m1.Groups[1].Value, m1.Groups[2].Value, m1.Groups[3].Value));
|
||
string prefix = "S";
|
||
string suffix = "";
|
||
foreach (Match m2 in m2s)
|
||
{
|
||
int i = ((int) '0') + int.Parse(m2.Groups[2].Value);
|
||
char c = (char)i;
|
||
suffix = c.ToString();
|
||
switch (m2.Groups[1].Value)
|
||
{
|
||
case "S":
|
||
break;
|
||
case "R":
|
||
prefix += "$";
|
||
suffix = "";
|
||
break;
|
||
case "C":
|
||
prefix = "!";
|
||
break;
|
||
case "N":
|
||
prefix = "*";
|
||
break;
|
||
case "T":
|
||
prefix += "#";
|
||
suffix = "";
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
retval.Append(prefix + suffix);
|
||
prefix = "";
|
||
}
|
||
retval.Append(prefix + "'");
|
||
return retval.ToString();
|
||
}
|
||
}
|
||
private static int CalcStepLevel(ItemInfo item)
|
||
{
|
||
if(item == null) return 0;
|
||
int id=0;
|
||
// Determines the substep level.
|
||
int level = CountLevels(item);
|
||
|
||
// PaginateOnFirstSubstep allows orphans, first child can be separated from its parent.
|
||
int firstInc = item.ActiveFormat.MyStepSectionLayoutData.PaginateOnFirstSubstep ? 0 : 1;
|
||
ItemInfo parent = item.ActiveParent as ItemInfo;
|
||
|
||
// TODO: Format flag 'TreatAsSequential':
|
||
// The following needs to account for use of format flag 'TreatAsSequential' when doing
|
||
// formats that have it.
|
||
if (item.IsExactType("And") || item.IsExactType("Or") || item.IsExactType("ImplicitOr"))
|
||
level++;
|
||
if (parent != null && (parent.IsExactType("And") || parent.IsExactType("Or")))
|
||
level++;
|
||
|
||
// First substep, this is where it uses the orphan logic from above.
|
||
if (!item.IsRNOPart && !item.IsHigh && item.MyPrevious == null)
|
||
level += firstInc;
|
||
else
|
||
firstInc = 0;
|
||
|
||
// Try not to paginate on a step that has Cautions & Notes, keep the Caution/Note with
|
||
// the step.
|
||
if (item.IsStepPart)
|
||
{
|
||
if (item.Cautions != null || item.Notes != null)
|
||
level += 2;
|
||
}
|
||
// Paginate before first caution, not between cautions.
|
||
else if (item.IsCautionPart)
|
||
{
|
||
if (item.MyPrevious == null) level-=(1 + firstInc);
|
||
else level++;
|
||
}
|
||
// Paginate before first note, if the step does not have a caution.
|
||
// Otherwise, try to keep the notes together.
|
||
else if (item.IsNotePart)
|
||
{
|
||
if (parent.Cautions == null && item.MyPrevious == null) level-=(1 + firstInc);
|
||
else level++;
|
||
}
|
||
// Try not to paginate on a table.
|
||
else if (item.IsTablePart)
|
||
{
|
||
level += 2;
|
||
}
|
||
// For an RNO to the right, make it the same level as the AER item.
|
||
else if(item.IsRNOPart)
|
||
{
|
||
level = (item.ActiveParent as ItemInfo).StepLevel + item.RNOLevel - item.ColumnMode;
|
||
}
|
||
return level;
|
||
}
|
||
|
||
/// <summary>
|
||
/// Count all levels, including substeps within RNOs. Ignore RNOs that are to the right of
|
||
/// the AER, but count those that are below higher level RNOs.
|
||
/// </summary>
|
||
/// <param name="item"></param>
|
||
/// <returns></returns>
|
||
private static int CountLevels(ItemInfo item)
|
||
{
|
||
int level = 0;
|
||
int ignoreRNOs = item.ActiveSection.ColumnMode;
|
||
while (item != null && !item.IsHigh)
|
||
{
|
||
if (ignoreRNOs > 0 && item.IsRNOPart)
|
||
ignoreRNOs--;
|
||
else
|
||
level++;
|
||
item = item.ActiveParent as ItemInfo;
|
||
}
|
||
return level;
|
||
}
|
||
#endregion
|
||
public bool HasHeader
|
||
{
|
||
get
|
||
{
|
||
if (MyHeader==null)return false;
|
||
if (MyHeader.CleanText==null) return false;
|
||
if (MyHeader.CleanText=="") return false;
|
||
return true;
|
||
}
|
||
}
|
||
protected void ExtensionRefreshFields(Item tmp)
|
||
{
|
||
_ActiveParent = null;
|
||
}
|
||
#region LoadAtOnce2
|
||
public static ItemInfo GetItemAndChildren2(int? itemID)
|
||
{
|
||
try
|
||
{
|
||
ItemInfo tmp = DataPortal.Fetch<ItemInfo>(new ItemAndChildrenCriteria2(itemID));
|
||
AddToCache(tmp);
|
||
if (tmp.ErrorMessage == "No Record Found") tmp = null;
|
||
return tmp;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
throw new DbCslaException("Error on ItemInfoList.GetItemAndChildren2", ex);
|
||
}
|
||
}
|
||
// Criteria to get Item and children
|
||
[Serializable()]
|
||
private class ItemAndChildrenCriteria2
|
||
{
|
||
public ItemAndChildrenCriteria2(int? itemID)
|
||
{
|
||
_ItemID = itemID;
|
||
}
|
||
private int? _ItemID;
|
||
public int? ItemID
|
||
{
|
||
get { return _ItemID; }
|
||
set { _ItemID = value; }
|
||
}
|
||
}
|
||
// Data Portal to Get Item and Children
|
||
private void DataPortal_Fetch(ItemAndChildrenCriteria2 criteria)
|
||
{
|
||
try
|
||
{
|
||
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
|
||
{
|
||
ApplicationContext.LocalContext["cn"] = cn;
|
||
using (SqlCommand cm = cn.CreateCommand())
|
||
{
|
||
cm.CommandType = CommandType.StoredProcedure;
|
||
cm.CommandText = "getItem";
|
||
cm.Parameters.AddWithValue("@ItemID", criteria.ItemID);
|
||
using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader()))
|
||
{
|
||
if (!dr.Read())
|
||
{
|
||
_ErrorMessage = "No Record Found";
|
||
return;
|
||
}
|
||
ReadData(dr);
|
||
}
|
||
}
|
||
SpinThroughChildren();
|
||
// removing of item only needed for local data portal
|
||
if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client)
|
||
ApplicationContext.LocalContext.Remove("cn");
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
Database.LogException("ItemInfoList.DataPortal_Fetch", ex);
|
||
throw new DbCslaException("ItemInfoList.DataPortal_Fetch", ex);
|
||
}
|
||
RemoveFromCache(this);
|
||
}
|
||
private void SpinThroughChildren()
|
||
{
|
||
if(MyContent.ContentPartCount > 0)
|
||
foreach(PartInfo partInfo in MyContent.ContentParts)
|
||
foreach (ItemInfo itemInfo in partInfo.MyItems)
|
||
itemInfo.SpinThroughChildren();
|
||
}
|
||
#endregion
|
||
#region LoadAtOnce
|
||
// Method to Get Item and children
|
||
public static ItemInfo GetItemAndChildren(int? itemID,int? parentID)
|
||
{
|
||
try
|
||
{
|
||
ItemInfo tmp = DataPortal.Fetch<ItemInfo>(new ItemAndChildrenCriteria(itemID,parentID));
|
||
AddToCache(tmp);
|
||
if (tmp.ErrorMessage == "No Record Found") tmp = null;
|
||
return tmp;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
throw new DbCslaException("Error on ItemInfoList.GetChildren", ex);
|
||
}
|
||
}
|
||
// Criteria to get Item and children
|
||
[Serializable()]
|
||
private class ItemAndChildrenCriteria
|
||
{
|
||
public ItemAndChildrenCriteria(int? itemID, int? parentID)
|
||
{
|
||
_ItemID = itemID;
|
||
_ParentID = parentID;
|
||
}
|
||
private int? _ItemID;
|
||
public int? ItemID
|
||
{
|
||
get { return _ItemID; }
|
||
set { _ItemID = value; }
|
||
}
|
||
private int? _ParentID;
|
||
public int? ParentID
|
||
{
|
||
get { return _ParentID; }
|
||
set { _ParentID = value; }
|
||
}
|
||
}
|
||
// Data Portal to Get Item and Children
|
||
private void DataPortal_Fetch(ItemAndChildrenCriteria criteria)
|
||
{
|
||
//ItemInfo tmp = null;
|
||
Dictionary<int, ItemInfo> lookup = new Dictionary<int, ItemInfo>(); ;
|
||
try
|
||
{
|
||
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
|
||
{
|
||
using (SqlCommand cm = cn.CreateCommand())
|
||
{
|
||
cm.CommandType = CommandType.StoredProcedure;
|
||
cm.CommandText = "vesp_ListItemAndChildren";
|
||
cm.Parameters.AddWithValue("@ItemID", criteria.ItemID);
|
||
cm.Parameters.AddWithValue("@ParentID", criteria.ParentID);
|
||
using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader()))
|
||
{
|
||
while (dr.Read())
|
||
{
|
||
if (dr.GetInt32("Level")==0)
|
||
{
|
||
//tmp = itemInfo;
|
||
ReadData(dr);
|
||
AddContent(dr);
|
||
lookup[this.ItemID] = this;
|
||
}
|
||
else
|
||
{
|
||
ItemInfo itemInfo = null;
|
||
int itemType = dr.GetInt32("Type") / 10000;
|
||
switch (itemType)
|
||
{
|
||
case 0:
|
||
itemInfo = new ProcedureInfo(dr);
|
||
break;
|
||
case 1:
|
||
itemInfo = new SectionInfo(dr);
|
||
break;
|
||
case 2:
|
||
itemInfo = new StepInfo(dr);
|
||
break;
|
||
}
|
||
// Load Children
|
||
itemInfo.AddContent(dr);
|
||
ItemInfo parent = lookup[dr.GetInt32("ParentID")];
|
||
itemInfo._ActiveParent = parent;
|
||
itemInfo._ActiveSection = (itemInfo.IsSection ? itemInfo : parent._ActiveSection);
|
||
parent.AddPart(dr, itemInfo);
|
||
lookup.Add(itemInfo.ItemID, itemInfo);
|
||
}
|
||
}
|
||
//Console.WriteLine("I'm here {0}",this.MyContent.ContentPartCount);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
Database.LogException("ItemInfoList.DataPortal_Fetch", ex);
|
||
throw new DbCslaException("ItemInfoList.DataPortal_Fetch", ex);
|
||
}
|
||
}
|
||
private void AddPart(SafeDataReader dr, ItemInfo itemInfo)
|
||
{
|
||
// Either a new PartInfo or an existing PartInfo
|
||
if (dr.IsDBNull(dr.GetOrdinal("PreviousID")))
|
||
{
|
||
//PartInfo prt = new PartInfo(dr, itemInfo);
|
||
_MyContent.AddPart(dr, itemInfo);
|
||
}
|
||
else
|
||
{
|
||
foreach (PartInfo pi in MyContent.ContentParts)
|
||
{
|
||
if (dr.GetInt32("FromType") == (int)pi.PartType)
|
||
{
|
||
if (pi._MyItems == null)
|
||
pi._MyItems = new ItemInfoList(itemInfo);
|
||
else
|
||
pi.MyItems.AddItem(itemInfo);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
#endregion
|
||
#region IsType
|
||
public bool IsFirstCautionPart
|
||
{
|
||
get
|
||
{
|
||
return ((ItemPartCount > 0) && (ItemParts[0].PartType == E_FromType.Caution));
|
||
}
|
||
}
|
||
public bool IsFirstNotePart
|
||
{
|
||
get
|
||
{
|
||
return ((ItemPartCount > 0) && (ItemParts[0].PartType == E_FromType.Note));
|
||
}
|
||
}
|
||
|
||
public bool IsCautionPart
|
||
{
|
||
get
|
||
{
|
||
return ((FirstSibling.ItemPartCount > 0) && (FirstSibling.ItemParts[0].PartType == E_FromType.Caution));
|
||
}
|
||
}
|
||
public bool IsNotePart
|
||
{
|
||
get
|
||
{
|
||
return ((FirstSibling.ItemPartCount > 0) && (FirstSibling.ItemParts[0].PartType == E_FromType.Note));
|
||
}
|
||
}
|
||
|
||
public bool IsType(string type)
|
||
{
|
||
if ((int)MyContent.Type < 20000) return false;
|
||
int stepType = ((int)MyContent.Type) % 10000;
|
||
StepDataList sdlist = ActiveFormat.PlantFormat.FormatData.StepDataList;
|
||
if (stepType > sdlist.Count)
|
||
{
|
||
Console.WriteLine("Error getting type - contentid = {0}", MyContent.ContentID);
|
||
return false;
|
||
}
|
||
StepData sd = sdlist[stepType];
|
||
while (sd.Index != 0)
|
||
{
|
||
if (sd.Type == type) return true;
|
||
sd = sdlist[sd.ParentType];
|
||
}
|
||
return false;
|
||
}
|
||
public bool IsExactType(string type)
|
||
{
|
||
if ((int)MyContent.Type < 20000) return false;
|
||
int stepType = ((int)MyContent.Type) % 10000;
|
||
StepDataList sdlist = ActiveFormat.PlantFormat.FormatData.StepDataList;
|
||
if (stepType > sdlist.Count)
|
||
{
|
||
Console.WriteLine("Error getting type - contentid = {0}", MyContent.ContentID);
|
||
return false;
|
||
}
|
||
StepData sd = sdlist[stepType];
|
||
return (sd.Type == type);
|
||
}
|
||
public bool IsCaution
|
||
{
|
||
get
|
||
{
|
||
return IsType("Caution");
|
||
}
|
||
}
|
||
public bool IsNote
|
||
{
|
||
get
|
||
{
|
||
return IsType("Note");
|
||
}
|
||
}
|
||
public bool IsTable
|
||
{
|
||
get
|
||
{
|
||
return IsType("Table");
|
||
}
|
||
}
|
||
public bool IsFigure
|
||
{
|
||
get
|
||
{
|
||
return IsType("Figure");
|
||
}
|
||
}
|
||
public bool IsOr
|
||
{
|
||
get
|
||
{
|
||
return IsType("Or");
|
||
}
|
||
}
|
||
public bool IsAnd
|
||
{
|
||
get
|
||
{
|
||
return IsType("And");
|
||
}
|
||
}
|
||
public bool IsEquipmentList
|
||
{
|
||
get
|
||
{
|
||
return IsType("EquipmentList");
|
||
}
|
||
}
|
||
public bool IsTitle
|
||
{
|
||
get
|
||
{
|
||
return IsType("Title");
|
||
}
|
||
}
|
||
public bool IsAccPages
|
||
{
|
||
get
|
||
{
|
||
return IsType("AccPages");
|
||
}
|
||
}
|
||
public bool IsParagraph
|
||
{
|
||
get
|
||
{
|
||
return IsType("Paragraph");
|
||
}
|
||
}
|
||
public bool IsDefault
|
||
{
|
||
get
|
||
{
|
||
return IsType("Default");
|
||
}
|
||
}
|
||
public bool IsContAcSequential
|
||
{
|
||
get
|
||
{
|
||
return IsType("ContAcSequential");
|
||
}
|
||
}
|
||
public bool IsHigh
|
||
{
|
||
get
|
||
{
|
||
// check to see if ActiveParent is a section, if so it is a high level step
|
||
if (MyContent.Type / 10000 != 2) return false;
|
||
ItemInfo parent = ActiveParent as ItemInfo;
|
||
if (parent == null) return false;
|
||
if ((parent.MyContent.Type / 10000) == 1)
|
||
return true;
|
||
return false;
|
||
}
|
||
}
|
||
public bool IsSequential
|
||
{
|
||
get
|
||
{
|
||
if (((MyContent.Type / 10000) == 2) && ((((int)MyContent.Type) % 10000) == 1)) return true;
|
||
return false;
|
||
}
|
||
}
|
||
public bool IsTablePart
|
||
{
|
||
get
|
||
{
|
||
return ((ItemPartCount > 0) && (ItemParts[0].PartType == E_FromType.Table));
|
||
}
|
||
}
|
||
public bool IsRNOPart
|
||
{
|
||
get
|
||
{
|
||
return ((ItemPartCount > 0) && (ItemParts[0].PartType == E_FromType.RNO));
|
||
}
|
||
}
|
||
public bool IsInRNO
|
||
{
|
||
get
|
||
{
|
||
if (IsHigh) return false;
|
||
if (IsRNOPart) return true;
|
||
ItemInfo parent = ActiveParent as ItemInfo;
|
||
if (parent == null) return false;
|
||
return parent.IsInRNO;
|
||
}
|
||
}
|
||
#endregion
|
||
#region Level Columns Relationships
|
||
public int RNOLevel
|
||
{
|
||
get
|
||
{
|
||
return ((IsProcedure || IsSection || IsHigh)?0:(IsRNOPart?1:0)+((ItemInfo)ActiveParent).RNOLevel);
|
||
}
|
||
}
|
||
public int ColumnMode
|
||
{
|
||
get
|
||
{
|
||
// check config value on my section, if null/default use Pmode of active format
|
||
SectionInfo si = SectionInfo.Get(ActiveSection.ItemID); //ActiveSection as SectionInfo;
|
||
if (si != null)
|
||
{
|
||
// there is no longer a "default" ENUM item - SectionConfig will return format default if needed
|
||
//if (si.SectionConfig.Section_ColumnMode != SectionConfig.SectionColumnMode.Default)
|
||
return (int)si.SectionConfig.Section_ColumnMode - 1;
|
||
}
|
||
return (ActiveFormat.MyStepSectionLayoutData.PMode ?? 2) -1;
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// FormatStepType - Maps to step type in format file. All types map directly from step type in content
|
||
/// to step type in format
|
||
/// </summary>
|
||
public int FormatStepType
|
||
{
|
||
get
|
||
{
|
||
return (((int)MyContent.Type) % 10000);
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// returns the format's stepdata for the given content type.
|
||
/// </summary>
|
||
public StepData FormatStepData
|
||
{
|
||
get
|
||
{
|
||
int typ = (int)MyContent.Type - 20000;
|
||
foreach (StepData sd in ActiveFormat.PlantFormat.FormatData.StepDataList)
|
||
{
|
||
if (sd.Index == typ) return sd;
|
||
}
|
||
return null;
|
||
}
|
||
}
|
||
public ItemInfo FirstSibling
|
||
{
|
||
get
|
||
{
|
||
ItemInfo temp = this;
|
||
while (temp.MyPrevious != null) temp = temp.MyPrevious;
|
||
return temp;
|
||
}
|
||
}
|
||
public ItemInfo LastSibling
|
||
{
|
||
get
|
||
{
|
||
ItemInfo temp = this;
|
||
while (temp.NextItems != null) temp = temp.NextItems[0];
|
||
return temp;
|
||
}
|
||
}
|
||
public ItemInfo LastChild(E_FromType partType)
|
||
{
|
||
ItemInfoList myitems = Lookup((int)partType);
|
||
if (myitems !=null) return myitems[myitems.Count-1];
|
||
return null;
|
||
}
|
||
public ItemInfo FirstChild(E_FromType partType)
|
||
{
|
||
ItemInfoList myitems = Lookup((int)partType);
|
||
if (myitems != null) return myitems[0];
|
||
return null;
|
||
}
|
||
#endregion
|
||
#region More IsType
|
||
public bool IsProcedurePart
|
||
{
|
||
get
|
||
{
|
||
return ((FirstSibling.ItemPartCount > 0) && (FirstSibling.ItemParts[0].PartType == E_FromType.Procedure));
|
||
}
|
||
}
|
||
public bool IsSectionPart
|
||
{
|
||
get
|
||
{
|
||
return ((FirstSibling.ItemPartCount > 0) && (FirstSibling.ItemParts[0].PartType == E_FromType.Section));
|
||
}
|
||
}
|
||
public bool IsStepPart
|
||
{
|
||
get
|
||
{
|
||
return ((FirstSibling.ItemPartCount > 0) && (FirstSibling.ItemParts[0].PartType == E_FromType.Step));
|
||
}
|
||
}
|
||
public bool IsInSubStep
|
||
{
|
||
get
|
||
{
|
||
if (IsHigh) return false;
|
||
if (IsStepPart) return true;
|
||
ItemInfo parent = ActiveParent as ItemInfo;
|
||
if (parent == null) return false;
|
||
return parent.IsInSubStep;
|
||
}
|
||
}
|
||
public bool IsInFirstLevelSubStep
|
||
{
|
||
get
|
||
{
|
||
ItemInfo temp = FirstSibling;
|
||
if(temp.ActiveParent.GetType() == typeof(VEPROMS.CSLA.Library.DocVersionInfo))return false;
|
||
if (temp.MyParent.IsSection) return false; // already at hls
|
||
while (((ItemInfo)temp.ActiveParent).IsHigh == false) temp = ((ItemInfo)temp.ActiveParent).FirstSibling;
|
||
return temp.IsStepPart;
|
||
}
|
||
}
|
||
public bool IsStepSection
|
||
{
|
||
get
|
||
{
|
||
if (IsSection && MyDocStyle.IsStepSection) return true;
|
||
return false;
|
||
}
|
||
}
|
||
public bool IsSection
|
||
{
|
||
get
|
||
{
|
||
if ((MyContent.Type / 10000) == 1) return true;
|
||
return false;
|
||
}
|
||
}
|
||
public bool IsDefaultSection
|
||
{
|
||
get
|
||
{
|
||
// check to see if ActiveParent is a section, if so it is a high level step
|
||
if (MyContent.Type / 10000 != 1) return false;
|
||
// get procedure section and then
|
||
ItemInfo parent = (ItemInfo)ActiveParent;
|
||
if (!parent.IsProcedure) return false;
|
||
ProcedureConfig pc = (ProcedureConfig)parent.MyConfig;
|
||
int sectstartid = -1;
|
||
string ss = pc == null ? null : pc.SectionStart;
|
||
if (ss != null) sectstartid = System.Convert.ToInt32(ss);
|
||
else return false;
|
||
if (ItemID == sectstartid) return true;
|
||
return false;
|
||
}
|
||
}
|
||
public bool IsProcedure
|
||
{
|
||
get
|
||
{
|
||
if ((MyContent.Type / 10000) == 0) return true;
|
||
return false;
|
||
}
|
||
}
|
||
public bool IsStep
|
||
{
|
||
get
|
||
{
|
||
if ((MyContent.Type / 10000) == 2) return true;
|
||
return false;
|
||
}
|
||
}
|
||
private E_FromType ItemType
|
||
{
|
||
get
|
||
{
|
||
if (MyContent.Type == 0) return E_FromType.Procedure;
|
||
if (MyContent.Type < 20000) return E_FromType.Section;
|
||
return E_FromType.Step;
|
||
}
|
||
}
|
||
public Item GetByType()
|
||
{
|
||
Item tmp = null;
|
||
switch (ItemType)
|
||
{
|
||
case E_FromType.Procedure:
|
||
tmp = Procedure.Get(_ItemID);
|
||
break;
|
||
//case E_FromType.Section:
|
||
// itemInfo = new Section(dr);
|
||
// break;
|
||
//default:
|
||
// itemInfo = new Step(dr);
|
||
// break;
|
||
}
|
||
return tmp;
|
||
}
|
||
#endregion
|
||
#region Ordinal CslaType and Tostring
|
||
[NonSerialized]
|
||
private int? _Ordinal;
|
||
public int Ordinal
|
||
{
|
||
get
|
||
{
|
||
if (_Ordinal == null)
|
||
{
|
||
if (MyPrevious != null)
|
||
_Ordinal = MyPrevious.Ordinal + 1;
|
||
else
|
||
_Ordinal = 1;
|
||
}
|
||
return (int) _Ordinal;
|
||
}
|
||
}
|
||
public string CslaType
|
||
{ get { return this.GetType().FullName; } }
|
||
public override string ToString()
|
||
{
|
||
//Item editable = Item.GetExistingByPrimaryKey(_ItemID);
|
||
//return string.Format("{0}{1} {2}", (editable == null ? "" : (editable.IsDirty ? "* " : "")),
|
||
// (MyContent.Type >= 20000 ? Ordinal.ToString() + "." : MyContent.Number), MyContent.Text);
|
||
ContentInfo cont = MyContent;
|
||
//string number = cont.Number;
|
||
string number = DisplayNumber;
|
||
//if (cont.Type >= 20000) number = Ordinal.ToString() + ".";
|
||
if (cont.Type >= 20000) number = MyTab.CleanText;
|
||
return string.Format("{0} {1}", number, DisplayText).Trim();
|
||
//return string.Format("{0} {1}", number, cont.Text).Trim();
|
||
//return string.Format("{0} {1}", cont.Number, cont.Text);
|
||
//return "Now is the time for all good men to come to the aid of their country!";
|
||
}
|
||
//public string ToString(string str,System.IFormatProvider ifp)
|
||
//{
|
||
// return ToString();
|
||
//}
|
||
#endregion
|
||
#region Search
|
||
internal string _SearchDVPath;
|
||
public string SearchDVPath
|
||
{
|
||
get { return _SearchDVPath; }
|
||
}
|
||
internal string _SearchPath;
|
||
public string SearchPath
|
||
{
|
||
get { return _SearchPath; }
|
||
}
|
||
public string ShortSearchPath
|
||
{
|
||
get { return ConvertToDisplayText(Regex.Replace(_SearchPath, "\x11.*?\x07", "\x07")); }
|
||
}
|
||
internal int _SearchAnnotationID;
|
||
public int SearchAnnotationID
|
||
{
|
||
get { return _SearchAnnotationID; }
|
||
}
|
||
internal string _SearchAnnotationText;
|
||
public string SearchAnnotationText
|
||
{
|
||
get { return _SearchAnnotationText; }
|
||
}
|
||
internal string _SearchAnnotationType;
|
||
public string SearchAnnotationType
|
||
{
|
||
get { return _SearchAnnotationType; }
|
||
}
|
||
#endregion
|
||
#region ProcedureConfig
|
||
[NonSerialized]
|
||
private ProcedureConfig _ProcedureConfig = null;
|
||
public PrintChangeBar PrintChangeBar
|
||
{
|
||
get
|
||
{
|
||
if (_ProcedureConfig == null) SetProcedureConfig();
|
||
return _ProcedureConfig.Print_ChangeBar;
|
||
}
|
||
}
|
||
public PrintChangeBarLoc PrintChangeBarLoc
|
||
{
|
||
get
|
||
{
|
||
if (_ProcedureConfig == null) SetProcedureConfig();
|
||
return _ProcedureConfig.Print_ChangeBarLoc;
|
||
}
|
||
}
|
||
public PrintChangeBarText PrintChangeBarText
|
||
{
|
||
get
|
||
{
|
||
if (_ProcedureConfig == null) SetProcedureConfig();
|
||
return _ProcedureConfig.Print_ChangeBarText;
|
||
}
|
||
}
|
||
public string PrintChangeBarUsrMsg1
|
||
{
|
||
get
|
||
{
|
||
if (_ProcedureConfig == null) SetProcedureConfig();
|
||
return _ProcedureConfig.Print_UserCBMess1;
|
||
}
|
||
}
|
||
public string PrintChangeBarUsrMsg2
|
||
{
|
||
get
|
||
{
|
||
if (_ProcedureConfig == null) SetProcedureConfig();
|
||
return _ProcedureConfig.Print_UserCBMess2;
|
||
}
|
||
}
|
||
private void SetProcedureConfig()
|
||
{
|
||
// Walk up tree until find my procedure. Then get its change bar (default will
|
||
// get inherited information if not set at this level).
|
||
// Find the procedure level and its config.
|
||
ItemInfo tmpitm = this;
|
||
while (tmpitm.MyContent.Type != 0)
|
||
tmpitm = tmpitm.MyParent;
|
||
|
||
ProcedureInfo pi = ProcedureInfo.Get(tmpitm.ItemID);
|
||
if (pi == null) return;
|
||
_ProcedureConfig = pi.MyConfig as ProcedureConfig;
|
||
}
|
||
#endregion
|
||
#region Formatting of Text
|
||
public string DisplayText
|
||
{
|
||
get { return ConvertToDisplayText(MyContent.Text); }
|
||
}
|
||
public string DisplayNumber
|
||
{
|
||
get { return ConvertToDisplayText(MyContent.Number); }
|
||
}
|
||
public static string ConvertToDisplayText(string txt)
|
||
{
|
||
string retval = txt;
|
||
retval = StripRtfFormatting(retval);
|
||
retval = StripLinks(retval);
|
||
retval = ReplaceSpecialCharacters(retval);
|
||
retval = retval.Replace("\u2011","-");
|
||
return retval;
|
||
}
|
||
private static string StripRtfFormatting(string rtf)
|
||
{
|
||
string retval = rtf;
|
||
retval = Regex.Replace(retval, @"\\b0 ?", "");
|
||
retval = Regex.Replace(retval, @"\\b ?", "");
|
||
retval = Regex.Replace(retval, @"\\ulnone ?", "");
|
||
retval = Regex.Replace(retval, @"\\ul0 ?", "");
|
||
retval = Regex.Replace(retval, @"\\ul ?", "");
|
||
retval = Regex.Replace(retval, @"\\i0 ?", "");
|
||
retval = Regex.Replace(retval, @"\\i ?", "");
|
||
//retval = Regex.Replace(retval, @"\\super ?", "");
|
||
//retval = Regex.Replace(retval, @"\\sub ?", "");
|
||
//retval = Regex.Replace(retval, @"\\nosupersub ?", "");
|
||
retval = Regex.Replace(retval, @"\\up[30] ?", "");
|
||
retval = Regex.Replace(retval, @"\\dn[30] ?", "");
|
||
return retval;
|
||
}
|
||
private static string StripLinks(string rtf)
|
||
{
|
||
string retval = rtf;
|
||
retval = Regex.Replace(retval, @"\\v.*?\\v0", "");
|
||
retval = retval.Replace("\u252C", "");// Unicode 9516 Transition
|
||
retval = retval.Replace("\u2566", "");// Unicode 9574 Transition
|
||
retval = retval.Replace("\u0015", "");// Unicode 21 RO
|
||
return retval;
|
||
}
|
||
private static string ReplaceSpecialCharacter(Match m)
|
||
{
|
||
StringBuilder sb = new StringBuilder();
|
||
int i = int.Parse(m.ToString().Substring(2,m.ToString().Length-3));
|
||
sb.Append((char)i);
|
||
return sb.ToString();
|
||
}
|
||
private static string ReplaceSpecialHexCharacter(Match m)
|
||
{
|
||
StringBuilder sb = new StringBuilder();
|
||
int i = int.Parse(m.ToString().Substring(2), System.Globalization.NumberStyles.HexNumber);
|
||
sb.Append((char)i);
|
||
return sb.ToString();
|
||
}
|
||
private static string ReplaceSpecialCharacters(string rtf)
|
||
{
|
||
string retval = rtf;
|
||
retval = retval.Replace("`", "\u00BA");// Degree
|
||
retval = Regex.Replace(retval, @"\\u[0-9]+[?]", new MatchEvaluator(ReplaceSpecialCharacter));
|
||
retval = Regex.Replace(retval, @"\\'[0-9A-Fa-f][0-9A-Fa-f]", new MatchEvaluator(ReplaceSpecialHexCharacter));
|
||
return retval;
|
||
}
|
||
|
||
public VE_Font GetItemFont()
|
||
{
|
||
return GetItemFont(ActiveFormat);
|
||
}
|
||
|
||
public VE_Font GetItemFont(FormatInfo fmt)
|
||
{
|
||
VE_Font font = null;
|
||
try
|
||
{
|
||
FormatInfo format = (LocalFormat != null || fmt == null) ? LocalFormat : fmt;//_MyItemInfo.ActiveFormat;
|
||
int type = (int)MyContent.Type;//_MyItemInfo.MyContent.Type;
|
||
switch (type / 10000)
|
||
{
|
||
case 0: // procedure
|
||
font = format.PlantFormat.FormatData.Font;
|
||
break;
|
||
case 1: // section
|
||
font = format.PlantFormat.FormatData.SectData.SectionHeader.Font;
|
||
break;
|
||
case 2: // step types
|
||
int typindx = type - 20000; // what to do for other types rather than steps
|
||
font = format.PlantFormat.FormatData.StepDataList[typindx].Font;
|
||
if (typindx == _ParagraphType) font = AdjustForTextSubFollowsTextStyle(format,typindx,font);
|
||
break;
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
Console.WriteLine("GetItemFont(): {0} - {1}", ex.GetType(), ex.Message);
|
||
}
|
||
return font;
|
||
}
|
||
private const int _ParagraphType=24;
|
||
protected VE_Font AdjustForTextSubFollowsTextStyle(VE_Font font)
|
||
{
|
||
return AdjustForTextSubFollowsTextStyle(ActiveFormat, this.FormatStepType, font);
|
||
}
|
||
private VE_Font AdjustForTextSubFollowsTextStyle(FormatInfo format, int typindx, VE_Font font)
|
||
{
|
||
StepData myFormatStepData = format.PlantFormat.FormatData.StepDataList[typindx];
|
||
if (myFormatStepData.TextSubFollowsTextStyle && ParentNoteOrCaution != null)
|
||
{
|
||
bool isBold = (myFormatStepData.Font.Style & E_Style.Bold) > 0;
|
||
bool isMmBold = (myFormatStepData.Font.Style & E_Style.MmBold) > 0;
|
||
myFormatStepData = format.PlantFormat.FormatData.StepDataList[ParentNoteOrCaution.FormatStepType];
|
||
font = myFormatStepData.Font;
|
||
E_Style myStyle = (E_Style) font.Style;
|
||
myStyle ^= (myStyle & E_Style.Bold);
|
||
myStyle ^= (myStyle & E_Style.MmBold);
|
||
myStyle |= isBold ? E_Style.Bold : 0;
|
||
myStyle |= isMmBold ? E_Style.MmBold : 0;
|
||
if (myStyle != font.Style)
|
||
font = new VE_Font(font.Family, (int)font.Size, myStyle);
|
||
}
|
||
return font;
|
||
}
|
||
private string RemoveToken(string str, string token)
|
||
{
|
||
// if this token is preceeded by another token and followed by a space
|
||
// leave the preceeding token the ending space
|
||
string retval = Regex.Replace(str, @"(\\[^ \\?\r\n\t]*)" + token + " ", "$1 ");
|
||
if (retval != str)
|
||
Console.WriteLine("leave the preceeding token the ending space");
|
||
// otherwise replace the token optionally followed by a space
|
||
retval = Regex.Replace(retval, token + " ?", "");
|
||
return retval;
|
||
}
|
||
public string RemoveRtfStyles(string rtf)
|
||
{
|
||
return RemoveRtfStyles(rtf, ActiveFormat);
|
||
}
|
||
public string RemoveRtfStyles(string rtf, FormatInfo fmt)
|
||
{
|
||
string retval = rtf;
|
||
VE_Font TextFont = GetItemFont(fmt);
|
||
if (TextFont != null)
|
||
{
|
||
// remove rtf commands for any styles that were added. Note that if
|
||
// the entire item has a style, and also contains 'pieces' of text with
|
||
// the same style, the underlying rtf box removes the embedded rtf commands,
|
||
// for example, if the entire step is bolded, and 'THEN' has bold on/off
|
||
// surrounding it, the rtf box removes the bold around the 'THEN'
|
||
// These remove the command with a following space or the command alone,
|
||
// either case may exist, because if there are rtf commands following the
|
||
// style command, there will be no space character following the style command.
|
||
if (((TextFont.Style & E_Style.Bold) > 0) || ((TextFont.Style & E_Style.MmBold) > 0))
|
||
{
|
||
retval = RemoveToken(retval, @"\\b0");
|
||
retval = RemoveToken(retval, @"\\b");
|
||
}
|
||
if ((TextFont.Style & E_Style.Underline) > 0)
|
||
{
|
||
retval = RemoveToken(retval, @"\\ulnone");
|
||
retval = RemoveToken(retval, @"\\ul");
|
||
}
|
||
if ((TextFont.Style & E_Style.Italics) > 0)
|
||
{
|
||
retval = RemoveToken(retval, @"\\i0");
|
||
retval = RemoveToken(retval, @"\\i");
|
||
}
|
||
}
|
||
return retval;
|
||
}
|
||
#endregion
|
||
#region Path and Parent
|
||
public string Path
|
||
{
|
||
get
|
||
{
|
||
string number = (MyContent.Type >= 20000 ? Ordinal.ToString() + "." : ((DisplayNumber ?? "")==""? DisplayText: DisplayNumber));
|
||
ItemInfo parent = this;
|
||
while (parent.MyPrevious != null) parent = parent.MyPrevious;
|
||
if (parent.ItemPartCount == 0)
|
||
return number + ", " + DisplayText;
|
||
else
|
||
{
|
||
PartInfo partInfo = parent.ItemParts[0];
|
||
return partInfo.MyContent.ContentItems.Items[0].Path + " " + ((E_FromType)partInfo.FromType).ToString() + " " + number;
|
||
}
|
||
}
|
||
}
|
||
public string ShortPath
|
||
{
|
||
get
|
||
{
|
||
string number = (MyContent.Type >= 20000 ? Ordinal.ToString() + "." : ((DisplayNumber ?? "") == "" ? DisplayText : DisplayNumber));
|
||
ItemInfo parent = this;
|
||
while (parent.MyPrevious != null) parent = parent.MyPrevious;
|
||
if (parent.ItemPartCount == 0)
|
||
return number;
|
||
else
|
||
{
|
||
PartInfo partInfo = parent.ItemParts[0];
|
||
return partInfo.MyContent.ContentItems.Items[0].ShortPath + "." + ((E_FromType)partInfo.FromType).ToString().Substring(0,1) + number;
|
||
}
|
||
}
|
||
}
|
||
public ContentInfo ParentContent
|
||
{
|
||
get
|
||
{
|
||
string number = (MyContent.Type >= 20000 ? Ordinal.ToString() + "." : ((MyContent.Number ?? "") == "" ? MyContent.Text : MyContent.Number));
|
||
ItemInfo parent = this;
|
||
while (parent.MyPrevious != null) parent = parent.MyPrevious;
|
||
if (parent.ItemPartCount <= 0 || parent.ItemParts.Count == 0)
|
||
return null;
|
||
else
|
||
{
|
||
return parent.ItemParts[0].MyContent;
|
||
}
|
||
}
|
||
}
|
||
public ItemInfo MyParent
|
||
{
|
||
get
|
||
{
|
||
//if (ItemDocVersionCount > 0) return ItemDocVersions[0]; Need to create one interface to support Folders, DocVersions and Items
|
||
ContentInfo parentContent = ParentContent;
|
||
if (parentContent == null || parentContent.ContentItemCount == 0) return null;
|
||
return parentContent.ContentItems[0];
|
||
}
|
||
}
|
||
#endregion
|
||
#region Lookups and More Related
|
||
private ItemInfoList Lookup(int fromType, ref ItemInfoList itemInfoList)
|
||
{
|
||
if (itemInfoList == null)
|
||
itemInfoList = Lookup(fromType);
|
||
return itemInfoList;
|
||
}
|
||
internal ItemInfoList Lookup(int fromType)
|
||
{
|
||
ItemInfoList itemInfoList = null;
|
||
if (MyContent.ContentPartCount != 0)
|
||
foreach (PartInfo partInfo in MyContent.ContentParts)
|
||
if (partInfo.FromType == fromType)
|
||
{
|
||
itemInfoList = partInfo._MyItems = ItemInfoList.GetList(partInfo.ItemID, partInfo.FromType);
|
||
return itemInfoList;
|
||
}
|
||
return null;
|
||
}
|
||
public static void ResetParts(int itemID)
|
||
{
|
||
string key = itemID.ToString();
|
||
if (_CacheByPrimaryKey.ContainsKey(key))
|
||
{
|
||
bool firstContent = true;
|
||
foreach (ItemInfo itm in _CacheByPrimaryKey[key])
|
||
{
|
||
itm.ResetParts();
|
||
if (itm._MyContent != null && firstContent)
|
||
{
|
||
firstContent = false;// Only need to do this once.
|
||
//RefreshContentParts looks through ContentInfo objects
|
||
itm._MyContent.RefreshContentParts();
|
||
}
|
||
}
|
||
}
|
||
}
|
||
public void ResetParts()
|
||
{
|
||
_Procedures = null;
|
||
_Sections = null;
|
||
_Cautions = null;
|
||
_Notes = null;
|
||
_RNOs = null;
|
||
_Steps = null;
|
||
_Tables = null;
|
||
}
|
||
private ItemInfoList _Procedures;
|
||
public ItemInfoList Procedures
|
||
{ get { return Lookup(1,ref _Procedures); } }
|
||
private ItemInfoList _Sections;
|
||
public ItemInfoList Sections
|
||
{ get { return Lookup(2,ref _Sections); } }
|
||
private ItemInfoList _Cautions;
|
||
public ItemInfoList Cautions
|
||
{ get { return Lookup(3,ref _Cautions); } }
|
||
private ItemInfoList _Notes;
|
||
public ItemInfoList Notes
|
||
{ get { return Lookup(4,ref _Notes); } }
|
||
private ItemInfoList _RNOs;
|
||
public ItemInfoList RNOs
|
||
{ get { return Lookup(5,ref _RNOs); } }
|
||
private ItemInfoList _Steps;
|
||
public ItemInfoList Steps
|
||
{ get { return Lookup(6,ref _Steps); } }
|
||
private ItemInfoList _Tables;
|
||
public ItemInfoList Tables
|
||
{ get { return Lookup(7,ref _Tables); } }
|
||
//public void ResetChildren()
|
||
//{
|
||
// _Procedures = null;
|
||
// _Sections = null;
|
||
// _Steps = null;
|
||
// _Cautions = null;
|
||
// _Notes = null;
|
||
// _RNOs = null;
|
||
// _Steps = null;
|
||
// _Tables = null;
|
||
//}
|
||
//public XmlDocument ToXml()
|
||
//{
|
||
// XmlDocument retval = new XmlDocument();
|
||
// retval.LoadXml("<root/>");
|
||
// return ToXml(retval.DocumentElement);
|
||
//}
|
||
//public void AddList(XmlNode xn,string name, ItemInfoList itemInfoList)
|
||
//{
|
||
// if (itemInfoList != null)
|
||
// {
|
||
// XmlNode nd = xn.OwnerDocument.CreateElement(name);
|
||
// xn.AppendChild(nd);
|
||
// itemInfoList.ToXml(xn);
|
||
// }
|
||
//}
|
||
//public XmlDocument ToXml(XmlNode xn)
|
||
//{
|
||
// XmlNode nd = MyContent.ToXml(xn);
|
||
// // Now add the children
|
||
// AddList(nd, "Procedures", Procedures);
|
||
// AddList(nd, "Sections", Sections);
|
||
// AddList(nd, "Cautions", Cautions);
|
||
// AddList(nd, "Notes", Notes);
|
||
// AddList(nd, "RNOs", RNOs);
|
||
// AddList(nd, "Steps", SubItems);
|
||
// AddList(nd, "Tables", Tables);
|
||
// return xn.OwnerDocument;
|
||
//}
|
||
#endregion
|
||
#region UI Tab
|
||
public string TabToolTip
|
||
{
|
||
get
|
||
{
|
||
if (MyContent.MyEntry == null)
|
||
return DisplayNumber + " - " + DisplayText;
|
||
string toolTip = MyProcedure.TabToolTip + "\r\n";
|
||
if (MyContent.Number != "")
|
||
toolTip += DisplayNumber + " - " + DisplayText;
|
||
else
|
||
toolTip += DisplayText;
|
||
DocumentInfo myDocument = MyContent.MyEntry.MyDocument;
|
||
if (myDocument.LibTitle != "")
|
||
{
|
||
toolTip += string.Format("\r\n(Library Document - {0})", myDocument.LibTitle);
|
||
toolTip += myDocument.LibraryDocumentUsage;
|
||
}
|
||
return toolTip;
|
||
}
|
||
}
|
||
public string TabTitle
|
||
{
|
||
get
|
||
{
|
||
if (MyContent.MyEntry == null)
|
||
return DisplayNumber.Replace("\u2011","-");
|
||
if (MyContent.Number != "")
|
||
return ((MyContent.MyEntry.MyDocument.LibTitle ?? "") == "" ? "" : "\u1D38\u1D35\u1D2E ") + DisplayNumber;
|
||
if (DisplayText.Length <= 10)
|
||
return DisplayText.Replace("\u2011", "-");
|
||
return DisplayText.Replace("\u2011", "-").Split(" ,.;:-_".ToCharArray())[0]+ "...";
|
||
}
|
||
}
|
||
#endregion
|
||
#region Change Bar
|
||
public bool HasChangeBar()
|
||
{
|
||
if (this.IsAccPages || this.IsProcedure || this.IsSection) return false;
|
||
StepInfo si = this as StepInfo;
|
||
if (si == null) return false;
|
||
StepConfig sc = si.MyConfig as StepConfig;
|
||
if (sc == null) return false;
|
||
// if there is no override & return whether there was a change to the text.
|
||
if (sc.Step_CBOverride == null)
|
||
return (DTS > MyProcedure.DTS);
|
||
else // override is on:
|
||
{
|
||
// If the date time stamp says that text was changed so a change bar should exist,
|
||
// check override to see how change bar controls are set. The override flag can
|
||
// be either On or Off.
|
||
if (DTS > MyProcedure.DTS)
|
||
return (sc.Step_CBOverride == "On");
|
||
else
|
||
return (sc.Step_CBOverride == "Off");
|
||
}
|
||
}
|
||
#endregion
|
||
#region IVEReadOnlyItem
|
||
PartInfoList _PartInfoList;
|
||
public System.Collections.IList GetChildren()
|
||
{
|
||
_PartInfoList = this.MyContent.ContentParts;
|
||
if (_PartInfoList.Count == 1 && ( _PartInfoList[0].ToString() == "Sections" || _PartInfoList[0].ToString() == "Steps"))
|
||
return _PartInfoList[0].GetChildren();
|
||
return _PartInfoList;
|
||
}
|
||
public System.Collections.IList GetChildren(bool allParts)
|
||
{
|
||
_PartInfoList = this.MyContent.ContentParts;
|
||
if (allParts)
|
||
{
|
||
if (_PartInfoList.Count == 1 && (_PartInfoList[0].ToString() == "Sections" || _PartInfoList[0].ToString() == "Steps"))
|
||
return _PartInfoList[0].GetChildren();
|
||
return _PartInfoList;
|
||
}
|
||
else // Steps and Sections only
|
||
{
|
||
for(int i = 0;i<_PartInfoList.Count;i++)
|
||
if(_PartInfoList[i].ToString() == "Sections" || _PartInfoList[i].ToString() == "Steps")
|
||
return _PartInfoList[i].GetChildren();
|
||
return null;
|
||
}
|
||
}
|
||
//public bool ChildrenAreLoaded
|
||
//{
|
||
// get { return _PartInfoList == null; }
|
||
//}
|
||
public bool HasChildren
|
||
{
|
||
get { return this.MyContent.ContentPartCount > 0; }
|
||
}
|
||
public bool HasWordContent
|
||
{
|
||
get { return this.MyContent.MyEntry != null; }
|
||
}
|
||
public bool HasStepContent
|
||
{
|
||
get
|
||
{
|
||
if (MyContent.ContentPartCount == 0) return false;
|
||
if (MyContent.ContentPartCount == 1 && MyContent.ContentParts[0].PartType == E_FromType.Section) return false;
|
||
return true;
|
||
}
|
||
}
|
||
|
||
public ProcedureInfo MyProcedure
|
||
{
|
||
get
|
||
{
|
||
// Walk up active parents until the parent is not an item
|
||
ItemInfo tmp = this;
|
||
while (tmp.ActiveParent != null && tmp.ActiveParent.GetType() != typeof(DocVersionInfo))
|
||
tmp = (ItemInfo)tmp.ActiveParent;
|
||
return ProcedureInfo.Get(tmp.ItemID);
|
||
}
|
||
}
|
||
private ItemInfo _MyHLS = null;
|
||
public ItemInfo MyHLS
|
||
{
|
||
get
|
||
{
|
||
if (_MyHLS == null)
|
||
{
|
||
if (IsHigh) _MyHLS = this;
|
||
else
|
||
{
|
||
_MyHLS = ((ItemInfo)MyActiveParent).MyHLS;
|
||
}
|
||
}
|
||
return _MyHLS;
|
||
}
|
||
}
|
||
|
||
private DocVersionInfo _MyDocVersion = null;
|
||
|
||
public DocVersionInfo MyDocVersion
|
||
{
|
||
get
|
||
{
|
||
if (_MyDocVersion == null)
|
||
{
|
||
if (ActiveParent is DocVersionInfo)
|
||
_MyDocVersion = ActiveParent as DocVersionInfo;
|
||
else
|
||
_MyDocVersion = (ActiveParent as ItemInfo).MyDocVersion;
|
||
}
|
||
return _MyDocVersion;
|
||
}
|
||
}
|
||
private IVEDrillDownReadOnly _ActiveParent = null;
|
||
public IVEDrillDownReadOnly MyActiveParent { get { return _ActiveParent; } }
|
||
public IVEDrillDownReadOnly ActiveParent
|
||
{
|
||
get
|
||
{
|
||
//if (_ActiveParent == this)_ActiveParent = null;
|
||
if (_ActiveParent == null)
|
||
{
|
||
if (MyPrevious != null)
|
||
_ActiveParent = _MyPrevious.ActiveParent;
|
||
else
|
||
{
|
||
if (this.ItemDocVersions != null && this.ItemDocVersions.Count > 0)
|
||
_ActiveParent = this.ItemDocVersions[0];
|
||
else
|
||
{
|
||
//The following using command caused a cached iteminfo to be disposed.
|
||
//using (ContentInfo parentContent = ParentContent)
|
||
//{
|
||
ContentInfo parentContent = ParentContent;
|
||
if (parentContent == null || parentContent.ContentItemCount == 0)
|
||
_ActiveParent = this;
|
||
else
|
||
{
|
||
int itemID = 0;
|
||
using(ItemInfoList list = parentContent.ContentItems)
|
||
itemID = list[0].ItemID;
|
||
_ActiveParent = ItemInfo.Get(itemID);
|
||
}
|
||
//}
|
||
}
|
||
}
|
||
}
|
||
return _ActiveParent==this ? null : _ActiveParent;
|
||
}
|
||
internal set
|
||
//set
|
||
{
|
||
_ActiveParent = value;
|
||
}
|
||
}
|
||
private ItemInfo _ActiveSection = null;
|
||
public ItemInfo MyActiveSection { get { return _ActiveSection; } }
|
||
public ItemInfo ActiveSection
|
||
{
|
||
get
|
||
{
|
||
if (_ActiveSection == null)
|
||
{
|
||
if (IsSection)
|
||
_ActiveSection = this;
|
||
else
|
||
{
|
||
ItemInfo parent = ActiveParent as ItemInfo;
|
||
if (parent != null)
|
||
_ActiveSection = parent.ActiveSection;
|
||
else
|
||
_ActiveSection = this;
|
||
}
|
||
}
|
||
return _ActiveSection.IsSection ? _ActiveSection : null;
|
||
}
|
||
set
|
||
{
|
||
_ActiveSection = value;
|
||
}
|
||
}
|
||
private DocStyle _MyDocStyle;
|
||
public DocStyle MyDocStyle
|
||
{
|
||
get
|
||
{
|
||
if (_MyDocStyle == null)
|
||
{
|
||
int typ = (int)ActiveSection.MyContent.Type;
|
||
int subtyp = typ % 10000;
|
||
_MyDocStyle = ActiveFormat.PlantFormat.DocStyles.DocStyleList[subtyp];
|
||
}
|
||
return _MyDocStyle;
|
||
}
|
||
}
|
||
private FormatInfo _ActiveFormat = null;
|
||
public FormatInfo ActiveFormat
|
||
{
|
||
get
|
||
{
|
||
if (_ActiveFormat == null) // jsj added check for NULL ActiveParent
|
||
_ActiveFormat = (LocalFormat != null ? LocalFormat : (ActiveParent != null)? ActiveParent.ActiveFormat : null);
|
||
//Console.WriteLine("Active {0}", (_ActiveFormat == null) ? "_ActiveFormat is null" : _ActiveFormat.Name);
|
||
return _ActiveFormat;
|
||
}
|
||
//get { return LocalFormat != null ? LocalFormat : ActiveParent.ActiveFormat; }
|
||
}
|
||
public FormatInfo LocalFormat
|
||
{
|
||
get {
|
||
//Console.WriteLine("Local {0}", (MyContent.MyFormat==null)?"MYformat is null": MyContent.MyFormat.Name);
|
||
return MyContent.MyFormat; }
|
||
}
|
||
private ConfigDynamicTypeDescriptor _MyConfig=null;
|
||
public ConfigDynamicTypeDescriptor MyConfig
|
||
{
|
||
get
|
||
{
|
||
if (_MyConfig == null)
|
||
{
|
||
switch (MyContent.Type / 10000)
|
||
{
|
||
case 0:
|
||
_MyConfig = new ProcedureConfig(MyContent.Config);
|
||
break;
|
||
case 1:
|
||
_MyConfig = new SectionConfig(MyContent.Config);
|
||
break;
|
||
case 2:
|
||
_MyConfig = new StepConfig(MyContent.Config);
|
||
break;
|
||
}
|
||
}
|
||
return _MyConfig;
|
||
}
|
||
set
|
||
{
|
||
if (_MyConfig == null) return;
|
||
// MyContent.Config = value;
|
||
}
|
||
}
|
||
//public bool HasStandardSteps()
|
||
//{ return MyContent.ContentItemCount > 1; }
|
||
public Color ForeColor
|
||
{ get { return (HasBrokenRules != null ? Color.Red : (MyContent.ContentItemCount > 1 ? Color.Blue : Color.Black)); } }
|
||
public Color BackColor
|
||
{ get { return (ItemAnnotationCount > 0 ? Color.Yellow : Color.White); } }
|
||
#endregion
|
||
#region Constructor
|
||
internal ItemInfo(SafeDataReader dr, bool forIRichtem)
|
||
{
|
||
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ItemInfo.Constructor", GetHashCode());
|
||
try
|
||
{
|
||
ReadData(dr);
|
||
AddContent(dr);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
if (_MyLog.IsErrorEnabled) _MyLog.Error("ItemInfo.Constructor", ex);
|
||
throw new DbCslaException("ItemInfo.Constructor", ex);
|
||
}
|
||
}
|
||
internal void AddContent(SafeDataReader dr)
|
||
{
|
||
_MyContent = new ContentInfo(dr, true);
|
||
}
|
||
#endregion
|
||
#region MetaTags - Tabs, Headers, Footers
|
||
[NonSerialized]
|
||
protected Tab _MyTab;
|
||
public Tab MyTab
|
||
{
|
||
get
|
||
{
|
||
if (!_TagsSetup) SetupTags();
|
||
return _MyTab;
|
||
}
|
||
set
|
||
{
|
||
_MyTab = value;
|
||
}
|
||
}
|
||
[NonSerialized]
|
||
protected MetaTag _MyHeader;
|
||
public MetaTag MyHeader
|
||
{
|
||
get
|
||
{
|
||
if (!_TagsSetup) SetupTags();
|
||
return _MyHeader;
|
||
}
|
||
set { _MyHeader = value; }
|
||
}
|
||
[NonSerialized]
|
||
protected MetaTag _MyFooter;
|
||
public MetaTag MyFooter
|
||
{
|
||
get
|
||
{
|
||
if (!_TagsSetup) SetupTags();
|
||
return _MyFooter;
|
||
}
|
||
set { _MyFooter = value; }
|
||
}
|
||
[NonSerialized]
|
||
protected bool _TagsSetup = false;
|
||
public virtual void SetupTags()
|
||
{
|
||
if (IsStep)
|
||
{
|
||
MyTab = new Tab(AdjustForTextSubFollowsTextStyle(FormatStepData.TabData.Font));
|
||
MyHeader = new MetaTag(FormatStepData.TabData.Font);
|
||
MyFooter = new MetaTag(FormatStepData.TabData.Font);
|
||
SetTabText();
|
||
}
|
||
else
|
||
{
|
||
_MyTab = new Tab(ActiveFormat.PlantFormat.FormatData.Font);
|
||
_MyHeader = null;
|
||
_MyFooter = null;
|
||
_MyTab.CleanText = DisplayNumber;
|
||
}
|
||
_TagsSetup = true;
|
||
}
|
||
protected void SetTabText()
|
||
{
|
||
string cltext = null;
|
||
if (IsParagraph)
|
||
{
|
||
_MyTab.Text = "";
|
||
_MyTab.CleanText = "";
|
||
return;
|
||
}
|
||
int stepType = (int)(MyContent.Type % 10000);
|
||
string tbformat = IsInRNO ? FormatStepData.TabData.RNOIdentPrint : FormatStepData.TabData.IdentPrint;
|
||
// rno gets parent tab
|
||
if (IsRNOPart)
|
||
{
|
||
try
|
||
{
|
||
if ((((ItemInfo)ActiveParent).IsHigh && FormatStepData.NumberHighLevel) || ((!((ItemInfo)ActiveParent).IsHigh) && ((tbformat == null || tbformat == "") && (RNOLevel <= ColumnMode))))
|
||
{
|
||
_MyTab.CleanText = ((ItemInfo)ActiveParent).MyTab.CleanText;
|
||
_MyTab.Text = ((ItemInfo)ActiveParent).MyTab.Text;
|
||
return;
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
Console.WriteLine("SetTabText IsRNO error {0}", ex.Message);
|
||
}
|
||
}
|
||
if (tbformat == null)
|
||
{
|
||
_MyTab.Text = "";
|
||
_MyTab.CleanText = "";
|
||
return;
|
||
}
|
||
// Start with basic cases of alpha/numeric/seq:
|
||
if (tbformat.IndexOf("{seq}") > -1)
|
||
{
|
||
int level = 0;
|
||
ItemInfo par = this;
|
||
while (!par.IsHigh)
|
||
{
|
||
// 16bit TODO:
|
||
//if (par.IsRNO) // do I need to save 'lastrnoptr'
|
||
//if (!IsRNO(ptr) && (IsSequential(ptr) ||
|
||
// (!IsText(ptr) && CountAllSubLevels))) - Add this line of code for non-hlp
|
||
if (!par.IsRNOPart && par.IsSequential) level++;
|
||
par = par.MyParent;
|
||
}
|
||
SeqTabFmtList seqtabs = ActiveFormat.PlantFormat.FormatData.SectData.StepSectionData.SeqTabFmtList;
|
||
tbformat = seqtabs[level % seqtabs.Count].PrintTabFormat;
|
||
// If token includes 'Wpar', the parent tab prefix's the tab.
|
||
if (level > 0 && (tbformat.IndexOf("{numericWpar}") > -1 || tbformat.IndexOf("{alphaWpar}") > -1 || tbformat.IndexOf("{ALPHAWpar}") > -1))
|
||
{
|
||
string parentTab = ((ItemInfo)(ActiveParent)).MyTab.CleanText.Trim();
|
||
tbformat = parentTab + (parentTab.EndsWith(".") ? "" : ".") + tbformat.TrimStart();
|
||
}
|
||
if (tbformat.IndexOf("#2#") > -1 || tbformat.IndexOf("#1#") > -1)
|
||
{
|
||
string ofst = tbformat.Substring(0, 3);
|
||
_MyTab.Offset = Convert.ToInt32(ofst.Substring(1, 1));
|
||
cltext = tbformat.Replace("#2#", "");
|
||
cltext = cltext.Replace("#1#", "");
|
||
}
|
||
}
|
||
// if this is a caution/note type determine where 'NOTE/CAUTION' tab goes, as tab or as 'header'
|
||
// and also determine whether the tab itself gets converted to a bullet.
|
||
if (IsCaution || IsNote) tbformat = CheckNoteCautionTab(tbformat);
|
||
|
||
int ordinal = Ordinal;
|
||
string alpha = AlphabeticalNumbering(ordinal);
|
||
tbformat = tbformat.Replace("{alpha}", alpha.ToLower());
|
||
tbformat = tbformat.Replace("{alphaWpar}", alpha.ToLower());
|
||
tbformat = tbformat.Replace("{ALPHA}", alpha);
|
||
tbformat = tbformat.Replace("{ALPHAWpar}", alpha);
|
||
string roman = RomanNumbering(ordinal);
|
||
tbformat = tbformat.Replace("{roman}", roman.ToLower());
|
||
tbformat = tbformat.Replace("{ROMAN}", roman);
|
||
tbformat = tbformat.Replace("{numeric}", ordinal.ToString().PadLeft(2));
|
||
tbformat = tbformat.Replace("{numericWpar}", ordinal.ToString());
|
||
|
||
if (tbformat.IndexOf("{!C0}") > -1)
|
||
{
|
||
cltext = cltext == null ? tbformat.Replace("{!C0}", "") : cltext.Replace("{!C0}", "");
|
||
}
|
||
if (FormatStepData.Sep != null && MyPrevious != null)
|
||
{
|
||
if (_MyHeader == null) _MyHeader = new MetaTag(FormatStepData.TabData.Font);
|
||
_MyHeader.Text = _MyHeader.CleanText = FormatStepData.Sep;
|
||
MyHeader.Justify = ContentAlignment.MiddleCenter;
|
||
}
|
||
#region Non HLP tab TODO
|
||
// other possible 'tokens'
|
||
// Position offset - do this one here, so don't get background substitution below..
|
||
// ##-3# - Offset of -3 from Parent (FNP)
|
||
// "{Pos-3}"
|
||
|
||
// Background/Deviation Documents - check for E_PurchaseOptions.(ENHANCEDBACKGROUNDS or ENHANCEDDEVIATIONS)
|
||
// # - Related Caution or Note number
|
||
// ~ - Linked Step Number
|
||
//"{LNK C/N Num}"
|
||
//"{LNK Step Num}"
|
||
|
||
//Section Numbers
|
||
// % - Prefix with section number (works string in 16 bit, ie.e For 4.3 the prefix becomes 4.
|
||
// wid that would be stored.
|
||
//"{Section Prefix}"
|
||
|
||
// Position offset
|
||
// \257 - Indent (CALLOWAY BACKGROUNDS)
|
||
// Newline within a tab (calbck)
|
||
//"{indent}");
|
||
//"{par}");
|
||
|
||
//Macros
|
||
// <!diamond> - draws a diamond around the stepnumber
|
||
// <!diamond1> - A macro
|
||
// <!asterisk>
|
||
// <> - ignored
|
||
// \241 - circle macro around step, same as <!circle>
|
||
// Also note, the format files had "<>", these get converted during input in this
|
||
// format converter code.
|
||
//wkstr = wkstr.Replace("{!asterisk}", "\\fs10 \\b*\\b0"); // was font size 20 in 16-bit
|
||
//wkstr = Regex.Replace(wkstr, @"{![.*?]}", @"{!$1}");
|
||
//wkstr = wkstr.Replace("{}", "");
|
||
//wkstr = wkstr.Replace("<22>", "{!C0}");
|
||
//if (vefont != null && vefont.HasCircleString2()) wkstr.Insert(0,"{!C0}");
|
||
|
||
//wkstr = wkstr.Replace("<22>", @"{Box Step}");
|
||
#endregion
|
||
_MyTab.Text = tbformat;
|
||
_MyTab.CleanText = cltext != null ? cltext : tbformat;
|
||
}
|
||
private string CheckNoteCautionTab(string tbformat)
|
||
{
|
||
string prevTbFormat = null;
|
||
string nextTbFormat = null;
|
||
StepData nextStepData = null;
|
||
if (MyPrevious != null)
|
||
{
|
||
// int prevStepType = ((int)MyPrevious.MyContent.Type) % 10000;
|
||
StepData prevStepData = MyPrevious.FormatStepData; // ActiveFormat.PlantFormat.FormatData.StepDataList[prevStepType];
|
||
prevTbFormat = MyPrevious.IsInRNO ? prevStepData.TabData.RNOIdentPrint : prevStepData.TabData.IdentPrint;
|
||
}
|
||
if (NextItem != null)
|
||
{
|
||
//int nextStepType = ((int)NextItem.MyContent.Type) % 10000;
|
||
nextStepData = NextItem.FormatStepData; // ActiveFormat.PlantFormat.FormatData.StepDataList[nextStepType];
|
||
// tried to duplicate functionality from 16-bit code.
|
||
nextTbFormat = NextItem.IsInRNO ? nextStepData.TabData.RNOIdentPrint : nextStepData.TabData.IdentPrint;
|
||
}
|
||
// Handle the centered tab - if this tab is centered make it a header.
|
||
if (FormatStepData.TabData.Justify == "Center")
|
||
{
|
||
if (_MyHeader == null) _MyHeader = new MetaTag(FormatStepData.TabData.Font);
|
||
MyHeader.Justify = ContentAlignment.MiddleCenter;
|
||
MyHeader.Text = MyHeader.CleanText = tbformat.Trim(); ;
|
||
|
||
// if there is only step in the group - no bullet is used, if more that one replace the tab
|
||
// with a bullet
|
||
if (MyPrevious == null && NextItem == null)
|
||
tbformat = "";
|
||
else
|
||
{
|
||
if (MyPrevious != null) MyHeader = null;
|
||
tbformat = ActiveFormat.PlantFormat.FormatData.SectData.StepSectionData.IdentB;
|
||
if ((FormatStepData.TabData.Font.Style & E_Style.Underline) > 0)
|
||
{
|
||
FontStyle style = FontStyle.Regular;
|
||
if ((FormatStepData.TabData.Font.Style & E_Style.Bold) > 0) style |= FontStyle.Bold;
|
||
if ((FormatStepData.TabData.Font.Style & E_Style.Italics) > 0) style |= FontStyle.Italic;
|
||
_MyTab.MyFont.WindowsFont = new Font(FormatStepData.TabData.Font.WindowsFont.FontFamily, FormatStepData.TabData.Font.WindowsFont.Size, style);
|
||
}
|
||
|
||
}
|
||
return tbformat;
|
||
}
|
||
|
||
// If this has a previous, and the tabs of this & previous match
|
||
if (tbformat != null && MyPrevious != null && !FormatStepData.AlwaysTab && (!FormatStepData.MixCautionsAndNotes || (tbformat == prevTbFormat)))
|
||
{
|
||
tbformat = tbformat + ActiveFormat.PlantFormat.FormatData.SectData.StepSectionData.IdentB;
|
||
}
|
||
// else if this has a next
|
||
else if (tbformat != null && NextItem != null && !FormatStepData.AlwaysTab &&
|
||
(!FormatStepData.MixCautionsAndNotes ||
|
||
(FormatStepData.TabData.UsePreviousStyle && !nextStepData.TabData.UsePreviousStyle && tbformat == nextTbFormat) ||
|
||
((prevTbFormat != tbformat && (NextItem.MyContent.Type == (int)(MyContent.Type % 10000))))))
|
||
{
|
||
tbformat = tbformat + ActiveFormat.PlantFormat.FormatData.SectData.StepSectionData.IdentB;
|
||
}
|
||
return tbformat;
|
||
}
|
||
private string AlphabeticalNumbering(int number)
|
||
{
|
||
string retval = string.Empty;
|
||
if (number > 26) retval += Letter((number - 1) / 26);
|
||
retval += Letter(1 + ((number - 1) % 26));
|
||
return retval;
|
||
}
|
||
private string Letter(int number)
|
||
{
|
||
char c = (char)(number + 64);
|
||
return c.ToString();
|
||
}
|
||
private enum RomanOffset : int
|
||
{
|
||
Hundreds = 2,
|
||
Tens = 4,
|
||
Units = 6
|
||
}
|
||
private string _Romans = "MDCLXVI";
|
||
private string RomanPart(RomanOffset offset, int value)
|
||
{
|
||
int iFive = value / 5;
|
||
int iUnits = value % 5;
|
||
int iFour = iUnits / 4;
|
||
return _Romans.Substring(((int)offset), iFour) +
|
||
_Romans.Substring(((int)offset) - iFive - iFour, iFive | iFour) +
|
||
"".PadRight(iUnits % 4, _Romans[((int)offset)]);
|
||
}
|
||
private string RomanNumbering(int number)
|
||
{
|
||
int thousands = number / 1000;
|
||
int hundreds = (number % 1000) / 100;
|
||
int tens = (number % 100) / 10;
|
||
int units = number % 10;
|
||
return "".PadRight(thousands, _Romans[0]) +
|
||
RomanPart(RomanOffset.Hundreds, hundreds) +
|
||
RomanPart(RomanOffset.Tens, tens) +
|
||
RomanPart(RomanOffset.Units, units);
|
||
}
|
||
public static void ResetTabString(int itemID)
|
||
{
|
||
ConvertListToDictionary();
|
||
string key = itemID.ToString();
|
||
if (key != null && _CacheByPrimaryKey.ContainsKey(key))
|
||
{
|
||
ItemInfo[] items = _CacheByPrimaryKey[key].ToArray();
|
||
foreach (ItemInfo item in items)
|
||
{
|
||
item._TagsSetup = false;
|
||
}
|
||
}
|
||
}
|
||
#endregion
|
||
#region ParentNoteOrCaution
|
||
private bool _ParentNoteOrCautionLoaded = false;
|
||
private ItemInfo _ParentNoteOrCaution;
|
||
public ItemInfo ParentNoteOrCaution
|
||
{
|
||
get
|
||
{
|
||
if (!_ParentNoteOrCautionLoaded)
|
||
{
|
||
ItemInfo parent = ActiveParent as ItemInfo;
|
||
if (parent != null)
|
||
{
|
||
if (parent.IsCautionPart || parent.IsNotePart)
|
||
_ParentNoteOrCaution = parent;
|
||
else if(!parent.IsHigh)
|
||
{
|
||
_ParentNoteOrCaution = parent.ParentNoteOrCaution;
|
||
}
|
||
}
|
||
_ParentNoteOrCautionLoaded = true;
|
||
}
|
||
return _ParentNoteOrCaution;
|
||
}
|
||
}
|
||
#endregion
|
||
#region Macro List
|
||
[NonSerialized]
|
||
protected List<Macro> _MyMacros;
|
||
protected bool _MacrosSetup = false;
|
||
public List<Macro> MyMacros
|
||
{
|
||
get
|
||
{
|
||
if (!_MacrosSetup) SetupMacros();
|
||
return _MyMacros;
|
||
}
|
||
set
|
||
{
|
||
_MyMacros = value;
|
||
}
|
||
}
|
||
private void SetupMacros()
|
||
{
|
||
if (FormatStepData == null) return;
|
||
// see if each macro should be printed based on its attributes and the item we're on.
|
||
// Attributes to check are NotInRNO, i.e. only add this macro to the result list if
|
||
// the item is not in the RNO column. Also, Groupings is used to only have the macro if
|
||
// there are N or more of the type in the grouping.
|
||
List<Macro> tmp = new List<Macro>();
|
||
StepData myStepData = (FormatStepData.TextSubFollowsTextStyle && ParentNoteOrCaution != null) ? ParentNoteOrCaution.FormatStepData : FormatStepData;
|
||
// foreach (Macro macro in ActiveFormat.PlantFormat.FormatData.StepDataList[FormatStepType].TabData.MacroList)
|
||
foreach (Macro macro in myStepData.TabData.MacroList)
|
||
{
|
||
bool addToList = true;
|
||
if (macro.NotInRNO && IsInRNO) addToList = false;
|
||
if (macro.Grouping != null && macro.Grouping > 0)
|
||
{
|
||
int count = 0;
|
||
ItemInfo ii = FirstSibling;
|
||
while (ii != null)
|
||
{
|
||
if (ii.MyContent.Type == MyContent.Type) count++;
|
||
ii = ii.NextItem;
|
||
}
|
||
if (count <= macro.Grouping) addToList = false;
|
||
}
|
||
if (addToList) tmp.Add(macro);
|
||
}
|
||
if (tmp.Count > 0) _MyMacros = tmp;
|
||
}
|
||
#endregion
|
||
}
|
||
#endregion ItemInfo
|
||
#region Tab
|
||
public class MetaTag
|
||
{
|
||
public VE_Font MyFont;
|
||
public ContentAlignment Justify = ContentAlignment.MiddleLeft;
|
||
public string Text; // may include tokens, such as macros for circles/diamonds, etc
|
||
public string CleanText; // all tokens removed
|
||
//public bool _TagsSetup = false;
|
||
public MetaTag()
|
||
{
|
||
}
|
||
public MetaTag(VE_Font font)
|
||
{
|
||
MyFont = new VE_Font(font.XmlNode);
|
||
}
|
||
}
|
||
public class Tab : MetaTag
|
||
{
|
||
public Tab(VE_Font font)
|
||
{
|
||
MyFont = font;
|
||
}
|
||
public int Offset;
|
||
}
|
||
public class Header : MetaTag
|
||
{
|
||
}
|
||
#endregion
|
||
#region ItemInfoList
|
||
public partial class ItemInfoList
|
||
{
|
||
//public void ToXml(XmlNode xn)
|
||
//{
|
||
// foreach (ItemInfo itemInfo in this)
|
||
// {
|
||
// itemInfo.ToXml(xn);
|
||
// }
|
||
//}
|
||
internal ItemInfoList(ItemInfo itemInfo)
|
||
{
|
||
AddItem(itemInfo);
|
||
}
|
||
public static ItemInfoList GetList(int? itemID,int type)
|
||
{
|
||
try
|
||
{
|
||
ItemInfoList tmp = DataPortal.Fetch<ItemInfoList>(new ItemListCriteria(itemID,type));
|
||
ItemInfo.AddList(tmp);
|
||
tmp.AddEvents();
|
||
#if (!ItemWithContent) // If ItemWithContent is set, the content is returned with the ItemInfoList
|
||
ContentInfoList.GetList(itemID); // Performance - Load All Content
|
||
#endif
|
||
return tmp;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
throw new DbCslaException("Error on ItemInfoList.GetChildren", ex);
|
||
}
|
||
}
|
||
public static ItemInfoList GetListByPartType(E_FromType fromType)
|
||
{
|
||
try
|
||
{
|
||
ItemInfoList tmp = DataPortal.Fetch<ItemInfoList>(new ItemListPartTypeCriteria(fromType));
|
||
ItemInfo.AddList(tmp);
|
||
tmp.AddEvents();
|
||
#if (!ItemWithContent) // If ItemWithContent is set, the content is returned with the ItemInfoList
|
||
ContentInfoList.GetList(itemID); // Performance - Load All Content
|
||
#endif
|
||
return tmp;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
throw new DbCslaException("Error on ItemInfoList.GetChildren", ex);
|
||
}
|
||
}
|
||
[Serializable()]
|
||
private class ItemListCriteria
|
||
{
|
||
public ItemListCriteria(int? itemID,int type)
|
||
{
|
||
_ItemID = itemID;
|
||
_Type = type;
|
||
}
|
||
private int? _ItemID;
|
||
public int? ItemID
|
||
{
|
||
get { return _ItemID; }
|
||
set { _ItemID = value; }
|
||
}
|
||
private int _Type;
|
||
public int Type
|
||
{
|
||
get { return _Type; }
|
||
set { _Type = value; }
|
||
}
|
||
}
|
||
[Serializable()]
|
||
private class ItemListPartTypeCriteria
|
||
{
|
||
public ItemListPartTypeCriteria(E_FromType type)
|
||
{
|
||
_Type = type;
|
||
}
|
||
private E_FromType _Type;
|
||
public E_FromType Type
|
||
{
|
||
get { return _Type; }
|
||
set { _Type = value; }
|
||
}
|
||
}
|
||
private void DataPortal_Fetch(ItemListCriteria criteria)
|
||
{
|
||
this.RaiseListChangedEvents = false;
|
||
try
|
||
{
|
||
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
|
||
{
|
||
using (SqlCommand cm = cn.CreateCommand())
|
||
{
|
||
cm.CommandType = CommandType.StoredProcedure;
|
||
#if ItemWithContent
|
||
cm.CommandText = "vesp_ListItemsAndContent";
|
||
#else
|
||
cm.CommandText = "vesp_ListItems";
|
||
#endif
|
||
cm.Parameters.AddWithValue("@ItemID", criteria.ItemID);
|
||
using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader()))
|
||
{
|
||
while (dr.Read())
|
||
{
|
||
ItemInfo itemInfo = null;
|
||
switch ((E_FromType)criteria.Type)
|
||
{
|
||
case E_FromType.Procedure:
|
||
itemInfo = new ProcedureInfo(dr);
|
||
break;
|
||
case E_FromType.Section:
|
||
itemInfo = new SectionInfo(dr);
|
||
break;
|
||
default:
|
||
itemInfo = new StepInfo(dr);
|
||
break;
|
||
}
|
||
IsReadOnly = false;
|
||
this.Add(itemInfo);
|
||
IsReadOnly = true;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
Database.LogException("ItemInfoList.DataPortal_Fetch", ex);
|
||
throw new DbCslaException("ItemInfoList.DataPortal_Fetch", ex);
|
||
}
|
||
this.RaiseListChangedEvents = true;
|
||
}
|
||
private void DataPortal_Fetch(ItemListPartTypeCriteria criteria)
|
||
{
|
||
this.RaiseListChangedEvents = false;
|
||
try
|
||
{
|
||
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
|
||
{
|
||
using (SqlCommand cm = cn.CreateCommand())
|
||
{
|
||
cm.CommandType = CommandType.StoredProcedure;
|
||
#if ItemWithContent
|
||
cm.CommandText = "getItemsByPartTypeAndContent";
|
||
#else
|
||
cm.CommandText = "getItemsByPartType";
|
||
#endif
|
||
cm.Parameters.AddWithValue("@FromType", (int) criteria.Type);
|
||
using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader()))
|
||
{
|
||
while (dr.Read())
|
||
{
|
||
ItemInfo itemInfo = null;
|
||
switch (criteria.Type)
|
||
{
|
||
case E_FromType.Procedure:
|
||
itemInfo = new ProcedureInfo(dr);
|
||
break;
|
||
case E_FromType.Section:
|
||
itemInfo = new SectionInfo(dr);
|
||
break;
|
||
default:
|
||
itemInfo = new StepInfo(dr);
|
||
break;
|
||
}
|
||
IsReadOnly = false;
|
||
this.Add(itemInfo);
|
||
IsReadOnly = true;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
Database.LogException("ItemInfoList.DataPortal_Fetch", ex);
|
||
throw new DbCslaException("ItemInfoList.DataPortal_Fetch", ex);
|
||
}
|
||
this.RaiseListChangedEvents = true;
|
||
}
|
||
internal void AddItem(ItemInfo itemInfo)
|
||
{
|
||
IsReadOnly = false;
|
||
this.Add(itemInfo);
|
||
IsReadOnly = true;
|
||
}
|
||
#region Text Search
|
||
public static ItemInfoList GetListFromTextSearch(string docVersionList, string stepTypeList, string searchString, int caseSensitive, ItemSearchIncludeLinks includeLinks, bool includeRtfFormatting, bool includeSpecialCharacters)
|
||
{
|
||
try
|
||
{
|
||
ItemInfoList tmp = DataPortal.Fetch<ItemInfoList>(new ItemListSearchCriteria(docVersionList, stepTypeList, searchString, caseSensitive, includeLinks, includeRtfFormatting, includeSpecialCharacters));
|
||
ItemInfo.AddList(tmp);
|
||
tmp.AddEvents();
|
||
return tmp;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
throw new DbCslaException("Error on ItemInfoList.GetListFromTextSearch", ex);
|
||
}
|
||
}
|
||
[Serializable()]
|
||
private class ItemListSearchCriteria
|
||
{
|
||
private string _DocVersionList;
|
||
public string DocVersionList
|
||
{
|
||
get { return _DocVersionList; }
|
||
set { _DocVersionList = value; }
|
||
}
|
||
private string _StepTypeList;
|
||
public string StepTypeList
|
||
{
|
||
get { return _StepTypeList; }
|
||
set { _StepTypeList = value; }
|
||
}
|
||
private string _SearchString;
|
||
public string SearchString
|
||
{
|
||
get { return _SearchString; }
|
||
set { _SearchString = value; }
|
||
}
|
||
private int _CaseSensitive;
|
||
public int CaseSensitive
|
||
{
|
||
get { return _CaseSensitive; }
|
||
set { _CaseSensitive = value; }
|
||
}
|
||
private ItemSearchIncludeLinks _IncludeLinks;
|
||
public ItemSearchIncludeLinks IncludeLinks
|
||
{
|
||
get { return _IncludeLinks; }
|
||
set { _IncludeLinks = value; }
|
||
}
|
||
private bool _IncludeRtfFormatting;
|
||
public bool IncludeRtfFormatting
|
||
{
|
||
get { return _IncludeRtfFormatting; }
|
||
set { _IncludeRtfFormatting = value; }
|
||
}
|
||
private bool _IncludeSpecialCharacters;
|
||
public bool IncludeSpecialCharacters
|
||
{
|
||
get { return _IncludeSpecialCharacters; }
|
||
set { _IncludeSpecialCharacters = value; }
|
||
}
|
||
public ItemListSearchCriteria(string docVersionList, string stepTypeList, string searchString,
|
||
int caseSensitive, ItemSearchIncludeLinks includeLinks, bool includeRtfFormatting, bool includeSpecialCharacters)
|
||
{
|
||
_DocVersionList = docVersionList;
|
||
_StepTypeList = stepTypeList;
|
||
_SearchString = searchString;
|
||
_CaseSensitive = caseSensitive;
|
||
_IncludeLinks = includeLinks;
|
||
_IncludeRtfFormatting = includeRtfFormatting;
|
||
_IncludeSpecialCharacters = includeSpecialCharacters;
|
||
}
|
||
}
|
||
private void DataPortal_Fetch(ItemListSearchCriteria criteria)
|
||
{
|
||
this.RaiseListChangedEvents = false;
|
||
try
|
||
{
|
||
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
|
||
{
|
||
using (SqlCommand cm = cn.CreateCommand())
|
||
{
|
||
cm.CommandType = CommandType.StoredProcedure;
|
||
cm.CommandText = "vesp_SearchItemAndChildrenNew";
|
||
cm.Parameters.AddWithValue("@DocVersionList", criteria.DocVersionList);
|
||
cm.Parameters.AddWithValue("@StepTypeList", criteria.StepTypeList);
|
||
cm.Parameters.AddWithValue("@SearchString", criteria.SearchString);
|
||
cm.Parameters.AddWithValue("@CaseSensitive", criteria.CaseSensitive);
|
||
cm.Parameters.AddWithValue("@IncludeLinks", (int) criteria.IncludeLinks);
|
||
cm.Parameters.AddWithValue("@IncludeRtfFormatting", criteria.IncludeRtfFormatting ? 1 : 0);
|
||
cm.Parameters.AddWithValue("@IncludeSpecialCharacters", criteria.IncludeSpecialCharacters ? 1 : 0);
|
||
cm.CommandTimeout = 120;
|
||
using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader()))
|
||
{
|
||
while (dr.Read())
|
||
{
|
||
ItemInfo itemInfo = null;
|
||
int itemType = dr.GetInt32("Type") / 10000;
|
||
switch (itemType)
|
||
{
|
||
case 0:
|
||
itemInfo = new ProcedureInfo(dr);
|
||
break;
|
||
case 1:
|
||
itemInfo = new SectionInfo(dr);
|
||
break;
|
||
default:
|
||
itemInfo = new StepInfo(dr);
|
||
break;
|
||
}
|
||
itemInfo.AddContent(dr);
|
||
itemInfo._SearchDVPath = dr.GetString("DVPath");
|
||
itemInfo._SearchPath = dr.GetString("Path");
|
||
IsReadOnly = false;
|
||
this.Add(itemInfo);
|
||
IsReadOnly = true;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
Database.LogException("ItemInfoList.DataPortal_Fetch", ex);
|
||
throw new DbCslaException("ItemInfoList.DataPortal_Fetch", ex);
|
||
}
|
||
this.RaiseListChangedEvents = true;
|
||
}
|
||
#endregion
|
||
#region RO Search
|
||
public static ItemInfoList GetListFromROSearch(string docVersionList, string stepTypeList, string roSearchString)
|
||
{
|
||
try
|
||
{
|
||
ItemInfoList tmp = DataPortal.Fetch<ItemInfoList>(new ItemListROSearchCriteria(docVersionList, stepTypeList, roSearchString));
|
||
ItemInfo.AddList(tmp);
|
||
tmp.AddEvents();
|
||
return tmp;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
throw new DbCslaException("Error on ItemInfoList.GetChildren", ex);
|
||
}
|
||
}
|
||
[Serializable()]
|
||
private class ItemListROSearchCriteria
|
||
{
|
||
private string _DocVersionList;
|
||
public string DocVersionList
|
||
{
|
||
get { return _DocVersionList; }
|
||
set { _DocVersionList = value; }
|
||
}
|
||
private string _StepTypeList;
|
||
public string StepTypeList
|
||
{
|
||
get { return _StepTypeList; }
|
||
set { _StepTypeList = value; }
|
||
}
|
||
private string _ROSearchString;
|
||
public string ROSearchString
|
||
{
|
||
get { return _ROSearchString; }
|
||
set { _ROSearchString = value; }
|
||
}
|
||
public ItemListROSearchCriteria(string docVersionList, string stepTypeList, string roSearchString)
|
||
{
|
||
_DocVersionList = docVersionList;
|
||
_StepTypeList = stepTypeList;
|
||
_ROSearchString = roSearchString;
|
||
}
|
||
}
|
||
private void DataPortal_Fetch(ItemListROSearchCriteria criteria)
|
||
{
|
||
this.RaiseListChangedEvents = false;
|
||
try
|
||
{
|
||
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
|
||
{
|
||
using (SqlCommand cm = cn.CreateCommand())
|
||
{
|
||
cm.CommandType = CommandType.StoredProcedure;
|
||
cm.CommandText = "vesp_SearchROItemAndChildren";
|
||
cm.Parameters.AddWithValue("@DocVersionList", criteria.DocVersionList);
|
||
cm.Parameters.AddWithValue("@StepTypeList", criteria.StepTypeList);
|
||
cm.Parameters.AddWithValue("@ROSearchString", criteria.ROSearchString);
|
||
using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader()))
|
||
{
|
||
while (dr.Read())
|
||
{
|
||
ItemInfo itemInfo = null;
|
||
int itemType = dr.GetInt32("Type") / 10000;
|
||
switch (itemType)
|
||
{
|
||
case 0:
|
||
itemInfo = new ProcedureInfo(dr);
|
||
break;
|
||
case 1:
|
||
itemInfo = new SectionInfo(dr);
|
||
break;
|
||
default:
|
||
itemInfo = new StepInfo(dr);
|
||
break;
|
||
}
|
||
itemInfo.AddContent(dr);
|
||
itemInfo._SearchDVPath = dr.GetString("DVPath");
|
||
itemInfo._SearchPath = dr.GetString("Path");
|
||
IsReadOnly = false;
|
||
this.Add(itemInfo);
|
||
IsReadOnly = true;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
Database.LogException("ItemInfoList.DataPortal_Fetch", ex);
|
||
throw new DbCslaException("ItemInfoList.DataPortal_Fetch", ex);
|
||
}
|
||
this.RaiseListChangedEvents = true;
|
||
}
|
||
#endregion
|
||
#region Annotation Search
|
||
public static ItemInfoList GetListFromAnnotationSearch(string docVersionList, string stepTypeList, string annotationTypeList, string searchString, bool caseSensitive)
|
||
{
|
||
try
|
||
{
|
||
ItemInfoList tmp = DataPortal.Fetch<ItemInfoList>(new ItemListAnnotationSearchCriteria(docVersionList, stepTypeList, annotationTypeList, searchString, caseSensitive));
|
||
ItemInfo.AddList(tmp);
|
||
tmp.AddEvents();
|
||
return tmp;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
throw new DbCslaException("Error on ItemInfoList.GetChildren", ex);
|
||
}
|
||
}
|
||
[Serializable()]
|
||
private class ItemListAnnotationSearchCriteria
|
||
{
|
||
private string _DocVersionList;
|
||
public string DocVersionList
|
||
{
|
||
get { return _DocVersionList; }
|
||
set { _DocVersionList = value; }
|
||
}
|
||
private string _StepTypeList;
|
||
public string StepTypeList
|
||
{
|
||
get { return _StepTypeList; }
|
||
set { _StepTypeList = value; }
|
||
}
|
||
private string _AnnotationTypeList;
|
||
public string AnnotationTypeList
|
||
{
|
||
get { return _AnnotationTypeList; }
|
||
set { _AnnotationTypeList = value; }
|
||
}
|
||
private string _SearchString;
|
||
public string SearchString
|
||
{
|
||
get { return _SearchString; }
|
||
set { _SearchString = value; }
|
||
}
|
||
private bool _CaseSensitive;
|
||
public bool CaseSensitive
|
||
{
|
||
get { return _CaseSensitive; }
|
||
set { _CaseSensitive = value; }
|
||
}
|
||
public ItemListAnnotationSearchCriteria(string docVersionList, string stepTypeList, string annotationTypeList, string searchString, bool caseSensitive)
|
||
{
|
||
_DocVersionList = docVersionList;
|
||
_StepTypeList = stepTypeList;
|
||
_AnnotationTypeList = annotationTypeList;
|
||
_SearchString = searchString;
|
||
_CaseSensitive = caseSensitive;
|
||
}
|
||
}
|
||
private void DataPortal_Fetch(ItemListAnnotationSearchCriteria criteria)
|
||
{
|
||
this.RaiseListChangedEvents = false;
|
||
try
|
||
{
|
||
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
|
||
{
|
||
using (SqlCommand cm = cn.CreateCommand())
|
||
{
|
||
cm.CommandType = CommandType.StoredProcedure;
|
||
cm.CommandText = "vesp_SearchAnnotationItemAndChildren";
|
||
cm.Parameters.AddWithValue("@DocVersionList", criteria.DocVersionList);
|
||
cm.Parameters.AddWithValue("@StepTypeList", criteria.StepTypeList);
|
||
cm.Parameters.AddWithValue("@AnnotationTypeList", criteria.AnnotationTypeList);
|
||
cm.Parameters.AddWithValue("@SearchString", criteria.SearchString);
|
||
cm.Parameters.AddWithValue("@CaseSensitive", criteria.CaseSensitive ? 1 : 0);
|
||
using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader()))
|
||
{
|
||
while (dr.Read())
|
||
{
|
||
ItemInfo itemInfo = null;
|
||
int itemType = dr.GetInt32("Type") / 10000;
|
||
switch (itemType)
|
||
{
|
||
case 0:
|
||
itemInfo = new ProcedureInfo(dr);
|
||
break;
|
||
case 1:
|
||
itemInfo = new SectionInfo(dr);
|
||
break;
|
||
default:
|
||
itemInfo = new StepInfo(dr);
|
||
break;
|
||
}
|
||
itemInfo.AddContent(dr);
|
||
itemInfo._SearchDVPath = dr.GetString("DVPath");
|
||
itemInfo._SearchPath = dr.GetString("Path");
|
||
itemInfo._SearchAnnotationID = dr.GetInt32("SearchAnnotationID");
|
||
itemInfo._SearchAnnotationText = dr.GetString("SearchText");
|
||
itemInfo._SearchAnnotationType = dr.GetString("AnnotationType");
|
||
IsReadOnly = false;
|
||
this.Add(itemInfo);
|
||
IsReadOnly = true;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
Database.LogException("ItemInfoList.DataPortal_Fetch", ex);
|
||
throw new DbCslaException("ItemInfoList.DataPortal_Fetch", ex);
|
||
}
|
||
this.RaiseListChangedEvents = true;
|
||
}
|
||
#endregion
|
||
}
|
||
#endregion
|
||
#region ProcedureInfo
|
||
[Serializable()]
|
||
public partial class ProcedureInfo : ItemInfo, IVEDrillDownReadOnly
|
||
{
|
||
public override void SetupTags()
|
||
{
|
||
base.SetupTags();
|
||
}
|
||
protected override void RefreshFields(Item tmp)
|
||
{
|
||
base.RefreshFields(tmp);
|
||
ExtensionRefreshFields(tmp);
|
||
}
|
||
#if ItemWithContent
|
||
public ProcedureInfo(SafeDataReader dr) : base(dr, true) { }
|
||
#else
|
||
public ProcedureInfo(SafeDataReader dr) : base(dr) { }
|
||
#endif
|
||
private ProcedureInfo() : base() { ;}
|
||
public new static ProcedureInfo Get(int itemID)
|
||
{
|
||
//if (!CanGetObject())
|
||
// throw new System.Security.SecurityException("User not authorized to view a Item");
|
||
try
|
||
{
|
||
ProcedureInfo tmp = GetCachedByPrimaryKey(itemID) as ProcedureInfo;
|
||
if (tmp == null)
|
||
{
|
||
tmp = DataPortal.Fetch<ProcedureInfo>(new PKCriteria(itemID));
|
||
AddToCache(tmp);
|
||
}
|
||
if (tmp.ErrorMessage == "No Record Found") tmp = null;
|
||
return tmp;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
throw new DbCslaException("Error on Item.Get", ex);
|
||
}
|
||
}
|
||
public void MoveProcedure(IVEDrillDownReadOnly pInfo, int index)
|
||
{
|
||
using (Item ii = Item.Get(this.ItemID))
|
||
{
|
||
ii.MoveItem(pInfo, index);
|
||
}
|
||
}
|
||
public new Procedure Get()
|
||
{
|
||
return (Procedure) (_Editable = Procedure.Get(ItemID));
|
||
}
|
||
#region ProcedureConfig
|
||
[NonSerialized]
|
||
private ProcedureConfig _ProcedureConfig;
|
||
public ProcedureConfig ProcedureConfig
|
||
{ get { return (_ProcedureConfig != null ? _ProcedureConfig : _ProcedureConfig = new ProcedureConfig(this)); } }
|
||
#endregion
|
||
public new ConfigDynamicTypeDescriptor MyConfig
|
||
{
|
||
get { return ProcedureConfig ; }
|
||
}
|
||
}
|
||
#endregion
|
||
#region Procedure
|
||
[Serializable()]
|
||
public partial class Procedure : Item
|
||
{
|
||
public ProcedureInfo MyProcedureInfo /* Return Info version of the current Item */
|
||
{ get { return ProcedureInfo.Get(ItemID); } }
|
||
public new static Procedure Get(int itemID)
|
||
{
|
||
if (!CanGetObject())
|
||
throw new System.Security.SecurityException("User not authorized to view a Item");
|
||
try
|
||
{
|
||
Item itm = GetCachedByPrimaryKey(itemID);
|
||
Procedure tmp = itm as Procedure;
|
||
//Procedure tmp = (Procedure)GetExistingByPrimaryKey(itemID);
|
||
if (tmp == null)
|
||
{
|
||
if (itm != null) Console.WriteLine("type = {0}", itm.GetType().Name);
|
||
tmp = DataPortal.Fetch<Procedure>(new PKCriteria(itemID));
|
||
AddToCache(tmp);
|
||
}
|
||
if (tmp.ErrorMessage == "No Record Found") tmp = null;
|
||
return tmp;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
throw new DbCslaException("Error on Item.Get", ex);
|
||
}
|
||
}
|
||
public new Procedure Save()
|
||
{
|
||
return (Procedure)base.Save();
|
||
}
|
||
public static Procedure MakeProcedure(IVEDrillDownReadOnly parentInfo, ItemInfo previousInfo, string procNumber, string procTitle, int procType)
|
||
{
|
||
int newitemid = MakeNewItem(parentInfo, previousInfo, procNumber, procTitle, procType, E_FromType.Procedure);
|
||
return Procedure.Get(newitemid);
|
||
}
|
||
#region ProcedureConfig
|
||
[NonSerialized]
|
||
private ProcedureConfig _ProcedureConfig;
|
||
public ProcedureConfig ProcedureConfig
|
||
{
|
||
get
|
||
{
|
||
if (_ProcedureConfig == null)
|
||
{
|
||
_ProcedureConfig = new ProcedureConfig(this);
|
||
_ProcedureConfig.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(_ProcedureConfig_PropertyChanged);
|
||
}
|
||
return _ProcedureConfig;
|
||
}
|
||
}
|
||
private void _ProcedureConfig_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
|
||
{
|
||
MyContent.Config = _ProcedureConfig.ToString();
|
||
}
|
||
#endregion
|
||
}
|
||
#endregion
|
||
#region SectionInfo
|
||
[Serializable()]
|
||
public partial class SectionInfo : ItemInfo, IVEDrillDownReadOnly
|
||
{
|
||
public override void SetupTags()
|
||
{
|
||
MyTab = new Tab(ActiveFormat.PlantFormat.FormatData.SectData.SectionNumber.Font);
|
||
_MyTab.Text = DisplayNumber;
|
||
_MyTab.CleanText = DisplayNumber.PadRight(20);
|
||
MyHeader = new MetaTag(ActiveFormat.PlantFormat.FormatData.SectData.SectionHeader.Font);
|
||
_MyHeader.Text = null;
|
||
MyFooter = null;
|
||
_TagsSetup = true;
|
||
}
|
||
protected override void RefreshFields(Item tmp)
|
||
{
|
||
base.RefreshFields(tmp);
|
||
ExtensionRefreshFields(tmp);
|
||
}
|
||
#if ItemWithContent
|
||
public SectionInfo(SafeDataReader dr) : base(dr, true) { }
|
||
#else
|
||
public SectionInfo(SafeDataReader dr) : base(dr) { }
|
||
#endif
|
||
private SectionInfo() : base() { ;}
|
||
public new static SectionInfo Get(int itemID)
|
||
{
|
||
//if (!CanGetObject())
|
||
// throw new System.Security.SecurityException("User not authorized to view a Item");
|
||
try
|
||
{
|
||
SectionInfo tmp = GetCachedByPrimaryKey(itemID) as SectionInfo;
|
||
if (tmp == null)
|
||
{
|
||
tmp = DataPortal.Fetch<SectionInfo>(new PKCriteria(itemID));
|
||
AddToCache(tmp);
|
||
}
|
||
if (tmp.ErrorMessage == "No Record Found") tmp = null;
|
||
return tmp;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
throw new DbCslaException("Error on Item.Get", ex);
|
||
}
|
||
}
|
||
public void MoveSection(IVEDrillDownReadOnly pInfo, int index)
|
||
{
|
||
using (Item ii = Item.Get(this.ItemID))
|
||
{
|
||
ii.MoveItem(pInfo, index);
|
||
}
|
||
}
|
||
public new Section Get()
|
||
{
|
||
return (Section)(_Editable = Section.Get(ItemID));
|
||
}
|
||
#region SectionConfig
|
||
[NonSerialized]
|
||
private SectionConfig _SectionConfig;
|
||
public SectionConfig SectionConfig
|
||
{ get { return (_SectionConfig != null ? _SectionConfig : _SectionConfig = new SectionConfig(this)); } }
|
||
#endregion
|
||
public new ConfigDynamicTypeDescriptor MyConfig
|
||
{
|
||
get { return SectionConfig; }
|
||
}
|
||
}
|
||
#endregion
|
||
#region Section
|
||
[Serializable()]
|
||
public partial class Section : Item
|
||
{
|
||
public SectionInfo MySectionInfo /* Return Info version of the current Item */
|
||
{ get { return SectionInfo.Get(ItemID); } }
|
||
public new static Section Get(int itemID)
|
||
{
|
||
if (!CanGetObject())
|
||
throw new System.Security.SecurityException("User not authorized to view a Item");
|
||
try
|
||
{
|
||
Section tmp = GetCachedByPrimaryKey(itemID) as Section;
|
||
if (tmp == null)
|
||
{
|
||
tmp = DataPortal.Fetch<Section>(new PKCriteria(itemID));
|
||
AddToCache(tmp);
|
||
}
|
||
if (tmp.ErrorMessage == "No Record Found") tmp = null;
|
||
return tmp;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
throw new DbCslaException("Error on Item.Get", ex);
|
||
}
|
||
}
|
||
public new Section Save()
|
||
{
|
||
return (Section)base.Save();
|
||
}
|
||
public static Section MakeSection(IVEDrillDownReadOnly parentInfo, ItemInfo previousInfo, string sectNumber, string sectTitle, int sectType)
|
||
{
|
||
int newitemid = MakeNewItem(parentInfo, previousInfo, sectNumber, sectTitle, sectType, E_FromType.Section);
|
||
return Section.Get(newitemid);
|
||
}
|
||
#region SectionConfig
|
||
[NonSerialized]
|
||
private SectionConfig _SectionConfig;
|
||
public SectionConfig SectionConfig
|
||
{
|
||
get
|
||
{
|
||
if (_SectionConfig == null)
|
||
{
|
||
_SectionConfig = new SectionConfig(this);
|
||
_SectionConfig.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(_SectionConfig_PropertyChanged);
|
||
}
|
||
return _SectionConfig;
|
||
}
|
||
}
|
||
private void _SectionConfig_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
|
||
{
|
||
MyContent.Config = _SectionConfig.ToString();
|
||
}
|
||
#endregion
|
||
}
|
||
#endregion
|
||
#region StepInfo
|
||
[Serializable()]
|
||
public partial class StepInfo : ItemInfo
|
||
{
|
||
#region Tab
|
||
public override void SetupTags()
|
||
{
|
||
_TagsSetup = true;
|
||
MyTab = new Tab(AdjustForTextSubFollowsTextStyle(FormatStepData.TabData.Font));
|
||
MyHeader = new MetaTag(FormatStepData.TabData.Font);
|
||
MyFooter = new MetaTag(FormatStepData.TabData.Font);
|
||
SetTabText();
|
||
}
|
||
|
||
#endregion
|
||
protected override void RefreshFields(Item tmp)
|
||
{
|
||
base.RefreshFields(tmp);
|
||
ExtensionRefreshFields(tmp);
|
||
}
|
||
//public override string ToString()
|
||
//{
|
||
// return "Step " + base.ToString();
|
||
//}
|
||
#if ItemWithContent
|
||
public StepInfo(SafeDataReader dr) : base(dr, true) { }
|
||
#else
|
||
public StepInfo(SafeDataReader dr) : base(dr) { }
|
||
#endif
|
||
private StepInfo() : base() { ;}
|
||
public new static StepInfo Get(int itemID)
|
||
{
|
||
//if (!CanGetObject())
|
||
// throw new System.Security.SecurityException("User not authorized to view a Item");
|
||
try
|
||
{
|
||
StepInfo tmp = GetCachedByPrimaryKey(itemID) as StepInfo;
|
||
if (tmp == null)
|
||
{
|
||
tmp = DataPortal.Fetch<StepInfo>(new PKCriteria(itemID));
|
||
AddToCache(tmp);
|
||
}
|
||
if (tmp.ErrorMessage == "No Record Found") tmp = null;
|
||
return tmp;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
throw new DbCslaException("Error on Item.Get", ex);
|
||
}
|
||
}
|
||
public void MoveStep(IVEDrillDownReadOnly pInfo, int index)
|
||
{
|
||
using (Item ii = Item.Get(this.ItemID))
|
||
{
|
||
ii.MoveItem(pInfo, index);
|
||
}
|
||
}
|
||
public new Step Get()
|
||
{
|
||
return (Step)(_Editable = Step.Get(ItemID));
|
||
}
|
||
//public E_FromType FromType
|
||
//{ get { return E_FromType.Step; } }
|
||
}
|
||
|
||
#endregion
|
||
#region Step
|
||
[Serializable()]
|
||
public partial class Step : Item
|
||
{
|
||
public new static Step Get(int itemID)
|
||
{
|
||
if (!CanGetObject())
|
||
throw new System.Security.SecurityException("User not authorized to view a Item");
|
||
try
|
||
{
|
||
Step tmp = (Step)GetCachedByPrimaryKey(itemID);
|
||
if (tmp == null)
|
||
{
|
||
tmp = DataPortal.Fetch<Step>(new PKCriteria(itemID));
|
||
AddToCache(tmp);
|
||
}
|
||
if (tmp.ErrorMessage == "No Record Found") tmp = null;
|
||
return tmp;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
throw new DbCslaException("Error on Item.Get", ex);
|
||
}
|
||
}
|
||
// TODO :MakeCaution;
|
||
// TODO :MakeNote;
|
||
// TODO :MakeRNO;
|
||
// TODO :MakeSection;
|
||
// TODO :MakeSubStep;
|
||
// TODO :MakeTable;
|
||
public static Step MakeStep(IVEDrillDownReadOnly parentInfo, ItemInfo previousInfo, string stepNumber, string stepTitle, int stepType, E_FromType fromType)
|
||
{
|
||
int newitemid = MakeNewItem(parentInfo, previousInfo, stepNumber, stepTitle, stepType, fromType);
|
||
return Step.Get(newitemid);
|
||
}
|
||
//#region StepConfig
|
||
//[NonSerialized]
|
||
//private StepConfig _StepConfig;
|
||
//public StepConfig StepConfig
|
||
//{
|
||
// get
|
||
// {
|
||
// if (_StepConfig == null)
|
||
// {
|
||
// _StepConfig = new StepConfig(this);
|
||
// _StepConfig.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(_StepConfig_PropertyChanged);
|
||
// }
|
||
// return _SectionConfig;
|
||
// }
|
||
//}
|
||
//private void _StepConfig_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
|
||
//{
|
||
// MyContent.Config = _StepConfig.ToString();
|
||
//}
|
||
//#endregion
|
||
}
|
||
#endregion
|
||
public enum ItemSearchIncludeLinks
|
||
{
|
||
Nothing = 0,
|
||
Value = 1,
|
||
Everything =2
|
||
}
|
||
}
|