private void OnButtonbtnGetResultsClick(object sender, System.Windows.RoutedEventArgs e)
 {
     AllStudentDetails.Clear();
     FinalAllotmentResults.Clear();
     InitializeAvailableSeatsAndAllotmentResults();
     ReadAndUpdateStudentData();
     AssignBranchToStudent();
 }
        private void UpdateOtherStudentDetails(DataTable dt)
        {
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                StudentDetails stuDetails;
                var            studentid = dt.Rows[i][1].ToString();
                if (AllStudentDetails.Any(x => x.Id == studentid))
                {
                    stuDetails = AllStudentDetails.Select(x => x).Where(x => x.Id == studentid).FirstOrDefault();
                }
                else
                {
                    stuDetails = new StudentDetails();
                }


                if (stuDetails.Id == null)
                {
                    stuDetails.Id              = dt.Rows[i][1].ToString();
                    stuDetails.Name            = dt.Rows[i][2].ToString();
                    stuDetails.GenderType      = (StudentDetails.Gender)Enum.Parse(typeof(StudentDetails.Gender), dt.Rows[i][3].ToString());
                    stuDetails.StudentCaste    = (StudentDetails.Cast)Enum.Parse(typeof(StudentDetails.Cast), dt.Rows[i][4].ToString().ToUpper().Replace("-", string.Empty));
                    stuDetails.SpecialCategory = (StudentDetails.Category)Enum.Parse(typeof(StudentDetails.Category),
                                                                                     dt.Rows[i][5].ToString() == string.Empty ? "NONE" : dt.Rows[i][5].ToString().ToUpper().Replace("-", string.Empty));
                    stuDetails.CGPA = Convert.ToDouble(dt.Rows[i][6]);
                    if (dt.Rows[i][7].ToString() != string.Empty)
                    {
                        stuDetails.MathsAvg = (double)Convert.ToDouble(dt.Rows[i][7]);
                    }
                    if (dt.Rows[i][8].ToString() != string.Empty)
                    {
                        stuDetails.PhysicsAvg = (double)Convert.ToDouble(dt.Rows[i][8]);
                    }
                    if (dt.Rows[i][9].ToString() != string.Empty)
                    {
                        stuDetails.DateOfBirth = Convert.ToDateTime(dt.Rows[i][9]);
                    }
                }

                if (!AllStudentDetails.Any(x => x.Id == studentid))
                {
                    AllStudentDetails.Add(stuDetails);
                }
            }
        }
        private void UpdateStudentPreferences(DataTable item)
        {
            DataTable dt = new DataTable();

            dt = item;
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                StudentDetails stuDetails;
                var            studentid = dt.Rows[i][1].ToString();
                if (AllStudentDetails.Any(x => x.Id == studentid))
                {
                    stuDetails = AllStudentDetails.Select(x => x).Where(x => x.Id == studentid).FirstOrDefault();
                }
                else
                {
                    stuDetails = new StudentDetails();
                }

                for (int j = 1; j < dt.Columns.Count; j++)
                {
                    if (j == 1)
                    {
                        if (stuDetails.Id == null)
                        {
                            stuDetails.Id = dt.Rows[i][j].ToString();
                        }
                    }
                    else
                    {
                        var val = dt.Rows[i][j].ToString();
                        if (stuDetails.PreferredCourses == null)
                        {
                            stuDetails.PreferredCourses = new List <StudentDetails.Branches>();
                        }
                        stuDetails.PreferredCourses.Add((StudentDetails.Branches)Enum.Parse(typeof(StudentDetails.Branches), val));
                    }
                }

                if (!AllStudentDetails.Any(x => x.Id == studentid))
                {
                    AllStudentDetails.Add(stuDetails);
                }
            }
        }
        private void AllocateSpecialCategorySeats()
        {
            var AllStudents = AllStudentDetails.Select(x => x).Where(x => x.CGPA >= 6 && !x.isBranchAllotted)
                              .OrderByDescending(x => x.CGPA).ThenByDescending(x => x.MathsAvg).ThenByDescending(x => x.PhysicsAvg).ThenByDescending(x => x.DateOfBirth);
            var studentsWithSpecialCatogory = AllStudents.Select(x => x).Where(x => x.SpecialCategory != StudentDetails.Category.NONE)
                                              .OrderByDescending(x => x.CGPA).ThenByDescending(x => x.MathsAvg).ThenByDescending(x => x.PhysicsAvg).ThenByDescending(x => x.DateOfBirth);

            foreach (var student in studentsWithSpecialCatogory)
            {
                var preferences = student.PreferredCourses;
                foreach (var preferredCource in preferences)
                {
                    if (preferredCource.Equals(StudentDetails.Branches.ECE))
                    {
                        CheckAndAllocatebranchToSpecialCategoryStudent(student, ECEavailableSeats, EceAllotmentResults, StudentDetails.Branches.ECE);
                        if (student.isBranchAllotted)
                        {
                            break;
                        }
                    }
                    if (preferredCource.Equals(StudentDetails.Branches.CSE))
                    {
                        CheckAndAllocatebranchToSpecialCategoryStudent(student, CSEavailableSeats, CseAllotmentResults, StudentDetails.Branches.CSE);
                        if (student.isBranchAllotted)
                        {
                            break;
                        }
                    }
                    if (preferredCource.Equals(StudentDetails.Branches.EEE))
                    {
                        CheckAndAllocatebranchToSpecialCategoryStudent(student, EEEavailableSeats, EeeAllotmentResults, StudentDetails.Branches.EEE);
                        if (student.isBranchAllotted)
                        {
                            break;
                        }
                    }
                    if (preferredCource.Equals(StudentDetails.Branches.ME))
                    {
                        CheckAndAllocatebranchToSpecialCategoryStudent(student, MEavailableSeats, MeAllotmentResults, StudentDetails.Branches.ME);
                        if (student.isBranchAllotted)
                        {
                            break;
                        }
                    }
                    if (preferredCource.Equals(StudentDetails.Branches.ChE))
                    {
                        CheckAndAllocatebranchToSpecialCategoryStudent(student, ChEavailableSeats, CheAllotmentResults, StudentDetails.Branches.ChE);
                        if (student.isBranchAllotted)
                        {
                            break;
                        }
                    }
                    if (preferredCource.Equals(StudentDetails.Branches.CE))
                    {
                        CheckAndAllocatebranchToSpecialCategoryStudent(student, CEavailableSeats, CeAllotmentResults, StudentDetails.Branches.CE);
                        if (student.isBranchAllotted)
                        {
                            break;
                        }
                    }
                    if (preferredCource.Equals(StudentDetails.Branches.MME))
                    {
                        CheckAndAllocatebranchToSpecialCategoryStudent(student, MMEavailableSeats, MmeAllotmentResults, StudentDetails.Branches.MME);
                        if (student.isBranchAllotted)
                        {
                            break;
                        }
                    }
                }
            }
        }