/// <summary> /// Add or Update a record /// </summary> /// <param name="type">In case of an update, checks the issue number /// </param> /// <returns></returns> public int Save(HeaderInfo headerInfo, string type = null) { // Check if code value exists. // If it exists, update // Else Add a new one int uidReturn = 0; Document find = new Document(); // find.CUID = this.CUID; // CUID can be modified! find.UID = this.UID; if (find.Read()) { // If it is a new issue, save the old issue in the issue table // if (find.IssueNumber == this.IssueNumber) { if (type == Utils.SaveType.UPDATE) { uidReturn = this.Update(headerInfo); } } else { LogFile.WriteToTodaysLogFile( "Document Save - issue number is different. CUID: " + this.CUID, headerInfo.UserID, "Document.cs" ); } } else { uidReturn = this.Add(headerInfo); } return(uidReturn); }
public static void ListInTree( TreeView fileList, DocumentSetDocumentLinkList documentList, Document root) { // Find root folder // Document rootDocument = new Document(); rootDocument.CUID = root.CUID; rootDocument.RecordType = root.RecordType; rootDocument.UID = root.UID; rootDocument.Read(); // Create root // var rootNode = new TreeNode(rootDocument.Name, FCMConstant.Image.Folder, FCMConstant.Image.Folder); // Add root node to tree // fileList.Nodes.Add(rootNode); rootNode.Tag = rootDocument; rootNode.Name = rootDocument.Name; foreach (var document in documentList.documentSetDocumentLinkList) { int image = 0; image = Utils.ImageSelect(document.documentChild.RecordType.Trim()); var treeNode = new TreeNode(document.documentChild.Name, image, image); treeNode.Tag = document; treeNode.Name = document.LinkType; rootNode.Nodes.Add(treeNode); } }
/// <summary> /// Generate one document /// </summary> /// <param name="doco"></param> public void GenerateDocument(scClientDocSetDocLink doco) { // Retrieve latest version // Document.Document document = new Document.Document(); document.UID = doco.clientDocument.FKDocumentUID; document.Read(); string msg = ">>> Generating file: " + document.UID + " === " + document.SimpleFileName; if (uioutput != null) { uioutput.AddOutputMessage(msg); } // if (iconMessage != null) iconMessage.Text = ">>> Generating file: " + document.UID; // Locate source file // string sourceFileLocationName = Utils.getFilePathName( doco.clientDocument.SourceLocation, doco.clientDocument.SourceFileName); // Find the parent folder location // int parentUID = doco.clientDocument.ParentUID; ClientDocument cdParent = new ClientDocument(); cdParent.UID = parentUID; cdParent.Read(); // This is the client destination folder (and name) // //ResponseStatus destLocationDerivedClient = ClientDocument.GetDocumentPath(doco.clientDocument); //string destLocationDerived = destLocationDerivedClient.Contents.ToString(); string clientDestinationFileLocation = doco.clientDocument.Location.Trim(); string clientDestinationFileLocationName = Utils.getFilePathName( clientDestinationFileLocation, doco.clientDocument.FileName.Trim()); // This is the source client file name // string clientSourceFileLocation = doco.clientDocument.Location.Trim(); string clientSourceFileLocationName = Utils.getFilePathName( clientSourceFileLocation, doco.clientDocument.FileName.Trim()); // Source location and destination may be different. // The destination of the file must be the one where it lives on the actual tree // To determine where the file should be located, we need to get the parent folder // The only way to determine the parent folder is walking through the entire tree from the root. // The root is the only thing that can be trusted. Every other location is dependent on the root. // The determination of the file location occurs in 2 parts. The one here is the second part. // At this point we are not going to use the source location of the original document, instead // we are going to use the client document location // // Check if destination folder directory exists // string PhysicalLocation = Utils.GetPathName(clientDestinationFileLocation); if (string.IsNullOrEmpty(PhysicalLocation)) { string er = "Location is empty " + clientDestinationFileLocation + "\n" + "File Name: " + doco.document.Name; uioutput.AddOutputMessage(er); return; } // 02/04/2011 // This step should be done when the "FOLDER" record is created and not when the document // is generated // //if (!Directory.Exists( PhysicalLocation )) // Directory.CreateDirectory( PhysicalLocation ); // However the folder existence must be checked // if (!Directory.Exists(PhysicalLocation)) { Directory.CreateDirectory(PhysicalLocation); string er = "Destination folder has been created with File! " + PhysicalLocation + "\n" + "File Name: " + doco.document.Name; uioutput.AddOutputMessage(er); //return; } if (File.Exists(clientDestinationFileLocationName)) { // Proceed but report in list // if (overrideDocuments == "Yes") { // Delete file try { File.Delete(clientDestinationFileLocationName); uioutput.AddOutputMessage("File replaced: " + document.SimpleFileName); } catch (Exception) { uioutput.AddOutputMessage("Error deleting file " + document.SimpleFileName); uioutput.AddErrorMessage("Error deleting file " + document.SimpleFileName); return; } } else { uioutput.AddOutputMessage("File already exists " + document.SimpleFileName); return; } } // Copy and fix file // // Word Documents // if (doco.clientDocument.RecordType.Trim() == Utils.RecordType.FOLDER) { // Update file - set as GENERATED. // // This is the moment where the folder destination has to be created // and the folder db record has to be updated with the location // if (!Directory.Exists(PhysicalLocation)) { Directory.CreateDirectory(PhysicalLocation); } uioutput.AddOutputMessage("FOLDER: " + doco.clientDocument.SourceFileName); } else { // If is is not a folder, it must be a regular file. // Trying to copy it as well... // var currentDocumentPath = Path.GetExtension(doco.clientDocument.FileName); if (doco.clientDocument.DocumentType == Utils.DocumentType.WORD) { #region Word // ------------------------------------------------------------------------ // ------------------------------------------------------------------------ // Generate Document and replace tag values in new document generated // ------------------------------------------------------------------------ // ------------------------------------------------------------------------ var results = WordDocumentTasks.CopyDocument(sourceFileLocationName, clientSourceFileLocationName, ts, vkWordApp, uioutput); if (results.ReturnCode < 0) { // Error has occurred // var er = (System.Exception)results.Contents; uioutput.AddOutputMessage("ERROR: " + er.ToString()); uioutput.AddErrorMessage("ERROR: " + er.ToString()); return; } #endregion Word } else if (doco.clientDocument.DocumentType == Utils.DocumentType.EXCEL) { // ------------------------------------------------------------------------ // ------------------------------------------------------------------------ // Generate Document and replace tag values in new document generated // ------------------------------------------------------------------------ // ------------------------------------------------------------------------ ExcelSpreadsheetTasks.CopyDocument(sourceFileLocationName, clientSourceFileLocationName, ts, vkExcelApp, uioutput); } else { File.Copy(sourceFileLocationName, clientSourceFileLocationName); uioutput.AddOutputMessage("File copied but not modified: " + Path.GetExtension(doco.clientDocument.FileName) + " == File: " + clientSourceFileLocationName); } // // Instantiate client document ClientDocument cd = new ClientDocument(); cd.UID = doco.clientDocument.UID; // Update file - set as GENERATED. // cd.SetGeneratedFlagVersion('Y', document.IssueNumber); uioutput.AddOutputMessage("Document generated: " + clientDestinationFileLocationName); } return; }
/// <summary> /// Generate Documents Controller (Word must be previously initialised /// </summary> private void GenerateDocumentsController(TreeNode documentsTreeNode) { scClientDocSetDocLink documentTN = new scClientDocSetDocLink(); // Get List of documents for a client // if (documentsTreeNode.Tag.GetType().Name == "scClientDocSetDocLink") { documentTN = (scClientDocSetDocLink)documentsTreeNode.Tag; } else { if (documentsTreeNode.Tag.GetType().Name == "Document") { if (documentTN.clientDocument == null) { if (uioutput != null) { uioutput.AddOutputMessage("Error CDISNULL019202 - client document is null."); } if (uioutput != null) { uioutput.AddErrorMessage("Error CDISNULL019202 - client document is null. Generation stopped."); } return; } documentTN.clientDocument.RecordType = Utils.RecordType.DOCUMENT; documentTN.document = (Document.Document)documentsTreeNode.Tag; } } // If it is a document, generate if (documentTN.clientDocument.RecordType.Trim() != Utils.RecordType.FOLDER) { #region Generate Document // Generate // Retrieve updated file name from source Document.Document document = new Document.Document(); document.UID = documentTN.clientDocument.FKDocumentUID; document.Read(); if (uioutput != null) { uioutput.AddOutputMessage("Inspecting file: " + document.UID + " === " + document.Name); } // if (iconMessage != null) iconMessage.Text = "Start time: " + System.DateTime.Now.ToString(); // Update client records with new file name // // Instantiate client document ClientDocument cd = new ClientDocument(); cd.UID = documentTN.clientDocument.UID; cd.SourceFileName = document.FileName; // cd.Read(); // Set comboIssueNumber and File Name // ClientDocument.SetClientDestinationFile( clientDocument: cd, clientUID: documentTN.clientDocument.FKClientUID, documentCUID: document.CUID, sourceFileName: document.FileName, sourceVersionNumber: document.IssueNumber, simpleFileName: document.SimpleFileName); cd.UpdateSourceFileName(); // Update memory with latest file name documentTN.clientDocument.SourceFileName = cd.SourceFileName; string sourceFileLocationName = Utils.getFilePathName( documentTN.clientDocument.SourceLocation, documentTN.clientDocument.SourceFileName); // check if source folder/ file exists if (string.IsNullOrEmpty(documentTN.clientDocument.Location)) { if (uioutput != null) { uioutput.AddOutputMessage("Document Location is empty."); } return; } if (string.IsNullOrEmpty(documentTN.clientDocument.FileName)) { if (uioutput != null) { uioutput.AddOutputMessage("File Name is empty."); } return; } if (!File.Exists(sourceFileLocationName)) { string er = "File does not exist " + sourceFileLocationName + " - File Name: " + documentTN.clientDocument.SourceFileName; if (uioutput != null) { uioutput.AddOutputMessage(er); } if (uioutput != null) { uioutput.AddErrorMessage(er); } return; } // Check if destination folder exists // if (string.IsNullOrEmpty(cds.Folder)) { string er = "Destination folder not set. Generation stopped."; if (uioutput != null) { uioutput.AddOutputMessage(er); } return; } string PhysicalCDSFolder = Utils.GetPathName(cds.Folder); if (!Directory.Exists(PhysicalCDSFolder)) { Directory.CreateDirectory(PhysicalCDSFolder); } // Generate one document (Folder will also be created in this call) // // Get time before file var previousTime = System.DateTime.Now; GenerateDocument(documentTN); // Get time after file var agora = System.DateTime.Now; fileprocessedcount++; valueForProgressBar = (fileprocessedcount / filecount) * 100; int leftToProcess = filecount - Convert.ToInt32(fileprocessedcount); // Get the time it took to process one file TimeSpan span = agora.Subtract(previousTime); // Average span in seconds acumulatedSpanInSec += span.Seconds; averageSpanInSec = acumulatedSpanInSec / fileprocessedcount; // Calculate the estimated time to complete estimated = System.DateTime.Now.AddSeconds(averageSpanInSec * leftToProcess); if (uioutput != null) { uioutput.UpdateProgressBar(valueForProgressBar, estimated, leftToProcess); } return; #endregion Generate Document // Processing for one file ends here } else { // If item imported is a FOLDER // This is the client destination folder (and name) // string clientDestinationFileLocation = documentTN.clientDocument.Location.Trim(); if (!string.IsNullOrEmpty(clientDestinationFileLocation)) { string clientDestinationFileLocationName = Utils.getFilePathName( clientDestinationFileLocation, documentTN.clientDocument.FileName.Trim()); // string PhysicalLocation = Utils.GetPathName(clientDestinationFileLocation); string PhysicalLocation = clientDestinationFileLocationName; if (uioutput != null) { uioutput.AddOutputMessage("Processing Folder: " + PhysicalLocation); } if (!string.IsNullOrEmpty(PhysicalLocation)) { if (!Directory.Exists(PhysicalLocation)) { if (uioutput != null) { uioutput.AddOutputMessage("Folder Created: " + clientDestinationFileLocationName); } Directory.CreateDirectory(PhysicalLocation); } else { if (uioutput != null) { uioutput.AddOutputMessage("Folder Already Exists: " + clientDestinationFileLocationName); } } } } else { if (uioutput != null) { uioutput.AddOutputMessage("Folder Ignored: " + documentTN.document.Name); } } // Process each document in folder // foreach (TreeNode tn in documentsTreeNode.Nodes) { scClientDocSetDocLink doco = (scClientDocSetDocLink)tn.Tag; GenerateDocumentsController(tn); } } }
/// <summary> /// Generate documents selected for a client /// </summary> /// <param name="clientID"></param> /// <param name="clientDocSetID"></param> /// <param name="uioutput"></param> /// <param name="overrideDocuments"></param> private void TBD_GenerateDocumentsForClient( int clientID, int clientDocSetID, string overrideDocuments) { uioutput.AddOutputMessage("Start time: " + System.DateTime.Now.ToString()); // Instantiate Word // object vkFalse = false; Word.Application vkWordApp = new Word.Application(); // Make it not visible vkWordApp.Visible = false; Excel.Application vkExcelApp = new Excel.Application(); // Make it not visible vkExcelApp.Visible = false; // Get Metadata for client ReportMetadataList clientMetadata = new ReportMetadataList(); clientMetadata.ListMetadataForClient(clientID); var ts = new List <WordDocumentTasks.TagStructure>(); // Load variables/ metadata into memory // foreach (ReportMetadata metadata in clientMetadata.reportMetadataList) { // Retrieve value for the field selected // string value = metadata.GetValue(); // If the field is not enabled, the program has to replace the value with spaces. // var valueOfTag = metadata.Enabled == 'Y' ? value : string.Empty; // When the field is an image and it is not enable, do not include the "No image" icon in the list // if (metadata.InformationType == Utils.InformationType.IMAGE && metadata.Enabled == 'N') { continue; } ts.Add(new WordDocumentTasks.TagStructure() { TagType = metadata.InformationType, Tag = metadata.FieldCode, TagValue = valueOfTag }); } // Get Client Document Set Details // To get the source and destination folders ClientDocumentSet cds = new ClientDocumentSet(); cds.Get(clientID, clientDocSetID); // Get List of documents for a client // var cdl = new ClientDocument(); cdl.List(Utils.ClientID, Utils.ClientSetID); bool fileNotFound = false; // --------------------------------------------------------------------------- // Check if source files exist before generation starts // --------------------------------------------------------------------------- int filecount = 0; foreach (scClientDocSetDocLink doco in cdl.clientDocSetDocLink) { #region File Inspection filecount++; // Ignore for now // if (doco.clientDocument.RecordType.Trim() == Utils.RecordType.FOLDER) { string er = "Folder " + doco.document.Name; uioutput.AddOutputMessage(er); continue; } // Retrieve updated file name from source Document.Document document = new Document.Document(); document.UID = doco.clientDocument.FKDocumentUID; document.Read(); uioutput.AddOutputMessage("Inspecting file: " + document.UID + " === " + document.Name); // Client Document.SourceFileName is the name for the FCM File // Client Document.FileName is the client file name // Update client records with new file name // // Instantiate client document ClientDocument cd = new ClientDocument(); cd.UID = doco.clientDocument.UID; // cd.FileName = document.FileName; cd.SourceFileName = document.FileName; cd.UpdateSourceFileName(); // Update memory with latest file name // doco.clientDocument.SourceFileName = cd.FileName; doco.clientDocument.SourceFileName = cd.SourceFileName; string sourceFileLocationName = Utils.getFilePathName( doco.clientDocument.SourceLocation, doco.clientDocument.SourceFileName); // check if source folder/ file exists if (string.IsNullOrEmpty(doco.clientDocument.Location)) { MessageBox.Show("Document Location is empty."); return; } if (string.IsNullOrEmpty(doco.clientDocument.FileName)) { MessageBox.Show("File Name is empty."); return; } if (!File.Exists(sourceFileLocationName)) { string er = "File does not exist " + sourceFileLocationName + " - File Name: " + doco.clientDocument.SourceFileName; uioutput.AddOutputMessage(er); uioutput.AddErrorMessage(er); fileNotFound = true; continue; } #endregion File Inspection } // Can't proceed if file not found if (fileNotFound) { return; } // Check if destination folder exists // if (string.IsNullOrEmpty(cds.Folder)) { MessageBox.Show("Destination folder not set. Generation stopped."); return; } string PhysicalCDSFolder = Utils.GetPathName(cds.Folder); if (!Directory.Exists(PhysicalCDSFolder)) { Directory.CreateDirectory(PhysicalCDSFolder); } // ----------------------------------------------------------------------- // Generation starts here // ----------------------------------------------------------------------- fileprocessedcount = 0; valueForProgressBar = 0; startTime = System.DateTime.Now.ToString(); estimated = System.DateTime.Now.AddSeconds(5 * filecount); var previousTime = System.DateTime.Now; var agora = System.DateTime.Now; foreach (scClientDocSetDocLink doco in cdl.clientDocSetDocLink) { fileprocessedcount++; valueForProgressBar = (fileprocessedcount / filecount) * 100; // Get current time agora = System.DateTime.Now; // Get the time it took to process one file TimeSpan span = agora.Subtract(previousTime); // Calculate the estimated time to complete estimated = System.DateTime.Now.AddSeconds(span.TotalSeconds * filecount); uioutput.UpdateProgressBar(valueForProgressBar, estimated); previousTime = System.DateTime.Now; // Retrieve latest version // Document.Document document = new Document.Document(); document.UID = doco.clientDocument.FKDocumentUID; document.Read(); uioutput.AddOutputMessage(">>> Generating file: " + document.UID + " === " + document.SimpleFileName); string sourceFileLocationName = Utils.getFilePathName( doco.clientDocument.SourceLocation, doco.clientDocument.SourceFileName); // This is the client file name // string clientFileLocation = cds.Folder.Trim() + doco.clientDocument.Location.Trim(); string clientFileLocationName = Utils.getFilePathName( clientFileLocation, doco.clientDocument.FileName.Trim()); // Check if file destination directory exists // string PhysicalLocation = Utils.GetPathName(clientFileLocation); if (string.IsNullOrEmpty(PhysicalLocation)) { string er = "Location is empty " + doco.clientDocument.Location + "\n" + "File Name: " + doco.document.Name; uioutput.AddOutputMessage(er); continue; } if (!Directory.Exists(PhysicalLocation)) { Directory.CreateDirectory(PhysicalLocation); } if (File.Exists(clientFileLocationName)) { // Proceed but report in list // if (overrideDocuments == "Yes") { // Delete file try { File.Delete(clientFileLocationName); uioutput.AddOutputMessage("File replaced " + document.SimpleFileName); } catch (Exception) { uioutput.AddOutputMessage("Error deleting file " + document.SimpleFileName); uioutput.AddErrorMessage("Error deleting file " + document.SimpleFileName); continue; } } else { uioutput.AddOutputMessage("File already exists " + document.SimpleFileName); continue; } } // Copy and fix file // // Word Documents // if (doco.clientDocument.RecordType.Trim() == Utils.RecordType.FOLDER) { // Update file - set as GENERATED. // uioutput.AddOutputMessage("FOLDER: " + doco.clientDocument.SourceFileName); } else { // If is is not a folder, it must be a regular file. // Trying to copy it as well... // var currentDocumentPath = Path.GetExtension(doco.clientDocument.FileName); if (doco.clientDocument.DocumentType == Utils.DocumentType.WORD) { #region Word // ------------------------------------------------------------------------ // ------------------------------------------------------------------------ // Generate Document and replace tag values in new document generated // ------------------------------------------------------------------------ // ------------------------------------------------------------------------ var results = WordDocumentTasks.CopyDocument(sourceFileLocationName, clientFileLocationName, ts, vkWordApp, uioutput); if (results.ReturnCode < 0) { // Error has occurred // var er = (System.Exception)results.Contents; uioutput.AddOutputMessage("ERROR: " + er.ToString()); uioutput.AddErrorMessage("ERROR: " + er.ToString()); continue; } // // Instantiate client document ClientDocument cd = new ClientDocument(); cd.UID = doco.clientDocument.UID; // Update file - set as GENERATED. // cd.SetGeneratedFlagVersion('Y', document.IssueNumber); uioutput.AddOutputMessage("Document generated: " + clientFileLocationName); #endregion Word } else if (doco.clientDocument.DocumentType == Utils.DocumentType.EXCEL) { // ------------------------------------------------------------------------ // ------------------------------------------------------------------------ // Generate Document and replace tag values in new document generated // ------------------------------------------------------------------------ // ------------------------------------------------------------------------ ExcelSpreadsheetTasks.CopyDocument(sourceFileLocationName, clientFileLocationName, ts, vkExcelApp, uioutput); // // Instantiate client document ClientDocument cd = new ClientDocument(); cd.UID = doco.clientDocument.UID; // Update file - set as GENERATED. // cd.SetGeneratedFlagVersion('Y', document.IssueNumber); uioutput.AddOutputMessage("Document generated: " + clientFileLocationName); } else { File.Copy(sourceFileLocationName, clientFileLocationName); uioutput.AddOutputMessage("File copied but not modified: " + Path.GetExtension(doco.clientDocument.FileName) + " == File: " + clientFileLocationName); } } } // close word application vkWordApp.Quit(ref vkFalse, ref vkFalse, ref vkFalse); vkExcelApp.Quit(); uioutput.AddOutputMessage("End time: " + System.DateTime.Now.ToString()); }
// ----------------------------------------------------- // Load documents in a tree // ----------------------------------------------------- public static void ListInTree( TreeView fileList, DocumentLinkList documentList, Document root) { // Find root folder // Document rootDocument = new Document(); rootDocument.CUID = root.CUID; rootDocument.RecordType = root.RecordType; rootDocument.UID = root.UID; rootDocument.Read(); // Create root // var rootNode = new TreeNode(rootDocument.Name, FCMConstant.Image.Folder, FCMConstant.Image.Folder); // Add root node to tree // fileList.Nodes.Add(rootNode); rootNode.Tag = rootDocument; rootNode.Name = rootDocument.Name; foreach (var document in documentList.documentLinkList) { // Ignore root folder if (document.documentTo.CUID == "ROOT") { continue; } // Check if folder has a parent string cdocumentUID = document.UID.ToString(); string cparentIUID = document.documentTo.ParentUID.ToString(); int image = 0; document.documentTo.RecordType = document.documentTo.RecordType.Trim(); image = Utils.ImageSelect(document.documentTo.RecordType); if (document.documentTo.ParentUID == 0) { var treeNode = new TreeNode(document.documentTo.Name, image, image); treeNode.Tag = document; treeNode.Name = cdocumentUID; rootNode.Nodes.Add(treeNode); } else { // Find the parent node // var node = fileList.Nodes.Find(cparentIUID, true); if (node.Count() > 0) { var treeNode = new TreeNode(document.documentTo.Name, image, image); treeNode.Tag = document; treeNode.Name = cdocumentUID; node[0].Nodes.Add(treeNode); } else { // Add Element to the root // var treeNode = new TreeNode(document.documentTo.Name, image, image); treeNode.Tag = document; treeNode.Name = cdocumentUID; rootNode.Nodes.Add(treeNode); } } } }
// ----------------------------------------------------- // Load documents in a tree // ----------------------------------------------------- public static void ListInTree( TreeView fileList, DocumentList documentList, Document root) { // Find root folder // Document rootDocument = new Document(); rootDocument.CUID = root.CUID; rootDocument.RecordType = root.RecordType; rootDocument.UID = root.UID; rootDocument.Read(); // Create root // var rootNode = new TreeNode(rootDocument.Name, FCMConstant.Image.Folder, FCMConstant.Image.Folder); // Add root node to tree // fileList.Nodes.Add(rootNode); rootNode.Tag = rootDocument; rootNode.Name = rootDocument.Name; foreach (var document in documentList.documentList) { // Ignore root folder if (document.CUID == "ROOT") { continue; } // Check if folder has a parent string cdocumentUID = document.UID.ToString(); string cparentIUID = document.ParentUID.ToString(); int image = 0; int imageSelected = 0; document.RecordType = document.RecordType.Trim(); #region Image switch (document.DocumentType) { case Utils.DocumentType.WORD: image = FCMConstant.Image.Word32; imageSelected = FCMConstant.Image.Word32; // I have to think about this... // if (document.RecordType == Utils.RecordType.APPENDIX) { image = FCMConstant.Image.Appendix; imageSelected = FCMConstant.Image.Appendix; } break; case Utils.DocumentType.EXCEL: image = FCMConstant.Image.Excel; imageSelected = FCMConstant.Image.Excel; break; case Utils.DocumentType.FOLDER: image = FCMConstant.Image.Folder; imageSelected = FCMConstant.Image.Folder; break; case Utils.DocumentType.PDF: image = FCMConstant.Image.PDF; imageSelected = FCMConstant.Image.PDF; break; default: image = FCMConstant.Image.Word32; imageSelected = FCMConstant.Image.Word32; break; } #endregion Image if (document.ParentUID == 0) { var treeNode = new TreeNode(document.Name, image, image); treeNode.Tag = document; treeNode.Name = cdocumentUID; rootNode.Nodes.Add(treeNode); } else { // Find the parent node // var node = fileList.Nodes.Find(cparentIUID, true); if (node.Count() > 0) { var treeNode = new TreeNode(document.Name, image, imageSelected); treeNode.Tag = document; treeNode.Name = cdocumentUID; node[0].Nodes.Add(treeNode); } else { // Add Element to the root // var treeNode = new TreeNode(document.Name, image, imageSelected); treeNode.Tag = document; treeNode.Name = cdocumentUID; rootNode.Nodes.Add(treeNode); } } } }