// ----------------------------------------------------- // Load documents in a tree // ----------------------------------------------------- public static void ListInTree( TreeView fileList, DocumentLinkList documentList, Model.ModelDocument.Document root) { // Find root folder // Model.ModelDocument.Document rootDocument = new Model.ModelDocument.Document(); rootDocument.CUID = root.CUID; rootDocument.RecordType = root.RecordType; rootDocument.UID = root.UID; // rootDocument.Read(); rootDocument = RepDocument.Read(true, root.UID); // Create root // var rootNode = new TreeNode(rootDocument.Name, MakConstant.Image.Folder, MakConstant.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); } } } }
// ----------------------------------------------------- // List related documents // ----------------------------------------------------- public static DocumentLinkList ListRelatedDocuments(int docUID, string type) { DocumentLinkList ret = new DocumentLinkList(); ret.documentLinkList = new List <DocumentLink>(); string linktype = ""; if (type == "ALL" || string.IsNullOrEmpty(type)) { // do nothing } else { linktype = " AND link.LinkType = '" + type + "'"; } using (var connection = new MySqlConnection(ConnString.ConnectionString)) { var commandString = string.Format( " SELECT " + " link.FKParentDocumentUID " + " ,doc.UID DOCUID " + " ,link.LinkType " + " ,doc.CUID " + " ,doc.Name " + " ,doc.SequenceNumber,doc.IssueNumber " + " ,doc.Location,doc.Comments,doc.SourceCode,doc.FileName " + " ,doc.FKClientUID,doc.ParentUID " + " ,doc.RecordType,doc.IsProjectPlan " + " ,docFrom.CUID docFromCUID " + " ,docFrom.Name docFromName " + " ,docFrom.SequenceNumber " + " ,docFrom.IssueNumber " + " ,docFrom.UID docFromUID " + " ,docFrom.Location docFromLocation " + " ,docFrom.Comments " + " ,docFrom.SourceCode,docFrom.FileName " + " ,docFrom.FKClientUID,docFrom.ParentUID " + " ,docFrom.RecordType,docFrom.IsProjectPlan " + " ,link.UID,link.IsVoid " + " FROM Document doc, " + " DocumentLink link, " + " Document docFrom " + " WHERE " + " link.IsVoid = 'N' " + linktype + " AND link.FKParentDocumentUID = {0} " + " AND doc.UID = link.FKChildDocumentUID " + " AND docFrom.UID = link.FKParentDocumentUID ", docUID ); using (var command = new MySqlCommand( commandString, connection)) { connection.Open(); using (MySqlDataReader reader = command.ExecuteReader()) { while (reader.Read()) { DocumentLink _Document = new DocumentLink(); _Document.FKParentDocumentUID = docUID; _Document.documentFrom = new Model.ModelDocument.Document(); _Document.documentTo = new Model.ModelDocument.Document(); _Document.documentTo.UID = Convert.ToInt32(reader["DOCUID"].ToString()); _Document.FKChildDocumentUID = _Document.documentTo.UID; _Document.documentTo.CUID = reader["CUID"].ToString(); _Document.documentTo.Name = reader["Name"].ToString(); _Document.documentTo.SequenceNumber = Convert.ToInt32(reader["SequenceNumber"].ToString()); _Document.documentTo.IssueNumber = Convert.ToInt32(reader["IssueNumber"].ToString()); _Document.documentTo.Location = reader["Location"].ToString(); _Document.documentTo.Comments = reader["Comments"].ToString(); _Document.documentTo.SourceCode = reader["SourceCode"].ToString(); _Document.documentTo.FileName = reader["FileName"].ToString(); _Document.documentTo.FKClientUID = Convert.ToInt32(reader["FKClientUID"].ToString()); _Document.documentTo.ParentUID = Convert.ToInt32(reader["ParentUID"].ToString()); _Document.documentTo.RecordType = reader["RecordType"].ToString(); _Document.documentTo.IsProjectPlan = reader["IsProjectPlan"].ToString(); _Document.LinkType = reader["LinkType"].ToString(); _Document.documentFrom.UID = Convert.ToInt32(reader["docFromUID"].ToString()); _Document.documentFrom.Name = reader["docFromName"].ToString(); string isVoid = reader["IsVoid"].ToString(); ret.documentLinkList.Add(_Document); } } } } return(ret); }
/// <summary> /// Load document into document set /// </summary> public void LoadAllDocuments() { // Retrieve all documents // For each document (order by parent uid) // check if it is already connected to current Document Set // If it is not, connect document // Link with parent document in the set // Replicate Document Links // 21/08/2013 // Stop using DocumentList // //DocumentList dl = new DocumentList(); //dl.List(); List <Document> docl = RepDocument.List(HeaderInfo.Instance); foreach (Document document in docl) { var found = DocumentSet.FindDocumentInSet(this.UID, document.UID); if (found.document.UID > 0) { continue; } else { DocumentSetDocument dsl = new DocumentSetDocument(); // Generate new UID dsl.UID = this.GetLastUID() + 1; // Add document to set // dsl.FKDocumentSetUID = this.UID; dsl.FKDocumentUID = document.UID; dsl.Location = document.Location; dsl.IsVoid = 'N'; dsl.StartDate = System.DateTime.Today; dsl.EndDate = System.DateTime.MaxValue; dsl.FKParentDocumentUID = document.ParentUID; // Uses the Document UID as the source (Has to be combined with Doc Set) dsl.FKParentDocumentSetUID = dsl.FKDocumentSetUID; dsl.SequenceNumber = document.SequenceNumber; dsl.Add(); } } // Replicate document links // foreach (Document document in docl) { var children = DocumentLinkList.ListRelatedDocuments(document.UID); foreach (var child in children.documentLinkList) { // DocumentSetDocumentLink dsdl = new DocumentSetDocumentLink(); dsdl.FKParentDocumentUID = 0; dsdl.FKChildDocumentUID = 0; dsdl.IsVoid = 'N'; dsdl.LinkType = child.LinkType; dsdl.UID = GetLastUID() + 1; // Find parent var parent1 = DocumentSet.FindDocumentInSet(this.UID, child.FKParentDocumentUID); // Find child var child1 = DocumentSet.FindDocumentInSet(this.UID, child.FKChildDocumentUID); dsdl.FKParentDocumentUID = parent1.DocumentSetDocument.UID; dsdl.FKChildDocumentUID = child1.DocumentSetDocument.UID; dsdl.Add(); } } }