Esempio n. 1
0
        private void ScoreSaver_DoWork(object sender, DoWorkEventArgs e)
        {
            List <JHSCETakeRecord> sceList = new List <JHSCETakeRecord>();

            List <StudentData> sdList = AttendManager.Instance.GetStudentDataList();
            int count = 0;

            foreach (StudentData sd in sdList)
            {
                count++;
                sceList.AddRange(sd.GetCopiedScores(Config.SourceSubject, Config.TargetSubjects));
                ScoreSaver.ReportProgress(Util.CalculatePercentage(sdList.Count, count), "複製評量成績中...");
            }

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

            foreach (JHSCETakeRecord sce in sceList)
            {
                if (string.IsNullOrEmpty(sce.ID))
                {
                    insertList.Add(sce);
                }
                else
                {
                    updateList.Add(sce);
                }
            }

            if (insertList.Count > 0)
            {
                FunctionSpliter <JHSCETakeRecord, string> spliterInsert = new FunctionSpliter <JHSCETakeRecord, string>(100, Util.MaxThread);
                spliterInsert.Function = delegate(List <JHSCETakeRecord> part)
                {
                    JHSCETake.Insert(part);
                    return(null);
                };
                spliterInsert.ProgressChange = delegate(int progress)
                {
                    ScoreSaver.ReportProgress(Util.CalculatePercentage(insertList.Count, progress), "儲存評量成績中...");
                };
                spliterInsert.Execute(insertList);
            }
            if (updateList.Count > 0)
            {
                FunctionSpliter <JHSCETakeRecord, string> spliterUpdate = new FunctionSpliter <JHSCETakeRecord, string>(100, Util.MaxThread);
                spliterUpdate.Function = delegate(List <JHSCETakeRecord> part)
                {
                    JHSCETake.Update(part);
                    return(null);
                };
                spliterUpdate.ProgressChange = delegate(int progress)
                {
                    ScoreSaver.ReportProgress(Util.CalculatePercentage(updateList.Count, progress), "儲存評量成績中...");
                };
                spliterUpdate.Execute(updateList);
            }
        }
Esempio n. 2
0
 private void Update(object item)
 {
     try
     {
         List <List <HC.JHSCETakeRecord> > updatePackages = (List <List <HC.JHSCETakeRecord> >)item;
         foreach (List <HC.JHSCETakeRecord> package in updatePackages)
         {
             JHSCETake.Update(package.AsJHSCETakeRecords());
         }
     }
     catch (Exception ex)
     {
     }
 }
Esempio 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);
            }
        }