From 1081d01da210070d2cc43c23bae5880bc4a7c302 Mon Sep 17 00:00:00 2001 From: Kathy Date: Fri, 26 Oct 2012 10:21:48 +0000 Subject: [PATCH] --- .../Extension/ItemInsertExt.cs | 49 +++++++++++++++++-- 1 file changed, 46 insertions(+), 3 deletions(-) diff --git a/PROMS/VEPROMS.CSLA.Library/Extension/ItemInsertExt.cs b/PROMS/VEPROMS.CSLA.Library/Extension/ItemInsertExt.cs index eebcb8e3..6a74578a 100644 --- a/PROMS/VEPROMS.CSLA.Library/Extension/ItemInsertExt.cs +++ b/PROMS/VEPROMS.CSLA.Library/Extension/ItemInsertExt.cs @@ -283,7 +283,12 @@ namespace VEPROMS.CSLA.Library } public ItemInfo InsertSiblingBefore(string text, string number) { - ItemInfo tmp = NewItemInfoFetch(ItemID, EAddpingPart.Before, number, text, null, null, null, null, DateTime.Now, Volian.Base.Library.VlnSettings.UserID); + ItemInfo tmp = null; + if (FormatStepData.UseSmartTemplate || MyHLS.FormatStepData.UseSmartTemplate) + 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); + // this item is updated in SQL so we have to manually force the iteminfo updates // Refresh ItemInfo to update Previous using (Item item = Get()) ItemInfo.Refresh(item); @@ -293,6 +298,41 @@ namespace VEPROMS.CSLA.Library ((ItemInfo)ActiveParent).MyContent.RefreshContentParts(); return tmp; } + + 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(); + if (tpIndx != -1) + { + bool firstInsert = true; + ItemInfo tmpSmart = null; + ItemInfo subSmart = null; + int level = FormatStepData.MyFormat.PlantFormat.FormatData.Templates[tpIndx].level; + while (level > 0) + { + if (firstInsert) + { + subSmart = NewItemInfoFetch(ItemID, adPart, number, text, type, null, null, null, DateTime.Now, Volian.Base.Library.VlnSettings.UserID); + tmpSmart = subSmart; + firstInsert = false; + newItemID = subSmart.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); + newItemID = tmp.ItemID; + } + tpIndx++; + level = tpIndx < FormatStepData.MyFormat.PlantFormat.FormatData.Templates.Count ? + FormatStepData.MyFormat.PlantFormat.FormatData.Templates[tpIndx].level : -1; + } + tmp = tmpSmart; + } + return tmp; + } #endregion #region PasteSiblingBefore public ItemInfo PasteSiblingBefore(int copyStartID) @@ -369,8 +409,11 @@ namespace VEPROMS.CSLA.Library } public ItemInfo InsertSiblingAfter(string text, string number, int? type) { - ItemInfo tmp = NewItemInfoFetch(ItemID, EAddpingPart.After, number, text, type, null, null, null, DateTime.Now, Volian.Base.Library.VlnSettings.UserID); - //tmp = DataPortal.Fetch(new AddingPartCriteria(ItemID, EAddpingPart.After, number, text, type, null, null, null, DateTime.Now, Volian.Base.Library.VlnSettings.UserID)); + ItemInfo tmp = null; + if (FormatStepData.UseSmartTemplate || MyHLS.FormatStepData.UseSmartTemplate) + 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); // if next exists, it is updated in SQL so we have to manually force the iteminfo updates // Refresh ItemInfo to update PreviousID field if (tmp.NextItem != null) using (Item item = tmp.NextItem.Get()) ItemInfo.Refresh(item);