private bool CheckCapacity(T_RegisteredStudentSemester value)
 {
     using (SMSNotification nofity = new SMSNotification())
     {
         var cap = nofity.GetRegisterStudent().Where(x => x.Day == value.Day && x.TImeEnd.ToShortTimeString() == value.TImeEnd.ToShortTimeString() && x.TimeStart.ToShortTimeString() == value.TimeStart.ToShortTimeString() && x.Semester == value.Semester && x.SemEndDate.ToShortDateString() == value.SemEndDate.ToShortDateString() && x.SemStartDate.ToShortDateString() == value.SemStartDate.ToShortDateString() && x.YearClass == value.YearClass && x.Active == true).ToList().Count;
         //lblSelected.Text = string.Format("Selected",cap);
         return(cap <= GetCapacity(value.RoomCode)?true:false);
     }
 }
        void LoadRoomRecord()
        {
            int i = 1;

            dgRoomRecord.Rows.Clear();
            using (SMSNotification notify = new SMSNotification())
            {
                notify.GetRegisterStudent().OrderBy(o => o.TimeStart).ToList().ForEach(x =>
                {
                    using (Maintenance maintain = new Maintenance())
                    {
                        using (Students stud = new Students())
                        {
                            var studs     = stud.GetStudentInfo().Where(s => s.StudentID == x.StudentID).FirstOrDefault();
                            var valueBldg = maintain.GetRoom().Where(xx => xx.RoomCode == x.RoomCode).FirstOrDefault();
                            dgRoomRecord.Rows.Add(x.ID, i, x.StudentID, studs.LastName + "," + studs.FirstName, x.Semester, valueBldg.BuildingCode, x.RoomCode, valueBldg.Description, x.TimeStart.ToShortTimeString() + " to " + x.TImeEnd.ToShortTimeString());
                            i++;
                        }
                    }
                });
            }
        }
        void LoadSearch(bool Year, bool Semester, bool Room, bool Subject)
        {
            dgRoomRecord.Rows.Clear();
            int i = 1;

            using (SMSNotification notify = new SMSNotification())
            {
                using (Maintenance maintain = new Maintenance())
                {
                    using (Students stud = new Students())
                    {
                        if (!Year && !Semester && !Room && !Subject)
                        {
                            LoadRoomRecord();
                        }
                        if (Year && Semester && Room && Subject)//four
                        {
                            dgRoomRecord.Rows.Clear();
                            var value = notify.GetRegisterStudent().Where(x => x.YearClass == cmbYearClass.Text && x.Semester == cmbSemester.Text && x.RoomCode == cmbRoomCode.Text && x.SubjectCode == cmbSubCode.Text).OrderBy(o => o.TimeStart).ToList();
                            if (value.Count > 0)
                            {
                                value.ForEach(x =>
                                {
                                    var studs     = stud.GetStudentInfo().Where(s => s.StudentID == x.StudentID).FirstOrDefault();
                                    var valueBldg = maintain.GetRoom().Where(xx => xx.RoomCode == x.RoomCode).FirstOrDefault();
                                    dgRoomRecord.Rows.Add(x.ID, i, x.StudentID, studs.LastName + "," + studs.FirstName, x.Semester, valueBldg.BuildingCode, x.RoomCode, valueBldg.Description, x.TimeStart.ToShortTimeString() + " to " + x.TImeEnd.ToShortTimeString());
                                    i++;
                                });
                            }
                        }
                        if (Year) //four
                        {
                            dgRoomRecord.Rows.Clear();
                            var value = notify.GetRegisterStudent().Where(x => x.YearClass == cmbYearClass.Text).OrderBy(o => o.TimeStart).ToList();
                            if (value.Count > 0)
                            {
                                value.ForEach(x =>
                                {
                                    var studs     = stud.GetStudentInfo().Where(s => s.StudentID == x.StudentID).FirstOrDefault();
                                    var valueBldg = maintain.GetRoom().Where(xx => xx.RoomCode == x.RoomCode).FirstOrDefault();
                                    dgRoomRecord.Rows.Add(x.ID, i, x.StudentID, studs.LastName + "," + studs.FirstName, x.Semester, valueBldg.BuildingCode, x.RoomCode, valueBldg.Description, x.TimeStart.ToShortTimeString() + " to " + x.TImeEnd.ToShortTimeString());
                                    i++;
                                });
                            }
                        }
                        if (Semester) //four
                        {
                            dgRoomRecord.Rows.Clear();
                            var value = notify.GetRegisterStudent().Where(x => x.Semester == cmbSemester.Text).OrderBy(o => o.TimeStart).ToList();
                            if (value.Count > 0)
                            {
                                value.ForEach(x =>
                                {
                                    var studs     = stud.GetStudentInfo().Where(s => s.StudentID == x.StudentID).FirstOrDefault();
                                    var valueBldg = maintain.GetRoom().Where(xx => xx.RoomCode == x.RoomCode).FirstOrDefault();
                                    dgRoomRecord.Rows.Add(x.ID, i, x.StudentID, studs.LastName + "," + studs.FirstName, x.Semester, valueBldg.BuildingCode, x.RoomCode, valueBldg.Description, x.TimeStart.ToShortTimeString() + " to " + x.TImeEnd.ToShortTimeString());
                                    i++;
                                });
                            }
                        }
                        if (Room) //four
                        {
                            dgRoomRecord.Rows.Clear();
                            var value = notify.GetRegisterStudent().Where(x => x.RoomCode == cmbRoomCode.Text).OrderBy(o => o.TimeStart).ToList();
                            if (value.Count > 0)
                            {
                                value.ForEach(x =>
                                {
                                    var studs     = stud.GetStudentInfo().Where(s => s.StudentID == x.StudentID).FirstOrDefault();
                                    var valueBldg = maintain.GetRoom().Where(xx => xx.RoomCode == x.RoomCode).FirstOrDefault();
                                    dgRoomRecord.Rows.Add(x.ID, i, x.StudentID, studs.LastName + "," + studs.FirstName, x.Semester, valueBldg.BuildingCode, x.RoomCode, valueBldg.Description, x.TimeStart.ToShortTimeString() + " to " + x.TImeEnd.ToShortTimeString());
                                    i++;
                                });
                            }
                        }
                        if (Subject)//four
                        {
                            dgRoomRecord.Rows.Clear();
                            var value = notify.GetRegisterStudent().Where(x => x.SubjectCode == cmbSubCode.Text).OrderBy(o => o.TimeStart).ToList();
                            if (value.Count > 0)
                            {
                                value.ForEach(x =>
                                {
                                    var studs     = stud.GetStudentInfo().Where(s => s.StudentID == x.StudentID).FirstOrDefault();
                                    var valueBldg = maintain.GetRoom().Where(xx => xx.RoomCode == x.RoomCode).FirstOrDefault();
                                    dgRoomRecord.Rows.Add(x.ID, i, x.StudentID, studs.LastName + "," + studs.FirstName, x.Semester, valueBldg.BuildingCode, x.RoomCode, valueBldg.Description, x.TimeStart.ToShortTimeString() + " to " + x.TImeEnd.ToShortTimeString());
                                    i++;
                                });
                            }
                        }
                        if (Year && Semester && Room)
                        {
                            dgRoomRecord.Rows.Clear();
                            var value = notify.GetRegisterStudent().Where(x => x.YearClass == cmbYearClass.Text && x.Semester == cmbSemester.Text && x.RoomCode == cmbRoomCode.Text).OrderBy(o => o.TimeStart).ToList();
                            if (value.Count > 0)
                            {
                                value.ForEach(x =>
                                {
                                    var studs     = stud.GetStudentInfo().Where(s => s.StudentID == x.StudentID).FirstOrDefault();
                                    var valueBldg = maintain.GetRoom().Where(xx => xx.RoomCode == x.RoomCode).FirstOrDefault();
                                    dgRoomRecord.Rows.Add(x.ID, i, x.StudentID, studs.LastName + "," + studs.FirstName, x.Semester, valueBldg.BuildingCode, x.RoomCode, valueBldg.Description, x.TimeStart.ToShortTimeString() + " to " + x.TImeEnd.ToShortTimeString());
                                    i++;
                                });
                            }
                        }
                        if (Year && Semester && Subject)
                        {
                            dgRoomRecord.Rows.Clear();
                            var value = notify.GetRegisterStudent().Where(x => x.YearClass == cmbYearClass.Text && x.Semester == cmbSemester.Text && x.SubjectCode == cmbSubCode.Text).OrderBy(o => o.TimeStart).ToList();
                            if (value.Count > 0)
                            {
                                value.ForEach(x =>
                                {
                                    var studs     = stud.GetStudentInfo().Where(s => s.StudentID == x.StudentID).FirstOrDefault();
                                    var valueBldg = maintain.GetRoom().Where(xx => xx.RoomCode == x.RoomCode).FirstOrDefault();
                                    dgRoomRecord.Rows.Add(x.ID, i, x.StudentID, studs.LastName + "," + studs.FirstName, x.Semester, valueBldg.BuildingCode, x.RoomCode, valueBldg.Description, x.TimeStart.ToShortTimeString() + " to " + x.TImeEnd.ToShortTimeString());
                                    i++;
                                });
                            }
                        }

                        if (Semester && Room && Subject)
                        {
                            dgRoomRecord.Rows.Clear();
                            var value = notify.GetRegisterStudent().Where(x => x.Semester == cmbSemester.Text && x.RoomCode == cmbRoomCode.Text && x.SubjectCode == cmbSubCode.Text).OrderBy(o => o.TimeStart).ToList();
                            if (value.Count > 0)
                            {
                                value.ForEach(x =>
                                {
                                    var studs     = stud.GetStudentInfo().Where(s => s.StudentID == x.StudentID).FirstOrDefault();
                                    var valueBldg = maintain.GetRoom().Where(xx => xx.RoomCode == x.RoomCode).FirstOrDefault();
                                    dgRoomRecord.Rows.Add(x.ID, i, x.StudentID, studs.LastName + "," + studs.FirstName, x.Semester, valueBldg.BuildingCode, x.RoomCode, valueBldg.Description, x.TimeStart.ToShortTimeString() + " to " + x.TImeEnd.ToShortTimeString());
                                    i++;
                                });
                            }
                        }
                        if (Year && Room && Subject)
                        {
                            dgRoomRecord.Rows.Clear();
                            var value = notify.GetRegisterStudent().Where(x => x.YearClass == cmbYearClass.Text && x.RoomCode == cmbRoomCode.Text && x.SubjectCode == cmbSubCode.Text).OrderBy(o => o.TimeStart).ToList();
                            if (value.Count > 0)
                            {
                                value.ForEach(x =>
                                {
                                    var studs     = stud.GetStudentInfo().Where(s => s.StudentID == x.StudentID).FirstOrDefault();
                                    var valueBldg = maintain.GetRoom().Where(xx => xx.RoomCode == x.RoomCode).FirstOrDefault();
                                    dgRoomRecord.Rows.Add(x.ID, i, x.StudentID, studs.LastName + "," + studs.FirstName, x.Semester, valueBldg.BuildingCode, x.RoomCode, valueBldg.Description, x.TimeStart.ToShortTimeString() + " to " + x.TImeEnd.ToShortTimeString());
                                    i++;
                                });
                            }
                        }

                        if (Year && Semester)
                        {
                            dgRoomRecord.Rows.Clear();
                            var value = notify.GetRegisterStudent().Where(x => x.YearClass == cmbYearClass.Text && x.Semester == cmbSemester.Text).OrderBy(o => o.TimeStart).ToList();
                            if (value.Count > 0)
                            {
                                value.ForEach(x =>
                                {
                                    var studs     = stud.GetStudentInfo().Where(s => s.StudentID == x.StudentID).FirstOrDefault();
                                    var valueBldg = maintain.GetRoom().Where(xx => xx.RoomCode == x.RoomCode).FirstOrDefault();
                                    dgRoomRecord.Rows.Add(x.ID, i, x.StudentID, studs.LastName + "," + studs.FirstName, x.Semester, valueBldg.BuildingCode, x.RoomCode, valueBldg.Description, x.TimeStart.ToShortTimeString() + " to " + x.TImeEnd.ToShortTimeString());
                                    i++;
                                });
                            }
                        }
                        if (Year && Room)
                        {
                            dgRoomRecord.Rows.Clear();
                            var value = notify.GetRegisterStudent().Where(x => x.YearClass == cmbYearClass.Text && x.RoomCode == cmbRoomCode.Text).OrderBy(o => o.TimeStart).ToList();
                            if (value.Count > 0)
                            {
                                value.ForEach(x =>
                                {
                                    var studs     = stud.GetStudentInfo().Where(s => s.StudentID == x.StudentID).FirstOrDefault();
                                    var valueBldg = maintain.GetRoom().Where(xx => xx.RoomCode == x.RoomCode).FirstOrDefault();
                                    dgRoomRecord.Rows.Add(x.ID, i, x.StudentID, studs.LastName + "," + studs.FirstName, x.Semester, valueBldg.BuildingCode, x.RoomCode, valueBldg.Description, x.TimeStart.ToShortTimeString() + " to " + x.TImeEnd.ToShortTimeString());
                                    i++;
                                });
                            }
                        }
                        if (Year && Subject)
                        {
                            dgRoomRecord.Rows.Clear();
                            var value = notify.GetRegisterStudent().Where(x => x.YearClass == cmbYearClass.Text && x.SubjectCode == cmbSubCode.Text).OrderBy(o => o.TimeStart).ToList();
                            if (value.Count > 0)
                            {
                                value.ForEach(x =>
                                {
                                    var studs     = stud.GetStudentInfo().Where(s => s.StudentID == x.StudentID).FirstOrDefault();
                                    var valueBldg = maintain.GetRoom().Where(xx => xx.RoomCode == x.RoomCode).FirstOrDefault();
                                    dgRoomRecord.Rows.Add(x.ID, i, x.StudentID, studs.LastName + "," + studs.FirstName, x.Semester, valueBldg.BuildingCode, x.RoomCode, valueBldg.Description, x.TimeStart.ToShortTimeString() + " to " + x.TImeEnd.ToShortTimeString());
                                    i++;
                                });
                            }
                        }

                        if (Semester && Room)
                        {
                            dgRoomRecord.Rows.Clear();
                            var value = notify.GetRegisterStudent().Where(x => x.Semester == cmbSemester.Text && x.RoomCode == cmbRoomCode.Text).OrderBy(o => o.TimeStart).ToList();
                            if (value.Count > 0)
                            {
                                value.ForEach(x =>
                                {
                                    var studs     = stud.GetStudentInfo().Where(s => s.StudentID == x.StudentID).FirstOrDefault();
                                    var valueBldg = maintain.GetRoom().Where(xx => xx.RoomCode == x.RoomCode).FirstOrDefault();
                                    dgRoomRecord.Rows.Add(x.ID, i, x.StudentID, studs.LastName + "," + studs.FirstName, x.Semester, valueBldg.BuildingCode, x.RoomCode, valueBldg.Description, x.TimeStart.ToShortTimeString() + " to " + x.TImeEnd.ToShortTimeString());
                                    i++;
                                });
                            }
                        }
                        if (Semester && Subject)
                        {
                            dgRoomRecord.Rows.Clear();
                            var value = notify.GetRegisterStudent().Where(x => x.Semester == cmbSemester.Text && x.SubjectCode == cmbSubCode.Text).OrderBy(o => o.TimeStart).ToList();
                            if (value.Count > 0)
                            {
                                value.ForEach(x =>
                                {
                                    var studs     = stud.GetStudentInfo().Where(s => s.StudentID == x.StudentID).FirstOrDefault();
                                    var valueBldg = maintain.GetRoom().Where(xx => xx.RoomCode == x.RoomCode).FirstOrDefault();
                                    dgRoomRecord.Rows.Add(x.ID, i, x.StudentID, studs.LastName + "," + studs.FirstName, x.Semester, valueBldg.BuildingCode, x.RoomCode, valueBldg.Description, x.TimeStart.ToShortTimeString() + " to " + x.TImeEnd.ToShortTimeString());
                                    i++;
                                });
                            }
                        }
                        if (Room && Subject)
                        {
                            dgRoomRecord.Rows.Clear();
                            var value = notify.GetRegisterStudent().Where(x => x.RoomCode == cmbRoomCode.Text && x.SubjectCode == cmbSubCode.Text).OrderBy(o => o.TimeStart).ToList();
                            if (value.Count > 0)
                            {
                                value.ForEach(x =>
                                {
                                    var studs     = stud.GetStudentInfo().Where(s => s.StudentID == x.StudentID).FirstOrDefault();
                                    var valueBldg = maintain.GetRoom().Where(xx => xx.RoomCode == x.RoomCode).FirstOrDefault();
                                    dgRoomRecord.Rows.Add(x.ID, i, x.StudentID, studs.LastName + "," + studs.FirstName, x.Semester, valueBldg.BuildingCode, x.RoomCode, valueBldg.Description, x.TimeStart.ToShortTimeString() + " to " + x.TImeEnd.ToShortTimeString());
                                    i++;
                                });
                            }
                        }
                    }
                }
            }
        }