private void SelectRegister_Execute(object sender, SimpleActionExecuteEventArgs args)
        {
            ObjectSpace os = Application.CreateObjectSpace();

            if (SecuritySystem.CurrentUser is Student)
            {
                #region student
                ObjectSpace objectSpace = Application.CreateObjectSpace();
                CriteriaOperatorCollection c = new CriteriaOperatorCollection();

                CollectionSource newCollectionSource = new CollectionSource(objectSpace, typeof(Lesson));
                listVacancies = new List<Vacancy>();
                foreach (RegisterDetail regDetail in ((ProxyCollection)((DevExpress.ExpressApp.ListView)View).CollectionSource.Collection))
                {
                    foreach (TkbSemester tkbsem in regDetail.Lesson.TKBSemesters)
                    {
                        listVacancies.Add(new Vacancy(tkbsem.Day, tkbsem.Period, tkbsem.Weeks, tkbsem.Classroom.ClassroomCode));
                    }
                    //newCollectionSource.Criteria[regDetail.Lesson.Oid.ToString()] =
                    //    new BinaryOperator("Oid", regDetail.Lesson.Oid, BinaryOperatorType.NotEqual);
                }

                using (XPCollection xpLesson = new XPCollection(objectSpace.Session, typeof(Lesson)))
                {
                    Vacancy vc;
                    foreach (Lesson lesson in xpLesson)
                    {
                        if ((!lesson.CanRegister) || (lesson.NumRegistration >= lesson.NumExpectation))
                        {
                            //quá sĩ số
                            newCollectionSource.Criteria[lesson.Oid.ToString()] = new BinaryOperator("Oid", lesson.Oid, BinaryOperatorType.NotEqual);

                        }
                        //vi phạm thời khóa biểu
                        foreach (TkbSemester tkbsem in lesson.TKBSemesters)
                        {
                            vc = new Vacancy(tkbsem.Day, tkbsem.Period, tkbsem.Weeks, (tkbsem.Classroom == null ? "" : tkbsem.Classroom.ClassroomCode));
                            if (Utils.IsConfictTKB(listVacancies, vc))
                            {
                                newCollectionSource.Criteria[lesson.Oid.ToString()] = new BinaryOperator("Oid", lesson.Oid, BinaryOperatorType.NotEqual);
                                break;
                            }
                        }

                    }
                }

                DevExpress.ExpressApp.ListView lv = Application.CreateListView(
                    Application.FindListViewId(typeof(Lesson)),
                    newCollectionSource, true);
                lv.Editor.AllowEdit = false;
                lv.Editor.ControlsCreated += Editor_ControlsCreated;

                args.ShowViewParameters.CreatedView = lv;
                args.ShowViewParameters.TargetWindow = TargetWindow.NewModalWindow;
                args.ShowViewParameters.CreateAllControllers = true;
                DialogController selectAcception = new DialogController();
                args.ShowViewParameters.Controllers.Add(selectAcception);
                selectAcception.Accepting += selectAcception_AcceptingStudent;
                #endregion
            }
            else
            {
                ObjectSpace objectSpace = Application.CreateObjectSpace();
                CriteriaOperatorCollection c = new CriteriaOperatorCollection();
                listStudentCode = new List<string>();
                CollectionSource newCollectionSource = new CollectionSource(objectSpace, typeof(Lesson));
                listVacancies = new List<Vacancy>();
                foreach (Student student in View.SelectedObjects)
                {
                    foreach (RegisterDetail regDetail in student.RegisterDetails)
                    {
                        foreach (TkbSemester tkbsem in regDetail.Lesson.TKBSemesters)
                        {
                            listVacancies.Add(new Vacancy(tkbsem.Day, tkbsem.Period, tkbsem.Weeks, tkbsem.Classroom.ClassroomCode));
                        }
                        //newCollectionSource.Criteria[regDetail.Lesson.Oid.ToString()] =
                        //    new BinaryOperator("Oid", regDetail.Lesson.Oid, BinaryOperatorType.NotEqual);
                    }
                    listStudentCode.Add(student.StudentCode);
                }
                using (XPCollection xpLesson = new XPCollection(objectSpace.Session, typeof(Lesson)))
                {
                    Vacancy vc;
                    foreach (Lesson lesson in xpLesson)
                    {
                        if ((!lesson.CanRegister) || (lesson.NumRegistration >= lesson.NumExpectation))
                        {
                            //quá sĩ số
                            newCollectionSource.Criteria[lesson.Oid.ToString()] = new BinaryOperator("Oid", lesson.Oid, BinaryOperatorType.NotEqual);

                        }
                        //vi phạm thời khóa biểu
                        foreach (TkbSemester tkbsem in lesson.TKBSemesters)
                        {
                            vc = new Vacancy(tkbsem.Day, tkbsem.Period, tkbsem.Weeks, (tkbsem.Classroom == null ? "" : tkbsem.Classroom.ClassroomCode));
                            if (Utils.IsConfictTKB(listVacancies, vc))
                            {
                                newCollectionSource.Criteria[lesson.Oid.ToString()] = new BinaryOperator("Oid", lesson.Oid, BinaryOperatorType.NotEqual);
                                break;
                            }
                        }

                    }
                }

                DevExpress.ExpressApp.ListView lv = Application.CreateListView(
                    Application.FindListViewId(typeof(Lesson)),
                    newCollectionSource, true);
                lv.Editor.AllowEdit = false;
                lv.Editor.ControlsCreated += Editor_ControlsCreated;

                args.ShowViewParameters.CreatedView = lv;
                args.ShowViewParameters.TargetWindow = TargetWindow.NewModalWindow;
                args.ShowViewParameters.CreateAllControllers = true;
                DialogController selectAcception = new DialogController();
                args.ShowViewParameters.Controllers.Add(selectAcception);
                selectAcception.Accepting += selectAcception_AcceptingAdmin;
            }
        }
 public static bool IsConfictTKB(List<Vacancy> lvc, Vacancy vc)
 {
     Vacancy nvc = lvc.Find(v => (v.day == vc.day && TestPeriod(v.period, vc.period) && TestWeek(v.weeks, vc.weeks)));
     return (nvc != null);
 }
        void gridView_SelectionChanged(object sender, EventArgs e)
        {
            if (SecuritySystem.CurrentUser is Student)
            {
                Student student = SecuritySystem.CurrentUser as Student;
                string currentClass = student.StudentClass.ClassCode;

                ASPxGridView gc = sender as ASPxGridView;

                List<Vacancy> tempList = new List<Vacancy>(listVacancies);

                List<object> listobj = gc.GetSelectedFieldValues(new string[] { "LessonCode" });
                List<object> listobjOid = gc.GetSelectedFieldValues(new string[] { "Oid" });
                ObjectSpace objectSpace = Application.CreateObjectSpace();

                Vacancy vc;
                string strFilter = "", strInclude = "";
                foreach (Guid guid in listobjOid)
                {
                    Lesson lesson = objectSpace.FindObject<Lesson>(new BinaryOperator("Oid", guid));
                    strInclude += String.Format("OR ([Oid]={0})", lesson.Oid);
                    foreach (TkbSemester tkbsem in lesson.TKBSemesters)
                    {
                        vc = new Vacancy(tkbsem.Day, tkbsem.Period, tkbsem.Weeks, (tkbsem.Classroom == null ? "" : tkbsem.Classroom.ClassroomCode));
                        tempList.Add(vc);
                    }
                }
                if (strInclude != "")
                    strInclude = String.Format("({0})", strInclude.Substring(3));

                if (listobj.Count > 0)
                {
                    foreach (int strLessonCode in listobj)
                    {
                        strFilter += String.Format("AND ([LessonCode]<>{0})", strLessonCode);
                    }

                    using (XPCollection xpLesson = new XPCollection(objectSpace.Session, typeof(Lesson)))
                    {

                        foreach (Lesson lesson in xpLesson)
                        {
                            foreach (TkbSemester tkbsem in lesson.TKBSemesters)
                            {
                                vc = new Vacancy(tkbsem.Day, tkbsem.Period, tkbsem.Weeks, (tkbsem.Classroom == null ? "" : tkbsem.Classroom.ClassroomCode));
                                if (Utils.IsConfictTKB(tempList, vc))
                                {
                                    strFilter += String.Format("AND ([Oid]<>{0})", lesson.Oid);
                                    break;
                                }
                            }
                        }
                        if (strFilter != "")
                            strFilter = String.Format("({0})", strFilter.Substring(4));

                    }
                }
                if (strInclude != "" && strFilter != "")
                {
                    strFilter = String.Format("({0} OR {1})", strFilter, strInclude);
                }
                else if (strInclude != "")
                {
                    strFilter = strInclude;

                }

                if (strFilter != "")
                {
                    if (gc.FilterExpression.Contains("ClassIDs"))
                    {
                        gc.FilterExpression = string.Format("([ClassIDs] Like '%{0}%') AND {1}", currentClass, strFilter);
                    }
                    else
                    {
                        gc.FilterExpression = strFilter;
                    }
                }

            }
        }
        private void SelectRegister_Execute(object sender, SimpleActionExecuteEventArgs args)
        {
            PopUpMessage ms;
            DialogController dc;
            ObjectSpace objectSpace = Application.CreateObjectSpace();
            {
                ConstrainstParameter cpNHHK = objectSpace.FindObject<ConstrainstParameter>(
                           new BinaryOperator("Code", "REGISTERSEMESTER"));

                if (cpNHHK == null || cpNHHK.Value == 0)
                    throw new UserFriendlyException("Người Quản trị chưa thiết lập NHHK để ĐKMH, vui lòng liên hệ quản trị viên.");

                if (SecuritySystem.CurrentUser is Student)
                {
                    #region student

                    CriteriaOperatorCollection c = new CriteriaOperatorCollection();

                    if (!IsInBookTime((Student)SecuritySystem.CurrentUser))
                    {
                        ms = objectSpace.CreateObject<PopUpMessage>();
                        ms.Title = "Không đăng ký được";
                        //ms.Message = string.Format("Chỉ đăng ký được trong khoảng thời gian qui định");
                        ms.Message = string.Format("Chỉ chọn được trong khoảng thời gian qui định\r\n từ ngày {0:dd-MM-yyyy} đến ngày {1:dd-MM-yyyy}",
                                StartConfirmDate, EndConfirmDate);
                        args.ShowViewParameters.CreatedView = Application.CreateDetailView(
                             objectSpace, ms);
                        args.ShowViewParameters.TargetWindow = TargetWindow.NewModalWindow;
                        args.ShowViewParameters.CreatedView.Caption = "Thông báo";
                        dc = Application.CreateController<DialogController>();
                        dc.AcceptAction.Active.SetItemValue("object", false);
                        dc.CancelAction.Caption = "Đóng";
                        args.ShowViewParameters.Controllers.Add(dc);

                        dc.SaveOnAccept = false;

                        return;
                    }

                    decimal deptAmount = 0m;
                    if (IsInDeptStudent(objectSpace, (Student)SecuritySystem.CurrentUser, out deptAmount))
                    {
                        ms = objectSpace.CreateObject<PopUpMessage>();
                        ms.Title = "Không đăng ký được";
                        ms.Message = string.Format("Không đăng ký được vì bạn đang nợ học phí số tiền {0:0,0}", deptAmount);
                        args.ShowViewParameters.CreatedView = Application.CreateDetailView(
                             objectSpace, ms);
                        args.ShowViewParameters.TargetWindow = TargetWindow.NewModalWindow;
                        args.ShowViewParameters.CreatedView.Caption = "Thông báo";
                        dc = Application.CreateController<DialogController>();
                        dc.AcceptAction.Active.SetItemValue("object", false);
                        dc.CancelAction.Caption = "Đóng";
                        args.ShowViewParameters.Controllers.Add(dc);
                        dc.SaveOnAccept = false;
                        return;
                    }

                    CollectionSource newCollectionSource = new CollectionSource(objectSpace, typeof(Lesson));
                    newCollectionSource.Criteria[cpNHHK.Value.ToString()] = new BinaryOperator(
                        "Semester.SemesterName", cpNHHK.Value, BinaryOperatorType.Greater);

                    listVacancies = new List<Vacancy>();
                    ASPxGridListEditor listEditor = ((ListView)View).Editor as ASPxGridListEditor;
                    ASPxGridView gv = listEditor.Grid;
                    gv.Selection.SelectAll();

                    foreach (RegisterDetail regDetail in ((ListView)View).SelectedObjects)
                    {
                        foreach (TkbSemester tkbsem in regDetail.Lesson.TKBSemesters)
                        {
                            listVacancies.Add(new Vacancy(tkbsem.Day, tkbsem.Period, tkbsem.Weeks, tkbsem.Classroom.ClassroomCode));
                        }
                        newCollectionSource.Criteria[regDetail.Lesson.Subject.SubjectCode] =
                               new BinaryOperator("Subject.SubjectCode", regDetail.Lesson.Subject.SubjectCode, BinaryOperatorType.NotEqual);

                        //newCollectionSource.Criteria[regDetail.Lesson.Oid.ToString()] =
                        //    new BinaryOperator("Oid", regDetail.Lesson.Oid, BinaryOperatorType.NotEqual);
                    }

                    using (XPCollection xpLesson = new XPCollection(objectSpace.Session, typeof(Lesson)))
                    {
                        Vacancy vc;
                        foreach (Lesson lesson in xpLesson)
                        {
                            if ((!lesson.CanRegister) || (lesson.NumRegistration >= lesson.NumExpectation)) //||(Convert.ToInt32(lesson.Semester.SemesterName)<=cpNHHK.Value)
                            {
                                //quá sĩ số
                                newCollectionSource.Criteria[lesson.Oid.ToString()] = new BinaryOperator("Oid", lesson.Oid, BinaryOperatorType.NotEqual);

                            }
                            //vi phạm thời khóa biểu
                            foreach (TkbSemester tkbsem in lesson.TKBSemesters)
                            {
                                vc = new Vacancy(tkbsem.Day, tkbsem.Period, tkbsem.Weeks, (tkbsem.Classroom == null ? "" : tkbsem.Classroom.ClassroomCode));
                                if (Utils.IsConfictTKB(listVacancies, vc))
                                {
                                    newCollectionSource.Criteria[lesson.Oid.ToString()] = new BinaryOperator("Oid", lesson.Oid, BinaryOperatorType.NotEqual);
                                    break;
                                }
                            }

                        }
                    }

                    ListView lv = Application.CreateListView(
                        Application.FindListViewId(typeof(Lesson)),
                        newCollectionSource, true);
                    lv.Editor.AllowEdit = false;
                    lv.Editor.ControlsCreated += Editor_ControlsCreated;

                    args.ShowViewParameters.CreatedView = lv;
                    args.ShowViewParameters.TargetWindow = TargetWindow.NewModalWindow;
                    args.ShowViewParameters.CreateAllControllers = true;
                    DialogController selectAcception = new DialogController();
                    args.ShowViewParameters.Controllers.Add(selectAcception);
                    selectAcception.AcceptAction.Caption = "Chọn";
                    selectAcception.CancelAction.Caption = "Bỏ qua";
                    selectAcception.Accepting += selectAcception_AcceptingStudent;
                    #endregion
                }
                else
                {

                    CriteriaOperatorCollection c = new CriteriaOperatorCollection();

                    dicStudentRegDetail = new Dictionary<string, List<string>>();

                    CollectionSource newCollectionSource = new CollectionSource(objectSpace, typeof(Lesson));
                    newCollectionSource.Criteria[cpNHHK.Value.ToString()] = new BinaryOperator(
                       "Semester.SemesterName", cpNHHK.Value, BinaryOperatorType.Greater);
                    listVacancies = new List<Vacancy>();
                    foreach (Student student in View.SelectedObjects)
                    {
                        if (!dicStudentRegDetail.ContainsKey(student.StudentCode))
                            dicStudentRegDetail.Add(student.StudentCode, new List<string>());

                        foreach (RegisterDetail regDetail in student.RegisterDetails)
                        {
                            foreach (TkbSemester tkbsem in regDetail.Lesson.TKBSemesters)
                            {
                                listVacancies.Add(new Vacancy(tkbsem.Day, tkbsem.Period, tkbsem.Weeks, tkbsem.Classroom.ClassroomCode));
                            }
                            dicStudentRegDetail[student.StudentCode].Add(regDetail.Lesson.Subject.SubjectCode);

                            newCollectionSource.Criteria[regDetail.Lesson.Subject.SubjectCode] =
                                new BinaryOperator("Subject.SubjectCode", regDetail.Lesson.Subject.SubjectCode, BinaryOperatorType.NotEqual);
                        }
                        //listStudentCode.Add(student.StudentCode);
                    }

                    using (XPCollection xpLesson = new XPCollection(objectSpace.Session, typeof(Lesson)))
                    {
                        Vacancy vc;
                        foreach (Lesson lesson in xpLesson)
                        {
                            if ((lesson.NumRegistration >= lesson.NumExpectation))//(Convert.ToInt32(lesson.Semester.SemesterName) <= cpNHHK.Value) ||
                            {
                                //quá sĩ số
                                newCollectionSource.Criteria[lesson.Oid.ToString()] = new BinaryOperator("Oid", lesson.Oid, BinaryOperatorType.NotEqual);

                            }
                            //vi phạm thời khóa biểu
                            foreach (TkbSemester tkbsem in lesson.TKBSemesters)
                            {
                                vc = new Vacancy(tkbsem.Day, tkbsem.Period, tkbsem.Weeks, (tkbsem.Classroom == null ? "" : tkbsem.Classroom.ClassroomCode));
                                if (Utils.IsConfictTKB(listVacancies, vc))
                                {
                                    newCollectionSource.Criteria[lesson.Oid.ToString()] = new BinaryOperator("Oid", lesson.Oid, BinaryOperatorType.NotEqual);
                                    break;
                                }
                            }

                        }
                    }

                    ListView lv = Application.CreateListView(
                        Application.FindListViewId(typeof(Lesson)),
                        newCollectionSource, true);
                    lv.Editor.AllowEdit = false;
                    lv.Editor.ControlsCreated += Editor_ControlsCreated;

                    args.ShowViewParameters.CreatedView = lv;
                    args.ShowViewParameters.TargetWindow = TargetWindow.NewModalWindow;
                    args.ShowViewParameters.CreateAllControllers = true;
                    //args.ShowViewParameters.Context = TemplateContext.View;
                    DialogController selectAcception = new DialogController();
                    args.ShowViewParameters.Controllers.Add(selectAcception);
                    selectAcception.Accepting += selectAcception_AcceptingAdmin;

                    selectAcception.AcceptAction.Caption = "Chọn";
                    selectAcception.CancelAction.Caption = "Bỏ qua";

                }
            }
        }
        private void DefaultRegister_Execute(object sender, SimpleActionExecuteEventArgs e)
        {
            ObjectSpace objectSpace = Application.CreateObjectSpace();

            dicStudentRegDetail = new Dictionary<string, List<string>>();
            Student currentStudent;
            Lesson curLesson;
            Dictionary<string, List<string>> errorstudent = new Dictionary<string, List<string>>();
            Dictionary<string, int> dicLessonCurrentRegNum = new Dictionary<string, int>();
            int numregok = 0;
            Vacancy vc;
            bool isConflictTKB = false;
            using (XPCollection<Lesson> newCollectionSource = new XPCollection<Lesson>(objectSpace.Session))
            {
                objectSpace.Session.BeginTransaction();
                foreach (StudentClass studentClass in View.SelectedObjects)
                {
                    newCollectionSource.Criteria = CriteriaOperator.Parse(
                        "ClassIDs like ?", string.Format("%{0}%", studentClass.ClassCode));

                    foreach (Student student in studentClass.Students)
                    {
                        listVacancies = new List<Vacancy>();
                        currentStudent = objectSpace.FindObject<Student>(
                        new BinaryOperator("StudentCode", student.StudentCode));

                        foreach (Lesson lesson in newCollectionSource)
                        {
                            isConflictTKB = false;
                            if (!dicLessonCurrentRegNum.ContainsKey(lesson.LessonName))
                            {
                                dicLessonCurrentRegNum[lesson.LessonName] = 0;
                            }
                            foreach (TkbSemester tkbsem in lesson.TKBSemesters)
                            {
                                vc = new Vacancy(tkbsem.Day, tkbsem.Period, tkbsem.Weeks, (tkbsem.Classroom == null ? "" : tkbsem.Classroom.ClassroomCode));
                                if (Utils.IsConfictTKB(listVacancies, vc))
                                {
                                    isConflictTKB = true;
                                    break;
                                }
                            }

                            if (isConflictTKB)
                            {
                                if (!errorstudent.ContainsKey(currentStudent.StudentCode))
                                    errorstudent.Add(currentStudent.StudentCode, new List<string>());
                                if (!errorstudent[currentStudent.StudentCode].Contains(lesson.Subject.SubjectCode))
                                    errorstudent[currentStudent.StudentCode].Add(lesson.Subject.SubjectCode + "{T}");
                            }
                            else
                            {
                                //si so chon chua vuot qua
                                if (lesson.NumExpectation > dicLessonCurrentRegNum[lesson.LessonName] + lesson.NumRegistration)
                                {
                                    curLesson = objectSpace.FindObject<Lesson>(
                                    new BinaryOperator("Oid", lesson.Oid));
                                    RegisterDetail regdetail = new RegisterDetail(objectSpace.Session)
                                    {
                                        Student = currentStudent,
                                        Lesson = curLesson,
                                        RegisterState = objectSpace.FindObject<RegisterState>(
                                            new BinaryOperator("Code", "SELECTED")),
                                        CheckState = objectSpace.FindObject<RegisterState>(
                                        new BinaryOperator("Code", "NOTCHECKED"))
                                    };
                                    RuleSet ruleSet = new RuleSet();

                                    RuleSetValidationResult result = ruleSet.ValidateTarget(regdetail, DefaultContexts.Save);
                                    if (ValidationState.Invalid ==
                                        result.GetResultItem("RegisterDetail.StudentRegLessonSemester").State)
                                    {
                                        if (!errorstudent.ContainsKey(currentStudent.StudentCode))
                                            errorstudent.Add(currentStudent.StudentCode, new List<string>());
                                        if (!errorstudent[currentStudent.StudentCode].Contains(curLesson.Subject.SubjectCode))
                                            errorstudent[currentStudent.StudentCode].Add(curLesson.Subject.SubjectCode + "{D}");
                                        regdetail.Delete();
                                        //regdetail.Reload();

                                    }
                                    else
                                    {
                                        numregok++;
                                        if (!dicStudentRegDetail.ContainsKey(student.StudentCode))
                                            dicStudentRegDetail.Add(student.StudentCode,new List<string>());
                                        dicStudentRegDetail[student.StudentCode].Add(curLesson.LessonName);

                                        dicLessonCurrentRegNum[lesson.LessonName]++;
                                        foreach (TkbSemester tkbsem in curLesson.TKBSemesters)
                                        {
                                            vc = new Vacancy(tkbsem.Day, tkbsem.Period, tkbsem.Weeks, (tkbsem.Classroom == null ? "" : tkbsem.Classroom.ClassroomCode));
                                            listVacancies.Add(vc);
                                        }
                                        regdetail.Save();
                                    }
                                }
                                else
                                {
                                    if (!errorstudent.ContainsKey(currentStudent.StudentCode))
                                        errorstudent.Add(currentStudent.StudentCode, new List<string>());
                                    if (!errorstudent[currentStudent.StudentCode].Contains(lesson.Subject.SubjectCode))
                                        errorstudent[currentStudent.StudentCode].Add(lesson.Subject.SubjectCode + "{H}");
                                }
                            }
                        }
                    }
                }
                objectSpace.Session.CommitTransaction();
                PopUpMessage ms = objectSpace.CreateObject<PopUpMessage>();
                if (errorstudent.Count > 0)
                {
                    ms.Title = "Có lỗi khi chọn nhóm MH đăng ký!";
                    ms.Message = string.Format("Đã chọn được cho {0} sinh viên với {1} lượt nhóm MH\r\n", dicStudentRegDetail.Count, numregok);
                    string strmessage = "Không chọn được nhóm môn học do trùng môn đã đăng ký, trùng lịch hoặc hết chỗ: ";
                    foreach (KeyValuePair<string, List<string>> keypair in errorstudent)
                    {
                        strmessage += string.Format("Sinh viên:[{0}] - Môn:[", keypair.Key);
                        foreach (string str in keypair.Value)
                        {
                            strmessage += str + ",";
                        }
                        strmessage = strmessage.TrimEnd(',');
                        strmessage += "]\r\n";
                    }
                    ms.Message += strmessage;
                }
                else
                {
                    ms.Title = "Chọn nhóm MH thành công";
                    ms.Message = string.Format("Chọn nhóm MH thành công cho {0} sinh viên với {1} lượt nhóm MH\r\n", dicStudentRegDetail.Count, numregok);
                }
                ShowViewParameters svp = new ShowViewParameters();
                svp.CreatedView = Application.CreateDetailView(
                     objectSpace, ms);
                svp.TargetWindow = TargetWindow.NewModalWindow;
                svp.CreatedView.Caption = "Thông báo";
                DialogController dc = Application.CreateController<DialogController>();
                svp.Controllers.Add(dc);

                dc.SaveOnAccept = false;
                Application.ShowViewStrategy.ShowView(svp, new ShowViewSource(null, null));
            }
        }
        private void SelectRegister_Execute(object sender, SimpleActionExecuteEventArgs args)
        {
            ObjectSpace objectSpace = Application.CreateObjectSpace();
            ConstrainstParameter cpNHHK = objectSpace.FindObject<ConstrainstParameter>(
                           new BinaryOperator("Code", "REGISTERSEMESTER"));
            if (cpNHHK == null || cpNHHK.Value == 0 || cpNHHK.Value.ToString().Length!=5)
                throw new UserFriendlyException("Người Quản trị chưa thiết lập NHHK để ĐKMH, vui lòng liên hệ quản trị viên.");

            CriteriaOperatorCollection c = new CriteriaOperatorCollection();

            dicStudentRegDetail = new Dictionary<string, List<string>>();

            CollectionSource newCollectionSource = new CollectionSource(objectSpace, typeof(Lesson));
            listVacancies = new List<Vacancy>();
            foreach (StudentClass studentClass in View.SelectedObjects)
            {
                foreach (Student student in studentClass.Students)
                {
                    if (!dicStudentRegDetail.ContainsKey(student.StudentCode))
                        dicStudentRegDetail.Add(student.StudentCode, new List<string>());

                    foreach (RegisterDetail regDetail in student.RegisterDetails)
                    {
                        foreach (TkbSemester tkbsem in regDetail.Lesson.TKBSemesters)
                        {
                            listVacancies.Add( new Vacancy(tkbsem.Day, tkbsem.Period, tkbsem.Weeks, (tkbsem.Classroom == null ? "" : tkbsem.Classroom.ClassroomCode)));
                        }
                        dicStudentRegDetail[student.StudentCode].Add(regDetail.Lesson.Subject.SubjectCode);

                        newCollectionSource.Criteria[regDetail.Lesson.Subject.SubjectCode] =
                            new BinaryOperator("Subject.SubjectCode", regDetail.Lesson.Subject.SubjectCode, BinaryOperatorType.NotEqual);
                    }
                    //listStudentCode.Add(student.StudentCode);
                }
            }

            using (XPCollection xpLesson = new XPCollection(objectSpace.Session, typeof(Lesson)))
            {
                Vacancy vc;
                foreach (Lesson lesson in xpLesson)
                {
                    if ((Convert.ToInt32(lesson.Semester.SemesterName) <= cpNHHK.Value) || (lesson.NumRegistration >= lesson.NumExpectation))
                    {
                        //không đăng ký, quá sĩ số, khác nhhk
                        newCollectionSource.Criteria[lesson.Oid.ToString()] = new BinaryOperator("Oid", lesson.Oid, BinaryOperatorType.NotEqual);

                    }
                    //vi phạm thời khóa biểu
                    foreach (TkbSemester tkbsem in lesson.TKBSemesters)
                    {
                        vc = new Vacancy(tkbsem.Day, tkbsem.Period, tkbsem.Weeks, (tkbsem.Classroom == null ? "" : tkbsem.Classroom.ClassroomCode));
                        if (Utils.IsConfictTKB(listVacancies, vc))
                        {
                            newCollectionSource.Criteria[lesson.Oid.ToString()] = new BinaryOperator("Oid", lesson.Oid, BinaryOperatorType.NotEqual);
                            break;
                        }
                    }

                }
            }

            ListView lv = Application.CreateListView(
                Application.FindListViewId(typeof(Lesson)),
                newCollectionSource, true);
            lv.Editor.AllowEdit = false;
            lv.Editor.ControlsCreated += Editor_ControlsCreated;

            args.ShowViewParameters.CreatedView = lv;
            args.ShowViewParameters.TargetWindow = TargetWindow.NewModalWindow;
            args.ShowViewParameters.CreateAllControllers = true;
            DialogController selectAcception = new DialogController();
            args.ShowViewParameters.Controllers.Add(selectAcception);
            selectAcception.Accepting += selectAcception_AcceptingAdmin;
        }