Example #1
0
        public void AddScore(string examID, decimal?score, int?effort)
        {
            if (!Scores.ContainsKey(examID))
            {
                Scores.Add(examID, new ScoreData());
            }
            ScoreData data = Scores[examID];

            data.Score  = score;
            data.Effort = effort;
        }
Example #2
0
        public decimal?GetScore(string examID)
        {
            if (_cached.Contains(examID) && _scoreCache.ContainsKey(examID))
            {
                return(_scoreCache[examID]);
            }
            else
            {
                _cached.Add(examID);
                decimal s        = decimal.Zero;
                decimal c        = decimal.Zero;
                bool    hasScore = false;

                foreach (var subject in Subjects.Values)
                {
                    if (!subject.Scores.ContainsKey(examID))
                    {
                        continue;
                    }
                    ScoreData data = subject.Scores[examID];

                    if (!data.Score.HasValue)
                    {
                        continue;
                    }

                    s       += data.Score.Value * subject.Credit;
                    c       += subject.Credit;
                    hasScore = true;
                }

                if (hasScore && c > decimal.Zero)
                {
                    if (!_scoreCache.ContainsKey(examID))
                    {
                        _scoreCache.Add(examID, null);
                    }
                    _scoreCache[examID] = s / c;
                    return(_scoreCache[examID]);
                }
                else
                {
                    return(null);
                }
            }
        }
Example #3
0
        private int WriteDomainRow(Cell indexCell, DomainRow domain)
        {
            WordHelper.Write(indexCell, _font, string.IsNullOrEmpty(domain.DomainName) ? "彈性課程" : domain.DomainName);
            int  col         = 0;
            Cell subjectCell = WordHelper.GetMoveRightCell(indexCell, 1);
            int  count       = 0;

            foreach (var subjectName in domain.Subjects.Keys)
            {
                SubjectRow row = domain.Subjects[subjectName];
                if (row.Display)
                {
                    Cell temp = subjectCell;
                    WordHelper.Write(temp, _font, row.SubjectName);
                    temp = temp.NextSibling as Cell;
                    WordHelper.Write(temp, _font, row.PeriodCredit);

                    foreach (string examID in row.Scores.Keys)
                    {
                        ScoreData data       = row.Scores[examID];
                        string    effortText = string.Empty;
                        if (data.Effort.HasValue)
                        {
                            effortText = _effortMapper.GetTextByInt(data.Effort.Value);
                        }

                        temp = WordHelper.GetMoveRightCell(subjectCell, _columnMapping[examID] - 1);
                        WordHelper.Write(temp, _font, (data.Score.HasValue ? "" + _calculator.ParseSubjectScore(data.Score.Value) : ""));
                        WordHelper.Write(temp.NextSibling as Cell, _font, effortText);
                    }

                    if (_AttendDict.ContainsKey(subjectName))
                    {
                        temp = WordHelper.GetMoveRightCell(subjectCell, _columnMapping["平時評量"] - 1);

                        // 平時
                        if (_AttendDict[subjectName].OrdinarilyScore.HasValue)
                        {
                            WordHelper.Write(temp, _font, _calculator.ParseSubjectScore(_AttendDict[subjectName].OrdinarilyScore.Value).ToString());
                        }
                        else
                        {
                            WordHelper.Write(temp, _font, "");
                        }

                        if (_AttendDict[subjectName].OrdinarilyEffort.HasValue)
                        {
                            WordHelper.Write(temp.NextSibling as Cell, _font, _effortMapper.GetTextByInt(_AttendDict[subjectName].OrdinarilyEffort.Value));
                        }
                        else
                        {
                            WordHelper.Write(temp.NextSibling as Cell, _font, "");
                        }


                        //temp = WordHelper.GetMoveRightCell(indexCell, _columnMapping["課程總成績"]);

                        //// 課程總成績
                        //if (_AttendDict[subjectName].Score.HasValue)
                        //    WordHelper.Write(temp, _font, _calculator.ParseSubjectScore(_AttendDict[subjectName].Score.Value).ToString());
                        //else
                        //    WordHelper.Write(temp, _font, "");

                        //if (_AttendDict[subjectName].Effort.HasValue)
                        //    WordHelper.Write(temp.NextSibling as Cell, _font, _effortMapper.GetTextByInt(_AttendDict[subjectName].Effort.Value));
                        //else
                        //    WordHelper.Write(temp.NextSibling as Cell, _font, "");
                    }

                    subjectCell = WordHelper.GetMoveDownCell(subjectCell, 1);

                    if (subjectCell == null)
                    {
                        break;
                    }
                    count++;
                }
            }
            return(count);
        }