public ReportModelView GetFeedbackReport() { ReportModelView report = new ReportModelView(); List <feedback> feedback = null; DynamicParameters param = new DynamicParameters(); using (IDbConnection conn = factory.GetConnection()) { conn.Open(); string SQL = @"[GetFeedBackReport]"; var contents = conn.QueryMultiple(SQL, param, commandType: CommandType.StoredProcedure); if (contents != null) { feedback = contents.Read <feedback>().ToList(); if (feedback != null) { report.Feedback = feedback; report.BrandService = contents.Read <BrandService>().ToList(); report.VehicleType = contents.Read <VehicleType>().ToList(); report.InformationType = contents.Read <InformationType>().ToList(); } } } return(report); }
public ActionResult Reports() { User parent = _userService.FindById(User.Identity.GetUserId()); List <GroupRequest> groupRequests = _groupService.GetAllRequests(User.Identity.GetUserId()); ReportModelView reports = new ReportModelView(); reports.Parent = parent; reports.GroupRequests = groupRequests; return(View(reports)); }
public void ExportToExcel(string key) { if (!string.IsNullOrEmpty(key)) { Guid Auth = new Guid(key); Guid guid = new Guid("753CD850-550E-4FAB-BB48-6DA2AD18F722"); if (Auth != Guid.Empty && Auth == guid) { DataTable list = new DataTable(); string ReportName = "Schaeffler"; var workbook = new XLWorkbook(); string range = "A1:B2"; ReportModelView report = _feedbackDao.GetFeedbackReport(); if (report != null) { if (report != null && report.Feedback != null && report.Feedback.Count > 0 && report.BrandService != null && report.BrandService.Count > 0 && report.VehicleType != null && report.VehicleType.Count > 0 && report.InformationType != null && report.InformationType.Count > 0) { List <feedback> fb = report.Feedback; List <BrandService> BS = report.BrandService; List <VehicleType> VT = report.VehicleType; List <InformationType> TI = report.InformationType; if (fb != null && fb.Count > 0) { DataTable list1 = new DataTable("User Information"); list1 = FeedbackDataTable(fb); var worksheet = workbook.AddWorksheet(list1, "User Information"); worksheet.Row(1).InsertRowsAbove(1); worksheet.Range(range).Row(1); worksheet.Range(range).Row(1).Merge(); } if (BS != null && BS.Count > 0) { DataTable list1 = new DataTable("Brand Service"); list1 = BrandServiceDataTable(BS); DataRow dr1 = list.NewRow(); var worksheet = workbook.AddWorksheet(list1, "Brand Service"); worksheet.Row(1).InsertRowsAbove(1); worksheet.Range(range).Row(1); worksheet.Range(range).Row(1).Merge(); } if (VT != null && VT.Count > 0) { DataTable list1 = new DataTable("Vehicle Type"); list1 = VehicleTypeDataTable(VT); DataRow dr1 = list.NewRow(); var worksheet = workbook.AddWorksheet(list1, "Vehicle Type"); worksheet.Row(1).InsertRowsAbove(1); worksheet.Range(range).Row(1); worksheet.Range(range).Row(1).Merge(); } if (TI != null && TI.Count > 0) { DataTable list1 = new DataTable("Type of Information"); list1 = InformationTypeDataTable(TI); DataRow dr1 = list.NewRow(); var worksheet = workbook.AddWorksheet(list1, "Type of Information"); worksheet.Row(1).InsertRowsAbove(1); worksheet.Range(range).Row(1); worksheet.Range(range).Row(1).Merge(); } } } else { DataTable list1 = new DataTable("report Empty"); var worksheet = workbook.AddWorksheet(list1, "No Results Found"); worksheet.Row(1).InsertRowsAbove(1); worksheet.Range(range).Row(1); worksheet.Range(range).Row(1).Merge(); } Response.AddHeader("content-disposition", "attachment; filename=" + ReportName + "_" + DateTime.Now.ToString() + "Reports.xls"); Response.ContentType = "application/vnd.ms-excel"; Response.Cache.SetCacheability(HttpCacheability.NoCache); using (var ms = new MemoryStream()) { workbook.SaveAs(ms); ms.WriteTo(Response.OutputStream); ms.Close(); } Response.Flush(); Response.End(); } else { RedirectToAction("Index"); } } }