Example #1
0
        //This generates all of the rows and cells for the report
        public ReportGenerator(int id, DateTime startDate, DateTime endDate, IPASEntities db)
        {
            reportId = id;
            startDateTime = startDate;
            endDateTime = endDate;
            repository = new Repository(db);
            columnHeaders = new List<string>();
            rowHeaders = new List<string>();
            finalReportRows = new List<FinalReportRow>();
            initialReportRowsList = repository.GetReportRowsForReportId(id);
            reportType = repository.GetReportType(reportId);
            measurementList = repository.GetAllAvaliableMeasurementsManageMeasurement();
            reportMeasurementList = new List<BaseFieldsViewModel>();

            // Build headers
            title = repository.GetReportTitle(reportId);
            GetReportColumnList();

            //Build data for report type 1(PAS Report)
            if (reportType == 1)
            {
                //populate reportMeasurementList with only measures that are in the report
                foreach (var measure in measurementList)
                {
                    int? measureIdInReport = null;
                    foreach (var row in initialReportRowsList)
                        if (row.Type == 1 && measure.MeasurementID == Convert.ToInt32(row.Row_Item))
                            measureIdInReport = Convert.ToInt32(row.Row_Item);

                    if (measureIdInReport != null)
                        reportMeasurementList.Add(measure);
                }

                //build Rows
                foreach (var row in initialReportRowsList)
                {
                    // Make new FinalReportrow
                    FinalReportRow reportRow = new FinalReportRow();

                    switch (row.Type)
                    {
                        case 1: //row is a measure
                            int measureId = Convert.ToInt32(row.Row_Item);
                            reportRow.rowName = reportMeasurementList.Find(m => m.MeasurementID == measureId).NameMeasurement;
                            rowHeaders.Add(reportRow.rowName);
                            //TODO optimize call so it only makes one database call per row, instead of once per column in each row
                            foreach (var col in columnList)
                            {
                                // Go through each column and get Datapoint
                                var list = repository.GetReportDatapoint(measureId, (ReportColumnsEnum)col.Type, startDate, endDate);

                                // Add DP to RR
                                reportRow.measurementId = measureId;
                                if (list == null)
                                    reportRow.rowItems.Add(new RowItemWithMetadata("", ""));
                                else
                                    foreach (var item in list)
                                        reportRow.rowItems.Add(item.cellData == null ? new RowItemWithMetadata("", "") : new RowItemWithMetadata(item.cellData, item.cellMetadata));
                            }
                            break;
                        case 2: //row is a Display Text
                            reportRow.rowName = row.Row_Item;
                            rowHeaders.Add(row.Row_Item);
                            reportRow.isHeader = true;
                            break;
                        case 3: //row is a Category Score
                            switch (row.Row_Item)
                            {
                                case "1":
                                    GetCategoryScoreData("Key Performance", startDate, endDate, ref reportRow);
                                    break;
                                case "2":
                                    GetCategoryScoreData("Financial", startDate, endDate, ref reportRow);
                                    break;
                                case "3":
                                    GetCategoryScoreData("HR", startDate, endDate, ref reportRow);
                                    break;
                                default:
                                    //error
                                    break;
                            }
                            break;
                        default:
                            //error
                            break;
                    }

                    // Add RR to table
                    finalReportRows.Add(reportRow);
                }
            }
        }