示例#1
0
        private void btnCreateGroups_Click(object sender, EventArgs e)
        {
            if (rbdGroupsRandom.Checked)
            {
                Commons.ShuffleList(listGroups);
            }
            else if (rdbGroupsBestGradesTogether.Checked)
            {
            }
            else if (rdbGradesBalanced.Checked)
            {
            }
            // create groups into groups array
            string[,] groups = new string[nStudentsPerGroup, nGroups];
            int stud = 0;

            for (int i = 0; i < nStudentsPerGroup; i++)
            {
                for (int j = 0; j < nGroups; 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[i, j] != null && groups[i, j] != " " && groups[i, j] != "  ")
                    {
                        groupsString += $"{nStud.ToString("00")} - {groups[i, j]} \r\n";
                        nStud++;
                    }
                }
                groupsString += "\r\n";
            }
            groupsString  += "\r\n";
            txtGroups.Text = groupsString;
        }
示例#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;
        }