diff --git a/PROMS/VEPROMS.CSLA.Library/Extension/ItemInsertExt.cs b/PROMS/VEPROMS.CSLA.Library/Extension/ItemInsertExt.cs index b661505f..a26925eb 100644 --- a/PROMS/VEPROMS.CSLA.Library/Extension/ItemInsertExt.cs +++ b/PROMS/VEPROMS.CSLA.Library/Extension/ItemInsertExt.cs @@ -284,7 +284,7 @@ namespace VEPROMS.CSLA.Library public ItemInfo InsertSiblingBefore(string text, string number) { ItemInfo tmp = null; - if (!IsSection && (FormatStepData.UseSmartTemplate || MyHLS.FormatStepData.UseSmartTemplate)) + if (!IsSection && (FormatStepData.UseSmartTemplate || MyHLS.FormatStepData.UseSmartTemplate || FormatStepData.UseOldTemplate)) tmp = InsertSmartTemplateSteps(text, number, tmp, EAddpingPart.Before, (int)MyContent.Type); else tmp = NewItemInfoFetch(ItemID, EAddpingPart.Before, number, text, null, null, null, null, DateTime.Now, Volian.Base.Library.VlnSettings.UserID); @@ -302,34 +302,54 @@ namespace VEPROMS.CSLA.Library private ItemInfo InsertSmartTemplateSteps(string text, string number, ItemInfo tmp, EAddpingPart adPart, int type) { int newItemID = 0; - // this step type may be a template step, if so, we need to put out edit windows for - // the template, by making these 'empty' (one space) steps: - int tpIndx = GetSmartTemplateIndex(); + int topType = GetSmartTemplateTopLevelIndx(); + if (topType == -1) return null; + int tpIndx = GetSmartTemplateIndex(topType, (int)MyContent.Type); if (tpIndx != -1) { - bool firstInsert = true; - ItemInfo tmpSmart = null; - ItemInfo subSmart = null; + ItemInfo siblingSmart = null; + ItemInfo firstSmart = null; int level = FormatStepData.MyFormat.PlantFormat.FormatData.Templates[tpIndx].level; + string tmptext = FormatStepData.MyFormat.PlantFormat.FormatData.NewTemplateFormat?text:FormatStepData.MyFormat.PlantFormat.FormatData.Templates[tpIndx].text; + int prevlevel = level; while (level > 0) { - if (firstInsert) + if (firstSmart == null) { - subSmart = NewItemInfoFetch(ItemID, adPart, number, text, type, null, null, null, DateTime.Now, Volian.Base.Library.VlnSettings.UserID); - tmpSmart = subSmart; - firstInsert = false; - newItemID = subSmart.ItemID; + firstSmart = NewItemInfoFetch(ItemID, adPart, number, tmptext, type, null, null, null, DateTime.Now, Volian.Base.Library.VlnSettings.UserID); + siblingSmart = firstSmart; + newItemID = firstSmart.ItemID; } else { - tmp = NewItemInfoFetch(newItemID, EAddpingPart.Child, null, " ", FormatStepData.MyFormat.PlantFormat.FormatData.Templates[tpIndx].type + 20001, (int?)E_FromType.Step, null, null, DateTime.Now, Volian.Base.Library.VlnSettings.UserID); + E_FromType fromType = E_FromType.Step; + EAddpingPart addPart = EAddpingPart.Child; // level > previous, add a child. + if (level == prevlevel) addPart = EAddpingPart.After; + if (level < prevlevel) + { + if (FormatStepData.MyFormat.PlantFormat.FormatData.Templates[tpIndx].type == 39) + { + fromType = E_FromType.RNO; + addPart = EAddpingPart.Child; + } + else + { + addPart = EAddpingPart.After; + } + newItemID = siblingSmart.ItemID; + } + + tmptext = FormatStepData.MyFormat.PlantFormat.FormatData.NewTemplateFormat ? " ": FormatStepData.MyFormat.PlantFormat.FormatData.Templates[tpIndx].text; + tmp = NewItemInfoFetch(newItemID, addPart, null, tmptext, FormatStepData.MyFormat.PlantFormat.FormatData.Templates[tpIndx].type + 20001, (int ?)fromType, null, null, DateTime.Now, Volian.Base.Library.VlnSettings.UserID); newItemID = tmp.ItemID; + if (level < prevlevel) siblingSmart = tmp; } tpIndx++; + prevlevel = level; level = tpIndx < FormatStepData.MyFormat.PlantFormat.FormatData.Templates.Count ? FormatStepData.MyFormat.PlantFormat.FormatData.Templates[tpIndx].level : -1; } - tmp = tmpSmart; + tmp = firstSmart; } return tmp; } @@ -427,7 +447,7 @@ namespace VEPROMS.CSLA.Library public ItemInfo InsertSiblingAfter(string text, string number, int? type) { ItemInfo tmp = null; - if (!IsSection &&(FormatStepData.UseSmartTemplate || MyHLS.FormatStepData.UseSmartTemplate)) + if (!IsSection && (FormatStepData.UseSmartTemplate || MyHLS.FormatStepData.UseSmartTemplate || FormatStepData.UseOldTemplate)) tmp = InsertSmartTemplateSteps(text, number, tmp, EAddpingPart.After, (int)MyContent.Type); else tmp = NewItemInfoFetch(ItemID, EAddpingPart.After, number, text, type, null, null, null, DateTime.Now, Volian.Base.Library.VlnSettings.UserID); diff --git a/PROMS/VEPROMS.CSLA.Library/Format/PlantFormat.cs b/PROMS/VEPROMS.CSLA.Library/Format/PlantFormat.cs index 85008587..07ed5da1 100644 --- a/PROMS/VEPROMS.CSLA.Library/Format/PlantFormat.cs +++ b/PROMS/VEPROMS.CSLA.Library/Format/PlantFormat.cs @@ -194,6 +194,33 @@ namespace VEPROMS.CSLA.Library return LazyLoad(ref _TPL, "@TPL"); } } + private bool _NewTemplateFormat; + public bool NewTemplateFormat + { + get { return _NewTemplateFormat; } + set { _NewTemplateFormat = value; } + } + private Dictionary _TopTemplateTypes; + public Dictionary TopTemplateTypes + { + get + { + if (_TopTemplateTypes == null) + { + _TopTemplateTypes = new Dictionary(); + // loop through all of templates to find those that are top level, i.e. + // right below the '0'. + int indx = 0; + while (indx < Templates.Count) + { + // level of 0 starts a new group. + if (Templates[indx].level == 0) TopTemplateTypes[Templates[indx + 1].type] = indx+1; + indx++; + } + } + return _TopTemplateTypes; + } + } private List _Templates; public List Templates { @@ -201,7 +228,7 @@ namespace VEPROMS.CSLA.Library { if (_Templates == null) // Load template class from format's string data. { - bool oldformat = true; + NewTemplateFormat = false; // count newlines - which gives number of template records. int NumTemplates = 0; int indx = TPL.IndexOf('\n'); @@ -214,7 +241,7 @@ namespace VEPROMS.CSLA.Library _Templates = new List(NumTemplates); // for each item, create and add to list - if (TPL.IndexOf(',') > -1) oldformat = false; + if (TPL.IndexOf(',') > -1) NewTemplateFormat = true; int cnt = 0; int tmpStrIndxStart = 0; @@ -231,7 +258,7 @@ namespace VEPROMS.CSLA.Library int nocol = 0; int row = 0; string stmp = null; - if (oldformat) + if (!NewTemplateFormat) { string[] tmpOld = tpl.Split(" ".ToCharArray()); level = Convert.ToInt32(tmpOld[0]); @@ -3669,6 +3696,14 @@ namespace VEPROMS.CSLA.Library return LazyLoad(ref _UseSmartTemplate, "@UseSmartTemplate"); } } + private LazyLoad _UseOldTemplate; + public bool UseOldTemplate + { + get + { + return LazyLoad(ref _UseOldTemplate, "@UseOldTemplate"); + } + } private LazyLoad _AlwaysUseExtraLines; public bool AlwaysUseExtraLines {