Пример #1
0
        public int DoCreateCoaReport(Sample sample, Identification identification)
        {
            ReportRecord reportRecord = null;

            logger.Log(LogLevel.Trace, AppLib.GetCaller(logger));

            using (SampleDAO dao = new SampleDAO()) {
                reportRecord = dao.CreateCoaReport(sample, identification);
            }
            if (reportRecord.Id.IsNotNull() && reportRecord.Id > 0) {
                using (ClientDAO customerDao = new ClientDAO()) {
                    reportRecord.ParentId = customerDao.GetClientId(reportRecord.ParentId.Value);
                }
                using (ReportDAO reportDao = new ReportDAO()) {
                    ReportNotification reportNotification = new ReportNotification();
                    reportNotification.ReportId = reportRecord.Id.Value;
                    reportNotification.CustomerId = reportRecord.ParentId.Value;
                    reportNotification.DepartmentId = reportRecord.DepartmentId.Value;
                    reportNotification.SubjectLine = reportRecord.SubjectLine;
                    reportDao.SaveNotificationReports(reportDao.GetNotificationRecords(reportNotification));
                }
            }

            return reportRecord.Id.Value;
        }
Пример #2
0
 private void RemoveExistingNotificationRecords(ref MsSqlPersistence dbConnection, ref SqlCommand dbCommand, ReportNotification reportNotification)
 {
     try
     {
         string sql = string.Empty;
         if (dbConnection.IsConnected())
         {
             using (dbCommand)
             {
                 sql = @"
                     DELETE
                     FROM report_notifications
                     WHERE report_notifications.departmentid = @DepartmentId
                     ";
                 dbCommand.Parameters.Clear();
                 dbCommand.CommandText = sql;
                 dbCommand.Parameters.Add("@DepartmentId", System.Data.SqlDbType.Int).Value = reportNotification.DepartmentId;
                 dbConnection.ExecuteCommand(dbCommand);
             }
         }
         else
         {
             throw new Exception("Unable to Connect");
         }
     }
     catch
     {
         throw;
     }
 }
Пример #3
0
        private static void RemoveProcessedNotificationRecords(ReportNotification reportNotification)
        {
            try
            {
                MsSqlConnectionSettings staticDbConnectionSettings = new MsSqlConnectionSettings();
                staticDbConnectionSettings.DataSource = AppVars.dbSettings.DataSource;
                staticDbConnectionSettings.Catalog = AppVars.dbSettings.DatabaseName;
                staticDbConnectionSettings.User = AppVars.dbSettings.UserLogin;
                staticDbConnectionSettings.Password = AppVars.dbSettings.Password;

                using (MsSqlPersistence staticConnection = new MsSqlPersistence(staticDbConnectionSettings, true))
                {
                    if (staticConnection.IsConnected())
                    {
                        using (SqlCommand staticCommand = new SqlCommand())
                        {
                            staticCommand.CommandText = @"
                            DELETE
                            FROM report_notifications
                            WHERE report_notifications.id = @Id
                            ";
                            staticCommand.Parameters.Add("@Id", System.Data.SqlDbType.UniqueIdentifier).Value = reportNotification.Id;
                            staticConnection.ExecuteCommand(staticCommand);
                        }

                    }
                    else
                    {
                        throw new Exception("Unable to Connect");
                    }
                }
            }
            catch
            {
                throw;
            }
        }
Пример #4
0
        public void SendReportEmail(ContactNotify notify, ReportNotification notificationRecord, ReportRecord report)
        {
            try
            {
                var htmlBody = string.Empty;
                var textBody = string.Empty;

                if(File.Exists(AppVars.ReportTemplateHtml))
                    htmlBody = File.ReadAllText(AppVars.ReportTemplateHtml);
                if(File.Exists(AppVars.ReportTemplateText))
                    textBody = File.ReadAllText(AppVars.ReportTemplateText);

                MailMessage message = new MailMessage(new MailAddress(AppVars.ReportEmailAddress, "Analytical Research Laboratories"), new MailAddress(notify.Value.Trim(), notify.ContactName));
                MemoryStream stream = new MemoryStream(report.ReportData);
                Attachment attachment = new Attachment(stream, "Certificate of Analysis Report #" + notificationRecord.ReportId.ToString() + ".pdf");
                message.Subject = notificationRecord.SubjectLine; //report.Department.DepartmentName + " Certificate of Analysis Report";
                message.Body = textBody;
                message.IsBodyHtml = false;
                message.BodyEncoding = System.Text.Encoding.UTF8;

                if (!string.IsNullOrWhiteSpace(htmlBody))
                    message.AlternateViews.Add(AlternateView.CreateAlternateViewFromString(htmlBody, null, MediaTypeNames.Text.Html));

                message.Attachments.Add(attachment);

                SmtpClient smtp = new SmtpClient(AppVars.SmtpServer, AppVars.SmtpPort);
                smtp.EnableSsl = AppVars.SmtpServerUseSSL;
                smtp.Credentials = new System.Net.NetworkCredential(AppVars.SmtpAccount, AppVars.SmtpPassword);

                smtp.SendCompleted += SendReportMailCompletedCallback;
                notificationRecord.DisposeMessage = message;
                notificationRecord.DisposeStream = stream;
                smtp.SendAsync(message, notificationRecord);
            }
            catch
            {

                throw;
            }
        }
Пример #5
0
        public void ReportSendFaxAsync(ContactNotify notify, ReportNotification notificationRecord, ReportRecord report)
        {
            if (string.IsNullOrWhiteSpace(AppVars.FaxUserName) || string.IsNullOrWhiteSpace(AppVars.FaxPassword)) return;

            long result = 0;
            int retriesToPerform = 2;
            string pageHeader = "To: {To} From: {From} Pages: {TotalPages}";
            string pageSize = "Letter";
            string pageOrientation = "Portriat";
            bool isHighResolution = false;
            bool isFineRendering = false;
            string fileTypes = "PDF";
            int chunkSize = 200000;
            string sessionId = string.Empty;

            string faxNumber = "1" + notify.Value;

            InterFaxWs.InterFax fws = new InterFaxWs.InterFax();
            if (report.ReportData.Length > chunkSize)
            {
                fws.StartFileUpload(AppVars.FaxUserName, AppVars.FaxPassword, ref sessionId);
                if (sessionId.Length > 0)
                {
                    using (MemoryStream rMs = new MemoryStream(report.ReportData))
                    {
                        bool isLast = false;
                        bool uploadError = false;
                        int readSoFar = 0;

                        while (!isLast && !uploadError)
                        {
                            byte[] b = new byte[chunkSize];
                            int read = rMs.Read(b, 0, b.Length);
                            int uploaded = 0;
                            readSoFar += read;
                            isLast = (readSoFar == rMs.Length);
                            if (read < b.Length)
                            {
                                byte[] b1 = new byte[read];
                                for (int i = 0; i < read; i++) b1[i] = b[i];
                                uploaded = fws.UploadFileChunk(sessionId, b1, isLast);
                            }
                            else
                                uploaded = fws.UploadFileChunk(sessionId, b, isLast);
                            uploadError = (uploaded <= 0);
                        }

                        result = fws.SendfaxEx_2(AppVars.FaxUserName, AppVars.FaxPassword, faxNumber,
                            notify.ContactName, null, fileTypes, readSoFar.ToString() + "/sessionId=" + sessionId,
                            DateTime.MinValue, retriesToPerform, "", pageHeader, "", notificationRecord.SubjectLine,
                            "", pageSize, pageOrientation, isHighResolution, isFineRendering);
                    }
                }
            }
            else {
                result = fws.SendfaxEx_2(AppVars.FaxUserName, AppVars.FaxPassword, faxNumber,
                    notify.ContactName, report.ReportData, fileTypes, report.ReportData.Length.ToString(),
                    DateTime.MinValue, retriesToPerform, "", pageHeader, "", notificationRecord.SubjectLine,
                    "", pageSize, pageOrientation, isHighResolution, isFineRendering);
            }

            if (result > 0)
            {
                ReportDAO.RemoveProcessedNotificationRecords(notificationRecord);
                if (SysVars.isConsole) Console.WriteLine("Fax sent to {1} transaction ID : ", notify.Value, result);
            }
            else
                if (SysVars.isConsole) Console.WriteLine("Result of Fax {0} to {1}", result, notify.Value);
        }
Пример #6
0
        public List<ReportNotification> GetNotificationRecords(ReportNotification reportNotification)
        {
            List<ReportNotification> reportNotifications = new List<ReportNotification>();
            try
            {
                string sql = string.Empty;
                using (DbConnection = new MsSqlPersistence(DbConnectionSettings, true))
                {
                    if (DbConnection.IsConnected())
                    {
                        using (DbCommand)
                        {
                            this.RemoveExistingNotificationRecords(ref  dbConnection, ref dbCommand, reportNotification);

                            if (reportNotification.ReportId > 0)
                            {
                                sql = @"
                                    SELECT DISTINCT contacts_notify.id
                                    FROM contacts_notify
                                    INNER JOIN contacts ON contacts.id = contacts_notify.parentid
                                    INNER JOIN customers ON customers.id = contacts.parentid
                                    WHERE customers.id = @CustomerId AND contacts.delete_date IS NULL
                                    AND (contacts_notify.departmentid = @DepartmentId OR contacts_notify.departmentid = 0 AND contacts_notify.delete_date IS NULL)
                                    ";

                            }
                            DbCommand.Parameters.Clear();
                            DbCommand.CommandText = sql;
                            DbCommand.Parameters.Add("@CustomerId", System.Data.SqlDbType.Int).Value = reportNotification.CustomerId;
                            DbCommand.Parameters.Add("@DepartmentId", System.Data.SqlDbType.Int).Value = reportNotification.DepartmentId;
                            DataTable returnDT = dbConnection.ExecuteQuery(dbCommand);
                            foreach (DataRow row in returnDT.Rows)
                            {
                                ReportNotification record = new ReportNotification();
                                record.Id = Guid.NewGuid();
                                record.ReportId = reportNotification.ReportId;
                                record.CustomerId = reportNotification.CustomerId;
                                record.DepartmentId = reportNotification.DepartmentId;
                                record.NotificationId = (int)row["id"];
                                record.SubjectLine = reportNotification.SubjectLine;
                                reportNotifications.Add(record);
                            }
                        }
                    }
                    else
                    {
                        throw new Exception("Unable to Connect");
                    }
                }
            }
            catch
            {
                throw;
            }
            return reportNotifications;
        }