diff --git a/PROMS/VEPROMS.CSLA.Library/Extension/DocumentExt.cs b/PROMS/VEPROMS.CSLA.Library/Extension/DocumentExt.cs index 7be91644..7b1e644f 100644 --- a/PROMS/VEPROMS.CSLA.Library/Extension/DocumentExt.cs +++ b/PROMS/VEPROMS.CSLA.Library/Extension/DocumentExt.cs @@ -497,7 +497,7 @@ namespace VEPROMS.CSLA.Library { // make new document with 'no' libtitle. Then link this to the item/content via the entry. // the data gets set below. - Document tdoc = Document.MakeDocument(null, null, null, null); + Document tdoc = Document.MakeDocument(null, null, null, null, null); _MyDocument = DocumentInfo.Get(doc.DocID); doc = tdoc; using (Entry ent = myItemInfo.MyContent.MyEntry.Get()) diff --git a/PROMS/VEPROMS.CSLA.Library/Extension/ItemInsertExt.cs b/PROMS/VEPROMS.CSLA.Library/Extension/ItemInsertExt.cs index d2e568b6..d8f986f9 100644 --- a/PROMS/VEPROMS.CSLA.Library/Extension/ItemInsertExt.cs +++ b/PROMS/VEPROMS.CSLA.Library/Extension/ItemInsertExt.cs @@ -6,6 +6,7 @@ using System.Data.SqlClient; using System.Text.RegularExpressions; using Csla; using Csla.Data; +using System.Windows.Forms; namespace VEPROMS.CSLA.Library { @@ -32,6 +33,58 @@ namespace VEPROMS.CSLA.Library } public partial class ItemInfo { + public ItemInfo HandleSqlExceptionOnDelete(Exception ex) + { + if (ex.Message.Contains("has External Transitions and has no next step")) + { + using (TransitionInfoList exTrans = TransitionInfoList.GetExternalTransitionsToChildren(ItemID)) + { + DialogResult ans = MessageBox.Show("Transitions exist to this step and cannot be adjusted automatically." + + "\r\n\r\nDo you want to be placed on the " + (exTrans.Count > 1 ? "first " : "") + "substep with the problem Transition?" + + "\r\n\r\nSubsteps with Problem Transitions" + + exTrans.Summarize(), + "Cannot Delete This Step", MessageBoxButtons.YesNo, MessageBoxIcon.Question); + if (ans == DialogResult.Yes) + { + return exTrans[0].MyContent.ContentItems[0]; + } + } + } + else if (ex.Message.Contains("has External Transitions to Procedure")) + { + using (TransitionInfoList exTrans = TransitionInfoList.GetExternalTransitionsToChildren(ItemID)) + { + DialogResult ans = MessageBox.Show("Transitions exist to this procedure and cannot be adjusted automatically." + + "\r\n\r\nDo you want to be placed on the " + (exTrans.Count > 1 ? "first " : "") + "substep with the problem Transition?" + + "\r\n\r\nSubsteps with Problem Transitions" + + exTrans.Summarize(), + "Cannot Delete This Procedure", MessageBoxButtons.YesNo, MessageBoxIcon.Question); + if (ans == DialogResult.Yes) + { + return exTrans[0].MyContent.ContentItems[0]; + } + } + } + else if (ex.Message.Contains("has External Transitions to it's children")) + { + using (TransitionInfoList exTrans = TransitionInfoList.GetExternalTransitionsToChildren(ItemID)) + { + DialogResult ans = MessageBox.Show("Transitions exist to substeps of this step and cannot be adjusted automatically." + + "\r\n\r\nDo you want to be placed on the " + (exTrans.Count > 1 ? "first " : "") + "substep with the problem Transition?" + + "\r\n\r\nSubsteps with Problem Transitions:" + + exTrans.Summarize(), + "Cannot Delete This Step", MessageBoxButtons.YesNo, MessageBoxIcon.Question); + if (ans == DialogResult.Yes) + { + return exTrans[0].MyContent.ContentItems[0]; + } + } + } + else + MessageBox.Show(ex.Message, "SQL Exception", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); + return null; + } + #region Old Insert //public ItemInfo InsertSiblingBeforeOld(string text) //{ @@ -605,7 +658,7 @@ namespace VEPROMS.CSLA.Library ItemInfo tmp = null; if (!IsSection && (FormatStepData.UseSmartTemplate || (MyHLS != null && MyHLS.FormatStepData.UseSmartTemplate) || FormatStepData.UseOldTemplate)) tmp = InsertSmartTemplateSteps(text, number, tmp, EAddpingPart.After, (int)MyContent.Type); - if(tmp == null) + if (tmp == null) 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 @@ -784,6 +837,156 @@ namespace VEPROMS.CSLA.Library return tmp; } #endregion + #region Enhanced Document Support + public ItemInfo InsertEnhancedSteps(string text, string number, EAddpingPart addType, int? type, int eDocType, int newSourceID) + //public ItemInfo InsertEnhancedSiblingAfter(string text, string number, int? type, int eDocType, int newID) + { + ItemInfo tmp = null; + if (addType == EAddpingPart.Child) + { + E_FromType fromType = E_FromType.Caution; + if (ActiveFormat.PlantFormat.FormatData.StepDataList[(int)type- 20000].Type.ToUpper() == "NOTE") fromType = E_FromType.Note; + tmp = InsertEnhancedSmartTemplateSubStep(text, number, this, addType, (int)type, fromType, newSourceID); + } + else + tmp = InsertEnhancedSmartTemplateSteps(text, number, this, addType, (int)type, newSourceID); + //ItemInfo tmp = InsertEnhancedSmartTemplateSteps(text, number, this, EAddpingPart.After, (int)MyContent.Type, newID); + // 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); + RefreshNextItems(); + // if inserting after a caution or note, refreshes tabs. This will adjust bullets + // of any previous cautions or notes. + if (tmp.IsCaution || tmp.IsNote) ResetOrdinal(); + // Update all of the content records that have transitions that point to the Siblings or Sibling Children of the new item + //tmp.UpdateTransitionText(); + tmp.UpdateROText(); + //?? OnNewSiblingAfter(new ItemInfoInsertEventArgs(tmp, EAddpingPart.After)); + return tmp; + } + + private ItemInfo InsertEnhancedSmartTemplateSubStep(string text, string number, ItemInfo tmp, EAddpingPart addType, int type, E_FromType fromTypeTop, int newID) + { + int newItemID = 0; + int topType = GetSmartTemplateTopLevelIndxOfThisType(type); + if (topType == -1) return null; + int tpIndx = GetSmartTemplateIndex(topType, type); + if (tpIndx != -1) + { + ItemInfo siblingSmart = null; + ItemInfo firstSmart = null; + int level = ActiveFormat.PlantFormat.FormatData.Templates[tpIndx].level; + string tmptext = ActiveFormat.PlantFormat.FormatData.NewTemplateFormat ? text : ActiveFormat.PlantFormat.FormatData.Templates[tpIndx].text; + int prevlevel = level; + while (level > 0) + { + if (firstSmart == null) + { + // set stepconfig for this new enhanced item: + StepConfig sc = new StepConfig(""); + sc.AddEnhancedDocument(0, newID); + + firstSmart = NewItemInfoFetch(ItemID, addType, number, tmptext, type, (int?)fromTypeTop, null, null, DateTime.Now, Volian.Base.Library.VlnSettings.UserID); + siblingSmart = firstSmart; + newItemID = firstSmart.ItemID; + } + else + { + 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 (ActiveFormat.PlantFormat.FormatData.Templates[tpIndx].type == 39) + { + fromType = E_FromType.RNO; + addPart = EAddpingPart.Child; + } + else + { + addPart = EAddpingPart.After; + } + newItemID = siblingSmart.ItemID; + } + + tmptext = /*ActiveFormat.PlantFormat.FormatData.NewTemplateFormat ? " ": */ActiveFormat.PlantFormat.FormatData.Templates[tpIndx].text; + tmp = NewItemInfoFetch(newItemID, addPart, null, tmptext, ActiveFormat.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 < ActiveFormat.PlantFormat.FormatData.Templates.Count ? + ActiveFormat.PlantFormat.FormatData.Templates[tpIndx].level : -1; + } + tmp = firstSmart; + } + return tmp; + } + private ItemInfo InsertEnhancedSmartTemplateSteps(string text, string number, ItemInfo tmp, EAddpingPart eAddpingPart, int type, int newSourceID) + { + int newItemID = 0; + int topType = GetSmartTemplateTopLevelIndx(); + if (topType == -1) return null; + int tpIndx = GetSmartTemplateIndex(topType, (int)MyContent.Type); + if (tpIndx != -1) + { + ItemInfo siblingSmart = null; // keep track of sibling + ItemInfo firstSmart = null; // hls or top template step + ItemInfo parentSmart = null; // keep track of parent as creating children + int level = ActiveFormat.PlantFormat.FormatData.Templates[tpIndx].level; + string tmptext = text; + int prevlevel = level; + while (level > 0) + { + if (firstSmart == null) + { + // set stepconfig for this new enhanced item: + StepConfig sc = new StepConfig("" ); + sc.AddEnhancedDocument(0, newSourceID); + firstSmart = CopyPasteItemInfoFetch(newSourceID, this.ItemID, type, type, eAddpingPart); + //firstSmart = NewItemInfoFetch(ItemID, eAddpingPart, number, tmptext, type, null, null, sc.ToString(), DateTime.Now, Volian.Base.Library.VlnSettings.UserID); + siblingSmart = parentSmart = firstSmart; + newItemID = firstSmart.ItemID; + } + else + { + E_FromType fromType = E_FromType.Step; + EAddpingPart addPart = EAddpingPart.Child; // level > previous, add a child. + if (level == prevlevel) addPart = EAddpingPart.After; // level = previous, add a sibling + if (level < prevlevel) // level < previous, go up to previous level's id + { + if (ActiveFormat.PlantFormat.FormatData.Templates[tpIndx].type == 39) + { + fromType = E_FromType.RNO; + addPart = EAddpingPart.Child; + newItemID = firstSmart.ItemID; + } + else + { + addPart = EAddpingPart.After; + newItemID = parentSmart.ItemID; + } + } + + tmptext = ActiveFormat.PlantFormat.FormatData.Templates[tpIndx].text; + tmp = NewItemInfoFetch(newItemID, addPart, null, tmptext, ActiveFormat.PlantFormat.FormatData.Templates[tpIndx].type + 20001, (int?)fromType, null, null, DateTime.Now, Volian.Base.Library.VlnSettings.UserID); + newItemID = tmp.ItemID; + if (level < prevlevel) siblingSmart = parentSmart; + else if (level > prevlevel) parentSmart = siblingSmart; + if (level == prevlevel) siblingSmart = tmp; + } + tpIndx++; + prevlevel = level; + level = tpIndx < ActiveFormat.PlantFormat.FormatData.Templates.Count ? + ActiveFormat.PlantFormat.FormatData.Templates[tpIndx].level : -1; + } + tmp = firstSmart; + } + + return tmp; + } + #endregion #region DataPortal private void DataPortal_Fetch(PastingPartCriteria criteria) { @@ -792,7 +995,7 @@ namespace VEPROMS.CSLA.Library { using (SqlConnection cn = Database.VEPROMS_SqlConnection) { - ApplicationContext.LocalContext["cn"] = cn; + Csla.ApplicationContext.LocalContext["cn"] = cn; using (SqlCommand cm = cn.CreateCommand()) { cm.CommandType = CommandType.StoredProcedure; @@ -833,8 +1036,8 @@ namespace VEPROMS.CSLA.Library } } // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); + if (Csla.ApplicationContext.ExecutionLocation == Csla.ApplicationContext.ExecutionLocations.Client) + Csla.ApplicationContext.LocalContext.Remove("cn"); } } catch (Exception ex) @@ -854,7 +1057,7 @@ namespace VEPROMS.CSLA.Library { using (SqlConnection cn = Database.VEPROMS_SqlConnection) { - ApplicationContext.LocalContext["cn"] = cn; + Csla.ApplicationContext.LocalContext["cn"] = cn; using (SqlCommand cm = cn.CreateCommand()) { cm.CommandType = CommandType.StoredProcedure; @@ -895,8 +1098,8 @@ namespace VEPROMS.CSLA.Library } } // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); + if (Csla.ApplicationContext.ExecutionLocation == Csla.ApplicationContext.ExecutionLocations.Client) + Csla.ApplicationContext.LocalContext.Remove("cn"); } } catch (Exception ex) @@ -1367,6 +1570,8 @@ namespace VEPROMS.CSLA.Library } catch (Exception ex) { + ItemInfo iii = itemInfo.HandleSqlExceptionOnDelete(ex); + if (iii != null) return iii; if (!HandleSqlExceptionOnCopy(ex)) { if (ex.Message.Contains("has External Transitions and has no next step")