From e389cbd5befe13040ef99bf8fc0b627015ea5bca Mon Sep 17 00:00:00 2001 From: Kathy Date: Mon, 14 Feb 2011 15:51:02 +0000 Subject: [PATCH] --- PROMS/Volian.Controls.Library/StepRTB.cs | 87 ++++++++++++++++++++++++ 1 file changed, 87 insertions(+) diff --git a/PROMS/Volian.Controls.Library/StepRTB.cs b/PROMS/Volian.Controls.Library/StepRTB.cs index 58581908..dacac3df 100644 --- a/PROMS/Volian.Controls.Library/StepRTB.cs +++ b/PROMS/Volian.Controls.Library/StepRTB.cs @@ -2661,6 +2661,93 @@ namespace Volian.Controls.Library } #endregion + #region + public string DoNewLinkInGridCell() + { + // first find the new link and determine whether it's RO or transition. + int indx = Rtf.IndexOf(@"#Link:ReferencedObject:"); + if (indx>0) + { + Match mro = Regex.Match(Rtf.Substring(indx,Rtf.Length-indx), @"([A-Za-z]*):(.*)\[END>"); + string linkstr = mro.Groups[2].Value; + string[] roparts = linkstr.Split(" ".ToCharArray()); + ContentRoUsage rousg = null; + int oldid = -1; + using (Item itm = MyItemInfo.Get()) + { + using (RODb rodb = RODb.GetJustRoDb(Convert.ToInt32(roparts[2]))) + { + rousg = itm.MyContent.ContentRoUsages.Add(roparts[1], rodb); + } + oldid = rousg.ROUsageID; + Rtf = Rtf.Replace("", string.Format("", rousg.ROUsageID)); + itm.Save(); + Rtf = Rtf.Replace(string.Format("", oldid), rousg.ROUsageID.ToString()); + itm.Save(); + } + } + Match mt = Regex.Match(Rtf, "Transition.*:.* "); + if (mt.Length > 0) + { + indx = mt.Index; + Match m = Regex.Match(Rtf.Substring(indx, Rtf.Length - indx), @"([A-Za-z]*):(.*)\[END>"); + bool isSingleTran = true; + if (Rtf.Substring(indx,16).IndexOf("TransitionRange")>=0) isSingleTran = false; + string linkstr = m.Groups[2].Value; + string[] tparts = linkstr.Split(" ".ToCharArray()); + int type = System.Convert.ToInt32(tparts[0]); + int tr1 = System.Convert.ToInt32(tparts[2]); // tparts[2] is token for tranid + int tr2 = tr1; + if (tparts.Length > 3) + tr2 = System.Convert.ToInt32(tparts[3]); // tparts[3] is token for rangeid + bool dispose1 = false; + Item itm1 = null; + bool dispose2 = false; + Item itm2 = null; + using (Item itm = MyItemInfo.Get()) + { + if (itm.ItemID == tr1) + itm1 = itm; // a transition that points to itself should not dispose + else + { + dispose1 = true; + itm1 = Item.Get(tr1); + } + if (itm.ItemID == tr2) + itm2 = itm; // a transition that points to itself should not dispose + else if (tr1 == tr2) + itm2 = itm1; // if both destinations are the same only dispose the first one + else + { + dispose2 = true; + itm2 = Item.Get(tr2); + } + ContentTransition ct = itm.MyContent.ContentTransitions.Add(itm1, itm2); + //Console.WriteLine("CT {0},{1},{2},{3}", ct.TransitionID, itm.ItemID, itm.MyContent.MyContentUnique, itm.MyContent.ContentTransitions.Count); + ct.TranType = type; + + if (isSingleTran) + ct.IsRange = 0; + else if (tr1 != tr2) + ct.IsRange = 1; + else + ct.IsRange = 2; + + int oldidt = ct.TransitionID; + Rtf = Rtf.Replace("", string.Format("", ct.TransitionID)); + itm.Save(); + Rtf = Rtf.Replace(string.Format("", oldidt), ct.TransitionID.ToString()); + itm.Save(); + } + + if (dispose2) itm2.Dispose(); + if (dispose1) itm1.Dispose(); + } + + return Rtf; + } + #endregion + #region Debug private bool _ShowDebug = false; public bool ShowDebug