protected override void OnPrimaryKeyChangedAsync()
        {
            Record = Student.SelectByID(PrimaryKey);

            List<StudentBrief2> student_Brief2s = Access.Select<StudentBrief2>(string.Format("ref_student_id = {0}", Record.ID));
            if (student_Brief2s.Count > 0)
                _StudentBrief2 = student_Brief2s[0];
            else
                _StudentBrief2 = new StudentBrief2();

            //List<DepartmentGroup> departmentGroups = Access.Select<DepartmentGroup>(string.Format("uid = {0}", _StudentBrief2.DepartmentGroupID.ToString()));
            /*
            if (departmentGroups.Count > 0)
                _DepartmentGroup = departmentGroups[0];
            else
                _DepartmentGroup = new DepartmentGroup();
             * */
        }
Example #2
0
        static void StudentInit_PopupOpen(object sender, PopupOpenEventArgs e)
        {
            AccessHelper Access = new AccessHelper();
            List<GraduationRequirement> graduationRequirements = Access.Select<GraduationRequirement>();
            List<DepartmentGroup> departmentGroups = Access.Select<DepartmentGroup>();
            //MenuButton mb = e.VirtualButtons["不指定"];
            e.VirtualButtons["不指定"].Click += delegate
            {
                List<string> selectedStudentIDs = K12.Presentation.NLDPanels.Student.SelectedSource;
                if (selectedStudentIDs.Count == 0)
                {
                    MessageBox.Show("請先選擇學生!");
                    return;
                }
                List<StudentBrief2> student_Brief2s = Access.Select<StudentBrief2>(string.Format("ref_student_id in {0}", "(" + string.Join(",", selectedStudentIDs) + ")"));
                if (student_Brief2s.Count > 0)
                {
                    student_Brief2s.ForEach(x => x.GraduationRequirementID = 0);
                    student_Brief2s.SaveAll();
                }
                ListPaneFields.Student_GraduationRequirement.Instance.ReloadMe();
            };
            int i = 0;
            foreach (GraduationRequirement var in graduationRequirements)
            {
                IEnumerable<DepartmentGroup> iDepartmentGroups = departmentGroups.Where(x => x.UID == var.DepartmentGroupID.ToString());
                string departmentGroup = string.Empty;
                if (iDepartmentGroups.Count()>0)
                    departmentGroup = iDepartmentGroups.Select(x => x.Name).ElementAt(0);

                if (string.IsNullOrEmpty(departmentGroup))
                    continue;

                i++;
                //mb = e.VirtualButtons[departmentGroup][var.Name];
                e.VirtualButtons[departmentGroup][var.Name].Tag = var.UID;
                if (i == 1)
                    e.VirtualButtons[departmentGroup].BeginGroup = true;

                e.VirtualButtons[departmentGroup][var.Name].Click += (s1, e1) =>
                {
                    MenuButton mb = (s1 as MenuButton);
                    List<string> selectedStudentIDs = K12.Presentation.NLDPanels.Student.SelectedSource;
                    if (selectedStudentIDs.Count == 0)
                    {
                        MessageBox.Show("請先選擇學生!");
                        return;
                    }
                    List<StudentBrief2> student_Brief2s = Access.Select<StudentBrief2>(string.Format("ref_student_id in {0}", "(" + string.Join(",", selectedStudentIDs) + ")"));
                    List<StudentBrief2> addStudent_Brief2s = new List<StudentBrief2>();
                    if (student_Brief2s.Count > 0)
                    {
                        student_Brief2s.ForEach(x => x.GraduationRequirementID = int.Parse(mb.Tag.ToString()));
                        student_Brief2s.SaveAll();
                    }

                    foreach (string studentID in selectedStudentIDs)
                    {
                        if (student_Brief2s.Where(x => x.StudentID.ToString() == studentID).Count() == 0)
                        {
                            StudentBrief2 studentBrief2 = new StudentBrief2();
                            studentBrief2.StudentID = int.Parse(studentID);
                            studentBrief2.GraduationRequirementID = int.Parse(mb.Tag.ToString());
                            addStudent_Brief2s.Add(studentBrief2);
                        }
                    }
                    if (addStudent_Brief2s.Count > 0)
                        addStudent_Brief2s.SaveAll();

                    ListPaneFields.Student_GraduationRequirement.Instance.ReloadMe();
                };
            }
        }