Exemplo 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");
        }
Exemplo n.º 2
0
        private void FormSemestersSubject_Load(object sender, EventArgs e)
        {
            //if (Site.DesignMode) return;

            RatingUtils.DisableControls(this);
            RefreshDomainOptions();
            RatingUtils.EnableControls(this);
        }
Exemplo n.º 3
0
        private void FormExamSubject_Load(object sender, EventArgs e)
        {
            //if (Site.DesignMode) return;

            RatingUtils.DisableControls(this);
            RatingUtils.SetSemesterDefaultItems(cboSchoolYear, cboSemester);
            Sems = new SemesterSelector(cboSchoolYear, cboSemester);
            Sems.SemesterChanged += new EventHandler(Sems_SemesterChanged);
            RefreshSubjectOptions();
            RatingUtils.EnableControls(this);
        }
Exemplo n.º 4
0
        private void btnRank_Click(object sender, EventArgs e)
        {
            if (Courses.Count <= 0)
            {
                MsgBox.Show("無任何成績資料可排名。");
                return; //沒有課程資料就不排名了。
            }
            if (!Sems.ValidateControlContent())
            {
                return;                                   //學期資訊不正確不進行排名。
            }
            if (!ValidateExamControl())
            {
                return;                           //試別資訊不正確不進行排名。
            }
            if (!ValidateTopRankText())
            {
                return;
            }
            if (!ValidateLastRankText())
            {
                return;
            }
            if (!ValidatePercentageText())
            {
                return;
            }
            if (!ValidateLastPercentageText())
            {
                return;
            }
            if (!ValidateDataGrid())
            {
                return;
            }

            RefreshSelectedItems();
            if (SelectedItems.Count <= 0)
            {
                return;
            }

            RatingUtils.DisableControls(this);
            PrepareData();
        }
Exemplo n.º 5
0
        private void btnRank_Click(object sender, EventArgs e)
        {
            if (SemesterScores.Count <= 0)
            {
                MsgBox.Show("無任何成績資料可排名。");
                return; //沒有任何學期成績不進行排名。
            }
            if (!ValidateDataGrid())
            {
                return;
            }
            if (!ValidateTopRankText())
            {
                return;
            }
            if (!ValidateLastRankText())
            {
                return;
            }
            if (!ValidatePercentageText())
            {
                return;
            }
            if (!ValidateLastPercentageText())
            {
                return;
            }

            RefreshSelectedItems();
            if (SelectedItems.Count <= 0)
            {
                return;
            }

            RefreshSelectedTokens();
            if (Tokens.Count <= 0)
            {
                MsgBox.Show("請選擇至少一個學期來進行排名。");
                return;
            }

            RatingUtils.DisableControls(this);
            PrepareData();
        }
Exemplo n.º 6
0
        private void FormExamSubject_Load(object sender, EventArgs e)
        {
            //if (Site.DesignMode) return;

            RatingUtils.DisableControls(this);
            RatingUtils.SetSemesterDefaultItems(cboSchoolYear, cboSemester);
            RatingUtils.SetExamDefaultItems(cboExam);
            Sems = new SemesterSelector(cboSchoolYear, cboSemester);
            Sems.SemesterChanged += new EventHandler(Sems_SemesterChanged);

            int t1 = Environment.TickCount;

            IncludeQuery = new AEIncludeQuery();
            Console.WriteLine(string.Format("new AEIncludeQuery() Time:{0}", Environment.TickCount - t1));

            t1 = Environment.TickCount;
            if (cboExam.Items.Count > 0)
            {
                cboExam.SelectedIndex = 0;
            }
            Console.WriteLine(string.Format("cboExam.SelectedIndex Time:{0}", Environment.TickCount - t1));

            RatingUtils.EnableControls(this);
        }
Exemplo n.º 7
0
        protected override void PrepareDataComplete(Exception error)
        {
            RatingUtils.EnableControls(this);

            if (error != null)
            {
                MsgBox.Show(error.Message);
                return;
            }

            CalculationScoreParser calcparser          = rbCombine.Checked ? GetCalculationScoreParser() : null;
            List <ScoreParser>     parsers             = SelectedItems.Keys.ToScoreParsers(Token);
            List <RatingScope <RatingStudent> > scopes = ToScopes();

            //分別排名。
            foreach (RatingScope <RatingStudent> eachScope in scopes)
            {
                foreach (ScoreParser eachParser in parsers)
                {
                    eachScope.Rank(eachParser, PlaceOptions.Unsequence);
                }
            }

            if (calcparser != null)
            {
                //運算排名。
                foreach (RatingScope <RatingStudent> eachScope in scopes)
                {
                    eachScope.Rank(calcparser, PlaceOptions.Unsequence);
                }
            }

            FilterParameter param = new FilterParameter();

            if (rbAllRank.Checked)
            {
                param.Mode = FilterMode.None;
            }
            else if (rbTopRank.Checked)
            {
                // 排名
                param.Mode = FilterMode.Place;
                param.Top  = int.Parse(txtTopRank.Text);
            }
            else if (rbLastRank.Checked)
            {
                // 後排名
                param.Mode = FilterMode.PlaceL;
                param.Last = int.Parse(txtLastRank.Text);
            }
            else if (rbPercentage.Checked)
            {
                // 排名百分比
                param.Mode = FilterMode.Percentage;
                param.Top  = int.Parse(txtPercentage.Text);
            }
            else if (rbLastPercentage.Checked)
            {
                // 後排名百分比
                param.Mode = FilterMode.PercentageL;
                param.Last = int.Parse(txtLastPercentage.Text);
            }

            else
            {
                throw new ArgumentException("無此種過慮排名的方式。");
            }

            if (rbSeparate.Checked)                                                 //分別排名。
            {
                if (rbAllRank.Checked)                                              //如果是列出全部名次的話。
                {
                    new OutputSeparatePivot().Output(scopes, parsers.ToNameList()); //分別列出科目、名次(Pivot 列法)。
                }
                else
                {
                    new OutputSeparate().Output(scopes, parsers.ToNameList(), param); //分別列出科目、名次(非 Pivot 列法)。
                }
            }
            else
            {
                new OutputCalculationPivot().Output(scopes, parsers, calcparser.Name, param); //列出運算名次、運算前成績。
            }
        }
Exemplo n.º 8
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");
        }
Exemplo n.º 10
0
 private void FormGraduation_Load(object sender, EventArgs e)
 {
     RatingUtils.DisableControls(this);
     RatingUtils.EnableControls(this);
 }
Exemplo n.º 11
0
 /// <summary>
 /// 將需要排名的學生指定到表單中。
 /// </summary>
 public void SetRatingStudents(IEnumerable <string> studentIds)
 {
     Students = RatingUtils.ToRatingStudent(studentIds);
     DisplaySelectedStudentCount();
 }