Ejemplo n.º 1
0
 public CoaReportModel GetDesignCoaReportModelData()
 {
     CoaReportModel results = new CoaReportModel();
     if (AppLib.DesignMode)
     {
         //results.Add(new CoaReportModel());
         //LoadSampleTestMockData(ref results);
     }
     return results;
 }
Ejemplo n.º 2
0
        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;
        }