public FileContentResult ExportAllPDF() { var db = DB.GetContext(); string fileType = "pdf"; string fileExtendsion = "pdf"; var listThiSinh = db.TN_ExamUser.Where(m => m.IsEnd).OrderBy(m => m.TN_User.FullName).ToList(); if (listThiSinh.Count > 0) { int count = listThiSinh[0].TN_Exam.QuestionCount; string[] getAnswer = { "A", "B", "C", "D", "E", "F", "G", "H" }; DataTable dt = new DataSet1().BCTH; foreach (var item in listThiSinh) { DataRow dr = dt.NewRow(); dr["HoTen"] = item.TN_User.FullName; dr["SBD"] = item.TN_User.SBD; dr["KetQua"] = item.CorrectCount + " / " + count; dt.Rows.Add(dr); } LocalReport localReport = new LocalReport(); localReport.ReportPath = Server.MapPath("~/Views/Exam/BCTH.rdlc"); string title = listThiSinh[0].TN_Exam != null ? listThiSinh[0].TN_Exam.Content : ""; ReportParameter param0 = new ReportParameter("Title", title); ReportDataSource reportDataSource = new ReportDataSource(); localReport.SetParameters(new ReportParameter[] { param0 }); reportDataSource.Name = "DataSet1"; reportDataSource.Value = dt; localReport.DataSources.Add(reportDataSource); Byte[] mybytes = localReport.Render(fileType); Response.AppendHeader("Content-Disposition", "inline; Tong-Hop-Ket-Qua." + fileExtendsion); return(File(mybytes, "application/pdf")); } return(null); }
public FileContentResult ExportPDF(int tnExamUserID) { var db = DB.GetContext(); var tnExamUser = db.TN_ExamUser.FirstOrDefault(m => m.ID == tnExamUserID); if (tnExamUser != null) { var user = tnExamUser.TN_User; string fileType = "pdf"; string fileExtendsion = "pdf"; var listTN_ExamUserAnswer = tnExamUser != null ? tnExamUser.TN_ExamUserAnswer : null; int count = 0; string[] getAnswer = { "A", "B", "C", "D", "E", "F", "G", "H" }; if (listTN_ExamUserAnswer != null && listTN_ExamUserAnswer.Count > 0) { DataTable dt = new DataSet1().KetQua; for (int i = 0; i < listTN_ExamUserAnswer.Count; i++) { var quest = listTN_ExamUserAnswer.ElementAt(i).TN_Question; var answerTrue = quest != null && quest.TN_Answer != null && quest.TN_Answer.Count > 0 ? quest.TN_Answer : null; if (answerTrue != null && answerTrue.Count > 0) { string traloi = "", dapan = ""; for (int j = 0; j < answerTrue.Count; j++) { if (answerTrue.ElementAt(j).ID == listTN_ExamUserAnswer.ElementAt(i).AnswerID) { traloi = getAnswer[j]; } if (answerTrue.ElementAt(j).IsCorrect) { dapan = getAnswer[j]; if (answerTrue.ElementAt(j).ID == listTN_ExamUserAnswer.ElementAt(i).AnswerID) { count++; } } } DataRow dr = dt.NewRow(); dr["CauHoi"] = "Câu " + (i + 1); dr["TraLoi"] = traloi; dr["DapAn"] = dapan; dt.Rows.Add(dr); } } LocalReport localReport = new LocalReport(); localReport.ReportPath = Server.MapPath("~/Views/Home/KetQua.rdlc"); string title = tnExamUser.TN_Exam != null ? tnExamUser.TN_Exam.Content : ""; ReportParameter param0 = new ReportParameter("Title", title); ReportParameter param1 = new ReportParameter("Name", user.FullName); ReportParameter param2 = new ReportParameter("SBD", user.SBD); ReportParameter param3 = new ReportParameter("Mark", count + " / " + listTN_ExamUserAnswer.Count); ReportDataSource reportDataSource = new ReportDataSource(); localReport.SetParameters(new ReportParameter[] { param0, param1, param2, param3 }); reportDataSource.Name = "DataSet1"; reportDataSource.Value = dt; localReport.DataSources.Add(reportDataSource); Byte[] mybytes = localReport.Render(fileType); Response.AppendHeader("Content-Disposition", "inline; Ket-qua_" + user.SBD + "." + fileExtendsion); return(File(mybytes, "application/pdf")); } } return(null); }
public FileContentResult ExportPDF() { var tn_ExamUser = (TN_ExamUser)Session[SessionKey.ExamUserObject]; if (tn_ExamUser == null) return null; var tnExamUser = db.TN_ExamUser.FirstOrDefault(m => m.ID == tn_ExamUser.ID); if (tnExamUser != null) { var user = tnExamUser.TN_User; string fileType = "pdf"; string fileExtendsion = "pdf"; var listTN_ExamUserAnswer = tnExamUser != null ? tnExamUser.TN_ExamUserAnswer : null; int count = 0; string[] getAnswer = { "A", "B", "C", "D", "E", "F", "G", "H" }; if (listTN_ExamUserAnswer != null && listTN_ExamUserAnswer.Count > 0) { DataTable dt = new DataSet1().KetQua; for (int i = 0; i < listTN_ExamUserAnswer.Count; i++) { var quest = listTN_ExamUserAnswer.ElementAt(i).TN_Question; var answerTrue = quest != null && quest.TN_Answer != null && quest.TN_Answer.Count > 0 ? quest.TN_Answer : null; if (answerTrue != null && answerTrue.Count > 0) { string traloi = "", dapan = ""; for (int j = 0; j < answerTrue.Count; j++) { if (answerTrue.ElementAt(j).ID == listTN_ExamUserAnswer.ElementAt(i).AnswerID) { traloi = getAnswer[j]; } if (answerTrue.ElementAt(j).IsCorrect) { dapan = getAnswer[j]; if (answerTrue.ElementAt(j).ID == listTN_ExamUserAnswer.ElementAt(i).AnswerID) { count++; } } } DataRow dr = dt.NewRow(); dr["CauHoi"] = "Câu " + (i + 1); dr["TraLoi"] = traloi; dr["DapAn"] = dapan; dt.Rows.Add(dr); } } LocalReport localReport = new LocalReport(); localReport.ReportPath = Server.MapPath("~/Views/Home/KetQua.rdlc"); string title = tnExamUser.TN_Exam != null ? tnExamUser.TN_Exam.Content : ""; ReportParameter param0 = new ReportParameter("Title", title); ReportParameter param1 = new ReportParameter("Name", user.FullName); ReportParameter param2 = new ReportParameter("SBD", user.SBD); ReportParameter param3 = new ReportParameter("Mark", count + " / " + listTN_ExamUserAnswer.Count); ReportDataSource reportDataSource = new ReportDataSource(); localReport.SetParameters(new ReportParameter[] { param0, param1, param2, param3 }); reportDataSource.Name = "DataSet1"; reportDataSource.Value = dt; localReport.DataSources.Add(reportDataSource); Byte[] mybytes = localReport.Render(fileType); Response.AppendHeader("Content-Disposition", "inline; Ket-qua_" + user.SBD + "." + fileExtendsion); return File(mybytes, "application/pdf"); } } return null; }