public List <StudentViewResult> GetViewResult(string RegNo) { SqlConnection connection = new SqlConnection(connectionString); string query = "SELECT * FROM viewresult WHERE Status='1'"; SqlCommand command = new SqlCommand(query, connection); List <StudentViewResult> alist = new List <StudentViewResult>(); connection.Open(); SqlDataReader reader = command.ExecuteReader(); if (reader.HasRows) { while (reader.Read()) { StudentViewResult aStudentViewResult = new StudentViewResult(); aStudentViewResult.RegistrationNo = reader["RegistrationNo"].ToString(); aStudentViewResult.Name = reader["Name"].ToString(); aStudentViewResult.Email = reader["Email"].ToString(); aStudentViewResult.DepartmentName = reader["DepartmentName"].ToString(); aStudentViewResult.CourseId = Convert.ToInt32(reader["CourseId"].ToString()); aStudentViewResult.CourseCode = reader["CourseCode"].ToString(); aStudentViewResult.CourseName = reader["CourseName"].ToString(); aStudentViewResult.Grade = reader["Grade"].ToString(); alist.Add(aStudentViewResult); } reader.Close(); } connection.Close(); return(alist); }
public ActionResult ViewResult(StudentViewResult aStudentViewResult) { StudentManager aStudentManager = new StudentManager(); ViewBag.students = aStudentManager.GetAllStudents(); //PDF var document = new Document(iTextSharp.text.PageSize.A4, 10, 10, 42, 35); PdfWriter.GetInstance(document, Response.OutputStream); document.Open(); var name = new Paragraph("Name :" + aStudentViewResult.Name + "\n\nRegistrationNo :" + aStudentViewResult.RegistrationNo + "\n\nDepartment :" + aStudentViewResult.DepartmentName + "\n\nEmail :" + aStudentViewResult.Email); var newli = new Paragraph("\n"); name.Alignment = Element.ALIGN_CENTER; //regNo.Alignment = Element.ALIGN_CENTER; //dep.Alignment = Element.ALIGN_CENTER; //emal.Alignment = Element.ALIGN_CENTER; document.Add(name); document.Add(newli); //document.Add(regNo); document.Add(newli); //document.Add(dep); document.Add(newli); //document.Add(emal); //create pdf table var table = new PdfPTable(3) { TotalWidth = 216f }; var widths = new float[] { 4f, 5f, 2f }; table.SetWidths(widths); table.HorizontalAlignment = 0; table.SpacingBefore = 30f; table.SpacingAfter = 40f; var ph = new Phrase("Result Sheet"); var nphs = new Phrase("\n"); var first = new Phrase("Course Code"); var second = new Phrase("Course Name"); var third = new Phrase("Grade"); var cell = new PdfPCell(ph); var ncelll = new PdfPCell(nphs); var fcelll = new PdfPCell(first); var scelll = new PdfPCell(second); var tcelll = new PdfPCell(third); cell.Colspan = 3; cell.Border = 0; cell.HorizontalAlignment = 1; ncelll.Colspan = 3; ncelll.Border = 0; ncelll.HorizontalAlignment = 1; fcelll.Colspan = 0; fcelll.Border = Rectangle.BOX; fcelll.HorizontalAlignment = 1; scelll.Colspan = 0; scelll.Border = Rectangle.BOX; scelll.HorizontalAlignment = 1; tcelll.Colspan = 0; tcelll.Border = Rectangle.BOX; tcelll.HorizontalAlignment = 1; table.AddCell(cell); table.AddCell(ncelll); table.AddCell(fcelll); table.AddCell(scelll); table.AddCell(tcelll); string connect = "Server=OSANSHAON-PC;Database=University System DB;Trusted_Connection=True;"; var conn = new SqlConnection(connect); string query = "SELECT CourseCode, CourseName, Grade FROM viewresult WHERE RegistrationNO='" + aStudentViewResult.RegistrationNo + "' AND Status='1'"; var cmd = new SqlCommand(query, conn); conn.Open(); SqlDataReader rdr = cmd.ExecuteReader(); while (rdr.Read()) { table.AddCell(rdr[0].ToString()); table.AddCell(rdr[1].ToString()); table.AddCell(rdr[2].ToString()); } table.HorizontalAlignment = Element.ALIGN_CENTER; document.Add(table); document.Close(); Response.ContentType = "application/pdf"; Response.AddHeader("content-disposition", "attachment; filename = viewresult.pdf"); Response.End(); return(View()); }