From e3131bfff9506bc7839bd5749f9ee38351308cbb Mon Sep 17 00:00:00 2001 From: Kathy Date: Mon, 14 Mar 2011 11:33:53 +0000 Subject: [PATCH] --- PROMS/Volian.Controls.Library/GridItem.cs | 147 ++++++++++++++++++++++ 1 file changed, 147 insertions(+) diff --git a/PROMS/Volian.Controls.Library/GridItem.cs b/PROMS/Volian.Controls.Library/GridItem.cs index 07205aa3..b7fe9254 100644 --- a/PROMS/Volian.Controls.Library/GridItem.cs +++ b/PROMS/Volian.Controls.Library/GridItem.cs @@ -216,6 +216,14 @@ namespace Volian.Controls.Library MyFlexGrid.Select(MyFlexGrid.Selection); } } + private string MyFlexGrid_AdjustPastedText(object sender, VlnFlexGridPasteEventArgs args) + { + string tmpForLink = args.Text; + tmpForLink = Regex.Replace(tmpForLink, @"#Link:ReferencedObject:[0-9]+ ", @"#Link:ReferencedObject: "); + tmpForLink = Regex.Replace(tmpForLink, @"#Link:Transition:([0-9]+) [0-9]+ ", @"#Link:Transition:$1 "); + tmpForLink = Regex.Replace(tmpForLink, @"#Link:TransitionRange:([0-9]+) [0-9]+ ", @"#Link:TransitionRange:$1 "); + return tmpForLink; + } #endregion // Event Handlers #region Constructors public GridItem() @@ -258,7 +266,10 @@ namespace Volian.Controls.Library this.MyFlexGrid.SelChange += new EventHandler(MyFlexGrid_SelChange); this.MyStepRTB.GotFocus += new EventHandler(MyStepRTB_GotFocus); this.MyStepRTB.RoInsert += new StepRTBRoEvent(MyStepRTB_RoInsert); + this.MyFlexGrid.AdjustPastedText += new VlnFlexGridPasteEvent(MyFlexGrid_AdjustPastedText); } + + void MyStepRTB_RoInsert(object sender, StepRTBRoEventArgs args) { if (MyFlexGrid.IsRoTable) @@ -504,6 +515,15 @@ namespace Volian.Controls.Library } return true; } + public void BasicSave() + { + using (Item itm = MyItemInfo.Get()) + { + itm.MyContent.MyGrid.Data = MyFlexGrid.GetXMLData(); + itm.Save(); + //MyItemInfo.MyContent.MyGrid.ResetContent(itm.MyContent.MyGrid); + } + } public override bool CanExpand { get { return false; } set { ;} } public override void HandleResize() { ;} // DONE public override void MatchExpanded() { ;} // DONE @@ -836,6 +856,133 @@ namespace Volian.Controls.Library SaveContents(); } public override void SetExpandAndExpander(ItemInfo itemInfo) { CanExpand = false; } // can't expand a table + public void SavePastedCellRoTran() + { + if (!MyFlexGrid.GetXMLData().Contains("<NewID>")) return; + BasicSave(); + // need to loop thru all pasted cells: for now do all cells. + int w = MyFlexGrid.Cols.Count; + int h = MyFlexGrid.Rows.Count; + int r = 0; + int c = 0; + String Rtf = null; + while (r < h) + { + CellRange cr = MyFlexGrid.GetMergedRange(r, c); + if (cr.r1 == r && cr.c1 == c) + { + Rtf = (string)MyFlexGrid[r, c]; + if (Rtf != null) + { + int startIndx = 0; + while (Rtf.IndexOf("") > -1) + { + // first find the new link and determine whether it's RO or transition. + int indx = Rtf.IndexOf(@"#Link:ReferencedObject:", startIndx); + if (indx > 0) + { + // only look in the substring limited by the first occurrance of [END>. If there is more + // than one, don't get multiple links in the string. + int endindx = Rtf.IndexOf(@"END>", indx) + 4; + Match mro = Regex.Match(Rtf.Substring(indx, endindx - 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; + int newid = Rtf.IndexOf("", indx); + Rtf = Rtf.Remove(newid, 7); + Rtf = Rtf.Insert(newid, string.Format("", rousg.ROUsageID)); + itm.Save(); + Rtf = Rtf.Replace(string.Format("", oldid), rousg.ROUsageID.ToString()); + itm.Save(); + MyItemInfo.MyContent.RefreshContentRoUsages(); + } + startIndx = endindx; + } + else + { + Match mt = Regex.Match(Rtf, @"#Link:Transition:([0-9]+) "); + if (mt.Length <= 0) mt = Regex.Match(Rtf, @"#Link:TransitionRange:([0-9]+) "); + if (mt.Length > 0) + { + int endtindx = Rtf.IndexOf("END>", mt.Index) + 4; + indx = mt.Index + 6; // get past '#Link:" + Match m = Regex.Match(Rtf.Substring(indx, endtindx - 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; + int newidt = Rtf.IndexOf("", indx); + Rtf = Rtf.Remove(newidt, 7); + Rtf = Rtf.Insert(newidt, string.Format("", ct.TransitionID)); + //Rtf = Rtf.Replace("", string.Format("", ct.TransitionID)); + itm.Save(); + Rtf = Rtf.Replace(string.Format("", oldidt), ct.TransitionID.ToString()); + itm.Save(); + MyItemInfo.MyContent.RefreshContentTransitions(); + } + if (dispose2) itm2.Dispose(); + if (dispose1) itm1.Dispose(); + } + } + } + MyFlexGrid[r, c] = Rtf; + } + } + c = c + 1; + if (c == w) + { + c = 0; + r = r + 1; + } + } + } public override void SaveCurrentAndContents() { if (MyFlexGrid.Row >= 0 && MyFlexGrid.Col >= 0 && MyStepRTB.EditMode) // Only if a Cell is Selected