// -----------------------------------------------------
        //    Save Links
        // -----------------------------------------------------
        public static void LinkDocuments(int DocumentSetUID, int ParentID, int ChildID, string LinkType)
        {
            DocumentSetDocumentLink findOne = new DocumentSetDocumentLink();

            if (findOne.Read(DocumentSetUID, ParentID, ChildID, LinkType))
            {
                // Already exists
            }
            else
            {
                findOne.LinkType            = LinkType;
                findOne.FKDocumentSetUID    = DocumentSetUID;
                findOne.FKParentDocumentUID = ParentID;
                findOne.FKChildDocumentUID  = ChildID;

                findOne.Add();
            }
        }
Exemplo n.º 2
0
        // -----------------------------------------------------
        //          Delete Link
        // -----------------------------------------------------
        public static void Delete(int DocumentSetUID, int DocumentUID)
        {
            // Links have to be deleted first
            //

            DocumentSetDocument dsd = new DocumentSetDocument();

            dsd.Find(documentUID: DocumentUID, docSetUID: DocumentSetUID, voidRead: 'N');

            if (dsd.UID <= 0)
            {
                return;
            }

            DocumentSetDocumentLink.DeleteAllRelated(dsd.UID);

            using (var connection = new SqlConnection(ConnString.ConnectionString))
            {
                var commandString =
                    (
                        "DELETE FROM [DocumentSetDocument] " +
                        " WHERE [FKDocumentUID] = @FKDocumentUID " +
                        "   AND [FKDocumentSetUID] = @FKDocumentSetUID "
                    );

                using (var command = new SqlCommand(
                           commandString, connection))
                {
                    command.Parameters.Add("@FKDocumentUID", SqlDbType.BigInt).Value    = DocumentUID;
                    command.Parameters.Add("@FKDocumentSetUID", SqlDbType.BigInt).Value = DocumentSetUID;
                    command.Parameters.Add("@IsVoid", SqlDbType.Char).Value             = 'Y';

                    connection.Open();
                    command.ExecuteNonQuery();
                }
            }
            return;
        }
Exemplo n.º 3
0
        // -----------------------------------------------------
        //    Load document into document set
        // -----------------------------------------------------
        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

            DocumentList dl = new DocumentList();

            dl.List();

            foreach (Document document in dl.documentList)
            {
                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 dl.documentList)
            {
                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();
                }
            }
        }
Exemplo n.º 4
0
        public static DocumentSetDocumentLinkList ListRelatedDocuments(int documentSetUID, int documentUID, string type)
        {
            DocumentSetDocumentLinkList ret = new DocumentSetDocumentLinkList();

            ret.documentSetDocumentLinkList = new List <DocumentSetDocumentLink>();

            string linktype = "";

            if (type == "ALL" || string.IsNullOrEmpty(type))
            {
                // do nothing
            }
            else
            {
                linktype = "  AND DSDL.LinkType = '" + type + "'";
            }

            using (var connection = new SqlConnection(ConnString.ConnectionString))
            {
                var commandString = string.Format
                                    (
                    "SELECT DSDL.[UID]                        DSDLUID                 " +
                    "      ,DSDL.[FKParentDocumentUID]        DSDLFKParentDocumentUID " +
                    "       ,DSDL.[FKChildDocumentUID]        DSDLFKChildDocumentUID " +
                    "       ,DSDL.[LinkType]                  DSDLLinkType " +
                    "       ,DSDL.[IsVoid]                    DSDLIsVoid " +
                    "       ," +
                    Document.SQLDocumentConcat("DOCUMENTCHILD") +
                    "       ," +
                    Document.SQLDocumentConcat("DOCUMENTPARENT") +
                    "       ," +
                    DocumentSetDocument.SQLDocumentConcat("DSDCHILD") +
                    "       ," +
                    DocumentSetDocument.SQLDocumentConcat("DSDPARENT") +

                    "  " +
                    "   FROM [management].[dbo].[DocumentSetDocumentLink] DSDL " +
                    "       ,[management].[dbo].[DocumentSetDocument] DSDCHILD " +
                    "       ,[management].[dbo].[DocumentSetDocument] DSDPARENT " +
                    "       ,[management].[dbo].[Document] DOCUMENTCHILD " +
                    "       ,[management].[dbo].[Document] DOCUMENTPARENT " +
                    "  WHERE  " +
                    "        DSDL.[IsVoid] = 'N' " +
                    "    AND DSDL.[FKParentDocumentUID] = {0} " +
                    linktype +
                    "    AND DSDL.FKDocumentSetUID = {1}  " +
                    "    AND DSDL.FKChildDocumentUID = DSDCHILD.UID  " +
                    "    AND DSDL.FKParentDocumentUID = DSDPARENT.UID  " +
                    "    AND DSDCHILD.FKDocumentUID = DOCUMENTCHILD.UID " +
                    "    AND DSDPARENT.FKDocumentUID = DOCUMENTPARENT.UID "
                    , documentUID
                    , documentSetUID
                                    );

                using (var command = new SqlCommand(
                           commandString, connection))
                {
                    connection.Open();
                    using (SqlDataReader reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            DocumentSetDocumentLink _Document = new DocumentSetDocumentLink();
                            _Document.documentChild             = new Document();
                            _Document.documentParent            = new Document();
                            _Document.documentSetDocumentChild  = new DocumentSetDocument();
                            _Document.documentSetDocumentParent = new DocumentSetDocument();

                            // Link information
                            //
                            _Document.FKChildDocumentUID  = Convert.ToInt32(reader["DSDLFKChildDocumentUID"].ToString());
                            _Document.FKParentDocumentUID = Convert.ToInt32(reader["DSDLFKParentDocumentUID"].ToString());
                            _Document.LinkType            = reader["DSDLLinkType"].ToString();

                            _Document.documentParent.UID            = Convert.ToInt32(reader["DOCUMENTPARENTUID"].ToString());
                            _Document.documentParent.SimpleFileName = reader["DOCUMENTPARENTUID"].ToString();
                            _Document.documentParent.CUID           = reader["DOCUMENTPARENTSimpleFileName"].ToString();
                            _Document.documentParent.Name           = reader["DOCUMENTPARENTName"].ToString();

                            _Document.documentChild.UID            = Convert.ToInt32(reader["DOCUMENTCHILDUID"].ToString());
                            _Document.documentChild.CUID           = reader["DOCUMENTCHILDSimpleFileName"].ToString();
                            _Document.documentChild.Name           = reader["DOCUMENTCHILDName"].ToString();
                            _Document.documentChild.SequenceNumber = Convert.ToInt32(reader["DOCUMENTCHILDSequenceNumber"].ToString());
                            _Document.documentChild.IssueNumber    = Convert.ToInt32(reader["DOCUMENTCHILDIssueNumber"].ToString());
                            _Document.documentChild.Location       = reader["DOCUMENTCHILDLocation"].ToString();
                            _Document.documentChild.Comments       = reader["DOCUMENTCHILDComments"].ToString();
                            _Document.documentChild.SourceCode     = reader["DOCUMENTCHILDSourceCode"].ToString();
                            _Document.documentChild.FileName       = reader["DOCUMENTCHILDFileName"].ToString();
                            _Document.documentChild.SimpleFileName = reader["DOCUMENTCHILDSimpleFileName"].ToString();
                            _Document.documentChild.FKClientUID    = Convert.ToInt32(reader["DOCUMENTCHILDFKClientUID"].ToString());
                            _Document.documentChild.ParentUID      = Convert.ToInt32(reader["DOCUMENTCHILDParentUID"].ToString());
                            _Document.documentChild.RecordType     = reader["DOCUMENTCHILDRecordType"].ToString();
                            _Document.documentChild.IsProjectPlan  = reader["DOCUMENTCHILDIsProjectPlan"].ToString();
                            _Document.documentChild.DocumentType   = reader["DOCUMENTCHILDDocumentType"].ToString();

                            _Document.documentSetDocumentChild.UID                    = Convert.ToInt32(reader["DSDCHILDUID"].ToString());
                            _Document.documentSetDocumentChild.FKDocumentUID          = Convert.ToInt32(reader["DSDCHILDFKDocumentUID"].ToString());
                            _Document.documentSetDocumentChild.FKDocumentSetUID       = Convert.ToInt32(reader["DSDCHILDFKDocumentSetUID"].ToString());
                            _Document.documentSetDocumentChild.Location               = reader["DSDCHILDLocation"].ToString();
                            _Document.documentSetDocumentChild.StartDate              = Convert.ToDateTime(reader["DSDCHILDStartDate"].ToString());
                            _Document.documentSetDocumentChild.EndDate                = Convert.ToDateTime(reader["DSDCHILDEndDate"].ToString());
                            _Document.documentSetDocumentChild.FKParentDocumentUID    = Convert.ToInt32(reader["DSDCHILDFKParentDocumentUID"].ToString());
                            _Document.documentSetDocumentChild.SequenceNumber         = Convert.ToInt32(reader["DSDCHILDSequenceNumber"].ToString());
                            _Document.documentSetDocumentChild.FKParentDocumentSetUID = Convert.ToInt32(reader["DSDCHILDFKParentDocumentSetUID"].ToString());

                            ret.documentSetDocumentLinkList.Add(_Document);
                        }
                    }
                }
            }
            return(ret);
        }