From d207a0eefa62785b17f0d3a8cd78f9063d8049c6 Mon Sep 17 00:00:00 2001 From: Kathy Date: Wed, 27 Apr 2011 11:18:37 +0000 Subject: [PATCH] --- .../Extension/DocumentExt.cs | 38 +++++++++++++++---- 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/PROMS/VEPROMS.CSLA.Library/Extension/DocumentExt.cs b/PROMS/VEPROMS.CSLA.Library/Extension/DocumentExt.cs index 0f56c814..3095cd38 100644 --- a/PROMS/VEPROMS.CSLA.Library/Extension/DocumentExt.cs +++ b/PROMS/VEPROMS.CSLA.Library/Extension/DocumentExt.cs @@ -238,7 +238,7 @@ namespace VEPROMS.CSLA.Library } catch (IOException ex) { - // _MyLog.Error("TryDelete", ex); + // _MyLog.Error("TryDelete", ex); } finally { @@ -273,7 +273,7 @@ namespace VEPROMS.CSLA.Library { _MyFile = new FileInfo(string.Format(@"{0}\tmp_{1}{2}{3}", VlnSettings.TemporaryFolder, MyDocument.DocID, Unique, MyDocument.FileExtension)); FileStream fs = _MyFile.Create(); - if(MyDocument.DocContent != null)fs.Write(MyDocument.DocContent, 0, MyDocument.DocContent.Length); + if (MyDocument.DocContent != null) fs.Write(MyDocument.DocContent, 0, MyDocument.DocContent.Length); fs.Close(); _MyFile.CreationTime = _MyDocument.DTS; _MyFile.LastWriteTime = _MyDocument.DTS; @@ -290,19 +290,41 @@ namespace VEPROMS.CSLA.Library get { return _MyFile.FullName; } set { - if(FullName != value) + if (FullName != value) _MyFile = new FileInfo(value); } } - public void SaveFile(float length,string ascii,ItemInfo myItemInfo) + public void SaveFile(float length, string ascii, ItemInfo myItemInfo, bool cvtLibDoc) { // TODO: Add Try & Catch logic if (_MyDocument == null) return; Document doc = _MyDocument.Get(); FileStream fs = _MyFile.Open(FileMode.Open, FileAccess.Read, FileShare.ReadWrite); Byte[] buf = new byte[_MyFile.Length]; - fs.Read(buf,0,buf.Length); + fs.Read(buf, 0, buf.Length); fs.Close(); + + // Handle if this is a libdoc & the user wanted to convert to a non-library document. + if (cvtLibDoc) + { + // if just one usage (this one), then just convert this to a non-library document. If there is more + // than one usage, make a copy so that the rest of the usages still point to the library document. + if (doc.DocumentEntryCount == 1) + doc.LibTitle = null; + else + { + // make new document with 'no' libtitle. Then link this to the item/content via the entry. + // the data gets set below. + Document tdoc = Document.MakeDocument(null, null, null, null); + _MyDocument = DocumentInfo.Get(doc.DocID); + doc = tdoc; + using (Entry ent = myItemInfo.MyContent.MyEntry.Get()) + { + ent.MyDocument = tdoc; + ent.Save(); + } + } + } doc.FileExtension = MyFile.Extension; doc.DocContent = buf; doc.DocAscii = ascii; @@ -313,7 +335,7 @@ namespace VEPROMS.CSLA.Library doc.DTS = _MyFile.LastWriteTime; doc = doc.Save(); List roids = new List(); - string pdfTmp = MSWordToPDF.ToPDFReplaceROs(_MyDocument,roids,myItemInfo); + 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]; @@ -322,8 +344,8 @@ namespace VEPROMS.CSLA.Library pdfFile.Delete(); Pdf.DeleteAll(doc.DocID); // clear the PDF table for DocID first DocStyle myDocStyle = myItemInfo.ActiveSection.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)) { ;} + 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(); }