/// <summary> /// 計算學年科目成績 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void buttonItem4_Click(object sender, EventArgs e) { ISubjectCalcPostProcess obj = FISCA.InteractionService.DiscoverAPI <ISubjectCalcPostProcess>(); if (obj != null) { obj.ShowConfigForm(); } new CalcSemesterSubjectScoreWizard(SelectType.Student).ShowDialog(); }
void bkw_DoWork(object sender, DoWorkEventArgs e) { warningList.Clear();// 將警告名單清空 BackgroundWorker bkw = ((BackgroundWorker)sender); int schoolyear = (int)((object[])e.Argument)[0]; int semester = (int)((object[])e.Argument)[1]; AccessHelper helper = (AccessHelper)((object[])e.Argument)[2]; List <StudentRecord> selectedStudents = (List <StudentRecord>)((object[])e.Argument)[3]; bool registerSemesterHistory = (bool)((object[])e.Argument)[4]; bkw.ReportProgress(1, null); WearyDogComputer computer = new WearyDogComputer(); int packageSize = 50; int packageCount = 0; List <StudentRecord> package = null; List <List <StudentRecord> > packages = new List <List <StudentRecord> >(); foreach (StudentRecord s in selectedStudents) { if (packageCount == 0) { package = new List <StudentRecord>(packageSize); packages.Add(package); packageCount = packageSize; packageSize += 50; if (packageSize > _MaxPackageSize) { packageSize = _MaxPackageSize; } } package.Add(s); packageCount--; } double maxStudents = selectedStudents.Count; if (maxStudents == 0) { maxStudents = 1; } double computedStudents = 0; bool allPass = true; foreach (List <StudentRecord> var in packages) { #region 處理學期歷程 if (registerSemesterHistory) { if (var.Count > 0) { helper.StudentHelper.FillField("SemesterHistory", var); List <StudentRecord> editList = new List <StudentRecord>(); #region 檢查並編及每個選取學生的學期歷程 foreach (StudentRecord stu in var) { int gyear; if (stu.RefClass != null && int.TryParse(stu.RefClass.GradeYear, out gyear)) { XmlElement semesterHistory = (XmlElement)stu.Fields["SemesterHistory"]; XmlElement historyElement = null; foreach (XmlElement history in new DSXmlHelper(semesterHistory).GetElements("History")) { int year, sems, gradeyear; if ( int.TryParse(history.GetAttribute("SchoolYear"), out year) && int.TryParse(history.GetAttribute("Semester"), out sems) && year == schoolyear && sems == semester ) { historyElement = history; } } // 小郭, 2013/12/26 string className = string.Empty; string deptName = string.Empty; string seatNo = string.Empty; string teacherName = string.Empty; if (stu.RefClass != null) { className = stu.RefClass.ClassName; deptName = stu.RefClass.Department; if (stu.RefClass.RefTeacher != null) { teacherName = stu.RefClass.RefTeacher.TeacherName; } } seatNo = stu.SeatNo; if (historyElement == null) { historyElement = semesterHistory.OwnerDocument.CreateElement("History"); historyElement.SetAttribute("SchoolYear", "" + schoolyear); historyElement.SetAttribute("Semester", "" + semester); historyElement.SetAttribute("GradeYear", "" + gyear); // 小郭, 2013/12/26 historyElement.SetAttribute("ClassName", className); historyElement.SetAttribute("DeptName", deptName); historyElement.SetAttribute("SeatNo", seatNo); historyElement.SetAttribute("Teacher", teacherName); semesterHistory.AppendChild(historyElement); editList.Add(stu); } else { #region 判斷那些欄位需要更新 bool isRevised = false; // 小郭, 2013/12/26 if (historyElement.GetAttribute("GradeYear") != "" + gyear) { historyElement.SetAttribute("GradeYear", "" + gyear); // editList.Add(stu); isRevised = true; } // 小郭, 2013/12/26 if (!string.IsNullOrEmpty(className) && historyElement.GetAttribute("ClassName") != className) { historyElement.SetAttribute("ClassName", className); isRevised = true; } if (!string.IsNullOrEmpty(deptName) && historyElement.GetAttribute("DeptName") != deptName) { historyElement.SetAttribute("DeptName", deptName); isRevised = true; } if (!string.IsNullOrEmpty(seatNo) && historyElement.GetAttribute("SeatNo") != seatNo) { historyElement.SetAttribute("SeatNo", seatNo); isRevised = true; } if (!string.IsNullOrEmpty(teacherName) && historyElement.GetAttribute("Teacher") != teacherName) { historyElement.SetAttribute("Teacher", teacherName); isRevised = true; } if (isRevised == true) { editList.Add(stu); } #endregion 判斷那些欄位需要更新 } } } #endregion string req = "<UpdateStudentList>"; foreach (StudentRecord stu in var) { int tryParseInt; req += "<Student><Field><SemesterHistory>" + ((XmlElement)stu.Fields["SemesterHistory"]).InnerXml + "</SemesterHistory></Field><Condition><ID>" + stu.StudentID + "</ID></Condition></Student>"; } req += "</UpdateStudentList>"; DSRequest dsreq = new DSRequest(req); SmartSchool.Feature.EditStudent.Update(dsreq); } } #endregion computedStudents += var.Count; Dictionary <StudentRecord, List <string> > errormessages = computer.FillSemesterSubjectCalcScore(schoolyear, semester, helper, var); if (errormessages.Count > 0) { allPass = false; } if (bkw.CancellationPending) { break; } else { bkw.ReportProgress((int)((computedStudents * 100.0) / maxStudents), errormessages); } } //異常課程提示清單 if (computer._WarningList != null && computer._WarningList.Count > 0) { hasWarning = true; foreach (string s in computer._WarningList) // 這邊先整理好有疑慮的課程警告名單,等全部都做完後一併處理 { warningList.Add(s); } } if (allPass) { ISubjectCalcPostProcess obj = FISCA.InteractionService.DiscoverAPI <ISubjectCalcPostProcess>(); if (obj != null) { obj.PostProcess(schoolyear, semester, selectedStudents); } e.Result = selectedStudents; } else { e.Result = null; } }
void bkw_DoWork(object sender, DoWorkEventArgs e) { warningList.Clear();// 將警告名單清空 BackgroundWorker bkw = ((BackgroundWorker)sender); int schoolyear = (int)((object[])e.Argument)[0]; int semester = (int)((object[])e.Argument)[1]; AccessHelper helper = (AccessHelper)((object[])e.Argument)[2]; List <StudentRecord> selectedStudents = (List <StudentRecord>)((object[])e.Argument)[3]; bool registerSemesterHistory = (bool)((object[])e.Argument)[4]; bkw.ReportProgress(1, null); WearyDogComputer computer = new WearyDogComputer(); int packageSize = 50; int packageCount = 0; List <StudentRecord> package = null; List <List <StudentRecord> > packages = new List <List <StudentRecord> >(); // 學生系統編號 List <string> studIDList = new List <string>(); // 學生課程規畫表群組代碼對照用 Dictionary <string, string> studGDCCodeDict = new Dictionary <string, string>(); foreach (StudentRecord s in selectedStudents) { if (packageCount == 0) { package = new List <StudentRecord>(packageSize); packages.Add(package); packageCount = packageSize; packageSize += 50; if (packageSize > _MaxPackageSize) { packageSize = _MaxPackageSize; } } package.Add(s); packageCount--; } double maxStudents = selectedStudents.Count; if (maxStudents == 0) { maxStudents = 1; } double computedStudents = 0; bool allPass = true; foreach (List <StudentRecord> var in packages) { #region 處理學期歷程 if (registerSemesterHistory) { if (var.Count > 0) { // 取得學生群組代碼 studIDList.Clear(); studGDCCodeDict.Clear(); foreach (StudentRecord rec in var) { studIDList.Add(rec.StudentID); } try { QueryHelper qh = new QueryHelper(); // 取得學生群組代碼 string qry = "SELECT " + "student.id AS student_id" + ",COALESCE(student.gdc_code,class.gdc_code) AS gdc_code " + "FROM student " + "LEFT OUTER JOIN " + "class " + " ON student.ref_class_id = class.id " + " WHERE student.id IN(" + string.Join(",", studIDList.ToArray()) + ");"; DataTable dt = qh.Select(qry); foreach (DataRow dr in dt.Rows) { string sid = dr["student_id"] + ""; string groupCode = dr["gdc_code"] + ""; if (!studGDCCodeDict.ContainsKey(sid)) { studGDCCodeDict.Add(sid, groupCode); } } } catch (Exception ex) { Console.WriteLine(ex.Message); } helper.StudentHelper.FillField("SemesterHistory", var); List <StudentRecord> editList = new List <StudentRecord>(); #region 檢查並編及每個選取學生的學期歷程 foreach (StudentRecord stu in var) { int gyear; if (stu.RefClass != null && int.TryParse(stu.RefClass.GradeYear, out gyear)) { XmlElement semesterHistory = (XmlElement)stu.Fields["SemesterHistory"]; XmlElement historyElement = null; foreach (XmlElement history in new DSXmlHelper(semesterHistory).GetElements("History")) { int year, sems, gradeyear; if ( int.TryParse(history.GetAttribute("SchoolYear"), out year) && int.TryParse(history.GetAttribute("Semester"), out sems) && year == schoolyear && sems == semester ) { historyElement = history; } } // 小郭, 2013/12/26 string className = string.Empty; string deptName = string.Empty; string seatNo = string.Empty; string teacherName = string.Empty; // 2021/2/19 string StudentNumber = string.Empty; string GDCCode = string.Empty; string ClassID = ""; if (stu.RefClass != null) { className = stu.RefClass.ClassName; ClassID = stu.RefClass.ClassID; deptName = stu.RefClass.Department; if (stu.RefClass.RefTeacher != null) { teacherName = stu.RefClass.RefTeacher.TeacherName; } } // 座號 seatNo = stu.SeatNo; // 學號 StudentNumber = stu.StudentNumber; // 課程群組代碼(由課程規劃表來) GDCCode = ""; if (studGDCCodeDict.ContainsKey(stu.StudentID)) { GDCCode = studGDCCodeDict[stu.StudentID]; } if (historyElement == null) { historyElement = semesterHistory.OwnerDocument.CreateElement("History"); historyElement.SetAttribute("SchoolYear", "" + schoolyear); historyElement.SetAttribute("Semester", "" + semester); historyElement.SetAttribute("GradeYear", "" + gyear); // 小郭, 2013/12/26 historyElement.SetAttribute("ClassName", className); historyElement.SetAttribute("DeptName", deptName); historyElement.SetAttribute("SeatNo", seatNo); historyElement.SetAttribute("Teacher", teacherName); historyElement.SetAttribute("GDCCode", GDCCode); historyElement.SetAttribute("ClassID", ClassID); historyElement.SetAttribute("StudentNumber", StudentNumber); semesterHistory.AppendChild(historyElement); editList.Add(stu); } else { #region 判斷那些欄位需要更新 bool isRevised = false; // 小郭, 2013/12/26 if (historyElement.GetAttribute("GradeYear") != "" + gyear) { historyElement.SetAttribute("GradeYear", "" + gyear); // editList.Add(stu); isRevised = true; } // 小郭, 2013/12/26 if (!string.IsNullOrEmpty(className) && historyElement.GetAttribute("ClassName") != className) { historyElement.SetAttribute("ClassName", className); isRevised = true; } if (!string.IsNullOrEmpty(deptName) && historyElement.GetAttribute("DeptName") != deptName) { historyElement.SetAttribute("DeptName", deptName); isRevised = true; } if (!string.IsNullOrEmpty(seatNo) && historyElement.GetAttribute("SeatNo") != seatNo) { historyElement.SetAttribute("SeatNo", seatNo); isRevised = true; } if (!string.IsNullOrEmpty(teacherName) && historyElement.GetAttribute("Teacher") != teacherName) { historyElement.SetAttribute("Teacher", teacherName); isRevised = true; } // 課程群組代碼 if (!string.IsNullOrEmpty(GDCCode) && historyElement.GetAttribute("GDCCode") != GDCCode) { historyElement.SetAttribute("GDCCode", GDCCode); isRevised = true; } // 學號 if (!string.IsNullOrEmpty(StudentNumber) && historyElement.GetAttribute("StudentNumber") != StudentNumber) { historyElement.SetAttribute("StudentNumber", StudentNumber); isRevised = true; } // 班級編號 if (!string.IsNullOrEmpty(ClassID) && historyElement.GetAttribute("ClassID") != ClassID) { historyElement.SetAttribute("ClassID", ClassID); isRevised = true; } if (isRevised == true) { editList.Add(stu); } #endregion 判斷那些欄位需要更新 } } } #endregion string req = "<UpdateStudentList>"; foreach (StudentRecord stu in var) { int tryParseInt; req += "<Student><Field><SemesterHistory>" + ((XmlElement)stu.Fields["SemesterHistory"]).InnerXml + "</SemesterHistory></Field><Condition><ID>" + stu.StudentID + "</ID></Condition></Student>"; } req += "</UpdateStudentList>"; DSRequest dsreq = new DSRequest(req); SmartSchool.Feature.EditStudent.Update(dsreq); } } #endregion computedStudents += var.Count; Dictionary <StudentRecord, List <string> > errormessages = computer.FillSemesterSubjectCalcScore(schoolyear, semester, helper, var); if (errormessages.Count > 0) { allPass = false; } if (bkw.CancellationPending) { break; } else { bkw.ReportProgress((int)((computedStudents * 100.0) / maxStudents), errormessages); } } //異常課程提示清單 if (computer._WarningList != null && computer._WarningList.Count > 0) { hasWarning = true; foreach (string s in computer._WarningList) // 這邊先整理好有疑慮的課程警告名單,等全部都做完後一併處理 { warningList.Add(s); } } if (allPass) { ISubjectCalcPostProcess obj = FISCA.InteractionService.DiscoverAPI <ISubjectCalcPostProcess>(); if (obj != null) { obj.PostProcess(schoolyear, semester, selectedStudents); } e.Result = selectedStudents; } else { e.Result = null; } }