예제 #1
0
        /// <summary>
        /// 初始化 BackgroundWorker
        /// </summary>
        private void InitializeWorker()
        {
            _worker = new BackgroundWorker();
            _worker.WorkerReportsProgress = true;
            _worker.DoWork += new DoWorkEventHandler(Worker_DoWork);

            _worker.ProgressChanged += delegate(object sender, ProgressChangedEventArgs e)
            {
                MotherForm.SetStatusBarMessage("" + e.UserState, e.ProgressPercentage);
            };

            _worker.RunWorkerCompleted += delegate(object sender, RunWorkerCompletedEventArgs e)
            {
                if (e.Result is List <string> )
                {
                    ErrorViewer viewer = new ErrorViewer();
                    viewer.SetHeader("班級");
                    foreach (string msg in e.Result as List <string> )
                    {
                        string className = msg.Split(new string[] { ":" }, StringSplitOptions.None)[0];
                        string errMsg    = msg.Split(new string[] { ":" }, StringSplitOptions.None)[1];
                        viewer.SetMessage(className, new List <string>(new string[] { errMsg }));
                    }
                    viewer.Show();
                }
                else
                {
                    MotherForm.SetStatusBarMessage("班級開課完成");
                }
            };
        }
 void bkw_ProgressChanged(object sender, ProgressChangedEventArgs e)
 {
     if (!((BackgroundWorker)sender).CancellationPending)
     {
         if (e.UserState != null)
         {
             Dictionary <StudentRecord, List <string> > errormessages = (Dictionary <StudentRecord, List <string> >)e.UserState;
             if (errormessages.Count > 0)
             {
                 foreach (StudentRecord stu in errormessages.Keys)
                 {
                     _ErrorViewer.SetMessage(stu, errormessages[stu]);
                 }
                 // 2018/5/24 穎驊完成項目調整 [H成績][02] 修正計算學期科目成績資料錯誤提醒,
                 // 統一將提醒錯誤視窗在bkw_RunWorkerCompleted 後才呈現,本來在背景執行序就不應該動到UI
                 //_ErrorViewer.Show();
             }
         }
         this.progressBarX1.Value = e.ProgressPercentage;
     }
 }
예제 #3
0
        private void HistoryWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            //progressBar.Value = 100;

            if (e.Error != null)
            {
                SmartSchool.ErrorReporting.ReportingService.ReportException(e.Error);
                MsgBox.Show("檢查學期歷程時發生錯誤。" + e.Error.Message);
                return;
            }

            if (_errorList.Count > 0)
            {
                btnExit.Enabled = true;

                ErrorViewer viewer = new ErrorViewer();
                viewer.SetHeader("學生");
                foreach (StudentRecord student in _errorList)
                {
                    viewer.SetMessage(student, new List <string>(new string[] { "學期歷程不完整" }));
                }
                viewer.ShowDialog();
                return;
            }
            else
            {
                // 加入這段主要在處理當學期還沒有產生學期歷程,資料可以判斷
                UIConfig._StudentSHistoryRecDict.Clear();
                Dictionary <string, int> studGradeYearDict = new Dictionary <string, int>();

                // 取得學生ID
                List <string> studIDs = (from data in _students select data.ID).Distinct().ToList();

                foreach (JHStudentRecord stud in JHStudent.SelectByIDs(studIDs))
                {
                    if (stud.Class != null)
                    {
                        if (stud.Class.GradeYear.HasValue)
                        {
                            if (!studGradeYearDict.ContainsKey(stud.ID))
                            {
                                studGradeYearDict.Add(stud.ID, stud.Class.GradeYear.Value);
                            }
                        }
                    }
                }
                bool checkInsShi = false;
                // 取得學生學期歷程,並加入學生學習歷程Cache
                foreach (JHSemesterHistoryRecord rec in JHSemesterHistory.SelectByStudentIDs(studIDs))
                {
                    checkInsShi = true;
                    K12.Data.SemesterHistoryItem shi = new K12.Data.SemesterHistoryItem();
                    shi.SchoolYear = UIConfig._UserSetSHSchoolYear;
                    shi.Semester   = UIConfig._UserSetSHSemester;
                    if (studGradeYearDict.ContainsKey(rec.RefStudentID))
                    {
                        shi.GradeYear = studGradeYearDict[rec.RefStudentID];
                    }

                    foreach (K12.Data.SemesterHistoryItem shiItem in rec.SemesterHistoryItems)
                    {
                        if (shiItem.SchoolYear == shi.SchoolYear && shiItem.Semester == shi.Semester)
                        {
                            checkInsShi = false;
                        }
                    }
                    if (checkInsShi)
                    {
                        rec.SemesterHistoryItems.Add(shi);
                    }

                    if (!UIConfig._StudentSHistoryRecDict.ContainsKey(rec.RefStudentID))
                    {
                        UIConfig._StudentSHistoryRecDict.Add(rec.RefStudentID, rec);
                    }
                }

                //lblProgress.Text = "畢業資格審查中…";
                FISCA.LogAgent.ApplicationLog.Log("成績系統.報表", "列印畢業預警報表", "產生畢業預警報表");

                _inspectWorker.RunWorkerAsync(_students, new object[] { _passList, _result });
            }
        }
        private void History_worker_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);
            }
            int total = students.Count;
            int count = 0;

            #region 檢查學期歷程
            _viewer.Clear();
            _viewer.SetHeader("學生");

            Dictionary <string, JHSchool.Data.JHSemesterHistoryRecord> studentHistories = new Dictionary <string, JHSchool.Data.JHSemesterHistoryRecord>();
            foreach (JHSchool.Data.JHSemesterHistoryRecord record in JHSchool.Data.JHSemesterHistory.SelectByStudentIDs(student_ids))
            {
                if (!studentHistories.ContainsKey(record.RefStudentID))
                {
                    studentHistories.Add(record.RefStudentID, record);
                }
            }

            _studentHistoryDict = new Dictionary <string, JHSchool.Data.JHSemesterHistoryRecord>();
            //SemesterHistory.Instance.SyncDataBackground(student_ids);
            //_studentHistoryEditors = new Dictionary<string, SemesterHistoryRecordEditor>();

            _gradeYears = new Dictionary <string, int>();

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

                bool hasSemesterHistory = false;
                foreach (K12.Data.SemesterHistoryItem item in studentHistories[each.ID].SemesterHistoryItems)
                {
                    if (item.SchoolYear == intSchoolYear.Value && item.Semester == intSemester.Value)
                    {
                        if (!_gradeYears.ContainsKey(each.ID))
                        {
                            _gradeYears.Add(each.ID, item.GradeYear);
                        }

                        if (_type.Equals("EduAdmin"))
                        {
                            item.ClassName = (each.Class != null) ? each.Class.Name : "";
                            int i;
                            item.SeatNo         = int.TryParse(each.SeatNo, out i) ? (int?)i : null;
                            item.Teacher        = (each.Class != null) ? ((each.Class.Teacher != null) ? each.Class.Teacher.Name : "") : "";
                            item.SchoolDayCount = (_schoolDayMapping.ContainsKey(item.GradeYear)) ? (int?)_schoolDayMapping[item.GradeYear] : null;
                            if (!_studentHistoryDict.ContainsKey(each.ID))
                            {
                                _studentHistoryDict.Add(each.ID, studentHistories[each.ID]);
                            }
                        }

                        hasSemesterHistory = true;
                        break;
                    }
                }

                if (!hasSemesterHistory)
                {
                    if (_type.Equals("EduAdmin"))
                    {
                        K12.Data.SemesterHistoryItem item = new K12.Data.SemesterHistoryItem();
                        item.SchoolYear = intSchoolYear.Value;
                        item.Semester   = intSemester.Value;
                        item.GradeYear  = intGradeYear.Value;
                        item.ClassName  = (each.Class != null) ? each.Class.Name : "";
                        int i;
                        item.SeatNo         = int.TryParse(each.SeatNo, out i) ? (int?)i : null;
                        item.Teacher        = (each.Class != null) ? ((each.Class.Teacher != null) ? each.Class.Teacher.Name : "") : "";
                        item.SchoolDayCount = (_schoolDayMapping.ContainsKey(item.GradeYear)) ? (int?)_schoolDayMapping[item.GradeYear] : null;
                        studentHistories[each.ID].SemesterHistoryItems.Add(item);
                        if (!_studentHistoryDict.ContainsKey(each.ID))
                        {
                            _studentHistoryDict.Add(each.ID, studentHistories[each.ID]);
                        }
                    }
                    error = true;
                    _viewer.SetMessage(each, new List <string>(new string[] { "缺少學期歷程資訊" }));
                }

                _history_worker.ReportProgress((int)((double)count * 100 / (double)total), "檢查學期歷程中…");
            }

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

            #endregion

            e.Result = "OK";
        }