Removed PDF info from Document and Document Config

Added DebugStatus to MSWordToPDF Class
Removed PDF info from Document Config
Moved PDF info from Documents to PDFs Table
Added MSWordPageCount Property
Delete PDFs when RO Value Changes in a related document
This commit is contained in:
Rich 2011-04-18 21:29:29 +00:00
parent dd9bc9e0dc
commit f4a3a969f4
6 changed files with 86 additions and 64 deletions

View File

@ -123,7 +123,7 @@ namespace VEPROMS
Content cont = Content.Get(sectinfo.MyContent.ContentID);
Byte[] tstbyte = System.Text.Encoding.Default.GetBytes("");
Document doc = Document.MakeDocument(null, tstbyte, null, null, null); // tstbyte, null, null, null);
Document doc = Document.MakeDocument(null, tstbyte, null, null); // tstbyte, null, null, null);
Entry entry = cont.MyEntry;
entry.MyDocument = Document.Get(doc.DocID);
cont.Save().Dispose();
@ -476,7 +476,7 @@ namespace VEPROMS
{
// make new document with 'no' libtitle - use libtitle for the doc title. Then link this
// to the item...
Document doc = Document.MakeDocument(null, doclibinfo.DocContent, doclibinfo.DocAscii, doclibinfo.Config, doclibinfo.DocPdf);
Document doc = Document.MakeDocument(null, doclibinfo.DocContent, doclibinfo.DocAscii, doclibinfo.Config);
_SectionConfig.MySection.MyContent.MyEntry.MyDocument = doc;
}
ppCmbxLibDoc.Items.Clear();

View File

@ -132,7 +132,15 @@ namespace VEPROMS
// When creating an XY Plot, a System.Drawing.Graphics is needed and it requires a form. Use the main
// form.
if (VlnSettings.DebugMode)
{
MSWordToPDF.DebugStatus = 1;
MSWordToPDF.OverrideColor = Color.Red;
}
else
{
MSWordToPDF.DebugStatus = 0;
MSWordToPDF.OverrideColor = Color.Transparent;
}
MSWordToPDF.FormForPlotGraphics = this;
// set the color of the ribbon

View File

@ -67,39 +67,40 @@ namespace VEPROMS.CSLA.Library
OnPropertyChanged("LibDoc_Comment");
}
}
[Category("Printing")]
[DisplayName("Length")]
[Description("Length of Document in Full and Partial Pages")]
public float Printing_Length
{
get
{
string s = _Xp["Printing", "Length"];// get the saved value
// RHM 20110415 - These are now stored in the PDF table.
//[Category("Printing")]
//[DisplayName("Length")]
//[Description("Length of Document in Full and Partial Pages")]
//public float Printing_Length
//{
// get
// {
// string s = _Xp["Printing", "Length"];// get the saved value
return float.Parse(s);
}
set
{
_Xp["Printing", "Length"] = string.Format("{0:0.0000}", value);
OnPropertyChanged("Printing_Length");
}
}
[Category("Printing")]
[DisplayName("Color")]
[Description("Color of Document Text")]
public Color Printing_Color
{
get
{
string sColor = _Xp["Printing", "Color"];
return ColorConfig.ColorFromString(sColor);
}
set
{
_Xp["Printing", "Color"] = value.ToString();
OnPropertyChanged("Printing_Color");
}
}
// return float.Parse(s);
// }
// set
// {
// _Xp["Printing", "Length"] = string.Format("{0:0.0000}", value);
// OnPropertyChanged("Printing_Length");
// }
//}
//[Category("Printing")]
//[DisplayName("Color")]
//[Description("Color of Document Text")]
//public Color Printing_Color
//{
// get
// {
// string sColor = _Xp["Printing", "Color"];
// return ColorConfig.ColorFromString(sColor);
// }
// set
// {
// _Xp["Printing", "Color"] = value.ToString();
// OnPropertyChanged("Printing_Color");
// }
//}
#endregion
#region ToString
public override string ToString()

View File

@ -294,7 +294,7 @@ namespace VEPROMS.CSLA.Library
_MyFile = new FileInfo(value);
}
}
public void SaveFile(float length,string ascii)
public void SaveFile(float length,string ascii,ItemInfo myItemInfo)
{
// TODO: Add Try & Catch logic
if (_MyDocument == null) return;
@ -308,21 +308,22 @@ namespace VEPROMS.CSLA.Library
doc.DocAscii = ascii;
//doc.UpdateDocAscii(_MyFile.FullName);
DocumentConfig cfg = new DocumentConfig(doc);
cfg.Printing_Length = length;
cfg.Printing_Color = MSWordToPDF.OverrideColor;
doc.Config = cfg.ToString();
doc.UserID = Volian.Base.Library.VlnSettings.UserID;
doc.DTS = _MyFile.LastWriteTime;
doc.Save();
doc = doc.Save();
List<string> roids = new List<string>();
string pdfTmp = MSWordToPDF.ToPDFReplaceROs(_MyDocument,roids);
string pdfTmp = MSWordToPDF.ToPDFReplaceROs(_MyDocument,roids,myItemInfo);
FileInfo pdfFile = new FileInfo(pdfTmp);
fs = pdfFile.Open(FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
buf = new byte[pdfFile.Length];
fs.Read(buf, 0, buf.Length);
fs.Close();
pdfFile.Delete();
doc.DocPdf = buf;
Pdf.DeleteAll(doc.DocID); // clear the PDF table for DocID first
DocStyle myDocStyle = myItemInfo.MyActiveSection.MyDocStyle;
using (Pdf myPdf = Pdf.MakePdf(doc, MSWordToPDF.DebugStatus, (int) myDocStyle.Layout.TopRow, (int) myDocStyle.Layout.PageLength,
(int) myDocStyle.Layout.LeftMargin, (int) myDocStyle.Layout.PageWidth, (double)myItemInfo.MSWordPageCount, buf)) { ;}
doc.UpdateDRoUsages(roids);
doc.Save();
}
@ -372,6 +373,12 @@ namespace VEPROMS.CSLA.Library
return _MyApp;
}
}
private static int _DebugStatus = 0;
public static int DebugStatus
{
get { return MSWordToPDF._DebugStatus; }
set { MSWordToPDF._DebugStatus = value; }
}
private static System.Drawing.Color _OverrideColor = System.Drawing.Color.Transparent;
public static System.Drawing.Color OverrideColor
{
@ -387,31 +394,29 @@ namespace VEPROMS.CSLA.Library
public static string GetDocPdf(SectionInfo sect, Color overrideColor)
{
DocumentInfo mydoc = sect.MyContent.MyEntry.MyDocument;
UpdateDocPdf(mydoc, overrideColor);
UpdateDocPdf(mydoc, overrideColor,sect);
string fileName = GetFileName(sect);
FileInfo fi = new FileInfo(fileName);
FileStream fs = fi.Create();
if (mydoc.DocPdf!=null)fs.Write(mydoc.DocPdf, 0, mydoc.DocPdf.Length);
PdfInfo myPdf = PdfInfo.Get(sect);
if (myPdf != null && myPdf.DocPdf != null) fs.Write(myPdf.DocPdf, 0, myPdf.DocPdf.Length);
fs.Close();
return fileName;
}
public static bool UpdateDocPdf(DocumentInfo mydoc, Color overrideColor)
{
if (mydoc.DocPdf == null || overrideColor.ToArgb() != mydoc.DocumentConfig.Printing_Color.ToArgb())
public static bool UpdateDocPdf(DocumentInfo mydoc, Color overrideColor, ItemInfo sect)
{
MSWordToPDF.OverrideColor = overrideColor;
return SetDocPdf(mydoc);
}
PdfInfo myPdf = PdfInfo.Get(sect);
return true;
}
public static bool SetDocPdf(DocumentInfo docInfo)
public static bool SetDocPdf(DocumentInfo docInfo, ItemInfo sect)
{
string pdfTmp = null;
List<string> roids = new List<string>();
try
{
pdfTmp = MSWordToPDF.ToPDFReplaceROs(docInfo,roids);
pdfTmp = MSWordToPDF.ToPDFReplaceROs(docInfo,roids,sect);
}
catch (Exception ex)
{
@ -426,19 +431,18 @@ namespace VEPROMS.CSLA.Library
pdfFile.Delete();
using (Document doc = docInfo.Get())
{
DocumentConfig dc = new DocumentConfig(doc);
dc.Printing_Color = MSWordToPDF.OverrideColor;
doc.Config = dc.ToString();
doc.DocPdf = buf;
DocStyle myDocStyle = sect.MyActiveSection.MyDocStyle;
using (Pdf myPdf = Pdf.MakePdf(doc, MSWordToPDF.DebugStatus, (int)myDocStyle.Layout.TopRow, (int)myDocStyle.Layout.PageLength,
(int)myDocStyle.Layout.LeftMargin, (int)myDocStyle.Layout.PageWidth, (double)sect.MSWordPageCount, buf)) { ;}
doc.UpdateDRoUsages(roids);
doc.Save();
}
docInfo.RefreshConfig();
return true;
}
public static string ToPDFReplaceROs(DocumentInfo doc,List<string> roids)
public static string ToPDFReplaceROs(DocumentInfo doc,List<string> roids, ItemInfo sect)
{
ItemInfo sect = doc.DocumentEntries[0].MyContent.ContentItems[0];
//ItemInfo sect = doc.DocumentEntries[0].MyContent.ContentItems[0];
return ToPDFReplaceROs(sect, false, roids);
}
public static string ToPDFReplaceROs(ItemInfo sect, bool openPdf, List<string> roids) //, System.Drawing.Color overrideColor, System.Windows.Forms.Form myForm)
@ -588,6 +592,7 @@ namespace VEPROMS.CSLA.Library
sel.Range.Font.Color = (LBWdColor)WordColor(OverrideColor == System.Drawing.Color.Transparent ? System.Drawing.Color.Black : OverrideColor);
sel.ParagraphFormat.LineSpacingRule = LBWdLineSpacing.wdLineSpaceExactly;
sel.ParagraphFormat.LineSpacing = 12;
sect.MSWordPageCount = myDoc.Length;
fileName = CreatePDF(fileName, openPdf);
MyApp.ActiveDocument.Close(false);
if (CloseWordWhenDone)

View File

@ -297,6 +297,12 @@ namespace VEPROMS.CSLA.Library
// return ii._ItemID == _ItemID;
// return false;
//}
private float _MSWordPageCount = 0;
public float MSWordPageCount
{
get { return _MSWordPageCount; }
set { _MSWordPageCount = value; }
}
public event ItemInfoEvent OrdinalChanged;
private void OnOrdinalChange()
{

View File

@ -247,14 +247,16 @@ namespace VEPROMS.CSLA.Library
{
foreach (DROUsageInfo droUsg in affected)
{
using (Document document = Document.Get(droUsg.DocID))
{
if (document.DocPdf != null)
{
document.DocPdf = null;
document.Save();
}
}
//using (Document document = Document.Get(droUsg.DocID))
//{
Pdf.DeleteAll(droUsg.DocID);
// Delete PDFs
//if (document.DocPdf != null)
//{
// document.DocPdf = null;
// document.Save();
//}
//}
}
}
}