Example #1
0
        private void SetLog()
        {
            sbLog = new StringBuilder();
            Dictionary <string, SHSCETakeRecord> delDic = new Dictionary <string, SHSCETakeRecord>();

            foreach (SHSCETakeRecord sce in _deleteScoreList)
            {
                if (!delDic.ContainsKey(sce.RefStudentID + "_" + sce.RefCourseID))
                {
                    delDic.Add(sce.RefStudentID + "_" + sce.RefCourseID, sce);
                }
            }

            foreach (SHSCETakeRecord sce in _addScoreList)
            {
                SHStudentRecord student = SHStudent.SelectByID(sce.RefStudentID);
                SHCourseRecord  course  = SHCourse.SelectByID(sce.RefCourseID);
                string          exam    = (examDict.ContainsKey(sce.RefExamID) ? examDict[sce.RefExamID] : "<未知的試別>");

                if (delDic.ContainsKey(sce.RefStudentID + "_" + sce.RefCourseID))
                {
                    string classname = student.Class != null ? student.Class.Name : "";
                    string seatno    = student.SeatNo.HasValue ? student.SeatNo.Value.ToString() : "";
                    sbLog.AppendLine(string.Format("班級「{0}」座號「{1}」姓名「{2}」在試別「{3}」課程「{4}」將成績「{5}」修改為「{6}」。", classname, seatno, student.Name, course.Name, exam, delDic[sce.RefStudentID + "_" + sce.RefCourseID].Score, sce.Score));
                }
                else
                {
                    string classname = student.Class != null ? student.Class.Name : "";
                    string seatno    = student.SeatNo.HasValue ? student.SeatNo.Value.ToString() : "";
                    sbLog.AppendLine(string.Format("班級「{0}」座號「{1}」姓名「{2}」在「{3}」課程「{4}」新增成績「{5}」。", classname, seatno, student.Name, course.Name, exam, sce.Score));
                }
            }

            FISCA.LogAgent.ApplicationLog.Log("讀卡系統", "評量成績", sbLog.ToString());
        }
Example #2
0
 internal void AddCourse(string student_id, SHCourseRecord course)
 {
     if (!courseTable.ContainsKey(student_id))
     {
         return;
     }
     courseTable[student_id].Add(course);
 }
        protected override void OnPrimaryKeyChangedAsync()
        {
            //Get the Course Record
            Record = SHCourse.SelectByID(PrimaryKey);

            //Get the Course_Ext Record
            AccessHelper ah = new AccessHelper();
            List<UDT.CourseExt> moreInfo = ah.Select<UDT.CourseExt>("ref_course_id='" + this.PrimaryKey + "'");
            this.Course2 = (moreInfo.Count > 0) ? moreInfo[0] : null;
        }
Example #4
0
        void bkwNotPassComputer_DoWork(object sender, DoWorkEventArgs e)
        {
            string        fileName        = (string)((object[])e.Argument)[0];
            List <string> courseFieldList = (List <string>)((object[])e.Argument)[1];
            List <string> exportFieldList = (List <string>)((object[])e.Argument)[2];
            Dictionary <ManualResetEvent, List <RowData> > Filler = (Dictionary <ManualResetEvent, List <RowData> >)((object[])e.Argument)[3];
            double   totleProgress   = 0.0;
            double   packageProgress = 100.0 / Filler.Count;
            Workbook report          = new Workbook();

            report.Worksheets[0].Name = _Title;
            ((BackgroundWorker)sender).ReportProgress(1, _Title + " 資料整理中...");
            int RowIndex = 0;
            int i        = 0;

            foreach (string field in exportFieldList)
            {
                if (courseFieldList.Contains(field))
                {
                    courseFieldList.Remove(field);
                }
            }
            //填表頭
            for (; i < courseFieldList.Count; i++)
            {
                report.Worksheets[0].Cells[0, i].PutValue(courseFieldList[i]);
            }
            for (int j = 0; j < exportFieldList.Count; j++)
            {
                report.Worksheets[0].Cells[0, i + j].PutValue(exportFieldList[j]);
            }
            RowIndex = 1;
            foreach (ManualResetEvent eve in Filler.Keys)
            {
                eve.WaitOne();
                if (RowIndex <= 65535)
                {
                    double miniProgress = Filler[eve].Count == 0 ? 1 : packageProgress / Filler[eve].Count;
                    double miniTotle    = 0;
                    foreach (RowData row in Filler[eve])
                    {
                        SHCourseRecord course = null;
                        if (row.ID != "")
                        {
                            course = SHCourse.SelectByID(row.ID);
                        }

                        if (course != null)
                        {
                            if (RowIndex <= 65535)
                            {
                                i = 0;
                                for (; i < courseFieldList.Count; i++)
                                {
                                    switch (courseFieldList[i])
                                    {
                                    case "課程系統編號": report.Worksheets[0].Cells[RowIndex, i].PutValue(course.ID); break;

                                    case "學年度": report.Worksheets[0].Cells[RowIndex, i].PutValue("" + course.SchoolYear); break;

                                    case "學期": report.Worksheets[0].Cells[RowIndex, i].PutValue("" + course.Semester); break;

                                    case "課程名稱": report.Worksheets[0].Cells[RowIndex, i].PutValue(course.Name); break;

                                    default:
                                        break;
                                    }
                                }
                                for (int j = 0; j < exportFieldList.Count; j++)
                                {
                                    report.Worksheets[0].Cells[RowIndex, i + j].PutValue(row.ContainsKey(exportFieldList[j]) ? row[exportFieldList[j]] : "");
                                }
                            }
                            RowIndex++;
                        }
                        miniTotle += miniProgress;
                        ((BackgroundWorker)sender).ReportProgress((int)(totleProgress + miniTotle), _Title + " 處理中...");
                    }
                }
                totleProgress += packageProgress;
                ((BackgroundWorker)sender).ReportProgress((int)(totleProgress), _Title + " 處理中...");
            }
            for (int k = 0; k < courseFieldList.Count + exportFieldList.Count; k++)
            {
                report.Worksheets[0].AutoFitColumn(k, 0, 150);
            }
            report.Worksheets[0].FreezePanes(1, 0, 1, courseFieldList.Count + exportFieldList.Count);
            e.Result = new object[] { report, fileName, RowIndex > 65535 };
        }
        private void Save_Click(object sender, EventArgs e)
        {
            List<DataGridViewRow> giveupRows = new List<DataGridViewRow>();
            List<DataGridViewRow> insertRows = new List<DataGridViewRow>();

            IEnumerable<DataGridViewRow> dgvrCourses = this.dgvChildData.Rows.Cast<DataGridViewRow>();

            if (dgvrCourses.Count() == 0)
                return;

            QueryHelper helper = new QueryHelper();

            DataTable courseTable = helper.Select(string.Format("select course_name from course left join $ischool.emba.course_ext on course.id=$ischool.emba.course_ext.ref_course_id where course.school_year='{0}' and course.semester='{1}'", this.nudSchoolYear.Value, (this.cboSemester.SelectedItem as SemesterItem).Value));

            IEnumerable<DataRow> tableCourses = courseTable.Rows.Cast<DataRow>();

            foreach (DataGridViewRow dataGridViewRow in dgvrCourses)
            {
                if (tableCourses.Where(x => dataGridViewRow.Cells["CourseName"].Value.ToString() == x["course_name"].ToString()).Count() == 0)
                    insertRows.Add(dataGridViewRow);
                else
                    giveupRows.Add(dataGridViewRow);
            }

            foreach (DataGridViewRow dataGridViewRow in insertRows)
            {
                SHCourseRecord course = new SHCourseRecord();
                course.Name = dataGridViewRow.Cells["CourseName"].Value.ToString();
                course.SchoolYear = int.Parse(this.nudSchoolYear.Value.ToString());
                course.Semester = int.Parse((this.cboSemester.SelectedItem as SemesterItem).Value);
                int intSubjectID = 0;
                int.TryParse(dataGridViewRow.Cells["RefSubjectID"].Value.ToString(), out intSubjectID);
                course.Subject = intSubjectID.ToString();
                decimal credit = 0;
                decimal.TryParse(dataGridViewRow.Cells["Credits"].Value.ToString(), out credit);
                course.Credit = credit;

                string courseID = SHCourse.Insert(course);

                CourseExt courseExt = new CourseExt();

                int intCapacity = 0;
                int.TryParse(dataGridViewRow.Cells["Capacity"].Value.ToString(), out intCapacity);
                courseExt.Capacity = intCapacity;
                courseExt.ClassName = dataGridViewRow.Cells["CourseItemNo"].Value.ToString();
                courseExt.CourseID = int.Parse(courseID);
                courseExt.CourseType = dataGridViewRow.Cells["CourseType"].Value.ToString();
                courseExt.IsRequired = (dataGridViewRow.Cells["CourseRequired"].Value.ToString() == "必" ? true : false) ;
                courseExt.NewSubjectCode = dataGridViewRow.Cells["CourseNewSubjectCode"].Value.ToString();
                int intSerialNo = 0;
                int.TryParse(dataGridViewRow.Cells["SerialNo"].Value.ToString(), out intSerialNo);
                courseExt.SerialNo = intSerialNo;
                courseExt.SubjectCode = dataGridViewRow.Cells["CourseSubjectCode"].Value.ToString();
                courseExt.SubjectID = intSubjectID;
                courseExt.Save();
            }
            string message = string.Empty;
            if (giveupRows.Count > 0)
            {
                message = "下列課程已存在並不儲存:\n";
                giveupRows.ForEach((x) =>
                {
                    message += x.Cells["CourseName"].Value.ToString() + "\n";
                });
            }
            if (insertRows.Count > 0)
            {
                if (!string.IsNullOrEmpty(message))
                    message += "\n\n";

                message += "下列課程儲存成功:\n";
                insertRows.ForEach((x) =>
                {
                    message += x.Cells["CourseName"].Value.ToString() + "\n";
                });
            }
            if (!string.IsNullOrEmpty(message))
                MsgBox.Show(message, "開課");

            this.Close();
                //MessageBox.Show(message, "開課", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly);
        }
        void AddLog(SHCourseRecord objCourse, UDT.CourseExt udtCourse)
        {
            this.logAgent.SetLogValue("開課", objCourse.Name);
            this.logAgent.SetLogValue("學年度", objCourse.SchoolYear.ToString());
            this.logAgent.SetLogValue("學期", SemesterItem.GetSemesterByCode(objCourse.Semester.ToString()).Name);
            this.logAgent.SetLogValue("開課班次", (udtCourse == null) ? "" : udtCourse.ClassName);
            this.logAgent.SetLogValue("類別", (udtCourse == null) ? "" : udtCourse.CourseType);
            this.logAgent.SetLogValue("課程識別", (udtCourse == null) ? "" : udtCourse.SubjectCode);
            //this.logAgent.SetLogValue("開課課程", udtCourse.);
            this.logAgent.SetLogValue("學分數", objCourse.Credit.ToString());
            this.logAgent.SetLogValue("必選修", (udtCourse == null) ? "" : udtCourse.IsRequired.ToString());
            this.logAgent.SetLogValue("流水號", (udtCourse == null) ? "" : udtCourse.SerialNo.ToString());
            this.logAgent.SetLogValue("人數上限", (udtCourse == null) ? "" : udtCourse.Capacity.ToString());

            this.logAgent.SetLogValue("教室", (udtCourse == null) ? "" : udtCourse.Classroom);
            this.logAgent.SetLogValue("上課時間", (udtCourse == null) ? "" : udtCourse.CourseTimeInfo);
            this.logAgent.SetLogValue("課程大綱", (udtCourse == null) ? "" : udtCourse.Syllabus);
            this.logAgent.SetLogValue("備註", (udtCourse == null) ? "" : udtCourse.Memo);
        }
        private void buttonX1_Click(object sender, EventArgs e)
        {
            this.textBoxX2.Text = "";

            this.addMsg(" ==== 開始匯入課程 ===");

            if (string.IsNullOrWhiteSpace(this.textBoxX1.Text))
                return;

            //1. 讀取所有科目 (供比對出科目代碼)
            this.GetAllSubjects();

            //2. 讀取某學年度學期的所有課程 (決定要新增或修改)
            this.GetAllCourses();

            //3. 開始讀取Excel 上的課程資料,
            Workbook wb = new Aspose.Cells.Workbook();
            wb.Open(this.textBoxX1.Text);
            Worksheet ws = wb.Worksheets[1];   //課程
            int rowIndex = 1;
            while (ws.Cells[rowIndex, 0].Value != null)
            {
                string courseCode = GetCellValue(ws.Cells[rowIndex, 1].Value);
                string classCode = GetCellValue(ws.Cells[rowIndex, 2].Value);
                if (classCode.Length > 2)
                    classCode = classCode.Substring(1, 2);
                string credit = GetCellValue(ws.Cells[rowIndex, 3].Value);
                string courseName = GetCellValue(ws.Cells[rowIndex, 4].Value);
                string semester = GetCellValue(ws.Cells[rowIndex, 5].Value);
                string schoolyear = GetCellValue(ws.Cells[rowIndex, 6].Value);

                string subjID = "0";
                if (!this.dicSubjects.ContainsKey(courseCode))
                    this.addMsg( string.Format("匯入課程時找不到 subject ID, code : {0}, class name :{1} , course name : {2}, schoolyear: {3}, semester :{4}  ",
                                                                                                                    courseCode, classCode, courseName, schoolyear, semester));
                else
                {
                    subjID = this.dicSubjects[courseCode].UID;

                    string key = string.Format("{0}_{1}", courseCode, classCode);
                    //檢查資料庫中是否已有存在?如果存再就修改,否則新增。
                    bool isCourseExisted = false;
                    if (this.dicCourseExts.ContainsKey(key))
                    {
                        UDT.CourseExt cExt = this.dicCourseExts[key];
                        if (this.dicCourses.ContainsKey(cExt.CourseID.ToString()))
                            isCourseExisted = true;
                    }

                    if (isCourseExisted)
                    {
                        UDT.CourseExt cExt = this.dicCourseExts[key];
                        cExt.ClassName = classCode;
                        cExt.SubjectCode = courseCode;
                        cExt.SubjectID = int.Parse(subjID);
                        List<ActiveRecord> recs = new List<ActiveRecord>();
                        recs.Add(cExt);
                        (new AccessHelper()).UpdateValues(recs);

                        SHCourseRecord course = this.dicCourses[cExt.CourseID.ToString()];
                        course.Credit = decimal.Parse(credit);
                        course.Name = string.Format("{0} {1}", courseName, classCode);
                        course.SchoolYear = int.Parse(schoolyear);
                        course.Semester = int.Parse(semester);
                        SHCourse.Update(course);
                    }
                    else
                    {
                        SHCourseRecord course = new SHCourseRecord();
                        course.Credit = decimal.Parse(credit);
                        course.Name = string.Format("{0} {1}", courseName, classCode);
                        course.SchoolYear = int.Parse(schoolyear);
                        course.Semester = int.Parse(semester);
                        string newID = SHCourse.Insert(course);

                        UDT.CourseExt cExt = new UDT.CourseExt();
                        cExt.CourseID = int.Parse(newID);
                        cExt.ClassName = classCode;
                        cExt.SubjectCode = courseCode;
                        cExt.SubjectID = int.Parse(subjID);
                        List<ActiveRecord> recs = new List<ActiveRecord>();
                        recs.Add(cExt);
                        (new AccessHelper()).InsertValues(recs);

                    }
                } //if find subject id
                rowIndex += 1;
                this.lblStatus.Text = rowIndex.ToString() ;
                Application.DoEvents();

            } // while loop

            //匯入修課學生
            this.ImportSCAttendRecords();
        }
Example #8
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(StudentNumberMax);
                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 取得驗證需要的資料
                SHCourse.RemoveAll();
                _worker.ReportProgress(5, "訊息:取得學生資料…");

                List <StudentObj> studentList = GetInSchoolStudents();

                List <string> s_ids = new List <string>();
                Dictionary <string, List <string> > studentNumberToStudentIDs = new Dictionary <string, List <string> >();
                foreach (StudentObj student in studentList)
                {
                    string sn = student.StudentNumber;// SCValidatorCreator.GetStudentNumberFormat(student.StudentNumber);
                    if (!studentNumberToStudentIDs.ContainsKey(sn))
                    {
                        studentNumberToStudentIDs.Add(sn, new List <string>());
                    }
                    studentNumberToStudentIDs[sn].Add(student.StudentID);
                }

                foreach (string each in studentNumberToStudentIDs.Keys)
                {
                    if (studentNumberToStudentIDs[each].Count > 1)
                    {
                        //學號重覆
                    }
                }

                foreach (var dr in drCollection)
                {
                    if (studentNumberToStudentIDs.ContainsKey(dr.StudentNumber))
                    {
                        s_ids.AddRange(studentNumberToStudentIDs[dr.StudentNumber]);
                    }
                }

                studentList.Clear();

                _worker.ReportProgress(10, "訊息:取得課程資料…");
                List <SHCourseRecord>    courseList = SHCourse.SelectBySchoolYearAndSemester(SchoolYear, Semester);
                List <SHAEIncludeRecord> aeList     = SHAEInclude.SelectAll();

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

                _worker.ReportProgress(20, "訊息:取得試別資料…");
                List <SHExamRecord> examList = SHExam.SelectAll();
                #endregion

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

                SCValidatorCreator scCreator = new SCValidatorCreator(SHStudent.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(45, "訊息:進行驗證中…");
                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 取得學生的評量成績

                _worker.ReportProgress(65, "訊息:取得學生評量成績…");

                _deleteScoreList.Clear();
                _addScoreList.Clear();
                AddScoreDic.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, SHSCETakeRecord>      sceList    = new Dictionary <string, SHSCETakeRecord>();
                FunctionSpliter <string, SHSCETakeRecord> spliterSCE = new FunctionSpliter <string, SHSCETakeRecord>(300, 3);
                spliterSCE.Function = delegate(List <string> part)
                {
                    return(SHSCETake.Select(null, null, null, null, part));
                };
                foreach (SHSCETakeRecord 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, SHExamRecord>     examTable = new Dictionary <string, SHExamRecord>();
                Dictionary <string, SHSCAttendRecord> scaTable  = new Dictionary <string, SHSCAttendRecord>();

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

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

                _worker.ReportProgress(80, "訊息:成績資料建立…");

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

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

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

                        SHSCETakeRecord sh = new SHSCETakeRecord();
                        sh.RefCourseID   = course.ID;
                        sh.RefExamID     = exam.ID;
                        sh.RefSCAttendID = scaTable[GetCombineKey(student.ID, course.ID)].ID;
                        sh.RefStudentID  = student.ID;

                        //轉型Double再轉回decimal,可去掉小數點後的0
                        double  reScore = (double)dr.Score;
                        decimal Score   = decimal.Parse(reScore.ToString());

                        if (Global.StudentDocRemove)
                        {
                            string qq = Score.ToString();
                            if (qq.Contains("."))
                            {
                                string[] kk = qq.Split('.');
                                sh.Score = decimal.Parse(kk[0]);
                            }
                            else
                            {
                                //
                                sh.Score = decimal.Parse(Score.ToString());
                            }
                        }
                        else
                        {
                            sh.Score = decimal.Parse(Score.ToString());
                        }

                        //sceNew.Effort = _effortMapper.GetCodeByScore(dr.Score);

                        //是否有重覆的學生,課程,評量
                        if (!AddScoreDic.ContainsKey(sh.RefStudentID + "_" + course.ID + "_" + exam.ID))
                        {
                            _addScoreList.Add(sh);
                            AddScoreDic.Add(sh.RefStudentID + "_" + course.ID + "_" + exam.ID, sh);
                        }
                    }
                }
                #endregion
                _worker.ReportProgress(100, "訊息:背景作業完成…");
                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.DoWork += new DoWorkEventHandler(_upload_DoWork);


            _upload.RunWorkerCompleted += new RunWorkerCompletedEventHandler(_upload_RunWorkerCompleted);

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

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

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

                    count++;


                    SHStudentRecord student = SHStudent.SelectByID(sce.RefStudentID);
                    SHCourseRecord  course  = SHCourse.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;

                    string scoreName = sce.RefStudentID + "_" + sce.RefCourseID + "_" + sce.RefExamID;

                    if (AddScoreDic.ContainsKey(scoreName))
                    {
                        form.AddMessage(student.ID, s, string.Format("學生在「{0}」課程「{1}」中已有成績「{2}」將修改為「{3}」。", course.Name, exam, sce.Score, AddScoreDic[scoreName].Score));
                    }
                    else
                    {
                        form.AddMessage(student.ID, s, string.Format("學生在「{0}」課程「{1}」中已有成績「{2}」。", course.Name, exam, sce.Score));
                    }

                    _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 <SHSCETakeRecord>();
            _deleteScoreList = new List <SHSCETakeRecord>();
            AddScoreDic      = new Dictionary <string, SHSCETakeRecord>();
            examDict         = new Dictionary <string, string>();
        }