internal LeaveRequestDetail(LeaveRequestRecord item) { InitializeComponent(); // 取得假別清單 foreach (var absenceRec in K12.Data.AbsenceMapping.SelectAll()) { _LeaveReference.Add(absenceRec.Name, absenceRec.Abbreviation); } //取得學校系統課程表 _PeriodList = K12.Data.PeriodMapping.SelectAll(); var studentHelper = new SmartSchool.Customization.Data.AccessHelper().StudentHelper; var stuRec = studentHelper.GetStudent("" + item.RefStudentID); //事由 labelX5.Text = item.Content.Reason; //假單編碼 textBoxX2.Text = item.key; //學生 labelX4.Text = (stuRec.RefClass != null ? ("" + stuRec.RefClass.ClassName + "班 " + stuRec.SeatNo + "號 ") : "") + "" + stuRec.StudentName; //核可狀態 labelX7.Text = item.Approved.HasValue && item.Approved.Value ? "已進入系統" : ""; //動態新增課程Col for (int ii = 0; ii < _PeriodList.Count; ii++) { DataGridViewColumn col = new DataGridViewColumn(); col.CellTemplate = new DataGridViewTextBoxCell(); col.Name = _PeriodList[ii].Name; col.Visible = true; //if (PeriodList[ii].Name == "早讀" || PeriodList[ii].Name == "升旗" || PeriodList[ii].Name == "午休") //{ // col.Width = 50; //} //else //{ // col.Width = 25; //} //自動符合欄寬 col.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; //一個字寬25 col.MinimumWidth = _PeriodList[ii].Name.Length * 25; dataGridViewX1.Columns.Add(col); } // 填表 foreach (var date in item.Content.Dates) { object[] values = new object[_PeriodList.Count + 1]; values[0] = date.Date; Dictionary <string, string> dicAbsence = new Dictionary <string, string>(); foreach (var p in date.Periods) { if (p.Absence != "") { dicAbsence.Add(p.Period, p.Absence); } } for (int i = 0; i < _PeriodList.Count; i++) { values[i + 1] = dicAbsence.ContainsKey(_PeriodList[i].Name) ? (_LeaveReference.ContainsKey(dicAbsence[_PeriodList[i].Name]) ? _LeaveReference[dicAbsence[_PeriodList[i].Name]] : "!?") : ""; } dataGridViewX1.Rows.Add(values); } }
//2016/8/9 穎驊把原本預載的功能搬到buttonX1_Click(),並把在.Designer的參考也一併註解 //private void LeaveRegistrationViewer_Load(object sender, EventArgs e) //{ //} // 搜尋 private void buttonX1_Click(object sender, EventArgs e) { //刪除舊資料 dgvResult.Rows.Clear(); var studentHelper = new SmartSchool.Customization.Data.AccessHelper().StudentHelper; AccessHelper accessHelper = new AccessHelper(); List <K12.Data.StudentRecord> StudentList = K12.Data.Student.SelectAll(); Dictionary <String, String> StuNum_To_StuID = new Dictionary <string, string>(); foreach (var StuRecord in StudentList) { if (!StuNum_To_StuID.ContainsKey(StuRecord.StudentNumber)) { StuNum_To_StuID.Add(StuRecord.StudentNumber, StuRecord.ID); } } if (dateTimeInput1.Value.Ticks == 0 || dateTimeInput2.Value.Ticks == 0) { MsgBox.Show("請選擇輸入時間區間"); return; } if (textBoxX1.Text != "" && !StuNum_To_StuID.ContainsKey(textBoxX1.Text)) { MsgBox.Show("查無此學生"); return; } //2016/8/9 穎驊註解, 原本的時間 * 10000 + 621355968000000000 為格林威治(+0)的時間,因應台灣是(+8)時區,所以必須 //再補上 8*60*60*1000*10000 =288000000000 ticks(豪微秒?) 才是真正的時間 long startDay = (dateTimeInput1.Value.Ticks - 621355968000000000 - 288000000000) / 10000; long endDay = (dateTimeInput2.Value.AddDays(1).Ticks - 621355968000000000 - 288000000000) / 10000; // 2016/8/8 父親節,穎驊改寫,選擇條件改為 ref_student_id 等於指定id 如此一來才不會選到公假單(公假單的ref_student_id 等於null) var list = accessHelper.Select <LeaveRequestRecord>((textBoxX1.Text == "" ? "ref_student_id >=0" : "ref_student_id =" + StuNum_To_StuID[textBoxX1.Text]) + " AND uqid >=" + "'" + startDay + "'" + " AND uqid < " + "'" + endDay + "'"); //選擇所有一般假單,一般假單由學生填寫,不會有ref_teacher_id //var list = accessHelper.Select<LeaveRequestRecord>("ref_student_id > 0"); //選擇所有公假單,公假單只能由老師填寫,不會有ref_student_id //var list = accessHelper.Select<LeaveRequestRecord>("ref_teacher_id >0"); list.Sort(delegate(LeaveRequestRecord lr1, LeaveRequestRecord lr2) { return(lr2.key.CompareTo(lr1.key)); }); if (list.Count == 0) { MsgBox.Show("該學生該時段無假單紀錄"); } //填值 foreach (var item in list) { var stuRec = studentHelper.GetStudent("" + item.RefStudentID); dgvResult.Rows.Add( stuRec.RefClass == null ? "" : stuRec.RefClass.ClassName, stuRec.SeatNo, stuRec.StudentNumber, stuRec.StudentName, item.key, item.Approved.HasValue && item.Approved.Value ? "已核准" : "", //2016/8/9 穎驊註解, 原本系統的時間 * 10000 + 621355968000000000 為格林威治(+0)的時間,因應台灣是(+8)時區,所以必須 //再補上 8*60*60*1000*10000 =288000000000 ticks(豪微秒?) 才是真正的時間 //簡單來說,存在資料庫的都是格林威治標準時間 new DateTime(long.Parse(item.key) * 10000 + 621355968000000000 + 288000000000).ToString("yyyy/MM/dd HH:mm:ss") ); } list_to_LeaveReqestDetail = list; }
void _bgWorker_DoWork(object sender, DoWorkEventArgs e) { _bgWorker.ReportProgress(1); Dictionary<string, string> DeptMappingDict = new Dictionary<string, string>(); // 取得科群對照 Dictionary<string, string> GroupIDDict = Utility.GetGroupDeptIDDict(); // 科別對照 DeptMappingDict = Utility.GetDepartmetDict(); // 取得學生學期對照班級 Dictionary<string, string> classNameDict = new Dictionary<string, string>(); List<SHSemesterHistoryRecord> SHSemesterHistoryRecordList = SHSemesterHistory.SelectByStudentIDs(_StudentIDList); foreach(SHSemesterHistoryRecord rec in SHSemesterHistoryRecordList) { foreach(K12.Data.SemesterHistoryItem item in rec.SemesterHistoryItems) { if(item.SchoolYear==_SchoolYear && item.Semester == _Semester) { if (!classNameDict.ContainsKey(rec.RefStudentID)) classNameDict.Add(rec.RefStudentID, item.ClassName); } } } // 取得特色班對照 Dictionary<string, string> SpecClassNameDict = _cd.GetKeyValueItem(_ConfigClassName); // 取得學生科別名稱 Dictionary<string, string> StudeDeptNameDict = Utility.GetStudDeptNameDict(_StudentIDList,_SchoolYear,_Semester); Dictionary<string, SubjectRec> SubjectRecDict = new Dictionary<string, SubjectRec>(); SmartSchool.Customization.Data.AccessHelper accHelper = new SmartSchool.Customization.Data.AccessHelper (); // 取得學生學期科目成績 List<SmartSchool.Customization.Data.StudentRecord> StudentRecList = accHelper.StudentHelper.GetStudents(_StudentIDList); accHelper.StudentHelper.FillSemesterSubjectScore(true, StudentRecList); foreach(SmartSchool.Customization.Data.StudentRecord studRec in StudentRecList) { string studClassName = ""; if(studRec.RefClass !=null) studClassName = studRec.RefClass.ClassName; if (classNameDict.ContainsKey(studRec.StudentID)) studClassName = classNameDict[studRec.StudentID]; // 科別 string DeptName = ""; if (StudeDeptNameDict.ContainsKey(studRec.StudentID)) DeptName = StudeDeptNameDict[studRec.StudentID]; foreach(SmartSchool.Customization.Data.StudentExtension.SemesterSubjectScoreInfo sssi in studRec.SemesterSubjectScoreList) { if(sssi.SchoolYear==_SchoolYear && sssi.Semester== _Semester) { // 需要加入科別,上傳測試過程科別也是key string SubjCode = sssi.Detail.GetAttribute("科目") + "_" + sssi.Detail.GetAttribute("開課學分數") + "_" + sssi.Detail.GetAttribute("修課必選修") + "_" + sssi.Detail.GetAttribute("修課校部訂") + "_" + sssi.Detail.GetAttribute("開課分項類別") + "_" + sssi.Detail.GetAttribute("不計學分"); string key = DeptName + SubjCode; if (!SubjectRecDict.ContainsKey(key)) { SubjectRec sr = new SubjectRec(); // 科/班/學程別代碼 string DCLCode = ""; string GroupID = ""; if (StudeDeptNameDict.ContainsKey(studRec.StudentID)) { string name = StudeDeptNameDict[studRec.StudentID]; if (DeptMappingDict.ContainsKey(name)) DCLCode = DeptMappingDict[name]; if (GroupIDDict.ContainsKey(DCLCode)) GroupID = GroupIDDict[DCLCode]; } sr.Code = SubjCode; sr.Name = sssi.Detail.GetAttribute("科目"); sr.CourseType = sssi.Detail.GetAttribute("修課校部訂") + sssi.Detail.GetAttribute("開課分項類別") + sssi.Detail.GetAttribute("修課必選修"); sr.DLCCode = DCLCode; sr.DomainType = ""; sr.Group = GroupID; sr.isCalc = sssi.Detail.GetAttribute("不計學分"); sr.Required = sssi.Detail.GetAttribute("修課必選修"); sr.SpcType = ""; if (SpecClassNameDict.ContainsKey(studClassName)) sr.SpcType = SpecClassNameDict[studClassName]; SubjectRecDict.Add(key, sr); } if (sssi.GradeYear == 1) SubjectRecDict[key].CreditG1 = sssi.Detail.GetAttribute("開課學分數"); if (sssi.GradeYear == 2) SubjectRecDict[key].CreditG2 = sssi.Detail.GetAttribute("開課學分數"); if (sssi.GradeYear == 3) SubjectRecDict[key].CreditG3 = sssi.Detail.GetAttribute("開課學分數"); } } } _bgWorker.ReportProgress(70); Dictionary<string, string> ClassTypeDict = GetClassTypeDict(); List<SubjectRec> SubjectRecList = new List<SubjectRec>(); foreach (SubjectRec rec in SubjectRecDict.Values) { // 資料轉換 if (rec.Required == "必修") rec.Required = "1"; else if (rec.Required == "選修") rec.Required = "2"; else rec.Required = "3"; if (rec.isCalc == "否") rec.isCalc = "1"; else if (rec.isCalc == "是") rec.isCalc = "2"; else rec.isCalc = "3"; if(!string.IsNullOrEmpty(rec.CourseType)) { if (ClassTypeDict.ContainsKey(rec.CourseType)) { rec.CourseType = ClassTypeDict[rec.CourseType]; } else rec.CourseType = "13"; } SubjectRecList.Add(rec); } // 寫入 Excel _wb = new Workbook(new MemoryStream(Properties.Resources.科目名冊樣板)); Worksheet wst1 = _wb.Worksheets["科目名冊封面"]; Worksheet wst2 = _wb.Worksheets["科目名冊"]; // 學年度 0,學期 1,學校代碼 2,學校種類 3,名冊別 4 wst1.Cells[1, 0].PutValue(_SchoolYear); wst1.Cells[1, 1].PutValue(_Semester); wst1.Cells[1, 2].PutValue(_SchoolCode); wst1.Cells[1, 3].PutValue(_SchoolType); wst1.Cells[1, 4].PutValue(_DocType); // 修課別 0,類別種類 1,領域分類 2,群別 3,科別 4,特色班/實驗班名稱 5,科目名稱 6,科目代碼 7, // 一年級學分 8,二年級學分 9,三年級學分 10,是否計算學分 11 int rowIdx = 1; foreach(SubjectRec rec in SubjectRecList) { wst2.Cells[rowIdx, 0].PutValue(rec.Required); wst2.Cells[rowIdx, 1].PutValue(rec.CourseType); wst2.Cells[rowIdx, 2].PutValue(rec.DomainType); wst2.Cells[rowIdx, 3].PutValue(rec.Group); wst2.Cells[rowIdx, 4].PutValue(rec.DLCCode); wst2.Cells[rowIdx, 5].PutValue(rec.SpcType); wst2.Cells[rowIdx, 6].PutValue(rec.Name); wst2.Cells[rowIdx, 7].PutValue(rec.Code); wst2.Cells[rowIdx, 8].PutValue(rec.CreditG1); wst2.Cells[rowIdx, 9].PutValue(rec.CreditG2); wst2.Cells[rowIdx, 10].PutValue(rec.CreditG3); wst2.Cells[rowIdx, 11].PutValue(rec.isCalc); rowIdx++; } }
void _bgWorker_DoWork(object sender, DoWorkEventArgs e) { _bgWorker.ReportProgress(1); List <SubjectScoreRec> SubjectScoreRecList = new List <SubjectScoreRec>(); Dictionary <string, string> DeptMappingDict = new Dictionary <string, string>(); Dictionary <string, List <string> > StudTagNameDict = new Dictionary <string, List <string> >(); // 科別對照 DeptMappingDict = Utility.GetDepartmetDict(); Dictionary <string, List <ConfigDataItem> > cdDict = _cd.GetConfigDataItemDict(); Dictionary <string, string> ClsMappingDict = new Dictionary <string, string>(); Dictionary <string, string> ClassNoMappingDict = new Dictionary <string, string>(); List <SHStudentTagRecord> SHStudentTagRecordList = SHStudentTag.SelectByStudentIDs(_StudentIDList); // 取得學期對照轉成大學繁星代碼 Dictionary <string, string> StudentSHClassCodDict = Utility.GetStudentClassCodeSeatNo(_StudentIDList, _SchoolYear, _Semester, false); // 班別對照 if (cdDict.ContainsKey("班別代碼")) { foreach (ConfigDataItem cdi in cdDict["班別代碼"]) { if (!ClsMappingDict.ContainsKey(cdi.TargetName)) { ClsMappingDict.Add(cdi.TargetName, cdi.Value); } } } // 取得學生類別 foreach (SHStudentTagRecord TRec in SHStudentTagRecordList) { if (!StudTagNameDict.ContainsKey(TRec.RefStudentID)) { StudTagNameDict.Add(TRec.RefStudentID, new List <string>()); } StudTagNameDict[TRec.RefStudentID].Add(TRec.FullName); } // 班級代碼對照 ClassNoMappingDict = Utility.GetLHClassCodeDict(); _bgWorker.ReportProgress(10); // 取得學生科別名稱 Dictionary <string, string> StudeDeptNameDict = Utility.GetStudDeptNameDict(_StudentIDList, _SchoolYear, _Semester); SmartSchool.Customization.Data.AccessHelper accHelper = new SmartSchool.Customization.Data.AccessHelper(); // 取得學生學期科目成績 List <SmartSchool.Customization.Data.StudentRecord> StudentRecList = accHelper.StudentHelper.GetStudents(_StudentIDList); accHelper.StudentHelper.FillSemesterSubjectScore(true, StudentRecList); // 取得及格標準 Dictionary <string, Dictionary <string, decimal> > passScoreDict = Utility.GetStudentApplyLimitDict(StudentRecList); Dictionary <string, string> StudGradYearDict = new Dictionary <string, string>(); foreach (SmartSchool.Customization.Data.StudentRecord rec in StudentRecList) { if (!StudGradYearDict.ContainsKey(rec.StudentID)) { if (rec.RefClass != null) { StudGradYearDict.Add(rec.StudentID, rec.RefClass.GradeYear); } } } // 取得學期對照年為主 List <SHSemesterHistoryRecord> SemsH = SHSemesterHistory.SelectByStudentIDs(_StudentIDList); foreach (SHSemesterHistoryRecord rec in SemsH) { foreach (K12.Data.SemesterHistoryItem item in rec.SemesterHistoryItems) { if (item.SchoolYear == _SchoolYear && item.Semester == _Semester) { if (!StudGradYearDict.ContainsKey(item.RefStudentID)) { StudGradYearDict.Add(item.RefStudentID, item.GradeYear.ToString()); } else { StudGradYearDict[item.RefStudentID] = item.GradeYear.ToString(); } } } } _bgWorker.ReportProgress(30); foreach (SmartSchool.Customization.Data.StudentRecord studRec in StudentRecList) { string IDNumber = studRec.IDNumber.ToUpper(); string BirthDate = ""; DateTime dt; if (DateTime.TryParse(studRec.Birthday, out dt)) { BirthDate = Utility.ConvertChDateString(dt); } // 科/班/學程別代碼 string DCLCode = ""; if (StudeDeptNameDict.ContainsKey(studRec.StudentID)) { string name = StudeDeptNameDict[studRec.StudentID]; if (DeptMappingDict.ContainsKey(name)) { DCLCode = DeptMappingDict[name]; } } // 修課班別 string ClClassName = _ClassTypeCode; if (StudTagNameDict.ContainsKey(studRec.StudentID)) { foreach (string str in StudTagNameDict[studRec.StudentID]) { if (ClsMappingDict.ContainsKey(str)) { ClClassName = ClsMappingDict[str]; } } } // 修課班級 string ClassCode = ""; if (StudentSHClassCodDict.ContainsKey(studRec.StudentID)) { ClassCode = StudentSHClassCodDict[studRec.StudentID]; } else { if (K12.Data.School.DefaultSchoolYear == _SchoolYear.ToString() && K12.Data.School.DefaultSemester == _Semester.ToString()) { if (ClassNoMappingDict.ContainsKey(studRec.RefClass.ClassName)) { ClassCode = ClassNoMappingDict[studRec.RefClass.ClassName]; } } } #region 一般與補修 foreach (SmartSchool.Customization.Data.StudentExtension.SemesterSubjectScoreInfo sssi in studRec.SemesterSubjectScoreList) { if (sssi.SchoolYear == _SchoolYear && sssi.Semester == _Semester) { SubjectScoreRec ssr = new SubjectScoreRec(); ssr.IDNumber = IDNumber; ssr.StudentID = studRec.StudentID; ssr.BirthDate = BirthDate; ssr.SubjectCode = sssi.Detail.GetAttribute("科目") + "_" + sssi.Detail.GetAttribute("開課學分數") + "_" + sssi.Detail.GetAttribute("修課必選修") + "_" + sssi.Detail.GetAttribute("修課校部訂") + "_" + sssi.Detail.GetAttribute("開課分項類別") + "_" + sssi.Detail.GetAttribute("不計學分"); ssr.ReSubjectCode = sssi.Detail.GetAttribute("科目") + "_" + sssi.Detail.GetAttribute("開課學分數") + "_" + sssi.Detail.GetAttribute("修課必選修") + "_" + sssi.Detail.GetAttribute("修課校部訂") + "_" + sssi.Detail.GetAttribute("開課分項類別") + "_" + sssi.Detail.GetAttribute("不計學分"); ssr.ScSubjectCode = sssi.Detail.GetAttribute("科目") + "_" + sssi.Detail.GetAttribute("開課學分數") + "_" + sssi.Detail.GetAttribute("修課必選修") + "_" + sssi.Detail.GetAttribute("修課校部訂") + "_" + sssi.Detail.GetAttribute("開課分項類別") + "_" + sssi.Detail.GetAttribute("不計學分"); ssr.SubjectCredit = sssi.Detail.GetAttribute("開課學分數"); // 預設值 -1 ssr.Score = ssr.ScScore = ssr.ReScore = ssr.MuScore = "-1"; string GrStr = ""; if (StudGradYearDict.ContainsKey(studRec.StudentID)) { GrStr = StudGradYearDict[studRec.StudentID] + "_及"; } decimal ds, dsre, dsmu, dssc, passScore = 60; // 及格標準 if (passScoreDict[studRec.StudentID].ContainsKey(GrStr)) { passScore = passScoreDict[studRec.StudentID][GrStr]; } if (decimal.TryParse(sssi.Detail.GetAttribute("原始成績"), out ds)) { if (ds < passScore) { ssr.Score = "*" + string.Format("{0:##0.00}", ds); } else { ssr.Score = string.Format("{0:##0.00}", ds); } } if (decimal.TryParse(sssi.Detail.GetAttribute("重修成績"), out dsre)) { if (dsre < passScore) { ssr.ReScore = "*" + string.Format("{0:##0.00}", dsre); } else { ssr.ReScore = string.Format("{0:##0.00}", dsre); } } if (decimal.TryParse(sssi.Detail.GetAttribute("補考成績"), out dsmu)) { if (dsmu < passScore) { ssr.MuScore = "*" + string.Format("{0:##0.00}", dsmu); } else { ssr.MuScore = string.Format("{0:##0.00}", dsmu); } } if (decimal.TryParse(sssi.Detail.GetAttribute("原始成績"), out dssc)) { if (dssc < passScore) { ssr.ScScore = "*" + string.Format("{0:##0.00}", dssc); } else { ssr.ScScore = string.Format("{0:##0.00}", dssc); } } ssr.isScScore = ssr.isReScore = false; if (sssi.Detail.GetAttribute("是否補修成績") == "是") { ssr.isScScore = true; ssr.ScSubjectGradeYearSemester = sssi.GradeYear.ToString() + sssi.Semester.ToString(); } ssr.DCLCode = DCLCode; ssr.ClassName = ClassCode; ssr.ClCode = ClClassName; SubjectScoreRecList.Add(ssr); } } #endregion #region 重修處理 foreach (SmartSchool.Customization.Data.StudentExtension.SemesterSubjectScoreInfo sssi in studRec.SemesterSubjectScoreList) { int chkSy = 0, chkSS = 0; if (sssi.Detail.GetAttribute("重修學年度") != "" && sssi.Detail.GetAttribute("重修學期") != "") { int sy, ss; if (int.TryParse(sssi.Detail.GetAttribute("重修學年度"), out sy)) { chkSy = sy; } if (int.TryParse(sssi.Detail.GetAttribute("重修學期"), out ss)) { chkSS = ss; } } // 以有填寫重修學年度學期為主 if (chkSy == _SchoolYear && chkSS == _Semester) { SubjectScoreRec ssr = new SubjectScoreRec(); ssr.IDNumber = IDNumber; ssr.StudentID = studRec.StudentID; ssr.BirthDate = BirthDate; ssr.SubjectCode = sssi.Detail.GetAttribute("科目") + "_" + sssi.Detail.GetAttribute("開課學分數") + "_" + sssi.Detail.GetAttribute("修課必選修") + "_" + sssi.Detail.GetAttribute("修課校部訂") + "_" + sssi.Detail.GetAttribute("開課分項類別") + "_" + sssi.Detail.GetAttribute("不計學分"); ssr.ReSubjectCode = sssi.Detail.GetAttribute("科目") + "_" + sssi.Detail.GetAttribute("開課學分數") + "_" + sssi.Detail.GetAttribute("修課必選修") + "_" + sssi.Detail.GetAttribute("修課校部訂") + "_" + sssi.Detail.GetAttribute("開課分項類別") + "_" + sssi.Detail.GetAttribute("不計學分"); ssr.ScSubjectCode = sssi.Detail.GetAttribute("科目") + "_" + sssi.Detail.GetAttribute("開課學分數") + "_" + sssi.Detail.GetAttribute("修課必選修") + "_" + sssi.Detail.GetAttribute("修課校部訂") + "_" + sssi.Detail.GetAttribute("開課分項類別") + "_" + sssi.Detail.GetAttribute("不計學分"); ssr.SubjectCredit = sssi.Detail.GetAttribute("開課學分數"); // 預設值 -1 ssr.Score = ssr.ScScore = ssr.ReScore = ssr.MuScore = "-1"; string GrStr = ""; if (StudGradYearDict.ContainsKey(studRec.StudentID)) { GrStr = StudGradYearDict[studRec.StudentID] + "_及"; } decimal ds, dsre, dsmu, dssc, passScore = 60; // 及格標準 if (passScoreDict[studRec.StudentID].ContainsKey(GrStr)) { passScore = passScoreDict[studRec.StudentID][GrStr]; } if (decimal.TryParse(sssi.Detail.GetAttribute("原始成績"), out ds)) { if (ds < passScore) { ssr.Score = "*" + string.Format("{0:##0.00}", ds); } else { ssr.Score = string.Format("{0:##0.00}", ds); } } if (decimal.TryParse(sssi.Detail.GetAttribute("重修成績"), out dsre)) { if (dsre < passScore) { ssr.ReScore = "*" + string.Format("{0:##0.00}", dsre); } else { ssr.ReScore = string.Format("{0:##0.00}", dsre); } } if (decimal.TryParse(sssi.Detail.GetAttribute("補考成績"), out dsmu)) { if (dsmu < passScore) { ssr.MuScore = "*" + string.Format("{0:##0.00}", dsmu); } else { ssr.MuScore = string.Format("{0:##0.00}", dsmu); } } if (decimal.TryParse(sssi.Detail.GetAttribute("原始成績"), out dssc)) { if (dssc < passScore) { ssr.ScScore = "*" + string.Format("{0:##0.00}", dssc); } else { ssr.ScScore = string.Format("{0:##0.00}", dssc); } } ssr.isScScore = ssr.isReScore = false; // 使用學年度為該學年度學期 ssr.ReSubjectSchoolYearSemester = string.Format("{0:000}", sssi.SchoolYear) + sssi.Semester; ssr.isReScore = true; ssr.DCLCode = DCLCode; ssr.ClassName = ClassCode; ssr.ClCode = ClClassName; SubjectScoreRecList.Add(ssr); } } #endregion } _bgWorker.ReportProgress(80); // 讀取樣版並寫入 Excel _wb = new Workbook(new MemoryStream(Properties.Resources.成績名冊樣版)); Worksheet wst1 = _wb.Worksheets["成績名冊封面"]; Worksheet wst2 = _wb.Worksheets["成績名冊"]; Worksheet wst3 = _wb.Worksheets["補修成績名冊"]; Worksheet wst4 = _wb.Worksheets["重修成績名冊"]; // wst1:學校代碼 0,學年度 1,學期 2,名冊別 3 wst1.Cells[1, 0].PutValue(_SchoolCode); wst1.Cells[1, 1].PutValue(_SchoolYear); wst1.Cells[1, 2].PutValue(_Semester); wst1.Cells[1, 3].PutValue(_DocType); // wst2:身分證號 0,出生日期 1,科目代碼 2,科目學分 3,修課科/班/學程別代碼 4,修課班級 5,修課班別 6,原始成績 7,補考成績 8 int rowIdx = 1; foreach (SubjectScoreRec ssr in SubjectScoreRecList) { // 跳過補修 if (ssr.isScScore) { continue; } wst2.Cells[rowIdx, 0].PutValue(ssr.IDNumber); wst2.Cells[rowIdx, 1].PutValue(ssr.BirthDate); wst2.Cells[rowIdx, 2].PutValue(ssr.SubjectCode); wst2.Cells[rowIdx, 3].PutValue(ssr.SubjectCredit); wst2.Cells[rowIdx, 4].PutValue(ssr.DCLCode); wst2.Cells[rowIdx, 5].PutValue(ssr.ClassName); wst2.Cells[rowIdx, 6].PutValue(ssr.ClCode); wst2.Cells[rowIdx, 7].PutValue(ssr.Score); wst2.Cells[rowIdx, 8].PutValue(ssr.MuScore); rowIdx++; } // wst3:身分證號 0,出生日期 1,補修科目代碼 2,補修科目開設年級及學期(選填) 3,科目學分 4,修課科/班/學程別代碼 5,修課班級 6,修課班別 7,補修成績 8,補考成績 9 rowIdx = 1; foreach (SubjectScoreRec ssr in SubjectScoreRecList) { // 補修成績 if (ssr.isScScore) { wst3.Cells[rowIdx, 0].PutValue(ssr.IDNumber); wst3.Cells[rowIdx, 1].PutValue(ssr.BirthDate); wst3.Cells[rowIdx, 2].PutValue(ssr.ScSubjectCode); wst3.Cells[rowIdx, 3].PutValue(ssr.ScSubjectGradeYearSemester); wst3.Cells[rowIdx, 4].PutValue(ssr.SubjectCredit); wst3.Cells[rowIdx, 5].PutValue(ssr.DCLCode); wst3.Cells[rowIdx, 6].PutValue(ssr.ClassName); wst3.Cells[rowIdx, 7].PutValue(ssr.ClCode); wst3.Cells[rowIdx, 8].PutValue(ssr.ScScore); wst3.Cells[rowIdx, 9].PutValue(ssr.MuScore); rowIdx++; } } // wst4:身分證號 0,出生日期 1,重修科目代碼 2,重修科目開設年級及學期 3,科目學分 4,修課科/班/學程別代碼 5,修課班級 6,修課班別 7,重修成績 8 rowIdx = 1; foreach (SubjectScoreRec ssr in SubjectScoreRecList) { // 有重修成績學年度學期 if (ssr.isReScore) { wst4.Cells[rowIdx, 0].PutValue(ssr.IDNumber); wst4.Cells[rowIdx, 1].PutValue(ssr.BirthDate); wst4.Cells[rowIdx, 2].PutValue(ssr.ReSubjectCode); wst4.Cells[rowIdx, 3].PutValue(ssr.ReSubjectSchoolYearSemester); wst4.Cells[rowIdx, 4].PutValue(ssr.SubjectCredit); wst4.Cells[rowIdx, 5].PutValue(ssr.DCLCode); wst4.Cells[rowIdx, 6].PutValue(ssr.ClassName); wst4.Cells[rowIdx, 7].PutValue(ssr.ClCode); wst4.Cells[rowIdx, 8].PutValue(ssr.ReScore); rowIdx++; } } _bgWorker.ReportProgress(100); }
void _bgWorker_DoWork(object sender, DoWorkEventArgs e) { _bgWorker.ReportProgress(1); Dictionary <string, string> DeptMappingDict = new Dictionary <string, string>(); // 取得科群對照 Dictionary <string, string> GroupIDDict = Utility.GetGroupDeptIDDict(); // 科別對照 DeptMappingDict = Utility.GetDepartmetDict(); // 取得學生學期對照班級 Dictionary <string, string> classNameDict = new Dictionary <string, string>(); List <SHSemesterHistoryRecord> SHSemesterHistoryRecordList = SHSemesterHistory.SelectByStudentIDs(_StudentIDList); foreach (SHSemesterHistoryRecord rec in SHSemesterHistoryRecordList) { foreach (K12.Data.SemesterHistoryItem item in rec.SemesterHistoryItems) { if (item.SchoolYear == _SchoolYear && item.Semester == _Semester) { if (!classNameDict.ContainsKey(rec.RefStudentID)) { classNameDict.Add(rec.RefStudentID, item.ClassName); } } } } // 取得特色班對照 Dictionary <string, string> SpecClassNameDict = _cd.GetKeyValueItem(_ConfigClassName); // 取得學生科別名稱 Dictionary <string, string> StudeDeptNameDict = Utility.GetStudDeptNameDict(_StudentIDList, _SchoolYear, _Semester); Dictionary <string, SubjectRec> SubjectRecDict = new Dictionary <string, SubjectRec>(); SmartSchool.Customization.Data.AccessHelper accHelper = new SmartSchool.Customization.Data.AccessHelper(); // 取得學生學期科目成績 List <SmartSchool.Customization.Data.StudentRecord> StudentRecList = accHelper.StudentHelper.GetStudents(_StudentIDList); accHelper.StudentHelper.FillSemesterSubjectScore(true, StudentRecList); foreach (SmartSchool.Customization.Data.StudentRecord studRec in StudentRecList) { string studClassName = ""; if (studRec.RefClass != null) { studClassName = studRec.RefClass.ClassName; } if (classNameDict.ContainsKey(studRec.StudentID)) { studClassName = classNameDict[studRec.StudentID]; } // 科別 string DeptName = ""; if (StudeDeptNameDict.ContainsKey(studRec.StudentID)) { DeptName = StudeDeptNameDict[studRec.StudentID]; } foreach (SmartSchool.Customization.Data.StudentExtension.SemesterSubjectScoreInfo sssi in studRec.SemesterSubjectScoreList) { if (sssi.SchoolYear == _SchoolYear && sssi.Semester == _Semester) { // 需要加入科別,上傳測試過程科別也是key string SubjCode = sssi.Detail.GetAttribute("科目") + "_" + sssi.Detail.GetAttribute("開課學分數") + "_" + sssi.Detail.GetAttribute("修課必選修") + "_" + sssi.Detail.GetAttribute("修課校部訂") + "_" + sssi.Detail.GetAttribute("開課分項類別") + "_" + sssi.Detail.GetAttribute("不計學分"); string key = DeptName + SubjCode; if (!SubjectRecDict.ContainsKey(key)) { SubjectRec sr = new SubjectRec(); // 科/班/學程別代碼 string DCLCode = ""; string GroupID = ""; if (StudeDeptNameDict.ContainsKey(studRec.StudentID)) { string name = StudeDeptNameDict[studRec.StudentID]; if (DeptMappingDict.ContainsKey(name)) { DCLCode = DeptMappingDict[name]; } if (GroupIDDict.ContainsKey(DCLCode)) { GroupID = GroupIDDict[DCLCode]; } } sr.Code = SubjCode; sr.Name = sssi.Detail.GetAttribute("科目"); sr.CourseType = sssi.Detail.GetAttribute("修課校部訂") + sssi.Detail.GetAttribute("開課分項類別") + sssi.Detail.GetAttribute("修課必選修"); sr.DLCCode = DCLCode; sr.DomainType = ""; sr.Group = GroupID; sr.isCalc = sssi.Detail.GetAttribute("不計學分"); sr.Required = sssi.Detail.GetAttribute("修課必選修"); sr.SpcType = ""; if (SpecClassNameDict.ContainsKey(studClassName)) { sr.SpcType = SpecClassNameDict[studClassName]; } SubjectRecDict.Add(key, sr); } if (sssi.GradeYear == 1) { SubjectRecDict[key].CreditG1 = sssi.Detail.GetAttribute("開課學分數"); } if (sssi.GradeYear == 2) { SubjectRecDict[key].CreditG2 = sssi.Detail.GetAttribute("開課學分數"); } if (sssi.GradeYear == 3) { SubjectRecDict[key].CreditG3 = sssi.Detail.GetAttribute("開課學分數"); } } } } _bgWorker.ReportProgress(70); Dictionary <string, string> ClassTypeDict = GetClassTypeDict(); List <SubjectRec> SubjectRecList = new List <SubjectRec>(); foreach (SubjectRec rec in SubjectRecDict.Values) { // 資料轉換 if (rec.Required == "必修") { rec.Required = "1"; } else if (rec.Required == "選修") { rec.Required = "2"; } else { rec.Required = "3"; } if (rec.isCalc == "否") { rec.isCalc = "1"; } else if (rec.isCalc == "是") { rec.isCalc = "2"; } else { rec.isCalc = "3"; } if (!string.IsNullOrEmpty(rec.CourseType)) { if (ClassTypeDict.ContainsKey(rec.CourseType)) { rec.CourseType = ClassTypeDict[rec.CourseType]; } else { rec.CourseType = "13"; } } SubjectRecList.Add(rec); } // 寫入 Excel _wb = new Workbook(new MemoryStream(Properties.Resources.科目名冊樣板)); Worksheet wst1 = _wb.Worksheets["科目名冊封面"]; Worksheet wst2 = _wb.Worksheets["科目名冊"]; // 學年度 0,學期 1,學校代碼 2,學校種類 3,名冊別 4 wst1.Cells[1, 0].PutValue(_SchoolYear); wst1.Cells[1, 1].PutValue(_Semester); wst1.Cells[1, 2].PutValue(_SchoolCode); wst1.Cells[1, 3].PutValue(_SchoolType); wst1.Cells[1, 4].PutValue(_DocType); // 修課別 0,類別種類 1,領域分類 2,群別 3,科別 4,特色班/實驗班名稱 5,科目名稱 6,科目代碼 7, // 一年級學分 8,二年級學分 9,三年級學分 10,是否計算學分 11 int rowIdx = 1; foreach (SubjectRec rec in SubjectRecList) { wst2.Cells[rowIdx, 0].PutValue(rec.Required); wst2.Cells[rowIdx, 1].PutValue(rec.CourseType); wst2.Cells[rowIdx, 2].PutValue(rec.DomainType); wst2.Cells[rowIdx, 3].PutValue(rec.Group); wst2.Cells[rowIdx, 4].PutValue(rec.DLCCode); wst2.Cells[rowIdx, 5].PutValue(rec.SpcType); wst2.Cells[rowIdx, 6].PutValue(rec.Name); wst2.Cells[rowIdx, 7].PutValue(rec.Code); wst2.Cells[rowIdx, 8].PutValue(rec.CreditG1); wst2.Cells[rowIdx, 9].PutValue(rec.CreditG2); wst2.Cells[rowIdx, 10].PutValue(rec.CreditG3); wst2.Cells[rowIdx, 11].PutValue(rec.isCalc); rowIdx++; } }
void _bgWorker_DoWork(object sender, DoWorkEventArgs e) { _bgWorker.ReportProgress(1); List<SubjectScoreRec> SubjectScoreRecList = new List<SubjectScoreRec>(); Dictionary<string, string> DeptMappingDict = new Dictionary<string, string>(); Dictionary<string, List<string>> StudTagNameDict = new Dictionary<string, List<string>>(); // 科別對照 DeptMappingDict = Utility.GetDepartmetDict(); Dictionary<string, List<ConfigDataItem>> cdDict = _cd.GetConfigDataItemDict(); Dictionary<string, string> ClsMappingDict = new Dictionary<string, string>(); Dictionary<string, string> ClassNoMappingDict = new Dictionary<string, string>(); List<SHStudentTagRecord> SHStudentTagRecordList = SHStudentTag.SelectByStudentIDs(_StudentIDList); // 取得學期對照轉成大學繁星代碼 Dictionary<string, string> StudentSHClassCodDict = Utility.GetStudentClassCodeSeatNo(_StudentIDList, _SchoolYear, _Semester, false); // 班別對照 if (cdDict.ContainsKey("班別代碼")) { foreach (ConfigDataItem cdi in cdDict["班別代碼"]) { if (!ClsMappingDict.ContainsKey(cdi.TargetName)) ClsMappingDict.Add(cdi.TargetName, cdi.Value); } } // 取得學生類別 foreach (SHStudentTagRecord TRec in SHStudentTagRecordList) { if (!StudTagNameDict.ContainsKey(TRec.RefStudentID)) StudTagNameDict.Add(TRec.RefStudentID, new List<string>()); StudTagNameDict[TRec.RefStudentID].Add(TRec.FullName); } // 班級代碼對照 ClassNoMappingDict = Utility.GetLHClassCodeDict(); _bgWorker.ReportProgress(10); // 取得學生科別名稱 Dictionary<string, string> StudeDeptNameDict = Utility.GetStudDeptNameDict(_StudentIDList,_SchoolYear,_Semester); SmartSchool.Customization.Data.AccessHelper accHelper = new SmartSchool.Customization.Data.AccessHelper(); // 取得學生學期科目成績 List<SmartSchool.Customization.Data.StudentRecord> StudentRecList = accHelper.StudentHelper.GetStudents(_StudentIDList); accHelper.StudentHelper.FillSemesterSubjectScore(true, StudentRecList); // 取得及格標準 Dictionary<string, Dictionary<string, decimal>> passScoreDict = Utility.GetStudentApplyLimitDict(StudentRecList); Dictionary<string, string> StudGradYearDict = new Dictionary<string, string>(); foreach (SmartSchool.Customization.Data.StudentRecord rec in StudentRecList) { if (!StudGradYearDict.ContainsKey(rec.StudentID)) if(rec.RefClass!=null) StudGradYearDict.Add(rec.StudentID, rec.RefClass.GradeYear); } // 取得學期對照年為主 List<SHSemesterHistoryRecord> SemsH = SHSemesterHistory.SelectByStudentIDs(_StudentIDList); foreach (SHSemesterHistoryRecord rec in SemsH) { foreach (K12.Data.SemesterHistoryItem item in rec.SemesterHistoryItems) { if (item.SchoolYear == _SchoolYear && item.Semester == _Semester) { if (!StudGradYearDict.ContainsKey(item.RefStudentID)) StudGradYearDict.Add(item.RefStudentID, item.GradeYear.ToString()); else StudGradYearDict[item.RefStudentID] = item.GradeYear.ToString(); } } } _bgWorker.ReportProgress(30); foreach(SmartSchool.Customization.Data.StudentRecord studRec in StudentRecList) { string IDNumber = studRec.IDNumber.ToUpper(); string BirthDate = ""; DateTime dt; if(DateTime.TryParse(studRec.Birthday,out dt)) BirthDate = Utility.ConvertChDateString(dt); // 科/班/學程別代碼 string DCLCode = ""; if (StudeDeptNameDict.ContainsKey(studRec.StudentID)) { string name = StudeDeptNameDict[studRec.StudentID]; if (DeptMappingDict.ContainsKey(name)) DCLCode = DeptMappingDict[name]; } // 修課班別 string ClClassName = _ClassTypeCode; if (StudTagNameDict.ContainsKey(studRec.StudentID)) { foreach (string str in StudTagNameDict[studRec.StudentID]) { if (ClsMappingDict.ContainsKey(str)) ClClassName = ClsMappingDict[str]; } } // 修課班級 string ClassCode = ""; if(StudentSHClassCodDict.ContainsKey(studRec.StudentID)) { ClassCode = StudentSHClassCodDict[studRec.StudentID]; } else { if (K12.Data.School.DefaultSchoolYear == _SchoolYear.ToString() && K12.Data.School.DefaultSemester == _Semester.ToString()) { if (ClassNoMappingDict.ContainsKey(studRec.RefClass.ClassName)) ClassCode = ClassNoMappingDict[studRec.RefClass.ClassName]; } } #region 一般與補修 foreach (SmartSchool.Customization.Data.StudentExtension.SemesterSubjectScoreInfo sssi in studRec.SemesterSubjectScoreList) { if (sssi.SchoolYear == _SchoolYear && sssi.Semester == _Semester) { SubjectScoreRec ssr = new SubjectScoreRec(); ssr.IDNumber = IDNumber; ssr.StudentID = studRec.StudentID; ssr.BirthDate = BirthDate; ssr.SubjectCode = sssi.Detail.GetAttribute("科目") + "_" + sssi.Detail.GetAttribute("開課學分數") + "_" + sssi.Detail.GetAttribute("修課必選修") + "_" + sssi.Detail.GetAttribute("修課校部訂") + "_" + sssi.Detail.GetAttribute("開課分項類別") + "_" + sssi.Detail.GetAttribute("不計學分"); ssr.ReSubjectCode = sssi.Detail.GetAttribute("科目") + "_" + sssi.Detail.GetAttribute("開課學分數") + "_" + sssi.Detail.GetAttribute("修課必選修") + "_" + sssi.Detail.GetAttribute("修課校部訂") + "_" + sssi.Detail.GetAttribute("開課分項類別") + "_" + sssi.Detail.GetAttribute("不計學分"); ssr.ScSubjectCode = sssi.Detail.GetAttribute("科目") + "_" + sssi.Detail.GetAttribute("開課學分數") + "_" + sssi.Detail.GetAttribute("修課必選修") + "_" + sssi.Detail.GetAttribute("修課校部訂") + "_" + sssi.Detail.GetAttribute("開課分項類別") + "_" + sssi.Detail.GetAttribute("不計學分"); ssr.SubjectCredit = sssi.Detail.GetAttribute("開課學分數"); // 預設值 -1 ssr.Score = ssr.ScScore = ssr.ReScore = ssr.MuScore = "-1"; string GrStr = ""; if (StudGradYearDict.ContainsKey(studRec.StudentID)) GrStr = StudGradYearDict[studRec.StudentID] + "_及"; decimal ds, dsre, dsmu, dssc, passScore = 60; // 及格標準 if (passScoreDict[studRec.StudentID].ContainsKey(GrStr)) passScore = passScoreDict[studRec.StudentID][GrStr]; if (decimal.TryParse(sssi.Detail.GetAttribute("原始成績"), out ds)) { if (ds < passScore) ssr.Score = "*" + string.Format("{0:##0.00}", ds); else ssr.Score = string.Format("{0:##0.00}", ds); } if (decimal.TryParse(sssi.Detail.GetAttribute("重修成績"), out dsre)) { if (dsre < passScore) ssr.ReScore = "*" + string.Format("{0:##0.00}", dsre); else ssr.ReScore = string.Format("{0:##0.00}", dsre); } if (decimal.TryParse(sssi.Detail.GetAttribute("補考成績"), out dsmu)) { if (dsmu < passScore) ssr.MuScore = "*" + string.Format("{0:##0.00}", dsmu); else ssr.MuScore = string.Format("{0:##0.00}", dsmu); } if (decimal.TryParse(sssi.Detail.GetAttribute("原始成績"), out dssc)) { if (dssc < passScore) ssr.ScScore = "*" + string.Format("{0:##0.00}", dssc); else ssr.ScScore = string.Format("{0:##0.00}", dssc); } ssr.isScScore = ssr.isReScore = false; if (sssi.Detail.GetAttribute("是否補修成績") == "是") { ssr.isScScore = true; ssr.ScSubjectGradeYearSemester = sssi.GradeYear.ToString() + sssi.Semester.ToString(); } ssr.DCLCode = DCLCode; ssr.ClassName = ClassCode; ssr.ClCode = ClClassName; SubjectScoreRecList.Add(ssr); } } #endregion #region 重修處理 foreach (SmartSchool.Customization.Data.StudentExtension.SemesterSubjectScoreInfo sssi in studRec.SemesterSubjectScoreList) { int chkSy = 0, chkSS = 0; if (sssi.Detail.GetAttribute("重修學年度") != "" && sssi.Detail.GetAttribute("重修學期") != "") { int sy, ss; if (int.TryParse(sssi.Detail.GetAttribute("重修學年度"), out sy)) chkSy = sy; if (int.TryParse(sssi.Detail.GetAttribute("重修學期"), out ss)) chkSS = ss; } // 以有填寫重修學年度學期為主 if (chkSy == _SchoolYear && chkSS == _Semester) { SubjectScoreRec ssr = new SubjectScoreRec(); ssr.IDNumber = IDNumber; ssr.StudentID = studRec.StudentID; ssr.BirthDate = BirthDate; ssr.SubjectCode = sssi.Detail.GetAttribute("科目") + "_" + sssi.Detail.GetAttribute("開課學分數") + "_" + sssi.Detail.GetAttribute("修課必選修") + "_" + sssi.Detail.GetAttribute("修課校部訂") + "_" + sssi.Detail.GetAttribute("開課分項類別") + "_" + sssi.Detail.GetAttribute("不計學分"); ssr.ReSubjectCode = sssi.Detail.GetAttribute("科目") + "_" + sssi.Detail.GetAttribute("開課學分數") + "_" + sssi.Detail.GetAttribute("修課必選修") + "_" + sssi.Detail.GetAttribute("修課校部訂") + "_" + sssi.Detail.GetAttribute("開課分項類別") + "_" + sssi.Detail.GetAttribute("不計學分"); ssr.ScSubjectCode = sssi.Detail.GetAttribute("科目") + "_" + sssi.Detail.GetAttribute("開課學分數") + "_" + sssi.Detail.GetAttribute("修課必選修") + "_" + sssi.Detail.GetAttribute("修課校部訂") + "_" + sssi.Detail.GetAttribute("開課分項類別") + "_" + sssi.Detail.GetAttribute("不計學分"); ssr.SubjectCredit = sssi.Detail.GetAttribute("開課學分數"); // 預設值 -1 ssr.Score = ssr.ScScore = ssr.ReScore = ssr.MuScore = "-1"; string GrStr = ""; if (StudGradYearDict.ContainsKey(studRec.StudentID)) GrStr = StudGradYearDict[studRec.StudentID] + "_及"; decimal ds, dsre, dsmu, dssc, passScore = 60; // 及格標準 if (passScoreDict[studRec.StudentID].ContainsKey(GrStr)) passScore = passScoreDict[studRec.StudentID][GrStr]; if (decimal.TryParse(sssi.Detail.GetAttribute("原始成績"), out ds)) { if (ds < passScore) ssr.Score = "*" + string.Format("{0:##0.00}", ds); else ssr.Score = string.Format("{0:##0.00}", ds); } if (decimal.TryParse(sssi.Detail.GetAttribute("重修成績"), out dsre)) { if (dsre < passScore) ssr.ReScore = "*" + string.Format("{0:##0.00}", dsre); else ssr.ReScore = string.Format("{0:##0.00}", dsre); } if (decimal.TryParse(sssi.Detail.GetAttribute("補考成績"), out dsmu)) { if (dsmu < passScore) ssr.MuScore = "*" + string.Format("{0:##0.00}", dsmu); else ssr.MuScore = string.Format("{0:##0.00}", dsmu); } if (decimal.TryParse(sssi.Detail.GetAttribute("原始成績"), out dssc)) { if (dssc < passScore) ssr.ScScore = "*" + string.Format("{0:##0.00}", dssc); else ssr.ScScore = string.Format("{0:##0.00}", dssc); } ssr.isScScore = ssr.isReScore = false; // 使用學年度為該學年度學期 ssr.ReSubjectSchoolYearSemester = string.Format("{0:000}", sssi.SchoolYear) + sssi.Semester; ssr.isReScore = true; ssr.DCLCode = DCLCode; ssr.ClassName = ClassCode; ssr.ClCode = ClClassName; SubjectScoreRecList.Add(ssr); } } #endregion } _bgWorker.ReportProgress(80); // 讀取樣版並寫入 Excel _wb = new Workbook(new MemoryStream(Properties.Resources.成績名冊樣版)); Worksheet wst1 = _wb.Worksheets["成績名冊封面"]; Worksheet wst2 = _wb.Worksheets["成績名冊"]; Worksheet wst3 = _wb.Worksheets["補修成績名冊"]; Worksheet wst4 = _wb.Worksheets["重修成績名冊"]; // wst1:學校代碼 0,學年度 1,學期 2,名冊別 3 wst1.Cells[1, 0].PutValue(_SchoolCode); wst1.Cells[1, 1].PutValue(_SchoolYear); wst1.Cells[1, 2].PutValue(_Semester); wst1.Cells[1, 3].PutValue(_DocType); // wst2:身分證號 0,出生日期 1,科目代碼 2,科目學分 3,修課科/班/學程別代碼 4,修課班級 5,修課班別 6,原始成績 7,補考成績 8 int rowIdx = 1; foreach(SubjectScoreRec ssr in SubjectScoreRecList) { // 跳過補修 if (ssr.isScScore ) continue; wst2.Cells[rowIdx, 0].PutValue(ssr.IDNumber); wst2.Cells[rowIdx, 1].PutValue(ssr.BirthDate); wst2.Cells[rowIdx, 2].PutValue(ssr.SubjectCode); wst2.Cells[rowIdx, 3].PutValue(ssr.SubjectCredit); wst2.Cells[rowIdx, 4].PutValue(ssr.DCLCode); wst2.Cells[rowIdx, 5].PutValue(ssr.ClassName); wst2.Cells[rowIdx, 6].PutValue(ssr.ClCode); wst2.Cells[rowIdx, 7].PutValue(ssr.Score); wst2.Cells[rowIdx, 8].PutValue(ssr.MuScore); rowIdx++; } // wst3:身分證號 0,出生日期 1,補修科目代碼 2,補修科目開設年級及學期(選填) 3,科目學分 4,修課科/班/學程別代碼 5,修課班級 6,修課班別 7,補修成績 8,補考成績 9 rowIdx = 1; foreach(SubjectScoreRec ssr in SubjectScoreRecList) { // 補修成績 if(ssr.isScScore) { wst3.Cells[rowIdx, 0].PutValue(ssr.IDNumber); wst3.Cells[rowIdx, 1].PutValue(ssr.BirthDate); wst3.Cells[rowIdx, 2].PutValue(ssr.ScSubjectCode); wst3.Cells[rowIdx, 3].PutValue(ssr.ScSubjectGradeYearSemester); wst3.Cells[rowIdx, 4].PutValue(ssr.SubjectCredit); wst3.Cells[rowIdx, 5].PutValue(ssr.DCLCode); wst3.Cells[rowIdx, 6].PutValue(ssr.ClassName); wst3.Cells[rowIdx, 7].PutValue(ssr.ClCode); wst3.Cells[rowIdx, 8].PutValue(ssr.ScScore); wst3.Cells[rowIdx, 9].PutValue(ssr.MuScore); rowIdx++; } } // wst4:身分證號 0,出生日期 1,重修科目代碼 2,重修科目開設年級及學期 3,科目學分 4,修課科/班/學程別代碼 5,修課班級 6,修課班別 7,重修成績 8 rowIdx = 1; foreach (SubjectScoreRec ssr in SubjectScoreRecList) { // 有重修成績學年度學期 if(ssr.isReScore) { wst4.Cells[rowIdx, 0].PutValue(ssr.IDNumber); wst4.Cells[rowIdx, 1].PutValue(ssr.BirthDate); wst4.Cells[rowIdx, 2].PutValue(ssr.ReSubjectCode); wst4.Cells[rowIdx, 3].PutValue(ssr.ReSubjectSchoolYearSemester); wst4.Cells[rowIdx, 4].PutValue(ssr.SubjectCredit); wst4.Cells[rowIdx, 5].PutValue(ssr.DCLCode); wst4.Cells[rowIdx, 6].PutValue(ssr.ClassName); wst4.Cells[rowIdx, 7].PutValue(ssr.ClCode); wst4.Cells[rowIdx, 8].PutValue(ssr.ReScore); rowIdx++; } } _bgWorker.ReportProgress(100); }