diff --git a/PROMS/VEPROMS.CSLA.Library/Extension/DocumentExt.cs b/PROMS/VEPROMS.CSLA.Library/Extension/DocumentExt.cs index 4fbb6732..9ac5fe14 100644 --- a/PROMS/VEPROMS.CSLA.Library/Extension/DocumentExt.cs +++ b/PROMS/VEPROMS.CSLA.Library/Extension/DocumentExt.cs @@ -370,22 +370,32 @@ namespace VEPROMS.CSLA.Library string fileName = GetFileName(sect); FileInfo fi = new FileInfo(fileName); FileStream fs = fi.Create(); - fs.Write(mydoc.DocPdf, 0, mydoc.DocPdf.Length); + if (mydoc.DocPdf!=null)fs.Write(mydoc.DocPdf, 0, mydoc.DocPdf.Length); fs.Close(); return fileName; } - public static void UpdateDocPdf(DocumentInfo mydoc, Color overrideColor) + public static bool UpdateDocPdf(DocumentInfo mydoc, Color overrideColor) { if (mydoc.DocPdf == null || overrideColor.ToArgb() != mydoc.DocumentConfig.Printing_Color.ToArgb()) { MSWordToPDF.OverrideColor = overrideColor; - SetDocPdf(mydoc); + return SetDocPdf(mydoc); } + return true; } - public static void SetDocPdf(DocumentInfo docInfo) + public static bool SetDocPdf(DocumentInfo docInfo) { - string pdfTmp = MSWordToPDF.ToPDFReplaceROs(docInfo); + string pdfTmp = null; + try + { + pdfTmp = MSWordToPDF.ToPDFReplaceROs(docInfo); + } + catch (Exception ex) + { + return false; + } + if (pdfTmp == null) return false; FileInfo pdfFile = new FileInfo(pdfTmp); FileStream fs = pdfFile.Open(FileMode.Open, FileAccess.Read, FileShare.ReadWrite); Byte[] buf = new byte[pdfFile.Length]; @@ -401,6 +411,7 @@ namespace VEPROMS.CSLA.Library doc.Save(); } docInfo.RefreshConfig(); + return true; } public static string ToPDFReplaceROs(DocumentInfo doc) { @@ -493,37 +504,44 @@ namespace VEPROMS.CSLA.Library } else if ((int)type == 4) // X-Y Plot { - val = val.Replace("`", "\xB0"); - //AddInfo("\tRO Found {0} = '{1}'", sel.Text, val); - sel.Text = ""; - //float width = 72 * Int32.Parse(vals[3], System.Globalization.NumberStyles.AllowHexSpecifier) / 12.0F; - //float height = 72 * lines / 6.0F; - string pngFile = VlnSettings.TemporaryFolder + @"\XYPlot1.png"; //@"C:\Temp\XYPlot1.png"; - RectangleF plotRect = CreatePlot(pngFile, val, 600F, FormForPlotGraphics); - //LBShape shape = myDoc.Shapes.AddPicture(@"C:\Temp\XYPlot.png", 0, 0, sel.Range); - float x = (float)sel.get_Information(LBWdInformation.wdHorizontalPositionRelativeToPage); - float y = (float)sel.get_Information(LBWdInformation.wdVerticalPositionRelativeToPage); - //LBInlineShape shape = sel.InlineShapes.AddPicture(pngFile); - LBRange myRange = sel.Paragraphs.First.Range; - float yTop = (float)myRange.get_Information(LBWdInformation.wdVerticalPositionRelativeToPage); - float xAdjust = -29.3F; // TODO: Check this value - float yAdjust = 9.1F; // TODO: Check this value - LBShape shape = myDoc.Shapes.AddPicture(pngFile, x + xAdjust + plotRect.X, yAdjust + y - yTop + plotRect.Y, sel.Range); - File.Delete(pngFile); - //Console.WriteLine(",{0},{1},{2},{3}", x, y - yTop, xAdjust,yAdjust); - shape.LockAspectRatio = LBMsoTriState.msoTrue; - //shape.Width = .89F * shape.Width; - //shape.Width = float.Parse(tbAdjust.Text) * shape.Width; - shape.Width = plotRect.Width; - //shape.Height = .89F * shape.Height; - sel.WholeStory(); - // TODO: Do we want to color code ROs - //sel.Range.Font.Color = LBWdColor.wdColorRed; - //Console.WriteLine("{0} Shape Width {1} Height {2}", val.Replace("\n", "','"), shape.Width, shape.Height); - //shape.Width = width; - //shape.Height = height; - //Console.WriteLine("{0} Shape Width {1} Height {2}", val.Replace("\n", "','"), shape.Width, shape.Height); - //imageROTokenReplaced = true; + try + { + val = val.Replace("`", "\xB0"); + //AddInfo("\tRO Found {0} = '{1}'", sel.Text, val); + sel.Text = ""; + //float width = 72 * Int32.Parse(vals[3], System.Globalization.NumberStyles.AllowHexSpecifier) / 12.0F; + //float height = 72 * lines / 6.0F; + string pngFile = VlnSettings.TemporaryFolder + @"\XYPlot1.png"; //@"C:\Temp\XYPlot1.png"; + RectangleF plotRect = CreatePlot(pngFile, val, 600F, FormForPlotGraphics); + //LBShape shape = myDoc.Shapes.AddPicture(@"C:\Temp\XYPlot.png", 0, 0, sel.Range); + float x = (float)sel.get_Information(LBWdInformation.wdHorizontalPositionRelativeToPage); + float y = (float)sel.get_Information(LBWdInformation.wdVerticalPositionRelativeToPage); + //LBInlineShape shape = sel.InlineShapes.AddPicture(pngFile); + LBRange myRange = sel.Paragraphs.First.Range; + float yTop = (float)myRange.get_Information(LBWdInformation.wdVerticalPositionRelativeToPage); + float xAdjust = -29.3F; // TODO: Check this value + float yAdjust = 9.1F; // TODO: Check this value + LBShape shape = myDoc.Shapes.AddPicture(pngFile, x + xAdjust + plotRect.X, yAdjust + y - yTop + plotRect.Y, sel.Range); + File.Delete(pngFile); + //Console.WriteLine(",{0},{1},{2},{3}", x, y - yTop, xAdjust,yAdjust); + shape.LockAspectRatio = LBMsoTriState.msoTrue; + //shape.Width = .89F * shape.Width; + //shape.Width = float.Parse(tbAdjust.Text) * shape.Width; + shape.Width = plotRect.Width; + //shape.Height = .89F * shape.Height; + sel.WholeStory(); + // TODO: Do we want to color code ROs + //sel.Range.Font.Color = LBWdColor.wdColorRed; + //Console.WriteLine("{0} Shape Width {1} Height {2}", val.Replace("\n", "','"), shape.Width, shape.Height); + //shape.Width = width; + //shape.Height = height; + //Console.WriteLine("{0} Shape Width {1} Height {2}", val.Replace("\n", "','"), shape.Width, shape.Height); + //imageROTokenReplaced = true; + } + catch (Exception ex) + { + return null; + } } else {