Ejemplo n.º 1
0
        /***********************************************
        * 2.2 Monthly Active Beneficiaries Summary Report
        ***********************************************/

        public ActionResult MonthlyActiveBeneficiariesSummaryReport()
        {
            TrimesterIntervalViewModel trimesterInterval = new TrimesterIntervalViewModel();
            DateTime  projectStartDate  = new DateTime(2016, 09, 21);
            DateTime  currentDate       = DateTime.Now;
            Trimester currenteTrimester = trimesterQueryService.GetTrimesterByDate(currentDate);

            List <SelectListItem> TrimesterList = new List <SelectListItem>();

            TrimesterList.AddRange(new SelectList(db.Trimesters.Where(t => t.StartDate >= projectStartDate && t.EndDate <= currenteTrimester.EndDate)
                                                  .OrderByDescending(x => x.Seq), "Seq", "TrimesterDescription"));
            //if (SequenceID > 0) TrimesterList.Where(x => x.Value == SequenceID.ToString()).FirstOrDefault().Selected = true;
            ViewBag.SequenceID = TrimesterList;

            return(View(trimesterInterval));
        }
Ejemplo n.º 2
0
        public ActionResult DownloadMonthlyActiveBeneficiariesSummaryReport([Bind(Include = "SequenceID")] TrimesterIntervalViewModel trimesterIntervalDTO)
        {
            var fileName = @"~\Templates\SummaryReports\monthly-active-beneficiaries-summary.xlsx";

            Microsoft.Office.Interop.Excel.Application excelApp = new Microsoft.Office.Interop.Excel.Application();
            Excel._Workbook workbook = excelApp.Workbooks.Open(Server.MapPath(fileName));
            //Excel._Worksheet worksheet = excelApp.ActiveSheet;

            DateTime CurrentTrimesterInitialDate = trimesterQueryService.getTrimesterStartOrEndDateByID(trimesterIntervalDTO.SequenceID, "start");
            DateTime CurrentTrimesterLastDate    = trimesterQueryService.getTrimesterStartOrEndDateByID(trimesterIntervalDTO.SequenceID, "end");

            string evaluationType = "ReportData";

            // Worksheet 2, grouped by partner

            Excel._Worksheet worksheet = excelApp.Worksheets[2];
            worksheet.Range["AG2:AN2"].Value = "Período de " + CurrentTrimesterInitialDate.ToShortDateString() + " à " + CurrentTrimesterLastDate.ToShortDateString();

            var row    = 6;
            var column = 0;
            List <EFDataAccess.DTO.MonthlyActiveBeneficiariesSummaryReportDTO> dataPartner = summaryReports.getMonthlyActiveBeneficiariesSummaryPartner(CurrentTrimesterInitialDate, CurrentTrimesterLastDate);

            foreach (var refType in dataPartner)
            {
                row++; column = 1;
                foreach (var item in refType.PopulatedValues())
                {
                    column++;
                    worksheet.Cells[row, column] = item;
                }
                worksheet.Rows[row + 1].Insert();
            }

            // Worksheet 1, grouped by head partner

            worksheet = excelApp.Worksheets[1];
            worksheet.Range["AG2:AN2"].Value = "Período de " + CurrentTrimesterInitialDate.ToShortDateString() + " à " + CurrentTrimesterLastDate.ToShortDateString();

            row    = 6;
            column = 0;
            List <EFDataAccess.DTO.MonthlyActiveBeneficiariesSummaryReportDTO> dataChiefPartner = summaryReports.getMonthlyActiveBeneficiariesSummaryChiefPartner(CurrentTrimesterInitialDate, CurrentTrimesterLastDate);

            foreach (var refType in dataChiefPartner)
            {
                row++; column = 1;
                foreach (var item in refType.PopulatedValues())
                {
                    column++;
                    worksheet.Cells[row, column] = item;
                }
                worksheet.Rows[row + 1].Insert();
            }

            var temporaryFilepath = Path.ChangeExtension(Path.GetTempFileName(), ".xlsx");

            workbook.SaveAs(temporaryFilepath);
            workbook.Close(0);
            excelApp.Quit();
            DownloadXlsxFile(temporaryFilepath);
            return(RedirectToAction("MonthlyActiveBeneficiariesSummaryReport"));
        }