/// <summary> /// Method that places a grade in the Panel which corresponds to the subject of the grade /// </summary> /// <param name="course">the course at which we want to add a grade</param> /// <param name="grade">the grade we want to add</param> private void PlaceGrade(PanelCourse course, Grade grade) { Label gradeName = new Label(); gradeName.Text = grade.NomCC; gradeName.AutoSize = true; Label note = new Label(); note.Text = "" + grade.Note; note.AutoSize = true; LabelGrade addGrade = new LabelGrade(gradeName, note); course.grades.Add(addGrade); course.Controls.Add(addGrade.name); course.Controls.Add(addGrade.grade); int count = course.grades.Count; int y; if (count == 0) { y = 40; } else { y = 30 * count; } addGrade.name.Location = new Point(200, y); addGrade.grade.Location = new Point(900, y); addGrade.name.Visible = true; addGrade.grade.Visible = true; course.Height += 20; }
/// <summary> /// Method that modifies attendance status for the class when the teacher click on the modify button /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void buttonModify_Click(object sender, EventArgs e) { connection.Open(); foreach (Control c in panelAttendance.Controls) { if (c is PanelCourse) { PanelCourse p = (PanelCourse)c; int att = 0; if (p.check.Checked == true && p.late.Checked == false) { p.status.Text = "Présent"; att = 2; } else if (p.late.Checked == true && p.check.Checked == true) { p.status.Text = "Late"; att = 1; } else { p.status.Text = "Absent"; } string info = p.name.Text; string ID = info.Split(' ')[2]; string name = course.name; String studentInfo = "SELECT * FROM attendance WHERE StudentID='" + ID + "' AND Subject ='" + name + "'"; MySqlDataAdapter SDA = new MySqlDataAdapter(studentInfo, connection); DataTable dt = new DataTable(); SDA.Fill(dt); string idAttendance = dt.Rows[0][0].ToString(); string[] attendance = dt.Rows[0]["Attendance"].ToString().Split(' '); attendance[attendance.Length - 1] = "" + att; string newAttendance = ""; for (int i = 0; i < attendance.Length; i++) { if (i == 0) { newAttendance += attendance[0]; } else { newAttendance += " " + attendance[i]; } } String query = "UPDATE attendance SET Attendance='" + newAttendance + "', LastChange='" + DateTime.Today.ToString("yyyy-MM-dd") + "' WHERE idAttendance='" + idAttendance + "'"; MySqlDataAdapter uptade = new MySqlDataAdapter(query, connection); uptade.SelectCommand.ExecuteNonQuery(); } } connection.Close(); }
/// <summary> /// A method that adds in a general panel another panel which describes a new course /// </summary> /// <param name="generalPanel">the general panel where the new course panel will be</param> /// <param name="avg">the average of the subject</param> /// <param name="listCourses">the list of all the courses in the genral Panel</param> /// <returns></returns> private PanelCourse AddCourse(Panel generalPanel, Average avg, List <PanelCourse> listCourses) { Label courseName = new Label(); Label averageLabel = new Label(); Label average = new Label(); List <LabelGrade> grades = new List <LabelGrade>(); PanelCourse newPan = new PanelCourse(courseName, averageLabel, average, grades); newPan.Height = 70; newPan.Width = 930; int x = 0; int y; int max = 0; foreach (Control c in generalPanel.Controls) { if (c is Panel && c.Location.Y > max) { max = c.Location.Y + c.Height; } } y = max + 10; generalPanel.Controls.Add(newPan); Panel title = new Panel(); title.Height = 30; title.Width = 930; title.BackColor = Color.LightSlateGray; newPan.Location = new Point(x, y); courseName.Text = avg.subject.name; courseName.AutoSize = true; courseName.Visible = true; title.Controls.Add(courseName); courseName.Location = new Point(10, 10); averageLabel.Text = "Average : "; averageLabel.AutoSize = true; averageLabel.Visible = true; title.Controls.Add(averageLabel); averageLabel.Location = new Point(850, 10); double mean = avg.GetAverage(); average.Text = "" + mean; average.AutoSize = true; average.Visible = true; title.Controls.Add(average); average.Location = new Point(900, 10); newPan.Controls.Add(title); listCourses.Add(newPan); return(newPan); }
/// <summary> /// Initializes the form at the actual attendance status for all the students /// </summary> /// <param name="con"></param> /// <param name="_course"></param> public AttendanceForm(MySqlConnection con, Course _course) { InitializeComponent(); connection = con; course = _course; GetListStudents(); labelName.Text = course.name + " " + course.courseClass.name; String verify = "SELECT * FROM attendance WHERE StudentID='" + course.courseClass.students[0].ID + "' AND Subject ='" + course.name + "'"; MySqlDataAdapter SDAVerify = new MySqlDataAdapter(verify, connection); DataTable dtVerify = new DataTable(); SDAVerify.Fill(dtVerify); string lastDate = dtVerify.Rows[0]["LastChange"].ToString(); if (_course.day != DateTime.Now.DayOfWeek.ToString() || lastDate == DateTime.Now.ToString("yyyy/MM/dd")) { buttonValidate.Enabled = false; buttonModify.Enabled = true; foreach (Control c in panelAttendance.Controls) { if (c is PanelCourse) { PanelCourse p = (PanelCourse)c; String studentInfo = "SELECT * FROM attendance WHERE StudentID='" + p.name.Text.Split(' ')[2] + "' AND Subject ='" + course.name + "'"; MySqlDataAdapter SDA = new MySqlDataAdapter(studentInfo, connection); DataTable dt = new DataTable(); SDA.Fill(dt); if (dt.Rows.Count != 0) { string[] attendance = dt.Rows[0]["Attendance"].ToString().Split(' '); int lastAtt = Convert.ToInt32(attendance[attendance.Length - 1]); if (lastAtt == 1) { p.check.Checked = true; p.status.Text = "Late"; p.late.Checked = true; } if (lastAtt == 2) { p.check.Checked = true; p.status.Text = "Present"; } } } } } }
/// <summary> /// Method that when the teacher clicks on the validate button add attendance status in the database for all the student /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void buttonValidate_Click(object sender, EventArgs e) { connection.Open(); foreach (Control c in panelAttendance.Controls) { if (c is PanelCourse) { PanelCourse p = (PanelCourse)c; int att = 0; if (p.check.Checked == true) { p.status.Text = "Présent"; att = 2; } if (p.late.Checked == true && p.check.Checked == true) { p.status.Text = "Late"; att = 1; } string info = p.name.Text; string ID = info.Split(' ')[2]; string name = course.name; String studentInfo = "SELECT * FROM attendance WHERE StudentID='" + ID + "' AND Subject ='" + name + "'"; MySqlDataAdapter SDA = new MySqlDataAdapter(studentInfo, connection); DataTable dt = new DataTable(); SDA.Fill(dt); String query; if (dt.Rows.Count == 0) { query = "INSERT INTO attendance (StudentID,Subject,Attendance,LastChange) VALUES ('" + ID + "','" + name + "','" + att + "','" + DateTime.Today.ToString("yyyy/MM/dd") + "')"; } else { string idAttendance = dt.Rows[0][0].ToString(); string attendance = dt.Rows[0]["Attendance"].ToString() + " " + att; query = "UPDATE attendance SET Attendance='" + attendance + "', LastChange='" + DateTime.Today.ToString("yyyy/MM/dd") + "' WHERE idAttendance='" + idAttendance + "'"; } MySqlDataAdapter uptade = new MySqlDataAdapter(query, connection); uptade.SelectCommand.ExecuteNonQuery(); } } buttonValidate.Enabled = false; buttonModify.Enabled = true; connection.Close(); }
/// <summary> /// Method that displays all the students of the class with checkbox to check the attendance /// </summary> public void GetListStudents() { List <Student> students = course.courseClass.students; for (int i = 0; i < students.Count; i++) { Label name = new Label(); name.Text = students[i].name.ToUpper() + " " + students[i].firstName + " " + students[i].ID; name.Location = new Point(10, 10); name.AutoSize = true; Label attendance = new Label(); attendance.Text = "Absent"; attendance.AutoSize = true; attendance.Location = new Point(300, 10); CheckBox check = new CheckBox(); check.Location = new Point(380, 10); check.Visible = true; check.AutoSize = true; Label lateLabel = new Label(); lateLabel.Text = "Late :"; lateLabel.AutoSize = true; lateLabel.Location = new Point(450, 10); CheckBox late = new CheckBox(); late.Location = new Point(500, 5); int max = -70; foreach (Control c in panelAttendance.Controls) { if (c is Panel && c.Location.Y > max) { max = c.Location.Y; } } int y = max + 70; PanelCourse student = new PanelCourse(name, attendance, check, lateLabel, late); student.Height = 70; student.Width = 520; student.Name = "" + students[i].ID; panelAttendance.Controls.Add(student); student.Location = new Point(0, y); } }
/// <summary> /// Method that displays grades of a student only in the subject that concerns the teacher /// </summary> /// <param name="panel">the panel where we want the grades to display</param> /// <param name="Teacher">the teacher who wants to see the grades</param> public void GetGrades2(Panel panel, Faculty Teacher) { String query = "SELECT * FROM grade WHERE studentID='" + ID + "'"; MySqlDataAdapter SDA = new MySqlDataAdapter(query, con); DataTable dt = new DataTable(); SDA.Fill(dt); List <PanelCourse> listCourses = new List <PanelCourse>(); List <Average> subjects = new List <Average>(); if (dt.Rows.Count != 0) { foreach (DataRow row in dt.Rows) { String query2 = "SELECT * FROM course WHERE Subject='" + row["Subject"].ToString() + "AND Class='" + row["Class"].ToString() + "'"; MySqlDataAdapter SDA2 = new MySqlDataAdapter(query2, con); DataTable dt2 = new DataTable(); SDA.Fill(dt2); foreach (DataRow row2 in dt2.Rows) { if (subjects.Count == 0) { Subject subject = new Subject(row["Subject"].ToString()); if (row["studentGrade"].ToString() != "Not yet graded" && row2["studentID"].ToString() == Teacher.ToString()) { Grade grade = new Grade(Convert.ToInt32(row["studentGrade"].ToString()), row["AssesmentName"].ToString(), Convert.ToInt32(row["coefficient"].ToString()), subject); List <Grade> grades = new List <Grade>(); grades.Add(grade); Average avg = new Average(subject, grades); subjects.Add(avg); } } else { bool subjExist = false; Average avg = null; for (int i = 0; i < subjects.Count; i++) { Subject subject = new Subject(row["Subject"].ToString()); if (subject.name.Equals(subjects[i].subject.name)) { subjExist = true; avg = subjects[i]; } } if (subjExist == true) { if (row["studentGrade"].ToString() != "Not yet graded" && row2["studentID"].ToString() == Teacher.ToString()) { Grade grade = new Grade(Convert.ToInt32(row["studentGrade"].ToString()), row["AssesmentName"].ToString(), Convert.ToInt32(row["coefficient"].ToString()), avg.subject); avg.grades.Add(grade); } } else { if (row["studentGrade"].ToString() != "Not yet graded" && row2["studentID"].ToString() == Teacher.ToString()) { Subject subject = new Subject(row["Subject"].ToString()); Grade grade = new Grade(Convert.ToInt32(row["studentGrade"].ToString()), row["AssesmentName"].ToString(), Convert.ToInt32(row["coefficient"].ToString()), subject); List <Grade> grades = new List <Grade>(); grades.Add(grade); avg = new Average(subject, grades); subjects.Add(avg); } } } } } for (int i = 0; i < subjects.Count; i++) { PanelCourse course = AddCourse(panel, subjects[i], listCourses); for (int j = 0; j < subjects[i].grades.Count; j++) { PlaceGrade(course, subjects[i].grades[j]); } } } }