void _bkWorker_DoWork(object sender, DoWorkEventArgs e) { //// 學生紀錄 //_StudRecList = Student.SelectByIDs(K12.Presentation.NLDPanels.Student.SelectedSource); // 學期對照 _SemesterHistoryRecordList = SemesterHistory.SelectByStudentIDs(K12.Presentation.NLDPanels.Student.SelectedSource); }
/// <summary> /// 取得所有資料 /// </summary> private void SetStudentBoxs() { List <string> StudentIDList = K12.Presentation.NLDPanels.Student.SelectedSource; ListStudent = Student.SelectByIDs(StudentIDList); //取得學生 ListStudent.Sort(new Comparison <StudentRecord>(ParseStudent)); ListPhone = Phone.SelectByStudentIDs(StudentIDList); //取得電話資料 ListParent = Parent.SelectByStudentIDs(StudentIDList); //取得監護人資料 ListAddress = Address.SelectByStudentIDs(StudentIDList); //取得地址資料 ListMerit = Merit.SelectByStudentIDs(StudentIDList); //取得獎勵資料(一對多) ListDeMerit = Demerit.SelectByStudentIDs(StudentIDList); //取得懲戒資料(一對多) ListMoralScore = SHMoralScore.SelectByStudentIDs(StudentIDList); //取得日常生活表現資料(一對多) ListUpdataRecord = UpdateRecord.SelectByStudentIDs(StudentIDList); //取得異動資料(一對多) ListJHSemesterHistory = SemesterHistory.SelectByStudentIDs(StudentIDList); //取得學生學期歷程 //ListAssnCode = _accessHelper.Select<AssnCode>(); //取得所有社團記錄 ListAutoSummary = AutoSummary.Select(StudentIDList, null); ListAutoSummary.Sort(SortSchoolYearSemester); }
/// <summary> /// 轉換學期歷程 /// </summary> private void ConvertStudentHistoryDict() { List <SemesterHistoryRecord> semsHis = SemesterHistory.SelectByStudentIDs(_StudentIDList); foreach (SemesterHistoryRecord shrec in semsHis) { foreach (SemesterHistoryItem shi in shrec.SemesterHistoryItems) { SchoolYearSemester sys = new SchoolYearSemester(); sys.SchoolYear = shi.SchoolYear.ToString(); sys.Semester = shi.Semester.ToString(); sys.GradeYear = shi.GradeYear.ToString(); if (!_StudentHistoryDict.ContainsKey(shi.RefStudentID)) { _StudentHistoryDict.Add(shi.RefStudentID, new List <SchoolYearSemester>()); } _StudentHistoryDict[shi.RefStudentID].Add(sys); } } }
private void btnPrint_Click(object sender, EventArgs e) { if (K12.Presentation.NLDPanels.Student.SelectedSource.Count < 1) { FISCA.Presentation.Controls.MsgBox.Show("請先選擇學生"); return; } btnPrint.Enabled = false; filter f = new filter { GradeType = comboBoxEx2.Text }; Document document = new Document(); BackgroundWorker bgw = new BackgroundWorker(); Dictionary <StudentRecord, List <string> > errCheck = new Dictionary <StudentRecord, List <string> >(); bgw.DoWork += delegate { #region DoWork Byte[] template; if (K12.Presentation.NLDPanels.Student.SelectedSource.Count <= 0) { return; } List <string> sids = K12.Presentation.NLDPanels.Student.SelectedSource; Dictionary <string, SemesterHistoryRecord> dshr = SemesterHistory.SelectByStudentIDs(sids).ToDictionary(x => x.RefStudentID, x => x); Dictionary <string, StudentRecord> dsr = Student.SelectByIDs(sids).ToDictionary(x => x.ID, x => x); Dictionary <string, SemesterScoreRecord> dssr = SemesterScore.SelectByStudentIDs(sids).ToDictionary(x => x.RefStudentID + "#" + x.SchoolYear + "#" + x.Semester, x => x); DataTable dt = tool._Q.Select("select ref_student_id,entrance_date,leaving_date from $jhcore_bilingual.studentrecordext where ref_student_id in ('" + string.Join("','", sids) + "')"); Dictionary <string, edld> dedld = new Dictionary <string, edld>(); DateTime tmp; foreach (DataRow row in dt.Rows) { if (!dedld.ContainsKey("" + row["ref_student_id"])) { dedld.Add("" + row["ref_student_id"], new edld() { }); } if (DateTime.TryParse("" + row["entrance_date"], out tmp)) { dedld["" + row["ref_student_id"]].entrance_date = tmp; } if (DateTime.TryParse("" + row["leaving_date"], out tmp)) { dedld["" + row["ref_student_id"]].leaving_date = tmp; } } List <string> gradeYearList; int domainDicKey; switch (f.GradeType) { case "3~6": case "6": gradeYearList = new List <string> { "3", "4", "5", "6" }; domainDicKey = 6; template = (ReportConfiguration3_6.Template != null) //單頁範本 ? ReportConfiguration3_6.Template.ToBinary() : new Campus.Report.ReportTemplate(Properties.Resources._6樣版, Campus.Report.TemplateType.Word).ToBinary(); Choose3to6Grade = true; break; case "7~8": case "8": gradeYearList = new List <string> { "7", "8" }; domainDicKey = 8; template = (ReportConfiguration7_8.Template != null) //單頁範本 ? ReportConfiguration7_8.Template.ToBinary() : new Campus.Report.ReportTemplate(Properties.Resources._8樣版, Campus.Report.TemplateType.Word).ToBinary(); Choose7to8Grade = true; break; case "9~12": case "12": gradeYearList = new List <string> { "9", "10", "11", "12" }; domainDicKey = 12; template = (ReportConfiguration9_12.Template != null) //單頁範本 ? ReportConfiguration9_12.Template.ToBinary() : new Campus.Report.ReportTemplate(Properties.Resources._9_12_grade樣板, Campus.Report.TemplateType.Word).ToBinary(); break; default: return; } List <CourseGradeB.Tool.Domain> cgbdl = CourseGradeB.Tool.DomainDic[domainDicKey]; // 2016/5/18 穎驊新增功能,因原本3~6年級其Domain 並無English、Western Social Studies ,會造成如果沒有成績,而不顯示N/A直接空白的問題 if (Choose3to6Grade) { English.Hours = 6; English.Name = "English"; English.ShortName = "English"; WesternSocialStudies.Hours = 2; WesternSocialStudies.Name = "Western Social Studies"; WesternSocialStudies.ShortName = "W.S.S"; cgbdl.Add(English); cgbdl.Add(WesternSocialStudies); } // 2016/5/20(蔡英文上任)穎驊新增功能,因原本7~8年級其Domain 並無Elective ,會造成如果沒有成績,而不顯示N/A直接空白的問題 if (Choose7to8Grade) { Elective.Hours = 2; Elective.Name = "Elective"; Elective.ShortName = "Elective"; cgbdl.Add(Elective); } cgbdl.Sort(delegate(CourseGradeB.Tool.Domain x, CourseGradeB.Tool.Domain y) { return(x.DisplayOrder.CompareTo(y.DisplayOrder)); }); //int domainCount; Dictionary <string, string> NationalityMapping = K12.EduAdminDataMapping.Utility.GetNationalityMappingDict(); Dictionary <string, object> mailmerge = new Dictionary <string, object>(); GradeCumulateGPA gcgpa = new GradeCumulateGPA(); foreach (var studentID in dshr.Keys) {//學生 System.IO.Stream docStream = new System.IO.MemoryStream(template); Document each = new Document(docStream); //DocumentBuilder db = new DocumentBuilder(each); //Table table = (Table)each.GetChild(NodeType.Table, 1, true); //table.AllowAutoFit = true; //not work,why ? // 2016/4/28 取得樣板上,所有的功能變數,以利以後核對使用。 string[] fieldNames = each.MailMerge.GetFieldNames(); grade lastGrade = null; mailmerge.Clear(); mailmerge.Add("列印日期", DateTime.Today.ToString("MMMM d, yyyy", new System.Globalization.CultureInfo("en-US"))); #region 學生資料 StudentRecord sr = dsr[studentID]; mailmerge.Add("學生系統編號", sr.ID); mailmerge.Add("學號", sr.StudentNumber); mailmerge.Add("姓名", sr.Name); mailmerge.Add("英文名", sr.EnglishName); string gender; switch (sr.Gender) { case "男": gender = "Male"; break; case "女": gender = "Female"; break; default: gender = sr.Gender; break; } mailmerge.Add("性別", gender); mailmerge.Add("國籍", sr.Nationality); if (NationalityMapping.ContainsKey(sr.Nationality)) { mailmerge["國籍"] = NationalityMapping[sr.Nationality]; } mailmerge.Add("生日", sr.Birthday.HasValue ? sr.Birthday.Value.ToString("d-MMMM-yyyy", new System.Globalization.CultureInfo("en-US")) : ""); string esy = "", edog = ""; if (dedld.ContainsKey(studentID)) { if (dedld[studentID].entrance_date != null) { esy = dedld[studentID].entrance_date.Value.ToString("MMMM-yyyy", new System.Globalization.CultureInfo("en-US")); } if (dedld[studentID].leaving_date != null) { edog = dedld[studentID].leaving_date.Value.ToString("MMMM-yyyy", new System.Globalization.CultureInfo("en-US")); } } mailmerge.Add("入學日期", esy); mailmerge.Add("預計畢業日期", edog); //mailmerge.Add("Registrar", row.Value[0].SeatNo); //mailmerge.Add("Dean", row.Value[0].SeatNo); //mailmerge.Add("Principal", row.Value[0].SeatNo); #endregion #region 學生成績 Dictionary <int, grade> dgrade = new Dictionary <int, grade>(); #region 整理學生成績及年級 foreach (SemesterHistoryItem shi in dshr[studentID].SemesterHistoryItems) { if (!gradeYearList.Contains("" + shi.GradeYear)) { continue; } int _gradeYear = shi.GradeYear; string key = shi.RefStudentID + "#" + shi.SchoolYear + "#" + shi.Semester; if (!dgrade.ContainsKey(_gradeYear)) { dgrade.Add(_gradeYear, new grade() { grade_year = shi.GradeYear, school_year = shi.SchoolYear }); } if (shi.Semester == 1) { dgrade[_gradeYear].semester = 1; if (dssr.ContainsKey(key)) { dgrade[_gradeYear].sems1 = dssr[key]; } } else if (shi.Semester == 2) { dgrade[_gradeYear].semester = 2; if (dssr.ContainsKey(key)) { dgrade[_gradeYear].sems2 = dssr[key]; } } } #endregion mailmerge.Add("GPA", ""); int gradeCount = 1; foreach (string gy in gradeYearList) {//級別_ //群 , 科目 , 分數 //Dictionary<string, Dictionary<string, course>> dcl = new Dictionary<string, Dictionary<string, course>>(); Dictionary <string, List <SubjectScore> > dcl = new Dictionary <string, List <SubjectScore> >(); mailmerge.Add(string.Format("級別{0}", gradeCount), gy); mailmerge.Add(string.Format("學年度{0}", gradeCount), ""); if (dgrade.ContainsKey(int.Parse(gy))) { grade g = dgrade[int.Parse(gy)]; mailmerge[string.Format("學年度{0}", gradeCount)] = (g.school_year + 1911) + "-" + (g.school_year + 1912); foreach (var semScore in new SemesterScoreRecord[] { g.sems1, g.sems2 }) { if (semScore != null) { foreach (var subjectScore in semScore.Subjects.Values) { //if (!dcl.ContainsKey(subjectScore.Domain)) // dcl.Add(subjectScore.Domain, new Dictionary<string, course>()); //if (!dcl[subjectScore.Domain].ContainsKey(subjectScore.Subject)) // dcl[subjectScore.Domain].Add(subjectScore.Subject, new course()); //switch (subjectScore.Semester) //{ // case 1: // dcl[subjectScore.Domain][subjectScore.Subject].sems1_title = subjectScore.Subject; // dcl[subjectScore.Domain][subjectScore.Subject].sems1_score = subjectScore.Score.HasValue ? Math.Round(subjectScore.Score.Value, 0, MidpointRounding.AwayFromZero) : 0; // break; // case 2: // dcl[subjectScore.Domain][subjectScore.Subject].sems2_title = subjectScore.Subject; // dcl[subjectScore.Domain][subjectScore.Subject].sems2_score = subjectScore.Score.HasValue ? Math.Round(subjectScore.Score.Value, 0, MidpointRounding.AwayFromZero) : 0; // break; //} if (!dcl.ContainsKey(subjectScore.Domain)) { dcl.Add(subjectScore.Domain, new List <SubjectScore>()); } subjectScore.Score = subjectScore.Score.HasValue ? Math.Round(subjectScore.Score.Value, 0, MidpointRounding.AwayFromZero) : 0; dcl[subjectScore.Domain].Add(subjectScore); } } } //使用學期歷程最後一筆的學年度學期 if (g.sems1 != null) { mailmerge["GPA"] = g.sems1.CumulateGPA; } if (g.sems2 != null) { mailmerge["GPA"] = g.sems2.CumulateGPA; } lastGrade = g; } //檢查預設清單,缺漏處補回空資料 foreach (CourseGradeB.Tool.Domain domain in cgbdl) { //if (!dcl.ContainsKey(domain.Name)) // dcl.Add(domain.Name, new Dictionary<string, course>()); if (!dcl.ContainsKey(domain.Name)) { dcl.Add(domain.Name, new List <SubjectScore>()); } } foreach (var domain in dcl.Keys) { foreach (var semester in new int[] { 1, 2 }) { //群 int courseCount = 1; dcl[domain].Sort((SubjectScore s1, SubjectScore s2) => { return((s1.Subject + " (" + s1.Credit + ")").CompareTo(s2.Subject + " (" + s2.Credit + ")")); }); foreach (var item in dcl[domain]) { if (item.Semester == semester) { mailmerge.Add(string.Format("{0}_級{1}_學期{2}_科目{3}", domain.FixFieldName(), gradeCount, semester, courseCount), item.Subject + " (" + item.Credit + ")"); mailmerge.Add(string.Format("{0}_級{1}_學期{2}_科目級別{3}", domain.FixFieldName(), gradeCount, semester, courseCount), "Level:" + item.Level); mailmerge.Add(string.Format("{0}_級{1}_學期{2}_科目成績{3}", domain.FixFieldName(), gradeCount, semester, courseCount), "" + item.Score); // 2016/4/28 穎驊筆記,下面為檢察功能,fieldName為目前樣板的所有功能變數,假如樣版沒有完整的對應功能變數,會加入錯誤訊息提醒。 if (!fieldNames.Contains(string.Format("{0}_級{1}_學期{2}_科目成績{3}", domain.FixFieldName(), gradeCount, semester, courseCount))) { if (!errCheck.ContainsKey(sr)) { errCheck.Add(sr, new List <string>()); } errCheck[sr].Add("合併欄位「" + string.Format("{0}_級{1}_學期{2}_科目成績{3}", domain.FixFieldName(), gradeCount, semester, courseCount) + "」在樣板中不存在(" + item.SchoolYear + "學年度第" + item.Semester + "學期 科目名稱 " + item.Subject + ")。"); } courseCount++; //mailmerge.Add(string.Format("{0}_級{1}_學期1_科目{2}", domain.FixFieldName(), gradeCount, courseCount), item.sems1_title); //mailmerge.Add(string.Format("{0}_級{1}_學期2_科目{2}", domain.FixFieldName(), gradeCount, courseCount), item.sems2_title); ////都存在且相同才需要合併 //if (item.sems1_title != null && item.sems2_title != null && item.sems1_title == item.sems2_title) //{ // mailmerge[string.Format("{0}_級{1}_學期1_科目{2}", domain.FixFieldName(), gradeCount, courseCount)] = new mailmergeSpecial() { cellmerge = Aspose.Words.Tables.CellMerge.First, value = item.sems1_title }; // mailmerge[string.Format("{0}_級{1}_學期2_科目{2}", domain.FixFieldName(), gradeCount, courseCount)] = new mailmergeSpecial() { cellmerge = Aspose.Words.Tables.CellMerge.Previous, value = item.sems2_title }; //} //mailmerge.Add(string.Format("{0}_級{1}_學期1_科目成績{2}", domain.FixFieldName(), gradeCount, courseCount), // item.sems1_title != null ? "" + item.sems1_score : "N/A"); //mailmerge.Add(string.Format("{0}_級{1}_學期2_科目成績{2}", domain.FixFieldName(), gradeCount, courseCount), // item.sems2_title != null ? "" + item.sems2_score : "N/A"); //courseCount++; } } for (; courseCount <= 3; courseCount++) { mailmerge.Add(string.Format("{0}_級{1}_學期{2}_科目{3}", domain.FixFieldName(), gradeCount, semester, courseCount), ""); mailmerge.Add(string.Format("{0}_級{1}_學期{2}_科目級別{3}", domain.FixFieldName(), gradeCount, semester, courseCount), ""); mailmerge.Add(string.Format("{0}_級{1}_學期{2}_科目成績{3}", domain.FixFieldName(), gradeCount, semester, courseCount), "N/A"); //mailmerge.Add(string.Format("{0}_級{1}_學期1_科目{2}", domain.FixFieldName(), gradeCount, courseCount), new mailmergeSpecial() { cellmerge = Aspose.Words.Tables.CellMerge.First, value = "" }); //mailmerge.Add(string.Format("{0}_級{1}_學期2_科目{2}", domain.FixFieldName(), gradeCount, courseCount), new mailmergeSpecial() { cellmerge = Aspose.Words.Tables.CellMerge.Previous, value = "" }); //mailmerge.Add(string.Format("{0}_級{1}_學期1_科目成績{2}", domain.FixFieldName(), gradeCount, courseCount), "N/A"); //mailmerge.Add(string.Format("{0}_級{1}_學期2_科目成績{2}", domain.FixFieldName(), gradeCount, courseCount), "N/A"); } } for (var courseCount = 1; courseCount <= 3; courseCount++) { var subjName1 = "" + mailmerge[string.Format("{0}_級{1}_學期{2}_科目{3}", domain.FixFieldName(), gradeCount, 1, courseCount)]; var subjName2 = "" + mailmerge[string.Format("{0}_級{1}_學期{2}_科目{3}", domain.FixFieldName(), gradeCount, 2, courseCount)]; if (subjName1 == subjName2 || subjName1 == "" || subjName2 == "") { mailmerge[string.Format("{0}_級{1}_學期1_科目{2}", domain.FixFieldName(), gradeCount, courseCount)] = new mailmergeSpecial() { cellmerge = Aspose.Words.Tables.CellMerge.First, value = subjName1 }; mailmerge[string.Format("{0}_級{1}_學期2_科目{2}", domain.FixFieldName(), gradeCount, courseCount)] = new mailmergeSpecial() { cellmerge = Aspose.Words.Tables.CellMerge.Previous, value = subjName1 }; } if (subjName1 != "" && subjName2 == "") { mailmerge[string.Format("{0}_級{1}_學期1_科目{2}", domain.FixFieldName(), gradeCount, courseCount)] = new mailmergeSpecial() { cellmerge = Aspose.Words.Tables.CellMerge.First, value = subjName1 }; mailmerge[string.Format("{0}_級{1}_學期2_科目{2}", domain.FixFieldName(), gradeCount, courseCount)] = new mailmergeSpecial() { cellmerge = Aspose.Words.Tables.CellMerge.Previous, value = subjName1 }; } if (subjName1 == "" && subjName2 != "") { mailmerge[string.Format("{0}_級{1}_學期1_科目{2}", domain.FixFieldName(), gradeCount, courseCount)] = new mailmergeSpecial() { cellmerge = Aspose.Words.Tables.CellMerge.First, value = subjName2 }; mailmerge[string.Format("{0}_級{1}_學期2_科目{2}", domain.FixFieldName(), gradeCount, courseCount)] = new mailmergeSpecial() { cellmerge = Aspose.Words.Tables.CellMerge.Previous, value = subjName2 }; } var subjLevel1 = "" + mailmerge[string.Format("{0}_級{1}_學期{2}_科目級別{3}", domain.FixFieldName(), gradeCount, 1, courseCount)]; var subjLevel2 = "" + mailmerge[string.Format("{0}_級{1}_學期{2}_科目級別{3}", domain.FixFieldName(), gradeCount, 2, courseCount)]; if (subjLevel1 == subjLevel2) { mailmerge[string.Format("{0}_級{1}_學期1_科目級別{2}", domain.FixFieldName(), gradeCount, courseCount)] = new mailmergeSpecial() { cellmerge = Aspose.Words.Tables.CellMerge.First, value = subjLevel1 }; mailmerge[string.Format("{0}_級{1}_學期2_科目級別{2}", domain.FixFieldName(), gradeCount, courseCount)] = new mailmergeSpecial() { cellmerge = Aspose.Words.Tables.CellMerge.Previous, value = subjLevel1 }; } if (subjLevel1 != "" && subjLevel2 == "") { mailmerge[string.Format("{0}_級{1}_學期1_科目級別{2}", domain.FixFieldName(), gradeCount, courseCount)] = new mailmergeSpecial() { cellmerge = Aspose.Words.Tables.CellMerge.First, value = subjLevel1 }; mailmerge[string.Format("{0}_級{1}_學期2_科目級別{2}", domain.FixFieldName(), gradeCount, courseCount)] = new mailmergeSpecial() { cellmerge = Aspose.Words.Tables.CellMerge.Previous, value = subjLevel1 }; } if (subjLevel1 == "" && subjLevel2 != "") { mailmerge[string.Format("{0}_級{1}_學期1_科目級別{2}", domain.FixFieldName(), gradeCount, courseCount)] = new mailmergeSpecial() { cellmerge = Aspose.Words.Tables.CellMerge.First, value = subjLevel2 }; mailmerge[string.Format("{0}_級{1}_學期2_科目級別{2}", domain.FixFieldName(), gradeCount, courseCount)] = new mailmergeSpecial() { cellmerge = Aspose.Words.Tables.CellMerge.Previous, value = subjLevel2 }; } } } gradeCount++; } GradeCumulateGPARecord gcgpar; mailmerge.Add("級最高GPA", ""); mailmerge.Add("級平均GPA", ""); if (lastGrade != null && sr.Class != null) { //if (lastGrade.semester != null) //{ gcgpar = gcgpa.GetGradeCumulateGPARecord(lastGrade.school_year, lastGrade.semester, lastGrade.grade_year); if (gcgpar != null) { mailmerge["級最高GPA"] = decimal.Round(gcgpar.MaxGPA, 2, MidpointRounding.AwayFromZero); mailmerge["級平均GPA"] = decimal.Round(gcgpar.AvgGPA, 2, MidpointRounding.AwayFromZero); } //} } #endregion // 正式把MailMerge資料 給填上去,2015/4/27 驊紀錄 each.MailMerge.FieldMergingCallback = new MailMerge_MergeField(); each.MailMerge.Execute(mailmerge.Keys.ToArray(), mailmerge.Values.ToArray()); each.MailMerge.DeleteFields(); document.Sections.Add(document.ImportNode(each.FirstSection, true)); //2016/4/28 以下是恩正給穎驊的程式碼,可以輸出本程式MergeField 所有功能變數的縮寫成一個獨立Doc檔 // 在未來如果要要大量更動新增表格很方便可以直接複製貼上使用,如要使用,將上方原本的輸出MergeField、下面的//document.Sections.RemoveAt(0);註解掉即可。 //{ // Document doc = new Document(); // DocumentBuilder bu = new DocumentBuilder(doc); // bu.MoveToDocumentStart(); // bu.CellFormat.Borders.LineStyle = LineStyle.Single; // bu.CellFormat.VerticalAlignment = CellVerticalAlignment.Center; // Table table = bu.StartTable(); // foreach (String col in mailmerge.Keys) // { // bu.InsertCell(); // bu.CellFormat.Width = 15; // bu.InsertField("MERGEFIELD " + col + @" \* MERGEFORMAT", "«.»"); // bu.ParagraphFormat.Alignment = ParagraphAlignment.Center; // bu.InsertCell(); // bu.CellFormat.Width = 125; // bu.Write(col); // bu.ParagraphFormat.Alignment = ParagraphAlignment.Left; // bu.EndRow(); // } // table.AllowAutoFit = false; // bu.EndTable(); // document = doc; // break; //} } document.Sections.RemoveAt(0); #endregion }; bgw.RunWorkerCompleted += delegate { if (errCheck.Count > 0) { StringBuilder sb = new StringBuilder(); foreach (var stuRec in errCheck.Keys) { foreach (var err in errCheck[stuRec]) { sb.AppendLine(string.Format("{0} {1}({2}) {3}:{4}", stuRec.StudentNumber, stuRec.Class != null ? stuRec.Class.Name : "", stuRec.SeatNo, stuRec.Name, err)); } } MessageBox.Show(sb.ToString()); } #region Completed btnPrint.Enabled = true; //if (e.Error != null) //{ // MessageBox.Show(e.Error.Message); // return; //} Document inResult = document; try { SaveFileDialog SaveFileDialog1 = new SaveFileDialog(); SaveFileDialog1.Filter = "Word (*.doc)|*.doc|所有檔案 (*.*)|*.*"; SaveFileDialog1.FileName = "國外成績單"; if (SaveFileDialog1.ShowDialog() == DialogResult.OK) { inResult.Save(SaveFileDialog1.FileName); Process.Start(SaveFileDialog1.FileName); FISCA.Presentation.MotherForm.SetStatusBarMessage(SaveFileDialog1.FileName + ",列印完成!!"); //Update_ePaper ue = new Update_ePaper(new List<Document> { inResult }, current, PrefixStudent.學號); //ue.ShowDialog(); } else { FISCA.Presentation.Controls.MsgBox.Show("檔案未儲存"); return; } } catch (Exception exp) { string msg = "檔案儲存錯誤,請檢查檔案是否開啟中!!"; FISCA.Presentation.Controls.MsgBox.Show(msg + "\n" + exp.Message); FISCA.Presentation.MotherForm.SetStatusBarMessage(msg + "\n" + exp.Message); } #endregion }; bgw.RunWorkerAsync(); }
void BGW_DoWork(object sender, DoWorkEventArgs e) { //取得所選社團 List <string> SelectCLUBIDList = ClubAdmin.Instance.SelectedSource; //取得參與學生的社團學期成績 List <ResultScoreRecord> ResultList = helper.Select <ResultScoreRecord>("ref_club_id in ('" + string.Join("','", SelectCLUBIDList) + "')"); List <string> StudentIDList = new List <string>(); foreach (ResultScoreRecord rsr in ResultList) { if (!StudentIDList.Contains(rsr.RefStudentID)) { StudentIDList.Add(rsr.RefStudentID); } } #region 取得學生基本資料 List <StudentRecord> StudentRecordList = Student.SelectByIDs(StudentIDList); Dictionary <string, StudentRecord> StudentDic = new Dictionary <string, StudentRecord>(); foreach (StudentRecord each in StudentRecordList) { if (each.Status == StudentRecord.StudentStatus.一般 || each.Status == StudentRecord.StudentStatus.延修) { if (!StudentDic.ContainsKey(each.ID)) { StudentDic.Add(each.ID, each); } } } #endregion #region 學期歷程 List <SemesterHistoryRecord> SemesterList = SemesterHistory.SelectByStudentIDs(StudentIDList); //學生ID : SemesterHistoryRecord Dictionary <string, SemesterHistoryRecord> SemesterDic = new Dictionary <string, SemesterHistoryRecord>(); foreach (SemesterHistoryRecord each in SemesterList) { if (!SemesterDic.ContainsKey(each.RefStudentID)) { SemesterDic.Add(each.RefStudentID, each); } } #endregion Workbook wb = new Workbook(); Worksheet ws = wb.Worksheets[0]; //建立標頭 TitleList = GetTitle(); int TitleIndex = 0; foreach (string each in TitleList) { ws.Cells[0, TitleIndex].PutValue(each); TitleIndex++; } int RowIndex = 1; int ColumnIndex = 0; foreach (ResultScoreRecord Result in ResultList) { if (StudentDic.ContainsKey(Result.RefStudentID)) { #region 每筆資料 StudentRecord sr = StudentDic[Result.RefStudentID]; ColumnIndex = 0; ws.Cells[RowIndex, ColumnIndex].PutValue(sr.ID); ColumnIndex++; ws.Cells[RowIndex, ColumnIndex].PutValue(sr.StudentNumber); ColumnIndex++; ws.Cells[RowIndex, ColumnIndex].PutValue(string.IsNullOrEmpty(sr.RefClassID) ? "" : sr.Class.Name); ColumnIndex++; ws.Cells[RowIndex, ColumnIndex].PutValue(sr.SeatNo.HasValue ? sr.SeatNo.Value.ToString() : ""); ColumnIndex++; //ws.Cells[RowIndex, ColumnIndex].PutValue(""); //ColumnIndex++; ws.Cells[RowIndex, ColumnIndex].PutValue(sr.Name); ColumnIndex++; #region 其它 string 取得學分 = "是"; string 科目級別 = ""; string 成績年級 = ""; //if (Result.ResultScore.HasValue) //{ // if (Result.ResultScore.Value >= 60) // { // 取得學分 = "是"; // } //} if (SemesterDic.ContainsKey(Result.RefStudentID)) { SemesterHistoryRecord shr = SemesterDic[Result.RefStudentID]; foreach (SemesterHistoryItem each in shr.SemesterHistoryItems) { if (Result.SchoolYear == each.SchoolYear && Result.Semester == each.Semester) { 科目級別 = GetSchoolYearByGradeYear(each); 成績年級 = each.GradeYear.ToString(); } } } #endregion ws.Cells[RowIndex, ColumnIndex].PutValue("聯課活動"); ColumnIndex++; ws.Cells[RowIndex, ColumnIndex].PutValue(科目級別); ColumnIndex++; ws.Cells[RowIndex, ColumnIndex].PutValue("" + Result.SchoolYear); ColumnIndex++; ws.Cells[RowIndex, ColumnIndex].PutValue("" + Result.Semester); ColumnIndex++; ws.Cells[RowIndex, ColumnIndex].PutValue("0"); ColumnIndex++; ws.Cells[RowIndex, ColumnIndex].PutValue("必修"); ColumnIndex++; ws.Cells[RowIndex, ColumnIndex].PutValue("學業"); ColumnIndex++; ws.Cells[RowIndex, ColumnIndex].PutValue(成績年級); ColumnIndex++; ws.Cells[RowIndex, ColumnIndex].PutValue("部訂"); ColumnIndex++; ws.Cells[RowIndex, ColumnIndex].PutValue(Result.ResultScore.HasValue ? Result.ResultScore.Value.ToString() : ""); ColumnIndex++; ws.Cells[RowIndex, ColumnIndex].PutValue(Result.ResultScore.HasValue ? Result.ResultScore.Value.ToString() : ""); ColumnIndex++; ws.Cells[RowIndex, ColumnIndex].PutValue(取得學分); ColumnIndex++; RowIndex++; #endregion } } e.Result = wb; }
void _bgWork_DoWork(object sender, DoWorkEventArgs e) { _DataDict.Clear(); _MappingField.Clear(); List <string> StudentIDList = K12.Presentation.NLDPanels.Student.SelectedSource; List <DAO.StudentInfo> StudInfoList = _StudentInfoTransfer.GetStudentInfoList(StudentIDList); // 取得畫面所選學生學習歷程 Global._StudentSemesterHistoryItemDict.Clear(); foreach (SemesterHistoryRecord shr in SemesterHistory.SelectByStudentIDs(StudentIDList)) { // 依照年級、學期排序後加入 Global._StudentSemesterHistoryItemDict.Add(shr.RefStudentID, (from data in shr.SemesterHistoryItems orderby data.GradeYear, data.Semester select data).ToList()); } // 取得日常生活表現具體建議 Global._ABCard_StudentTextScoreDict = Utility.GetABCard_StudentTextScoreDict(StudentIDList); // 畢業資料 Global._ABCard_StudentGraduateDict = Utility.GetStudentGraduateDict(StudentIDList); // 異動資料 Global._ABCard_StudentUpdateRecDict = Utility.GetStudentUpdateRecDict(StudentIDList); //獎懲資料 Global._ABCard_StudentMDRecordDict = Utility.GetStudentMDRecDict(StudentIDList); // 參加社團 Global._ABCard_StudentSpecCourseDict = Utility.GetABCard_StudentSpecCourseDict(StudentIDList); // 擔任幹部 Global._ABCard_StudentTheCadreDict = Utility.GetABCard_StudentTheCadreDict(StudentIDList); // 學生領域成績與畢業成績 Global._AB_StudSemsDomainScoreDict = Utility.GetAB_StudSemsDomainScoreDict(StudentIDList); // 輔導個案會議 Global._AB_CaseMeetingRecordToABRptDataDict = Utility.ParseCaseMeetingRecordToABRptData(StudentIDList); // 輔導優先關懷 Global._AB_CareRecordToABRptDataDict = Utility.ParseCareRecordToABRptData(StudentIDList); // 輔導晤談紀錄 Global._AB_InterViewDataToABRptDataDict = Utility.ParseInterViewDataToABRptData(StudentIDList); // 學生入學照片 Global._AB_StudentFreshmanDict = Photo.SelectFreshmanPhoto(StudentIDList); // 學生畢業照片 Global._AB_StudentGraduateDict = Photo.SelectGraduatePhoto(StudentIDList); // 取得答案 Dictionary <string, List <DAO.AnswerPkey> > _AnsData = _ABCardPrintManager.GetAnswers(StudentIDList); List <string> QuetionFieldList = _ABCardPrintManager.GetMappingField(); _MappingField.AddRange(QuetionFieldList); Global._StudentNumberList.Clear(); // studID foreach (string studID in StudentIDList) { Dictionary <string, string> _ansDict = new Dictionary <string, string> (); // 處理學生基本資料、缺曠獎懲、.. DAO.StudentInfo studInfo = null; foreach (DAO.StudentInfo si in StudInfoList.Where(x => x.StudentID == studID)) { studInfo = si; } List <string> temp1 = new List <string>(); if (studInfo != null) { Dictionary <string, string> baseDict = new Dictionary <string, string>(); baseDict.Add("學校中文名稱", studInfo.SchoolName); temp1.Clear(); foreach (KeyValuePair <string, string> data in studInfo.AttendanceDict) { baseDict.Add("B_缺曠_" + data.Key, data.Value); temp1.Add(data.Key + "(" + data.Value + ")"); } if (temp1.Count > 0) { baseDict.Add("B_缺曠", string.Join(",", temp1.ToArray())); } baseDict.Add("B_入學前學校名稱", studInfo.BeforeEnrollSchoolName); baseDict.Add("B_入學年", studInfo.BeforeEnrollSchoolYear); baseDict.Add("B_出生日期", studInfo.Birthday); baseDict.Add("B_出生日期民國格式", studInfo.BirthdayTW); baseDict.Add("B_出生地", studInfo.Birthplace); baseDict.Add("B_畢業年月", studInfo.GraduationYearMonth); baseDict.Add("B_身分證號", studInfo.IDNumber); baseDict.Add("B_聯絡地址", studInfo.MailingAddress); baseDict.Add("B_聯絡電話", studInfo.MailingPhone); baseDict.Add("B_性別", studInfo.Gender); temp1.Clear(); foreach (KeyValuePair <string, string> data in studInfo.MeritDict) { baseDict.Add("B_獎懲_" + data.Key, data.Value); temp1.Add(data.Key + "(" + data.Value + ")"); } if (temp1.Count > 0) { baseDict.Add("B_獎懲", string.Join(",", temp1.ToArray())); } baseDict.Add("B_姓名", studInfo.Name); baseDict.Add("B_戶籍地址", studInfo.PermanentAddress); baseDict.Add("B_戶籍電話", studInfo.PermanentPhone); baseDict.Add("B_學號", studInfo.StudentNumber); Global._StudentNumberList.Add(studInfo.StudentNumber); baseDict.Add("GL_異動紀錄", string.Join(";", studInfo.UpdateRecordList.ToArray())); foreach (KeyValuePair <string, string> data in baseDict) { if (!_MappingField.Contains(data.Key)) { _MappingField.Add(data.Key); } _ansDict.Add(data.Key, data.Value); } } // 而外加入需要填在這合併名稱,處理在DocumentMerge // 加入學期歷程 _ansDict.Add("學習歷程", studID); _ansDict.Add("學期對照", studID); _MappingField.Add("學習歷程"); _MappingField.Add("學期對照"); // 加入導師評語與具體建議 _ansDict.Add("導師評語", studID); _ansDict.Add("具體建議", studID); _MappingField.Add("導師評語"); _MappingField.Add("具體建議"); // 加入畢業資料 _ansDict.Add("畢業資料", studID); _MappingField.Add("畢業資料"); // 加入異動資料 _ansDict.Add("異動資料", studID); _MappingField.Add("異動資料"); // 加入獎懲資料 _ansDict.Add("獎懲資料", studID); _MappingField.Add("獎懲資料"); // 加入參加社團 _ansDict.Add("參加社團", studID); _MappingField.Add("參加社團"); // 加入擔任幹部 _ansDict.Add("擔任幹部", studID); _MappingField.Add("擔任幹部"); // 加入學生領域與畢業成績 _ansDict.Add("學習領域與畢業成績", studID); _MappingField.Add("學習領域與畢業成績"); // 加入學生輔導個案會議 _ansDict.Add("輔導個案會議", studID); _MappingField.Add("輔導個案會議"); _MappingField.Add("輔導個案會議其它內容"); // 加入學生輔導優先關懷 _ansDict.Add("輔導優先關懷", studID); _MappingField.Add("輔導優先關懷"); _MappingField.Add("輔導優先關懷其它內容"); // 加入學生輔導晤談紀錄 _ansDict.Add("輔導晤談紀錄", studID); _MappingField.Add("輔導晤談紀錄"); _MappingField.Add("輔導晤談紀錄其它內容"); // 加入學生入學照片 _ansDict.Add("入學照片", studID); _MappingField.Add("入學照片"); // 加入學生畢業照片 _ansDict.Add("畢業照片", studID); _MappingField.Add("畢業照片"); if (_AnsData.ContainsKey(studID)) { // 加入測驗紀錄 _ansDict.Add("測驗紀錄", studID); _MappingField.Add("測驗紀錄"); foreach (string qField in QuetionFieldList) { foreach (DAO.AnswerPkey ap in _AnsData[studID]) { //string qqField = ap.Question.GetField(); if (ap.Question.QType == "grid") { string Idx1 = "GR_" + ap.Question.GetField(); if (!_ansDict.ContainsKey(Idx1)) { _ansDict.Add(Idx1, ap.dataElement.ToString()); if (!_MappingField.Contains(Idx1)) { _MappingField.Add(Idx1); } } int rowIdx = 1; foreach (XElement elm in ap.dataElement.Elements("Item")) { foreach (XElement elm2 in elm.Elements("Field")) { string key = ap.Question.GetField() + "_" + elm2.Attribute("key").Value + "R"; if (key == qField) { if (!_ansDict.ContainsKey(qField)) { string newField = qField + rowIdx; if (elm2.Attribute("value") == null) { _ansDict.Add(newField, ""); } else { _ansDict.Add(newField, elm2.Attribute("value").Value); } if (!_MappingField.Contains(newField)) { _MappingField.Add(newField); } } } } rowIdx++; } } else { //處理單一分割 string strVal = ""; if (ap.dataElement.Attribute("value") != null) { strVal = ap.dataElement.Attribute("value").Value; } if (ap.Question.GetField() == qField) { if (!_ansDict.ContainsKey(qField)) { _ansDict.Add(qField, strVal); } } // 處理組合在一起 if (qField.IndexOf("G") == 0) { if (ap.Question.GetFieldG() == qField) { if (strVal != "") { strVal = ap.Question.QLabel + ":" + strVal; } if (!_ansDict.ContainsKey(qField)) { _ansDict.Add(qField, strVal); } else { if (strVal != "") { _ansDict[qField] += "," + strVal; } } } } } } } } _DataDict.Add(_ansDict); } }
//覆寫 public override void InitializeExport(SmartSchool.API.PlugIn.Export.ExportWizard wizard) { List <string> FieldList = new List <string>(); FieldList.Add("科目"); //聯課活動 FieldList.Add("科目級別"); FieldList.Add("學年度"); //目前欄位 FieldList.Add("學期"); //目前欄位 FieldList.Add("學分數"); FieldList.Add("必選修"); FieldList.Add("分項類別"); FieldList.Add("成績年級"); FieldList.Add("校部訂"); FieldList.Add("科目成績"); //目前欄位 FieldList.Add("原始成績"); //目前欄位 FieldList.Add("取得學分"); FieldList.Add("社團名稱"); //目前欄位 FieldList.Add("社團成績"); //目前欄位 FieldList.Add("幹部記錄"); //目前欄位 wizard.ExportableFields.AddRange(FieldList); wizard.ExportPackage += (sender, e) => { //取得學生清單 AccessHelper helper = new AccessHelper(); string strCondition = string.Empty; foreach (string ID in e.List) { strCondition += strCondition == string.Empty ? "'" + ID + "'" : ",'" + ID + "'"; } List <ResultScoreRecord> records = helper.Select <ResultScoreRecord>("ref_student_id in (" + strCondition + ")"); //取得學生學期歷程 List <SemesterHistoryRecord> SemesterList = SemesterHistory.SelectByStudentIDs(e.List); //學生ID : SemesterHistoryRecord Dictionary <string, SemesterHistoryRecord> SemesterDic = new Dictionary <string, SemesterHistoryRecord>(); foreach (SemesterHistoryRecord each in SemesterList) { if (!SemesterDic.ContainsKey(each.RefStudentID)) { SemesterDic.Add(each.RefStudentID, each); } } //records.Sort(); for (int i = 0; i < records.Count; i++) { RowData row = new RowData(); row.ID = records[i].RefStudentID; foreach (string field in e.ExportFields) { if (wizard.ExportableFields.Contains(field)) { string 取得學分 = "否"; string 科目級別 = ""; string 成績年級 = ""; if (records[i].ResultScore.HasValue) { if (records[i].ResultScore.Value >= 60) { 取得學分 = "是"; } } if (SemesterDic.ContainsKey(records[i].RefStudentID)) { SemesterHistoryRecord shr = SemesterDic[records[i].RefStudentID]; foreach (SemesterHistoryItem each in shr.SemesterHistoryItems) { if (records[i].SchoolYear == each.SchoolYear && records[i].Semester == each.Semester) { 科目級別 = GetSchoolYearByGradeYear(each); 成績年級 = each.GradeYear.ToString(); } } } switch (field) { case "科目": row.Add(field, "聯課活動"); break; //需要依據學期歷程進行判斷 case "科目級別": row.Add(field, 科目級別); break; case "學年度": row.Add(field, "" + records[i].SchoolYear); break; case "學期": row.Add(field, "" + records[i].Semester); break; case "學分數": row.Add(field, "0"); break; case "必選修": row.Add(field, "必修"); break; case "分項類別": row.Add(field, "學業"); break; case "成績年級": row.Add(field, 成績年級); break; case "校部訂": row.Add(field, "部訂"); break; case "科目成績": row.Add(field, records[i].ResultScore.HasValue ? records[i].ResultScore.Value.ToString() : ""); break; case "原始成績": row.Add(field, records[i].ResultScore.HasValue ? records[i].ResultScore.Value.ToString() : ""); break; case "取得學分": row.Add(field, 取得學分); break; case "社團名稱": row.Add(field, records[i].ClubName); break; case "社團成績": row.Add(field, records[i].ResultScore.HasValue ? records[i].ResultScore.Value.ToString() : ""); break; case "幹部記錄": row.Add(field, records[i].CadreName); break; } } } e.Items.Add(row); } }; }
void _bkWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { _DelRecList.Clear(); _NewRecList.Clear(); // 刪除 if (_isDelRec) { foreach (SemesterHistoryRecord shRec in _SemesterHistoryRecordList) { SemesterHistoryItem shiRec = null; foreach (SemesterHistoryItem shi in shRec.SemesterHistoryItems) { if (shi.SchoolYear == _SelSchoolYear && shi.Semester == _SelSemester) { shiRec = shi; } } if (shiRec != null) { shRec.SemesterHistoryItems.Remove(shiRec); _DelRecList.Add(shRec); } } if (_DelRecList.Count > 0) { if (FISCA.Presentation.Controls.MsgBox.Show("請問是否刪除" + _SelSchoolYear + "學年度 第" + _SelSemester + "學期,共" + _DelRecList.Count + "筆資料?", "刪除學期對照", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == System.Windows.Forms.DialogResult.Yes) { SemesterHistory.Update(_DelRecList); FISCA.Presentation.Controls.MsgBox.Show(_DelRecList.Count + "筆資料刪除完成."); } } else { FISCA.Presentation.Controls.MsgBox.Show("沒有刪除的資料."); } btnDel.Enabled = true; } else { // 新增或修改 int insertCount = 0, updateCount = 0; foreach (SemesterHistoryRecord shRec in _SemesterHistoryRecordList) { bool hasData = false; foreach (SemesterHistoryItem shi in shRec.SemesterHistoryItems) { if (shi.SchoolYear == _SelSchoolYear && shi.Semester == _SelSemester) { shi.GradeYear = _SelGradeYear; hasData = true; updateCount++; } } if (hasData == false) { SemesterHistoryItem shiNew = new SemesterHistoryItem(); shiNew.SchoolYear = _SelSchoolYear; shiNew.Semester = _SelSemester; shiNew.GradeYear = _SelGradeYear; shRec.SemesterHistoryItems.Add(shiNew); insertCount++; } } if (updateCount > 0) { if (FISCA.Presentation.Controls.MsgBox.Show("已有" + updateCount + "筆資料,請問是否覆蓋?", "覆蓋學期對照", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == System.Windows.Forms.DialogResult.Yes) { SemesterHistory.Update(_SemesterHistoryRecordList); FISCA.Presentation.Controls.MsgBox.Show("已新增" + insertCount + "筆資料,已覆蓋" + updateCount + "筆資料."); } } else { if (insertCount > 0) { SemesterHistory.Update(_SemesterHistoryRecordList); FISCA.Presentation.Controls.MsgBox.Show("已新增" + insertCount + "筆資料."); } } btnRun.Enabled = true; } }