private void RetrieveData(RadioButton rdb)
        {
            if (cmbSummaryGradeType.SelectedItem != null && cmbSchoolSubjects.SelectedItem != null)
            {
                if (rdb == rdbMissing)
                {
                    dgwGrades.DataSource = db.GetStudentsWithNoMicrogrades(currentClass,
                                                                           ((GradeType)(cmbSummaryGradeType.SelectedItem)).IdGradeType,
                                                                           ((SchoolSubject)(cmbSchoolSubjects.SelectedItem)).IdSchoolSubject,
                                                                           dtpStartPeriod.Value, dtpEndPeriod.Value
                                                                           );
                }
                if (rdb == rdbShowGrades)
                {
                    dgwGrades.DataSource = db.GetGradesOfClass(currentClass,
                                                               ((GradeType)(cmbSummaryGradeType.SelectedItem)).IdGradeType,
                                                               ((SchoolSubject)(cmbSchoolSubjects.SelectedItem)).IdSchoolSubject,
                                                               dtpStartPeriod.Value, dtpEndPeriod.Value
                                                               );
                    lblSum.Text = "";
                    txtMediaMicroDomande.Text = "";
                }
                else if (rdb == rdbShowWeights)
                {
                    dgwGrades.DataSource = db.GetWeightedAveragesOfClass(currentClass,
                                                                         ((GradeType)(cmbSummaryGradeType.SelectedItem)).IdGradeType,
                                                                         ((SchoolSubject)(cmbSchoolSubjects.SelectedItem)).IdSchoolSubject,
                                                                         dtpStartPeriod.Value, dtpEndPeriod.Value
                                                                         );
                    double sumLeftToClose    = 0;
                    double maxGradesFraction = 0;
                    foreach (DataRow row in ((DataTable)dgwGrades.DataSource).Rows)
                    {
                        double gf = (double)row["GradesFraction"];
                        if (gf > maxGradesFraction)
                        {
                            maxGradesFraction = gf;
                        }
                        sumLeftToClose += (double)row["LeftToCloseAssesments"];
                    }
                    int nGrades = (int)Math.Round(maxGradesFraction + 0.10);
                    lblSum.Text = "Mancanti a fine giro";
                    txtMediaMicroDomande.Text = (sumLeftToClose / nGrades).ToString();
                }
                else if (rdb == rdbShowWeightedGrades)
                {
                    dgwGrades.DataSource = db.GetGradesWeightedAveragesOfClass(currentClass,
                                                                               ((GradeType)(cmbSummaryGradeType.SelectedItem)).IdGradeType,
                                                                               ((SchoolSubject)(cmbSchoolSubjects.SelectedItem)).IdSchoolSubject,
                                                                               dtpStartPeriod.Value, dtpEndPeriod.Value
                                                                               );
                    lblSum.Text = "";
                    txtMediaMicroDomande.Text = "";
                }
                else if (rdb == rdbShowWeightsOnOpenGrades)
                {
                    dgwGrades.DataSource = db.GetGradesWeightsOfClassOnOpenGrades(currentClass,
                                                                                  ((GradeType)(cmbSummaryGradeType.SelectedItem)).IdGradeType,
                                                                                  ((SchoolSubject)(cmbSchoolSubjects.SelectedItem)).IdSchoolSubject,
                                                                                  dtpStartPeriod.Value, dtpEndPeriod.Value
                                                                                  );
                    lblSum.Text = "";
                    txtMediaMicroDomande.Text = "";

                    setRowNumbers(dgwGrades);
                }
            }
            txtNStudents.Text = ((DataTable)dgwGrades.DataSource).Rows.Count.ToString();
        }
Пример #2
0
        private void btnCreateGroups_Click(object sender, EventArgs e)
        {
            DataTable tb = db.GetGradesWeightedAveragesOfClass(schoolClass, schoolGrade.IdGradeType, schoolSubject.IdSchoolSubject, (DateTime)schoolPeriod.DateStart, (DateTime)schoolPeriod.DateFinish);
            List<StudentAndGrade> listStudents = new List<StudentAndGrade>();
            foreach (DataRow row in tb.Rows)
                listStudents.Add(new StudentAndGrade(row.ItemArray[2].ToString(), row.ItemArray[3].ToString(), (double)row.ItemArray[4]));

            listStudents.Sort((firstGrade, secondGrade) => firstGrade.grade.CompareTo(secondGrade.grade));
            listStudents.Reverse(); //Lista studenti in ordine decrescente in base al voto
            List<Student> listTempStudents;

            if (rbdGroupsRandom.Checked)
            {
                Commons.ShuffleList(listGroups);
            }
            else if (rdbGroupsBestGradesTogether.Checked)
            {
                listTempStudents = new List<Student>();

                for (int i = 0; i < listStudents.Count; i++)
                {
                    for (int j = 0; j < listGroups.Count; j++)
                    {
                        if (listStudents[i].lastName == listGroups[j].LastName && listStudents[i].firstName == listGroups[j].FirstName)
                        {
                            listTempStudents.Add(listGroups[j]);
                        }
                    }

                }
                listGroups = listTempStudents;
            }
            else if (rdbGradesBalanced.Checked)
            {
                int lengthLista = listStudents.Count;
                listTempStudents = new List<Student>();
               
                for (int i = 0, g = 0; g < lengthLista ; g++)
                {
                    for (int j = 0; j < listGroups.Count; j++)
                    {
                        if (listStudents[i].lastName == listGroups[j].LastName && listStudents[i].firstName == listGroups[j].FirstName)
                        {
                            listTempStudents.Add(listGroups[j]);
                        }
                    }
                    listStudents.RemoveAt(i);
                    
                    if (i == 0)
                        i = listStudents.Count - 1;
                    else
                        i = 0;
                }
                listGroups = listTempStudents;
            }
            // create groups into groups array
            string[,] groups = new string[nGroups, nStudentsPerGroup];
            int stud = 0;
            for (int i = 0; i < nGroups; i++)
            {
                for (int j = 0; j < nStudentsPerGroup; j++)
                {
                    Student s = listGroups[stud];
                    groups[i, j] = s.LastName + " " + s.FirstName;
                    stud++;
                    if (stud == listGroups.Count)
                        break;
                }
                if (stud == listGroups.Count)
                    break;
            }
            // make the string to show groups
            string groupsString = "";
            for (int j = 0; j < nGroups; j++)
            {
                groupsString += "Gruppo " + (j + 1).ToString() + "\r\n";
                int nStud = 1; 
                for (int i = 0; i < nStudentsPerGroup; i++)
                {
                    if (groups[j, i] != null && groups[j, i] != " " && groups[j, i] != "  ")
                    {
                        groupsString += $"{nStud.ToString("00")} - {groups[j, i]} \r\n";
                        nStud++; 
                    }
                }
                groupsString += "\r\n";
            }
            groupsString += "\r\n";
            txtGroups.Text = groupsString;
        }