Esempio n. 1
0
        /// <summary>
        /// Retrieve the parent folder for a given document
        /// </summary>
        /// <param name="parentDocumentUID"></param>
        /// <returns></returns>
        private static string GetClientDocumentLocation(int clientDocumentUID)
        {
            string         ret            = "";
            var            rs             = BUSClientDocument.ClientDocumentReadS(clientDocumentUID: clientDocumentUID);
            ClientDocument clientDocument = new ClientDocument();


            if (rs.ReturnCode == 1 && rs.ReasonCode == 1)
            {
                clientDocument = (ClientDocument)rs.Contents;

                //  This is to prevent the first level from taking an extra \\ at the front
                // it was causing the folder to be like \\%CLIENTFOLDER%\\
                // At the end the client folder was replace by a physical path
                // and it appears like "\\c:\\fcm\\document\\"

                clientDocument.Location = clientDocument.Location.Trim();

                if (string.IsNullOrEmpty(clientDocument.Location))
                {
                    ret = clientDocument.FileName;
                }
                else
                {
                    ret = clientDocument.Location + "\\" + clientDocument.FileName;
                }
            }

            if (rs.ReturnCode == 1 && rs.ReasonCode == 2)
            {
                // Client document not found
            }

            return(ret);
        }
Esempio n. 2
0
        /// <summary>
        /// Add client
        /// </summary>
        /// <param name="headerInfo"> </param>
        /// <param name="eventClient"></param>
        /// <param name="linkInitialSet"> </param>
        /// <returns></returns>
        public static ResponseStatus ClientAdd(HeaderInfo headerInfo,
                                               Client.Client eventClient,
                                               string linkInitialSet)
        {
            ResponseStatus response = new ResponseStatus();

            //
            // This is a new client.
            //
            if (string.IsNullOrEmpty(eventClient.Name))
            {
                response.ReturnCode = -0010;
                response.ReasonCode = 0001;
                response.Message    = "Client Name is mandatory.";
                response.Contents   = 0;
                return(response);
            }

            // --------------------------------------------------------------
            // Check if user ID is already connected to a client
            // --------------------------------------------------------------
            #region Check if user is already connected to a client
            if (!string.IsNullOrEmpty(eventClient.FKUserID))
            {
                var checkLinkedUser = new Client.Client {
                    FKUserID = eventClient.FKUserID
                };
                var responseLinked = checkLinkedUser.ReadLinkedUser();

                if (!responseLinked.Successful)
                {
                    return(responseLinked);
                }

                if (responseLinked.ReturnCode == 0001 && responseLinked.ReasonCode == 0001)
                {
                    response.ReturnCode = -0010;
                    response.ReasonCode = 0002;
                    response.Message    = "User ID is already linked to another client.";
                    response.Contents   = 0;

                    return(response);
                }
            }
            #endregion

            var newClientUid = 0;

            using (var connection = new SqlConnection(ConnString.ConnectionString))
            {
                using (var tr = new TransactionScope(TransactionScopeOption.Required))
                {
                    connection.Open();

                    // -------------------------------
                    // Call method to add new client
                    // -------------------------------
                    var newClient = eventClient.Insert(headerInfo, connection);
                    //       var newClientX = eventClient.MySQLInsert(headerInfo);

                    newClientUid = Convert.ToInt32(newClient.Contents);

                    // -------------------------------------------
                    // Call method to add client extra information
                    // -------------------------------------------
                    eventClient.clientExtraInformation.FKClientUID = eventClient.UID;
                    var cei = ClientExtraInformation.Insert(
                        HeaderInfo.Instance,
                        eventClient.clientExtraInformation,
                        connection);

                    if (cei.ReturnCode != 1)
                    {
                        // Rollback transaction
                        //
                        tr.Dispose();
                        return(cei);
                    }

                    // --------------------------------------------
                    // Add first document set
                    // --------------------------------------------
                    var cds = new ClientDocumentSet();
                    cds.FKClientUID = newClientUid;

                    // cds.FolderOnly = "CLIENT" + newClientUID.ToString().Trim().PadLeft(4, '0');
                    cds.FolderOnly = "CLIENT" + newClientUid.ToString(CultureInfo.InvariantCulture).Trim().PadLeft(4, '0');

                    // cds.Folder = FCMConstant.SYSFOLDER.CLIENTFOLDER + "\\CLIENT" + newClientUID.ToString().Trim().PadLeft(4, '0');
                    cds.Folder = FCMConstant.SYSFOLDER.CLIENTFOLDER + @"\" + cds.FolderOnly;

                    cds.SourceFolder = FCMConstant.SYSFOLDER.TEMPLATEFOLDER;
                    cds.Add(headerInfo, connection);

                    // --------------------------------------------
                    // Apply initial document set
                    // --------------------------------------------
                    if (linkInitialSet == "Y")
                    {
                        BUSClientDocument.AssociateDocumentsToClient(
                            clientDocumentSet: cds,
                            documentSetUID: eventClient.FKDocumentSetUID,
                            headerInfo: headerInfo);

                        // Fix Destination Folder Location
                        //
                        BUSClientDocumentGeneration.UpdateLocation(cds.FKClientUID, cds.ClientSetID);
                    }

                    // Commit transaction
                    //
                    tr.Complete();
                }
            }

            ClientList(headerInfo);

            // Return new client id
            response.Contents = newClientUid;
            return(response);
        }