コード例 #1
0
        private void Worker_DoWork(object sender, DoWorkEventArgs e)
        {
            #region DoWork
            object[] objs         = (object[])e.Argument;
            int      schoolyear   = Framework.Int.Parse(objs[0] as string);
            int      semester     = Framework.Int.Parse(objs[1] as string);
            string   domain       = objs[2] as string;
            string   subject      = objs[3] as string;
            string   periodcredit = objs[4] as string;
            string   required     = objs[5] as string;

            PeriodCredit pc = new PeriodCredit();
            pc.Parse(periodcredit);

            double total   = _classes.Count;
            double counter = 0;
            if (total == 0)
            {
                total = 1;
            }
            else
            {
                total *= 2;
            }
            _worker.ReportProgress(1, "正在檢查班級課程…");

            _classes.Sort(SortClassesByClassName);

            #region 檢查重複開課
            List <string> errors = new List <string>();

            List <string> classIDs = new List <string>();
            foreach (JHClassRecord cla in _classes)
            {
                classIDs.Add(cla.ID);
            }

            Dictionary <string, List <JHCourseRecord> > classExistCourses = new Dictionary <string, List <JHCourseRecord> >();
            List <JHCourseRecord> orphanCourse = new List <JHCourseRecord>();

            foreach (JHCourseRecord course in JHCourse.SelectBySchoolYearAndSemester(schoolyear, semester))
            {
                if (!classIDs.Contains(course.RefClassID))
                {
                    orphanCourse.Add(course);
                    continue;
                }

                if (!classExistCourses.ContainsKey(course.RefClassID))
                {
                    classExistCourses.Add(course.RefClassID, new List <JHCourseRecord>());
                }
                classExistCourses[course.RefClassID].Add(course);
            }

            foreach (JHClassRecord cla in _classes)
            {
                if (!classExistCourses.ContainsKey(cla.ID))
                {
                    continue;
                }

                foreach (JHCourseRecord course in classExistCourses[cla.ID])
                {
                    if (course.Subject == subject)
                    {
                        errors.Add(cla.Name + ":已有相同科目(" + subject + ")的課程。");
                    }
                }

                foreach (JHCourseRecord course in orphanCourse)
                {
                    if (course.Name == cla.Name + " " + subject)
                    {
                        errors.Add(cla.Name + ":已有相同課程名稱(" + course.Name + ")的課程。");
                    }
                }
            }

            if (errors.Count > 0)
            {
                e.Result = errors;
                return;
            }
            #endregion

            #region 開課
            Dictionary <string, string> classNewCourse = new Dictionary <string, string>();

            DSXmlHelper req = new DSXmlHelper("UpdateRequest");

            foreach (JHClassRecord cla in _classes)
            {
                JHCourseRecord newCourse = new JHCourseRecord();
                newCourse.CalculationFlag = "1";
                newCourse.Period          = pc.Period;
                newCourse.Credit          = pc.Credit;
                newCourse.Domain          = domain;
                newCourse.Subject         = subject;
                newCourse.Name            = cla.Name + " " + subject;
                newCourse.SchoolYear      = schoolyear;
                newCourse.Semester        = semester;
                newCourse.RefClassID      = cla.ID;

                //建立Course時也將CourseExtendRecord建立
                string             course_id = JHCourse.Insert(newCourse);
                CourseExtendRecord courseEx  = new CourseExtendRecord();
                courseEx.Ref_course_id = int.Parse(course_id);
                courseEx.GradeYear     = cla.GradeYear == null ? -1 : int.Parse(cla.GradeYear + "");
                courseEx.Save();

                classNewCourse.Add(cla.ID, course_id);
                req.AddElement("Course");
                req.AddElement("Course", "Field");
                req.AddElement("Course/Field", "IsRequired", required.Replace("修", ""));
                req.AddElement("Course", "Condition");
                req.AddElement("Course/Condition", "ID", classNewCourse[cla.ID]);

                counter++;
                _worker.ReportProgress((int)(counter * 100d / total), "正在進行開課…");
            }

            //更新必選修
            if (classNewCourse.Count > 0)
            {
                JHSchool.Feature.Legacy.EditCourse.UpdateCourse(new DSRequest(req));
            }

            #endregion

            #region 加入學生修課

            foreach (JHClassRecord cla in _classes)
            {
                List <JHSCAttendRecord> scattends = new List <JHSchool.Data.JHSCAttendRecord>();
                foreach (JHStudentRecord stu in cla.Students)
                {
                    JHSCAttendRecord scattend = new JHSchool.Data.JHSCAttendRecord();
                    scattend.RefCourseID  = classNewCourse[cla.ID];
                    scattend.RefStudentID = stu.ID;

                    scattends.Add(scattend);
                }

                if (scattends.Count > 0)
                {
                    JHSCAttend.Insert(scattends);
                }

                counter++;
                _worker.ReportProgress((int)(counter * 100d / total), "正在加入學生修課…");
            }
            #endregion

            // 加這主要是重新整理
            Course.Instance.SyncDataBackground(classNewCourse.Values);

            e.Result = string.Empty;

            #endregion
        }
コード例 #2
0
        private void btnOk_Click(object sender, EventArgs e)
        {
            int i;
            int grade = 1;

            if (int.TryParse(cboGrade.Text, out i))
            {
                grade = i;
            }

            string ids = string.Join(",", _courses);

            Dictionary <string, CourseExtendRecord> dic = new Dictionary <string, CourseExtendRecord>();

            foreach (CourseExtendRecord cer in _A.Select <CourseExtendRecord>("ref_course_id in (" + ids + ")"))
            {
                if (!dic.ContainsKey(cer.Ref_course_id + ""))
                {
                    dic.Add(cer.Ref_course_id + "", cer);
                }
            }

            List <CourseExtendRecord> update = new List <CourseExtendRecord>();
            List <CourseExtendRecord> insert = new List <CourseExtendRecord>();

            foreach (string id in _courses)
            {
                int temp;
                int ref_course_id = 0;

                if (int.TryParse(id, out temp))
                {
                    ref_course_id = temp;
                }

                if (dic.ContainsKey(id))
                {
                    dic[id].GradeYear = grade;
                    update.Add(dic[id]);
                }
                else
                {
                    if (ref_course_id > 0)
                    {
                        CourseExtendRecord cer = new CourseExtendRecord();
                        cer.Ref_course_id = ref_course_id;
                        cer.GradeYear     = grade;

                        insert.Add(cer);
                    }
                }
            }

            if (update.Count > 0)
            {
                _A.UpdateValues(update);
            }

            if (insert.Count > 0)
            {
                _A.InsertValues(insert);
            }

            MessageBox.Show("修改完成");
            this.Close();
        }
コード例 #3
0
        private void buttonX1_Click(object sender, EventArgs e)
        {
            EventHandler eh;
            string       EventCode = "Res_CourseExt";

            eh = FISCA.InteractionService.PublishEvent(EventCode);

            if (itemPanel1.SelectedItems.Count == 1)
            {
                string ref_exam_template_id = itemPanel1.SelectedItems[0].Tag + "";

                string course_ids = string.Join(",", _Course);

                List <CourseExtendRecord>            list = _A.Select <CourseExtendRecord>("ref_course_id in (" + course_ids + ")");
                Dictionary <int, CourseExtendRecord> dic  = new Dictionary <int, CourseExtendRecord>();
                foreach (CourseExtendRecord r in list)
                {
                    if (!dic.ContainsKey(r.Ref_course_id))
                    {
                        dic.Add(r.Ref_course_id, r);
                    }
                }

                List <CourseExtendRecord> insert = new List <CourseExtendRecord>();
                List <CourseExtendRecord> update = new List <CourseExtendRecord>();
                List <CourseExtendRecord> delete = new List <CourseExtendRecord>();
                foreach (string sid in _Course)
                {
                    int id = int.Parse(sid);
                    if (dic.ContainsKey(id))
                    {
                        if (ref_exam_template_id == "-1")
                        {
                            delete.Add(dic[id]);
                        }
                        else
                        {
                            //dic[id].Ref_exam_template_id = int.Parse(ref_exam_template_id);
                            update.Add(dic[id]);
                        }
                    }
                    else
                    {
                        if (ref_exam_template_id != "-1")
                        {
                            CourseExtendRecord record = new CourseExtendRecord();
                            record.Ref_course_id = id;
                            //record.Ref_exam_template_id = int.Parse(ref_exam_template_id);
                            insert.Add(record);
                        }
                    }
                }

                if (insert.Count > 0)
                {
                    _A.InsertValues(insert);
                }

                if (update.Count > 0)
                {
                    _A.UpdateValues(update);
                }

                if (delete.Count > 0)
                {
                    _A.DeletedValues(delete);
                }

                eh(null, EventArgs.Empty);

                this.Close();
            }
            else
            {
                MessageBox.Show("請選擇一個評分樣板");
            }
        }