internal ScoreCalcRuleRecordEditor(ScoreCalcRuleRecord record)
     : this()
 {
     ID            = record.ID;
     Name          = record.Name;
     Content       = record.Content;
     ScoreCalcRule = record;
 }
示例#2
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (SelectedItem == null)
            {
                return;
            }

            if (!_error.HasError)
            {
                ScoreCalcRuleRecord       record = SelectedItem.Tag as ScoreCalcRuleRecord;
                ScoreCalcRuleRecordEditor editor = record.GetEditor();
                editor.Content = GetContent();
                editor.Save();
            }
        }
示例#3
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            if (SelectedItem == null)
            {
                return;
            }

            if (MsgBox.Show("您確定要刪除「" + SelectedItem.Text + "」嗎?", MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                ScoreCalcRuleRecord       record = SelectedItem.Tag as ScoreCalcRuleRecord;
                ScoreCalcRuleRecordEditor editor = record.GetEditor();
                editor.Remove = true;
                editor.Save();
            }
        }
示例#4
0
        //private List<SemesterHistoryRecord> ReadSemesterHistory(List<string> studentIDs)
        //{
        //    FunctionSpliter<string, SemesterHistoryRecord> selectData = new FunctionSpliter<string, SemesterHistoryRecord>(500, Util.MaxThread);
        //    selectData.Function = delegate(List<string> p)
        //    {
        //        return K12.Data.SemesterHistory.SelectByStudentIDs(p);
        //    };
        //    return selectData.Execute(studentIDs);
        //}

        /// <summary>
        /// 進行畢業判斷
        /// </summary>
        /// <param name="students"></param>
        /// <returns></returns>
        public Dictionary <string, bool> Evaluate(IEnumerable <StudentRecord> students)
        {
            //每位學生過與不過
            Dictionary <string, bool> passList   = new Dictionary <string, bool>();
            List <EvaluationResult>   resultList = new List <EvaluationResult>();
            //鍵值為成績計算規則系統編號,值為這些成績計算規則的學生列表
            Dictionary <string, List <StudentRecord> > valid_students = new Dictionary <string, List <StudentRecord> >();

            //針對每位學生
            foreach (StudentRecord student in students)
            {
                //先假設學生通過
                passList.Add(student.ID, true);
                //取得學生成績計算規則
                ScoreCalcRuleRecord rule = student.GetScoreCalcRuleRecord();
                if (rule != null)
                {
                    if (!valid_students.ContainsKey(rule.ID))
                    {
                        valid_students.Add(rule.ID, new List <StudentRecord>());
                    }
                    valid_students[rule.ID].Add(student);
                }
            }

            //針對每項成績計算規則
            foreach (string rule_id in valid_students.Keys)
            {
                if (_evals.ContainsKey(rule_id))
                {
                    Dictionary <string, bool> evalPassList = _evals[rule_id].Evaluate(valid_students[rule_id]);
                    foreach (string id in evalPassList.Keys)
                    {
                        passList[id] = evalPassList[id];
                    }
                    resultList.Add(_evals[rule_id].Result);
                }
            }

            if (resultList.Count > 0)
            {
                MergeResults(passList, resultList);
            }
            return(passList);
        }
示例#5
0
        private void RefreshItemPanel(string id)
        {
            ScoreCalcRuleRecord record     = ScoreCalcRule.Instance.Items[id];
            ButtonItem          updateItem = null;

            foreach (ButtonItem item in itemPanel.Items)
            {
                ScoreCalcRuleRecord r = item.Tag as ScoreCalcRuleRecord;
                if (r.ID == id)
                {
                    updateItem = item;
                    break;
                }
            }

            if (record != null && updateItem == null) //Insert
            {
                ButtonItem item = new ButtonItem();
                item.Text        = record.Name;
                item.Tag         = record;
                item.OptionGroup = "ScoreCalcRule";
                item.Click      += new EventHandler(item_Click);
                itemPanel.Items.Add(item);
                item.RaiseClick();
            }
            else if (record != null && updateItem != null) //Update
            {
                updateItem.Tag = record;
                updateItem.RaiseClick();
            }
            else if (record == null && updateItem != null) //Delete
            {
                updateItem.Click -= new EventHandler(item_Click);
                itemPanel.Items.Remove(updateItem);
                SelectedItem       = null;
                CardPanelEnabled   = false;
                SaveButtonEnabled  = false;
                SaveWarningVisible = false;
                LabelNameText      = "";
            }

            itemPanel.Refresh();
            itemPanel.EnsureVisible(itemPanel.Items[itemPanel.Items.Count - 1]);
        }
示例#6
0
        /// <summary>
        /// 確認成績計算規則 是否有新設定 核可節次別 ( 2019/05/24 穎驊因應 [#6886][03] 國中畢業判斷,學生出缺部份母數會把不統計的節次類別計入。 項目與佳樺討論過後新增,)
        /// </summary>
        /// <param name="students"></param>
        /// <returns></returns>
        public List <StudentRecord> CheckScoreCaculatedRule(IEnumerable <StudentRecord> students)
        {
            List <StudentRecord> errorList = new List <StudentRecord>();

            foreach (StudentRecord student in students)
            {
                ScoreCalcRuleRecord rule = student.GetScoreCalcRuleRecord();
                if (rule != null)
                {
                    XmlElement xml          = (XmlElement)rule.Content.SelectSingleNode("畢業條件/日常生活表現畢業條件/條件[@Type='AbsenceAmountAllFraction']");
                    string     peroid_types = xml.GetAttribute("核可節次別");

                    if ("" + peroid_types == "")
                    {
                        errorList.Add(student);
                    }
                }
            }

            return(errorList);
        }
 public static ScoreCalcRuleRecordEditor GetEditor(this ScoreCalcRuleRecord record)
 {
     return(new ScoreCalcRuleRecordEditor(record));
 }
        public static void Calculate(List <StudentRecord> students)
        {
            const string LearnDomain = "學習領域";
            const string CourseLearn = "課程學習";

            ScoreCalcRule.Instance.SyncAllBackground();
            //SemesterScore.Instance.SyncAllBackground();
            Dictionary <string, List <JHSemesterScoreRecord> > studentSemesterScoreRecordCache = new Dictionary <string, List <JHSchool.Data.JHSemesterScoreRecord> >();

            foreach (JHSemesterScoreRecord record in JHSemesterScore.SelectByStudentIDs(students.AsKeyList()))
            {
                if (!studentSemesterScoreRecordCache.ContainsKey(record.RefStudentID))
                {
                    studentSemesterScoreRecordCache.Add(record.RefStudentID, new List <JHSchool.Data.JHSemesterScoreRecord>());
                }
                studentSemesterScoreRecordCache[record.RefStudentID].Add(record);
            }

            List <GradScoreRecordEditor> editors = new List <GradScoreRecordEditor>();

            BackgroundWorker worker = new BackgroundWorker();

            worker.WorkerReportsProgress = true;

            MultiThreadBackgroundWorker <GradScoreRecordEditor> multiWorker = new MultiThreadBackgroundWorker <GradScoreRecordEditor>();

            multiWorker.WorkerReportsProgress = true;
            multiWorker.AutoReportsProgress   = true;
            multiWorker.PackageSize           = 50;
            multiWorker.Loading = MultiThreadLoading.Light;

            worker.DoWork += delegate
            {
                Dictionary <string, ScoreCalculator> calc = new Dictionary <string, ScoreCalculator>();

                double studentTotal = students.Count;
                double studentCount = 0;

                foreach (StudentRecord student in students)
                {
                    studentCount++;

                    #region 取得成績計算規則
                    string calcID = string.Empty;
                    ScoreCalcRuleRecord calcRecord = student.GetScoreCalcRuleRecord();
                    if (calcRecord != null)
                    {
                        calcID = calcRecord.ID;
                        if (!calc.ContainsKey(calcID))
                        {
                            JHScoreCalcRuleRecord        record = null;
                            List <JHScoreCalcRuleRecord> list   = JHScoreCalcRule.SelectByIDs(new string[] { calcRecord.ID });
                            if (list.Count > 0)
                            {
                                record = list[0];
                            }
                            calc.Add(calcID, new ScoreCalculator(record));
                        }
                    }
                    else
                    {
                        if (!calc.ContainsKey(string.Empty))
                        {
                            calc.Add(string.Empty, new ScoreCalculator(null));
                        }
                    }
                    #endregion

                    #region 取得各學期成績
                    List <JHSemesterScoreRecord> semesterScoreRecordList;
                    if (studentSemesterScoreRecordCache.ContainsKey(student.ID))
                    {
                        semesterScoreRecordList = studentSemesterScoreRecordCache[student.ID];
                    }
                    else
                    {
                        semesterScoreRecordList = new List <JHSemesterScoreRecord>();
                    }
                    Dictionary <string, List <decimal> > domainScores = new Dictionary <string, List <decimal> >();

                    foreach (JHSemesterScoreRecord record in semesterScoreRecordList)
                    {
                        foreach (K12.Data.DomainScore domain in record.Domains.Values)
                        {
                            if (!domainScores.ContainsKey(domain.Domain))
                            {
                                domainScores.Add(domain.Domain, new List <decimal>());
                            }

                            if (domain.Score.HasValue)
                            {
                                domainScores[domain.Domain].Add(domain.Score.Value);
                            }
                        }

                        if (!domainScores.ContainsKey(LearnDomain))
                        {
                            domainScores.Add(LearnDomain, new List <decimal>());
                        }
                        if (record.LearnDomainScore.HasValue)
                        {
                            domainScores[LearnDomain].Add(record.LearnDomainScore.Value);
                        }

                        if (!domainScores.ContainsKey(CourseLearn))
                        {
                            domainScores.Add(CourseLearn, new List <decimal>());
                        }
                        if (record.CourseLearnScore.HasValue)
                        {
                            domainScores[CourseLearn].Add(record.CourseLearnScore.Value);
                        }
                    }
                    #endregion

                    #region 產生畢業成績資料
                    GradScoreRecordEditor editor;
                    GradScoreRecord       gradScoreRecord = GradScore.Instance.Items[student.ID];
                    if (gradScoreRecord != null)
                    {
                        editor = gradScoreRecord.GetEditor();
                    }
                    else
                    {
                        editor = new GradScoreRecordEditor(student);
                    }

                    editor.LearnDomainScore = null;
                    editor.CourseLearnScore = null;
                    editor.Domains.Clear();

                    foreach (string domain in domainScores.Keys)
                    {
                        decimal total = 0;
                        decimal count = domainScores[domain].Count;

                        if (count <= 0)
                        {
                            continue;
                        }

                        foreach (decimal score in domainScores[domain])
                        {
                            total += score;
                        }

                        total = total / count;
                        total = calc[calcID].ParseGraduateScore(total);


                        if (domain == LearnDomain)
                        {
                            editor.LearnDomainScore = total;
                        }
                        else if (domain == CourseLearn)
                        {
                            editor.CourseLearnScore = total;
                        }
                        else
                        {
                            if (!editor.Domains.ContainsKey(domain))
                            {
                                editor.Domains.Add(domain, new GradDomainScore(domain));
                            }
                            editor.Domains[domain].Score = total;
                        }
                    }

                    editors.Add(editor);
                    #endregion

                    worker.ReportProgress((int)(studentCount * 100 / studentTotal));
                }
            };
            worker.ProgressChanged += delegate(object sender, ProgressChangedEventArgs e)
            {
                FISCA.Presentation.MotherForm.SetStatusBarMessage("計算畢業成績中", e.ProgressPercentage);
            };
            worker.RunWorkerCompleted += delegate(object sender, RunWorkerCompletedEventArgs e)
            {
                if (e.Error != null)
                {
                    MsgBox.Show("計算畢業成績時發生錯誤。" + e.Error.Message);
                    editors.Clear();
                }
                else
                {
                    multiWorker.RunWorkerAsync(editors);
                }
            };

            multiWorker.DoWork += delegate(object sender, PackageDoWorkEventArgs <GradScoreRecordEditor> e)
            {
                IEnumerable <GradScoreRecordEditor> list = e.Items;
                list.SaveAllEditors();
            };
            multiWorker.ProgressChanged += delegate(object sender, ProgressChangedEventArgs e)
            {
                FISCA.Presentation.MotherForm.SetStatusBarMessage("上傳畢業成績中", e.ProgressPercentage);
            };
            multiWorker.RunWorkerCompleted += delegate(object sender, RunWorkerCompletedEventArgs e)
            {
                if (e.Error != null)
                {
                    MsgBox.Show("上傳畢業成績時發生錯誤。" + e.Error.Message);
                }
                else
                {
                    FISCA.Presentation.MotherForm.SetStatusBarMessage("上傳畢業成績完成");
                }
            };

            worker.RunWorkerAsync();
        }
        private void CalcWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            bool error = false;

            List <StudentRecord> students    = _students;
            List <string>        student_ids = new List <string>();

            foreach (StudentRecord each in students)
            {
                student_ids.Add(each.ID);
            }
            double total = students.Count;
            double count = 0;

            #region 寫入學期歷程
            if (_studentHistoryDict != null && _studentHistoryDict.Count > 0)
            {
                try
                {
                    List <JHSchool.Data.JHSemesterHistoryRecord> list = new List <JHSchool.Data.JHSemesterHistoryRecord>();
                    int    size   = 50;
                    double count2 = 0;
                    double total2 = _studentHistoryDict.Count;
                    foreach (JHSchool.Data.JHSemesterHistoryRecord record in _studentHistoryDict.Values)
                    {
                        if (_calc_worker.CancellationPending)
                        {
                            return;
                        }

                        list.Add(record);
                        count2++;
                        if (list.Count == size)
                        {
                            JHSchool.Data.JHSemesterHistory.Update(list);
                            list.Clear();
                            _calc_worker.ReportProgress((int)(count2 * 100 / total2), "寫入學期歷程中…");
                        }
                    }
                    if (list.Count > 0)
                    {
                        JHSchool.Data.JHSemesterHistory.Update(list);
                        list.Clear();
                        _calc_worker.ReportProgress(100, "學期歷程寫入完成");
                    }
                }
                catch (Exception ex)
                {
                    MsgBox.Show("寫入學期歷程失敗。" + ex.Message);
                    e.Result = null;
                    return;
                }
            }
            #endregion

            #region 計算課程成績

            _viewer.Clear();
            _viewer.SetHeader("課程");

            _calc_worker.ReportProgress(0, "計算課程成績…");

            if (_calc_worker.CancellationPending)
            {
                return;
            }
            _raw_data = new CourseDataLoader();
            _raw_data.LoadCalculationData(this, _students, intSchoolYear.Value, intSemester.Value);

            foreach (CW.Course course in _raw_data.Courses.Values)
            {
                if (string.IsNullOrEmpty(course.ExamTemplateId) && course.ExamRequired)
                {
                    _viewer.SetMessage(course.CourseName, new List <string>(new string[] { "缺少評量設定" }));
                    error = true;
                }
            }

            if (error)
            {
                e.Result = error;
                return;
            }

            _viewer.Clear();
            if (_calc_worker.CancellationPending)
            {
                return;
            }
            CourseScoreCalculate calculate = new CourseScoreCalculate(_raw_data.Courses);
            calculate.Calculate();

            foreach (CW.Course course in _raw_data.Courses.Values)
            {
                Dictionary <string, string> examLacks       = new Dictionary <string, string>();
                Dictionary <string, int>    examScoreLacks  = new Dictionary <string, int>();
                Dictionary <string, int>    examEffortLacks = new Dictionary <string, int>();

                List <CW.SCAttend> scattends         = new List <CW.SCAttend>();
                List <CW.SCAttend> no_exam_scattends = new List <CW.SCAttend>();
                foreach (CW.SCAttend scattend in course.SCAttends.Values)
                {
                    if (student_ids.Contains(scattend.StudentIdentity))
                    {
                        if (scattend.ContainsLack)
                        {
                            scattends.Add(scattend);
                        }
                        if (scattend.NoExam)
                        {
                            no_exam_scattends.Add(scattend);
                        }
                    }
                }

                foreach (CW.SCAttend scattend in scattends)
                {
                    foreach (string exam in scattend.ScoreLack)
                    {
                        if (!examLacks.ContainsKey(exam))
                        {
                            examLacks.Add(exam, "");
                        }

                        if (!examScoreLacks.ContainsKey(exam))
                        {
                            examScoreLacks.Add(exam, 0);
                        }
                        examScoreLacks[exam]++;
                    }

                    foreach (string exam in scattend.EffortLack)
                    {
                        if (!examLacks.ContainsKey(exam))
                        {
                            examLacks.Add(exam, "");
                        }

                        if (!examEffortLacks.ContainsKey(exam))
                        {
                            examEffortLacks.Add(exam, 0);
                        }
                        examEffortLacks[exam]++;
                    }
                }

                if (scattends.Count > 0)
                {
                    List <string> msgs = new List <string>();
                    foreach (string exam in new List <string>(examLacks.Keys))
                    {
                        if (examScoreLacks.ContainsKey(exam))
                        {
                            examLacks[exam] += "有" + examScoreLacks[exam] + "位學生缺少分數評量,";
                        }
                        if (examEffortLacks.ContainsKey(exam))
                        {
                            examLacks[exam] += "有" + examEffortLacks[exam] + "位學生缺少努力程度,";
                        }
                        if (!string.IsNullOrEmpty(examLacks[exam]))
                        {
                            examLacks[exam] = examLacks[exam].Substring(0, examLacks[exam].Length - 1);
                        }

                        msgs.Add(exam + ":" + examLacks[exam]);
                    }
                    _viewer.SetMessage(course.CourseName, msgs);
                    error = true;
                }

                if (no_exam_scattends.Count > 0)
                {
                    _viewer.SetMessage(course.CourseName, new List <string>(new string[] { "沒有設定各次評量" }));
                    error = true;
                }
            }

            if (error)
            {
                e.Result = true;
                return;
            }

            if (_calc_worker.CancellationPending)
            {
                return;
            }
            CourseScoreUpdater updater = new CourseScoreUpdater(_raw_data.Courses, this, false);
            updater.UpdateToServer();
            #endregion

            #region 計算學期成績

            //List<SemesterScoreRecordEditor> editors = new List<SemesterScoreRecordEditor>();
            List <JHSemesterScoreRecord> semesterScoreRecordList = new List <JHSchool.Data.JHSemesterScoreRecord>();

            JHSchool.Evaluation.SCAttend.Instance.SyncAllBackground();

            Dictionary <string, List <JHSemesterScoreRecord> > studentSemesterScoreCache = new Dictionary <string, List <JHSchool.Data.JHSemesterScoreRecord> >();
            foreach (JHSemesterScoreRecord record in JHSemesterScore.SelectByStudentIDs(students.AsKeyList()))
            {
                if (!studentSemesterScoreCache.ContainsKey(record.RefStudentID))
                {
                    studentSemesterScoreCache.Add(record.RefStudentID, new List <JHSchool.Data.JHSemesterScoreRecord>());
                }
                studentSemesterScoreCache[record.RefStudentID].Add(record);
            }

            count = 0;
            foreach (StudentRecord each in students)
            {
                count++;

                ScoreCalcRuleRecord   old       = GetScoreCalcRuleRecord(each);
                JHScoreCalcRuleRecord dalrecord = null;
                if (old != null)
                {
                    List <JHScoreCalcRuleRecord> list = JHScoreCalcRule.SelectByIDs(new string[] { old.ID });
                    if (list.Count > 0)
                    {
                        dalrecord = list[0];
                    }
                }
                ScoreCalculator calculator = new ScoreCalculator(dalrecord);

                List <SCAttendRecord> scattends = new List <SCAttendRecord>();
                foreach (SCAttendRecord scattend in JHSchool.Evaluation.SCAttend.Instance.GetStudentAttend(each.ID))
                {
                    CourseRecord course = scattend.Course;
                    if (course.SchoolYear == intSchoolYear.Value &&
                        course.Semester == intSemester.Value &&
                        !string.IsNullOrEmpty(course.RefAssessmentSetupID) &&
                        course.CalculationFlag == "1"
                        )
                    {
                        scattends.Add(scattend);
                    }
                }

                if (scattends.Count > 0)
                {
                    List <K12.Data.SubjectScore> subjectScores = _inner_calculator.CalculateSubjectScore(scattends);
                    foreach (K12.Data.SubjectScore subject in subjectScores)
                    {
                        subject.Score = calculator.ParseSubjectScore((decimal)subject.Score);
                    }
                    List <K12.Data.DomainScore> domainScores = _inner_calculator.CalculateDomainScore(subjectScores);
                    foreach (K12.Data.DomainScore domain in domainScores)
                    {
                        domain.Score = calculator.ParseDomainScore((decimal)domain.Score);
                    }

                    List <K12.Data.DomainScore> domainListWithoutElastic = new List <K12.Data.DomainScore>();
                    bool hasElasticCourse = false;
                    foreach (K12.Data.DomainScore domain in domainScores)
                    {
                        if (domain.Domain == "彈性課程")
                        {
                            hasElasticCourse = true;
                        }
                        else
                        {
                            domainListWithoutElastic.Add(domain);
                        }
                    }

                    decimal?learnDomainScore = calculator.ParseLearnDomainScore(_inner_calculator.CalculateTotalDomainScore(domainListWithoutElastic));
                    decimal?courseLearnScore = null;
                    if (hasElasticCourse)
                    {
                        courseLearnScore = calculator.ParseLearnDomainScore(_inner_calculator.CalculateTotalDomainScore(domainScores));
                    }

                    JHSemesterScoreRecord current = null;
                    if (studentSemesterScoreCache.ContainsKey(each.ID))
                    {
                        foreach (JHSemesterScoreRecord record in studentSemesterScoreCache[each.ID])
                        {
                            if (record.SchoolYear == intSchoolYear.Value && record.Semester == intSemester.Value)
                            {
                                current = record;
                            }
                        }
                    }

                    if (current != null)
                    {
                        //editor = current.GetEditor();
                        current.Subjects = new Dictionary <string, K12.Data.SubjectScore>();
                        current.Domains  = new Dictionary <string, K12.Data.DomainScore>();
                    }
                    else
                    {
                        //current = new SemesterScoreRecordEditor(each, intSchoolYear.Value, intSemester.Value, _gradeYears[each.ID]);
                        current = new JHSchool.Data.JHSemesterScoreRecord();
                        current.RefStudentID = each.ID;
                        current.SchoolYear   = intSchoolYear.Value;
                        current.Semester     = intSemester.Value;
                    }

                    foreach (K12.Data.SubjectScore subject in subjectScores)
                    {
                        current.Subjects.Add(subject.Subject, subject);
                    }
                    foreach (K12.Data.DomainScore domain in domainScores)
                    {
                        current.Domains.Add(domain.Domain, domain);
                    }
                    current.LearnDomainScore = learnDomainScore;
                    current.CourseLearnScore = courseLearnScore;

                    //editors.Add(editor);
                    semesterScoreRecordList.Add(current);
                }

                _calc_worker.ReportProgress((int)((double)count * 100 / (double)total), "計算學期成績…");
            }

            e.Result = semesterScoreRecordList;
            #endregion
        }