示例#1
0
        public ActionResult TrackPG(Report report)
        {
            if (report.type == "Primary")
            {
                ViewBag.first = repoService.primaryGuardianRepo.FindById(report.pgid).FirstName;
                ViewBag.last = repoService.primaryGuardianRepo.FindById(report.pgid).LastName;
                ViewBag.pgid = report.pgid;
            }
            else if (report.type == "Child")
            {
                ViewBag.first = repoService.childRepo.FindById(report.pgid).FirstName;
                ViewBag.last = repoService.childRepo.FindById(report.pgid).LastName;
            }

            ViewBag.type = report.type;

            var repo = getVisitHistory(report.startDay2, report.endDay2, report.type, report.pgid);
            return View(repo);
        }
示例#2
0
        public ActionResult Generate(Report report, int mode)
        {
            DateTime startday = report.startDay;
            DateTime endday = report.endDay.AddDays(1);
            string[,] pgTable = getStringPGTable(report.startDay, endday);
            string[,] languageTable = getStringLanguageTable(report.startDay, endday);
            string[,] countryTable = getStringCountryTable(report.startDay, endday);
            ViewBag.myReport = report;
            ViewBag.center = repoService.centerRepo.FindAll().ToArray();
            ViewBag.pgTable = pgTable;
            ViewBag.languageTable = languageTable;
            ViewBag.countryTable = countryTable;

            if (mode == 1)
            {
                return View();
            }
            else if (mode == 2)
            {

                Response.AddHeader("content-disposition", "attachment; filename=Report.csv");
                Response.ContentType = "text/plain; charset=UTF-8";
                parseStringTable(pgTable);
                parseStringTable(countryTable);
                parseStringTable(languageTable);

                Response.End();

            }
            else if (mode == 3)
            {
                // filename for temporary excel file
                string tempFileName = Path.GetTempFileName();
                System.IO.File.Delete(tempFileName); // delete the file created so we can save as
                tempFileName += ".xlsx";

                SpreadsheetDocument spreadsheetDocument = SpreadsheetDocument.Create(tempFileName, SpreadsheetDocumentType.Workbook);

                // Add a WorkbookPart to the document.
                WorkbookPart workbookpart = spreadsheetDocument.AddWorkbookPart();
                workbookpart.Workbook = new Workbook();

                // Add a WorksheetPart to the WorkbookPart.
                WorksheetPart worksheetPart = workbookpart.AddNewPart<WorksheetPart>();
                worksheetPart.Worksheet = new Worksheet(new SheetData());

                // Add Sheets to the Workbook.
                Sheets sheets = spreadsheetDocument.WorkbookPart.Workbook.AppendChild<Sheets>(new Sheets());

                // Append a new worksheet and associate it with the workbook.
                Sheet sheet = new Sheet() { Id = spreadsheetDocument.WorkbookPart.GetIdOfPart(worksheetPart), SheetId = 1, Name = "Sheet1" };
                sheets.Append(sheet);

                // Get the sheetData cell table.
                SheetData sheetData = worksheetPart.Worksheet.GetFirstChild<SheetData>();

                uint rowIndex = 1;

                for (uint i = 0; i < pgTable.GetLength(0); i++)
                {
                    // add a row to the cell table
                    Row row;
                    row = new Row() { RowIndex = rowIndex };
                    sheetData.Append(row);

                    // populate the row
                    for (uint j = 0; j < pgTable.GetLength(1); j++)
                    {
                        CreateCell(row, pgTable[i, j], j);
                    }
                    rowIndex++;
                }

                // one blank row to separate data
                rowIndex++;

                for (uint i = 0; i < countryTable.GetLength(0); i++)
                {
                    // add a row to the cell table
                    Row row;
                    row = new Row() { RowIndex = rowIndex };
                    sheetData.Append(row);

                    // populate the row
                    for (uint j = 0; j < countryTable.GetLength(1); j++)
                    {
                        CreateCell(row, countryTable[i, j], j);
                    }
                    rowIndex++;
                }

                // one blank row to separate data
                rowIndex++;

                for (uint i = 0; i < languageTable.GetLength(0); i++)
                {
                    // add a row to the cell table
                    Row row;
                    row = new Row() { RowIndex = rowIndex };
                    sheetData.Append(row);

                    // populate the row
                    for (uint j = 0; j < languageTable.GetLength(1); j++)
                    {
                        CreateCell(row, languageTable[i, j], j);
                    }
                    rowIndex++;
                }

                workbookpart.Workbook.Save();
                spreadsheetDocument.Close();

                Response.Clear();
                Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
                Response.AddHeader("content-disposition", "attachment; filename=Report.xlsx");

                Response.WriteFile(tempFileName);
                Response.Flush();

                // clean temp file
                System.IO.File.Delete(tempFileName);
                Response.End();
            }
            return View();
        }
示例#3
0
        public ActionResult Index(Report report)
        {
            DateTime startDay = report.startDay;
            DateTime endDay = report.endDay;

            ViewBag.myReport = report;
            ViewBag.numOfNewPG = getNumOfNewPGTable(startDay, endDay);

            return RedirectToAction("Generate","Report");
        }