New function to fix the ro values in the link text within the content text (for example, if the rodbid is updated in the link text)
Add menu item for ro fixer. Fix ro values correctly if containing a dash and/or in a grid
This commit is contained in:
parent
7530ca00f3
commit
2702cfeeed
113
PROMS/DataLoader/ROFixer.cs
Normal file
113
PROMS/DataLoader/ROFixer.cs
Normal file
@ -0,0 +1,113 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using VEPROMS.CSLA.Library;
|
||||
|
||||
namespace DataLoader
|
||||
{
|
||||
public delegate void ROFixerEvent(object sender, ROFixerEventArgs args);
|
||||
public class ROFixerEventArgs
|
||||
{
|
||||
private string _MyStatus;
|
||||
|
||||
public string MyStatus
|
||||
{
|
||||
get { return _MyStatus; }
|
||||
set { _MyStatus = value; }
|
||||
}
|
||||
public ROFixerEventArgs(string myStatus)
|
||||
{
|
||||
_MyStatus = myStatus;
|
||||
}
|
||||
}
|
||||
class ROFixer
|
||||
{
|
||||
public static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
|
||||
public event ROFixerEvent StatusChanged;
|
||||
private void OnStatusChanged(object sender, ROFixerEventArgs args)
|
||||
{
|
||||
if (StatusChanged != null)
|
||||
StatusChanged(sender, args);
|
||||
}
|
||||
private string _Status;
|
||||
|
||||
public string Status
|
||||
{
|
||||
get { return _Status; }
|
||||
set
|
||||
{
|
||||
_Status = value;
|
||||
OnStatusChanged(this, new ROFixerEventArgs(_Status));
|
||||
}
|
||||
}
|
||||
private int _ErrorCount = 0;
|
||||
|
||||
public int ErrorCount
|
||||
{
|
||||
get { return _ErrorCount; }
|
||||
set { _ErrorCount = value; }
|
||||
}
|
||||
private string _LogPath;
|
||||
public ROFixer(string logpath)
|
||||
{
|
||||
_LogPath = logpath;
|
||||
}
|
||||
public TimeSpan Process()
|
||||
{
|
||||
DateTime tstart = DateTime.Now;
|
||||
ProcessROs();
|
||||
return DateTime.Now - tstart;
|
||||
}
|
||||
private void ProcessROs()
|
||||
{
|
||||
Status = "Getting List...";
|
||||
// get list of content records
|
||||
List<int> myContentList = new List<int>();
|
||||
RoUsageInfoList myRoUsages = RoUsageInfoList.Get();
|
||||
Dictionary<int, ROFSTLookup> roFstLookups = new Dictionary<int,ROFSTLookup>();
|
||||
foreach (RoUsageInfo rou in myRoUsages)
|
||||
{
|
||||
if (!myContentList.Contains(rou.ContentID))
|
||||
{
|
||||
myContentList.Add(rou.ContentID);
|
||||
}
|
||||
}
|
||||
int i = 0;
|
||||
foreach (int cid in myContentList)
|
||||
{
|
||||
Status = string.Format("Processing {0} of {1} steps", ++i, myContentList.Count);
|
||||
ContentInfo myContentInfo = ContentInfo.Get(cid);
|
||||
DocVersionInfo dvi = myContentInfo.ContentItems[0].MyProcedure.MyDocVersion;
|
||||
int versionId = dvi.VersionID;
|
||||
if (!roFstLookups.ContainsKey(versionId))
|
||||
{
|
||||
ROFstInfo myRoFst = dvi.DocVersionAssociations[0].MyROFst;
|
||||
roFstLookups.Add(versionId, myRoFst.GetROFSTLookup(dvi));
|
||||
}
|
||||
ROFSTLookup myLookup = roFstLookups[versionId];
|
||||
using (Content ctmp = myContentInfo.Get())
|
||||
{
|
||||
ItemInfo ii = myContentInfo.ContentItems[0];
|
||||
foreach (RoUsageInfo ru in myContentInfo.ContentRoUsages)
|
||||
{
|
||||
//ROFSTLookup.rochild rocc = myLookup.GetRoChild12(ru.ROID);
|
||||
//if (rocc.value == null)
|
||||
ROFSTLookup.rochild rocc = myLookup.GetRoChild(ru.ROID);
|
||||
//string myValue = rocc.value;
|
||||
|
||||
int myType = rocc.type;
|
||||
string myValue = myLookup.GetTranslatedRoValue(ru.ROID, ii.ActiveFormat.PlantFormat.FormatData.SectData.ConvertCaretToDelta);
|
||||
ctmp.FixContentText(ru, myValue, myType, null);
|
||||
if (ctmp.IsDirty) Console.WriteLine("{0}, {1}", myValue, ru.ROID);
|
||||
}
|
||||
if (ctmp.IsDirty)
|
||||
{
|
||||
ctmp.DTS = DateTime.Now;
|
||||
ctmp.Save();
|
||||
ContentInfo.Refresh(ctmp);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
14
PROMS/DataLoader/frmLoader.Designer.cs
generated
14
PROMS/DataLoader/frmLoader.Designer.cs
generated
@ -74,6 +74,7 @@ namespace DataLoader
|
||||
this.fixAllToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.approvalDatabasesToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.updateFormatsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.fixROValuesToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.sc.Panel1.SuspendLayout();
|
||||
this.sc.Panel2.SuspendLayout();
|
||||
this.sc.SuspendLayout();
|
||||
@ -253,7 +254,7 @@ namespace DataLoader
|
||||
// exitToolStripMenuItem
|
||||
//
|
||||
this.exitToolStripMenuItem.Name = "exitToolStripMenuItem";
|
||||
this.exitToolStripMenuItem.Size = new System.Drawing.Size(92, 22);
|
||||
this.exitToolStripMenuItem.Size = new System.Drawing.Size(102, 24);
|
||||
this.exitToolStripMenuItem.Text = "E&xit";
|
||||
this.exitToolStripMenuItem.Click += new System.EventHandler(this.exitToolStripMenuItem_Click);
|
||||
//
|
||||
@ -269,7 +270,8 @@ namespace DataLoader
|
||||
this.convertToChangeManagerToolStripMenuItem,
|
||||
this.convertToApprovalToolStripMenuItem,
|
||||
this.load16BitApprovalToolStripMenuItem,
|
||||
this.fixesToolStripMenuItem});
|
||||
this.fixesToolStripMenuItem,
|
||||
this.fixROValuesToolStripMenuItem});
|
||||
this.processToolStripMenuItem.Name = "processToolStripMenuItem";
|
||||
this.processToolStripMenuItem.Size = new System.Drawing.Size(70, 24);
|
||||
this.processToolStripMenuItem.Text = "&Process";
|
||||
@ -445,6 +447,13 @@ namespace DataLoader
|
||||
this.updateFormatsToolStripMenuItem.Text = "Update Formats";
|
||||
this.updateFormatsToolStripMenuItem.Click += new System.EventHandler(this.updateFormatsToolStripMenuItem_Click);
|
||||
//
|
||||
// fixROValuesToolStripMenuItem
|
||||
//
|
||||
this.fixROValuesToolStripMenuItem.Name = "fixROValuesToolStripMenuItem";
|
||||
this.fixROValuesToolStripMenuItem.Size = new System.Drawing.Size(264, 24);
|
||||
this.fixROValuesToolStripMenuItem.Text = "Fix RO Values";
|
||||
this.fixROValuesToolStripMenuItem.Click += new System.EventHandler(this.fixROValuesToolStripMenuItem_Click);
|
||||
//
|
||||
// frmLoader
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F);
|
||||
@ -516,5 +525,6 @@ namespace DataLoader
|
||||
private System.Windows.Forms.ToolStripMenuItem fixAllToolStripMenuItem;
|
||||
private System.Windows.Forms.ToolStripMenuItem approvalDatabasesToolStripMenuItem;
|
||||
private System.Windows.Forms.ToolStripMenuItem updateFormatsToolStripMenuItem;
|
||||
private System.Windows.Forms.ToolStripMenuItem fixROValuesToolStripMenuItem;
|
||||
}
|
||||
}
|
||||
|
@ -1145,7 +1145,20 @@ namespace DataLoader
|
||||
|
||||
}
|
||||
|
||||
private void fixROValuesToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
Database.VEPROMS_Connection = MySettings.ConnectionString.Replace("{DBName}", MySettings.DBName);
|
||||
ROFixer myRoFixer = new ROFixer(MySettings.LogFilePath);
|
||||
myRoFixer.StatusChanged += new ROFixerEvent(myRoFixer_StatusChanged);
|
||||
TimeSpan howlong = myRoFixer.Process();
|
||||
string RoFixTime = string.Format("Fix RO Values completion time: {0:D2}:{1:D2}:{2:D2}.{3}", howlong.Hours, howlong.Minutes, howlong.Seconds, howlong.Milliseconds);
|
||||
MyInfo = RoFixTime;
|
||||
}
|
||||
|
||||
void myRoFixer_StatusChanged(object sender, ROFixerEventArgs args)
|
||||
{
|
||||
Status = args.MyStatus;
|
||||
}
|
||||
}
|
||||
public class MessageBuilder
|
||||
{
|
||||
|
@ -54,7 +54,17 @@ namespace VEPROMS.CSLA.Library
|
||||
if (m != null && m.Groups.Count > 1)
|
||||
{
|
||||
System.Text.RegularExpressions.Group g = m.Groups[3];
|
||||
if (g.ToString() != newvalue)
|
||||
System.Text.RegularExpressions.Group g2 = m.Groups[2];
|
||||
if (g2.Value.StartsWith(@"\u8209?"))
|
||||
{
|
||||
string gg = g2.Value + " " + g.Value;
|
||||
if (gg != newvalue)
|
||||
{
|
||||
Text = Text.Substring(0, offset + g2.Index) + newvalue + Text.Substring(offset + g2.Index + gg.Length);
|
||||
break; // Text has been processed
|
||||
}
|
||||
}
|
||||
else if (g.ToString() != newvalue)
|
||||
{
|
||||
Text = Text.Substring(0, offset + g.Index) + newvalue + Text.Substring(offset + g.Index + g.Length);
|
||||
break; // Text has been processed
|
||||
@ -79,12 +89,14 @@ namespace VEPROMS.CSLA.Library
|
||||
foreach (Match mmg in msg)
|
||||
{
|
||||
int offset = 0; // crashed in substring line below if using mmg.Index; Set to 0 and it worked - KBR.
|
||||
Match mg = Regex.Match(MyGrid.Data, lookForXml);
|
||||
Match mg = Regex.Match(mmg.Value, lookForXml);// Regex.Match(MyGrid.Data, lookForXml);
|
||||
if (mg != null && mg.Groups.Count > 1)
|
||||
{
|
||||
System.Text.RegularExpressions.Group g = mg.Groups[3];
|
||||
if (g.ToString() != newvalue)
|
||||
MyGrid.Data = MyGrid.Data.Substring(0, offset + g.Index) + newvalue + MyGrid.Data.Substring(offset + g.Index + g.Length);
|
||||
{
|
||||
MyGrid.Data = MyGrid.Data.Substring(0, offset + mmg.Index + g.Index) + newvalue + MyGrid.Data.Substring(offset + mmg.Index + g.Index + g.Length);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user