Beispiel #1
0
        public bool DoesScannedFormRowExist(string fileName)
        {
            bool doesScanFormRowExist = false;

            Facade.Form   facScanForm = new Orchestrator.Facade.Form();
            Entities.Scan scan        = facScanForm.GetForScannedFormForScannedFormPDF(fileName);

            if (scan.ScannedFormId > 0)
            {
                doesScanFormRowExist = true;
            }

            return(doesScanFormRowExist);
        }
Beispiel #2
0
        public string ScanHasBeenUploadedTo(string URL)
        {
            string methodStatus = String.Empty;

            Uri    URI         = new Uri(URL);
            string newFileName = URI.Segments[URI.Segments.Length - 1];

            Facade.Form   facScanForm = new Orchestrator.Facade.Form();
            Entities.Scan scan        = facScanForm.GetForScannedFormForScannedFormPDF(newFileName);

            if (scan == null)
            {
                throw new ApplicationException("ScanHasBeenUploadedTo - Scan not found for filename " + newFileName);
            }

            scan.IsUploaded     = true;
            scan.ScannedFormPDF = URL;

            try
            {
                // update the IsUploaded flag on the scannedForm
                facScanForm.Update(scan, scan.CreateUserID);
            }
            catch (Exception ex)
            {
                throw new ApplicationException("ScanHasBeenUploadedTo - Update ScanForm failed", ex);
            }

            //If the scan is a POD email it
            if (scan.FormTypeId == eFormTypeId.POD)
            {
                //Email the POD to the client
                Facade.IPOD facPod = new Facade.POD();

                //Make the call to send the email async as it will
                //have to download the attachment
                MethodCall <string, int> asyncSendClientPod = facPod.SendClientPod;
                asyncSendClientPod.BeginInvoke(scan.ScannedFormId, r =>
                {
                    try { asyncSendClientPod.EndInvoke(r); }
                    catch (Exception ex) { WebUI.Global.UnhandledException(ex); }
                }, null);
            }

            return(methodStatus);
        }
Beispiel #3
0
        public Entities.Scan GetScannedForm(string FileName, out string PreviousScanURL)
        {
            Facade.Form   facScanForm = new Orchestrator.Facade.Form();
            Entities.Scan scan        = facScanForm.GetForScannedFormForScannedFormPDF(FileName);

            PreviousScanURL = string.Empty;
            if (scan != null && scan.PreviousScannedFormId.HasValue)
            {
                Entities.Scan previousScan = facScanForm.GetForScannedFormId(scan.PreviousScannedFormId.Value);
                if (previousScan != null)
                {
                    PreviousScanURL = previousScan.ScannedFormPDF;
                }
            }

            if (scan == null || scan.ScannedFormId < 1)
            {
                return(null);
            }
            else
            {
                return(scan);
            }
        }
Beispiel #4
0
        public string ScanHasBeenUploaded(string fileNameAndFTPDirectory)
        {
            if (fileNameAndFTPDirectory.StartsWith("\\"))
            {
                fileNameAndFTPDirectory = fileNameAndFTPDirectory.Substring(1, fileNameAndFTPDirectory.Length - 1);
            }

            string pdfLocation            = Server.MapPath("~/PDFS");
            string methodStatus           = String.Empty;
            string newFileName            = Path.GetFileName(fileNameAndFTPDirectory);
            string newFileLocation        = Path.Combine(pdfLocation, fileNameAndFTPDirectory.Replace(newFileName, ""));
            string newFileLocationAndName = Path.Combine(newFileLocation, newFileName);

            Facade.Form   facScanForm = new Orchestrator.Facade.Form();
            Entities.Scan scan        = facScanForm.GetForScannedFormForScannedFormPDF(newFileName);

            if (scan.IsAppend && scan.PreviousScannedFormId != null)
            {
                Entities.Scan existingScan = null;

                // get the previous scannedForm Record
                existingScan = facScanForm.GetForScannedFormId((int)scan.PreviousScannedFormId);

                if (existingScan != null)
                {
                    PdfDocument previousDocument;
                    //string existingFileNameAndPath = Path.Combine(pdfLocation, existingScan.ScannedFormPDF);
                    string existingFileNameAndPath = Server.MapPath(existingScan.ScannedFormPDF);

                    if (File.Exists(existingFileNameAndPath))
                    {
                        previousDocument = PdfReader.Open(existingFileNameAndPath, PdfDocumentOpenMode.Import);

                        try
                        {
                            // should always exist
                            if (!Directory.Exists(newFileLocation))
                            {
                                Directory.CreateDirectory(newFileLocation);
                            }
                        }
                        catch (Exception ex)
                        {
                            throw new ApplicationException("ScanHasBeenUploaded - Error Creating directory - "
                                                           + newFileLocation, ex);
                        }

                        try
                        {
                            // read the exisiting but newly created pdf
                            PdfDocument newPdfDoc = PdfReader.Open(newFileLocationAndName, PdfDocumentOpenMode.Import);

                            PdfDocument finalDoc = new PdfDocument();
                            // Append the previous document to our new document
                            foreach (PdfPage page in previousDocument.Pages)
                            {
                                finalDoc.AddPage(page);
                            }
                            // Append the new document to the previous document
                            foreach (PdfPage page in newPdfDoc.Pages)
                            {
                                finalDoc.AddPage(page);
                            }

                            // attempt to save the new doc
                            finalDoc.Save(newFileLocationAndName);

                            methodStatus = "Appended " + newFileLocationAndName
                                           + " to " + existingFileNameAndPath;
                        }
                        catch (Exception ex)
                        {
                            throw new ApplicationException("ScanHasBeenUploaded - Error appending document - "
                                                           + fileNameAndFTPDirectory, ex);
                        }
                    }
                    else
                    {
                        throw new ApplicationException("ExistingScanForm file could not be found - Path - "
                                                       + existingFileNameAndPath + " - New FileLocationAndName: " + newFileLocationAndName);
                    }
                }
                else
                {
                    throw new ApplicationException("ExistingScanForm entity could not be found.");
                }
            }
            else
            {
                methodStatus = "Append = false or no previousScanneDformId to append too." + Environment.NewLine;
            }

            scan.IsUploaded = true;

            //Use full URL instead
            //scan.ScannedFormPDF = fileNameAndFTPDirectory;
            string URL = this.Context.Request.Url.GetLeftPart(UriPartial.Authority) + "/PDFS/" + fileNameAndFTPDirectory.Replace('\\', '/');

            scan.ScannedFormPDF = URL;

            try
            {
                // update the IsUploaded flag on the scannedForm
                facScanForm.Update(scan, scan.CreateUserID);

                Facade.IPOD facPod = new Facade.POD();
                methodStatus += facPod.SendClientPod(scan.ScannedFormId);
            }
            catch (Exception ex)
            {
                throw new ApplicationException("ScanHasBeenUploaded - Update ScanForm failed (ScanForm ID:" + scan.ScannedFormId + ")", ex);
            }

            return(methodStatus);
        }