Example #1
0
 /// <summary>
 /// Возвращает рейтинг игрока на определенную дату.
 /// Участие в турнире влияет на рейтинг только на следующей день после турнира.
 /// Для игрока, которого нет в БД возвращается -1
 /// </summary>
 /// <param name="playerId">Id игрока из БД</param>
 /// <param name="date">дата, на которую рассчитывается рейтинг</param>
 /// <returns></returns>
 public int GetPlayerRating(int playerId, DateTime date)
 {
     if (FPlayers.ContainsKey(playerId))
     {
         Player player = FPlayers[playerId];
         if (date > player.LastRatingDate)
         {
             return(player.Rating - (GetMonthCount(player.LastRatingDate, date) / 3) * 25);
         }
         DateTime last_date = DateTime.MinValue;
         int      rating    = 0;
         foreach (Competition comp in FCompetitions)
         {
             if (comp.Date < date && comp.Results.ContainsKey(playerId))
             {
                 CompetitionResult res = comp.Results[playerId];
                 rating    = res.RatingBegin + res.Penalty;
                 last_date = comp.Date;
             }
         }
         if (last_date != DateTime.MinValue)
         {
             rating -= (GetMonthCount(last_date, date) / 3) * 25;
         }
         return(rating);
     }
     else
     {
         return(-1);
     }
 }
        protected override void OnMouseMove(MouseEventArgs e)
        {
            base.OnMouseMove(e);
            if (RS == null)
            {
                return;
            }
            Point cell;

            if (MouseToCell(e.Location, out cell) && (RS.Players.Count > cell.Y) && (RS.Competitions.Count > cell.X) && (cell.X - ViewColFrom < VisibleColCount))
            {
                Point loc = Rect_Results.Location;
                loc.Offset((cell.X - ViewColFrom + 1) * ColWidth_C - ColWidth_C / 2, (cell.Y - ViewRowFrom) * Height_Row + 2 - pnlInfo.Height);
                //lblCellInfo.Text = String.Format("{0}x{1}", cell.X, cell.Y);
                pnlInfo.Location = loc;
                int         playerId = FPlayers[cell.Y].Id;
                Competition comp     = RS.Competitions[cell.X];
                if (comp.Results.ContainsKey(playerId))
                {
                    CompetitionResult res = comp.Results[playerId];
                    lblInfoRatingBegin.Text = res.RatingBegin.ToString();
                    lblInfoDelta.Text       = res.Delta.ToString();
                    lblInfoPenalty.Text     = (res.Penalty == 0) ? "-" : res.Penalty.ToString();
                    lblInfoRating.Text      = (res.RatingBegin + res.Delta).ToString();
                    pnlInfo.Visible         = true;
                    pnlInfo.BringToFront();
                }
                else
                {
                    pnlInfo.Visible = false;
                }
            }
            else
            {
                pnlInfo.Visible = false;
            }
        }
        protected override void OnPaint(PaintEventArgs e)
        {
            //base.OnPaint(e);
            if (background == null)
            {
                background = new Bitmap(Width, Height);
            }
            Graphics gr = Graphics.FromImage(background);

            gr.FillRectangle(FPlayersBrush, Rect_Players);
            gr.FillRectangle(FResultBkBrush, Rect_Results);
            gr.FillRectangle(FHeaderBkBrush, Rect_Header_C);
            gr.FillRectangle(FRatingBkBrush, Rect_Rating);
            gr.FillRectangle(Brushes.WhiteSmoke, Rect_Footer);
            gr.DrawString("Список игроков", Font, FPlayersFontBrush, new Rectangle(0, 0, ColWidth_P, Height_Header), sf_center);
            Rectangle header_caption_rect = new Rectangle(ColWidth_P, 0, Rect_Results.Width, Height_Header / 2);

            gr.DrawRectangle(FLinePen, header_caption_rect);
            gr.DrawString("Результаты участия в турнирах", Font, FPlayersFontBrush, header_caption_rect, sf_center);



            if (RS != null)
            {
                Rectangle player_rect = new Rectangle(0, Height_Header, ColWidth_P, Height_Row);
                Rectangle rating_rect = new Rectangle(Width - ColWidth_R, Height_Header, ColWidth_R, Height_Row);
                Rectangle comp_rect   = new Rectangle(new Point(ColWidth_P, Height_Header), new Size(ColWidth_C, Height_Row));

                for (int p = ViewRowFrom; p < FPlayers.Length && p < ViewRowFrom + VisibleRowCount; p++)
                {
                    Player player = FPlayers[p];
                    gr.DrawRectangle(FLinePen, player_rect);
                    gr.DrawRectangle(FLinePen, new Rectangle(player_rect.Location, new Size(Width, Height_Row)));
                    gr.DrawString(player.Name, Font, FPlayersFontBrush, player_rect, sf_left);

                    comp_rect.X = ColWidth_P + 1;
                    comp_rect.Y = player_rect.Y;
                    Rectangle header_rect = new Rectangle(comp_rect.X, Height_Header / 2, ColWidth_C, Height_Header / 2);
                    for (int i = ViewColFrom; (i < RS.Competitions.Count) && (i - ViewColFrom < VisibleColCount); i++)
                    {
                        gr.DrawRectangle(FLinePen, header_rect);
                        gr.DrawString(RS.Competitions[i].Date.ToString("dd.MM.yyyy"), Font, FHeaderBrush, header_rect, sf_center);
                        header_rect.Offset(header_rect.Width, 0);
                        gr.DrawRectangle(FLinePen, comp_rect);
                        if (RS.Competitions[i].Results.ContainsKey(player.Id))
                        {
                            CompetitionResult res = RS.Competitions[i].Results[player.Id];
                            if (res.Penalty != 0)
                            {
                                gr.DrawString((-res.Penalty).ToString(), Font, FPenaltyBrush, comp_rect, sf_left);
                            }
                            string delta = res.Delta.ToString();
                            if (res.Delta > 0)
                            {
                                delta = "+" + delta;
                            }
                            gr.DrawString(delta, Font, FDeltaBrush, comp_rect, sf_right);
                        }
                        comp_rect.Offset(comp_rect.Width, 0);
                    }
                    gr.FillRectangle(FRatingBkBrush, rating_rect);
                    gr.DrawRectangle(FLinePen, rating_rect);
                    gr.DrawString(player.Rating.ToString(), Font, FRatingFontBrush, rating_rect, sf_left);
                    player_rect.Offset(0, player_rect.Height);
                    rating_rect.Offset(0, rating_rect.Height);
                }
            }
            Rectangle rating_header_rect = new Rectangle(Width - ColWidth_R, 0, ColWidth_R, Height_Header);

            gr.FillRectangle(FRatingBkBrush, rating_header_rect);
            gr.DrawRectangle(FLinePen, rating_header_rect);
            string date_str = String.Format("Рейтинг на {0}", FRatingDate.ToString("dd.MM.yyyy"));

            gr.DrawString(date_str, Font, FRatingFontBrush, rating_header_rect, sf_center);
            //gr.DrawString(hScrollBar.Value.ToString(), Font, FRatingFontBrush, rating_header_rect, sf_center);

            e.Graphics.DrawImage(background, 0, 0, Width, Height);
        }