protected void BindGridView(object p1, EventArgs p2) { var students = new StudentTable(db). GetStudents(ddlFromYear.SelectedValue, ddlFromClass.SelectedValue, ddlFromSection.SelectedValue); var marks = new MarkTable(db). GetYearlyMark(ddlFromYear.SelectedValue, ddlFromClass.SelectedValue, ddlFromSection.SelectedValue); var orderedMarks = marks.OrderByDescending(x => x.Mark).ToList(); for (int i = 1; i <= orderedMarks.Count; i++) { orderedMarks[i - 1].MarkId = i.ToString(); } gvPromote.DataSource = orderedMarks; gvPromote.DataBind(); }
protected void ReloadChart(object sender, EventArgs e) { var studentId = new StudentTable(db).GetStudentId(User.Identity.GetUserId()); var SYCSRId = new StudentYearClassSectionRollTable(db). GetStudentYearClassSectionRollId(ddlYear.SelectedValue, studentId); var dataSource = new MarkTable(db). GetStudentMark(SYCSRId, ddlTerm.SelectedValue, ddlSubject.SelectedValue); Series series = new Series(ddlSubject.SelectedItem.Text); Chart1.Series.Add(series); series.ChartType = SeriesChartType.Spline; //var groups = dataSource.GroupBy(x => x.MarkPortionName); foreach (var mark in dataSource) { series.Points.AddXY(mark.MarkPortionName, mark.Mark); } }
protected void LoadGV(object e, EventArgs o) { var YCSId = new YearClassSectionTable(db).GetYearClassSectionId( new YearTable(db).GetYearId(DateTime.Now.Year), ddlClass.SelectedValue, ddlSecion.SelectedValue); var students = new TeacherSubjectTable(db).GetStudent(ddlSubject.SelectedValue); var portions = new MarkPortionTable(db).GetMarkPortion(ddlSubject.SelectedValue); DataTable table = new DataTable(); table.Columns.Add("Student"); table.Columns.Add("StudentId"); foreach (var portion in portions) { table.Columns.Add(portion.Text); table.Columns.Add(portion.Value); } MarkTable markTable = new MarkTable(db); foreach (var student in students) { var row = table.Rows.Add(); foreach (var portion in portions) { var mark = markTable.GetMark(student.RollYearClassSectionId, ddlTerm.SelectedValue, portion.Value); if (mark == null) { row[portion.Text] = "NULL"; row[portion.Value] = portion.Value; } else { row[portion.Text] = mark.Text; row[portion.Value] = mark.Value; } } } }
protected void LoadGV(object p1, EventArgs p2) { var res = new MarkTable(db).GetTermTabulation(ddlTerm.SelectedValue); DataTable pivotTable = new DataTable(); pivotTable.Columns.Add("Position"); pivotTable.Columns.Add("Roll"); //roll.AutoIncrement = true; //roll.AutoIncrementStep = 1; //roll.AutoIncrementSeed = 1; pivotTable.Columns.Add("First Name"); pivotTable.Columns.Add("Last Name"); Dictionary <string, List <TextValuePair> > subjectMarkPortions = new Dictionary <string, List <TextValuePair> >(); var teacherSubjects = new TeacherSubjectTable(db).GetTeacherSubject( new YearClassSectionTable(db).GetYearClassSectionId(ddlYear.SelectedValue, ddlClass.SelectedValue, ddlSection.SelectedValue)); foreach (var teacherSubject in teacherSubjects) { var portions = new MarkPortionTable(db).GetMarkPortion(teacherSubject.TeacherSubjectId); subjectMarkPortions.Add(teacherSubject.TeacherSubjectId, portions); headerLength.Add(teacherSubject.Name, portions.Count + 1); foreach (var portion in portions) { pivotTable.Columns.Add(portion.Text + "|" + teacherSubject.TeacherSubjectId); } pivotTable.Columns.Add("Total|" + teacherSubject.TeacherSubjectId); } pivotTable.Columns.Add("Grand Total"); var students = new StudentTable(db).GetStudents(ddlYear.SelectedValue, ddlClass.SelectedValue, ddlSection.SelectedValue); var studentMarks = res.GroupBy(x => x.Student.ID).ToList(); foreach (var student in students) { var studentMark = studentMarks.Find(x => x.Key == student.ID); var newRow = pivotTable.Rows.Add(); newRow["Roll"] = student.Roll; newRow["First Name"] = student.FirstName; newRow["Last Name"] = student.LastName; int grandTotal = 0; bool termAbsent = true; if (studentMark == null) { for (int i = 0; i < newRow.ItemArray.Length; i++) { newRow.ItemArray[i] = "A"; } } else { foreach (var subjectMarkPortion in subjectMarkPortions) { int subjectTotal = 0; bool subjectAbsent = true; foreach (var portion in subjectMarkPortion.Value) { try { int mark; if (int.TryParse(studentMark.Where(x => x.PortionId == portion.Value).First().Mark, out mark) && mark >= 0) { newRow[portion.Text + "|" + subjectMarkPortion.Key] = mark; subjectTotal += mark; subjectAbsent = false; } else { newRow[portion.Text + "|" + subjectMarkPortion.Key] = "A"; } } catch (Exception ex) { newRow[portion.Text + "|" + subjectMarkPortion.Key] = "A"; Global.LogError(ex); } } if (subjectAbsent) { newRow["Total|" + subjectMarkPortion.Key] = "A"; } else { newRow["Total|" + subjectMarkPortion.Key] = subjectTotal; termAbsent = false; } grandTotal += subjectTotal; } } if (termAbsent) { newRow["Grand Total"] = "A"; } else { newRow["Grand Total"] = grandTotal; } } pivotTable.DefaultView.Sort = "Grand Total DESC"; gv.DataSource = pivotTable; gv.DataBind(); }
protected void LoadGridView(object sender, EventArgs e) { //var studentId = new UserTable<ApplicationUser>(db).GetUserId(User.Identity.Name); //var dataSource = (ddlSubject.SelectedValue == "all") ? // db.Query("getMarkBySUIdYCSIdTId", // new Dictionary<string, object>() { // { "@SUId", studentId }, // { "@YCSId", ddlYear.SelectedValue }, // {"@TId", ddlTerm.SelectedValue } }, // true) : // db.Query("getMarkBySUIdTidTSId", // new Dictionary<string, object>() { // { "@SUId", studentId }, // {"@TSId", ddlSubject.SelectedValue }, // {"@TId", ddlTerm.SelectedValue } }, // true); //List<string> markPortions = dataSource.Select(x => x["Portion Name"]).Distinct().ToList(); //DataTable pivotTable = new DataTable(); //pivotTable.Columns.Add("Subject", typeof(string)); //foreach (var item in markPortions) { // pivotTable.Columns.Add(item, typeof(string)); //} //var subjects = dataSource.GroupBy(x => x["Subject"]).ToList(); //foreach (var item in subjects) { // DataRow newRow = pivotTable.Rows.Add(); // newRow["Subject"] = item.Key; // foreach (var item2 in item) { // newRow[item2["Portion Name"]] = item2["Mark"]; // } //} var studentId = new StudentTable(db).GetStudentId(User.Identity.GetUserId()); var SYCSRId = new StudentYearClassSectionRollTable(db). GetStudentYearClassSectionRollId(ddlYear.SelectedValue, studentId); var dataSource = new MarkTable(db).GetStudentMark(SYCSRId, ddlTerm.SelectedValue); List <string> markPortions = dataSource.Select(x => x.MarkPortionName).Distinct().ToList(); DataTable pivotTable = new DataTable(); pivotTable.Columns.Add("Subject", typeof(string)); foreach (var markPortion in markPortions) { pivotTable.Columns.Add(markPortion, typeof(string)); } pivotTable.Columns.Add("Total", typeof(string)); pivotTable.Columns.Add("Grade", typeof(string)); var subjects = dataSource.GroupBy(x => x.Subject.ToString(false)).ToList(); foreach (var subject in subjects) { DataRow newRow = pivotTable.Rows.Add(); newRow["Subject"] = subject.Key; int total = 0; foreach (var portion in subject) { newRow[portion.MarkPortionName] = portion.Mark; total += (int)(Convert.ToDouble(portion.Mark)); } newRow["Total"] = total; string grade = null; if (total >= 80) { grade = "A+"; } else if (total >= 70) { grade = "A"; } else if (total >= 60) { grade = "A-"; } else if (total >= 50) { grade = "B"; } else if (total >= 40) { grade = "C"; } else if (total >= 33) { grade = "D"; } else { grade = "F"; } newRow["Grade"] = grade; } gvMark.DataSource = pivotTable; gvMark.DataBind(); }
//protected void LoadDDLStudent(object sndr, EventArgs e) { // var YCSId = new YearClassSectionTable(db).GetYearClassSectionId( // new YearTable(db).GetYearId(DateTime.Now.Year), // ddlClass.SelectedValue, // ddlSecion.SelectedValue); // ddlStudent.DataSource = new TeacherSubjectTable(db).GetStudent(User.Identity.Name, YCSId) // .Select(x => new TextValuePair { Text = x.Roll + ". " + x.FullName, Value = x.ID.ToString() }).ToList(); // ddlStudent.DataBind(); // ddlStudent.Items.Insert(0, new ListItem("All", "all")); //} protected void LoadGridView(Object obj, EventArgs e) { var YCSId = new YearClassSectionTable(db).GetYearClassSectionId( new YearTable(db).GetYearId(DateTime.Now.Year), ddlClass.SelectedValue, ddlSecion.SelectedValue); var markTable = new MarkTable(db); var dataSource = markTable.GetMark(ddlSubject.SelectedValue, ddlTerm.SelectedValue); portions = new MarkPortionTable(db).GetMarkPortion(ddlSubject.SelectedValue); var pivotTable = new DataTable(); pivotTable.Columns.Add("Student", typeof(string)); pivotTable.Columns.Add("StudentId", typeof(int)); foreach (var pn in portions) { pivotTable.Columns.Add(pn.Text, typeof(string)); pivotTable.Columns.Add(pn.Text + "id", typeof(string)); } //var students = dataSource.GroupBy(x => x["studentid"]).ToList(); var students = dataSource.GroupBy(x => x.Student.ID).ToList(); List <TextValuePair> studentFromDDL = new List <TextValuePair>(); //List<AspNet.Identity.MySQL.Student> studentFromDDL = new List<AspNet.Identity.MySQL.Student>(); foreach (var item in new TeacherSubjectTable(db).GetStudent(ddlSubject.SelectedValue)) { studentFromDDL.Add(new TextValuePair() { Text = item.ToString(), Value = item.ID.ToString() }); } //if (ddlStudent.SelectedValue == "all") { //} else { // studentFromDDL.Add(new TextValuePair() { Text = ddlStudent.SelectedItem.Text, Value = ddlStudent.SelectedValue }); //} foreach (var student in studentFromDDL) { DataRow newRow = pivotTable.Rows.Add(); newRow["Student"] = student.Text; newRow["StudentId"] = student.Value; //try { // var studentGroup = students.Where(x => x.Key == student.Value).ToList()[0]; // foreach (var row in studentGroup) { // //newRow[row["portionname"]] = row["mark"]; // //newRow[row["portionname"] + "id"] = row["markid"]; // try { // newRow[row.PortionName] = row.Mark; // newRow[row.PortionName + "id"] = row.MarkId; // } catch (Exception) { // newRow[row.PortionName] = "NULL"; // newRow[row.PortionName + "id"] = row.PortionId; // } // } //} catch (Exception ex) { // foreach (var portion in portions) { // newRow[portion.Text] = "NULL"; // newRow[portion.Text + "id"] = portion.Value; // } //} try { var studentGroup = students.Where(x => x.Key == student.Value).ToList()[0]; foreach (var portion in portions) { var studentMark = studentGroup.Where(x => x.PortionName == portion.Text).FirstOrDefault(); if (studentMark == null) { newRow[portion.Text] = "NULL"; newRow[portion.Text + "id"] = portion.Value; } else { newRow[portion.Text] = studentMark.Mark; newRow[portion.Text + "id"] = studentMark.MarkId; } } } catch (Exception) { foreach (var portion in portions) { newRow[portion.Text] = "NULL"; newRow[portion.Text + "id"] = portion.Value; } } } gvMark.Columns.Clear(); TemplateField tfStd = new TemplateField(); tfStd.HeaderText = "Student"; gvMark.Columns.Add(tfStd); foreach (var pn in portions) { TemplateField tf = new TemplateField(); tf.HeaderText = pn.Text; gvMark.Columns.Add(tf); } gvMark.DataSource = pivotTable; gvMark.DataBind(); }