示例#1
0
            public int Compare(Student x, Student y)
            {
                decimal scoreX = _target.GetScore(x);
                decimal scoreY = _target.GetScore(y);

                //反過來排,由大到小。
                return(scoreY.CompareTo(scoreX));
            }
示例#2
0
        public static void Rank(RatingScope scope, IRatingTarget targetScore, RatingMethod method)
        {
            //int t1 = Environment.TickCount;

            List <Student> students = scope.GetContainTargetList(targetScore);

            //按成績高低排序。
            students.Sort(new ScoreComparer(targetScore));

            //實際有包含成績的人數。
            int actualBase = students.Count;

            //所有被排名的人數。
            int baseCount = scope.Count;

            //名次決定演算法。
            IRatingAlgorithm placeDecision = GetAlgorithm(method);

            foreach (Student eachStudent in students)
            {
                //決定名次
                int place = placeDecision.NextPlace(targetScore.GetScore(eachStudent));

                //寫入名次資訊。
                targetScore.SetPlace(eachStudent, new ResultPlace(scope, targetScore, baseCount, actualBase, place));
            }

            //string msg = "排名時間:{0} 範圍名稱:{1} 成績名稱:{2}";
            //Console.WriteLine(msg, Environment.TickCount - t1, scope.Name, targetScore.Name);
        }
示例#3
0
        private void lvTargets_Click(object sender, EventArgs e)
        {
            if (lvScopes.FocusedItem == null)
            {
                return;
            }
            if (lvTargets.FocusedItem == null)
            {
                return;
            }
            HighlighSelected(sender as ListView);

            IRatingTarget target = lvTargets.FocusedItem.Tag as IRatingTarget;
            RatingScope   scope  = lvScopes.FocusedItem.Tag as RatingScope;

            lvPlace.SuspendLayout();
            lvPlace.Items.Clear();
            List <ListViewItem> items = new List <ListViewItem>();

            foreach (Student eachStu in scope)
            {
                ListViewItem item = new ListViewItem();
                item.Text = eachStu.ClassName;
                item.SubItems.Add(eachStu.SeatNumber);
                item.SubItems.Add(eachStu.Name);

                decimal score = target.GetScore(eachStu);
                if (score == decimal.MinValue)
                {
                    item.SubItems.Add("無");
                }
                else
                {
                    item.SubItems.Add(score.ToString());
                }

                ResultPlace place = target.GetPlace(eachStu, scope.ScopeType);
                if (place == null)
                {
                    item.SubItems.Add("無");
                }
                else
                {
                    item.SubItems.Add(place.Place.ToString());
                }

                item.Tag = eachStu;

                items.Add(item);
            }
            lvPlace.Items.AddRange(items.ToArray());
            lvPlace.ResumeLayout();
        }