public void btnSubmit_Click(object sender, EventArgs e) { MarksDAL mdal = new MarksDAL(); int id = Convert.ToInt32(Session["Marks_Key"]); DataSet ds = mdal.getData(id); for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { DataTable dt = ds.Tables[0]; DataRow dr = dt.Rows[0]; try { int marks = Convert.ToInt32(String.Format("{0}", Request.Form["" + i + "</td"])); if (marks > 100) { lblError.Text = "Incorrect Marks Entered"; break; } else if (marks == null) { lblError.Text = "Marks Columns is blank"; break; } int course_id = Convert.ToInt32(dr["Course_id"]); int student_id = Convert.ToInt32(ds.Tables[0].Rows[i]["Student_id"]); MarksDAL mdale = new MarksDAL(); mdale.AddMarks(student_id, course_id, marks); lblError.ForeColor = System.Drawing.Color.Green; lblError.Text = "Succesfully Entered Marks"; DBDataPlaceHolder.Visible = false; btnSubmit.Visible = false; } catch (Exception ex) { lblError.Text = "Succesfully Entered Marks"; } } }
public IActionResult StudentListView() { StudentDAL dal = new StudentDAL(); List <Student> students = (List <Student>)dal.GetAllStudents(); ViewData["students"] = students; SubjectDAL dal2 = new SubjectDAL(); List <Subject> subjects = (List <Subject>)dal2.GetAllSubjects(); MarksDAL dal3 = new MarksDAL(); List <Marks> marks = (List <Marks>)dal3.GetAllMarks(); var TotalStudent = students.Count(); ViewData["TotalStudents"] = TotalStudent; var TotalSubjects = subjects.Count(); ViewData["TotalSubjects"] = TotalSubjects; //MiniMarks in each Subject var innerjoin = (from st in marks join sub in subjects on st.Subject_ID equals sub.ID select new { Subject = sub.Name, Marks = st.Value }).ToList(); var MinMarks = (from ij in innerjoin group ij by ij.Subject into ijGroup select new { Subject = ijGroup.Key, MinMarks = ijGroup.Min(x => x.Marks) }); ViewData["MiniMumMarks"] = MinMarks; //MaximumMarks in each Subject var MaxMarks = (from ij in innerjoin group ij by ij.Subject into ijGroup select new { Subject = ijGroup.Key, MaxMarks = ijGroup.Max(x => x.Marks) }); ViewData["MaxMarks"] = MaxMarks; //Avergae in each Subject var AvgMarks = (from ij in innerjoin group ij by ij.Subject into ijGroup select new { Subject = ijGroup.Key, AvgMarks = ijGroup.Average(x => x.Marks) }); ViewData["AvgMarks"] = AvgMarks; var crossjoin = (from st in students from sub in subjects select new { st.ID, st.Name, st.Email, st.Address, st.Class, Subject = sub.Name, Subject_ID = sub.ID }).ToList(); var mark = (from m in marks from cs in crossjoin where m.Student_ID == cs.ID && m.Subject_ID == cs.Subject_ID select new { cs.ID, cs.Name, cs.Email, cs.Address, cs.Class, cs.Subject_ID, Marks = m.Value, cs.Subject } ).ToList(); ViewData["crossjoin"] = mark; //Highestmarks var stud = from s in mark group s by s.Subject into stugrp let topp = stugrp.Max(x => x.Marks) select new { Subject = stugrp.Key, TopStudent = stugrp.First(y => y.Marks == topp).ID, MaximumMarks = topp } ; var HighestMarks = (from h in mark from st in stud where h.ID == st.TopStudent && h.Subject == st.Subject select new { Name = h.Name, Email = h.Email, Address = h.Address, Subject = st.Subject, Marks = st.MaximumMarks }).ToList(); ViewData["HighestMarks"] = HighestMarks; //Lowest Marks var Loweststud = from s in mark group s by s.Subject into Loweststudgrp let low = Loweststudgrp.Min(x => x.Marks) select new { Subject = Loweststudgrp.Key, TopStudent = Loweststudgrp.First(y => y.Marks == low).ID, LowestMarks = low } ; var lowestMarks = (from h in mark from st in Loweststud where h.ID == st.TopStudent && h.Subject == st.Subject select new { Name = h.Name, Email = h.Email, Address = h.Address, Subject = st.Subject, Marks = st.LowestMarks }).ToList(); ViewData["lowestMarks"] = lowestMarks; return(View()); }
public void Page_Load(object sender, EventArgs e) { MarksDAL mdal = new MarksDAL(); try { this.Master.name.Text = Session["User"].ToString(); } catch (Exception ex) { Response.Redirect("index.aspx"); } int id = Convert.ToInt32(Session["Marks_Key"]); DataSet ds1 = mdal.CheckMarksUploaded(id); if (ds1.Tables[0].Rows.Count > 0) { lblError.ForeColor = System.Drawing.Color.Green; btnSubmit.Visible = false; lblError.Text = "Marks Already Uploaded"; } else { DataTable dt = new DataTable(); StringBuilder htmlTable = new StringBuilder(); DataSet ds = mdal.getData(id); htmlTable.Append("<table border='1' id='Table1' class='table-hover' width='500px' height='80'>"); htmlTable.Append("<tr style='background-color:green; color: White; '><th style='text-align:center'>Student ID</th><th style='text-align:center'>Student Name</th><th style='text-align:center'>Enter Marks (out of 100)</th></tr>"); int j = 1000; for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { htmlTable.Append("<tr style='color: black;'>"); htmlTable.Append("<td>" + ds.Tables[0].Rows[i]["Student_id"] + "</td>"); htmlTable.Append("<td>" + ds.Tables[0].Rows[i]["Student_Name"] + "</td>"); htmlTable.Append("<td> <input runat='server' type='text' id=" + i + " name=" + i + "</td>"); htmlTable.Append("</tr>"); } htmlTable.Append("</table>"); DBDataPlaceHolder.Controls.Add(new Literal { Text = htmlTable.ToString() }); if (ds.Tables[0].Rows.Count == 0) { DBDataPlaceHolder.Visible = false; lblError.ForeColor = System.Drawing.Color.Green; btnSubmit.Visible = false; lblError.Text = "There are no Students Currently Registered for Course"; } } }