/// <summary> /// Generate word document with register of system documents /// </summary> /// <param name="tv"></param> public string RegisterOfSytemDocuments(TreeView tv, string clientFolder) { object oMissing = System.Reflection.Missing.Value; var pastPlannedActivities = string.Empty; //Start Word and create a new document. WordNet._Application oWord = new Application { Visible = false }; WordNet._Document oDoc = oWord.Documents.Add(ref oMissing, ref oMissing, ref oMissing, ref oMissing); oDoc.PageSetup.Orientation = WordNet.WdOrientation.wdOrientLandscape; PrintToWord(oDoc, "Register of System Documents", 16, 0, FCMWordAlign.CENTER); PrintToWord(oDoc, " ", 8, 0); // Locate client folder // string clientFileLocationName = Utils.getFilePathName(@"%TEMPLATEFOLDER%\ClientSource\", "ROS-001 Register Of System Documents.doc"); FullFileNamePath = clientFileLocationName; FileName = "RegisterOfSystemDocuments.doc"; if (File.Exists(clientFileLocationName)) { // Delete file try { File.Delete(clientFileLocationName); uioutput.AddOutputMessage("File replaced: " + clientFileLocationName); } catch (Exception) { uioutput.AddOutputMessage("Error deleting file " + clientFileLocationName); uioutput.AddErrorMessage("Error deleting file " + clientFileLocationName); return(clientFileLocationName); } } // string filename = Path.Combine(Path.GetTempPath(), Path.ChangeExtension(Path.GetTempFileName(), "doc")); oDoc.SaveAs(clientFileLocationName); string msg = ">>> Generating file... "; if (uioutput != null) { uioutput.AddOutputMessage(msg); } PrintToWord(oDoc, " ", 8, 1); WordNet.Range wrdRng; WordNet.Table oTable; wrdRng = oDoc.Bookmarks.get_Item(oEndOfDoc).Range; int rowCount = 30; // Get number of rows for a client document, client document set // var cds = new BUSClientDocumentSet(Utils.ClientID, Utils.ClientSetID); rowCount = cds.DocumentCount; if (rowCount < 1) { return(clientFileLocationName); } oTable = oDoc.Tables.Add(wrdRng, rowCount, 6, ref vkFalse, ref vkFalse); //oTable.Borders.InsideLineWidth = WordNet.WdLineWidth.wdLineWidth050pt; //oTable.Borders.InsideColor = WordNet.WdColor.wdColorAutomatic; //oTable.Borders.OutsideLineWidth = WordNet.WdLineWidth.wdLineWidth050pt; //oTable.Borders.OutsideColor = WordNet.WdColor.wdColorAutomatic; oTable.Rows[1].HeadingFormat = -1; WordNet.Row headingRow = oTable.Rows[1]; ApplyHeadingStyle(headingRow.Cells[1], 40); headingRow.Cells[1].Range.Text = ""; ApplyHeadingStyle(headingRow.Cells[2], 30); headingRow.Cells[2].Range.Text = ""; ApplyHeadingStyle(headingRow.Cells[3], 60); headingRow.Cells[3].Range.Text = "Document Number"; ApplyHeadingStyle(headingRow.Cells[4], 50); headingRow.Cells[4].Range.Text = "Version"; ApplyHeadingStyle(headingRow.Cells[5], 300); headingRow.Cells[5].Range.Text = "Document Name"; ApplyHeadingStyle(headingRow.Cells[6], 100); headingRow.Cells[6].Range.Text = "Comments"; int line = 0; foreach (var treeNode in tv.Nodes) { line++; WriteLineToRoSD(tv.Nodes[0], oDoc, oTable, prefix: "", parent: "", seqnum: line); } msg = ">>> End "; if (uioutput != null) { uioutput.AddOutputMessage(msg); } PrintToWord(oDoc, " ", 12, 1); oDoc.Save(); oDoc.Close(); oWord.Visible = true; oWord.Documents.Open(FileName: clientFileLocationName); oWord.Activate(); return(clientFileLocationName); }
/// <summary> /// Generate register of systems document using existing file. /// </summary> /// <param name="tv"></param> /// <param name="clientFolder"></param> /// <param name="fileName"></param> /// <returns></returns> public ResponseStatus RegisterOfSytemDocuments2(TreeView tv, string clientFolder, string fileName, string processName, string userID) { uioutput.AddOutputMessage("Starting Register of Systems Documents generation...", processName, userID); uioutput.AddOutputMessage(clientFolder, processName, userID); uioutput.AddOutputMessage(fileName, processName, userID); ResponseStatus ret = new ResponseStatus(); object oMissing = System.Reflection.Missing.Value; object vkMissing = System.Reflection.Missing.Value; object vkReadOnly = false; object vkVisiblefalse = false; object vkFalse = false; var pastPlannedActivities = string.Empty; //Start Word and open the document. //WordNet._Application oApplication = new Application { Visible = false }; // string clientDestinationFileLocation = document.clientDocument.Location.Trim(); string clientDestinationFileLocation = clientFolder; //string clientDestinationFileLocationName = Utils.getFilePathName( // clientDestinationFileLocation, document.clientDocument.FileName.Trim() ); string clientDestinationFileLocationName = Utils.getFilePathName(clientDestinationFileLocation, fileName.Trim()); object destinationFileName = clientDestinationFileLocationName; if (!File.Exists(clientDestinationFileLocationName)) { uioutput.AddOutputMessage("File doesn't exist " + destinationFileName, processName: processName, userID: userID); uioutput.AddErrorMessage("File doesn't exist " + destinationFileName, processName: processName, userID: userID); var responseerror = new ResponseStatus(MessageType.Error); responseerror.Message = "File doesn't exist " + destinationFileName; return(responseerror); } WordNet._Document oDoc; try { uioutput.AddOutputMessage("Opening document in Word... " + destinationFileName, processName: processName, userID: userID); oDoc = oApplication.Documents.Open( ref destinationFileName, ref vkMissing, ref vkFalse, ref vkMissing, ref vkMissing, ref vkMissing, ref vkMissing, ref vkMissing, ref vkMissing, ref vkMissing, ref vkMissing, ref vkVisiblefalse); } catch (Exception ex) { var responseerror = new ResponseStatus(MessageType.Error); responseerror.ReturnCode = -1; responseerror.ReasonCode = 1000; responseerror.Message = "Error copying file."; responseerror.Contents = ex; return(responseerror); } if (oDoc.ReadOnly) { if (uioutput != null) { uioutput.AddOutputMessage("(Word) File is Read-only contact support: " + destinationFileName, processName, userID); } oDoc.Close(); System.Runtime.InteropServices.Marshal.ReleaseComObject(oDoc); var responseerror = new ResponseStatus(MessageType.Error); responseerror.Message = "(Word) File is Read-only contact support: " + destinationFileName; return(responseerror); } try { if (uioutput != null) { uioutput.AddOutputMessage("Saving document in Word... " + destinationFileName, processName, userID); } oDoc.Save(); } catch (Exception ex) { if (uioutput != null) { uioutput.AddOutputMessage("Error saving file " + clientDestinationFileLocationName, processName, userID); } var responseerror = new ResponseStatus(MessageType.Error); responseerror.Message = "Error saving file " + clientDestinationFileLocationName; return(responseerror); } string msg = ">>> Opening file... " + destinationFileName; if (uioutput != null) { uioutput.AddOutputMessage(msg, processName, userID); } PrintToWord(oDoc, " ", 8, 1); WordNet.Range wrdRng; WordNet.Table oTable; wrdRng = oDoc.Bookmarks.get_Item(oEndOfDoc).Range; int rowCount = 30; // Get number of rows for a client document, client document set // // var cds = new BUSClientDocumentSet( Utils.ClientID, Utils.ClientSetID XXXXXXXXXXXXXXX ); var cds = new BUSClientDocumentSet(clientID, clientDocSetID); rowCount = cds.DocumentCount; if (rowCount < 1) { return(new ResponseStatus(MessageType.Error)); } oTable = oDoc.Tables.Add(wrdRng, rowCount, 8, ref vkFalse, ref vkFalse); oTable.Borders.OutsideColor = WordNet.WdColor.wdColorBlack; oTable.Borders.InsideLineStyle = WordNet.WdLineStyle.wdLineStyleDouble; oTable.Borders.OutsideColor = WordNet.WdColor.wdColorBlueGray; oTable.Borders.OutsideLineStyle = WordNet.WdLineStyle.wdLineStyleEmboss3D; oTable.Rows [1].HeadingFormat = -1; WordNet.Row headingRow = oTable.Rows [1]; ApplyHeadingStyle(headingRow.Cells [1], 200); headingRow.Cells [1].Range.Text = "Directory"; ApplyHeadingStyle(headingRow.Cells [2], 60); headingRow.Cells [2].Range.Text = "Sub Directory"; ApplyHeadingStyle(headingRow.Cells [3], 80); headingRow.Cells [3].Range.Text = "Document Number"; ApplyHeadingStyle(headingRow.Cells [4], 30); headingRow.Cells [4].Range.Text = "Sml"; ApplyHeadingStyle(headingRow.Cells [5], 40); headingRow.Cells [5].Range.Text = "Med"; ApplyHeadingStyle(headingRow.Cells [6], 30); headingRow.Cells [6].Range.Text = "Lrg"; ApplyHeadingStyle(headingRow.Cells [7], 50); headingRow.Cells [7].Range.Text = "Version"; ApplyHeadingStyle(headingRow.Cells [8], 200); headingRow.Cells [8].Range.Text = "Document Name"; int line = 0; foreach (var treeNode in tv.Nodes) { line++; WriteLineToRoSD(tv.Nodes [0], oDoc, oTable, prefix: "", parent: "", seqnum: line); } msg = ">>> End "; if (uioutput != null) { uioutput.AddOutputMessage(msg, processName, userID); } PrintToWord(oDoc, " ", 12, 1); try { oDoc.Save(); } catch (Exception ex) { if (uioutput != null) { uioutput.AddOutputMessage("Error saving file again... " + clientDestinationFileLocationName, processName, userID); } var responseerror = new ResponseStatus(MessageType.Error); responseerror.Message = "Error saving file again... " + clientDestinationFileLocationName; return(responseerror); } oDoc.Close(); ResponseStatus goodresponse = new ResponseStatus(MessageType.Informational); goodresponse.Message = "Document SRG-01 generated successfully."; return(goodresponse); }