/// <summary> /// Binds the indicators by order. /// </summary> /// <param name="sort">The sort.</param> /// <param name="sortdir">The sortdir.</param> /// <param name="showInActive"></param> /// <returns></returns> public ActionResult BindIndicatorsByOrder(string sort, string sortdir, int showInActive) { using (var bal = new DashboardIndicatorsBal()) { //Get the Entity list var list = bal.GetDashboardIndicatorsListActiveInActive(Helpers.GetSysAdminCorporateID(), showInActive); //Intialize the View Model i.e. DashboardIndicatorsView which is binded to Main View Index.cshtml under DashboardIndicators var orderByExpression = HtmlExtensions.GetOrderByExpression <DashboardIndicatorsCustomModel>(sort); var data = HtmlExtensions.OrderByDir <DashboardIndicatorsCustomModel>(list, sortdir, orderByExpression); //Pass the View Model in ActionResult to View DashboardIndicators return(PartialView(PartialViews.DashboardIndicatorsList, data)); } }
/// <summary> /// Exports to excel. /// </summary> /// <returns></returns> public ActionResult ExportToExcel(int?showInActive) { var workbook = new HSSFWorkbook(); var sheet = workbook.CreateSheet("DashboardIndicatorsData"); var format = workbook.CreateDataFormat(); sheet.CreateFreezePane(0, 1, 0, 1); sheet.SetAutoFilter(CellRangeAddress.ValueOf("A1:L1")); // Add header labels var rowIndex = 0; var row = sheet.CreateRow(rowIndex); row.CreateCell(0).SetCellValue("Indicator Number"); row.CreateCell(1).SetCellValue("Dashboard"); row.CreateCell(2).SetCellValue("Description"); row.CreateCell(3).SetCellValue("Defination"); row.CreateCell(4).SetCellValue("Sub Category 1"); row.CreateCell(5).SetCellValue("Sub Category 2"); row.CreateCell(6).SetCellValue("Format Type"); row.CreateCell(7).SetCellValue("Decimal Numbers"); row.CreateCell(8).SetCellValue("Ferquency Type"); row.CreateCell(9).SetCellValue("OwnerShip"); row.CreateCell(10).SetCellValue("Facility"); row.CreateCell(11).SetCellValue("SortOrder"); rowIndex++; using (var bal = new DashboardIndicatorsBal()) { var indicatorsData = bal.GetDashboardIndicatorsListActiveInActive(Helpers.GetSysAdminCorporateID(), showInActive); indicatorsData = indicatorsData.OrderBy(x => Convert.ToInt32(x.IndicatorNumber)).ToList(); var cellStyle = workbook.CreateCellStyle(); cellStyle.DataFormat = HSSFDataFormat.GetBuiltinFormat("0.00"); foreach (var item in indicatorsData) { row = sheet.CreateRow(rowIndex); row.CreateCell(0).SetCellType(CellType.Numeric); row.CreateCell(0).CellStyle = cellStyle; row.CreateCell(0).SetCellValue(Convert.ToDouble(item.IndicatorNumber)); row.CreateCell(1).SetCellValue(item.Dashboard); row.CreateCell(2).SetCellValue(item.Description); row.CreateCell(3).SetCellValue(item.Defination); row.CreateCell(4).SetCellValue(item.SubCategoryFirst); row.CreateCell(5).SetCellValue(item.SubCategorySecond); row.CreateCell(6).SetCellValue(item.FormatTypeStr); row.CreateCell(7).SetCellType(CellType.Numeric); row.CreateCell(7).CellStyle = cellStyle; row.CreateCell(7).SetCellValue(item.DecimalNumbers); row.CreateCell(8).SetCellValue(item.FerquencyTypeStr); row.CreateCell(9).SetCellValue(item.OwnerShip); row.CreateCell(10).SetCellValue(item.FacilityNameStr); row.CreateCell(11).SetCellValue(Convert.ToInt32(item.SortOrder)); rowIndex++; } } using (var exportData = new MemoryStream()) { var currentDateTime = Helpers.GetInvariantCultureDateTime(); var cookie = new HttpCookie("Downloaded", "True"); Response.Cookies.Add(cookie); workbook.Write(exportData); var saveAsFileName = string.Format("DashboardIndicatorsData-{0:d}.xls", currentDateTime).Replace("/", "-"); return(File(exportData.ToArray(), "application/vnd.ms-excel", string.Format("{0}", saveAsFileName))); } }