Ejemplo n.º 1
0
        private void Update(object item)
        {
            List <List <JHSCAttendRecord> > updatePackages = (List <List <JHSCAttendRecord> >)item;

            foreach (List <JHSCAttendRecord> package in updatePackages)
            {
                JHSCAttend.Update(package);
            }
        }
Ejemplo n.º 2
0
        public void Save()
        {
            #region 儲存課程成績。
            List <JHSCAttendRecord> attends = new List <JHSCAttendRecord>();

            foreach (StudentScore student in Students)
            {
                foreach (string subject in student.AttendScore)
                {
                    if (FilterSubject.Contains(subject) || FilterSubject.Count <= 0)
                    {
                        AttendScore      attend    = student.AttendScore[subject];
                        JHSCAttendRecord DALAttend = attend.RawAttend;

                        DALAttend.Score  = attend.Value;
                        DALAttend.Effort = attend.Effort;
                        DALAttend.Text   = attend.Text;

                        attends.Add(DALAttend);
                    }
                }
            }

            if (attends.Count <= 0)
            {
                return;
            }

            FunctionSpliter <JHSCAttendRecord, JHSCAttendRecord> spliter = new FunctionSpliter <JHSCAttendRecord, JHSCAttendRecord>(300 * 10, Util.MaxThread);
            spliter.Function = delegate(List <JHSCAttendRecord> attendPart)
            {
                JHSCAttend.Update(attendPart);
                return(new List <JHSCAttendRecord>());
            };
            spliter.ProgressChange = delegate(int progress)
            {
                Reporter.Feedback("儲存計算結果...", Util.CalculatePercentage(attends.Count, progress));
            };
            spliter.Execute(attends);
            #endregion
        }
Ejemplo n.º 3
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);
            }
        }
        public void ExecuteAutoCorrect(IEnumerable <string> EntityIDs)
        {
            int AutoCorrectCount1 = 0;
            int AutoCorrectCount2 = 0;
            int AutoCorrectCount3 = 0;

            StringBuilder strLogDetail = new StringBuilder();

            List <SCETakeScoreRATRecord> SelectedRATRecords = EntityIDs == null ?
                                                              RATRecords : RATRecords.Where(x => EntityIDs.Contains(x.評量系統編號)).ToList();

            Dictionary <string, JHSCETakeRecord> UpdatedSCETakeRecords = JHSCETake
                                                                         .Select(null, null, null, SelectedRATRecords.Select(x => x.評量系統編號), null)
                                                                         .ToDictionary(x => x.ID);

            List <SCETakeScoreRATRecord> SCRecords = SelectedRATRecords
                                                     .FindAll(x => x.自動修正建議.StartsWith("1"));

            Dictionary <string, JHSCAttendRecord> UpdatedSCAttendRecords = new Dictionary <string, JHSCAttendRecord>();

            if (SCRecords.Count > 0)
            {
                UpdatedSCAttendRecords = JHSCAttend
                                         .SelectByIDs(SCRecords.Select(x => x.學生修課編號))
                                         .ToDictionary(x => x.ID);
            }

            try
            {
                foreach (SCETakeScoreRATRecord record in SelectedRATRecords)
                {
                    if (string.IsNullOrEmpty(record.平時評量成績))
                    {
                        strLogDetail.AppendLine("== SCETakeRecord:" + record.評量系統編號 + "、狀況一 ==");
                        strLogDetail.AppendLine(UpdatedSCETakeRecords[record.評量系統編號].ToString());

                        UpdatedSCAttendRecords[record.學生修課編號].OrdinarilyScore  = UpdatedSCETakeRecords[record.評量系統編號].Score;
                        UpdatedSCAttendRecords[record.學生修課編號].OrdinarilyEffort = UpdatedSCETakeRecords[record.評量系統編號].Effort;

                        UpdatedSCETakeRecords[record.評量系統編號].Score  = null;
                        UpdatedSCETakeRecords[record.評量系統編號].Effort = null;

                        AutoCorrectCount1++;
                    }
                    else if (record.定期評量設定中含平時評量成績.Equals(record.平時評量成績))
                    {
                        strLogDetail.AppendLine("== SCETakeRecord:" + record.評量系統編號 + "、狀況二 ==");
                        strLogDetail.AppendLine(UpdatedSCETakeRecords[record.評量系統編號].ToString());

                        UpdatedSCETakeRecords[record.評量系統編號].Score  = null;
                        UpdatedSCETakeRecords[record.評量系統編號].Effort = null;

                        AutoCorrectCount2++;
                    }
                    else if (!record.定期評量設定中含平時評量成績.Equals(record.平時評量成績))
                    {
                        strLogDetail.AppendLine("== SCETakeRecord:" + record.評量系統編號 + "、狀況三 ==");
                        strLogDetail.AppendLine(UpdatedSCETakeRecords[record.評量系統編號].ToString());

                        UpdatedSCETakeRecords[record.評量系統編號].Score  = null;
                        UpdatedSCETakeRecords[record.評量系統編號].Effort = null;

                        AutoCorrectCount3++;
                    }
                }

                StringBuilder strLog = new StringBuilder();

                strLog.AppendLine("自動修正將依照檢查結果建議值進行修正總共" + SelectedRATRecords.Count + "筆,強烈建議您務必將檢查結果匯出備份,是否進行自動修正?");
                strLog.AppendLine("1.『定期評量設定中含平時評量成績』有資料,而『平時評量成績』無資料,『自動修正』將前者資料複蓋到後者,並將前者資料清空。=>共" + AutoCorrectCount1 + "筆");
                strLog.AppendLine("2.『定期評量設定中含平時評量成績』等於『平時評量成績』,『自動修正』將前者資料清空。=>共" + AutoCorrectCount2 + "筆");
                strLog.AppendLine("3.『定期評量設定中含平時評量成績』不等於『平時評量成績』,建議先手動核對後者正確性,再『自動修正』將前者資料清空。=>共" + AutoCorrectCount3 + "筆");

                if (MsgBox.Show(strLog.ToString(), "您是否要進行自動修正?", System.Windows.Forms.MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes)
                {
                    strLog.AppendLine(strLogDetail.ToString());

                    if (UpdatedSCETakeRecords.Values.Count > 0)
                    {
                        JHSCETake.Update(UpdatedSCETakeRecords.Values);
                    }
                    if (UpdatedSCAttendRecords.Values.Count > 0)
                    {
                        JHSCAttend.Update(UpdatedSCAttendRecords.Values);
                    }

                    MsgBox.Show("已自動修正完成!若要再繼續修正,請重新執行本合理性檢查以確保取得最新資料!");
                    FISCA.LogAgent.ApplicationLog.Log("資料合理性檢查.平時評量成績輸入檢查", "平時評量成績輸入自動修正", strLog.ToString());
                }
            }
            catch (Exception e)
            {
                SmartSchool.ErrorReporting.ReportingService.ReportException(e);
                MsgBox.Show(e.Message);
            }
        }
Ejemplo n.º 5
0
        public override void InitializeImport(SmartSchool.API.PlugIn.Import.ImportWizard wizard)
        {
            //學生資訊 key: studentID
            Dictionary <string, JHStudentRecord> students = new Dictionary <string, JHStudentRecord>();
            //學生修課資訊 studentID -> List:SCAttendRecord
            Dictionary <string, List <JHSCAttendRecord> > scattends = new Dictionary <string, List <JHSCAttendRecord> >();
            //學生修習的課程 courseID -> CourseRecord
            Dictionary <string, JHCourseRecord> courses = new Dictionary <string, JHCourseRecord>();
            //所有課程(依學年度學期分開) schoolYear_semester -> (courseName -> CourseRecord)
            Dictionary <string, Dictionary <string, JHCourseRecord> > allcourses = new Dictionary <string, Dictionary <string, JHSchool.Data.JHCourseRecord> >();
            //學生修習的課程對應的評量設定細節
            Dictionary <string, List <JHAEIncludeRecord> > courseAe = new Dictionary <string, List <JHSchool.Data.JHAEIncludeRecord> >();
            //學生的評量成績記錄
            Dictionary <string, List <JHSCETakeRecord> > existSces = new Dictionary <string, List <JHSchool.Data.JHSCETakeRecord> >();
            //所有試別
            Dictionary <string, JHExamRecord> exams = new Dictionary <string, JHSchool.Data.JHExamRecord>();

            // 取得努力程度對照
            K12.Data.Configuration.ConfigData cd = K12.Data.School.Configuration["努力程度對照表"];
            if (!string.IsNullOrEmpty(cd["xml"]))
            {
                XmlElement element = XmlHelper.LoadXml(cd["xml"]);

                foreach (XmlElement each in element.SelectNodes("Effort"))
                {
                    int     code = int.Parse(each.GetAttribute("Code"));
                    decimal score;
                    if (!decimal.TryParse(each.GetAttribute("Score"), out score))
                    {
                        score = 0;
                    }

                    if (!_EffortDict.ContainsKey(score))
                    {
                        _EffortDict.Add(score, code);
                    }
                }

                _ScoreList.AddRange(_EffortDict.Keys);
                _ScoreList.Reverse();
            }


            wizard.PackageLimit = 3000;
            // 2018.09.05 [ischoolKingdom] Vicky依據 [02-01][03] 匯入評量成績 項目,移除文字描述。
            wizard.ImportableFields.AddRange("學年度", "學期", "課程名稱", "評量名稱", "分數評量", "努力程度");
            wizard.RequiredFields.AddRange("學年度", "學期", "課程名稱", "評量名稱");

            wizard.ValidateStart += delegate(object sender, SmartSchool.API.PlugIn.Import.ValidateStartEventArgs e)
            {
                #region 取得學生資訊
                foreach (JHStudentRecord stu in JHStudent.SelectByIDs(e.List))
                {
                    if (!students.ContainsKey(stu.ID))
                    {
                        students.Add(stu.ID, stu);
                    }
                }
                #endregion

                #region 取得修課記錄
                MultiThreadWorker <string> loader1 = new MultiThreadWorker <string>();
                loader1.MaxThreads     = 3;
                loader1.PackageSize    = 250;
                loader1.PackageWorker += delegate(object sender1, PackageWorkEventArgs <string> e1)
                {
                    foreach (JHSCAttendRecord record in JHSCAttend.SelectByStudentIDAndCourseID(e1.List, new string[] { }))
                    {
                        if (!scattends.ContainsKey(record.RefStudentID))
                        {
                            scattends.Add(record.RefStudentID, new List <JHSchool.Data.JHSCAttendRecord>());
                        }
                        scattends[record.RefStudentID].Add(record);

                        if (!courses.ContainsKey(record.RefCourseID))
                        {
                            courses.Add(record.RefCourseID, null);
                        }
                    }
                };
                loader1.Run(e.List);
                #endregion

                #region 取得課程資訊
                MultiThreadWorker <string> loader2 = new MultiThreadWorker <string>();
                loader2.MaxThreads     = 3;
                loader2.PackageSize    = 250;
                loader2.PackageWorker += delegate(object sender2, PackageWorkEventArgs <string> e2)
                {
                    foreach (JHCourseRecord record in JHCourse.SelectByIDs(new List <string>(e2.List)))
                    {
                        if (courses.ContainsKey(record.ID))
                        {
                            courses[record.ID] = record;
                        }
                    }
                };
                loader2.Run(courses.Keys);

                foreach (JHCourseRecord course in JHCourse.SelectAll())
                {
                    string key = course.SchoolYear + "_" + course.Semester;
                    if (!allcourses.ContainsKey(key))
                    {
                        allcourses.Add(key, new Dictionary <string, JHSchool.Data.JHCourseRecord>());
                    }
                    if (!allcourses[key].ContainsKey(course.Name))
                    {
                        allcourses[key].Add(course.Name, course);
                    }
                }
                #endregion

                #region 取得目前評量成績記錄

                MultiThreadWorker <string> loader3 = new MultiThreadWorker <string>();
                loader3.MaxThreads     = 3;
                loader3.PackageSize    = 250;
                loader3.PackageWorker += delegate(object sender3, PackageWorkEventArgs <string> e3)
                {
                    foreach (JHSCETakeRecord sce in JHSCETake.SelectByStudentIDs(e3.List))
                    {
                        if (!existSces.ContainsKey(sce.RefSCAttendID))
                        {
                            existSces.Add(sce.RefSCAttendID, new List <JHSchool.Data.JHSCETakeRecord>());
                        }
                        existSces[sce.RefSCAttendID].Add(sce);
                    }
                };
                loader3.Run(e.List);
                #endregion

                #region 取得評量設定
                foreach (JHAEIncludeRecord ae in JHAEInclude.SelectAll())
                {
                    if (!courseAe.ContainsKey(ae.RefAssessmentSetupID))
                    {
                        courseAe.Add(ae.RefAssessmentSetupID, new List <JHSchool.Data.JHAEIncludeRecord>());
                    }
                    courseAe[ae.RefAssessmentSetupID].Add(ae);
                }
                #endregion

                #region 取得試別
                foreach (JHExamRecord exam in JHExam.SelectAll())
                {
                    if (!exams.ContainsKey(exam.ID))
                    {
                        exams.Add(exam.ID, exam);
                    }
                }
                #endregion
            };

            wizard.ValidateRow += delegate(object sender, SmartSchool.API.PlugIn.Import.ValidateRowEventArgs e)
            {
                int     i = -1;
                decimal d = -1;

                #region 檢查學生是否存在
                JHStudentRecord student = null;
                if (students.ContainsKey(e.Data.ID))
                {
                    student = students[e.Data.ID];
                }
                else
                {
                    e.ErrorMessage = "壓根就沒有這個學生" + e.Data.ID;
                    return;
                }
                #endregion

                #region 驗證各個欄位格式
                bool inputFormatPass = true;
                foreach (string field in e.SelectFields)
                {
                    string value = e.Data[field];
                    switch (field)
                    {
                    default:
                        break;

                    case "學年度":
                    case "學期":
                        if (value == "" || !int.TryParse(value, out i))
                        {
                            inputFormatPass &= false;
                            e.ErrorFields.Add(field, "必須填入整數");
                        }
                        break;

                    case "課程名稱":
                        if (value == "")
                        {
                            inputFormatPass &= false;
                            e.ErrorFields.Add(field, "必須填入課程名稱");
                        }
                        break;

                    case "評量名稱":
                        if (value == "")
                        {
                            inputFormatPass &= false;
                            e.ErrorFields.Add(field, "必須填入評量名稱");
                        }
                        break;

                    case "分數評量":
                        if (value != "" && !decimal.TryParse(value, out d))
                        {
                            inputFormatPass &= false;
                            e.ErrorFields.Add(field, "必須填入空白或數值");
                        }
                        break;

                    case "努力程度":
                        if (value != "" && !int.TryParse(value, out i))
                        {
                            inputFormatPass &= false;
                            e.ErrorFields.Add(field, "必須填入空白或整數");
                        }
                        else
                        {
                            // 2020/10/15 加入檢查,當分數與努力轉換後努力程度不同,需要顯示警告
                            if (value != "")
                            {
                                int x = ConvertEffort(d);
                                if (x != i)
                                {
                                    e.WarningFields.Add(field, "努力程度與使用分數轉換後不一致");
                                }
                            }
                        }
                        break;

                        // 2018.09.05 [ischoolKingdom] Vicky依據 [02-01][03] 匯入評量成績 項目,移除文字描述。
                        //case "文字描述":
                        //    break;
                    }
                }
                #endregion

                //輸入格式正確才會針對情節做檢驗
                #region 驗證各種情節
                if (inputFormatPass)
                {
                    string errorMessage = "";

                    string sy         = e.Data["學年度"];
                    string se         = e.Data["學期"];
                    string key        = e.Data.ID + "_" + sy + "_" + se;
                    string courseName = e.Data["課程名稱"];
                    string semsKey    = sy + "_" + se;
                    string examName   = e.Data["評量名稱"];

                    //int schoolyear = Framework.Int.ParseInt(sy);
                    //int semester = Framework.Int.ParseInt(se);

                    #region 檢查課程是否存在系統中
                    bool noCourse = false;
                    if (!allcourses.ContainsKey(semsKey))
                    {
                        noCourse      = true;
                        errorMessage += (errorMessage == "" ? "" : "\n") + " 系統中找不到該課程";
                    }
                    else if (!allcourses[semsKey].ContainsKey(courseName))
                    {
                        noCourse      = true;
                        errorMessage += (errorMessage == "" ? "" : "\n") + " 系統中找不到該課程";
                    }
                    else
                    {
                    }
                    #endregion

                    #region 檢查學生是否有修此課程 & 評量是否存在
                    bool attended = false;

                    JHCourseRecord attendCourse = null;
                    if (scattends.ContainsKey(e.Data.ID))
                    {
                        foreach (JHSCAttendRecord record in scattends[e.Data.ID])
                        {
                            bool HasRec = false;

                            // 當有學年度學期課程名稱相同
                            if (courses[record.RefCourseID].Name == courseName && courses[record.RefCourseID].SchoolYear.HasValue && courses[record.RefCourseID].Semester.HasValue)
                            {
                                if ((courses[record.RefCourseID].SchoolYear.Value.ToString().Trim() == sy.Trim()) && courses[record.RefCourseID].Semester.Value.ToString().Trim() == se.Trim())
                                {
                                    HasRec = true;
                                }
                            }
                            if (HasRec && courses.ContainsKey(record.RefCourseID))
                            {
                                attendCourse = courses[record.RefCourseID];
                            }
                        }
                    }
                    else //學生沒修半堂課
                    {
                    }

                    if (attendCourse == null && !noCourse)
                    {
                        if (!e.ErrorFields.ContainsKey("無修課記錄"))
                        {
                            e.ErrorFields.Add("無修課記錄", "學生在此學期並無修習此課程");
                        }
                    }
                    else if (attendCourse != null)
                    {
                        #region 驗證評量是否存在
                        if (string.IsNullOrEmpty(attendCourse.RefAssessmentSetupID))
                        {
                            if (!e.ErrorFields.ContainsKey("無評量設定"))
                            {
                                e.ErrorFields.Add("無評量設定", "課程(" + attendCourse.Name + ")無評量設定");
                            }
                        }
                        else
                        {
                            if (!courseAe.ContainsKey(attendCourse.RefAssessmentSetupID))
                            {
                                if (!e.ErrorFields.ContainsKey("無評量設定"))
                                {
                                    e.ErrorFields.Add("無評量設定", "課程(" + attendCourse.Name + ")無評量設定");
                                }
                            }
                            else
                            {
                                bool examValid = false;
                                foreach (JHAEIncludeRecord ae in courseAe[attendCourse.RefAssessmentSetupID])
                                {
                                    if (!exams.ContainsKey(ae.RefExamID))
                                    {
                                        continue;
                                    }

                                    // 2016/7/26,穎驊新增,由於高雄國中希望可以加入匯出匯入"平時評量的功能",因此必須要在原本的Exam.Name驗證
                                    // 加上 ||examName =="平時評量" ,避免平時評量的欄位被擋掉
                                    if (exams[ae.RefExamID].Name == examName || examName == "平時評量")
                                    {
                                        examValid = true;
                                    }
                                }

                                if (!examValid)
                                {
                                    if (!e.ErrorFields.ContainsKey("評量名稱無效"))
                                    {
                                        e.ErrorFields.Add("評量名稱無效", "評量名稱(" + examName + ")不存在系統中");
                                    }
                                }
                            }
                        }
                        #endregion
                    }
                    #endregion

                    e.ErrorMessage = errorMessage;
                }
                #endregion
            };

            wizard.ImportPackage += delegate(object sender, SmartSchool.API.PlugIn.Import.ImportPackageEventArgs e)
            {
                Dictionary <string, List <RowData> > id_Rows = new Dictionary <string, List <RowData> >();

                #region 分包裝
                foreach (RowData data in e.Items)
                {
                    if (!id_Rows.ContainsKey(data.ID))
                    {
                        id_Rows.Add(data.ID, new List <RowData>());
                    }
                    id_Rows[data.ID].Add(data);
                }
                #endregion

                List <KH.JHSCETakeRecord> insertList = new List <KH.JHSCETakeRecord>();
                List <KH.JHSCETakeRecord> updateList = new List <KH.JHSCETakeRecord>();


                // 檢查是否有努力程度欄位
                bool isHasEffortField = false;

                //交叉比對各學生資料
                #region 交叉比對各學生資料
                foreach (string id in id_Rows.Keys)
                {
                    JHStudentRecord studentRec = students[id];

                    foreach (RowData data in id_Rows[id])
                    {
                        string examName   = data["評量名稱"];
                        string courseName = data["課程名稱"];
                        string SchoolYear = data["學年度"];
                        string Semester   = data["學期"];

                        if (isHasEffortField == false)
                        {
                            if (data.ContainsKey("努力程度"))
                            {
                                // 有努力程度這欄位
                                isHasEffortField = true;
                            }
                        }

                        // 2016/7/26,穎驊新增bool值避免 在有"平時評量"的評量名稱Row 進入算評量成績的判斷式
                        bool isOrdinarilyScore = false;

                        if (!scattends.ContainsKey(id))
                        {
                            continue;
                        }

                        foreach (JHSCAttendRecord record in scattends[id])
                        {
                            if (!courses.ContainsKey(record.RefCourseID))
                            {
                                continue;
                            }
                            JHCourseRecord course = courses[record.RefCourseID];
                            //if (course.Name != courseName) continue;

                            string sy = "", ss = "";
                            if (course.SchoolYear.HasValue)
                            {
                                sy = course.SchoolYear.Value.ToString();
                            }
                            if (course.Semester.HasValue)
                            {
                                ss = course.Semester.Value.ToString();
                            }

                            if (SchoolYear != sy || Semester != ss || course.Name != courseName)
                            {
                                continue;
                            }


                            KH.JHSCETakeRecord currentSCE = null;

                            if (SchoolYear == sy && Semester == ss && course.Name == courseName)
                            {
                                // 2016/7/26,穎驊新增,由於高雄國中希望可以加入匯出匯入"平時評量的功能",在原本的Code努力尋找見縫插針的位子,
                                //因為"平時評量"與一般的"評量成績"處理邏輯要分開
                                //後來決定這邊是最佳位子,邏輯為,當程序在一條一條讀取Excel Row時,讀到欄位"評量名稱"值為 "平時評量"
                                //則進入我們處理平時評量的程序,如果欄位"評量名稱"值非為 "平時評量" 則使用它原本的邏輯處理
                                // 上面的CODE會幫忙進行學年、學期、課程的驗證,確保是同一門課程成績資料,
                                //而 JHSCAttendRecord record內意外發現剛好有 平時評量OrdinarilyScore的欄位
                                //因此只要指定欄位為新的Excel 內的值,最後 使用JHSCAttend.Update(record) 更新即可

                                if (data.ContainsKey("評量名稱"))
                                {
                                    if (data["評量名稱"] == "平時評量")
                                    {
                                        if (data.ContainsKey("分數評量"))
                                        {
                                            if (data["分數評量"] != null && data["分數評量"] != "")
                                            {
                                                decimal d;

                                                // 使用TryParse 的轉換,是因為可能會有Row 的分數評量欄位是空的(EX: 社團成績) ,直接Parse會爆
                                                if (decimal.TryParse(data["分數評量"], out d))
                                                {
                                                    record.OrdinarilyScore = d;
                                                }
                                            }

                                            // 當分數評量是空白
                                            if (data["分數評量"] != null && data["分數評量"].Trim() == "")
                                            {
                                                record.OrdinarilyScore = null;
                                            }
                                        }

                                        if (data.ContainsKey("努力程度"))
                                        {
                                            if (data["努力程度"] != null && data["努力程度"] != "")
                                            {
                                                int i;
                                                if (int.TryParse(data["努力程度"], out i))
                                                {
                                                    record.OrdinarilyEffort = i;
                                                }
                                            }

                                            if (data["努力程度"] != null && data["努力程度"].Trim() == "")
                                            {
                                                record.OrdinarilyEffort = null;
                                            }
                                        }

                                        // 2018.09.05 [ischoolKingdom] Vicky依據 [02-01][03] 匯入評量成績 項目,移除文字描述。
                                        //if (data["文字描述"] != null)
                                        //{
                                        //    record.Text = data["文字描述"].ToString();
                                        //}

                                        // 2020/10/15 宏安與小組會議討論,當沒有努力程度欄位,會使用成績轉換努力程度
                                        if (isHasEffortField == false)
                                        {
                                            if (record.OrdinarilyScore.HasValue)
                                            {
                                                record.OrdinarilyEffort = ConvertEffort(record.OrdinarilyScore.Value);
                                            }
                                            else
                                            {
                                                record.OrdinarilyEffort = null;
                                            }
                                        }


                                        JHSCAttend.Update(record);

                                        isOrdinarilyScore = true;

                                        currentSCE = null;
                                    }

                                    else
                                    {
                                        if (existSces.ContainsKey(record.ID))
                                        {
                                            foreach (KH.JHSCETakeRecord sce in existSces[record.ID].AsKHJHSCETakeRecords())
                                            {
                                                if (!exams.ContainsKey(sce.RefExamID))
                                                {
                                                    continue;
                                                }

                                                if (exams[sce.RefExamID].Name == examName)
                                                {
                                                    currentSCE = sce;
                                                }
                                            }
                                        }
                                    }
                                }
                            }

                            // 2016/7/26,穎驊新增bool值避免 在有"平時評量"的評量名稱Row 進入算評量成績的判斷式
                            if (currentSCE != null && isOrdinarilyScore == false)
                            {
                                //bool changed = false;

                                #region 填入資料
                                foreach (string field in e.ImportFields)
                                {
                                    string value = data[field];
                                    switch (field)
                                    {
                                    case "分數評量":
                                        if ("" + currentSCE.Score != value)
                                        {
                                            decimal d;
                                            if (decimal.TryParse(value, out d))
                                            {
                                                currentSCE.Score = d;
                                            }
                                            else
                                            {
                                                currentSCE.Score = null;
                                            }
                                            //   changed = true;
                                        }
                                        break;

                                    case "努力程度":
                                        if ("" + currentSCE.Effort != value)
                                        {
                                            int i;
                                            if (int.TryParse(value, out i))
                                            {
                                                currentSCE.Effort = i;
                                            }
                                            else
                                            {
                                                currentSCE.Effort = null;
                                            }
                                            //  changed = true;
                                        }
                                        break;
                                        // 2018.09.05 [ischoolKingdom] Vicky依據 [02-01][03] 匯入評量成績 項目,移除文字描述。
                                        //case "文字描述":
                                        //    if (currentSCE.Text != value)
                                        //    {
                                        //        currentSCE.Text = value;
                                        //        changed = true;
                                        //    }
                                        //    break;
                                    }
                                }
                                #endregion

                                //    if (changed)
                                updateList.Add(currentSCE);
                            }

                            // 2016/7/26,穎驊新增bool值避免 在有"平時評量"的評量名稱Row 進入算評量成績的判斷式
                            if (currentSCE == null && isOrdinarilyScore == false)
                            {
                                KH.JHSCETakeRecord newSCE = new KH.JHSCETakeRecord(new JHSCETakeRecord());
                                newSCE.RefStudentID  = id;
                                newSCE.RefSCAttendID = record.ID;
                                newSCE.RefCourseID   = record.RefCourseID;

                                foreach (JHExamRecord exam in exams.Values)
                                {
                                    if (exam.Name == examName)
                                    {
                                        newSCE.RefExamID = exam.ID;
                                        break;
                                    }
                                }

                                #region 填入資料
                                foreach (string field in e.ImportFields)
                                {
                                    string value = data[field];
                                    switch (field)
                                    {
                                    case "分數評量":
                                        if (value != "")
                                        {
                                            decimal d;
                                            if (decimal.TryParse(value, out d))
                                            {
                                                newSCE.Score = d;
                                            }
                                            else
                                            {
                                                newSCE.Score = null;
                                            }
                                        }
                                        else
                                        {
                                            newSCE.Score = null;
                                        }
                                        break;

                                    case "努力程度":
                                        if (value != "")
                                        {
                                            int i;
                                            if (int.TryParse(value, out i))
                                            {
                                                newSCE.Effort = i;
                                            }
                                            else
                                            {
                                                newSCE.Effort = null;
                                            }
                                        }
                                        else
                                        {
                                            newSCE.Effort = null;
                                        }
                                        break;

                                        // 2018.09.05 [ischoolKingdom] Vicky依據 [02-01][03] 匯入評量成績 項目,移除文字描述。
                                        //case "文字描述":
                                        //    newSCE.Text = value;
                                        //    break;
                                    }
                                }
                                #endregion

                                if (newSCE.RefExamID != "")
                                {
                                    insertList.Add(newSCE);
                                }
                            }
                        }
                    }
                }

                try
                {
                    // 解析並填入轉換空白的努力程度
                    // 2020/10/15 透過宏安討論,當沒有努力程度欄位才會使用成績轉換,如果有努力程度欄位不會使用成績轉換。
                    foreach (KH.JHSCETakeRecord rec in updateList)
                    {
                        //// 當努力程度沒有值卻有成績。
                        //if ((rec.Effort.HasValue == false) && rec.Score.HasValue)
                        //{
                        //    rec.Effort = ConvertEffort(rec.Score.Value);
                        //}

                        if (isHasEffortField == false)
                        {
                            if (rec.Score.HasValue)
                            {
                                rec.Effort = ConvertEffort(rec.Score.Value);
                            }
                            else
                            {
                                rec.Effort = null;
                            }
                        }
                    }

                    foreach (KH.JHSCETakeRecord rec in insertList)
                    {
                        //// 當努力程度沒有值卻有成績。
                        //if ((rec.Effort.HasValue == false) && rec.Score.HasValue)
                        //{
                        //    rec.Effort = ConvertEffort(rec.Score.Value);
                        //}

                        if (isHasEffortField == false)
                        {
                            if (rec.Score.HasValue)
                            {
                                rec.Effort = ConvertEffort(rec.Score.Value);
                            }
                            else
                            {
                                rec.Effort = null;
                            }
                        }
                    }



                    if (updateList.Count > 0)
                    {
                        #region 分批次兩路上傳
                        List <List <KH.JHSCETakeRecord> > updatePackages  = new List <List <KH.JHSCETakeRecord> >();
                        List <List <KH.JHSCETakeRecord> > updatePackages2 = new List <List <KH.JHSCETakeRecord> >();
                        {
                            List <KH.JHSCETakeRecord> package = null;
                            int count = 0;
                            foreach (KH.JHSCETakeRecord var in updateList)
                            {
                                if (count == 0)
                                {
                                    package = new List <KH.JHSCETakeRecord>(30);
                                    count   = 30;
                                    if ((updatePackages.Count & 1) == 0)
                                    {
                                        updatePackages.Add(package);
                                    }
                                    else
                                    {
                                        updatePackages2.Add(package);
                                    }
                                }
                                package.Add(var);
                                count--;
                            }
                        }
                        Thread threadUpdateSemesterSubjectScore = new Thread(new ParameterizedThreadStart(Update));
                        threadUpdateSemesterSubjectScore.IsBackground = true;
                        threadUpdateSemesterSubjectScore.Start(updatePackages);
                        Thread threadUpdateSemesterSubjectScore2 = new Thread(new ParameterizedThreadStart(Update));
                        threadUpdateSemesterSubjectScore2.IsBackground = true;
                        threadUpdateSemesterSubjectScore2.Start(updatePackages2);

                        threadUpdateSemesterSubjectScore.Join();
                        threadUpdateSemesterSubjectScore2.Join();
                        #endregion
                    }
                }
                catch (Exception ex)
                {
                }

                if (insertList.Count > 0)
                {
                    #region 分批次兩路上傳

                    List <List <KH.JHSCETakeRecord> > insertPackages  = new List <List <KH.JHSCETakeRecord> >();
                    List <List <KH.JHSCETakeRecord> > insertPackages2 = new List <List <KH.JHSCETakeRecord> >();
                    {
                        List <KH.JHSCETakeRecord> package = null;
                        int count = 0;
                        foreach (KH.JHSCETakeRecord var in insertList)
                        {
                            if (count == 0)
                            {
                                package = new List <KH.JHSCETakeRecord>(30);
                                count   = 30;
                                if ((insertPackages.Count & 1) == 0)
                                {
                                    insertPackages.Add(package);
                                }
                                else
                                {
                                    insertPackages2.Add(package);
                                }
                            }
                            package.Add(var);
                            count--;
                        }
                    }
                    Thread threadInsertSemesterSubjectScore = new Thread(new ParameterizedThreadStart(Insert));
                    threadInsertSemesterSubjectScore.IsBackground = true;
                    threadInsertSemesterSubjectScore.Start(insertPackages);
                    Thread threadInsertSemesterSubjectScore2 = new Thread(new ParameterizedThreadStart(Insert));
                    threadInsertSemesterSubjectScore2.IsBackground = true;
                    threadInsertSemesterSubjectScore2.Start(insertPackages2);

                    threadInsertSemesterSubjectScore.Join();
                    threadInsertSemesterSubjectScore2.Join();
                    #endregion
                }

                FISCA.LogAgent.ApplicationLog.Log("成績系統.匯入匯出", "匯入評量成績", "總共匯入" + (insertList.Count + updateList.Count) + "筆評量成績。");
                #endregion
            };
        }
Ejemplo n.º 6
0
        private void btn_Save_Click(object sender, EventArgs e)
        {
            dgv.EndEdit();

            try
            {
                //回寫資料到 record
                WriteDGVToRec();

                List <JHSCAttendRecord> UpdateSCAtendList = new List <JHSCAttendRecord>();
                UpdateSCAtendList.AddRange(_SCAttendListDic.Values);

                if (UpdateSCAtendList.Count < 1)
                {
                    return;
                }

                bool checkLoadSave = false;
                // 檢查超過 0~100

                foreach (JHSCAttendRecord rec in UpdateSCAtendList)
                {
                    if (rec.OrdinarilyScore.HasValue)
                    {
                        if (rec.OrdinarilyScore.Value < 0 || rec.OrdinarilyScore.Value > 100)
                        {
                            checkLoadSave = true;
                        }
                    }
                }

                if (checkLoadSave)
                {
                    CheckSaveForm csf = new CheckSaveForm();
                    csf.ShowDialog();
                    if (csf.DialogResult == DialogResult.Cancel)
                    {
                        return;
                    }
                }

                StringBuilder sb = new StringBuilder();

                // 記 Log;
                foreach (StudentSCAtendScore rec in _StudentSCAtendScoreList)
                {
                    string str = "";

                    if (_StudOldScoreDic.ContainsKey(rec.StudentID))
                    {
                        if (_StudOldScoreDic[rec.StudentID] != rec.GetOrdinarilyScore())
                        {
                            str += "平時評量由「" + _StudOldScoreDic[rec.StudentID] + "」改成「" + rec.GetOrdinarilyScore() + "」";
                        }
                    }
                    if (_StudOldEffortDic.ContainsKey(rec.StudentID))
                    {
                        if (_StudOldEffortDic[rec.StudentID] != rec.GetOrdinarilyEffort())
                        {
                            str += "努力程度由「" + _StudOldEffortDic[rec.StudentID] + "」改成「" + rec.GetOrdinarilyEffort() + "」";
                        }
                    }

                    if (str != "")
                    {
                        sb.Append("班級:" + rec.ClassName + ",座號:" + rec.SeatNo + ",姓名:" + rec.Name + " " + str);
                    }
                }

                JHSCAttend.Update(UpdateSCAtendList);
                lblSave.Visible = false;

                FISCA.LogAgent.ApplicationLog.Log("課程平時評量輸入", "", "course", _CourseRec.ID, sb.ToString());

                CopySCAttendListDic();
                MsgBox.Show("儲存成功。");
            }
            catch (Exception ex)
            {
                MsgBox.Show("儲存失敗。\n" + ex.Message);
            }

            // 載入分數顏色
            LoadDvScoreColor();
        }