/// <summary> /// 完整刪除單筆學年科目成績 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnCompleteDelete_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty("" + cmbSchoolYear.SelectedItem)) { MessageBox.Show("請選擇學年度!"); return; } int SchoolYear = K12.Data.Int.Parse("" + cmbSchoolYear.SelectedItem); strLog = new StringBuilder(); strLog.AppendLine("『完整刪除學年科目成績紀錄』"); List <SHSchoolYearScoreRecord> DeleteRecords = StudentScores.Where(x => x.SchoolYear == SchoolYear).ToList(); foreach (SHSchoolYearScoreRecord record in DeleteRecords) { SHStudentRecord s = StudentRecords.Find(x => x.ID.Equals(record.RefStudentID)); strLog.AppendLine("系統編號:" + record.ID + ",學生編號:" + s.ID + ",學生學號:" + s.StudentNumber + ",學生姓名:" + s.Name + ",學年度:" + record.SchoolYear); } int SuccessCount = 0; if (K12.Data.Utility.Utility.IsNullOrEmpty(DeleteRecords)) { MessageBox.Show("沒有資料不需刪除!!"); return; } try { if (MessageBox.Show("與您確認是否要刪除總共" + DeleteRecords.Count + "筆成績?提醒在刪除前先備份該位學生所有學年科目成績,並在成功後備份『刪除紀錄』。", "刪除學年科目成績確認", MessageBoxButtons.YesNo) == DialogResult.Yes) { SuccessCount = SHSchoolYearScore.Delete(DeleteRecords); MessageBox.Show("成功刪除筆數:" + SuccessCount); txtLog.Text = txtLog.Text + strLog.ToString(); FISCA.LogAgent.ApplicationLog.Log("成績模組.學年科目成績資料維護", strLog.ToString()); } } catch (Exception ve) { MessageBox.Show(ve.Message); txtLog.Text = txtLog.Text + ve.Message; } finally { RefreshUI(); } }
private void RefreshUI() { List <string> SelectStudentIDs = K12.Presentation.NLDPanels.Student.SelectedSource; StudentScores = SHSemesterScore.SelectByStudentIDs(SelectStudentIDs, false); //取得選取學生的學年科目成績 StudentSchoolYearScores = SHSchoolYearScore.SelectByStudentIDs(SelectStudentIDs); //根據選取學生的學期科目成績計算出成績裡的學年度、學期、級別及科目 List <string> SchoolYears = new List <string>(); List <string> Semesters = new List <string>(); List <int> Levels = new List <int>(); List <string> Subjects = new List <string>(); foreach (SHSemesterScoreRecord record in StudentScores) { if (!SchoolYears.Contains("" + record.SchoolYear)) { SchoolYears.Add("" + record.SchoolYear); } if (!Semesters.Contains("" + record.Semester)) { Semesters.Add("" + record.Semester); } Levels.AddRange(record.Subjects.Values.Where(x => x.Level.HasValue).Select(x => x.Level.Value).ToList()); Subjects.AddRange(record.Subjects.Values.Where(x => !Subjects.Contains(x.Subject)).Select(x => x.Subject)); } Levels.Sort(); Levels.Distinct().ToList().ForEach(x => cmbLevels.Items.Add("" + x)); Subjects.Sort(); Subjects.Sort(new SubjectComparer() { }); Subjects.ForEach(x => cmbSubjects.Items.Add(x)); SchoolYears.Sort(); SchoolYears.ForEach(x => cmbSchoolYear.Items.Add(x)); Semesters.Sort(); Semesters.ForEach(x => cmbSemester.Items.Add(x)); }
/// <summary> /// 重新整理介面 /// </summary> private void RefreshUI() { //取得學年科目成績 StudentScores = SHSchoolYearScore.SelectByStudentIDs(K12.Presentation.NLDPanels.Student.SelectedSource); #region 取得選取學生的學年度及科目 List <string> SchoolYears = new List <string>(); List <string> Subjects = new List <string>(); foreach (SHSchoolYearScoreRecord record in StudentScores) { if (!SchoolYears.Contains("" + record.SchoolYear)) { SchoolYears.Add("" + record.SchoolYear); } Subjects.AddRange(record.Subjects.Where(x => !Subjects.Contains(x.Subject)).Select(x => x.Subject)); } cmbSubjects.SelectedItem = null; cmbSubjects.Items.Clear(); cmbSchoolYear.SelectedItem = null; cmbSchoolYear.Items.Clear(); Subjects.Sort(); Subjects.Sort(new SubjectComparer() { }); Subjects.ForEach(x => cmbSubjects.Items.Add(x)); SchoolYears.Sort(); SchoolYears.ForEach(x => cmbSchoolYear.Items.Add(x)); grdData.DataSource = null; #endregion }
//[SelectMethod("SchoolYearScoreJudge", "取得選取學生學年科目不及格進校判斷")] public static List <SchoolYearScoreJudgeRecord> Select() { List <SchoolYearScoreJudgeRecord> Result = new List <SchoolYearScoreJudgeRecord>(); List <string> StudentIDs = K12.Presentation.NLDPanels.Student.SelectedSource; if (K12.Data.Utility.Utility.IsNullOrEmpty(StudentIDs)) { return(Result); } List <SHSchoolYearScoreRecord> StudentSchoolYearScores = SHSchoolYearScore.SelectByStudentIDs(StudentIDs); List <SHSemesterScoreRecord> StudentScores = SHSemesterScore.SelectByStudentIDs(StudentIDs); //將學期科目成績用學生編號做群組 foreach (var StudentGroup in StudentScores.GroupBy(x => x.RefStudentID)) { //將個別學生學期科目成績用學年度做群組 foreach (var StudentSchoolYearGroup in StudentGroup.GroupBy(x => x.SchoolYear)) { //假學生的學年有上下兩筆學期科目成績才進行處理 if (StudentSchoolYearGroup.ToList().Count >= 2) { //將資料根據學期加以排序 List <SHSemesterScoreRecord> records = StudentSchoolYearGroup.OrderBy(x => x.Semester).ToList(); //掃描上學期的每筆學期科目成績 foreach (string strSubject in records[0].Subjects.Keys) { //判斷下學期是否有相同的科目名稱 if (records[1].Subjects.ContainsKey(strSubject)) { //上學期科目成績 decimal?UpScore = records[0].Subjects[strSubject].Score; //下學期科目成績 decimal?DownScore = records[1].Subjects[strSubject].Score; //判斷是否上學期科目成績大於50小於60,並且下學期科目成績大於60 if ((UpScore >= 50 && UpScore < 60) && DownScore > 60) { decimal?SchoolYearScore = null; List <SHSchoolYearScoreRecord> SchoolYearScoreRecords = StudentSchoolYearScores.Where(x => x.RefStudentID.Equals(StudentGroup.Key) && x.SchoolYear.Equals(StudentSchoolYearGroup.Key)).ToList(); if (SchoolYearScoreRecords.Count > 0) { List <SHSchoolYearScoreSubject> Subjects = SchoolYearScoreRecords[0].Subjects.Where(x => x.Subject.Equals(strSubject)).ToList(); if (Subjects.Count > 0) { SchoolYearScore = Subjects[0].Score; } } SchoolYearScoreJudgeRecord record = new SchoolYearScoreJudgeRecord(); record.StudentNumber = records[0].Student.StudentNumber; record.Name = records[0].Student.Name; record.SchoolYear = records[0].SchoolYear; record.UPSemesterSubject = (strSubject + records[0].Subjects[strSubject].Level); record.UpScore = records[0].Subjects[strSubject].Score; record.DownSemesterSubject = (strSubject + records[1].Subjects[strSubject].Level); record.DownSemesterScore = records[1].Subjects[strSubject].Score; record.SchoolYearSubject = strSubject; record.SchoolYearScore = SchoolYearScore; Result.Add(record); } } } } } } return(Result); }
/// <summary> /// 刪除單筆學年科目成績 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnDeleteSubject_Click(object sender, EventArgs e) { if (!IsInput()) { MessageBox.Show("請完整輸入欄位資訊!"); return; } int SchoolYear = K12.Data.Int.Parse("" + cmbSchoolYear.SelectedItem); string Subject = "" + cmbSubjects.SelectedItem; strLog = new StringBuilder(); strLog.AppendLine("『刪除學年科目成績紀錄』"); int RemoveCount = 0; List <SHSchoolYearScoreRecord> FinalUpdateRecords = new List <SHSchoolYearScoreRecord>(); List <SHSchoolYearScoreRecord> FinalDeleteRecords = new List <SHSchoolYearScoreRecord>(); UpdateRecords = StudentScores.Where(x => x.SchoolYear == SchoolYear).ToList(); foreach (SHSchoolYearScoreRecord record in UpdateRecords) { SHStudentRecord s = StudentRecords.Find(x => x.ID.Equals(record.RefStudentID)); List <string> RemoveSubjects = new List <string>(); foreach (SHSchoolYearScoreSubject SubjectScore in record.Subjects) { if (SubjectScore.Subject.Equals(Subject) || string.IsNullOrEmpty(Subject)) { RemoveSubjects.Add(SubjectScore.Subject); RemoveCount++; } } if (RemoveSubjects.Count > 0) { FinalUpdateRecords.Add(record); strLog.AppendLine("系統編號:" + record.ID + ",學生編號:" + s.ID + ",學生學號:" + s.StudentNumber + ",學生姓名:" + s.Name + ",學年度:" + record.SchoolYear); } foreach (string RemoveSubject in RemoveSubjects) { SHSchoolYearScoreSubject removerecord = record.Subjects.Find(x => x.Subject.Equals(RemoveSubject)); record.Subjects.Remove(removerecord); } #region 移除時判斷是否科目已清空,若是則加到刪除清單中 if (record.Subjects.Count == 0) { FinalDeleteRecords.Add(record); } #endregion } int SuccessCount = 0; if (K12.Data.Utility.Utility.IsNullOrEmpty(FinalUpdateRecords)) { MessageBox.Show("沒有資料不需刪除!!"); return; } try { if (MessageBox.Show("與您確認是否要刪除總共" + RemoveCount + "筆成績?提醒在刪除前先備份該位學生所有學年科目成績,並在成功後備份『刪除紀錄』。", "刪除學年科目成績確認", MessageBoxButtons.YesNo) == DialogResult.Yes) { SuccessCount = SHSchoolYearScore.Update(FinalUpdateRecords); if (FinalDeleteRecords.Count > 0) { SHSchoolYearScore.Delete(FinalDeleteRecords); } MessageBox.Show("成功刪除筆數:" + RemoveCount); txtLog.Text = txtLog.Text + strLog.ToString(); FISCA.LogAgent.ApplicationLog.Log("成績模組.學年科目成績資料維護", strLog.ToString()); } } catch (Exception ve) { MessageBox.Show(ve.Message); txtLog.Text = txtLog.Text + ve.Message; } finally { RefreshUI(); } }
/// <summary> /// 更新學年科目名稱 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnChangeSubject_Click(object sender, System.EventArgs e) { if (!IsInput() && string.IsNullOrEmpty("" + cmbSubjects.SelectedItem) && !string.IsNullOrEmpty(txtChangeSubject.Text)) { MessageBox.Show("請完整輸入欄位資訊!"); return; } int SchoolYear = K12.Data.Int.Parse("" + cmbSchoolYear.SelectedItem); string Subject = "" + cmbSubjects.SelectedItem; string ChangeSubject = txtChangeSubject.Text; strLog = new StringBuilder(); strLog.AppendLine("『更改學年科目名稱』"); int UpdateCount = 0; List <SHSchoolYearScoreRecord> FinalUpdateRecords = new List <SHSchoolYearScoreRecord>(); UpdateRecords = StudentScores.Where(x => x.SchoolYear == SchoolYear).ToList(); foreach (SHSchoolYearScoreRecord record in UpdateRecords) { SHStudentRecord s = StudentRecords.Find(x => x.ID.Equals(record.RefStudentID)); List <string> UpdateSubjects = new List <string>(); foreach (SHSchoolYearScoreSubject SubjectScore in record.Subjects) { if (SubjectScore.Subject.Equals(Subject)) { UpdateSubjects.Add(SubjectScore.Subject); UpdateCount++; } } if (UpdateSubjects.Count > 0) { FinalUpdateRecords.Add(record); strLog.AppendLine("系統編號:" + record.ID + ",學生編號:" + s.ID + ",學生學號:" + s.StudentNumber + ",學生姓名:" + s.Name + ",學年度:" + record.SchoolYear + ",更新後科目名稱:" + ChangeSubject); } foreach (string UpdateSubject in UpdateSubjects) { SHSchoolYearScoreSubject Score = record.Subjects.Find(x => x.Subject.Equals(UpdateSubject)); record.Subjects.Remove(Score); Score.Subject = ChangeSubject; record.Subjects.Add(Score); } } int SuccessCount = 0; if (K12.Data.Utility.Utility.IsNullOrEmpty(FinalUpdateRecords)) { MessageBox.Show("沒有資料不需更新!!"); return; } try { if (MessageBox.Show("與您確認是否要更新總共" + UpdateCount + "筆成績?提醒在更新前先備份該位學生所有學年科目成績,並在成功後備份『更新紀錄』。", "更新學年科目成績確認", MessageBoxButtons.YesNo) == DialogResult.Yes) { SuccessCount = SHSchoolYearScore.Update(FinalUpdateRecords); MessageBox.Show("成功更新筆數:" + UpdateCount); txtLog.Text = txtLog.Text + strLog.ToString(); FISCA.LogAgent.ApplicationLog.Log("成績模組.學年科目成績資料維護", strLog.ToString()); } } catch (Exception ve) { MessageBox.Show(ve.Message); txtLog.Text = txtLog.Text + ve.Message; } finally { RefreshUI(); } }
// 初始化所需資料 private void ProduceData(List <SHStudentRecord> pStudents) { IEnumerable <string> pStudentIDs = pStudents.Select(x => x.ID); Dictionary <string, SHScoreCalcRuleRecord> _SHScoreCalcRule = SHScoreCalcRule.SelectAll().ToDictionary(x => x.ID); // 學生修習科目學年成績資料 List <SHSchoolYearScoreRecord> _SHYearScore = SHSchoolYearScore.SelectByStudentIDs(pStudentIDs); if (_SHYearScore.Count > 0) { _SHYearScore = _SHYearScore.OrderByDescending(x => x.SchoolYear).Select(x => x).ToList(); } // 學生修習科目學年成績資料,因為補考成績與重修成績是新加入的,SHSchoolYearScore 尚未支援,暫以 DBHelper 取得資料解析之。 DataTable dataTable = (new QueryHelper()).Select(string.Format("select ref_student_id as student_id, school_year, grade_year, score_info from year_subj_score where ref_student_id in ({0}) ", string.Join(",", pStudentIDs))); foreach (DataRow row in dataTable.Rows) { string student_id = row["student_id"] + ""; string school_year = row["school_year"] + ""; string grade_year = row["grade_year"] + ""; string score_info = row["score_info"] + ""; if (string.IsNullOrWhiteSpace(score_info)) { continue; } decimal?Score = null; decimal?ReExamScore = null; decimal?ReCourseScore = null; decimal dScore; decimal dReExamScore; decimal dReCourseScore; try { // <Subject 學年成績="69" 科目="國文" 結算成績="69" 補考成績="" 重修成績=""/> XDocument Document = XDocument.Parse(score_info); foreach (XElement Element in Document.Descendants("Subject")) { string subject = (Element.Attribute("科目") == null ? string.Empty : Element.Attribute("科目").Value + ""); string key = student_id + "_" + school_year + "_" + subject + "_" + grade_year; if (Element.Attribute("學年成績") != null) { if (decimal.TryParse(Element.Attribute("學年成績").Value + "", out dScore)) { Score = dScore; if (!this._PersonalScore.ContainsKey(key)) { this._PersonalScore.Add(key, Score.Value); } } else { Score = null; } } else { Score = null; } if (Element.Attribute("補考成績") != null) { if (decimal.TryParse(Element.Attribute("補考成績").Value + "", out dReExamScore)) { ReExamScore = dReExamScore; if (!this._PersonalReExamScore.ContainsKey(key)) { this._PersonalReExamScore.Add(key, ReExamScore.Value); } } else { ReExamScore = null; } } else { ReExamScore = null; } if (Element.Attribute("重修成績") != null) { if (decimal.TryParse(Element.Attribute("重修成績").Value + "", out dReCourseScore)) { ReCourseScore = dReCourseScore; if (!this._PersonalReCourseScore.ContainsKey(key)) { this._PersonalReCourseScore.Add(key, ReCourseScore.Value); } } else { ReCourseScore = null; } } else { ReCourseScore = null; } } } catch { } } // 收集學生修習科目學年成績資料 foreach (SHSchoolYearScoreRecord sr in _SHYearScore) { // 學生個人學年歷程記錄 if (!_PersonalYearSubjectScoreHistoryInfo.ContainsKey(sr.RefStudentID)) { _PersonalYearSubjectScoreHistoryInfo.Add(sr.RefStudentID, new Dictionary <int, int>()); } if (!_PersonalYearSubjectScoreHistoryInfo[sr.RefStudentID].ContainsKey(sr.GradeYear)) { _PersonalYearSubjectScoreHistoryInfo[sr.RefStudentID].Add(sr.GradeYear, sr.SchoolYear); } else { if (!_PersonalReReadSchoolYear.ContainsKey(sr.RefStudentID)) { _PersonalReReadSchoolYear.Add(sr.RefStudentID, new List <int>()); } _PersonalReReadSchoolYear[sr.RefStudentID].Add(sr.SchoolYear); } if (_PersonalReReadSchoolYear.ContainsKey(sr.RefStudentID) && _PersonalReReadSchoolYear[sr.RefStudentID].Contains(sr.SchoolYear)) { continue; } foreach (SHSchoolYearScoreSubject ss in sr.Subjects) { string keySingleSubject = sr.RefStudentID + "_" + sr.SchoolYear.ToString() + "_" + ss.Subject + "_" + sr.GradeYear; string keyYearSubject = sr.RefStudentID + "_" + sr.SchoolYear.ToString(); if (!_PersonalSubjectYearScoreInfo.ContainsKey(keySingleSubject)) { _PersonalSubjectYearScoreInfo.Add(keySingleSubject, new SHSubjectYearScoreInfo()); } _PersonalSubjectYearScoreInfo[keySingleSubject].SchoolYear = sr.SchoolYear; _PersonalSubjectYearScoreInfo[keySingleSubject].StudentID = sr.RefStudentID; _PersonalSubjectYearScoreInfo[keySingleSubject].SubjectName = ss.Subject; if (this._PersonalScore.ContainsKey(keySingleSubject)) { _PersonalSubjectYearScoreInfo[keySingleSubject].Score = this._PersonalScore[keySingleSubject]; } else { _PersonalSubjectYearScoreInfo[keySingleSubject].Score = null; } if (this._PersonalReExamScore.ContainsKey(keySingleSubject)) { _PersonalSubjectYearScoreInfo[keySingleSubject].ReExamScore = this._PersonalReExamScore[keySingleSubject]; } else { _PersonalSubjectYearScoreInfo[keySingleSubject].ReExamScore = null; } if (this._PersonalReCourseScore.ContainsKey(keySingleSubject)) { _PersonalSubjectYearScoreInfo[keySingleSubject].ReCourseScore = this._PersonalReCourseScore[keySingleSubject]; } else { _PersonalSubjectYearScoreInfo[keySingleSubject].ReCourseScore = null; } _PersonalSubjectYearScoreInfo[keySingleSubject].GradeYear = sr.GradeYear; if (!_PersonalYearSubjectScoreInfo.ContainsKey(keyYearSubject)) { _PersonalYearSubjectScoreInfo.Add(keyYearSubject, new List <SHSubjectYearScoreInfo>()); } _PersonalYearSubjectScoreInfo[keyYearSubject].Add(_PersonalSubjectYearScoreInfo[keySingleSubject]); // 學生個人學年歷程記錄 //if (!_PersonalYearSubjectScoreHistoryInfo.ContainsKey(sr.RefStudentID)) // _PersonalYearSubjectScoreHistoryInfo.Add(sr.RefStudentID, new Dictionary<int, int>()); //if (!_PersonalYearSubjectScoreHistoryInfo[sr.RefStudentID].ContainsKey(sr.SchoolYear)) // _PersonalYearSubjectScoreHistoryInfo[sr.RefStudentID].Add(sr.SchoolYear, sr.GradeYear); } } //Dictionary<string, Dictionary<int, int>> dd = new Dictionary<string, Dictionary<int, int>>(); //foreach (string studentID in _PersonalYearSubjectScoreHistoryInfo.Keys) //{ // var _SchoolYearHistoryItems = from pair in _PersonalYearSubjectScoreHistoryInfo[studentID] orderby pair.Key descending select pair; // Dictionary<int, int> d = new Dictionary<int, int>(); // int yIndex = 0; // foreach (KeyValuePair<int, int> sh in _SchoolYearHistoryItems) // { // if (yIndex != sh.Value) // { // d.Add(sh.Key, sh.Value); // yIndex = sh.Value; // } // } // dd.Add(studentID, d); //} //_PersonalYearSubjectScoreHistoryInfo = dd; _SHYearScore = null; }