From 287707438e5ff3d11836121b0ef9708e2443a755 Mon Sep 17 00:00:00 2001 From: Kathy Date: Tue, 1 Mar 2011 13:26:22 +0000 Subject: [PATCH] --- .../GridItem.Designer.cs | 1 + PROMS/Volian.Controls.Library/GridItem.cs | 190 ++++++++++++++---- 2 files changed, 150 insertions(+), 41 deletions(-) diff --git a/PROMS/Volian.Controls.Library/GridItem.Designer.cs b/PROMS/Volian.Controls.Library/GridItem.Designer.cs index 901c7d86..966e5844 100644 --- a/PROMS/Volian.Controls.Library/GridItem.Designer.cs +++ b/PROMS/Volian.Controls.Library/GridItem.Designer.cs @@ -18,6 +18,7 @@ namespace Volian.Controls.Library components.Dispose(); } base.Dispose(disposing); + MyItemInfo.MyContent.Changed -= new VEPROMS.CSLA.Library.ContentInfoEvent(MyContent_Changed); } #region Component Designer generated code diff --git a/PROMS/Volian.Controls.Library/GridItem.cs b/PROMS/Volian.Controls.Library/GridItem.cs index b61ef14a..03bc84ac 100644 --- a/PROMS/Volian.Controls.Library/GridItem.cs +++ b/PROMS/Volian.Controls.Library/GridItem.cs @@ -29,7 +29,6 @@ namespace Volian.Controls.Library * 3) When data migration of tables, need to include the font if there is a symbol. Move * AddFontTable from StepRTB.cs to a place accessible, such as volian.base. And then * in data migration, will need to know if a font is fixed. - * 4) KBR Paste step crashes. Look at when doing insert. */ #region Fields public VlnFlexGrid MyFlexGrid @@ -76,6 +75,11 @@ namespace Volian.Controls.Library if (MyStepPanel.DisplayItemChanging) return; MyStepRTB.MyItemInfo = MyItemInfo; // should be in vlnFlexGrid MyStepPanel.SelectedEditItem = this; + if (MyFlexGrid.IsRoTable) + { + MyFlexGrid.Cols.Fixed = MyFlexGrid.Cols.Count; + MyFlexGrid.Rows.Fixed = MyFlexGrid.Rows.Count; + } } void MyFlexGrid_KeyDown(object sender, KeyEventArgs e) { @@ -189,7 +193,15 @@ namespace Volian.Controls.Library void MyStepRTB_DoSaveContents(object sender, EventArgs args) { if (MyFlexGrid.Row >= 0 && MyFlexGrid.Col >= 0) // Only if a Cell is Selected - MyFlexGrid[MyFlexGrid.Row, MyFlexGrid.Col] = MyStepRTB.Rtf = MyStepRTB.DoNewLinkInGridCell(); + { + int row = MyFlexGrid.Row; + int col = MyFlexGrid.Col; + SaveContents(); + MyStepRTB.Rtf = MyStepRTB.DoNewLinkInGridCell(); + MyFlexGrid.Row = row; + MyFlexGrid.Col = col; + MyFlexGrid[MyFlexGrid.Row, MyFlexGrid.Col] = MyStepRTB.Rtf; + } SaveContents(); } void MyStepRTB_VisibleChanged(object sender, EventArgs e) @@ -254,14 +266,12 @@ namespace Volian.Controls.Library InitializeComponent(); SetupEventHandlers(); SetupEditItem(itemInfo, myStepPanel, myParentEditItem, myChildRelation, expand, null); - //RefreshDisplay(true); //TODO: is the argument true? } public GridItem(ItemInfo itemInfo, StepPanel myStepPanel, EditItem myParentEditItem, ChildRelation myChildRelation, bool expand, EditItem nextEditItem) { InitializeComponent(); SetupEventHandlers(); SetupEditItem(itemInfo, myStepPanel, myParentEditItem, myChildRelation, expand, nextEditItem); - //RefreshDisplay(true); //TODO: is the argument true? } private void SetupEventHandlers() { @@ -286,6 +296,20 @@ namespace Volian.Controls.Library this.MyStepRTB.KeyDown += new KeyEventHandler(MyStepRTB_KeyDown); this.MyFlexGrid.SelChange += new EventHandler(MyFlexGrid_SelChange); this.MyStepRTB.GotFocus += new EventHandler(MyStepRTB_GotFocus); + this.MyStepRTB.RoInsert += new StepRTBRoEvent(MyStepRTB_RoInsert); + } + void MyStepRTB_RoInsert(object sender, StepRTBRoEventArgs args) + { + if (MyFlexGrid.IsRoTable) + { + MyFlexGrid.Clear(); + ConvertTableToGrid(args.RawValText); + MyFlexGrid.RODbId = args.RODbID; + MyFlexGrid.ROID = args.ROID; + SaveContents(); + } + else + MyStepRTB.UpdateStepRtb(args.LinkText, args.ValText); } void MyStepRTB_GotFocus(object sender, EventArgs e) { @@ -374,45 +398,68 @@ namespace Volian.Controls.Library int w = MyFlexGrid.Cols.Count; int h = MyFlexGrid.Rows.Count; - while (r < h) + string srchtxt = MyFlexGrid.GetSearchableText(); + // find the rousages within the grid cell. If this is an ro table, there will only be one usage + // if it is a modify and there will be no usages if it is new (the usage gets created on the save) + if (!MyFlexGrid.IsRoTable) { - CellRange cr = MyFlexGrid.GetMergedRange(r, c); - if (cr.r1 == r && cr.c1 == c) + while (r < h) { - // see if there are any links and save these so that any deleted ROs or transitions in the - // steprtb can have associated usages/transitions records removed from the database. - string lookFor = string.Format(@""); - MatchCollection matches = Regex.Matches((string)MyFlexGrid[r, c], lookFor); - for (int i = matches.Count - 1; i >= 0; i--) + CellRange cr = MyFlexGrid.GetMergedRange(r, c); + if (cr.r1 == r && cr.c1 == c) { - Match m = matches[i]; - if (m != null && m.Groups.Count > 6 && m.Groups[6].ToString() == "ReferencedObject") + if (MyFlexGrid[r, c] != null) { - Regex regRefObj = new Regex(@"\#Link\:ReferencedObject\:([0-9]*) ([0-9a-zA-Z]*) ([0-9]*)", RegexOptions.Singleline); - Match myMatch = regRefObj.Match(m.Value); - if (myMatch.Success) + // see if there are any links and save these so that any deleted ROs or transitions in the + // steprtb can have associated usages/transitions records removed from the database. + string lookFor = string.Format(@""); + MatchCollection matches = Regex.Matches((string)MyFlexGrid[r, c], lookFor); + for (int i = matches.Count - 1; i >= 0; i--) { - int usgid = int.Parse(myMatch.Groups[1].Value); - RtfRoUsageList.Add(usgid); - } - } - if (m != null && m.Groups.Count > 6 && m.Groups[6].ToString().StartsWith("Transition")) - { - Regex regRefObj = new Regex(@"\#Link\:Transition[a-zA-Z]*\:([0-9]*) ([0-9]*) ([0-9]*)", RegexOptions.Singleline); - Match myMatch = regRefObj.Match(m.Value); - if (myMatch.Success) - { - int tid = int.Parse(myMatch.Groups[2].Value); - RtfTransList.Add(tid); + Match m = matches[i]; + if (m != null && m.Groups.Count > 6 && m.Groups[6].ToString() == "ReferencedObject") + { + Regex regRefObj = new Regex(@"\#Link\:ReferencedObject\:([0-9]*) ([0-9a-zA-Z]*) ([0-9]*)", RegexOptions.Singleline); + Match myMatch = regRefObj.Match(m.Value); + if (myMatch.Success) + { + int usgid = int.Parse(myMatch.Groups[1].Value); + RtfRoUsageList.Add(usgid); + } + } + if (m != null && m.Groups.Count > 6 && m.Groups[6].ToString().StartsWith("Transition")) + { + Regex regRefObj = new Regex(@"\#Link\:Transition[a-zA-Z]*\:([0-9]*) ([0-9]*) ([0-9]*)", RegexOptions.Singleline); + Match myMatch = regRefObj.Match(m.Value); + if (myMatch.Success) + { + int tid = int.Parse(myMatch.Groups[2].Value); + RtfTransList.Add(tid); + } + } } } } + c = c + 1; + if (c == w) + { + c = 0; + r = r + 1; + } } - c = c + 1; - if (c == w) + } + else + { + // new roid is in flexgrid.roid. Compare to previous, if there was a previous. If there + // is a modify RO, then need to delete the existing rousage record because a new usage + // record will get created that contains the selected ROID. + Regex regRefObj = new Regex(@"\#Link\:ReferencedObject\:([0-9]*) ([0-9a-zA-Z]*) ([0-9]*)", RegexOptions.Singleline); + Match myMatch = regRefObj.Match(MyItemInfo.MyContent.Text); + if (myMatch.Success) { - c = 0; - r = r + 1; + int usgid = int.Parse(myMatch.Groups[1].Value); + RoUsageInfo rui = RoUsageInfo.Get(usgid); + if (rui.ROID == MyFlexGrid.ROID)RtfRoUsageList.Add(usgid); } } // compare ro usages & transitions from database and list from grid contents @@ -435,24 +482,62 @@ namespace Volian.Controls.Library foreach (int dt in delTrans) Transition.Delete(dt); } - // now save the resulting Xml text, and the searchable text. - bool success = FinishSave(MyFlexGrid.GetSearchableText()); - if (success) + bool success = FinishSave(srchtxt); + if (success && !MyFlexGrid.IsRoTable) { MyStepRTB.FindAllLinks(); MyStepRTB.OrigRTF = MyStepRTB.Rtf; MyStepRTB.ClearUndo(); } } - + private string DoLinkForRoTable() + { + // if no ro has been defined yet, just return null + if (MyFlexGrid.ROID == null) return null; + ContentRoUsage rousg = null; + using (Item itm = MyItemInfo.Get()) + { + using (RODb rodb = RODb.GetJustRoDb(MyFlexGrid.RODbId)) + { + string padroid = (MyFlexGrid.ROID.Length <= 12) ? MyFlexGrid.ROID + "0000" : MyFlexGrid.ROID; + rousg = itm.MyContent.ContentRoUsages.Add(MyFlexGrid.ROID, rodb); + } + itm.Save(); + } + MyItemInfo.MyContent.RefreshContentRoUsages(); + return string.Format(@"#Link:ReferencedObject:{0} {1} {2}", rousg.ROUsageID, MyFlexGrid.ROID, MyFlexGrid.RODbId); + } + private void ConvertTableToGrid(string valtext) + { + VE_Font vefont = this.MyItemInfo.ActiveFormat.PlantFormat.FormatData.StepDataList.Table.Font; + Font GridFont = new Font(vefont.Family, (float)vefont.Size); + MyFlexGrid.Font = GridFont; + MyFlexGrid.ParseTableFromText(valtext); + MyFlexGrid.AutoSizeCols(); + MyFlexGrid.AutoSizeRows(); + MyFlexGrid.MakeRTFcells(); + } private bool FinishSave(string searchableText) { + // Just in case if the grid was in a mode to change sizes, clear out that setting + // in the grid: + MyFlexGrid.Cols.Fixed = 0; + MyFlexGrid.Rows.Fixed = 0; + string xml = MyFlexGrid.GetXMLData(); using (Item itm = MyItemInfo.Get()) { itm.MyContent.MyGrid.Data = xml; - itm.MyContent.Text = searchableText; - // what about the 'config' for ro tables. + // if this is the initial save of an ro table, then the 'DoLinkForRoTable' will + // create the usage for it. this code gets run on modify of the ro table and also + // on exit of the griditem. We don't want to save the ro usage again, if it's already + // been saved. + if (MyFlexGrid.IsRoTable && MyFlexGrid.ROID != null && itm.MyContent.ContentRoUsageCount < 1) + { + searchableText = string.Format(@"\v\v0 ", searchableText, DoLinkForRoTable()); + itm.MyContent.Text = searchableText; + } + if (!MyFlexGrid.IsRoTable)itm.MyContent.Text = searchableText; itm.Save(); MyItemInfo.MyContent.MyGrid.ResetContent(itm.MyContent.MyGrid); } @@ -481,7 +566,14 @@ namespace Volian.Controls.Library MyFlexGrid.Focus(); ScrollToCenter(); } - public override StepRTB MyStepRTB { get { return MyFlexGrid.TableCellEditor; } } + public StepRTB DisplayRoStepRTB; + public override StepRTB MyStepRTB + { + get + { + return MyFlexGrid.TableCellEditor; + } + } public override DialogResult ReplaceText(string rpltxt, string fndstr, bool caseSensitive, bool matchWholeWord, bool reverse, bool prompt, IWin32Window fndrpldlg) { int r = MyFlexGrid.Row; @@ -756,10 +848,26 @@ namespace Volian.Controls.Library public override void SetupHeader(ItemInfo itemInfo) { ;} // tables do not have headers public override void ShowExpanded() {;} public override void SetText() - { + { + // if this is an RO Table, regenerate xml. This is done in the case that + // the rotable was updated by the ro editor. + //if (MyFlexGrid.IsRoTable) RefreshGridData(); RefreshDisplay(false); IdentifyMe(false); } + + private void RefreshGridData() + { + string ROID = MyFlexGrid.ROID; + int rodbid = MyFlexGrid.RODbId; + MyFlexGrid.Clear(); + ROFSTLookup MyROFSTLookup = MyItemInfo.MyDocVersion.DocVersionAssociations[0].MyROFst.ROFSTLookup; + ConvertTableToGrid(MyROFSTLookup.GetRoValue(ROID)); + MyFlexGrid.RODbId = rodbid; + MyFlexGrid.ROID = ROID; + MyFlexGrid.IsRoTable = true; + SaveContents(); + } public override void SetExpandAndExpander(ItemInfo itemInfo) { CanExpand = false; } // can't expand a table #endregion }