コード例 #1
0
        public void LinkDocumentListToSet(ListOfscDocoSetDocumentLink docListToLink)
        {
            // for each document in the list
            // check if it is already linked with document set
            // if it is not linked, add a new link record
            // otherwise, ignore link.

            foreach (var doco in docListToLink.list)
            {
                DocumentSetDocument dslLocate = new DocumentSetDocument();
                dslLocate.StartDate        = DateTime.Today;
                dslLocate.IsVoid           = 'N';
                dslLocate.FKDocumentUID    = doco.document.UID;
                dslLocate.FKDocumentSetUID = doco.documentSet.UID;

                if (dslLocate.Find(doco.document.UID, doco.documentSet.UID, 'N'))
                {
                    // Fact: There is an existing non-voided row
                    // Intention (1): Make it void
                    // Intention (2): Do nothing
                    //

                    // Check for Intention (1)
                    //
                    if (doco.DocumentSetDocument.IsVoid == 'Y')
                    {
                        // Update row to make it voided...
                        //
                        Update(doco.DocumentSetDocument.UID);
                    }

                    // else, do nothing
                }
                else
                {
                    // if the pair does not exist, check if it is void.
                    // If void = Y, just ignore.

                    if (doco.DocumentSetDocument.IsVoid == 'Y')
                    {
                        // just ignore. The pair was not saved initially.
                    }
                    else
                    {
                        // add document to set

                        DocumentSetDocument dslAdd = new DocumentSetDocument();
                        dslAdd.StartDate        = DateTime.Today;
                        dslAdd.IsVoid           = 'N';
                        dslAdd.FKDocumentUID    = doco.document.UID;
                        dslAdd.FKDocumentSetUID = doco.documentSet.UID;

                        dslAdd.Add();
                    }
                }
            }
        }
コード例 #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;
        }