Exemplo n.º 1
0
        private void Load()
        {
            string         pathToCsv      = "";
            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.Filter = "Файл csv|*.csv";
            if (openFileDialog.ShowDialog() == true)
            {
                pathToCsv = openFileDialog.FileName;
            }
            if (File.Exists(pathToCsv))
            {
                char[] delimiters = new char[] { ';' };
                using (StreamReader reader = new StreamReader(pathToCsv, System.Text.Encoding.Default))
                {
                    while (true)
                    {
                        string line = reader.ReadLine();
                        if (line == null)
                        {
                            break;
                        }
                        string[] parts = line.Split(delimiters);
                        bool     exist = false;
                        foreach (var group in ClassGroups)
                        {
                            if (group.NameOfGroup.Equals(parts[0].Trim(' ')))
                            {
                                exist = true;
                            }
                        }
                        if (!exist)
                        {
                            Department Department = null;
                            foreach (var dep in departments)
                            {
                                if (dep.NameOfDepartment.Equals(parts[2].Trim(' ')))
                                {
                                    Department = dep;
                                }
                            }
                            if (Department != null)
                            {
                                Group group = new Group
                                {
                                    NameOfGroup = parts[0].Trim(' '),
                                    Term        = Convert.ToInt32(parts[1].Trim(' ')),
                                    Department  = Department
                                };

                                if (RequestToDataBase.Instance.requestInsertIntoGroup(group))
                                {
                                    ClassGroups.Add(group);
                                }
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
 private void Remove()
 {
     if (Index >= 0)
     {
         ClassGroups.RemoveAt(Index);
     }
 }
Exemplo n.º 3
0
 private void Remove()
 {
     if (Index >= 0)
     {
         if (RequestToDataBase.Instance.requestDeleteFromGroup(ClassGroups, Index))
         {
             ClassGroups.RemoveAt(Index);
         }
     }
 }
Exemplo n.º 4
0
        private void Add()
        {
            var context = new GroupVM(departments.ToArray());
            var wing    = new NewGroup()
            {
                DataContext = context
            };

            wing.ShowDialog();
            System.Console.WriteLine(context.Group != null);
            if (context.Group != null)
            {
                ClassGroups.Add(context.Group);
            }
        }
Exemplo n.º 5
0
        private void Add()
        {
            var context = new GroupVM(departments.ToArray());
            var wind    = new NewGroup()
            {
                DataContext = context
            };

            wind.ShowDialog();
            if (wind.DialogResult == true)
            {
                if (context.Group != null)
                {
                    if (RequestToDataBase.Instance.requestInsertIntoGroup(context.Group))
                    {
                        ClassGroups.Add(context.Group);
                    }
                }
            }
        }
Exemplo n.º 6
0
        public void Init()
        {
            var limit = SheduleSettings.WeekDayMaxCount;

            IEnumerable <Group> ifiltered = ClassGroups.ToArray();

            if (DepartmentIndex != -1)
            {
                ifiltered =
                    ClassGroups
                    .Where(x => x.CodeOfDepartment == ClassDepartments[DepartmentIndex].CodeOfDepartment).ToArray();
            }
            foreach (var row in Data)
            {
                row.Clear();
            }
            filtered = ifiltered.ToArray();

            IEnumerable <Teacher> ifilteredteacher = ClassTeachers.ToArray();

            if (DepartmentIndex != -1)
            {
                ifilteredteacher =
                    ClassTeachers
                    .Where(x => x.CodeOfDepartment == ClassDepartments[DepartmentIndex].CodeOfDepartment).ToArray();
            }
            filteredTeacher = ifilteredteacher.ToArray();

            IEnumerable <ClassRoom> ifilteredclassroom = ClassClassrooms.ToArray();

            if (DepartmentIndex != -1)
            {
                ifilteredclassroom =
                    ClassClassrooms
                    .Where(x => x.CodeOfDepartment == ClassDepartments[DepartmentIndex].CodeOfDepartment).ToArray();
            }
            filteredClassroom = ifilteredclassroom.ToArray();

            for (int i = 0; i < filtered.Length; i++)
            {
                int j = 0;
                foreach (DayOfWeek week in Enum.GetValues(typeof(DayOfWeek)))
                {
                    if (week == DayOfWeek.Sunday)
                    {
                        continue;
                    }
                    if (week == DayOfWeek.Saturday)
                    {
                        limit = SheduleSettings.SaturdayMaxCount;
                    }
                    else
                    {
                        limit = SheduleSettings.WeekDayMaxCount;
                    }

                    for (int k = 0; k < limit; k++)
                    {
                        var pair = new PairInfo(k + 1, week);
                        Data[j].Add(new DropItem(filtered[i].NameOfGroup, typeof(Group), pair)
                        {
                            Item = new DropInformation {
                                Group = filtered[i].NameOfGroup
                            }
                        });
                        j++;
                    }
                }
            }
            Columns.Clear();
            foreach (var key in Data.First().Select(x => x.Key))
            {
                Columns.Add(key);
            }
            Rows.Clear();
            if (filtered.Length != 0)
            {
                foreach (var row in (Data.Select(x => x[0].Info)))
                {
                    Rows.Add(row);
                }
            }
            if (ch != 0)
            {
                Transform(ch);
            }
        }
        Dictionary <int, List <int> > AssignStudentToSubjectInOneCategory(IQueryable <ElectiveSubjectsAndSpecialities> subjects, Categories oneCategory, ClassGroups oneClassGroup)
        {
            Dictionary <int, List <int> > algorithmChoices = new Dictionary <int, List <int> >();
            List <int> chosenStudents = new List <int>();

            using (PPDBEntities db = new PPDBEntities())
            {
                var studentChoicesOneClassGroup = db.StudentChoices.Where(x => x.CategoryID == oneCategory.CategoryID).OrderBy(x => x.ChoiceDate);

                for (int ChoicePref = 1; ChoicePref <= oneCategory.MaxNoChoices; ChoicePref++)
                {
                    foreach (var oneSubject in subjects)
                    {
                        if (ChoicePref == 1)
                        {
                            chosenStudents = new List <int>();
                        }
                        else
                        {
                            chosenStudents = algorithmChoices[oneSubject.ElectiveSubjectAndSpecialityID];
                        }

                        if (oneSubject.UpperLimit != null)
                        {
                            int freePlaces = oneSubject.UpperLimit.Value - chosenStudents.Count;
                            if (freePlaces > 0)
                            {
                                var selectedStudentsNo       = studentChoicesOneClassGroup.Where(x => x.ChoiceID == oneSubject.ElectiveSubjectAndSpecialityID && x.PreferenceNo == ChoicePref).Select(x => x.StudentNo);
                                var selectedsortedStudentsNo = db.StudentsAndClassGroups.Where(x => selectedStudentsNo.Any(y => y == x.StudentNo)).OrderByDescending(x => x.AverageGrade).Select(x => x.StudentNo).Take(freePlaces);
                                foreach (var item in selectedsortedStudentsNo)
                                {
                                    studentChoicesOneClassGroup = studentChoicesOneClassGroup.Where(x => x.StudentNo != item).OrderBy(x => x.ChoiceDate);
                                    chosenStudents.Add(item);
                                }
                            }
                        }
                        else
                        {
                            var selectedStudentsNo       = studentChoicesOneClassGroup.Where(x => x.ChoiceID == oneSubject.ElectiveSubjectAndSpecialityID && x.PreferenceNo == ChoicePref).Select(x => x.StudentNo);
                            var selectedsortedStudentsNo = db.StudentsAndClassGroups.Where(x => selectedStudentsNo.Any(y => y == x.StudentNo)).Select(x => x.StudentNo);
                            foreach (var item in selectedsortedStudentsNo)
                            {
                                studentChoicesOneClassGroup = studentChoicesOneClassGroup.Where(x => x.StudentNo != item).OrderBy(x => x.ChoiceDate);
                                chosenStudents.Add(item);
                            }
                        }
                        algorithmChoices[oneSubject.ElectiveSubjectAndSpecialityID] = chosenStudents;
                    }
                }

                //weź studentów którzy nigdzie się nie dostali
                if (studentChoicesOneClassGroup.Count() > 0)
                {
                    var restOfStudentsNo = db.StudentsAndClassGroups.Where(x => studentChoicesOneClassGroup.Any(y => y.StudentNo == x.StudentNo)).OrderByDescending(x => x.AverageGrade).Select(x => x.StudentNo);
                    foreach (var oneSubject in subjects.Where(x => x.UpperLimit != null))
                    {
                        int freePlaces = oneSubject.UpperLimit.Value - algorithmChoices[oneSubject.ElectiveSubjectAndSpecialityID].Count;
                        if (freePlaces > 0)
                        {
                            var selectedsortedStudentsNo = restOfStudentsNo.Take(freePlaces);
                            foreach (var item in selectedsortedStudentsNo)
                            {
                                studentChoicesOneClassGroup = studentChoicesOneClassGroup.Where(x => x.StudentNo != item).OrderBy(x => x.ChoiceDate);;
                                algorithmChoices[oneSubject.ElectiveSubjectAndSpecialityID].Add(item);
                            }
                        }
                        if (restOfStudentsNo.Count() == 0)
                        {
                            break;
                        }
                    }

                    //tylko jeden weź
                    if (restOfStudentsNo.Count() > 0)
                    {
                        var oneSubject = subjects.Where(x => x.UpperLimit == null).FirstOrDefault();
                        if (oneSubject != null)
                        {
                            foreach (var item in restOfStudentsNo)
                            {
                                algorithmChoices[oneSubject.ElectiveSubjectAndSpecialityID].Add(item);
                            }
                        }
                        else
                        {
                            string alertStudents = string.Empty;
                            foreach (var item in restOfStudentsNo)
                            {
                                alertStudents += " " + item;
                            }
                            if (restOfStudentsNo.Count() == 1)
                            {
                                TempData["Alert"] = "Nie można przydzielić studenta o indeksie" + alertStudents;
                            }
                            else
                            {
                                TempData["Alert"] = "Nie można przydzielić studentów o indeksach:" + alertStudents;
                            }
                            TempData["Alert"] += " - brak wolnych miejsc w kategorii " + oneCategory.Name + " w grupie " + oneClassGroup.DegreeCourse.ToString() + "/" + oneClassGroup.Graduate.ToString() + "/";
                            if (oneClassGroup.FullTimeStudies == true)
                            {
                                TempData["Alert"] += "STACJ";
                            }
                            else
                            {
                                TempData["Alert"] += "NIESTACJ";
                            }
                            TempData["Alert"] += "/" + oneClassGroup.Semester.ToString() + "/" + oneClassGroup.Speciality.ToString() + "!";
                            return(null);
                        }
                    }
                }

                //weź studentów którzy nie wybrali
                var studentsWithoutChoicesNo = db.StudentsAndClassGroups.Where(x => x.ClassGroupID == oneClassGroup.ClassGroupID && !db.StudentChoices.Any(y => y.StudentNo == x.StudentNo && y.CategoryID == oneCategory.CategoryID)).OrderByDescending(x => x.AverageGrade).Select(x => x.StudentNo).ToList();
                if (studentsWithoutChoicesNo.Count() > 0)
                {
                    foreach (var oneSubject in subjects.Where(x => x.UpperLimit != null))
                    {
                        int freePlaces = oneSubject.UpperLimit.Value - algorithmChoices[oneSubject.ElectiveSubjectAndSpecialityID].Count;
                        if (freePlaces > 0)
                        {
                            var selectedsortedStudentsNo = studentsWithoutChoicesNo.Take(freePlaces);
                            foreach (var item in selectedsortedStudentsNo)
                            {
                                studentsWithoutChoicesNo = studentsWithoutChoicesNo.Where(x => x != item).ToList();
                                algorithmChoices[oneSubject.ElectiveSubjectAndSpecialityID].Add(item);
                            }
                        }
                        if (studentsWithoutChoicesNo.Count() == 0)
                        {
                            break;
                        }
                    }

                    //tylko jeden weź
                    if (studentsWithoutChoicesNo.Count() > 0)
                    {
                        var oneSubject = subjects.Where(x => x.UpperLimit == null).FirstOrDefault();
                        if (oneSubject != null)
                        {
                            foreach (var item in studentsWithoutChoicesNo)
                            {
                                algorithmChoices[oneSubject.ElectiveSubjectAndSpecialityID].Add(item);
                            }
                        }
                        else
                        {
                            string alertStudents = string.Empty;
                            foreach (var item in studentsWithoutChoicesNo)
                            {
                                alertStudents += " " + item;
                            }
                            if (studentsWithoutChoicesNo.Count() == 1)
                            {
                                TempData["Alert"] = "Nie można przydzielić studenta o indeksie" + alertStudents;
                            }
                            else
                            {
                                TempData["Alert"] = "Nie można przydzielić studentów o indeksach:" + alertStudents;
                            }
                            TempData["Alert"] += " - brak wolnych miejsc w kategorii " + oneCategory.Name + " w grupie " + oneClassGroup.DegreeCourse.ToString() + "/" + oneClassGroup.Graduate.ToString() + "/";
                            if (oneClassGroup.FullTimeStudies == true)
                            {
                                TempData["Alert"] += "STACJ";
                            }
                            else
                            {
                                TempData["Alert"] += "NIESTACJ";
                            }
                            TempData["Alert"] += "/" + oneClassGroup.Semester.ToString() + "/" + oneClassGroup.Speciality.ToString() + "!";
                            return(null);
                        }
                    }
                }

                //sprawdź limity dolne
                int excludedSubjectID = -1;
                int biggestDifferenceNumberOfPlaces = 0;
                foreach (var oneSubject in subjects.Where(x => x.LowerLimit != null))
                {
                    if (oneSubject.LowerLimit.Value - algorithmChoices[oneSubject.ElectiveSubjectAndSpecialityID].Count > biggestDifferenceNumberOfPlaces)
                    {
                        biggestDifferenceNumberOfPlaces = oneSubject.LowerLimit.Value - algorithmChoices[oneSubject.ElectiveSubjectAndSpecialityID].Count;
                        excludedSubjectID = oneSubject.ElectiveSubjectAndSpecialityID;
                    }
                }
                if (excludedSubjectID != -1)
                {
                    return(AssignStudentToSubjectInOneCategory(subjects.Where(x => x.ElectiveSubjectAndSpecialityID != excludedSubjectID), oneCategory, oneClassGroup));
                }
            }


            return(algorithmChoices);
        }