Exemplo n.º 1
0
        protected void gvExistingMarkPortion_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            var markPortionId = gvExistingMarkPortion.Rows[e.RowIndex].Cells[2].Text;
            //var markPortionId= Convert.ToInt32((e.Values[FindControl("hfPortionId")] as HiddenField).Value);

            // int key = Convert.ToInt32(gvExistingMarkPortion.DataKeys[e.RowIndex].Value.ToString());
            MarkPortionTable MPTable = new MarkPortionTable(db);

            MPTable.RemoveMarkPortionFromSubject(Convert.ToInt32(markPortionId));

            LoadGVDDLExistingSubject(null, null);
        }
Exemplo n.º 2
0
        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();
        }