Ejemplo n.º 1
0
        /// <summary>
        /// Pivot 列法,基本上名次一定是全部列出才能適用此種列法。
        /// </summary>
        /// <param name="scopes"></param>
        /// <param name="ratingNames">排名項目名稱清單,例:國文、英文...</param>
        /// <param name="filter"></param>
        public void Output(List <RatingScope <RatingStudent> > scopes, List <string> ratingNames)
        {
            Workbook book = new Workbook();

            book.Worksheets.Clear();
            Worksheet sheet = book.Worksheets[book.Worksheets.Add()];
            int       rowOffset = 0, columnOffset = 0;

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

            foreach (RatingScope <RatingStudent> each in scopes)
            {
                students.AddRange(each);
            }

            //排序學生資料。
            students.Sort(new Comparison <RatingStudent>(RatingUtils.RatingStudentComparison));

            foreach (string field in new string[] { "班級", "座號", "姓名", "學號" })
            {
                sheet.Cells[0, columnOffset++].PutValue(field);
            }

            foreach (string field in ratingNames)
            {
                sheet.Cells[0, columnOffset++].PutValue(field);
                sheet.Cells[0, columnOffset++].PutValue("排名");
                sheet.Cells[0, columnOffset++].PutValue("百分排名");
            }

            foreach (RatingStudent student in students)
            {
                columnOffset = 0;
                rowOffset++;

                foreach (string field in new string[] { student.ClassName, student.SeatNo, student.Name, student.StudentNumber })
                {
                    sheet.Cells[rowOffset, columnOffset++].PutValue(field);
                }

                foreach (string subject in ratingNames)
                {
                    string score = "", level = "", percentage = "";

                    if (student.Places.Contains(subject))
                    {
                        //去除 00 大絕招。
                        score      = ((double)student.Places[subject].Score).ToString();
                        level      = student.Places[subject].Level.ToString();
                        percentage = student.Places[subject].Percentage.ToString();
                    }

                    sheet.Cells[rowOffset, columnOffset++].PutValue(score);
                    sheet.Cells[rowOffset, columnOffset++].PutValue(level);
                    sheet.Cells[rowOffset, columnOffset++].PutValue(percentage);
                }
            }

            RatingUtils.Save(book, "分別排名結果.xls");
        }
Ejemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="scopes"></param>
        /// <param name="ratingNames">排名項目名稱,例:國文。</param>
        /// <param name="param"></param>
        internal void Output(List <RatingScope <RatingStudent> > scopes, List <string> ratingNames, FilterParameter filter)
        {
            Workbook book = new Workbook();

            book.Worksheets.Clear();
            Worksheet sheet = book.Worksheets[book.Worksheets.Add()];
            int       rowOffset = 0, columnOffset = 0;

            foreach (string field in new string[] { "班級 ", "座號", "姓名", "學號", "名稱", "分數", "排名", "百分排名" })
            {
                sheet.Cells[0, columnOffset++].PutValue(field);
            }

            foreach (string eachRating in ratingNames)                    //每一種排名。
            {
                foreach (RatingScope <RatingStudent> eachScope in scopes) //每一種範圍。
                {
                    RatingScope <RatingStudent> eachFiltered;
                    if (filter.Mode == FilterMode.None)
                    {
                        eachFiltered = eachScope;
                    }
                    else if (filter.Mode == FilterMode.Place)
                    {
                        eachFiltered = eachScope.GetTopPlaces(eachRating, filter.Top);
                    }
                    else if (filter.Mode == FilterMode.PlaceL)
                    {
                        eachFiltered = eachScope.GetLastPlaces(eachRating, filter.Last);
                    }
                    else if (filter.Mode == FilterMode.Percentage)
                    {
                        eachFiltered = eachScope.GetTopPercentage(eachRating, filter.Top);
                    }
                    else if (filter.Mode == FilterMode.PercentageL)
                    {
                        eachFiltered = eachScope.GetLastPercentage(eachRating, filter.Last);
                    }
                    else
                    {
                        throw new ArgumentException("無此種取名次方式。");
                    }

                    eachFiltered.Sort(new PlaceComparer(eachRating));

                    foreach (RatingStudent student in eachFiltered)
                    {
                        columnOffset = 0;
                        rowOffset++;

                        foreach (string field in new string[] { student.ClassName, student.SeatNo, student.Name, student.StudentNumber })
                        {
                            sheet.Cells[rowOffset, columnOffset++].PutValue(field);
                        }

                        string score = "", level = "", percentage = "";

                        //去除 00 大絕招。
                        score      = ((double)student.Places[eachRating].Score).ToString();
                        level      = student.Places[eachRating].Level.ToString();
                        percentage = student.Places[eachRating].Percentage.ToString();

                        sheet.Cells[rowOffset, columnOffset++].PutValue(eachRating);
                        sheet.Cells[rowOffset, columnOffset++].PutValue(score);
                        sheet.Cells[rowOffset, columnOffset++].PutValue(level);
                        sheet.Cells[rowOffset, columnOffset++].PutValue(percentage);
                    }
                }
            }

            RatingUtils.Save(book, "分別排名結果.xls");
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="scopes"></param>
        /// <param name="originParsers"></param>
        /// <param name="rankName">排名項目名稱,例如:加權平均…</param>
        /// <param name="filter"></param>
        internal void Output(List <RatingScope <RatingStudent> > scopes, List <ScoreParser> originParsers, string rankName, FilterParameter filter)
        {
            Workbook book = new Workbook();

            book.Worksheets.Clear();
            Worksheet sheet = book.Worksheets[book.Worksheets.Add()];
            int       rowOffset = 0, columnOffset = 0;

            Dictionary <string, RatingStudent> dicstudents = new Dictionary <string, RatingStudent>();

            foreach (RatingScope <RatingStudent> eachOrigin in scopes)
            {
                RatingScope <RatingStudent> eachFiltered;
                if (filter.Mode == FilterMode.None)
                {
                    eachFiltered = eachOrigin;
                }
                else if (filter.Mode == FilterMode.Place)
                {
                    eachFiltered = eachOrigin.GetTopPlaces(rankName, filter.Top);
                }
                else if (filter.Mode == FilterMode.PlaceL)
                {
                    eachFiltered = eachOrigin.GetLastPlaces(rankName, filter.Last);
                }
                else if (filter.Mode == FilterMode.Percentage)
                {
                    eachFiltered = eachOrigin.GetTopPercentage(rankName, filter.Top);
                }
                else if (filter.Mode == FilterMode.PercentageL)
                {
                    eachFiltered = eachOrigin.GetLastPercentage(rankName, filter.Last);
                }
                else
                {
                    throw new ArgumentException("無此種取名次方式。");
                }

                foreach (RatingStudent eachStud in eachFiltered)
                {
                    if (!dicstudents.ContainsKey(eachStud.Id))
                    {
                        dicstudents.Add(eachStud.Id, eachStud);
                    }
                }
            }
            List <RatingStudent> students = new List <RatingStudent>(dicstudents.Values);

            //排序學生資料。
            students.Sort(new Comparison <RatingStudent>(RatingUtils.RatingStudentComparison));

            foreach (string field in new string[] { "班級 ", "座號", "姓名", "學號" })
            {
                sheet.Cells[0, columnOffset++].PutValue(field);
            }

            //列出原始成績的科目欄位。
            foreach (ScoreParser field in originParsers)
            {
                sheet.Cells[0, columnOffset++].PutValue(field.Name);
            }

            sheet.Cells[0, columnOffset++].PutValue(rankName); //運算排名的名稱。
            sheet.Cells[0, columnOffset++].PutValue("名次");     //運算排名的名次。

            foreach (RatingStudent student in students)
            {
                columnOffset = 0;
                rowOffset++;

                foreach (string field in new string[] { student.ClassName, student.SeatNo, student.Name, student.StudentNumber })
                {
                    sheet.Cells[rowOffset, columnOffset++].PutValue(field);
                }

                //列出原始成績。
                foreach (ScoreParser eachParser in originParsers)
                {
                    decimal?originScore = eachParser.GetScore(student);

                    if (originScore.HasValue)
                    {
                        sheet.Cells[rowOffset, columnOffset++].PutValue(((double)originScore).ToString());
                    }
                    else
                    {
                        columnOffset++;
                    }
                }

                string score = "", level = "";
                if (student.Places.Contains(rankName))
                {
                    //去除 00 大絕招。
                    score = ((double)student.Places[rankName].Score).ToString();
                    level = student.Places[rankName].Level.ToString();
                }

                sheet.Cells[rowOffset, columnOffset++].PutValue(score);
                sheet.Cells[rowOffset, columnOffset++].PutValue(level);
            }

            RatingUtils.Save(book, "運算排名結果.xls");
        }