コード例 #1
0
        protected void btnAddNewPlayer_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                string firstName = txtNewPlayerFirstName.Text.Trim();
                string lastName  = txtNewPlayerLastName.Text.Trim();
                if (!string.IsNullOrEmpty(firstName) && !string.IsNullOrEmpty(lastName) && firstName.Length > 0 && firstName.Length <= 100 && lastName.Length > 0 && lastName.Length <= 100)
                {
                    int    location = int.Parse(ddlLocation.SelectedValue);
                    string nick     = (firstName.Length < 2 ? "Jakiś" : firstName.Substring(0, 2)) + (lastName.Length < 2 ? "Pseudonim" : lastName.Substring(0, 2));
                    using (TrambambuleDBContextDataContext context = new TrambambuleDBContextDataContext())
                    {
                        try
                        {
                            Player p = new Player();
                            p.FirstName = firstName;
                            p.LastName  = lastName;
                            p.Location  = location;
                            p.Nickname  = nick;
                            p.Timestamp = DateTime.Now;

                            context.Players.InsertOnSubmit(p);
                            context.SubmitChanges();

                            Cache.Remove(DataAccess.PlayersListCacheName);
                            Cache.Remove(DataAccess.PlayersNamesAndSurnamesWithoutPolishCharsCacheName);
                            Cache.Remove(DataAccess.PlayersAchievementsCacheName);
                            Cache.Remove(DataAccess.AllAchievementsCacheName);
                            Cache.Remove(DataAccess.OverallStatsCacheName);

                            new AchievementsService(new List <Player>()
                            {
                                p
                            }).RecalculateAchievements(true);

                            litStatus.Text             = "<div class=\"validator\">Użytkownik został dodany</div>";
                            txtNewPlayerFirstName.Text = "";
                            txtNewPlayerLastName.Text  = "";
                            ddlLocation.SelectedIndex  = 0;
                        }
                        catch { litStatus.Text = "<div class=\"validator\">Wystąpił błąd podczas dodawania nowego użytkownika</div>"; }
                    }
                }
            }
        }
コード例 #2
0
        protected void btnAddNewPlayer_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                string firstName = txtNewPlayerFirstName.Text.Trim();
                string lastName = txtNewPlayerLastName.Text.Trim();
                if (!string.IsNullOrEmpty(firstName) && !string.IsNullOrEmpty(lastName) && firstName.Length > 0 && firstName.Length <= 100 && lastName.Length > 0 && lastName.Length <= 100)
                {
                    int location = int.Parse(ddlLocation.SelectedValue);
                    string nick = (firstName.Length < 2 ? "Jakiś" : firstName.Substring(0, 2)) + (lastName.Length < 2 ? "Pseudonim" : lastName.Substring(0, 2));
                    using (TrambambuleDBContextDataContext context = new TrambambuleDBContextDataContext())
                    {
                        try
                        {
                            Player p = new Player();
                            p.FirstName = firstName;
                            p.LastName = lastName;
                            p.Location = location;
                            p.Nickname = nick;
                            p.Timestamp = DateTime.Now;

                            context.Players.InsertOnSubmit(p);
                            context.SubmitChanges();

                            Cache.Remove(DataAccess.PlayersListCacheName);
                            Cache.Remove(DataAccess.PlayersNamesAndSurnamesWithoutPolishCharsCacheName);
                            Cache.Remove(DataAccess.PlayersAchievementsCacheName);
                            Cache.Remove(DataAccess.AllAchievementsCacheName);
                            Cache.Remove(DataAccess.OverallStatsCacheName);

                            new AchievementsService(new List<Player>() { p }).RecalculateAchievements(true);

                            litStatus.Text = "<div class=\"validator\">Użytkownik został dodany</div>";
                            txtNewPlayerFirstName.Text = "";
                            txtNewPlayerLastName.Text = "";
                            ddlLocation.SelectedIndex = 0;
                        }
                        catch { litStatus.Text = "<div class=\"validator\">Wystąpił błąd podczas dodawania nowego użytkownika</div>"; }
                    }
                }
            }
        }
コード例 #3
0
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            litAchievements.Text = "";
            List <Player> players = DataAccess.GetPlayers();
            int           g1      = int.Parse(tbxScoreA.Text);
            int           g2      = int.Parse(tbxScoreB.Text);

            Common.EResult t1Result = Common.GetResult(g1, g2);
            Common.EResult t2Result = Common.GetResult(g2, g1);

            Match match = new Match()
            {
                Id = Guid.NewGuid(), Timestamp = DateTime.Now
            };
            TeamMatch tm1 = new TeamMatch()
            {
                Id     = Guid.NewGuid(), MatchId = match.Id,
                Result = (byte)t1Result, GoalsScored = g1, GoalsLost = g2, Timestamp = DateTime.Now
            };
            TeamMatch tm2 = new TeamMatch()
            {
                Id     = Guid.NewGuid(), MatchId = match.Id,
                Result = (byte)t2Result, GoalsScored = g2, GoalsLost = g1, Timestamp = DateTime.Now
            };
            Player        p1Off             = DataAccess.GetPlayer(tbxPlayer1Off.Text);
            Player        p1Def             = DataAccess.GetPlayer(tbxPlayer1Deff.Text);
            Player        p2Off             = DataAccess.GetPlayer(tbxPlayer2Off.Text);
            Player        p2Def             = DataAccess.GetPlayer(tbxPlayer2Deff.Text);
            List <Player> playersInThisGame = new List <Player>()
            {
                p1Off, p1Def, p2Off, p2Def
            };
            TeamMatchPlayer tmp1Off = new TeamMatchPlayer()
            {
                PlayerId    = p1Off.Id,
                Position    = (int)Common.EPosition.Offence,
                Timestamp   = DateTime.Now,
                TeamMatchId = tm1.Id
            };
            TeamMatchPlayer tmp1Def = new TeamMatchPlayer()
            {
                PlayerId    = p1Def.Id,
                Position    = (int)Common.EPosition.Defence,
                Timestamp   = DateTime.Now,
                TeamMatchId = tm1.Id
            };
            TeamMatchPlayer tmp2Off = new TeamMatchPlayer()
            {
                PlayerId    = p2Off.Id,
                Position    = (int)Common.EPosition.Offence,
                Timestamp   = DateTime.Now,
                TeamMatchId = tm2.Id
            };
            TeamMatchPlayer tmp2Def = new TeamMatchPlayer()
            {
                PlayerId    = p2Def.Id,
                Position    = (int)Common.EPosition.Defence,
                Timestamp   = DateTime.Now,
                TeamMatchId = tm2.Id
            };

            double?player1OffPreRating, player1DefPreRating, player2OffPreRating, player2DefPreRating;
            double?player1OffPreRankPosition = null;
            double?player1DefPreRankPosition = null;
            double?player2OffPreRankPosition = null;
            double?player2DefPreRankPosition = null;
            int?   player1OffPostRankPosition, player1DefPostRankPosition, player2OffPostRankPosition, player2DefPostRankPosition;

            using (TrambambuleDBContextDataContext context = new TrambambuleDBContextDataContext())
            {
                var player1Off = context.TeamMatchPlayers.Where(p => p.PlayerId == tmp1Off.PlayerId)
                                 .OrderByDescending(p => p.Timestamp).FirstOrDefault();

                var player1Def = context.TeamMatchPlayers.Where(p => p.PlayerId == tmp1Def.PlayerId)
                                 .OrderByDescending(p => p.Timestamp).FirstOrDefault();

                var player2Off = context.TeamMatchPlayers.Where(p => p.PlayerId == tmp2Off.PlayerId)
                                 .OrderByDescending(p => p.Timestamp).FirstOrDefault();

                var player2Def = context.TeamMatchPlayers.Where(p => p.PlayerId == tmp2Def.PlayerId)
                                 .OrderByDescending(p => p.Timestamp).FirstOrDefault();

                if (player1Off != null)
                {
                    player1OffPreRating       = player1Off.Rating;
                    player1OffPreRankPosition = context.GetPlayerRankPosition(player1Off.PlayerId);
                }
                else
                {
                    player1OffPreRating       = PlayerHelper.INITIAL_RATING;
                    player1OffPreRankPosition = null;
                }

                if (player1Def != null)
                {
                    player1DefPreRating       = player1Def.Rating;
                    player1DefPreRankPosition = context.GetPlayerRankPosition(player1Def.PlayerId);
                }
                else
                {
                    player1DefPreRating       = PlayerHelper.INITIAL_RATING;
                    player1DefPreRankPosition = null;
                }

                if (player2Off != null)
                {
                    player2OffPreRating       = player2Off.Rating;
                    player2OffPreRankPosition = context.GetPlayerRankPosition(player2Off.PlayerId);
                }
                else
                {
                    player2OffPreRating       = PlayerHelper.INITIAL_RATING;
                    player2OffPreRankPosition = null;
                }

                if (player2Def != null)
                {
                    player2DefPreRating       = player2Def.Rating;
                    player2DefPreRankPosition = context.GetPlayerRankPosition(player2Def.PlayerId);
                }
                else
                {
                    player2DefPreRating       = PlayerHelper.INITIAL_RATING;
                    player2DefPreRankPosition = null;
                }

                PlayerHelper.FillPlayersRating(ref tmp1Off, ref tmp1Def, ref tmp2Off, ref tmp2Def,
                                               player1Off,
                                               player1Def,
                                               player2Off,
                                               player2Def,
                                               g1, g2);

                context.Matches.InsertOnSubmit(match);
                context.TeamMatches.InsertOnSubmit(tm1);
                context.TeamMatches.InsertOnSubmit(tm2);
                context.TeamMatchPlayers.InsertOnSubmit(tmp1Def);
                context.TeamMatchPlayers.InsertOnSubmit(tmp2Def);
                context.TeamMatchPlayers.InsertOnSubmit(tmp1Off);
                context.TeamMatchPlayers.InsertOnSubmit(tmp2Off);
                context.SubmitChanges();

                player1OffPostRankPosition = context.GetPlayerRankPosition(tmp1Off.PlayerId);
                player1DefPostRankPosition = context.GetPlayerRankPosition(tmp1Def.PlayerId);
                player2OffPostRankPosition = context.GetPlayerRankPosition(tmp2Off.PlayerId);
                player2DefPostRankPosition = context.GetPlayerRankPosition(tmp2Def.PlayerId);
            }

            double player1OffRatingChange = Math.Round((double)(tmp1Off.Rating - player1OffPreRating), 0);
            double player1DefRatingChange = Math.Round((double)(tmp1Def.Rating - player1DefPreRating), 0);
            double player2OffRatingChange = Math.Round((double)(tmp2Off.Rating - player2OffPreRating), 0);
            double player2DefRatingChange = Math.Round((double)(tmp2Def.Rating - player2DefPreRating), 0);

            int player1OffRankPositionChange = player1OffPreRankPosition.HasValue ? (int)(player1OffPreRankPosition - player1OffPostRankPosition) : -1;
            int player1DefRankPositionChange = player1DefPreRankPosition.HasValue ? (int)(player1DefPreRankPosition - player1DefPostRankPosition) : -1;
            int player2OffRankPositionChange = player2OffPreRankPosition.HasValue ? (int)(player2OffPreRankPosition - player2OffPostRankPosition) : -1;
            int player2DefRankPositionChange = player2DefPreRankPosition.HasValue ? (int)(player2DefPreRankPosition - player2DefPostRankPosition) : -1;

            litTbxPlayer1OffStats.Text  = string.Format(PostSubmittedStats, player1OffPostRankPosition, GetColouredRankPosition(player1OffRankPositionChange), Math.Round((double)tmp1Off.Rating, 0), GetColouredRating(player1OffRatingChange));
            litTbxPlayer1DeffStats.Text = string.Format(PostSubmittedStats, player1DefPostRankPosition, GetColouredRankPosition(player1DefRankPositionChange), Math.Round((double)tmp1Def.Rating, 0), GetColouredRating(player1DefRatingChange));
            litTbxPlayer2OffStats.Text  = string.Format(PostSubmittedStats, player2OffPostRankPosition, GetColouredRankPosition(player2OffRankPositionChange), Math.Round((double)tmp2Off.Rating, 0), GetColouredRating(player2OffRatingChange));
            litTbxPlayer2DeffStats.Text = string.Format(PostSubmittedStats, player2DefPostRankPosition, GetColouredRankPosition(player2DefRankPositionChange), Math.Round((double)tmp2Def.Rating, 0), GetColouredRating(player2DefRatingChange));

            pnlInfo.Controls.Add(new LiteralControl("Mecz został zapisany"));
            tbxScoreA.Text = tbxScoreB.Text = "";
            tbxPlayer1Off.Focus();

            CalculateAchievements(playersInThisGame);
            Cache.Remove(DataAccess.OverallStatsCacheName);
        }
コード例 #4
0
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            litAchievements.Text = "";
            List<Player> players = DataAccess.GetPlayers();
            int g1 = int.Parse(tbxScoreA.Text);
            int g2 = int.Parse(tbxScoreB.Text);
            Common.EResult t1Result = Common.GetResult(g1, g2);
            Common.EResult t2Result = Common.GetResult(g2, g1);

            Match match = new Match() { Id = Guid.NewGuid(), Timestamp = DateTime.Now };
            TeamMatch tm1 = new TeamMatch() { Id = Guid.NewGuid(), MatchId = match.Id,
                Result = (byte)t1Result, GoalsScored = g1, GoalsLost = g2, Timestamp = DateTime.Now };
            TeamMatch tm2 = new TeamMatch() { Id = Guid.NewGuid(), MatchId = match.Id,
                Result = (byte)t2Result, GoalsScored = g2, GoalsLost = g1, Timestamp = DateTime.Now };
            Player p1Off = DataAccess.GetPlayer(tbxPlayer1Off.Text);
            Player p1Def = DataAccess.GetPlayer(tbxPlayer1Deff.Text);
            Player p2Off = DataAccess.GetPlayer(tbxPlayer2Off.Text);
            Player p2Def = DataAccess.GetPlayer(tbxPlayer2Deff.Text);
            List<Player> playersInThisGame = new List<Player>() { p1Off, p1Def, p2Off, p2Def };
            TeamMatchPlayer tmp1Off = new TeamMatchPlayer()
            {
                PlayerId = p1Off.Id,
                Position = (int)Common.EPosition.Offence,
                Timestamp = DateTime.Now,
                TeamMatchId = tm1.Id
            };
            TeamMatchPlayer tmp1Def = new TeamMatchPlayer()
            {
                PlayerId = p1Def.Id,
                Position = (int)Common.EPosition.Defence,
                Timestamp = DateTime.Now,
                TeamMatchId = tm1.Id
            };
            TeamMatchPlayer tmp2Off = new TeamMatchPlayer()
            {
                PlayerId = p2Off.Id,
                Position = (int)Common.EPosition.Offence,
                Timestamp = DateTime.Now,
                TeamMatchId = tm2.Id
            };
            TeamMatchPlayer tmp2Def = new TeamMatchPlayer()
            {
                PlayerId = p2Def.Id,
                Position = (int)Common.EPosition.Defence,
                Timestamp = DateTime.Now,
                TeamMatchId = tm2.Id
            };

            double? player1OffPreRating, player1DefPreRating, player2OffPreRating, player2DefPreRating;
            double? player1OffPreRankPosition = null;
            double? player1DefPreRankPosition = null;
            double? player2OffPreRankPosition = null;
            double? player2DefPreRankPosition = null;
            int? player1OffPostRankPosition, player1DefPostRankPosition, player2OffPostRankPosition, player2DefPostRankPosition;

            using (TrambambuleDBContextDataContext context = new TrambambuleDBContextDataContext())
            {
                var player1Off = context.TeamMatchPlayers.Where(p => p.PlayerId == tmp1Off.PlayerId)
                        .OrderByDescending(p => p.Timestamp).FirstOrDefault();

                var player1Def = context.TeamMatchPlayers.Where(p => p.PlayerId == tmp1Def.PlayerId)
                        .OrderByDescending(p => p.Timestamp).FirstOrDefault();

                var player2Off = context.TeamMatchPlayers.Where(p => p.PlayerId == tmp2Off.PlayerId)
                        .OrderByDescending(p => p.Timestamp).FirstOrDefault();

                var player2Def = context.TeamMatchPlayers.Where(p => p.PlayerId == tmp2Def.PlayerId)
                        .OrderByDescending(p => p.Timestamp).FirstOrDefault();

                if (player1Off != null)
                {
                    player1OffPreRating = player1Off.Rating;
                    player1OffPreRankPosition = context.GetPlayerRankPosition(player1Off.PlayerId);
                }
                else
                {
                    player1OffPreRating = PlayerHelper.INITIAL_RATING;
                    player1OffPreRankPosition = null;
                }

                if (player1Def != null)
                {
                    player1DefPreRating = player1Def.Rating;
                    player1DefPreRankPosition = context.GetPlayerRankPosition(player1Def.PlayerId);
                }
                else
                {
                    player1DefPreRating = PlayerHelper.INITIAL_RATING;
                    player1DefPreRankPosition = null;
                }

                if (player2Off != null)
                {
                    player2OffPreRating = player2Off.Rating;
                    player2OffPreRankPosition = context.GetPlayerRankPosition(player2Off.PlayerId);
                }
                else
                {
                    player2OffPreRating = PlayerHelper.INITIAL_RATING;
                    player2OffPreRankPosition = null;
                }

                if (player2Def != null)
                {
                    player2DefPreRating = player2Def.Rating;
                    player2DefPreRankPosition = context.GetPlayerRankPosition(player2Def.PlayerId);
                }
                else
                {
                    player2DefPreRating = PlayerHelper.INITIAL_RATING;
                    player2DefPreRankPosition = null;
                }

                PlayerHelper.FillPlayersRating(ref tmp1Off, ref tmp1Def, ref tmp2Off, ref tmp2Def,
                    player1Off,
                    player1Def,
                    player2Off,
                    player2Def,
                    g1, g2);

                context.Matches.InsertOnSubmit(match);
                context.TeamMatches.InsertOnSubmit(tm1);
                context.TeamMatches.InsertOnSubmit(tm2);
                context.TeamMatchPlayers.InsertOnSubmit(tmp1Def);
                context.TeamMatchPlayers.InsertOnSubmit(tmp2Def);
                context.TeamMatchPlayers.InsertOnSubmit(tmp1Off);
                context.TeamMatchPlayers.InsertOnSubmit(tmp2Off);
                context.SubmitChanges();

                player1OffPostRankPosition = context.GetPlayerRankPosition(tmp1Off.PlayerId);
                player1DefPostRankPosition = context.GetPlayerRankPosition(tmp1Def.PlayerId);
                player2OffPostRankPosition = context.GetPlayerRankPosition(tmp2Off.PlayerId);
                player2DefPostRankPosition = context.GetPlayerRankPosition(tmp2Def.PlayerId);
            }

            double player1OffRatingChange = Math.Round((double)(tmp1Off.Rating - player1OffPreRating),0);
            double player1DefRatingChange = Math.Round((double)(tmp1Def.Rating - player1DefPreRating),0);
            double player2OffRatingChange = Math.Round((double)(tmp2Off.Rating - player2OffPreRating),0);
            double player2DefRatingChange = Math.Round((double)(tmp2Def.Rating - player2DefPreRating),0);

            int player1OffRankPositionChange = player1OffPreRankPosition.HasValue ? (int)(player1OffPreRankPosition - player1OffPostRankPosition) : -1;
            int player1DefRankPositionChange = player1DefPreRankPosition.HasValue ? (int)(player1DefPreRankPosition - player1DefPostRankPosition) : -1;
            int player2OffRankPositionChange = player2OffPreRankPosition.HasValue ? (int)(player2OffPreRankPosition - player2OffPostRankPosition) : -1;
            int player2DefRankPositionChange = player2DefPreRankPosition.HasValue ? (int)(player2DefPreRankPosition - player2DefPostRankPosition) : -1;

            litTbxPlayer1OffStats.Text = string.Format(PostSubmittedStats, player1OffPostRankPosition, GetColouredRankPosition(player1OffRankPositionChange), Math.Round((double)tmp1Off.Rating, 0), GetColouredRating(player1OffRatingChange));
            litTbxPlayer1DeffStats.Text = string.Format(PostSubmittedStats, player1DefPostRankPosition, GetColouredRankPosition(player1DefRankPositionChange), Math.Round((double)tmp1Def.Rating, 0), GetColouredRating(player1DefRatingChange));
            litTbxPlayer2OffStats.Text = string.Format(PostSubmittedStats, player2OffPostRankPosition, GetColouredRankPosition(player2OffRankPositionChange), Math.Round((double)tmp2Off.Rating, 0), GetColouredRating(player2OffRatingChange));
            litTbxPlayer2DeffStats.Text = string.Format(PostSubmittedStats, player2DefPostRankPosition, GetColouredRankPosition(player2DefRankPositionChange), Math.Round((double)tmp2Def.Rating, 0), GetColouredRating(player2DefRatingChange));

            pnlInfo.Controls.Add(new LiteralControl("Mecz został zapisany"));
            tbxScoreA.Text = tbxScoreB.Text = "";
            tbxPlayer1Off.Focus();

            CalculateAchievements(playersInThisGame);
            Cache.Remove(DataAccess.OverallStatsCacheName);
        }