public PdfViewModel(string displayName, ModuleNames module, ReportRecord reportRecord) { DisplayName = displayName; this.ReportRecord = reportRecord; DialogHeight = IoC.Get<IShell>().CurrentHeight - 125; DialogWidth = IoC.Get<IShell>().CurrentWidth - 50; this.ModuleName = module; }
public void ReportCreated(object obj) { CoaCreateReportViewModel returnedModel = (CoaCreateReportViewModel)obj; if (returnedModel.WasCanceled) return; if (returnedModel.IsShowReport) { ReportRecord report = new ReportRecord(); report.Id = returnedModel.ReportId; report.ParentId = returnedModel.Sample.ARLNumber; ShowReport(report); } this.LoadViewPendingCOAs().AsCoroutine(); }
private void ShowReport(ReportRecord report) { Shell.Value.Dialogs.ShowDialog(new PdfViewModel("Report View", ModuleNames.Samples, report)); }
public ReportRecord CreateCoaReport(Sample sample, Identification identification) { ReportRecord rc = new ReportRecord(); DateTime reportDate = DateTime.Now; // Update Timepoint Data List<SampleTest> testsNotOnReport = new List<SampleTest>(); CoaReportModel reportData = new CoaReportModel(); try { /* using (DbConnection = new MsSqlPersistence(DbConnectionSettings, true)) { if (DbConnection.IsConnected()) { using (DbCommand) { // GET User using (UserDAO userDao = new UserDAO()) reportData.User = userDao.GetUser(ref dbConnection, ref dbCommand, identification.UserId); foreach (SampleTest test in sample.SampleTests) { List<TimePoint> timpointsNotOnReport = new List<TimePoint>(); //var isOnReport = Convert.ToBoolean(test.TimePoints.Count(x => x.IsOnReport == true)); //if (!isOnReport) //testsNotOnReport.Add(test); /*foreach (TimePoint timePoint in test.TimePoints) { if (!timePoint.IsOnReport) timpointsNotOnReport.Add(timePoint); if (timePoint.ReportDate.IsNull()) timePoint.ReportDate = reportDate; if ((timePoint.ReportBy == 0 || timePoint.ReportBy.IsNull()) && timePoint.IsOnReport) { timePoint.ReportBy = identification.UserId; timePoint.ReportedByUser = reportData.User.FullName; } UpdateOrderSampleTestTimePointReportData(ref dbConnection, ref dbCommand, (int)timePoint.Id, timePoint.IsOnReport, timePoint.ReportDate, timePoint.ReportBy); if (test.CatalogItem.AnalyteId.IsNotNull() && test.CatalogItem.AnalyteId > 0) { timePoint.ResultDetail.ExpectedAmount = sample.SampleAnalytes.FirstOrDefault(a => a.AnalyteId == test.AnalyteId).Amount; timePoint.ResultDetail.ExpectedUnits = sample.SampleAnalytes.FirstOrDefault(a => a.AnalyteId == test.AnalyteId).AmountUOM; } } foreach (TimePoint removeTimePoint in timpointsNotOnReport) { //test.TimePoints.Remove(removeTimePoint); } } } } else { throw new Exception("Unable to Connect"); } } } catch { throw; } foreach (SampleTest onTest in testsNotOnReport) sample.SampleTests.Remove(onTest); // Create Report try { string customerSql = @" select customers.id, customers.customer_name, customers.accountingid, customers.termid, terms.value as terms, customers.credit_check , customers.web_client, customers.sales_rep_id, (users.firstname + ' ' + users.lastname) as modifieduser, (users2.firstname + ' ' + users2.lastname) as createduser, customers.modified_by, customers.modified_date, customers.created_by, customers.created_date, salesrep.firstname, salesrep.lastname from customers LEFT JOIN [User] as users ON customers.modified_by = users.UserID LEFT JOIN [User] as users2 ON customers.created_by = users2.UserID LEFT JOIN list.terms as terms ON customers.termid = terms.termid LEFT JOIN [User] as salesrep ON customers.sales_rep_id = salesrep.UserID LEFT JOIN orders ON orders.parentid = customers.id where orders.id = "; // Get Customer for Sample using (ClientDAO dao = new ClientDAO()) reportData.Customer = dao.GetClient(0); string getOrderNotesSql = @" SELECT orders_notes.id, orders_notes.parentid,orders_notes.txt,orders_notes.is_show_on_report, orders_notes.html, orders_notes.linked_type, orders_notes.linked_id, orders_notes.isnotify, (users.firstname + ' ' + users.lastname) as modifieduser, orders_notes.modified_by, orders_notes.modified_date, orders_notes.created_by, orders_notes.created_date, (users2.firstname + ' ' + users2.lastname) as createduser FROM orders_notes LEFT JOIN [User] as users ON orders_notes.modified_by = users.UserID LEFT JOIN [User] as users2 ON orders_notes.created_by = users2.UserID WHERE parentid = @ID AND orders_notes.delete_date IS NULL AND orders_notes.linked_id = 0 AND orders_notes.linked_type = '" + EnumNoteLink.None.ToString() + @"' AND orders_notes.is_show_on_report = 1 "; //reportData.ReportNotes = GetSampleNotes(sample.ARLNumber.Value, identification, getOrderNotesSql); string getSampleNotesSql = @" SELECT orders_notes.id, orders_notes.parentid,orders_notes.txt,orders_notes.is_show_on_report, orders_notes.html, orders_notes.linked_type, orders_notes.linked_id, orders_notes.isnotify, (users.firstname + ' ' + users.lastname) as modifieduser, orders_notes.modified_by, orders_notes.modified_date, orders_notes.created_by, orders_notes.created_date, (users2.firstname + ' ' + users2.lastname) as createduser FROM orders_notes LEFT JOIN [User] as users ON orders_notes.modified_by = users.UserID LEFT JOIN [User] as users2 ON orders_notes.created_by = users2.UserID WHERE parentid = @ID AND orders_notes.delete_date IS NULL AND orders_notes.linked_id = " + sample.ARLNumber.Value + @" AND orders_notes.linked_type = '" + EnumNoteLink.Sample.ToString() + @"' AND orders_notes.is_show_on_report = 1 "; foreach (SampleTest test in sample.SampleTests) { string getTestNotesSql = @" SELECT orders_notes.id, orders_notes.parentid,orders_notes.txt,orders_notes.is_show_on_report, orders_notes.html, orders_notes.linked_type, orders_notes.linked_id, orders_notes.isnotify, (users.firstname + ' ' + users.lastname) as modifieduser, orders_notes.modified_by, orders_notes.modified_date, orders_notes.created_by, orders_notes.created_date, (users2.firstname + ' ' + users2.lastname) as createduser FROM orders_notes LEFT JOIN [User] as users ON orders_notes.modified_by = users.UserID LEFT JOIN [User] as users2 ON orders_notes.created_by = users2.UserID WHERE parentid = @ID AND orders_notes.delete_date IS NULL AND orders_notes.linked_id = " + test.SampleTestId.Value + @" AND orders_notes.linked_type = '" + EnumNoteLink.Test.ToString() + @"' AND orders_notes.is_show_on_report = 1 "; //test.ReportNotes = GetSampleNotes(test.ARLNumber.Value, identification, getTestNotesSql); } */ reportData.Sample = sample; if (!string.IsNullOrWhiteSpace(reportData.User.Signature.Signature)) reportData.Signature = Image.FromStream(new MemoryStream(Convert.FromBase64String(Security.AesDecrypt(reportData.User.Signature.Signature, AppVars.dbSettings.BaseKey)))); Reports.Coa report = new Reports.Coa(); //report.ReportData = reportData; ReportProcessor reportProcessor = new ReportProcessor(); InstanceReportSource instanceReportSource = new InstanceReportSource(); instanceReportSource.ReportDocument = report; RenderingResult result = reportProcessor.RenderReport("PDF", instanceReportSource, null); Byte[] pdfReport = result.DocumentBytes; rc.ReferenceId = sample.ARLNumber; rc.DepartmentId = sample.SampleTests[0].DepartmentId; rc.CreatedBy = identification.UserId; rc.CreatedDate = DateTime.Now; rc.ReportData = pdfReport; rc.ReportType = "PDF"; rc.ReportName = "Certificate of Analysis"; rc.SubjectLine = "Result ARL #" + sample.ARLNumber.ToString() + " Lot: " + sample.LotNumber.ToString() + " Drug: " + sample.Description.ToString(); rc.Id = SaveReport(rc); } catch { throw; } return rc; }
public int SaveReport(ReportRecord report) { int returnValue = -1; try { string sql = string.Empty; using (DbConnection = new MsSqlPersistence(DbConnectionSettings, true)) { if (DbConnection.IsConnected()) { using (DbCommand) { sql = @" INSERT INTO orders_reports ( parentid, referenceid,departmentid,report_type, report_name, report_data, created_by,created_date) VALUES ( @ParentId,@ReferenceId,@DepartmentId, @ReportType,@ReportName, @ReportData, @CreatedBy, @CreatedDate); SELECT id FROM orders_reports WHERE (id = SCOPE_IDENTITY()) "; DbCommand.Parameters.Clear(); DbCommand.CommandText = sql; DbCommand.Parameters.Add("@ParentId", System.Data.SqlDbType.Int).Value = report.ParentId; DbCommand.Parameters.Add("@ReferenceId", System.Data.SqlDbType.Int).Value = report.ReferenceId; DbCommand.Parameters.Add("@DepartmentId", System.Data.SqlDbType.Int).Value = report.DepartmentId ?? 0; DbCommand.Parameters.Add("@ReportType", System.Data.SqlDbType.VarChar, 3).Value = report.ReportType; DbCommand.Parameters.Add("@ReportName", System.Data.SqlDbType.VarChar, 30).Value = report.ReportName; DbCommand.Parameters.Add("@ReportData", System.Data.SqlDbType.VarBinary, -1).Value = report.ReportData; DbCommand.Parameters.Add("@CreatedBy", System.Data.SqlDbType.Int).Value = report.CreatedBy; DbCommand.Parameters.Add("@CreatedDate", System.Data.SqlDbType.DateTime).Value = report.CreatedDate; returnValue = (int)DbConnection.ExecuteScalar(DbCommand); } } else { throw new Exception("Unable to Connect"); } } } catch { throw; } return returnValue; }
public SmartCollection<ReportRecord> GetOrdersReports(int parentId, Identification identification) { try { SmartCollection<ReportRecord> resultList = new SmartCollection<ReportRecord>(); using (DbConnection = new MsSqlPersistence(DbConnectionSettings)) { if (DbConnection.IsConnected()) { using (DbCommand) { string sql = @" select orders_reports.id, orders_reports.parentid, orders_reports.referenceid, orders_reports.departmentid, orders_reports.report_type,orders_reports.report_name,orders_reports.created_by, orders_reports.created_date, dpart.department_name,dpart.result_template, (users.firstname + ' ' + users.lastname) as createduser from orders_reports LEFT JOIN [User] as users ON orders_reports.created_by = users.UserID LEFT JOIN list.departments as dpart ON orders_reports.departmentid = dpart.departmentid where orders_reports.parentid = @ParentId AND orders_reports.delete_date IS NULL order by orders_reports.created_date DESC "; DbCommand.Parameters.Add("@ParentId", System.Data.SqlDbType.Int).Value = parentId; DbCommand.CommandText = sql; DataTable returnDT = DbConnection.ExecuteQuery(DbCommand); foreach (DataRow row in returnDT.Rows) { ReportRecord report = new ReportRecord(); report.Id = Convert.ToInt32(row["Id"]); report.ParentId = Convert.ToInt32(row["ParentId"]); report.ReferenceId = Convert.ToInt32(row["ReferenceId"]); report.DepartmentId = row["departmentid"] != DBNull.Value ? Convert.ToInt32(row["departmentid"]) : 0; if (report.DepartmentId > 0) report.Department = new Department() { DepartmentId = report.DepartmentId, DepartmentName = row["department_name"].ToString(), ResultTemplateId = (int?)row["result_template"] }; report.ReportType = row["report_type"].ToString(); report.ReportName = row["report_name"].ToString(); report.CreatedBy = row["created_by"] != DBNull.Value ? Convert.ToInt32(row["created_by"]) : 0; report.CreatedUser = row["createduser"].ToString(); report.CreatedDate = row["created_date"] != DBNull.Value ? (DateTime?)row["created_date"] : null; resultList.Add(report); } returnDT = null; } } else { throw new Exception("Unable to Connect"); } } return resultList; } catch { throw; } }
public ReportRecord GetOrdersReport(int id, Identification identification) { try { ReportRecord report = new ReportRecord(); using (DbConnection = new MsSqlPersistence(DbConnectionSettings)) { if (DbConnection.IsConnected()) { using (DbCommand) { DbCommand.CommandText = @" SELECT orders_reports.id, orders_reports.parentid, orders_reports.referenceid, orders_reports.departmentid, orders_reports.report_type,orders_reports.report_name,orders_reports.created_by, orders_reports.created_date, dpart.department_name,dpart.result_template,orders_reports.report_data, (users.firstname + ' ' + users.lastname) as createduser FROM orders_reports LEFT JOIN [User] as users ON orders_reports.created_by = users.UserID LEFT JOIN list.departments as dpart ON orders_reports.departmentid = dpart.departmentid WHERE orders_reports.id = @Id AND orders_reports.delete_date IS NULL ;"; DbCommand.Parameters.Add("@Id", System.Data.SqlDbType.Int).Value = id; var table = dbConnection.ExecuteQuery(dbCommand); if (table.Rows.Count == 1) { var row = table.Rows[0]; report.Id = Convert.ToInt32(row["Id"]); report.ParentId = Convert.ToInt32(row["ParentId"]); report.ReferenceId = Convert.ToInt32(row["ReferenceId"]); report.DepartmentId = row["departmentid"] != DBNull.Value ? Convert.ToInt32(row["departmentid"]) : 0; if (report.DepartmentId > 0) report.Department = new Department() { DepartmentId = report.DepartmentId, DepartmentName = row["department_name"].ToString(), ResultTemplateId = (int?)row["result_template"] }; report.ReportType = row["report_type"].ToString(); report.ReportName = row["report_name"].ToString(); report.ReportData = (byte[])row["report_data"]; report.CreatedBy = row["created_by"] != DBNull.Value ? Convert.ToInt32(row["created_by"]) : 0; report.CreatedUser = row["createduser"].ToString(); report.CreatedDate = row["created_date"] != DBNull.Value ? (DateTime?)row["created_date"] : null; } } } else { throw new Exception("Unable to Connect"); } } return report; } catch { throw; } }
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; } }
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); }
public void ProcessNotifications() { if (!AppVars.ReportNotificationsEnabled) return; if (SysVars.isConsole) Console.WriteLine("Processing Notifications"); ReportNotificationsActive = true; List<ReportNotification> reportNotifications = this.GetReportNotifications(); if (reportNotifications.Count > 0) { foreach (ReportNotification item in reportNotifications) { ContactNotify notify = null; using (ClientDAO cDao = new ClientDAO()) { notify = null; } //cDao.GetContact(item.NotificationId);} item.NotifyContact = notify; ReportRecord report = new ReportRecord(); using (SampleDAO oDao = new SampleDAO()) { report = oDao.GetOrdersReport(item.ReportId, null); } // Email if (notify.IsFax == false) { this.SendReportEmail(notify, item, report); } //Fax if (notify.IsFax == true) { this.ReportSendFaxAsync(notify, item, report); } } } ReportNotificationsActive = false; }