void _BGWResitList_DoWork(object sender, DoWorkEventArgs e)
        {
            object[] objectValue = (object[])e.Argument;
            int      schoolyear  = (int)objectValue[0];
            int      semester    = (int)objectValue[1];

            _BGWResitList.ReportProgress(0);

            #region 取得所有學生以及補考資訊

            AccessHelper         helper      = new AccessHelper();
            List <StudentRecord> allStudents = new List <StudentRecord>();
            List <ClassRecord>   allClasses  = helper.ClassHelper.GetAllClass();
            WearyDogComputer     computer    = new WearyDogComputer();

            double currentClass = 1;
            double totalClasses = allClasses.Count;

            foreach (ClassRecord aClass in allClasses)
            {
                List <StudentRecord> classStudents = aClass.Students;
                computer.FillSemesterSubjectScoreInfoWithResit(helper, true, classStudents);
                allStudents.AddRange(classStudents);

                _BGWResitList.ReportProgress((int)(currentClass++ *90.0 / totalClasses));
            }

            double currentStudent = 1;
            double totalStudents  = allStudents.Count;

            #endregion

            #region 產生表格並填入資料

            Workbook template = new Workbook();
            template.Open(new MemoryStream(Properties.Resources.補考名單_依科目), FileFormatType.Excel2003);
            Workbook wb = new Workbook();
            wb.Copy(template);
            Worksheet ws = wb.Worksheets[0];
            ws.Name = "未達補考標準名單";

            Range eachSubject = template.Worksheets[0].Cells.CreateRange(0, 4, false);
            Range eachRow     = template.Worksheets[0].Cells.CreateRange(4, 1, false);

            int index = 0;

            Dictionary <string, Dictionary <string, string> >         subjectInfo        = new Dictionary <string, Dictionary <string, string> >();
            Dictionary <string, List <Dictionary <string, string> > > subjectStudentList = new Dictionary <string, List <Dictionary <string, string> > >();

            foreach (StudentRecord aStudent in allStudents)
            {
                string className     = aStudent.RefClass.ClassName;
                string seatNo        = aStudent.SeatNo;
                string studentName   = aStudent.StudentName;
                string studentNumber = aStudent.StudentNumber;

                //aStudent.SemesterSubjectScoreList.Sort(SortBySemesterSubjectScore);

                foreach (SemesterSubjectScoreInfo info in aStudent.SemesterSubjectScoreList)
                {
                    if (info.SchoolYear == schoolyear && info.Semester == semester && !info.Pass)
                    {
                        if (info.Detail.GetAttribute("達補考標準") == "否")
                        {
                            string sl = info.Subject + "_" + info.Level + "_" + info.CreditDec();

                            if (!subjectInfo.ContainsKey(sl))
                            {
                                subjectInfo.Add(sl, new Dictionary <string, string>());
                                subjectInfo[sl].Add("科目", info.Subject);
                                subjectInfo[sl].Add("級別", info.Level);
                                subjectInfo[sl].Add("學分", info.CreditDec().ToString());
                            }

                            if (!subjectStudentList.ContainsKey(sl))
                            {
                                subjectStudentList.Add(sl, new List <Dictionary <string, string> >());
                            }

                            Dictionary <string, string> data = new Dictionary <string, string>();
                            data.Add("班級", className);
                            data.Add("座號", seatNo);
                            data.Add("姓名", studentName);
                            data.Add("學號", studentNumber);
                            data.Add("必選修", info.Require ? "必修" : "選修");
                            data.Add("校部訂", info.Detail.HasAttribute("修課校部訂") ? info.Detail.GetAttribute("修課校部訂") : "");
                            data.Add("補考標準", info.Detail.HasAttribute("補考標準") ? info.Detail.GetAttribute("補考標準") : "");
                            data.Add("原始成績", info.Detail.HasAttribute("原始成績") ? info.Detail.GetAttribute("原始成績") : "");

                            subjectStudentList[sl].Add(data);
                        }
                    }
                }

                _BGWResitList.ReportProgress(90 + (int)(currentStudent++ *10.0 / totalStudents));
            }
            List <string> sortedList = new List <string>();
            sortedList.AddRange(subjectStudentList.Keys);
            sortedList.Sort(SortBySemesterSubjectScore);

            foreach (string key in sortedList)
            {
                int    level;
                string levelString = "";
                if (!string.IsNullOrEmpty(subjectInfo[key]["級別"]) && int.TryParse(subjectInfo[key]["級別"], out level))
                {
                    levelString = GetNumber(level);
                }
                string sl = subjectInfo[key]["科目"] + levelString;

                ws.Cells.CreateRange(index, 4, false).Copy(eachSubject);
                ws.Cells[index, 0].PutValue(SystemInformation.SchoolChineseName + " " + schoolyear + " 學年度 第 " + semester + " 學期 學生未達補考標準名單");
                ws.Cells[index + 1, 2].PutValue(sl);
                ws.Cells[index + 1, 7].PutValue(subjectInfo[key]["學分"]);
                index += 4;

                foreach (Dictionary <string, string> dict in subjectStudentList[key])
                {
                    ws.Cells.CreateRange(index, 1, false).Copy(eachRow);
                    ws.Cells[index, 0].PutValue(dict["班級"]);
                    ws.Cells[index, 1].PutValue(dict["座號"]);
                    ws.Cells[index, 2].PutValue(dict["姓名"]);
                    ws.Cells[index, 3].PutValue(dict["學號"]);
                    ws.Cells[index, 4].PutValue(dict["必選修"]);
                    ws.Cells[index, 5].PutValue(dict["校部訂"]);
                    ws.Cells[index, 6].PutValue(dict["補考標準"]);
                    ws.Cells[index, 7].PutValue(dict["原始成績"]);

                    index++;
                }
                index++;
            }

            #endregion

            e.Result = wb;
        }
        void bkw_DoWork(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker bkw                  = ((BackgroundWorker)sender);
            int                  schoolyear       = (int)((object[])e.Argument)[0];
            AccessHelper         helper           = (AccessHelper)((object[])e.Argument)[1];
            List <StudentRecord> selectedStudents = (List <StudentRecord>)((object[])e.Argument)[2];

            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;

            List <SmartSchool.Feature.Score.AddScore.InsertInfo>  insertList         = new List <SmartSchool.Feature.Score.AddScore.InsertInfo>();
            List <SmartSchool.Feature.Score.EditScore.UpdateInfo> updateList         = new List <SmartSchool.Feature.Score.EditScore.UpdateInfo>();
            List <SmartSchool.Feature.Score.EditScore.UpdateInfo> updateSemesterList = new List <SmartSchool.Feature.Score.EditScore.UpdateInfo>();
            XmlDocument doc = new XmlDocument();

            foreach (List <StudentRecord> var in packages)
            {
                computedStudents += var.Count;
                Dictionary <StudentRecord, List <string> > errormessages = computer.FillSchoolYearSubjectCalcScore(schoolyear, helper, var);
                helper.StudentHelper.FillSchoolYearSubjectScore(false, var);

                #region 每個學生去整理新增跟修改的資料
                foreach (StudentRecord stu in var)
                {
                    if (stu.Fields.ContainsKey("CalcSchoolYearSubjectScores"))
                    {
                        Dictionary <string, decimal> subjectScore = (Dictionary <string, decimal>)stu.Fields["CalcSchoolYearSubjectScores"];
                        //有分項成績
                        if (subjectScore.Count > 0)
                        {
                            int?gradeyear = null;
                            #region 判斷年級
                            foreach (SemesterSubjectScoreInfo score in stu.SemesterSubjectScoreList)
                            {
                                if (score.SchoolYear == schoolyear)
                                {
                                    if (gradeyear == null || score.GradeYear > gradeyear)
                                    {
                                        gradeyear = score.GradeYear;
                                    }
                                }
                            }
                            #endregion
                            //年級沒有問題
                            if (gradeyear != null)
                            {
                                #region 處理新增級修改的學年科目成績項目

                                bool updated = false;
                                //string updateid = "";
                                #region 找到ID,將計算分項與現有成績的分向做聯集
                                Dictionary <int, string> scoreID = (Dictionary <int, string>)stu.Fields["SchoolYearSubjectScoreID"];
                                //只處理德行分項
                                foreach (SchoolYearSubjectScoreInfo sc in stu.SchoolYearSubjectScoreList)
                                {
                                    if (sc.SchoolYear == schoolyear)
                                    {
                                        updated = true;
                                        XmlElement subjectScoreInfo = (XmlElement)sc.Detail.ParentNode;
                                        foreach (string subject in subjectScore.Keys)
                                        {
                                            XmlElement subjectElement = subjectScoreInfo.SelectSingleNode("Subject[@科目='" + subject + "']") as XmlElement;
                                            if (subjectElement != null)
                                            {
                                                decimal topScore = subjectScore[subject], tryParseScore;
                                                if (decimal.TryParse(subjectElement.GetAttribute("補考成績"), out tryParseScore) && topScore < tryParseScore)
                                                {
                                                    topScore = tryParseScore;
                                                }
                                                if (decimal.TryParse(subjectElement.GetAttribute("重修成績"), out tryParseScore) && topScore < tryParseScore)
                                                {
                                                    topScore = tryParseScore;
                                                }
                                                subjectElement.SetAttribute("結算成績", "" + subjectScore[subject]);
                                                subjectElement.SetAttribute("學年成績", "" + topScore);
                                            }
                                            else
                                            {
                                                subjectElement = subjectScoreInfo.OwnerDocument.CreateElement("Subject");
                                                subjectElement.SetAttribute("科目", subject);
                                                subjectElement.SetAttribute("學年成績", "" + subjectScore[subject]);
                                                subjectElement.SetAttribute("結算成績", "" + subjectScore[subject]);
                                                subjectScoreInfo.AppendChild(subjectElement);
                                            }
                                        }
                                        updateList.Add(new SmartSchool.Feature.Score.EditScore.UpdateInfo(scoreID[sc.SchoolYear], "" + gradeyear, subjectScoreInfo));
                                        break;
                                        //updateid = scoreID[sc.SchoolYear];
                                        ////如果計算的結果並不包含已存在成績的分項,將該分項及成績加入至計算的結果
                                        //if (!subjectScore.ContainsKey(sc.Subject))
                                        //{
                                        //    subjectScore.Add(sc.Subject, sc.Score);
                                        //}
                                    }
                                }
                                #endregion
                                //if (updateid != "")
                                //{
                                //    XmlElement subjectScoreInfo = doc.CreateElement("SchoolYearSubjectScore");
                                //    foreach (string subject in subjectScore.Keys)
                                //    {
                                //        XmlElement entryElement = doc.CreateElement("Subject");
                                //        entryElement.SetAttribute("科目", subject);
                                //        entryElement.SetAttribute("學年成績", "" + subjectScore[subject]);
                                //        entryElement.SetAttribute("結算成績", "" + subjectScore[subject]);
                                //        subjectScoreInfo.AppendChild(entryElement);
                                //    }
                                //    updateList.Add(new SmartSchool.Feature.Score.EditScore.UpdateInfo(updateid, "" + gradeyear, subjectScoreInfo));
                                //}
                                //else
                                if (!updated)
                                {
                                    XmlElement subjectScoreInfo = doc.CreateElement("SchoolYearSubjectScore");
                                    foreach (string subject in subjectScore.Keys)
                                    {
                                        XmlElement entryElement = doc.CreateElement("Subject");
                                        entryElement.SetAttribute("科目", subject);
                                        entryElement.SetAttribute("學年成績", "" + subjectScore[subject]);
                                        entryElement.SetAttribute("結算成績", "" + subjectScore[subject]);
                                        subjectScoreInfo.AppendChild(entryElement);
                                    }
                                    insertList.Add(new SmartSchool.Feature.Score.AddScore.InsertInfo(stu.StudentID, "" + schoolyear, "", "" + gradeyear, "", subjectScoreInfo));
                                }
                                #endregion
                            }
                        }
                    }
                    //if (stu.Fields.ContainsKey("SchoolYearApplyScores"))
                    //{
                    //    #region 處理學年調整成績更新清單
                    //    List<SemesterSubjectScoreInfo> updateScores = (List<SemesterSubjectScoreInfo>)stu.Fields["SchoolYearApplyScores"];
                    //    Dictionary<int, Dictionary<int, List<SemesterSubjectScoreInfo>>> semesterUpdateScores = new Dictionary<int, Dictionary<int, List<SemesterSubjectScoreInfo>>>();
                    //    //整理有取得學年調整成績的學年度學期
                    //    foreach (SemesterSubjectScoreInfo score in updateScores)
                    //    {
                    //        if (!semesterUpdateScores.ContainsKey(score.SchoolYear))
                    //            semesterUpdateScores.Add(score.SchoolYear, new Dictionary<int, List<SemesterSubjectScoreInfo>>());
                    //        if (!semesterUpdateScores[score.SchoolYear].ContainsKey(score.Semester))
                    //            semesterUpdateScores[score.SchoolYear].Add(score.Semester, new List<SemesterSubjectScoreInfo>());
                    //        semesterUpdateScores[score.SchoolYear][score.Semester].Add(score);
                    //    }
                    //    //將有取得學年調整成績的學期成績全部加入
                    //    foreach (SemesterSubjectScoreInfo score in stu.SemesterSubjectScoreList)
                    //    {
                    //        if (semesterUpdateScores.ContainsKey(score.SchoolYear) && semesterUpdateScores[score.SchoolYear].ContainsKey(score.Semester) && !semesterUpdateScores[score.SchoolYear][score.Semester].Contains(score))
                    //        {
                    //            semesterUpdateScores[score.SchoolYear][score.Semester].Add(score);
                    //        }
                    //    }
                    //    if (semesterUpdateScores.Count > 0)
                    //    {
                    //        //學生成績ID對照
                    //        Dictionary<int, Dictionary<int, string>> semeScoreID = (Dictionary<int, Dictionary<int, string>>)stu.Fields["SemesterSubjectScoreID"];
                    //        //整理學年調整成績更新清單
                    //        //XmlDocument doc = new XmlDocument();
                    //        foreach (int sy in semesterUpdateScores.Keys)
                    //        {
                    //            foreach (int se in semesterUpdateScores[sy].Keys)
                    //            {
                    //                if (semeScoreID.ContainsKey(sy) && semeScoreID[sy].ContainsKey(se))
                    //                {
                    //                    string gradeYear = "";
                    //                    XmlElement parentNode;
                    //                    parentNode = doc.CreateElement("SemesterSubjectScoreInfo");
                    //                    //加入成績資料
                    //                    foreach (SemesterSubjectScoreInfo score in semesterUpdateScores[sy][se])
                    //                    {
                    //                        gradeYear = "" + score.GradeYear;
                    //                        parentNode.AppendChild(doc.ImportNode(score.Detail, true));
                    //                    }
                    //                    updateSemesterList.Add(new SmartSchool.Feature.Score.EditScore.UpdateInfo(semeScoreID[sy][se], gradeYear, parentNode));
                    //                }
                    //            }
                    //        }
                    //    }
                    //    #endregion
                    //}
                }
                #endregion


                if (errormessages.Count > 0)
                {
                    allPass = false;
                }
                if (bkw.CancellationPending)
                {
                    break;
                }
                else
                {
                    bkw.ReportProgress((int)((computedStudents * 100.0) / maxStudents), errormessages);
                }
            }
            if (allPass)
            {
                e.Result = new object[] { insertList, updateList, updateSemesterList, selectedStudents }
            }
            ;
            else
            {
                e.Result = null;
            }
        }
 //private enum RoundMode { 四捨五入, 無條件進位, 無條件捨去 }
 private static decimal GetRoundScore(decimal score, int decimals, SmartSchool.Evaluation.WearyDogComputer.RoundMode mode)
 {
     return(WearyDogComputer.GetRoundScore(score, decimals, mode));
 }
Esempio n. 4
0
        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)
        {
            BackgroundWorker bkw                  = ((BackgroundWorker)sender);
            int                  schoolyear       = (int)((object[])e.Argument)[0];
            AccessHelper         helper           = (AccessHelper)((object[])e.Argument)[1];
            List <StudentRecord> selectedStudents = (List <StudentRecord>)((object[])e.Argument)[2];

            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;

            List <SmartSchool.Feature.Score.EditScore.UpdateInfo> updateSemesterList = new List <SmartSchool.Feature.Score.EditScore.UpdateInfo>();
            XmlDocument doc = new XmlDocument();

            foreach (List <StudentRecord> var in packages)
            {
                computedStudents += var.Count;
                Dictionary <StudentRecord, List <string> > errormessages = computer.FillSchoolYearApplyScoresCalcScore(schoolyear, helper, var);

                #region 每個學生去整理新增跟修改的資料
                foreach (StudentRecord stu in var)
                {
                    if (stu.Fields.ContainsKey("SchoolYearApplyScores"))
                    {
                        #region 處理學年調整成績更新清單
                        List <SemesterSubjectScoreInfo> updateScores = (List <SemesterSubjectScoreInfo>)stu.Fields["SchoolYearApplyScores"];
                        Dictionary <int, Dictionary <int, List <SemesterSubjectScoreInfo> > > semesterUpdateScores = new Dictionary <int, Dictionary <int, List <SemesterSubjectScoreInfo> > >();
                        //整理有取得學年調整成績的學年度學期
                        foreach (SemesterSubjectScoreInfo score in updateScores)
                        {
                            if (!semesterUpdateScores.ContainsKey(score.SchoolYear))
                            {
                                semesterUpdateScores.Add(score.SchoolYear, new Dictionary <int, List <SemesterSubjectScoreInfo> >());
                            }
                            if (!semesterUpdateScores[score.SchoolYear].ContainsKey(score.Semester))
                            {
                                semesterUpdateScores[score.SchoolYear].Add(score.Semester, new List <SemesterSubjectScoreInfo>());
                            }
                            semesterUpdateScores[score.SchoolYear][score.Semester].Add(score);
                        }
                        //將有取得學年調整成績的學期成績全部加入
                        foreach (SemesterSubjectScoreInfo score in stu.SemesterSubjectScoreList)
                        {
                            if (semesterUpdateScores.ContainsKey(score.SchoolYear) && semesterUpdateScores[score.SchoolYear].ContainsKey(score.Semester) && !semesterUpdateScores[score.SchoolYear][score.Semester].Contains(score))
                            {
                                semesterUpdateScores[score.SchoolYear][score.Semester].Add(score);
                            }
                        }
                        if (semesterUpdateScores.Count > 0)
                        {
                            //學生成績ID對照
                            Dictionary <int, Dictionary <int, string> > semeScoreID = (Dictionary <int, Dictionary <int, string> >)stu.Fields["SemesterSubjectScoreID"];
                            //整理學年調整成績更新清單
                            //XmlDocument doc = new XmlDocument();
                            foreach (int sy in semesterUpdateScores.Keys)
                            {
                                foreach (int se in semesterUpdateScores[sy].Keys)
                                {
                                    if (semeScoreID.ContainsKey(sy) && semeScoreID[sy].ContainsKey(se))
                                    {
                                        string     gradeYear = "";
                                        XmlElement parentNode;
                                        parentNode = doc.CreateElement("SemesterSubjectScoreInfo");
                                        //加入成績資料
                                        foreach (SemesterSubjectScoreInfo score in semesterUpdateScores[sy][se])
                                        {
                                            gradeYear = "" + score.GradeYear;
                                            parentNode.AppendChild(doc.ImportNode(score.Detail, true));
                                        }
                                        updateSemesterList.Add(new SmartSchool.Feature.Score.EditScore.UpdateInfo(semeScoreID[sy][se], gradeYear, parentNode));
                                    }
                                }
                            }
                        }
                        #endregion
                    }
                }
                #endregion


                if (errormessages.Count > 0)
                {
                    allPass = false;
                }
                if (bkw.CancellationPending)
                {
                    break;
                }
                else
                {
                    bkw.ReportProgress((int)((computedStudents * 100.0) / maxStudents), errormessages);
                }
            }
            if (allPass)
            {
                e.Result = new object[] { updateSemesterList, selectedStudents }
            }
            ;
            else
            {
                e.Result = null;
            }
        }
        void bkw_DoWork(object sender, DoWorkEventArgs e)
        {
            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];

            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;

            List <SmartSchool.Feature.Score.AddScore.InsertInfo>  insertList = new List <SmartSchool.Feature.Score.AddScore.InsertInfo>();
            List <SmartSchool.Feature.Score.EditScore.UpdateInfo> updateList = new List <SmartSchool.Feature.Score.EditScore.UpdateInfo>();
            XmlDocument doc = new XmlDocument();

            foreach (List <StudentRecord> var in packages)
            {
                computedStudents += var.Count;
                Dictionary <StudentRecord, List <string> > errormessages = computer.FillSemesterEntryCalcScore(schoolyear, semester, helper, var);
                helper.StudentHelper.FillSemesterEntryScore(false, var);

                #region 每個學生去整理新增跟修改的資料
                foreach (StudentRecord stu in var)
                {
                    if (stu.Fields.ContainsKey("CalcEntryScores"))
                    {
                        Dictionary <string, decimal> entryScore = (Dictionary <string, decimal>)stu.Fields["CalcEntryScores"];
                        //有分項成績
                        if (entryScore.Count > 0)
                        {
                            string gradeyear = "";
                            #region 判斷年級
                            foreach (SemesterSubjectScoreInfo subjectscore in stu.SemesterSubjectScoreList)
                            {
                                if (subjectscore.SchoolYear == schoolyear && subjectscore.Semester == semester)
                                {
                                    if (gradeyear == "")
                                    {
                                        gradeyear = "" + subjectscore.GradeYear;
                                    }
                                    else if (gradeyear != "" + subjectscore.GradeYear)
                                    {
                                        if (!errormessages.ContainsKey(stu))
                                        {
                                            errormessages.Add(stu, new List <string>());
                                        }
                                        errormessages[stu].Add("" + schoolyear + "學年度" + semester + "學期科目成績上的年級有誤(發現數筆不同年級資料)。");
                                        gradeyear = "";
                                        break;
                                    }
                                }
                            }
                            #endregion
                            //年級沒有問題
                            if (gradeyear != "")
                            {
                                string updateid = "";
                                #region 找到ID,將計算分項與現有成績的分向做聯集
                                Dictionary <int, Dictionary <int, Dictionary <string, string> > > scoreID = (Dictionary <int, Dictionary <int, Dictionary <string, string> > >)stu.Fields["SemesterEntryScoreID"];
                                //只處理以下幾個分項類別(學習類)
                                List <string> enableEntryLists = new List <string>(new string[] { "體育", "學業", "國防通識", "健康與護理", "實習科目" });
                                foreach (SemesterEntryScoreInfo sc in stu.SemesterEntryScoreList)
                                {
                                    if (enableEntryLists.Contains(sc.Entry) && sc.SchoolYear == schoolyear && sc.Semester == semester)
                                    {
                                        updateid = scoreID[sc.SchoolYear][sc.Semester]["學習"];
                                        //如果計算的結果並不包含已存在成績的分項,將該分項及成績加入至計算的結果
                                        if (!entryScore.ContainsKey(sc.Entry))
                                        {
                                            entryScore.Add(sc.Entry, sc.Score);
                                        }
                                    }
                                }
                                #endregion
                                if (updateid != "")
                                {
                                    XmlElement entryScoreInfo = doc.CreateElement("SemesterEntryScore");
                                    foreach (string entry in entryScore.Keys)
                                    {
                                        XmlElement entryElement = doc.CreateElement("Entry");
                                        entryElement.SetAttribute("分項", entry);
                                        entryElement.SetAttribute("成績", "" + entryScore[entry]);
                                        entryScoreInfo.AppendChild(entryElement);
                                    }
                                    updateList.Add(new SmartSchool.Feature.Score.EditScore.UpdateInfo(updateid, gradeyear, entryScoreInfo));
                                }
                                else
                                {
                                    XmlElement entryScoreInfo = doc.CreateElement("SemesterEntryScore");
                                    foreach (string entry in entryScore.Keys)
                                    {
                                        XmlElement entryElement = doc.CreateElement("Entry");
                                        entryElement.SetAttribute("分項", entry);
                                        entryElement.SetAttribute("成績", "" + entryScore[entry]);
                                        entryScoreInfo.AppendChild(entryElement);
                                    }
                                    insertList.Add(new SmartSchool.Feature.Score.AddScore.InsertInfo(stu.StudentID, "" + schoolyear, "" + semester, gradeyear, "學習", entryScoreInfo));
                                }
                            }
                        }
                    }
                }
                #endregion


                if (errormessages.Count > 0)
                {
                    allPass = false;
                }
                if (bkw.CancellationPending)
                {
                    break;
                }
                else
                {
                    bkw.ReportProgress((int)((computedStudents * 100.0) / maxStudents), errormessages);
                }
            }
            if (allPass)
            {
                e.Result = new object[] { insertList, updateList, selectedStudents }
            }
            ;
            else
            {
                e.Result = null;
            }
        }
        void _BWResitScoreImport_DoWork(object sender, DoWorkEventArgs e)
        {
            object[] objectValue = (object[])e.Argument;
            int      schoolyear  = (int)objectValue[0];
            int      semester    = (int)objectValue[1];

            _BWResitScoreImport.ReportProgress(0);

            #region 取得所有學生以及補考資訊

            AccessHelper         helper      = new AccessHelper();
            List <StudentRecord> allStudents = new List <StudentRecord>();
            List <ClassRecord>   allClasses  = helper.ClassHelper.GetAllClass();
            WearyDogComputer     computer    = new WearyDogComputer();

            double currentClass = 1;
            double totalClasses = allClasses.Count;

            List <StudentRecord> loadCourseStudents = new List <StudentRecord>();

            foreach (ClassRecord aClass in allClasses)
            {
                List <StudentRecord> classStudents = aClass.Students;
                computer.FillSemesterSubjectScoreInfoWithResit(helper, true, classStudents);
                helper.StudentHelper.FillField("及格標準", classStudents);

                allStudents.AddRange(classStudents);
                foreach (StudentRecord aStudent in classStudents)
                {
                    foreach (SemesterSubjectScoreInfo info in aStudent.SemesterSubjectScoreList)
                    {
                        if (info.SchoolYear == schoolyear && info.Semester == semester)
                        {
                            if (!info.Pass && info.Detail.HasAttribute("達補考標準") && info.Detail.GetAttribute("達補考標準") == "是")
                            {
                                if (!loadCourseStudents.Contains(aStudent))
                                {
                                    loadCourseStudents.Add(aStudent);
                                }
                            }
                        }
                    }
                }
                _BWResitScoreImport.ReportProgress((int)(currentClass++ *90.0 / totalClasses));
            }

            MultiThreadWorker <StudentRecord> multiThreadWorker = new MultiThreadWorker <StudentRecord>();
            multiThreadWorker.MaxThreads     = 3;
            multiThreadWorker.PackageSize    = 80;
            multiThreadWorker.PackageWorker += new EventHandler <PackageWorkEventArgs <StudentRecord> >(multiThreadWorker_PackageWorker);
            multiThreadWorker.Run(loadCourseStudents, new object[] { schoolyear, semester, helper });

            double currentStudent = 1;
            double totalStudents  = allStudents.Count;

            #endregion

            #region 產生表格並填入資料

            Workbook template = new Workbook();
            template.Open(new MemoryStream(Properties.Resources.補考成績匯入), FileFormatType.Excel2003);
            Workbook wb = new Workbook();
            wb.Copy(template);
            Worksheet ws = wb.Worksheets[0];

            Dictionary <string, int> columnIndexTable = new Dictionary <string, int>();

            int    headerIndex  = 0;
            string headerString = template.Worksheets[0].Cells[0, headerIndex].StringValue;
            while (!string.IsNullOrEmpty(headerString))
            {
                columnIndexTable.Add(headerString, headerIndex);
                headerString = template.Worksheets[0].Cells[0, ++headerIndex].StringValue;
            }

            foreach (StudentRecord aStudent in loadCourseStudents)
            {
                foreach (SemesterSubjectScoreInfo info in aStudent.SemesterSubjectScoreList)
                {
                    if (info.SchoolYear == schoolyear && info.Semester == semester)
                    {
                        if (!info.Pass && info.Detail.HasAttribute("達補考標準") && info.Detail.GetAttribute("達補考標準") == "是")
                        {
                            #region 搜尋授課教師
                            foreach (StudentAttendCourseRecord attendCourse in aStudent.AttendCourseList)
                            {
                                if (attendCourse.SchoolYear == schoolyear && attendCourse.Semester == semester && attendCourse.Subject == info.Subject && attendCourse.SubjectLevel == info.Level)
                                {
                                    List <TeacherRecord> teachers = helper.TeacherHelper.GetLectureTeacher(attendCourse);
                                    if (teachers.Count > 0)
                                    {
                                        info.Detail.SetAttribute("授課教師", teachers[0].TeacherName);
                                    }
                                }
                            }
                            #endregion
                            machine.AddSubject(aStudent, info);
                        }
                    }
                }

                _BWResitScoreImport.ReportProgress(90 + (int)(currentStudent++ *10.0 / totalStudents));
            }

            machine.Sort();

            int index = 1;
            foreach (Dictionary <string, string> info in machine.GetSubjects())
            {
                foreach (string key in info.Keys)
                {
                    ws.Cells[index, columnIndexTable[key]].PutValue(info[key]);
                }
                index++;
            }

            #endregion

            e.Result = wb;
        }
Esempio n. 8
0
        public static Dictionary <string, decimal> CalculateSchoolYearEntryScore(this StudentRecord student, Dictionary <string, bool> calcEntry, Dictionary <string, bool> calcInStudy, int schoolyear, int gradeyear, WearyDogComputer.RoundMode mode, int decimals)
        {
            Dictionary <string, decimal> entryCalcScores = new Dictionary <string, decimal>();

            //學年科目成績的學分數
            Dictionary <string, decimal> subjectCreditCount = new Dictionary <string, decimal>();

            //各個分項成績的學分數
            Dictionary <string, decimal> entryCreditCount = new Dictionary <string, decimal>();

            //學年科目成績的各個科目成績列表
            Dictionary <string, List <decimal> > entrySubjectScores = new Dictionary <string, List <decimal> >();

            //學年科目成績的加權總計
            Dictionary <string, decimal> entryDividend = new Dictionary <string, decimal>();

            #region 加總學年科目成績對應到的學期科目成績,各個科目的學分數加總
            foreach (SemesterSubjectScoreInfo score in student.SemesterSubjectScoreList)
            {
                if (!subjectCreditCount.ContainsKey(score.Subject))
                {
                    subjectCreditCount.Add(score.Subject, 0);
                }
                subjectCreditCount[score.Subject] += score.CreditDec();
            }
            #endregion

            #region 計算該年級的分項成績
            //Dictionary<string, List<decimal>> entryScores = new Dictionary<string, List<decimal>>();

            //foreach (SemesterEntryScoreInfo score in Scores)
            //{
            //    if (calcEntry.ContainsKey(score.Entry) && score.SchoolYear <= schoolyear && score.GradeYear == gradeyear)
            //    {
            //        if (!entryScores.ContainsKey(score.Entry))
            //            entryScores.Add(score.Entry, new List<decimal>());
            //        entryScores[score.Entry].Add(score.Score);
            //    }
            //}

            //foreach (string key in entryScores.Keys)
            //{
            //    decimal sum = 0;
            //    decimal count = 0;
            //    foreach (decimal sc in entryScores[key])
            //    {
            //        sum += sc;
            //        count += 1;
            //    }
            //    if (count > 0)
            //        entryCalcScores.Add(key, WearyDogComputer.GetRoundScore(sum / count, decimals, mode));
            //}
            #endregion

            #region 將成績分到各分項類別中
            foreach (SchoolYearSubjectScoreInfo subjectNode in student.SchoolYearSubjectScoreList)
            {
                //if (subjectNode.SchoolYear == schoolyear && subjectNode.Semester == semester)
                //留意是==schoolyear或是<=schoolyear
                if (subjectNode.SchoolYear == schoolyear && subjectNode.GradeYear == gradeyear)
                {
                    //不計學分或不需評分不用算
                    //if (subjectNode.Detail.GetAttribute("不需評分") == "是" || subjectNode.Detail.GetAttribute("不計學分") == "是")
                    //    continue;
                    #region 分項類別跟學分數
                    //string entry = subjectNode.Detail.GetAttribute("開課分項類別");
                    //int credit = subjectNode.CreditDec();
                    decimal credit = subjectCreditCount.ContainsKey(subjectNode.Subject)?subjectCreditCount[subjectNode.Subject]:0;
                    #endregion
                    decimal maxScore = subjectNode.Score;
                    #region 取得最高分數
                    //decimal tryParseDecimal;
                    //if (decimal.TryParse(subjectNode.Detail.GetAttribute("原始成績"), out tryParseDecimal))
                    //    maxScore = tryParseDecimal;
                    //if (decimal.TryParse(subjectNode.Detail.GetAttribute("學年調整成績"), out tryParseDecimal) && maxScore < tryParseDecimal)
                    //    maxScore = tryParseDecimal;
                    //if (decimal.TryParse(subjectNode.Detail.GetAttribute("擇優採計成績"), out tryParseDecimal) && maxScore < tryParseDecimal)
                    //    maxScore = tryParseDecimal;
                    //if (decimal.TryParse(subjectNode.Detail.GetAttribute("補考成績"), out tryParseDecimal) && maxScore < tryParseDecimal)
                    //    maxScore = tryParseDecimal;
                    //if (decimal.TryParse(subjectNode.Detail.GetAttribute("重修成績"), out tryParseDecimal) && maxScore < tryParseDecimal)
                    //    maxScore = tryParseDecimal;
                    #endregion

                    //加總學分數
                    if (!entryCreditCount.ContainsKey("學業"))
                    {
                        entryCreditCount.Add("學業", credit);
                    }
                    else
                    {
                        entryCreditCount["學業"] += credit;
                    }
                    //加入將成績資料分項
                    if (!entrySubjectScores.ContainsKey("學業"))
                    {
                        entrySubjectScores.Add("學業", new List <decimal>());
                    }
                    entrySubjectScores["學業"].Add(maxScore);
                    //加權總計
                    if (!entryDividend.ContainsKey("學業"))
                    {
                        entryDividend.Add("學業", maxScore * credit);
                    }
                    else
                    {
                        entryDividend["學業"] += (maxScore * credit);
                    }

                    //switch (entry)
                    //{
                    //    case "體育":
                    //    case "國防通識":
                    //    case "健康與護理":
                    //    case "實習科目":
                    //        //計算分項成績
                    //        if (calcEntry[entry])
                    //        {
                    //            //加總學分數
                    //            if (!entryCreditCount.ContainsKey(entry))
                    //                entryCreditCount.Add(entry, credit);
                    //            else
                    //                entryCreditCount[entry] += credit;
                    //            //加入將成績資料分項
                    //            if (!entrySubjectScores.ContainsKey(entry)) entrySubjectScores.Add(entry, new List<decimal>());
                    //            entrySubjectScores[entry].Add(maxScore);
                    //            //加權總計
                    //            if (!entryDividend.ContainsKey(entry))
                    //                entryDividend.Add(entry, maxScore * credit);
                    //            else
                    //                entryDividend[entry] += (maxScore * credit);
                    //        }
                    //        //將科目成績與學業成績一併計算
                    //        if (calcInStudy[entry])
                    //        {
                    //            //加總學分數
                    //            if (!entryCreditCount.ContainsKey("學業"))
                    //                entryCreditCount.Add("學業", credit);
                    //            else
                    //                entryCreditCount["學業"] += credit;
                    //            //加入將成績資料分項
                    //            if (!entrySubjectScores.ContainsKey("學業")) entrySubjectScores.Add("學業", new List<decimal>());
                    //            entrySubjectScores["學業"].Add(maxScore);
                    //            //加權總計
                    //            if (!entryDividend.ContainsKey("學業"))
                    //                entryDividend.Add("學業", maxScore * credit);
                    //            else
                    //                entryDividend["學業"] += (maxScore * credit);
                    //        }
                    //        break;

                    //    case "學業":
                    //    default:
                    //        //加總學分數
                    //        if (!entryCreditCount.ContainsKey("學業"))
                    //            entryCreditCount.Add("學業", credit);
                    //        else
                    //            entryCreditCount["學業"] += credit;
                    //        //加入將成績資料分項
                    //        if (!entrySubjectScores.ContainsKey("學業")) entrySubjectScores.Add("學業", new List<decimal>());
                    //        entrySubjectScores["學業"].Add(maxScore);
                    //        //加權總計
                    //        if (!entryDividend.ContainsKey("學業"))
                    //            entryDividend.Add("學業", maxScore * credit);
                    //        else
                    //            entryDividend["學業"] += (maxScore * credit);
                    //        break;
                    //}
                }
            }
            #endregion
            #region 處理計算各分項類別的成績
            foreach (string entry in entryCreditCount.Keys)
            {
                decimal entryScore = 0;
                #region 計算entryScore
                if (entryCreditCount[entry] == 0)
                {
                    foreach (decimal score in entrySubjectScores[entry])
                    {
                        entryScore += score;
                    }
                    entryScore = (entryScore / entrySubjectScores[entry].Count);
                }
                else
                {
                    //用加權總分除學分數
                    entryScore = (entryDividend[entry] / entryCreditCount[entry]);
                }
                #endregion
                //精準位數處理
                entryScore = WearyDogComputer.GetRoundScore(entryScore, decimals, mode);
                #region 填入EntryScores
                entryCalcScores.Add(entry, entryScore);
                #endregion
            }
            #endregion

            return(entryCalcScores);
        }
Esempio n. 9
0
        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;
            }
        }
Esempio n. 10
0
        void _BGWResitList_DoWork(object sender, DoWorkEventArgs e)
        {
            object[] objectValue = (object[])e.Argument;
            int      schoolyear  = (int)objectValue[0];
            int      semester    = (int)objectValue[1];

            _BGWResitList.ReportProgress(0);

            #region 取得所有學生以及補考資訊

            AccessHelper         helper      = new AccessHelper();
            List <StudentRecord> allStudents = new List <StudentRecord>();
            List <ClassRecord>   allClasses  = helper.ClassHelper.GetAllClass();
            WearyDogComputer     computer    = new WearyDogComputer();

            double currentClass = 1;
            double totalClasses = allClasses.Count;

            foreach (ClassRecord aClass in allClasses)
            {
                List <StudentRecord> classStudents = aClass.Students;
                computer.FillSemesterSubjectScoreInfoWithResit(helper, true, classStudents);
                allStudents.AddRange(classStudents);

                _BGWResitList.ReportProgress((int)(currentClass++ *90.0 / totalClasses));
            }

            double currentStudent = 1;
            double totalStudents  = allStudents.Count;

            #endregion

            #region 產生表格並填入資料

            Workbook template = new Workbook();
            template.Open(new MemoryStream(Properties.Resources.補考名單_依學生), FileFormatType.Excel2003);
            Workbook wb = new Workbook();
            wb.Copy(template);
            Worksheet ws = wb.Worksheets[0];

            Range eachRow = template.Worksheets[0].Cells.CreateRange(2, 1, false);

            ws.Cells[0, 0].PutValue(SystemInformation.SchoolChineseName + " " + schoolyear + " 學年度 第 " + semester + " 學期 學生補考名單");
            int index = 2;

            foreach (StudentRecord aStudent in allStudents)
            {
                string className     = aStudent.RefClass.ClassName;
                string seatNo        = aStudent.SeatNo;
                string studentNumber = aStudent.StudentNumber;
                string studentName   = aStudent.StudentName;

                aStudent.SemesterSubjectScoreList.Sort(SortBySemesterSubjectScore);

                foreach (SemesterSubjectScoreInfo info in aStudent.SemesterSubjectScoreList)
                {
                    if (info.SchoolYear == schoolyear && info.Semester == semester && !info.Pass)
                    {
                        if (info.Detail.GetAttribute("達補考標準") == "是")
                        {
                            string subject     = info.Subject;
                            string levelString = "";
                            int    level;
                            if (int.TryParse(info.Level, out level))
                            {
                                levelString = GetNumber(level);
                            }
                            string credit = info.CreditDec().ToString();
                            string score  = info.Detail.GetAttribute("原始成績");
                            string limit  = info.Detail.GetAttribute("補考標準");

                            ws.Cells.CreateRange(index, 1, false).Copy(eachRow);
                            ws.Cells[index, 0].PutValue(className);
                            ws.Cells[index, 1].PutValue(seatNo);
                            ws.Cells[index, 2].PutValue(studentNumber);
                            ws.Cells[index, 3].PutValue(studentName);
                            ws.Cells[index, 4].PutValue(subject + (string.IsNullOrEmpty(levelString) ? "" : " " + levelString));
                            ws.Cells[index, 5].PutValue(credit);
                            ws.Cells[index, 6].PutValue(score);
                            ws.Cells[index, 7].PutValue(limit);

                            index++;
                        }
                    }
                }

                _BGWResitList.ReportProgress(90 + (int)(currentStudent++ *10.0 / totalStudents));
            }

            #endregion

            e.Result = wb;
        }
Esempio n. 11
0
        public XmlElement CalculateSemesterEntryScore(XmlElement semesterSubjectScore)
        {
            Dictionary <string, decimal>         entryCreditCount   = new Dictionary <string, decimal>();
            Dictionary <string, List <decimal> > entrySubjectScores = new Dictionary <string, List <decimal> >();
            Dictionary <string, decimal>         entryDividend      = new Dictionary <string, decimal>();
            Dictionary <string, bool>            calcEntry          = new Dictionary <string, bool>();
            Dictionary <string, bool>            calcInStudy        = new Dictionary <string, bool>();
            List <string> takeScore = new List <string>();
            //精準位數
            int decimals = 2;

            //進位模式
            WearyDogComputer.RoundMode mode = WearyDogComputer.RoundMode.四捨五入;
            //成績年級及計算規則皆存在,允許計算成績
            bool canCalc = true;

            #region 取得成績年級跟計算規則

            #region 處理計算規則
            XmlElement scoreCalcRule = (XmlElement)_ScoreCalcRuleElement;//ScoreCalcRule.ScoreCalcRule.Instance.GetStudentScoreCalcRuleInfo(var.StudentID) == null ? null : ScoreCalcRule.ScoreCalcRule.Instance.GetStudentScoreCalcRuleInfo(var.StudentID).ScoreCalcRuleElement;

            DSXmlHelper helper = new DSXmlHelper(scoreCalcRule);
            bool        tryParsebool;
            int         tryParseint;
            decimal     tryParseDecimal;

            #region 精準位數
            if (scoreCalcRule.SelectSingleNode("各項成績計算位數/學期分項成績計算位數") != null)
            {
                if (int.TryParse(helper.GetText("各項成績計算位數/學期分項成績計算位數/@位數"), out tryParseint))
                {
                    decimals = tryParseint;
                }
                if (bool.TryParse(helper.GetText("各項成績計算位數/學期分項成績計算位數/@四捨五入"), out tryParsebool) && tryParsebool)
                {
                    mode = WearyDogComputer.RoundMode.四捨五入;
                }
                if (bool.TryParse(helper.GetText("各項成績計算位數/學期分項成績計算位數/@無條件捨去"), out tryParsebool) && tryParsebool)
                {
                    mode = WearyDogComputer.RoundMode.無條件捨去;
                }
                if (bool.TryParse(helper.GetText("各項成績計算位數/學期分項成績計算位數/@無條件進位"), out tryParsebool) && tryParsebool)
                {
                    mode = WearyDogComputer.RoundMode.無條件進位;
                }
            }
            #endregion
            #region 計算類別
            foreach (string entry in new string[] { "體育", "學業", "國防通識", "健康與護理", "實習科目", "專業科目" })
            {
                if (scoreCalcRule.SelectSingleNode("分項成績計算項目") == null || scoreCalcRule.SelectSingleNode("分項成績計算項目/" + entry) == null || ((XmlElement)scoreCalcRule.SelectSingleNode("分項成績計算項目/" + entry)).GetAttribute("計算成績") == "True")
                {
                    calcEntry.Add(entry, true);
                }
                else
                {
                    calcEntry.Add(entry, false);
                }

                // 2014/3/20,修改當沒有勾選 預設併入學期學業成績 ChenCT
                if (scoreCalcRule.SelectSingleNode("分項成績計算項目") == null || scoreCalcRule.SelectSingleNode("分項成績計算項目/" + entry) == null || ((XmlElement)scoreCalcRule.SelectSingleNode("分項成績計算項目/" + entry)).GetAttribute("併入學期學業成績") == "True")
                {
                    calcInStudy.Add(entry, true);
                }
                else
                {
                    calcInStudy.Add(entry, false);
                }
            }
            #endregion
            #region 採計成績欄位
            foreach (string item in new string[] { "原始成績", "補考成績", "重修成績", "擇優採計成績", "學年調整成績" })
            {
                if (!bool.TryParse(helper.GetText("分項成績計算採計成績欄位/@" + item), out tryParsebool) || tryParsebool)
                {//沒有設定這項成績設定規則(預設true)或者設定值是true
                    takeScore.Add(item);
                }
            }
            #endregion

            #endregion

            #endregion
            Dictionary <string, decimal> entryScores = new Dictionary <string, decimal>();

            #region 將成績分到各分項類別中
            foreach (XmlNode subjectNode in semesterSubjectScore.SelectNodes("Subject"))
            {
                XmlElement subjectElement = (XmlElement)subjectNode;
                //不計學分或不需評分不用算
                if (subjectElement.GetAttribute("不需評分") == "是" || subjectElement.GetAttribute("不計學分") == "是")
                {
                    continue;
                }
                #region 分項類別跟學分數
                string  entry  = subjectElement.GetAttribute("開課分項類別");
                decimal credit = 0;
                decimal.TryParse(subjectElement.GetAttribute("開課學分數"), out credit);
                #endregion
                decimal maxScore = 0;
                decimal original = 0;
                if (decimal.TryParse(subjectElement.GetAttribute("原始成績"), out tryParseDecimal))
                {
                    original = tryParseDecimal;
                }
                #region 取得最高分數
                foreach (var item in takeScore)
                {
                    if (decimal.TryParse(subjectElement.GetAttribute(item), out tryParseDecimal) && maxScore < tryParseDecimal)
                    {
                        maxScore = tryParseDecimal;
                    }
                }
                #endregion
                switch (entry)
                {
                case "體育":
                case "國防通識":
                case "健康與護理":
                case "實習科目":
                case "專業科目":
                    //計算分項成績
                    if (calcEntry[entry])
                    {
                        #region original
                        //加總學分數
                        if (!entryCreditCount.ContainsKey(entry + "(原始)"))
                        {
                            entryCreditCount.Add(entry + "(原始)", credit);
                        }
                        else
                        {
                            entryCreditCount[entry + "(原始)"] += credit;
                        }
                        //加入將成績資料分項
                        if (!entrySubjectScores.ContainsKey(entry + "(原始)"))
                        {
                            entrySubjectScores.Add(entry + "(原始)", new List <decimal>());
                        }
                        entrySubjectScores[entry + "(原始)"].Add(original);
                        //加權總計
                        if (!entryDividend.ContainsKey(entry + "(原始)"))
                        {
                            entryDividend.Add(entry + "(原始)", original * credit);
                        }
                        else
                        {
                            entryDividend[entry + "(原始)"] += (original * credit);
                        }
                        #endregion
                        #region maxScore
                        //加總學分數
                        if (!entryCreditCount.ContainsKey(entry))
                        {
                            entryCreditCount.Add(entry, credit);
                        }
                        else
                        {
                            entryCreditCount[entry] += credit;
                        }
                        //加入將成績資料分項
                        if (!entrySubjectScores.ContainsKey(entry))
                        {
                            entrySubjectScores.Add(entry, new List <decimal>());
                        }
                        entrySubjectScores[entry].Add(maxScore);
                        //加權總計
                        if (!entryDividend.ContainsKey(entry))
                        {
                            entryDividend.Add(entry, maxScore * credit);
                        }
                        else
                        {
                            entryDividend[entry] += (maxScore * credit);
                        }
                        #endregion
                    }
                    //將科目成績與學業成績一併計算
                    if (calcInStudy[entry])
                    {
                        #region original
                        //加總學分數
                        if (!entryCreditCount.ContainsKey("學業" + "(原始)"))
                        {
                            entryCreditCount.Add("學業" + "(原始)", credit);
                        }
                        else
                        {
                            entryCreditCount["學業" + "(原始)"] += credit;
                        }
                        //加入將成績資料分項
                        if (!entrySubjectScores.ContainsKey("學業" + "(原始)"))
                        {
                            entrySubjectScores.Add("學業" + "(原始)", new List <decimal>());
                        }
                        entrySubjectScores["學業" + "(原始)"].Add(original);
                        //加權總計
                        if (!entryDividend.ContainsKey("學業" + "(原始)"))
                        {
                            entryDividend.Add("學業" + "(原始)", original * credit);
                        }
                        else
                        {
                            entryDividend["學業" + "(原始)"] += (original * credit);
                        }
                        #endregion
                        #region maxScore
                        //加總學分數
                        if (!entryCreditCount.ContainsKey("學業"))
                        {
                            entryCreditCount.Add("學業", credit);
                        }
                        else
                        {
                            entryCreditCount["學業"] += credit;
                        }
                        //加入將成績資料分項
                        if (!entrySubjectScores.ContainsKey("學業"))
                        {
                            entrySubjectScores.Add("學業", new List <decimal>());
                        }
                        entrySubjectScores["學業"].Add(maxScore);
                        //加權總計
                        if (!entryDividend.ContainsKey("學業"))
                        {
                            entryDividend.Add("學業", maxScore * credit);
                        }
                        else
                        {
                            entryDividend["學業"] += (maxScore * credit);
                        }
                        #endregion
                    }
                    break;

                case "學業":
                default:
                    #region original
                    //加總學分數
                    if (!entryCreditCount.ContainsKey("學業" + "(原始)"))
                    {
                        entryCreditCount.Add("學業" + "(原始)", credit);
                    }
                    else
                    {
                        entryCreditCount["學業" + "(原始)"] += credit;
                    }
                    //加入將成績資料分項
                    if (!entrySubjectScores.ContainsKey("學業" + "(原始)"))
                    {
                        entrySubjectScores.Add("學業" + "(原始)", new List <decimal>());
                    }
                    entrySubjectScores["學業" + "(原始)"].Add(original);
                    //加權總計
                    if (!entryDividend.ContainsKey("學業" + "(原始)"))
                    {
                        entryDividend.Add("學業" + "(原始)", original * credit);
                    }
                    else
                    {
                        entryDividend["學業" + "(原始)"] += (original * credit);
                    }
                    #endregion
                    #region maxScore
                    //加總學分數
                    if (!entryCreditCount.ContainsKey("學業"))
                    {
                        entryCreditCount.Add("學業", credit);
                    }
                    else
                    {
                        entryCreditCount["學業"] += credit;
                    }
                    //加入將成績資料分項
                    if (!entrySubjectScores.ContainsKey("學業"))
                    {
                        entrySubjectScores.Add("學業", new List <decimal>());
                    }
                    entrySubjectScores["學業"].Add(maxScore);
                    //加權總計
                    if (!entryDividend.ContainsKey("學業"))
                    {
                        entryDividend.Add("學業", maxScore * credit);
                    }
                    else
                    {
                        entryDividend["學業"] += (maxScore * credit);
                    }
                    #endregion
                    break;
                }
            }
            #endregion

            XmlDocument doc            = new XmlDocument();
            XmlElement  entryScoreRoot = doc.CreateElement("SemesterEntryScore");
            #region 處理計算各分項類別的成績
            foreach (string entry in entryCreditCount.Keys)
            {
                decimal entryScore = 0;
                #region 計算entryScore
                if (entryCreditCount[entry] == 0)
                {
                    foreach (decimal score in entrySubjectScores[entry])
                    {
                        entryScore += score;
                    }
                    entryScore = (entryScore / entrySubjectScores[entry].Count);
                }
                else
                {
                    //用加權總分除學分數
                    entryScore = (entryDividend[entry] / entryCreditCount[entry]);
                }
                #endregion
                //精準位數處理
                entryScore = WearyDogComputer.GetRoundScore(entryScore, decimals, mode);
                #region 填入Xml
                XmlElement entryElement = doc.CreateElement("Entry");
                entryElement.SetAttribute("分項", entry);
                entryElement.SetAttribute("成績", entryScore.ToString());
                entryScoreRoot.AppendChild(entryElement);
                #endregion
            }
            #endregion
            return(entryScoreRoot);
        }
Esempio n. 12
0
        void runningBackgroundWorker3_DoWork(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker     bkw              = ((BackgroundWorker)sender);
            AccessHelper         helper           = (AccessHelper)((object[])e.Argument)[0];
            List <StudentRecord> selectedStudents = (List <StudentRecord>)((object[])e.Argument)[1];
            WearyDogComputer     computer         = new WearyDogComputer();
            int packageSize  = 50;
            int packageCount = 0;
            List <StudentRecord>         package  = null;
            List <List <StudentRecord> > packages = new List <List <StudentRecord> >();

            bkw.ReportProgress(1, null);
            #region 切package
            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--;
            }
            #endregion

            Dictionary <int, List <int> > insertTags = new Dictionary <int, List <int> >();
            Dictionary <int, List <int> > removeTags = new Dictionary <int, List <int> >();
            Dictionary <string, int>      usefulTags = new Dictionary <string, int>();

            List <DSRequest> updateList = new List <DSRequest>();
            #region 抓現有 "取得多學程"或"未取得預設學程"的類別
            foreach (XmlElement tagElement in SmartSchool.Feature.Tag.QueryTag.GetDetailList(SmartSchool.Feature.Tag.TagCategory.Student).SelectNodes("Tag"))
            {
                int    id     = int.Parse(tagElement.GetAttribute("ID"));
                string name   = "";
                string prefix = "";
                if (tagElement.SelectSingleNode("Prefix") != null)
                {
                    prefix = tagElement.SelectSingleNode("Prefix").InnerText;
                }
                if (tagElement.SelectSingleNode("Name") != null)
                {
                    name = tagElement.SelectSingleNode("Name").InnerText;
                }
                if (prefix == "" && (name == "取得多學程" || name == "未取得預設學程"))
                {
                    if (!usefulTags.ContainsKey(name))
                    {
                        usefulTags.Add(name, id);
                    }
                }
            }
            #endregion


            double maxStudents = selectedStudents.Count;
            if (maxStudents == 0)
            {
                maxStudents = 1;
            }
            double computedStudents = 0;
            bool   allPass          = true;
            foreach (List <StudentRecord> var in packages)
            {
                if (var.Count == 0)
                {
                    continue;
                }
                //判斷取得學程
                Dictionary <StudentRecord, List <string> > errormessages = computer.FillStudentFulfilledProgram(helper, var);
                //取得學生畢業資訊
                helper.StudentHelper.FillField("DiplomaNumber", var);

                #region 把學生"取得多學程"或"未取得預設學程"的標籤都加入移除清單
                List <int> idList = new List <int>();
                foreach (StudentRecord stu in var)
                {
                    idList.Add(int.Parse(stu.StudentID));
                }
                XmlElement studentTags = SmartSchool.Feature.Tag.QueryTag.GetDetailListByStudent(idList);
                foreach (XmlElement tag in studentTags.SelectNodes("Tag"))
                {
                    int    id           = int.Parse(tag.GetAttribute("ID"));
                    string name         = "";
                    string prefix       = "";
                    int    refStudentID = 0;
                    if (tag.SelectSingleNode("Prefix") != null)
                    {
                        prefix = tag.SelectSingleNode("Prefix").InnerText;
                    }
                    if (tag.SelectSingleNode("StudentID") != null)
                    {
                        refStudentID = int.Parse(tag.SelectSingleNode("StudentID").InnerText);
                    }
                    if (tag.SelectSingleNode("Name") != null)
                    {
                        name = tag.SelectSingleNode("Name").InnerText;
                    }
                    if (prefix == "" && (name == "取得多學程" || name == "未取得預設學程"))
                    {
                        if (!removeTags.ContainsKey(id))
                        {
                            removeTags.Add(id, new List <int>());
                        }
                        removeTags[id].Add(refStudentID);
                    }
                }
                #endregion

                foreach (StudentRecord student in var)
                {
                    int           studentID      = int.Parse(student.StudentID);
                    bool          diplomaChanged = false;
                    XmlElement    diplomaElement;
                    List <string> programList = new List <string>();
                    #region 整理每個學生取得學程資訊
                    if (student.Fields.ContainsKey("DiplomaNumber") && student.Fields["DiplomaNumber"] != null)
                    {
                        diplomaElement = student.Fields["DiplomaNumber"] as XmlElement;
                        foreach (XmlElement program in diplomaElement.SelectNodes("Message[@Type='取得學程']"))
                        {
                            if (!programList.Contains(program.GetAttribute("Value")))
                            {
                                programList.Add(program.GetAttribute("Value"));
                            }
                        }
                    }
                    else
                    {
                        diplomaElement = new XmlDocument().CreateElement("DiplomaNumber");
                    }

                    XmlElement fulfilledProgramElement = (XmlElement)student.Fields["FulfilledProgram"];

                    foreach (XmlElement programElement in fulfilledProgramElement.SelectNodes("Program"))
                    {
                        if (!programList.Contains(programElement.InnerText))  //取得新學程
                        {
                            diplomaChanged = true;
                            XmlElement msg = (XmlElement)diplomaElement.AppendChild(diplomaElement.OwnerDocument.CreateElement("Message"));
                            msg.SetAttribute("Type", "取得學程");
                            msg.SetAttribute("Value", programElement.InnerText);
                            programList.Add(programElement.InnerText);
                        }
                    }
                    #endregion
                    if (diplomaChanged)
                    {
                        #region  取得新學程的就加入更新清單
                        DSXmlHelper helper2 = new DSXmlHelper("UpdateStudentList");
                        helper2.AddElement("Student");
                        helper2.AddElement("Student", "Field");
                        helper2.AddElement("Student/Field", diplomaElement);
                        helper2.AddElement("Student", "Condition");
                        helper2.AddElement("Student/Condition", "ID", student.StudentID);
                        updateList.Add(new DSRequest(helper2));
                        #endregion
                    }
                    #region 整理學生取得類別
                    List <string> getTags = new List <string>();
                    if (programList.Count > 1)
                    {
                        getTags.Add("取得多學程");
                    }
                    if (student.Fields.ContainsKey("SubDepartment") &&                                //科別有子項
                        SubjectTable.Items["學程科目表"].Contains("" + student.Fields["SubDepartment"]) && //子項是一個學程名稱
                        !programList.Contains("" + student.Fields["SubDepartment"])                   //取得的學程中沒有子項的這個學程
                        )
                    {
                        getTags.Add("未取得預設學程");
                    }

                    foreach (string getTag in getTags)
                    {
                        int tagID;
                        if (!usefulTags.ContainsKey(getTag))
                        {
                            //新加入的未達標準原因
                            tagID = SmartSchool.Feature.Tag.EditTag.Insert("", getTag, Color.CornflowerBlue.ToArgb(), SmartSchool.Feature.Tag.TagCategory.Student);
                            usefulTags.Add(getTag, tagID);
                        }
                        else
                        {
                            tagID = usefulTags[getTag];
                        }
                        //此學生本來有這個TAG就不刪除
                        if (removeTags.ContainsKey(tagID) && removeTags[tagID].Contains(studentID))
                        {
                            removeTags[tagID].Remove(studentID);
                        }
                        else
                        {
                            //學生原本沒有這個TAG就加入新增清單
                            if (!insertTags.ContainsKey(tagID))
                            {
                                insertTags.Add(tagID, new List <int>());
                            }
                            insertTags[tagID].Add(studentID);
                        }
                    }
                    #endregion
                }
                computedStudents += var.Count;
                if (errormessages.Count > 0)
                {
                    allPass = false;
                }
                if (bkw.CancellationPending)
                {
                    break;
                }
                else
                {
                    bkw.ReportProgress((int)((computedStudents * 100.0) / maxStudents), errormessages);
                }
            }
            if (allPass)
            {
                e.Result = new object[] { insertTags, removeTags, updateList, selectedStudents }
            }
            ;
            else
            {
                e.Result = null;
            }
        }
Esempio n. 13
0
        void runningBackgroundWorker2_DoWork(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker     bkw              = ((BackgroundWorker)sender);
            AccessHelper         helper           = (AccessHelper)((object[])e.Argument)[0];
            List <StudentRecord> selectedStudents = (List <StudentRecord>)((object[])e.Argument)[1];
            WearyDogComputer     computer         = new WearyDogComputer();
            int packageSize  = 50;
            int packageCount = 0;
            List <StudentRecord>         package  = null;
            List <List <StudentRecord> > packages = new List <List <StudentRecord> >();

            bkw.ReportProgress(1, null);
            #region 切package
            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--;
            }
            #endregion

            Dictionary <int, List <int> > insertTags = new Dictionary <int, List <int> >();
            Dictionary <int, List <int> > removeTags = new Dictionary <int, List <int> >();
            Dictionary <string, int>      usefulTags = new Dictionary <string, int>();
            int unPassStudentCount = 0;
            #region 抓現有 未達畢業標準 類的類別
            foreach (XmlElement tagElement in SmartSchool.Feature.Tag.QueryTag.GetDetailList(SmartSchool.Feature.Tag.TagCategory.Student).SelectNodes("Tag"))
            {
                int    id     = int.Parse(tagElement.GetAttribute("ID"));
                string name   = "";
                string prefix = "";
                if (tagElement.SelectSingleNode("Prefix") != null)
                {
                    prefix = tagElement.SelectSingleNode("Prefix").InnerText;
                }
                if (tagElement.SelectSingleNode("Name") != null)
                {
                    name = tagElement.SelectSingleNode("Name").InnerText;
                }
                if (prefix == "未達畢業標準")
                {
                    if (!usefulTags.ContainsKey(name))
                    {
                        usefulTags.Add(name, id);
                    }
                }
            }
            #endregion


            double maxStudents = selectedStudents.Count;
            if (maxStudents == 0)
            {
                maxStudents = 1;
            }
            double computedStudents = 0;
            bool   allPass          = true;
            foreach (List <StudentRecord> var in packages)
            {
                if (var.Count == 0)
                {
                    continue;
                }
                Dictionary <StudentRecord, List <string> > errormessages = computer.FillStudentGradCheck(helper, var);
                #region 把學生"未達畢業標準"類的標籤都加入移除清單
                List <int> idList = new List <int>();
                foreach (StudentRecord stu in var)
                {
                    idList.Add(int.Parse(stu.StudentID));
                }
                XmlElement studentTags = SmartSchool.Feature.Tag.QueryTag.GetDetailListByStudent(idList);
                foreach (XmlElement tag in studentTags.SelectNodes("Tag"))
                {
                    int    id           = int.Parse(tag.GetAttribute("ID"));
                    string prefix       = "";
                    int    refStudentID = 0;
                    if (tag.SelectSingleNode("Prefix") != null)
                    {
                        prefix = tag.SelectSingleNode("Prefix").InnerText;
                    }
                    if (tag.SelectSingleNode("StudentID") != null)
                    {
                        refStudentID = int.Parse(tag.SelectSingleNode("StudentID").InnerText);
                    }
                    if (prefix == "未達畢業標準")
                    {
                        if (!removeTags.ContainsKey(id))
                        {
                            removeTags.Add(id, new List <int>());
                        }
                        removeTags[id].Add(refStudentID);
                    }
                }
                #endregion

                // 在畢業及離校資訊的離校類別加入檢查可已畢業
                List <string> studIDList = new List <string>();

                foreach (StudentRecord student in var)
                {
                    #region 整理每個學生未達畢業標準原因
                    XmlElement gradCheckElement = (XmlElement)student.Fields["GradCheck"];
                    int        studentID        = int.Parse(student.StudentID);
                    //累計未達標準人數
                    if (gradCheckElement.SelectNodes("UnPassReson").Count > 0)
                    {
                        unPassStudentCount++;
                    }
                    else
                    {
                        studIDList.Add(student.StudentID); // 可畢業
                    }
                    foreach (XmlElement unPassElement in gradCheckElement.SelectNodes("UnPassReson"))
                    {
                        string reson = unPassElement.InnerText;
                        int    tagID;
                        if (!usefulTags.ContainsKey(reson))
                        {
                            //新加入的未達標準原因
                            tagID = SmartSchool.Feature.Tag.EditTag.Insert("未達畢業標準", reson, Color.Tomato.ToArgb(), SmartSchool.Feature.Tag.TagCategory.Student);
                            usefulTags.Add(reson, tagID);
                        }
                        else
                        {
                            tagID = usefulTags[reson];
                        }
                        //此學生本來有這個TAG就不刪除
                        if (removeTags.ContainsKey(tagID) && removeTags[tagID].Contains(studentID))
                        {
                            removeTags[tagID].Remove(studentID);
                        }
                        else
                        {
                            //學生原本沒有這個TAG就加入新增清單
                            if (!insertTags.ContainsKey(tagID))
                            {
                                insertTags.Add(tagID, new List <int>());
                            }
                            insertTags[tagID].Add(studentID);
                        }
                    }
                    #endregion
                }
                computedStudents += var.Count;

                // 修改畢業及離校資訊的離校類別
                if (studIDList.Count > 0 && errormessages.Count == 0)
                {
                    List <K12.Data.LeaveInfoRecord> LeaveInfoRecordList = K12.Data.LeaveInfo.SelectByStudentIDs(studIDList);

                    foreach (K12.Data.LeaveInfoRecord rec in LeaveInfoRecordList)
                    {
                        rec.Reason = "畢業";
                    }

                    // 更新
                    K12.Data.LeaveInfo.Update(LeaveInfoRecordList);
                    // 同步資料
                    Student.Instance.SyncAllBackground();
                }

                if (errormessages.Count > 0)
                {
                    allPass = false;
                }
                if (bkw.CancellationPending)
                {
                    break;
                }
                else
                {
                    bkw.ReportProgress((int)((computedStudents * 100.0) / maxStudents), errormessages);
                }
            }
            if (allPass)
            {
                e.Result = new object[] { insertTags, removeTags, selectedStudents, unPassStudentCount }
            }
            ;
            else
            {
                e.Result = null;
            }
        }
Esempio n. 14
0
        void runningBackgroundWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker     bkw              = ((BackgroundWorker)sender);
            AccessHelper         helper           = (AccessHelper)((object[])e.Argument)[0];
            List <StudentRecord> selectedStudents = (List <StudentRecord>)((object[])e.Argument)[1];
            WearyDogComputer     computer         = new WearyDogComputer();
            int packageSize  = 50;
            int packageCount = 0;
            List <StudentRecord>         package  = null;
            List <List <StudentRecord> > packages = new List <List <StudentRecord> >();

            bkw.ReportProgress(1, null);
            #region 切package
            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--;
            }
            #endregion

            double maxStudents = selectedStudents.Count;
            if (maxStudents == 0)
            {
                maxStudents = 1;
            }
            double computedStudents = 0;
            bool   allPass          = true;

            List <DSRequest> requests = new List <DSRequest>();
            foreach (List <StudentRecord> var in packages)
            {
                if (var.Count == 0)
                {
                    continue;
                }
                Dictionary <StudentRecord, List <string> > errormessages = computer.FillStudentGradCalcScore(helper, var);
                DSXmlHelper requesthelper = new DSXmlHelper("UpdateStudentList");
                foreach (StudentRecord stu in var)
                {
                    requesthelper.AddElement("Student");
                    requesthelper.AddElement("Student", "Field");
                    requesthelper.AddElement("Student/Field", "GradScore");
                    requesthelper.AddElement("Student/Field/GradScore", ((XmlElement)stu.Fields["GradCalcScore"]));
                    requesthelper.AddElement("Student", "Condition");
                    requesthelper.AddElement("Student/Condition", "ID", stu.StudentID);
                }
                requests.Add(new DSRequest(requesthelper));
                computedStudents += var.Count;
                if (errormessages.Count > 0)
                {
                    allPass = false;
                }
                if (bkw.CancellationPending)
                {
                    break;
                }
                else
                {
                    bkw.ReportProgress((int)((computedStudents * 100.0) / maxStudents), errormessages);
                }
            }
            if (allPass)
            {
                e.Result = new object[] { requests, selectedStudents }
            }
            ;
            else
            {
                e.Result = null;
            }
        }