Exemplo n.º 1
0
        //最好這程式有人能維護的了.......
        private void MailMerge_MergeField(object sender, MergeFieldEventArgs e)
        {
            //不是 Fix 開頭的合併欄位不處理。
            if (!e.FieldName.ToUpper().StartsWith("Fix".ToUpper()))
            {
                return;
            }

            DocumentBuilder builder = new DocumentBuilder(e.Document);

            ReportStudent student = e.FieldValue as ReportStudent;

            //如果合併值不是 ReportStudent 就跳過...意思是有問題...。
            if (student == null)
            {
                return;
            }

            builder.MoveToField(e.Field, true);
            e.Field.Remove();

            if (e.FieldName == "Fix:科目資訊")
            {
                #region 列印年級學期資訊(有點複雜)。
                SemesterDataCollection semses = student.SHistory.GetGradeYearSemester();
                //Row SemesterRow = builder.CurrentParagraph.ParentNode.ParentNode.NextSibling as Row; //下一個 Row。
                //Paragraph originParagraph = builder.CurrentParagraph;

                int count = 0;//, offset = 1;

                foreach (SemesterData each in semses)
                {
                    //string currentGradeyear = Util.GetGradeyearString(each.GradeYear.ToString());

                    ////如果沒有年級,就跳過。
                    //if (string.IsNullOrEmpty(currentGradeyear)) continue;

                    //builder.Write(currentGradeyear + "年級");
                    Paragraph nextPh = Util.NextCell(builder.CurrentParagraph);
                    if (nextPh == null)
                    {
                        break;                 //沒有下一個 Cell ,就不印資料了。
                    }
                    builder.MoveTo(nextPh);

                    //Paragraph resetParagraph = builder.CurrentParagraph;
                    //SemesterRow.Cells[count + offset].Write(builder, GetSemesterString(each));

                    SemesterData semester = new SemesterData(0, each.SchoolYear, each.Semester);
                    if (!student.HeaderList.ContainsKey(semester))
                    {
                        student.HeaderList.AddRaw(each, count); //不要懷疑,這是對的。
                    }
                    //builder.MoveTo(resetParagraph);
                    count++;
                }

                //builder.MoveTo(originParagraph);
                //Paragraph nextParagrap = originParagraph;
                //string previousGradeyear = GetText(originParagraph);
                //while ((nextParagrap = Util.NextCell(nextParagrap)) != null)
                //{
                //    if (GetText(nextParagrap) == previousGradeyear)
                //        (nextParagrap.ParentNode as Cell).CellFormat.HorizontalMerge = CellMerge.Previous;

                //    previousGradeyear = GetText(nextParagrap);
                //}
                #endregion

                #region 列印科目資料(爆炸複雜)

                Row   template = builder.CurrentParagraph.ParentNode.ParentNode as Row;
                Table table    = template.ParentNode as Table;

                if (PrintSetting.ListMethod == ListMethod.DomainOnly)
                {
                    PrintDomainOnly(builder, student, template, table);
                }
                else
                {
                    PrintSubjectOnly(builder, student, template, table);
                }

                //設定表格下方線寬。
                double borderWidth = (template.NextSibling as Row).Cells[0].CellFormat.Borders.Bottom.LineWidth;
                foreach (Cell each in (template.PreviousSibling as Row).Cells)
                {
                    each.CellFormat.Borders.Bottom.LineWidth = borderWidth;
                }

                template.NextSibling.Remove();
                template.Remove();
                #endregion
            }
            if (e.FieldName == "Fix:照片")
            {
                if (student.GraduatePhoto != null)
                {
                    Shape photo = builder.InsertImage(student.GraduatePhoto);
                    Cell  cell  = builder.CurrentParagraph.ParentNode as Cell;
                    Row   row   = cell.ParentRow;

                    double rectHeight = row.RowFormat.Height, rectWidth = cell.CellFormat.Width;

                    double heightRate = (rectHeight / photo.Height);
                    double widthRate  = (rectWidth / photo.Width);
                    double rate       = 0;
                    if (heightRate < widthRate)
                    {
                        rate = heightRate;
                    }
                    else
                    {
                        rate = widthRate;
                    }

                    photo.Width  = photo.Width * rate;
                    photo.Height = photo.Height * rate;
                }
            }
        }
Exemplo n.º 2
0
        public static void ReadUpdateRecordDate(this IEnumerable <ReportStudent> students, IStatusReporter reporter)
        {
            int t1 = Environment.TickCount;
            Dictionary <string, ReportStudent> dicstudents = students.ToDictionary();
            List <string> keys = students.ToSC().ToKeys();

            Campus.FunctionSpliter <string, JHUpdateRecordRecord> selectData = new Campus.FunctionSpliter <string, JHUpdateRecordRecord>(500, 5);
            selectData.Function = delegate(List <string> ps)
            {
                return(JHUpdateRecord.SelectByStudentIDs(ps));
            };
            List <JHUpdateRecordRecord> updaterecords = selectData.Execute(keys);

            Dictionary <string, List <JHUpdateRecordRecord> > dicupdaterecords = new Dictionary <string, List <JHUpdateRecordRecord> >();
            string ValidCodes = "1:2";  //新生:1 轉入:3 復學:6,畢業:2

            foreach (JHUpdateRecordRecord each in updaterecords)
            {
                //不是要處理的代碼,就跳過。
                if (ValidCodes.IndexOf(each.UpdateCode) < 0)
                {
                    continue;
                }

                if (!dicupdaterecords.ContainsKey(each.StudentID))
                {
                    dicupdaterecords.Add(each.StudentID, new List <JHUpdateRecordRecord>());
                }
                dicupdaterecords[each.StudentID].Add(each);
            }

            foreach (KeyValuePair <string, List <JHUpdateRecordRecord> > each in dicupdaterecords)
            {
                each.Value.Sort(delegate(JHUpdateRecordRecord x, JHUpdateRecordRecord y)
                {
                    DateTime xx, yy;

                    if (!DateTime.TryParse(x.UpdateDate, out xx))
                    {
                        xx = DateTime.MinValue;
                    }

                    if (!DateTime.TryParse(y.UpdateDate, out yy))
                    {
                        yy = DateTime.MinValue;
                    }

                    return(xx.CompareTo(yy));
                });
            }

            string ECodes = "1"; //入學
            string GCodes = "2"; //畢業

            foreach (KeyValuePair <string, List <JHUpdateRecordRecord> > each in dicupdaterecords)
            {
                if (!dicstudents.ContainsKey(each.Key))
                {
                    continue;
                }
                ReportStudent student = dicstudents[each.Key];

                JHUpdateRecordRecord e = each.Value[0];
                JHUpdateRecordRecord g = each.Value[each.Value.Count - 1];

                if (ECodes.IndexOf(e.UpdateCode) >= 0)
                {
                    DateTime dt;

                    if (DateTime.TryParse(e.UpdateDate, out dt))
                    {
                        student.EntranceDate    = string.Format("{0}/{1}/{2}", dt.Year - 1911, dt.Month, dt.Day);
                        student.EngEntranceDate = dt.ToString(Util.EnglishFormat, Util.USCulture);
                    }
                }

                if (GCodes.IndexOf(g.UpdateCode) >= 0)
                {
                    DateTime dt;

                    if (DateTime.TryParse(g.UpdateDate, out dt))
                    {
                        student.GraduateDate    = string.Format("{0}/{1}/{2}", dt.Year - 1911, dt.Month, dt.Day);
                        student.EngGraduateDate = dt.ToString(Util.EnglishFormat, Util.USCulture);
                    }
                }
            }

            Console.WriteLine(Environment.TickCount - t1);
        }
Exemplo n.º 3
0
            public bool GetValue(string fieldName, out object fieldValue)
            {
                fieldValue = string.Empty;
                ReportStudent student = Students[Index];

                if (fieldName.ToUpper().StartsWith("Fix:".ToUpper()))
                {
                    fieldValue = student;
                    return(true);
                }

                switch (fieldName)
                {
                //case "學號":
                //    fieldValue = student.StudentNumber;
                //    break;
                //case "班級":
                //    fieldValue = student.ClassName;
                //    break;
                //case "座號":
                //    fieldValue = student.SeatNo;
                //    break;
                case "姓名":
                    fieldValue = student.Name;
                    break;

                case "英文姓名":
                    fieldValue = student.EnglishName;
                    break;

                case "身分證號":
                    fieldValue = student.IDNumber;
                    break;

                //case "性別":
                //    fieldValue = student.Gender;
                //    break;
                case "生日":
                    DateTime dtBirthday;

                    if (DateTime.TryParse(student.Birthday, out dtBirthday))
                    {
                        fieldValue = dtBirthday.ToString(Util.EnglishFormat, Util.USCulture);
                    }
                    else
                    {
                        fieldValue = string.Empty;
                    }

                    break;

                case "列印日期":
                    DateTime dtPrintDate;

                    if (DateTime.TryParse(PrintDate, out dtPrintDate))
                    {
                        fieldValue = dtPrintDate.ToString(Util.EnglishFormat, Util.USCulture);
                    }
                    else
                    {
                        fieldValue = string.Empty;
                    }
                    break;

                case "學校名稱":
                    fieldValue = K12.Data.School.ChineseName;
                    break;

                case "英文學校名稱":
                    fieldValue = K12.Data.School.EnglishName;
                    break;

                case "入學日期":
                    if (string.IsNullOrEmpty(Preference.EntranceDate))
                    {
                        fieldValue = student.EngEntranceDate;
                    }
                    else
                    {
                        DateTime engdt;
                        if (DateTime.TryParse(Preference.EntranceDate, out engdt))
                        {
                            fieldValue = engdt.ToString(Util.EnglishFormat, Util.USCulture);
                        }
                        else
                        {
                            fieldValue = Preference.EntranceDate;
                        }
                    }
                    break;

                case "畢業日期":
                    if (string.IsNullOrEmpty(Preference.GraduateDate))
                    {
                        fieldValue = student.EngGraduateDate;
                    }
                    else
                    {
                        DateTime engdt;
                        if (DateTime.TryParse(Preference.GraduateDate, out engdt))
                        {
                            fieldValue = engdt.ToString(Util.EnglishFormat, Util.USCulture);
                        }
                        else
                        {
                            fieldValue = Preference.GraduateDate;
                        }
                    }
                    break;
                }

                return(true);
            }
Exemplo n.º 4
0
        private void PrintDomainOnly(DocumentBuilder builder, ReportStudent student, Row template, Table table)
        {
            #region 列印領域
            UniqueSet <RowHeader> RowIndexs = new UniqueSet <RowHeader>();

            #region 列印 RowHeader
            foreach (SemesterData semester in student.SHistory.GetGradeYearSemester())
            {
                SemesterData sysems = new SemesterData(0, semester.SchoolYear, semester.Semester);

                //如果不包含該學期成績資料,就跳過。
                if (!student.SemestersScore.Contains(sysems))
                {
                    continue;
                }

                SemesterScore semsscore = student.SemestersScore[sysems];

                //準備彈性課程的科目(要詳列出來)。
                foreach (string strSubject in semsscore.Subject)
                {
                    SemesterSubjectScore subject = semsscore.Subject[strSubject];

                    if (DetailDomain.Contains(subject.Domain))
                    {
                        RowHeader header = new RowHeader(subject.Domain, strSubject);
                        header.IsDomain = false;

                        if (!RowIndexs.Contains(header))
                        {
                            RowIndexs.Add(header);
                        }
                    }
                }

                //準備領域資料。
                foreach (string strDomain in semsscore.Domain)
                {
                    if (!Subj.Domains.Contains(strDomain))
                    {
                        continue;
                    }

                    SemesterDomainScore domain = semsscore.Domain[strDomain];

                    if (!DetailDomain.Contains(strDomain))
                    {
                        RowHeader header = new RowHeader(strDomain, string.Empty);
                        header.IsDomain = true;

                        if (!RowIndexs.Contains(header))
                        {
                            RowIndexs.Add(header);
                        }
                    }
                }
            }

            List <RowHeader> sortedHeaders = SortHeader(RowIndexs.ToList());

            //產生 Row。
            List <RowHeader> indexHeaders = new List <RowHeader>();
            Row current  = template;
            int rowIndex = 0;
            foreach (RowHeader header in sortedHeaders)
            {
                RowHeader indexH = header;
                indexH.Index = rowIndex++;
                indexHeaders.Add(indexH);
                bool   hasGroup  = !string.IsNullOrEmpty(Subj.GetDomainGroup(header.Domain));
                string groupName = Subj.GetDomainGroup(header.Domain);

                Row datarow = table.InsertBefore(template.Clone(true), current) as Row;

                if (header.IsDomain)
                {
                    string domainCName  = header.Domain;
                    string domainEName  = Subj.GetDomainEnglish(header.Domain);
                    string domainString = domainCName + (string.IsNullOrEmpty(domainEName) ? "" : domainEName);

                    if (hasGroup)
                    {
                        string gn = groupName;

                        if (groupName == "語文")
                        {
                            gn = "語文\nLanguage";
                        }

                        datarow.Cells[0].Write(builder, gn);
                        datarow.Cells[1].Write(builder, domainString);
                    }
                    else
                    {
                        datarow.Cells[0].Write(builder, domainString);
                    }
                }
                else
                {
                    string gn = "";
                    //Additional Classes

                    if (IsFlexible(header.Domain))
                    {
                        gn = "彈性課程\nAdditional Classes";
                    }
                    else
                    {
                        gn = header.Domain;
                    }

                    string subjCName  = header.Subject;
                    string subjEName  = Subj.GetSubjectEnglish(header.Subject);
                    string subjString = header.Subject + (string.IsNullOrEmpty(subjEName) ? "" : "\n" + subjEName);

                    //把空白的領域當成「彈性課程」。
                    string domain = gn;
                    datarow.Cells[0].Write(builder, domain);
                    datarow.Cells[1].Write(builder, subjString);
                }
            }
            #endregion

            #region 填資料
            //Row RatingRow = null;
            foreach (RowHeader header in indexHeaders)
            {
                SemesterDataCollection semesters = new SemesterDataCollection();
                Row row = table.Rows[header.Index + DataRowOffset];
                foreach (SemesterData semester in student.SHistory.GetGradeYearSemester())
                {
                    SemesterData sysems = new SemesterData(0, semester.SchoolYear, semester.Semester);
                    semesters.Add(sysems);

                    if (!student.SemestersScore.Contains(sysems))
                    {
                        continue;
                    }
                    if (!student.HeaderList.ContainsKey(sysems))
                    {
                        continue;
                    }

                    int           columnIndex = student.HeaderList[sysems];
                    SemesterScore semsscore   = student.SemestersScore[sysems];

                    decimal?score  = null;
                    decimal?weight = null;

                    if (header.IsDomain)
                    {
                        if (semsscore.Domain.Contains(header.Domain))
                        {
                            score  = semsscore.Domain[header.Domain].Value;
                            weight = semsscore.Domain[header.Domain].Weight;
                        }
                    }
                    else
                    {
                        if (semsscore.Subject.Contains(header.Subject))
                        {
                            score  = semsscore.Subject[header.Subject].Value;
                            weight = semsscore.Subject[header.Subject].Weight;
                        }
                    }

                    if (!score.HasValue)
                    {
                        continue;
                    }
                    if (!weight.HasValue)
                    {
                        weight = 0;
                    }

                    if (PrintScore)
                    {
                        row.Cells[columnIndex + 2].Write(builder, score.Value + "");
                    }
                    else
                    {
                        row.Cells[columnIndex + 2].Write(builder, Util.GetDegreeEnglish(score.Value));
                    }
                }
            }

            #endregion

            #region 合併相關欄位。
            string previousCellDomain = string.Empty;
            foreach (RowHeader header in indexHeaders)
            {
                bool   hasGroup  = !string.IsNullOrEmpty(Subj.GetDomainGroup(header.Domain));
                string groupName = Subj.GetDomainGroup(header.Domain);

                Row row = table.Rows[header.Index + DataRowOffset];

                if (previousCellDomain == row.Cells[0].ToTxt())
                {
                    row.Cells[0].CellFormat.VerticalMerge = CellMerge.Previous;
                }
                else
                {
                    row.Cells[0].CellFormat.VerticalMerge = CellMerge.First;
                }

                if (header.IsDomain)
                {
                    if (!hasGroup)
                    {
                        row.Cells[0].CellFormat.HorizontalMerge = CellMerge.First;
                        row.Cells[1].CellFormat.HorizontalMerge = CellMerge.Previous;
                    }
                }

                previousCellDomain = row.Cells[0].ToTxt();
            }
            #endregion

            #endregion
        }
Exemplo n.º 5
0
        private void PrintSubjectOnly(DocumentBuilder builder, ReportStudent student, Row template, Table table)
        {
            #region 列印科目
            UniqueSet <RowHeader> RowIndexs = new UniqueSet <RowHeader>();

            #region 列印 RowHeader
            Dictionary <string, string> subjToDomain = new Dictionary <string, string>();
            foreach (SemesterData semester in student.SHistory.GetGradeYearSemester())
            {
                SemesterData sysems = new SemesterData(0, semester.SchoolYear, semester.Semester);
                if (!student.SemestersScore.Contains(sysems))
                {
                    continue;
                }

                SemesterScore semsscore = student.SemestersScore[sysems];

                foreach (string strSubject in semsscore.Subject)
                {
                    SemesterSubjectScore subject = semsscore.Subject[strSubject];

                    if (!subjToDomain.ContainsKey(strSubject))
                    {
                        subjToDomain.Add(strSubject, subject.Domain);
                    }

                    RowHeader header = new RowHeader(subjToDomain[strSubject], strSubject);
                    header.IsDomain = false;

                    if (!RowIndexs.Contains(header))
                    {
                        RowIndexs.Add(header);
                    }
                }
            }

            List <RowHeader> sortedHeaders = RowIndexs.ToList();
            sortedHeaders.Sort(delegate(RowHeader x, RowHeader y)
            {
                Subj xx = new JHSchool.Evaluation.Subject(x.Subject, x.Domain);
                Subj yy = new JHSchool.Evaluation.Subject(y.Subject, y.Domain);

                return(xx.CompareTo(yy));
            });

            //產生 Row。
            List <RowHeader> indexHeaders = new List <RowHeader>();
            Row current  = template;
            int rowIndex = 0;
            foreach (RowHeader header in sortedHeaders)
            {
                RowHeader indexH = header;
                indexH.Index = rowIndex++;
                indexHeaders.Add(indexH);

                Row datarow = table.InsertBefore(template.Clone(true), current) as Row;

                string gn = "";
                //Additional Classes

                string subjCName  = header.Subject;
                string subjEName  = Subj.GetSubjectEnglish(header.Subject);
                string subjString = header.Subject + (string.IsNullOrEmpty(subjEName) ? "" : " " + subjEName);

                datarow.Cells[0].Write(builder, subjString);

                //if (IsFlexible(header.Domain))
                //{
                //    gn = "彈性課程\nAdditional Classes";
                //    //把空白的領域當成「彈性課程」。
                //    datarow.Cells[0].Write(builder, gn);
                //    datarow.Cells[1].Write(builder, subjString);
                //}
                //else
                //{
                //}
            }
            #endregion

            #region 填資料
            //填資料
            foreach (RowHeader header in indexHeaders)
            {
                SemesterDataCollection semesters = new SemesterDataCollection();
                Row row = table.Rows[header.Index + DataRowOffset];
                foreach (SemesterData semester in student.SHistory.GetGradeYearSemester())
                {
                    SemesterData sysems = new SemesterData(0, semester.SchoolYear, semester.Semester);
                    semesters.Add(sysems);

                    if (!student.SemestersScore.Contains(sysems))
                    {
                        continue;
                    }
                    if (!student.HeaderList.ContainsKey(sysems))
                    {
                        continue;
                    }

                    int           columnIndex = student.HeaderList[sysems];
                    SemesterScore semsscore   = student.SemestersScore[sysems];

                    decimal?score  = null;
                    decimal?weight = null;

                    //if (header.IsDomain)
                    //{
                    //    if (semsscore.Domain.Contains(header.Domain))
                    //    {
                    //        score = semsscore.Domain[header.Domain].Value;
                    //        weight = semsscore.Domain[header.Domain].Weight;
                    //    }
                    //}
                    //else
                    //{
                    if (semsscore.Subject.Contains(header.Subject))
                    {
                        score  = semsscore.Subject[header.Subject].Value;
                        weight = semsscore.Subject[header.Subject].Weight;
                    }
                    //}

                    if (!score.HasValue)
                    {
                        continue;
                    }
                    if (!weight.HasValue)
                    {
                        weight = 0;
                    }

                    if (PrintScore)
                    {
                        row.Cells[columnIndex + 2].Write(builder, score.Value + "");
                    }
                    else
                    {
                        row.Cells[columnIndex + 2].Write(builder, Util.GetDegreeEnglish(score.Value));
                    }
                }
            }
            #endregion

            #region 合併相關欄位。
            string previousCellDomain = string.Empty;
            foreach (RowHeader header in indexHeaders)
            {
                Row row = table.Rows[header.Index + DataRowOffset];

                //if (IsFlexible(header.Domain))
                //{
                //    if (previousCellDomain == row.Cells[0].ToTxt())
                //        row.Cells[0].CellFormat.VerticalMerge = CellMerge.Previous;
                //    else
                //        row.Cells[0].CellFormat.VerticalMerge = CellMerge.First;
                //}
                //else
                {
                    row.Cells[0].CellFormat.HorizontalMerge = CellMerge.First;
                    row.Cells[1].CellFormat.HorizontalMerge = CellMerge.Previous;
                }

                previousCellDomain = row.Cells[0].ToTxt();
            }
            #endregion

            #endregion
        }
Exemplo n.º 6
0
        private void MasterWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            StudentScore.SetClassMapping();

            // 取得學生類別List
//            List<K12.Data.StudentTagRecord> StudTagRecList = K12.Data.StudentTag.SelectByStudentIDs(StudentIDs);
            List <K12.Data.StudentTagRecord> StudTagRecList = K12.Data.StudentTag.SelectAll();

            // 過濾不排學生ID
            List <string> NonStudentIDList = DAL.DALTransfer.GetNonRankStudentIDFromUDTByStudentTag(StudTagRecList, JointAdmissionModule.DAL.DALTransfer.SchoolType.高中);

            foreach (string id in NonStudentIDList)
            {
                if (StudentIDs.Contains(id))
                {
                    StudentIDs.Remove(id);
                }
            }

            List <ReportStudent> PrintStudents = StudentIDs.ToReportStudent();

            if (Preference.PrintRank || Preference.PrintRankPercentage || Preference.FilterRankScope)
            {
                #region 如果要排名。
                //List<ReportStudent> RatingStudents = Util.GetAllStudents();
                List <ReportStudent> RatingStudents = Util.GetStudentsDef(NonStudentIDList);

                RatingStudents.ToSC().ReadSemesterScore(this);
                RatingStudents.ToSC().ReadSemesterHistory(this);

                List <IScoreParser <ReportStudent> > parsers = new List <IScoreParser <ReportStudent> >();
                List <SLearningDomainParser>         allsems = new List <SLearningDomainParser>();

                parsers.Add(new LearningDomainParser(Preference.PrintSemesters));
                allsems.Add(new SLearningDomainParser(1, 1));
                allsems.Add(new SLearningDomainParser(1, 2));
                allsems.Add(new SLearningDomainParser(2, 1));
                allsems.Add(new SLearningDomainParser(2, 2));
                allsems.Add(new SLearningDomainParser(3, 1));
                allsems.Add(new SLearningDomainParser(3, 2));
                allsems.Add(new SLearningDomainParser(7, 1));
                allsems.Add(new SLearningDomainParser(7, 2));
                allsems.Add(new SLearningDomainParser(8, 1));
                allsems.Add(new SLearningDomainParser(8, 2));
                allsems.Add(new SLearningDomainParser(9, 1));
                allsems.Add(new SLearningDomainParser(9, 2));
                foreach (SLearningDomainParser each in allsems)
                {
                    parsers.Add(each);
                }

                // 將學生加入年排名
                List <RatingScope <ReportStudent> > scopes = RatingStudents.ToGradeYearScopes();
                foreach (RatingScope <ReportStudent> each in scopes)
                {
                    foreach (IScoreParser <ReportStudent> parser in parsers)
                    {
                        each.Rank(parser, PlaceOptions.Unsequence);
                    }
                }

                Dictionary <string, StudentScore> DicPrintStudents = PrintStudents.ToSC().ToDictionary();

                foreach (ReportStudent each in RatingStudents)
                {
                    if (DicPrintStudents.ContainsKey(each.Id))
                    {
                        DicPrintStudents[each.Id] = each;
                    }

                    //each.Places["學習領域"].Percentage
                    //each.Places["學習領域"].GetPercentage();
                    //each.Places["學習領域"].Score
                }

                // 整理全部學生年排名
                DAL.DALTransfer.StudRankScoreDict.Clear();

                // 建立Key
                foreach (RatingScope <ReportStudent> scope in scopes)
                {
                    DAL.DALTransfer.StudRankScoreDict.Add(scope.Name, new Dictionary <string, List <JointAdmissionModule.DAL.StudRankScore> >());
                    DAL.DALTransfer.StudRankScoreDict[scope.Name].Add("學期總平均", new List <JointAdmissionModule.DAL.StudRankScore>());
                    foreach (SLearningDomainParser semsIndex in allsems)
                    {
                        DAL.DALTransfer.StudRankScoreDict[scope.Name].Add(semsIndex.Name, new List <JointAdmissionModule.DAL.StudRankScore>());
                    }
                }

                foreach (RatingScope <ReportStudent> scope in scopes)
                {
                    // 學習領域
                    foreach (ReportStudent stud in (from xx in scope where xx.Places.NS("年排名").Contains("學習領域") select xx).ToList())
                    {
                        DAL.StudRankScore srs = new JointAdmissionModule.DAL.StudRankScore();
                        srs.StudentID = stud.StudentID;
                        srs.Place     = stud.Places.NS("年排名")["學習領域"];
                        DAL.DALTransfer.StudRankScoreDict[scope.Name]["學期總平均"].Add(srs);
                    }

                    foreach (SLearningDomainParser semsIndex in allsems)
                    {
                        foreach (ReportStudent stud in (from xx in scope where xx.Places.NS("年排名").Contains(semsIndex.Name) select xx).ToList())
                        {
                            DAL.StudRankScore srs = new JointAdmissionModule.DAL.StudRankScore();
                            srs.StudentID = stud.StudentID;
                            srs.Place     = stud.Places.NS("年排名")[semsIndex.Name];
                            DAL.DALTransfer.StudRankScoreDict[scope.Name][semsIndex.Name].Add(srs);
                        }
                    }
                }



                //foreach (ReportStudent stud in RatingStudents)
                //{
                //-----------------
                //foreach (RatingScope<ReportStudent> scope in scopes)
                //{
                //    if (!DAL.DALTransfer.StudRankScoreDict.ContainsKey(scope.Name))
                //        DAL.DALTransfer.StudRankScoreDict.Add(scope.Name, new Dictionary<string, List<DAL.StudRankScore>>());

                //    foreach (ReportStudent stud in scope)
                //    {
                //        // 學期總平均
                //            if (stud.Places.NS("年排名").Contains("學習領域"))
                //            {
                //                DAL.StudRankScore srs = new JointAdmissionModule.DAL.StudRankScore();
                //                srs.StudentID = stud.StudentID;
                //                srs.Place = stud.Places.NS("年排名")["學習領域"];
                //                if (DAL.DALTransfer.StudRankScoreDict[scope.Name].ContainsKey("學期總平均"))
                //                {
                //                    DAL.DALTransfer.StudRankScoreDict[scope.Name]["學期總平均"].Add(srs);
                //                }
                //                else
                //                {
                //                    List<DAL.StudRankScore> srsList = new List<JointAdmissionModule.DAL.StudRankScore>();
                //                    srsList.Add(srs);
                //                    DAL.DALTransfer.StudRankScoreDict[scope.Name].Add("學期總平均", srsList);
                //                }
                //            }

                //            foreach (SLearningDomainParser semsIndex in allsems)
                //            {

                //                    if (stud.Places.NS("年排名").Contains(semsIndex.Name))
                //                    {
                //                        DAL.StudRankScore srs = new JointAdmissionModule.DAL.StudRankScore();
                //                        srs.StudentID = stud.StudentID;
                //                        srs.Place = stud.Places.NS("年排名")[semsIndex.Name];
                //                        if (DAL.DALTransfer.StudRankScoreDict[scope.Name].ContainsKey(semsIndex.Name))
                //                        {
                //                            DAL.DALTransfer.StudRankScoreDict[scope.Name][semsIndex.Name].Add(srs);
                //                        }
                //                        else
                //                        {
                //                            List<DAL.StudRankScore> srsList = new List<JointAdmissionModule.DAL.StudRankScore>();
                //                            srsList.Add(srs);
                //                            DAL.DALTransfer.StudRankScoreDict[scope.Name].Add(semsIndex.Name, srsList);
                //                        }


                //                    }
                //            }

                //    }
                //}
                //------------------------------------
                //}

                //// 排序對照年排名資料 debug 用
                //for (int i = 1; i <= 9; i++)
                //{
                //    if (DAL.DALTransfer.StudRankScoreDict.ContainsKey(i.ToString()))
                //    {
                //        string idx = i.ToString();
                //        foreach (SLearningDomainParser semsIndex in allsems)
                //        {
                //            if (DAL.DALTransfer.StudRankScoreDict[idx].ContainsKey(semsIndex.Name))
                //            {
                //                var x = from xx in DAL.DALTransfer.StudRankScoreDict[idx][semsIndex.Name] orderby xx.Place.Score descending select xx;
                //                DAL.DALTransfer.StudRankScoreDict[idx][semsIndex.Name] = x.ToList();

                //            }

                //        }
                //    }
                //}

                Workbook wb = new Workbook();
                Dictionary <string, ReportStudent> students = RatingStudents.ToDictionary(x => x.Id);
                int wstCot = 0;
                // 排序對照年排名資料 debug 用

                foreach (RatingScope <ReportStudent> scope in scopes)
                {
                    if (DAL.DALTransfer.StudRankScoreDict.ContainsKey(scope.Name))
                    {
                        string idx = scope.Name;

                        string AvggName = "學期總平均";
                        if (DAL.DALTransfer.StudRankScoreDict[idx].ContainsKey(AvggName))
                        {
                            int row = 1;

                            wb.Worksheets.Add();
                            wb.Worksheets[wstCot].Name = idx + AvggName;
                            wb.Worksheets[wstCot].Cells[0, 0].PutValue("成績");
                            wb.Worksheets[wstCot].Cells[0, 1].PutValue("年排名");
                            wb.Worksheets[wstCot].Cells[0, 2].PutValue("分類");
                            wb.Worksheets[wstCot].Cells[0, 3].PutValue("年級");
                            wb.Worksheets[wstCot].Cells[0, 4].PutValue("SID");
                            wb.Worksheets[wstCot].Cells[0, 5].PutValue("StudCount");

                            foreach (JointAdmissionModule.DAL.StudRankScore xx in DAL.DALTransfer.StudRankScoreDict[idx][AvggName].OrderByDescending(x => x.Place.Score))
                            {
                                wb.Worksheets[wstCot].Cells[row, 0].PutValue(xx.Place.Score);
                                wb.Worksheets[wstCot].Cells[row, 1].PutValue(xx.Place.Percentage);
                                wb.Worksheets[wstCot].Cells[row, 2].PutValue(AvggName);
                                wb.Worksheets[wstCot].Cells[row, 3].PutValue(idx);
                                wb.Worksheets[wstCot].Cells[row, 4].PutValue(xx.StudentID);
                                wb.Worksheets[wstCot].Cells[row, 5].PutValue(xx.Place.Radix);
                                wb.Worksheets[wstCot].Cells[row, 6].PutValue(students[xx.StudentID].GradeYear);
                                row++;
                            }
                            wstCot++;
                        }

                        foreach (SLearningDomainParser semsIndex in allsems)
                        {
                            int row = 1;

                            wb.Worksheets.Add();
                            wb.Worksheets[wstCot].Name = idx + semsIndex.Name.Replace(":", "-");
                            wb.Worksheets[wstCot].Cells[0, 0].PutValue("成績");
                            wb.Worksheets[wstCot].Cells[0, 1].PutValue("年排名");
                            wb.Worksheets[wstCot].Cells[0, 2].PutValue("分類");
                            wb.Worksheets[wstCot].Cells[0, 3].PutValue("年級");
                            wb.Worksheets[wstCot].Cells[0, 4].PutValue("SID");
                            wb.Worksheets[wstCot].Cells[0, 5].PutValue("StudCount");

                            if (DAL.DALTransfer.StudRankScoreDict[idx].ContainsKey(semsIndex.Name))
                            {
                                foreach (JointAdmissionModule.DAL.StudRankScore xx in DAL.DALTransfer.StudRankScoreDict[idx][semsIndex.Name].OrderByDescending(x => x.Place.Score))
                                {
                                    wb.Worksheets[wstCot].Cells[row, 0].PutValue(xx.Place.Score);
                                    wb.Worksheets[wstCot].Cells[row, 1].PutValue(xx.Place.Percentage);
                                    wb.Worksheets[wstCot].Cells[row, 2].PutValue(semsIndex.Name);
                                    wb.Worksheets[wstCot].Cells[row, 3].PutValue(semsIndex.Grade);
                                    wb.Worksheets[wstCot].Cells[row, 4].PutValue(xx.StudentID);
                                    wb.Worksheets[wstCot].Cells[row, 5].PutValue(xx.Place.Radix);
                                    wb.Worksheets[wstCot].Cells[row, 6].PutValue(students[xx.StudentID].GradeYear);
                                    row++;
                                }
                            }
                            wstCot++;
                        }
                    }
                }

                for (int i = 0; i < wb.Worksheets.Count; i++)
                {
                    if (wb.Worksheets[i].Cells.MaxDataRow < 2)
                    {
                        wb.Worksheets.RemoveAt(i);
                    }
                }

                try
                {
                    wb.Save(Application.StartupPath + "\\樂學成績debug.xls", FileFormatType.Excel2003);

                    // System.Diagnostics.Process.Start(Application.StartupPath + "\\樂學成績debug.xls");
                }
                catch (Exception ex)
                {
                }

                if (Preference.FilterRankScope)
                {
                    List <ReportStudent> filteredStudent = new List <ReportStudent>();
                    foreach (ReportStudent each in DicPrintStudents.Values.ToSS())
                    {
                        //看是否有「學習領域」的年排名。
                        if (each.Places.NS("年排名").Contains(LearningDomainParser.PlaceName))
                        {
                            Place place = each.Places.NS("年排名")[LearningDomainParser.PlaceName];
                            if (place.Level >= Preference.RankStart && place.Level <= Preference.RankEnd)
                            {
                                filteredStudent.Add(each);
                            }
                        }
                        PrintStudents = filteredStudent;
                    }
                }
                else
                {
                    PrintStudents = new List <ReportStudent>(DicPrintStudents.Values.ToSS());
                }
                #endregion
            }
            else
            {
                PrintStudents.ToSC().ReadSemesterScore(this);
                PrintStudents.ToSC().ReadSemesterHistory(this);
            }

            List <StudentScore> CalcStudents;
            if (PrintStudents.Count <= 0)
            {
                Feedback("", -1);  //把 Status bar Reset...
                throw new ArgumentException("沒有任何學生資料可列印。");
            }
            else
            {
                CalcStudents = PrintStudents.ToSC();
                CalcStudents.ReadCalculationRule(this); //讀取成績計算規則。

                #region 讀取缺曠獎懲。
                //List<JHMoralScoreRecord> jhmorals = JHSchool.Data.JHMoralScore.SelectByStudentIDs(StudentIDs);
                List <AutoSummaryRecord> jhsummary = AutoSummary.Select(StudentIDs, null);

                Dictionary <string, ReportStudent> DicStudents = PrintStudents.ToDictionary();
                //foreach (JHMoralScoreRecord each in jhmorals)
                foreach (AutoSummaryRecord each in jhsummary)
                {
                    if (!DicStudents.ContainsKey(each.RefStudentID))
                    {
                        continue;
                    }

                    SemesterData  semester = new SemesterData(0, each.SchoolYear, each.Semester);
                    ReportStudent student  = DicStudents[each.RefStudentID];

                    if (!student.Summaries.ContainsKey(semester))
                    {
                        student.Summaries.Add(semester, each.AutoSummary);
                    }
                }
                #endregion

                PrintStudents.ReadUpdateRecordDate(this);

                e.Result = new Report(PrintStudents, Preference).Print();



                Feedback("列印完成", -1);
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// 傳入不包含學生的學生IDList,取得一般或輟學學生
        /// </summary>
        /// <param name="NotInStudentIDList"></param>
        /// <returns></returns>
        public static List <ReportStudent> GetStudentsDef(List <string> NotInStudentIDList)
        {
            List <string> StudentIDList = new List <string>();

            List <ReportStudent> students = new List <ReportStudent>();

            foreach (JHStudentRecord each in JHStudent.SelectAll())
            {
                // 不包含
                if (NotInStudentIDList.Contains(each.ID))
                {
                    continue;
                }

                if (each.Status == K12.Data.StudentRecord.StudentStatus.一般 ||
                    each.Status == K12.Data.StudentRecord.StudentStatus.輟學)
                {
                    ReportStudent rs = new ReportStudent(each);
                    students.Add(rs);
                    StudentIDList.Add(each.ID);
                }
            }

            // 取得學生類別List
            List <StudentTagRecord> StudTagRecList = StudentTag.SelectByStudentIDs(StudentIDList);


            // 取得特種身分學生,加分比
            Dictionary <string, decimal> StudAddWeightDict = DAL.DALTransfer.GetStudentAddWeightFormUDTByStudentTag(StudTagRecList, DAL.DALTransfer.SchoolType.高中);
            // 取得特種身分學生名稱
            Dictionary <string, string> StudSpecTypeDict = DAL.DALTransfer.GetStudentSpcTypeFormUDTByStudentTag(StudTagRecList, JointAdmissionModule.DAL.DALTransfer.SchoolType.高中);
            Dictionary <string, K12.Data.UpdateRecordRecord> studUpdateRec = DAL.DALTransfer.GetStudentUpdareDate3ByStudentID(StudentIDList);

            foreach (ReportStudent rs in students)
            {
                // 加分比
                if (StudAddWeightDict.ContainsKey(rs.StudentID))
                {
                    rs.AddWeight = StudAddWeightDict[rs.StudentID];
                }

                // 學生身分
                if (StudSpecTypeDict.ContainsKey(rs.StudentID))
                {
                    rs.SpcStudTypeName = StudSpecTypeDict[rs.StudentID];
                }

                // 轉入學生異動
                if (studUpdateRec.ContainsKey(rs.StudentID))
                {
                    if (studUpdateRec[rs.StudentID] != null)
                    {
                        DateTime dt;

                        if (DateTime.TryParse(studUpdateRec[rs.StudentID].UpdateDate, out dt))
                        {
                            rs.TransUpdateDateStr = (dt.Year - 1911).ToString() + "/" + dt.Month + "/" + dt.Day;
                        }
                        else
                        {
                            rs.TransUpdateDateStr = "";
                        }

                        rs.LastEnterSchoolyear = studUpdateRec[rs.StudentID].SchoolYear;
                        rs.LastEnterSemester   = studUpdateRec[rs.StudentID].Semester;
                        int gr;
                        if (int.TryParse(studUpdateRec[rs.StudentID].GradeYear, out gr))
                        {
                            rs.LastEnterGradeYear = gr;
                        }
                    }
                }
            }
            return(students);
        }