Added UpdateDRoUsages to Update DROUsages when a Document is Saved

Added a list of ROIDs as a parameter to the code that walks through the MSWORD Document text and replaces ROs with their values
Fixed search string in FindRO
Added code to call GetAffectedDROUsages when an RO changes.
This adds annotations to show the changes to RO Values.
Added DROUsages table to capture ROUsages in Documents
This commit is contained in:
Rich
2011-01-20 20:22:10 +00:00
parent 7cdc7f4994
commit c4344f2308
7 changed files with 280 additions and 22 deletions

View File

@@ -27,6 +27,25 @@ namespace VEPROMS.CSLA.Library
return _LibTitle;
}
}
public void UpdateDRoUsages(List<string> roids)
{
if (DocumentDROUsageCount > 0)
{
foreach (DocumentDROUsage myUsage in DocumentDROUsages)
{
string roidkey = string.Format("{0}:{1}", myUsage.RODbID, myUsage.ROID);
if (roids.Contains(roidkey))
roids.Remove(roidkey);// If in both, nothing to do
else
myUsage.Delete(); // If only in old, remove it
}
}
foreach (string roidkey in roids)
{
string [] parts = roidkey.Split(":".ToCharArray());
DocumentDROUsages.Add(parts[1], RODb.Get(int.Parse(parts[0])));
}
}
/// <summary>
/// FixString processes the string returned and changes any symbols (0xF0??) to normal characters
/// </summary>
@@ -295,7 +314,8 @@ namespace VEPROMS.CSLA.Library
doc.UserID = Volian.Base.Library.VlnSettings.UserID;
doc.DTS = _MyFile.LastWriteTime;
doc.Save();
string pdfTmp = MSWordToPDF.ToPDFReplaceROs(_MyDocument);
List<string> roids = new List<string>();
string pdfTmp = MSWordToPDF.ToPDFReplaceROs(_MyDocument,roids);
FileInfo pdfFile = new FileInfo(pdfTmp);
fs = pdfFile.Open(FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
buf = new byte[pdfFile.Length];
@@ -303,6 +323,7 @@ namespace VEPROMS.CSLA.Library
fs.Close();
pdfFile.Delete();
doc.DocPdf = buf;
doc.UpdateDRoUsages(roids);
doc.Save();
}
#endregion
@@ -387,9 +408,10 @@ namespace VEPROMS.CSLA.Library
public static bool SetDocPdf(DocumentInfo docInfo)
{
string pdfTmp = null;
List<string> roids = new List<string>();
try
{
pdfTmp = MSWordToPDF.ToPDFReplaceROs(docInfo);
pdfTmp = MSWordToPDF.ToPDFReplaceROs(docInfo,roids);
}
catch (Exception ex)
{
@@ -408,17 +430,18 @@ namespace VEPROMS.CSLA.Library
dc.Printing_Color = MSWordToPDF.OverrideColor;
doc.Config = dc.ToString();
doc.DocPdf = buf;
doc.UpdateDRoUsages(roids);
doc.Save();
}
docInfo.RefreshConfig();
return true;
}
public static string ToPDFReplaceROs(DocumentInfo doc)
public static string ToPDFReplaceROs(DocumentInfo doc,List<string> roids)
{
ItemInfo sect = doc.DocumentEntries[0].MyContent.ContentItems[0];
return ToPDFReplaceROs(sect, false);
return ToPDFReplaceROs(sect, false, roids);
}
public static string ToPDFReplaceROs(ItemInfo sect, bool openPdf) //, System.Drawing.Color overrideColor, System.Windows.Forms.Form myForm)
public static string ToPDFReplaceROs(ItemInfo sect, bool openPdf, List<string> roids) //, System.Drawing.Color overrideColor, System.Windows.Forms.Form myForm)
{
string fileName = GetFileName(sect);
// TODO: do we want to cache the word pdfs
@@ -465,7 +488,13 @@ namespace VEPROMS.CSLA.Library
// if type is null, then set type to zero so that InsertROValue will put in "RO Not Found" for the value
if (type == null)
type = 0;
string roid = lookup.GetROIDByAccPagID(sel.Text, spPrefix, igPrefix);
if (roid != null)
{
string roidkey = string.Format("{0}:{1}",rofst.RODbID, roid);
if (!roids.Contains(roidkey))
roids.Add(roidkey);
}
if ((int)type == 8) // Image
{
//Console.WriteLine("Image: {0} - {1}", sect.MyContent.Number, sect.MyContent.Text);
@@ -716,7 +745,15 @@ namespace VEPROMS.CSLA.Library
LBSelection sel = MyApp.Selection;
LBFind find = sel.Find;
find.ClearFormatting();
find.Text = "[<](?@)-(?@)[>]";
// Search string format - this is MSWord wildcard format
// If you do a search in MSWord, make sure wildcard box is checked and then press the
// Special button to see the definitions of the various wildcards
// [<] - Less-Than Character
// [!<> ]@ - 1 or more characters not including Less-Than, Greater-Than or Space
// - Dash
// [!<> ]@ - 1 or more characters not including Less-Than, Greater-Than or Space
// [>] - Greater-Than Character
find.Text = "[<][!<> ]@-[!<> ]@[>]";
//find.Wrap = LBWdFindWrap.wdFindStop;
find.Wrap = LBWdFindWrap.wdFindContinue;
find.MatchCase = false;

View File

@@ -224,14 +224,30 @@ namespace VEPROMS.CSLA.Library
// roid's are stored in database as 16 characters long in the rousages table. They may be stored
// as 12 characters in the ro.fst.
string padroid = chg.Length <= 12 ? chg + "0000" : chg;
RoUsageInfoList affected = RoUsageInfoList.GetAffected(origROFstInfo.MyRODb.RODbID, padroid, desc, "Changed");
foreach (RoUsageInfo roUsg in affected)
using (RoUsageInfoList affected = RoUsageInfoList.GetAffected(origROFstInfo.MyRODb.RODbID, padroid, desc, "Changed"))
{
using (Content content = Content.Get(roUsg.MyContent.ContentID))
foreach (RoUsageInfo roUsg in affected)
{
content.FixContentText(roUsg, newvalue);
if (content.IsDirty)
content.Save();
using (Content content = Content.Get(roUsg.MyContent.ContentID))
{
content.FixContentText(roUsg, newvalue);
if (content.IsDirty)
content.Save();
}
}
}
using (DROUsageInfoList affected = DROUsageInfoList.GetAffected(origROFstInfo.MyRODb.RODbID, padroid, desc, "Changed"))
{
foreach (DROUsageInfo droUsg in affected)
{
using (Document document = Document.Get(droUsg.DocID))
{
if (document.DocPdf != null)
{
document.DocPdf = null;
document.Save();
}
}
}
}
}
@@ -240,7 +256,8 @@ namespace VEPROMS.CSLA.Library
Console.WriteLine("Deleted ROID = {0}", del);
string desc = string.Format("Deleted RO: Value = {0}", origLU.GetRoValue(del));
string padroiddel = del.Length <= 12 ? del + "0000" : del;
RoUsageInfoList affected = RoUsageInfoList.GetAffected(origROFstInfo.MyRODb.RODbID, padroiddel, desc, "Deleted");
using (RoUsageInfoList affected = RoUsageInfoList.GetAffected(origROFstInfo.MyRODb.RODbID, padroiddel, desc, "Deleted")) ;
using (DROUsageInfoList Daffected = DROUsageInfoList.GetAffected(origROFstInfo.MyRODb.RODbID, padroiddel, desc, "Deleted")) ;
}
}