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);
            }
        }
        public SingleValue AddMark(int markPortionId, int studentId, int classId, int sectionId, int termYearClassSectionId, int mark, string teacherId)
        {
            MySQLDatabase db    = new MySQLDatabase();
            var           YCSId = new YearClassSectionTable(db).GetYearClassSectionId(
                new YearTable(db).GetYearId(DateTime.Now.Year),
                classId,
                sectionId);

            var SYCSRId = new StudentYearClassSectionRollTable(db).GetStudentYearClassSectionRollId(YCSId, studentId);

            return(new SingleValue()
            {
                Value = db.QueryValue("addMark", new Dictionary <string, object>()
                {
                    { "@MPId", markPortionId },
                    { "@SYCSRId", SYCSRId },
                    { "@TYCSId", termYearClassSectionId },
                    { "@mark", mark },
                    { "@TUId", teacherId }
                }, true).ToString()
            });
        }
        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();
        }