Пример #1
0
        private void btnTestEmail_Click(object sender, EventArgs e)
        {
            Facade.EmailTemplate   facEmailTemplate = new Facade.EmailTemplate();
            Entities.EmailTemplate emailTemplate    = facEmailTemplate.GetForEmailTemplateId(Globals.Configuration.PodEmailTemplateId);

            // Get data to be used to populate placeHolders
            Facade.IPOD facPod = new Facade.POD();
            facPod.SendClientPod(113530);
        }
Пример #2
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);
        }