Exemple #1
0
        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));
            }
        }
        void selectAcception_AcceptingAdmin(object sender, DialogControllerAcceptingEventArgs e)
        {
            Dictionary <string, int> dicLessonCurrentRegNum = new Dictionary <string, int>();
            ObjectSpace         objectSpace = Application.CreateObjectSpace();
            ListView            lv          = ((ListView)((WindowController)sender).Window.View);
            User                u           = (User)SecuritySystem.CurrentUser;
            XPCollection <Role> xpc         = new XPCollection <Role>(u.Roles,
                                                                      new BinaryOperator("Name", "Administrators"));
            XPCollection <Role> xpc2 = new XPCollection <Role>(u.Roles,
                                                               new BinaryOperator("Name", "DataAdmins"));

            if (xpc.Count + xpc2.Count > 0)
            {
                objectSpace.Session.BeginTransaction();

                Student currentStudent;
                Lesson  curLesson;
                Dictionary <string, List <string> > errorstudent = new Dictionary <string, List <string> >();
                int numregok = 0;
                foreach (string studentCode in dicStudentRegDetail.Keys)
                {
                    currentStudent = objectSpace.FindObject <Student>(
                        new BinaryOperator("StudentCode", studentCode));
                    foreach (Lesson lesson in lv.SelectedObjects)
                    {
                        if (!dicLessonCurrentRegNum.ContainsKey(lesson.LessonName))
                        {
                            dicLessonCurrentRegNum[lesson.LessonName] = 0;
                        }
                        //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);
                                }
                                regdetail.Delete();
                            }
                            else
                            {
                                numregok++;
                                dicLessonCurrentRegNum[lesson.LessonName]++;
                                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);
                            }
                        }
                    }
                }
                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ý 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));
            }
        }
Exemple #3
0
        void selectAcception_AcceptingAdmin(object sender, DialogControllerAcceptingEventArgs e)
        {
            ObjectSpace objectSpace = Application.CreateObjectSpace();

            DevExpress.ExpressApp.ListView lv = ((DevExpress.ExpressApp.ListView)((WindowController)sender).Window.View);
            User u = (User)SecuritySystem.CurrentUser;
            XPCollection <Role> xpc = new XPCollection <Role>(u.Roles,
                                                              new BinaryOperator("Name", "Administrators"));
            XPCollection <Role> xpc2 = new XPCollection <Role>(u.Roles,
                                                               new BinaryOperator("Name", "DataAdmins"));

            if (xpc.Count + xpc2.Count > 0)
            {
                objectSpace.Session.BeginTransaction();

                Student currentStudent;
                Lesson  curLesson;
                foreach (string studentCode in listStudentCode)
                {
                    currentStudent = objectSpace.FindObject <Student>(
                        new BinaryOperator("StudentCode", studentCode));
                    foreach (Lesson lesson in lv.SelectedObjects)
                    {
                        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)
                        {
                            regdetail.Delete();
                        }
                        else
                        {
                            regdetail.Save();
                        }
                    }
                }
                objectSpace.Session.CommitTransaction();

                PopUpMessage ms = objectSpace.CreateObject <PopUpMessage>();
                ms.Title   = "Lỗi đăng ký";
                ms.Message = string.Format("Error");
                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));
                ////               View.ObjectSpace.CommitChanges();
                //View.ObjectSpace.Refresh();
                //ListView view = null;
                //Frame currentFrame = ((ActionBase)sender).Controller.Frame;
                //switch (currentFrame.View.ObjectTypeInfo.Name)
                //{
                //    case "Student":
                //        view = Application.CreateListView(objectSpace,typeof(RegisterDetail),true);
                //        break;
                //}
                //currentFrame.SetView(view);
                //e.Cancel = true;
            }
        }