Ejemplo n.º 1
0
        private void ProcessDomain(Dictionary <string, DomainScoreCalculator> domainscores,
                                   JHSCETakeRecord take,
                                   JHCourseRecord course,
                                   RatingStudent student,
                                   ScoreItem subject,
                                   ScoreItem domain)
        {
            if (!course.Credit.HasValue)
            {
                return;                          //如果課程沒有權重就不處理。
            }
            decimal weight = course.Credit.Value;

            if (!SelectedItems.Contains(domain))
            {
                return; //不在處理的領域清單中。
            }
            if (!domainscores.ContainsKey(student.Id))
            {
                domainscores.Add(student.Id, new DomainScoreCalculator());
            }

            if (domainscores[student.Id].Contains(subject.Name))
            {
                throw new ArgumentException(string.Format("學生「{0}」在同一學期修習「{1}」科目一次以上。", student.Name, subject.Name));
            }

            domainscores[student.Id].Add(domain.Name, subject.Name, take.Score.Value, weight);
        }
Ejemplo n.º 2
0
 public void AddScore(JHSCETakeRecord score)
 {
     if (!Rows.ContainsKey(score.RefStudentID))
     {
         Rows.Add(score.RefStudentID, new StudentRow(_StudentScoreDict[score.RefStudentID]));
     }
     Rows[score.RefStudentID].AddRawScore(score);
 }
Ejemplo n.º 3
0
        public void Add(JHSCETakeRecord score)
        {
            string subject = JHCourse.SelectByID(score.RefCourseID).Subject;

            if (!Scores.ContainsKey(subject))
            {
                Scores.Add(subject, score);
            }
        }
Ejemplo n.º 4
0
        public SCETakeRecord(JHSCETakeRecord record)
        {
            _record = record;

            //try to read score
            XmlElement root  = _record.ToXML();
            XmlNode    node1 = root.SelectSingleNode("Extension/Extension/Score");
            XmlNode    node2 = root.SelectSingleNode("Extension/Extension/AssignmentScore");

            _examScore    = node1 == null ? string.Empty : node1.InnerText;
            _regularScore = node2 == null ? string.Empty : node2.InnerText;
        }
Ejemplo n.º 5
0
        private void ProcessSubject(ScoreItem subject, RatingStudent student, JHSCETakeRecord take)
        {
            ScoreCollection subjScores = student.Scores[subject.Regulation(Token)];

            if (!SelectedItems.Contains(subject))
            {
                return; //不在處理的科目清單中。
            }
            if (subjScores.Contains(subject.Name))
            {
                throw new ArgumentException(string.Format("學生「{0}」在同一學期修習「{1}」科目一次以上。", student.Name, subject.Name));
            }

            //take.Score  一定有值,因為在很前面就處理掉了。
            subjScores.Add(subject.Name, take.Score.Value);
        }
Ejemplo n.º 6
0
        /*
         * JHSCETakeRecord
         * <Extension>
         *      <Effort>0</Effort>
         *      <Text/>
         *      <Score>56</Score>
         *      <AssignmentScore>56</AssignmentScore>
         * </Extension>
         */

        /*
         * JHAEIncludeRecord
         * <Extension>
         *      <UseScore>是</UseScore>
         *      <UseEffort>否</UseEffort>
         *      <UseText>否</UseText>
         *      <UseAssignmentScore>是</UseAssignmentScore>
         * </Extension>
         */

        public TakeScore(JHSCETakeRecord sceTake, AEIncludeData include)
        {
            SCETakeData   scedata = new SCETakeData(sceTake);
            AEIncludeData aedata  = include; //為了效率...

            Text   = scedata.Text;
            Effort = null;
            Value  = null;
            Weight = include.Weight;

            if (Program.Mode == ModuleMode.KaoHsiung)
            {
                if (aedata.UseScore)
                {
                    Value = scedata.Score;
                }
                if (aedata.UseEffort)
                {
                    Effort = scedata.Effort;
                }
            }
            else if (Program.Mode == ModuleMode.HsinChu)
            {
                decimal sum = 0, weight = 0;

                if (aedata.UseScore && scedata.Score.HasValue)
                {
                    sum += scedata.Score.Value;
                    weight++;
                }

                if (aedata.UseAssignmentScore && scedata.AssignmentScore.HasValue)
                {
                    sum += scedata.AssignmentScore.Value;
                    weight++;
                }

                if (weight > 0)
                {
                    Value = (sum / weight);
                }
            }
            else
            {
                throw new ArgumentException(string.Format("沒有此種縣市的處理方式({0})。", Program.Mode.ToString()));
            }
        }
Ejemplo n.º 7
0
        public SCETakeData(JHSCETakeRecord record)
        {
            Origin = record;

            XmlElement xmlrecord = record.ToXML();

            #region 嘗試取得 AssignmentScore
            XmlNode assignment = xmlrecord.SelectSingleNode("Extension/Extension/AssignmentScore");
            if (assignment != null)
            {
                AssignmentScore = ParseDecimalAllowNull(assignment.InnerText);
            }
            #endregion

            #region 嘗試取得 Effort
            XmlNode effort = xmlrecord.SelectSingleNode("Extension/Extension/Effort");
            if (effort != null)
            {
                Effort = (int?)ParseDecimalAllowNull(effort.InnerText);
            }
            #endregion
        }
Ejemplo n.º 8
0
 public void AddRawScore(JHSCETakeRecord score)
 {
     RawScoreList.Add(new HC.JHSCETakeRecord(score));
 }
Ejemplo n.º 9
0
        /*
         * JHSCETakeRecord
         * <Extension>
         *      <Effort>0</Effort>
         *      <Text/>
         *      <Score>56</Score>
         *      <AssignmentScore>56</AssignmentScore>
         * </Extension>
         */

        /*
         * JHAEIncludeRecord
         * <Extension>
         *      <UseScore>是</UseScore>
         *      <UseEffort>否</UseEffort>
         *      <UseText>否</UseText>
         *      <UseAssignmentScore>是</UseAssignmentScore>
         * </Extension>
         */

        public TakeScore(JHSCETakeRecord sceTake, AEIncludeData include)
        {
            SCETakeData   scedata = new SCETakeData(sceTake);
            AEIncludeData aedata  = include; //為了效率...

            Text   = scedata.Text;
            Effort = null;
            Value  = null;
            Weight = include.Weight;

            if (Program.Mode == ModuleMode.KaoHsiung)
            {
                if (aedata.UseScore)
                {
                    Value = scedata.Score;
                }
                if (aedata.UseEffort)
                {
                    Effort = scedata.Effort;
                }
            }
            else if (Program.Mode == ModuleMode.HsinChu)
            {
                // 預設取得比例
                decimal scoreWeight = 0, assignmentWeight = 0, totalWeight = 0;
                decimal?totalScore = null;

                // 使用系統內預設比例
                if (Util.ScorePercentageHSDict.ContainsKey(aedata.RefAssessmentSetupID))
                {
                    scoreWeight      = Util.ScorePercentageHSDict[aedata.RefAssessmentSetupID];
                    assignmentWeight = 100 - scoreWeight;
                }
                if (aedata.UseScore && !aedata.UseAssignmentScore)
                {
                    scoreWeight      = 100;
                    assignmentWeight = 0;
                }
                if (!aedata.UseScore && aedata.UseAssignmentScore)
                {
                    scoreWeight      = 0;
                    assignmentWeight = 100;
                }
                if (!aedata.UseScore && !aedata.UseAssignmentScore)
                {
                    scoreWeight      = 0;
                    assignmentWeight = 0;
                }
                if (scedata.Score.HasValue && Program.ScoreValueMap.ContainsKey(scedata.Score.Value))
                {
                    if (!Program.ScoreValueMap[scedata.Score.Value].AllowCalculation)
                    {
                        scoreWeight      = 0;
                        assignmentWeight = 100;
                    }
                }
                if (scedata.AssignmentScore.HasValue && Program.ScoreValueMap.ContainsKey(scedata.AssignmentScore.Value))
                {
                    if (!Program.ScoreValueMap[scedata.AssignmentScore.Value].AllowCalculation)
                    {
                        scoreWeight      = 100;
                        assignmentWeight = 0;
                    }
                }
                if (scoreWeight > 0 && scedata.Score.HasValue)
                {
                    if (Program.ScoreValueMap.ContainsKey(scedata.Score.Value))
                    {
                        if (Program.ScoreValueMap[scedata.Score.Value].AllowCalculation)
                        {
                            totalScore   = (totalScore == null ? 0 : totalScore) + Program.ScoreValueMap[scedata.Score.Value].Score.Value * scoreWeight;
                            totalWeight += scoreWeight;
                        }
                    }
                    else
                    {
                        totalScore   = (totalScore == null ? 0 : totalScore) + scedata.Score.Value * scoreWeight;
                        totalWeight += scoreWeight;
                    }
                }
                if (assignmentWeight > 0 && scedata.AssignmentScore.HasValue)
                {
                    if (Program.ScoreValueMap.ContainsKey(scedata.AssignmentScore.Value))
                    {
                        if (Program.ScoreValueMap[scedata.AssignmentScore.Value].AllowCalculation)
                        {
                            totalScore   = (totalScore == null ? 0 : totalScore) + Program.ScoreValueMap[scedata.AssignmentScore.Value].Score.Value * assignmentWeight;
                            totalWeight += assignmentWeight;
                        }
                    }
                    else
                    {
                        totalScore   = (totalScore == null ? 0 : totalScore) + scedata.AssignmentScore.Value * assignmentWeight;
                        totalWeight += assignmentWeight;
                    }
                }

                //if (aedata.UseScore && scedata.Score.HasValue)
                //{
                //    totalScore += scedata.Score.Value * scoreWeight;
                //    totalWeight += scoreWeight;
                //}

                //if (aedata.UseAssignmentScore && scedata.AssignmentScore.HasValue)
                //{
                //    totalScore += scedata.AssignmentScore.Value * assignmentWeight;
                //    totalWeight += assignmentWeight;
                //}

                if (totalWeight != 0)
                {
                    Value = totalScore / totalWeight;
                }
                else
                {
                    Value = null;
                }

                //// 原本作法
                //decimal sum = 0, weight = 0;

                //if (aedata.UseScore && scedata.Score.HasValue)
                //{
                //    sum += scedata.Score.Value;
                //    weight++;
                //}

                //if (aedata.UseAssignmentScore && scedata.AssignmentScore.HasValue)
                //{
                //    sum += scedata.AssignmentScore.Value;
                //    weight++;
                //}

                //if (weight > 0)
                //    Value = (sum / weight);
            }
            else
            {
                throw new ArgumentException(string.Format("沒有此種縣市的處理方式({0})。", Program.Mode.ToString()));
            }
        }
Ejemplo n.º 10
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            dgv.EndEdit();

            if (!IsValid())
            {
                return;
            }

            try
            {
                List <HC.JHSCETakeRecord> sceUpdateList = new List <HC.JHSCETakeRecord>();
                List <HC.JHSCETakeRecord> sceInsertList = new List <HC.JHSCETakeRecord>();
                List <HC.JHSCETakeRecord> sceDeleteList = new List <HC.JHSCETakeRecord>();

                bool scattendNeedSave = false;

                foreach (DataGridViewRow row in dgv.Rows)
                {
                    if (row.IsNewRow)
                    {
                        continue;
                    }

                    if ("" + row.Tag == "課程總成績")
                    {
                        #region 課程總成績
                        if ("" + row.Cells[chScore.Index].Value != "" + _scattend.Score)
                        {
                            scattendNeedSave = true;
                            decimal d;
                            if (decimal.TryParse("" + row.Cells[chScore.Index].Value, out d))
                            {
                                _scattend.Score = d;
                            }
                            else
                            {
                                _scattend.Score = null;
                            }
                        }
                        //if ("" + row.Cells[chAssignmentScore.Index].Value != "" + _scattend.Effort)
                        //{
                        //    scattendNeedSave = true;
                        //    int i;
                        //    if (int.TryParse("" + row.Cells[chScore.Index].Value, out i))
                        //        _scattend.Score = i;
                        //    else
                        //        _scattend.Score = null;
                        //}
                        if ("" + row.Cells[chText.Index].Value != _scattend.Text)
                        {
                            scattendNeedSave = true;
                            _scattend.Text   = "" + row.Cells[chText.Index].Value;
                        }
                        #endregion
                    }
                    else if (row.Tag != null)
                    {
                        #region  評量成績記錄的情況
                        HC.JHSCETakeRecord sce = row.Tag as HC.JHSCETakeRecord;

                        if (!string.IsNullOrEmpty("" + row.Cells[chScore.Index].Value))
                        {
                            sce.Score = decimal.Parse("" + row.Cells[chScore.Index].Value);
                        }
                        else
                        {
                            sce.Score = null;
                        }

                        if (!string.IsNullOrEmpty("" + row.Cells[chAssignmentScore.Index].Value))
                        {
                            sce.AssignmentScore = decimal.Parse("" + row.Cells[chAssignmentScore.Index].Value);
                        }
                        else
                        {
                            sce.AssignmentScore = null;
                        }

                        sce.Text = "" + row.Cells[chText.Index].Value;

                        if (!sce.Score.HasValue && !sce.AssignmentScore.HasValue && string.IsNullOrEmpty(sce.Text))
                        {
                            sceDeleteList.Add(sce);
                        }
                        else
                        {
                            sceUpdateList.Add(sce);
                        }
                        #endregion
                    }
                    else
                    {
                        #region 無評量成績記錄的情況
                        bool needsave = false;
                        if (!string.IsNullOrEmpty("" + row.Cells[chScore.Index].Value))
                        {
                            needsave = true;
                        }
                        if (!string.IsNullOrEmpty("" + row.Cells[chAssignmentScore.Index].Value))
                        {
                            needsave = true;
                        }
                        if (!string.IsNullOrEmpty("" + row.Cells[chText.Index].Value))
                        {
                            needsave = true;
                        }
                        if (needsave)
                        {
                            JHSCETakeRecord    jh  = new JHSCETakeRecord();
                            HC.JHSCETakeRecord sce = new HC.JHSCETakeRecord(jh);
                            sce.RefCourseID   = _course.ID;
                            sce.RefExamID     = "" + row.Cells[chExamName.Index].Tag;
                            sce.RefSCAttendID = _scattend != null ? _scattend.ID : "";
                            sce.RefStudentID  = _student.ID;
                            if (!string.IsNullOrEmpty("" + row.Cells[chScore.Index].Value))
                            {
                                sce.Score = decimal.Parse("" + row.Cells[chScore.Index].Value);
                            }
                            else
                            {
                                sce.Score = null;
                            }

                            if (!string.IsNullOrEmpty("" + row.Cells[chAssignmentScore.Index].Value))
                            {
                                sce.AssignmentScore = decimal.Parse("" + row.Cells[chAssignmentScore.Index].Value);
                            }
                            else
                            {
                                sce.AssignmentScore = null;
                            }

                            sce.Text = "" + row.Cells[chText.Index].Value;
                            sceInsertList.Add(sce);
                        }
                        #endregion
                    }
                }

                if (sceUpdateList.Count > 0)
                {
                    JHSCETake.Update(sceUpdateList.AsJHSCETakeRecords());
                }
                if (sceInsertList.Count > 0)
                {
                    JHSCETake.Insert(sceInsertList.AsJHSCETakeRecords());
                }
                if (sceDeleteList.Count > 0)
                {
                    JHSCETake.Delete(sceDeleteList.AsJHSCETakeRecords());
                }

                if (scattendNeedSave)
                {
                    JHSCAttend.Update(_scattend);
                }

                // log 處理
                SetSaveDataToLog();
                prlp.SetActionBy("學生", "評量成績輸入");
                prlp.SetAction("評量成績輸入");
                prlp.SetDescTitle("");
                prlp.SaveLog("", "", "Student", _student.ID);
                SetLoadDataToLog();
                this.DialogResult = DialogResult.OK;
                this.Close();
            }
            catch (Exception ex)
            {
                MsgBox.Show("儲存失敗。" + ex.Message);
            }
        }
Ejemplo n.º 11
0
        public ImportStartupForm()
        {
            InitializeComponent();
            InitializeSemesters();

            _effortMapper = new EffortMapper();

            // 載入預設儲存值
            LoadConfigData();

            _worker = new BackgroundWorker();
            _worker.WorkerReportsProgress = true;
            _worker.ProgressChanged      += delegate(object sender, ProgressChangedEventArgs e)
            {
                lblMessage.Text = "" + e.UserState;
            };
            _worker.DoWork += delegate(object sender, DoWorkEventArgs e)
            {
                #region Worker DoWork
                _worker.ReportProgress(0, "檢查讀卡文字格式…");

                #region 檢查文字檔
                ValidateTextFiles  vtf      = new ValidateTextFiles(intStudentNumberLenght.Value);
                ValidateTextResult vtResult = vtf.CheckFormat(_files);
                if (vtResult.Error)
                {
                    e.Result = vtResult;
                    return;
                }
                #endregion

                //文字檔轉 RawData
                RawDataCollection rdCollection = new RawDataCollection();
                rdCollection.ConvertFromFiles(_files);

                //RawData 轉 DataRecord
                DataRecordCollection drCollection = new DataRecordCollection();
                drCollection.ConvertFromRawData(rdCollection);

                _rawDataValidator    = new DataValidator <RawData>();
                _dataRecordValidator = new DataValidator <DataRecord>();

                #region 取得驗證需要的資料
                JHCourse.RemoveAll();
                _worker.ReportProgress(0, "取得學生資料…");
                List <JHStudentRecord> studentList = GetInSchoolStudents();

                List <string> s_ids = new List <string>();
                Dictionary <string, List <string> > studentNumberToStudentIDs = new Dictionary <string, List <string> >();
                foreach (JHStudentRecord student in studentList)
                {
                    string sn = SCValidatorCreator.GetStudentNumberFormat(student.StudentNumber);
                    if (!studentNumberToStudentIDs.ContainsKey(sn))
                    {
                        studentNumberToStudentIDs.Add(sn, new List <string>());
                    }
                    studentNumberToStudentIDs[sn].Add(student.ID);
                }
                foreach (var dr in drCollection)
                {
                    if (studentNumberToStudentIDs.ContainsKey(dr.StudentNumber))
                    {
                        s_ids.AddRange(studentNumberToStudentIDs[dr.StudentNumber]);
                    }
                }

                studentList.Clear();

                _worker.ReportProgress(0, "取得課程資料…");
                List <JHCourseRecord>    courseList = JHCourse.SelectBySchoolYearAndSemester(SchoolYear, Semester);
                List <JHAEIncludeRecord> aeList     = JHAEInclude.SelectAll();

                //List<JHSCAttendRecord> scaList = JHSCAttend.SelectAll();
                var c_ids = from course in courseList select course.ID;
                _worker.ReportProgress(0, "取得修課資料…");
                //List<JHSCAttendRecord> scaList2 = JHSCAttend.SelectByStudentIDAndCourseID(s_ids, c_ids.ToList<string>());
                List <JHSCAttendRecord> scaList = new List <JHSCAttendRecord>();
                FunctionSpliter <string, JHSCAttendRecord> spliter = new FunctionSpliter <string, JHSCAttendRecord>(300, 3);
                spliter.Function = delegate(List <string> part)
                {
                    return(JHSCAttend.Select(part, c_ids.ToList <string>(), null, SchoolYear.ToString(), Semester.ToString()));
                };
                scaList = spliter.Execute(s_ids);

                _worker.ReportProgress(0, "取得試別資料…");
                List <JHExamRecord> examList = JHExam.SelectAll();
                #endregion

                #region 註冊驗證
                _worker.ReportProgress(0, "載入驗證規則…");
                _rawDataValidator.Register(new SubjectCodeValidator());
                _rawDataValidator.Register(new ClassCodeValidator());
                _rawDataValidator.Register(new ExamCodeValidator());

                SCValidatorCreator scCreator = new SCValidatorCreator(JHStudent.SelectByIDs(s_ids), courseList, scaList);
                _dataRecordValidator.Register(scCreator.CreateStudentValidator());
                _dataRecordValidator.Register(new ExamValidator(examList));
                _dataRecordValidator.Register(scCreator.CreateSCAttendValidator());
                _dataRecordValidator.Register(new CourseExamValidator(scCreator.StudentCourseInfo, aeList, examList));
                #endregion

                #region 進行驗證
                _worker.ReportProgress(0, "進行驗證中…");
                List <string> msgList = new List <string>();

                foreach (RawData rawData in rdCollection)
                {
                    List <string> msgs = _rawDataValidator.Validate(rawData);
                    msgList.AddRange(msgs);
                }
                if (msgList.Count > 0)
                {
                    e.Result = msgList;
                    return;
                }

                foreach (DataRecord dataRecord in drCollection)
                {
                    List <string> msgs = _dataRecordValidator.Validate(dataRecord);
                    msgList.AddRange(msgs);
                }
                if (msgList.Count > 0)
                {
                    e.Result = msgList;
                    return;
                }
                #endregion

                #region 取得學生的評量成績
                _deleteScoreList.Clear();
                _addScoreList.Clear();

                //var student_ids = from student in scCreator.StudentNumberDictionary.Values select student.ID;
                //List<string> course_ids = scCreator.AttendCourseIDs;

                var scaIDs = from sca in scaList select sca.ID;

                Dictionary <string, JHSCETakeRecord>      sceList    = new Dictionary <string, JHSCETakeRecord>();
                FunctionSpliter <string, JHSCETakeRecord> spliterSCE = new FunctionSpliter <string, JHSCETakeRecord>(300, 3);
                spliterSCE.Function = delegate(List <string> part)
                {
                    return(JHSCETake.Select(null, null, null, null, part));
                };
                foreach (JHSCETakeRecord sce in spliterSCE.Execute(scaIDs.ToList()))
                {
                    string key = GetCombineKey(sce.RefStudentID, sce.RefCourseID, sce.RefExamID);
                    if (!sceList.ContainsKey(key))
                    {
                        sceList.Add(key, sce);
                    }
                }

                Dictionary <string, JHExamRecord>     examTable = new Dictionary <string, JHExamRecord>();
                Dictionary <string, JHSCAttendRecord> scaTable  = new Dictionary <string, JHSCAttendRecord>();

                foreach (JHExamRecord exam in examList)
                {
                    if (!examTable.ContainsKey(exam.Name))
                    {
                        examTable.Add(exam.Name, exam);
                    }
                }

                foreach (JHSCAttendRecord sca in scaList)
                {
                    string key = GetCombineKey(sca.RefStudentID, sca.RefCourseID);
                    if (!scaTable.ContainsKey(key))
                    {
                        scaTable.Add(key, sca);
                    }
                }

                foreach (DataRecord dr in drCollection)
                {
                    JHStudentRecord       student = student = scCreator.StudentNumberDictionary[dr.StudentNumber];
                    JHExamRecord          exam    = examTable[dr.Exam];
                    List <JHCourseRecord> courses = new List <JHCourseRecord>();
                    foreach (JHCourseRecord course in scCreator.StudentCourseInfo.GetCourses(dr.StudentNumber))
                    {
                        if (dr.Subjects.Contains(course.Subject))
                        {
                            courses.Add(course);
                        }
                    }

                    foreach (JHCourseRecord course in courses)
                    {
                        string key = GetCombineKey(student.ID, course.ID, exam.ID);

                        if (sceList.ContainsKey(key))
                        {
                            _deleteScoreList.Add(sceList[key]);
                        }

                        JHSCETakeRecord    jh     = new JHSCETakeRecord();
                        KH.JHSCETakeRecord sceNew = new KH.JHSCETakeRecord(jh);
                        sceNew.RefCourseID   = course.ID;
                        sceNew.RefExamID     = exam.ID;
                        sceNew.RefSCAttendID = scaTable[GetCombineKey(student.ID, course.ID)].ID;
                        sceNew.RefStudentID  = student.ID;
                        sceNew.Score         = dr.Score;
                        sceNew.Effort        = _effortMapper.GetCodeByScore(dr.Score);
                        _addScoreList.Add(sceNew.AsJHSCETakeRecord());
                    }
                }
                #endregion

                e.Result = null;
                #endregion
            };
            _worker.RunWorkerCompleted += delegate(object sender, RunWorkerCompletedEventArgs e)
            {
                #region Worker Completed
                if (e.Error == null && e.Result == null)
                {
                    if (!_upload.IsBusy)
                    {
                        //如果學生身上已有成績,則提醒使用者
                        if (_deleteScoreList.Count > 0)
                        {
                            _warn.RunWorkerAsync();
                        }
                        else
                        {
                            lblMessage.Text = "成績上傳中…";
                            FISCA.Presentation.MotherForm.SetStatusBarMessage("成績上傳中…", 0);
                            counter = 0;
                            _upload.RunWorkerAsync();
                        }
                    }
                }
                else
                {
                    ControlEnable = true;

                    if (e.Error != null)
                    {
                        MsgBox.Show("匯入失敗。" + e.Error.Message);
                        SmartSchool.ErrorReporting.ReportingService.ReportException(e.Error);
                    }
                    else if (e.Result != null && e.Result is ValidateTextResult)
                    {
                        ValidateTextResult    result = e.Result as ValidateTextResult;
                        ValidationErrorViewer viewer = new ValidationErrorViewer();
                        viewer.SetTextFileError(result.LineIndexes, result.ErrorFormatLineIndexes, result.DuplicateLineIndexes);
                        viewer.ShowDialog();
                    }
                    else if (e.Result != null && e.Result is List <string> )
                    {
                        ValidationErrorViewer viewer = new ValidationErrorViewer();
                        viewer.SetErrorLines(e.Result as List <string>);
                        viewer.ShowDialog();
                    }
                }
                #endregion
            };

            _upload = new BackgroundWorker();
            _upload.WorkerReportsProgress = true;
            _upload.ProgressChanged      += new ProgressChangedEventHandler(_upload_ProgressChanged);
            //_upload.ProgressChanged += delegate(object sender, ProgressChangedEventArgs e)
            //{
            //    counter += double.Parse("" + e.ProgressPercentage);
            //    FISCA.Presentation.MotherForm.SetStatusBarMessage("成績上傳中…", (int)(counter * 100f / (double)_addScoreList.Count));
            //};
            _upload.DoWork += new DoWorkEventHandler(_upload_DoWork);

            //_upload.DoWork += delegate
            //{


            //#region Upload DoWork
            //Framework.MultiThreadWorker<JHSCETakeRecord> multi = new Framework.MultiThreadWorker<JHSCETakeRecord>();
            //multi.MaxThreads = 3;
            //multi.PackageSize = 500;
            //multi.PackageWorker += delegate(object sender, Framework.PackageWorkEventArgs<JHSCETakeRecord> e)
            //{
            //    JHSCETake.Delete(e.List);
            //};
            //multi.Run(_deleteScoreList);

            //Framework.MultiThreadWorker<JHSCETakeRecord> multi2 = new Framework.MultiThreadWorker<JHSCETakeRecord>();
            //multi2.MaxThreads = 3;
            //multi2.PackageSize = 500;
            //multi2.PackageWorker += delegate(object sender, Framework.PackageWorkEventArgs<JHSCETakeRecord> e)
            //{
            //    JHSCETake.Insert(e.List);
            //    lock (_upload)
            //    {
            //        _upload.ReportProgress(e.List.Count);
            //    }
            //};
            //multi2.Run(_addScoreList);
            //#endregion
            //};


            _upload.RunWorkerCompleted += new RunWorkerCompletedEventHandler(_upload_RunWorkerCompleted);

            _warn = new BackgroundWorker();
            _warn.WorkerReportsProgress = true;
            _warn.DoWork += delegate(object sender, DoWorkEventArgs e)
            {
                _warn.ReportProgress(0, "產生警告訊息...");

                Dictionary <string, string> examDict = new Dictionary <string, string>();
                foreach (JHExamRecord exam in JHExam.SelectAll())
                {
                    if (!examDict.ContainsKey(exam.ID))
                    {
                        examDict.Add(exam.ID, exam.Name);
                    }
                }

                WarningForm form  = new WarningForm();
                int         count = 0;
                foreach (JHSCETakeRecord sce in _deleteScoreList)
                {
                    // 當成績資料是空值跳過
                    if (sce.Score.HasValue == false && sce.Effort.HasValue == false && string.IsNullOrEmpty(sce.Text))
                    {
                        continue;
                    }

                    count++;

                    JHStudentRecord student = JHStudent.SelectByID(sce.RefStudentID);
                    JHCourseRecord  course  = JHCourse.SelectByID(sce.RefCourseID);
                    string          exam    = (examDict.ContainsKey(sce.RefExamID) ? examDict[sce.RefExamID] : "<未知的試別>");

                    string s = "";
                    if (student.Class != null)
                    {
                        s += student.Class.Name;
                    }
                    if (!string.IsNullOrEmpty("" + student.SeatNo))
                    {
                        s += " " + student.SeatNo + "號";
                    }
                    if (!string.IsNullOrEmpty(student.StudentNumber))
                    {
                        s += " (" + student.StudentNumber + ")";
                    }
                    s += " " + student.Name;

                    form.Add(student.ID, s, string.Format("學生在「{0}」課程「{1}」中已有成績。", course.Name, exam));
                    _warn.ReportProgress((int)(count * 100 / _deleteScoreList.Count), "產生警告訊息...");
                }

                e.Result = form;
            };
            _warn.RunWorkerCompleted += delegate(object sender, RunWorkerCompletedEventArgs e)
            {
                WarningForm form = e.Result as WarningForm;

                if (form.ShowDialog() == DialogResult.OK)
                {
                    lblMessage.Text = "成績上傳中…";
                    FISCA.Presentation.MotherForm.SetStatusBarMessage("成績上傳中…", 0);
                    counter = 0;
                    _upload.RunWorkerAsync();
                }
                else
                {
                    this.DialogResult = DialogResult.Cancel;
                }
            };
            _warn.ProgressChanged += delegate(object sender, ProgressChangedEventArgs e)
            {
                FISCA.Presentation.MotherForm.SetStatusBarMessage("" + e.UserState, e.ProgressPercentage);
            };

            _files           = new List <FileInfo>();
            _addScoreList    = new List <JHSCETakeRecord>();
            _deleteScoreList = new List <JHSCETakeRecord>();
        }