private void BackToMenu(object sender, EventArgs e) { if (canBackToMatch != true) //BackToMenu { SummonerInfoPanel.Hide(); FIVEvsFIVEpanel.Hide(); TypeLabel.Visible = false; basicPage.Show(); basicPage.BringToFront(); //BACK BUTTON if (!SaveChechBox.Checked) { TextBoxSummonerName.Text = string.Empty; } } else // BackToMatch { canBackToMatch = false; SummonerInfoPanel.Hide(); FIVEvsFIVEpanel.Show(); FIVEvsFIVEpanel.BringToFront(); } }
public void SearchSummoner(string Summoner) { #region Control_TextBox LoadCircle.Visible = true; if (Summoner == "") { MessageLabel.Visible = true; MessageLabel.Text = "Enter summoner name!"; //CONTROL EMPTY TEXTOBX emptyTextBoxControlTimer.Enabled = true; LoadCircle.Visible = false; } #endregion else { try { #region GetSummonerAndIcon SummonerInfo summonerInfo = GetSummoner.ReturnSummoner(Summoner, regionsComboBox.Text, apiKey); SummonerIconPictureBox.Image = ProfileIcon.ReturnIcon(summonerInfo.profileIconId.ToString(), version); SummonerNameLabel.Text = summonerInfo.name; levelLabel.Text = "Level: " + summonerInfo.summonerLevel; #endregion //---------------------------------------------------------------------------------#ff000000------#ff010101----------------------------------------------------------------------------------------------------------------------// #region DataTable DataTable dt = new DataTable(); dt.Columns.Add("Champion"); dt.Columns.Add("KDA"); dt.Columns.Add("Games played"); dt.Columns.Add("Wins"); dt.Columns.Add("Minions"); dt.Columns.Add("Golds"); dt.Columns.Add("Penta Kills"); dt.Columns.Add("Quadra Kills"); dt.Columns.Add("Triple Kills"); dt.Columns.Add("Double Kills"); dt.Columns.Add("Max kills"); dt.Columns.Add("Max deaths"); dt.Columns.Add("Turrets destroyed"); if (summonerInfo.summonerLevel == 30) { WebClient statclient = new WebClient(); Stream statdata = statclient.OpenRead("https://" + regionsComboBox.Text.ToLower() + ".api.pvp.net/api/lol/" + regionsComboBox.Text.ToLower() + "/v1.3/stats/by-summoner/" + summonerInfo.id + "/ranked?api_key=" + apiKey); StreamReader statreader = new StreamReader(statdata); //GET STATS string result = statreader.ReadLine(); StatsInfo statsInfo = JsonConvert.DeserializeObject <StatsInfo>(result); //DESERIALIZE JSON STRING //-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------// Champion TotalStatus = new Champion(); List <Champion> listChampions = new List <Champion>(); foreach (Champion champion in statsInfo.champions) { if (champion.id == 0) { TotalStatus = champion; } listChampions.Add(champion); } listChampions.Sort(delegate(Champion c1, Champion c2) { return(c2.stats.totalSessionsPlayed.CompareTo(c1.stats.totalSessionsPlayed)); }); string joinedIDs = ""; int countChampion = 0; foreach (Champion champ in listChampions) { joinedIDs += champ.id.ToString() + ","; countChampion++; //RETURN CHAMPIONS BY IDS AND RETURN VERSION OF CHAMPION POOL } joinedIDs = joinedIDs.Remove(joinedIDs.Length - 1); string[] Champions = Transform.ReturnChampion(JSON, joinedIDs, countChampion); version = Transform.returnVersion(JSON); //-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------// int x = 0; foreach (Champion champion in statsInfo.champions) //SORT STATS INFO { if (x != 0) { float WonPercentage = ((float)listChampions[x].stats.totalSessionsWon / (float)listChampions[x].stats.totalSessionsPlayed) * 100; int wonPercToInt = (int)WonPercentage; dt.Rows.Add(Champions[x], Math.Round(listChampions[x].stats.totalChampionKills / listChampions[x].stats.totalSessionsPlayed) + "/" + Math.Round(listChampions[x].stats.totalDeathsPerSession / listChampions[x].stats.totalSessionsPlayed) + "/" + Math.Round(listChampions[x].stats.totalAssists / listChampions[x].stats.totalSessionsPlayed), listChampions[x].stats.totalSessionsPlayed, listChampions[x].stats.totalSessionsWon + " (" + wonPercToInt + "%)", listChampions[x].stats.totalMinionKills / listChampions[x].stats.totalSessionsPlayed, listChampions[x].stats.totalGoldEarned / listChampions[x].stats.totalSessionsPlayed, listChampions[x].stats.totalPentaKills, listChampions[x].stats.totalQuadraKills, listChampions[x].stats.totalTripleKills, listChampions[x].stats.totalDoubleKills, listChampions[x].stats.maxChampionsKilled, listChampions[x].stats.maxNumDeaths, listChampions[x].stats.totalTurretsKilled); } x++; } float AvgWon = ((float)listChampions[0].stats.totalSessionsWon / (float)listChampions[0].stats.totalSessionsPlayed) * 100; int avgWonINT = (int)AvgWon; WLlabel.Text = (TotalStatus.stats.totalSessionsWon + "/" + TotalStatus.stats.totalSessionsLost) + " (" + avgWonINT.ToString() + "%)"; avgKDAlabel.Text = Math.Round(listChampions[0].stats.totalChampionKills / listChampions[0].stats.totalSessionsPlayed) + "/" + Math.Round(listChampions[0].stats.totalDeathsPerSession / listChampions[0].stats.totalSessionsPlayed) + "/" + Math.Round(listChampions[0].stats.totalAssists / listChampions[0].stats.totalSessionsPlayed); avgPentakillsLabel.Text = listChampions[0].stats.totalPentaKills.ToString(); avgMinionsLabel.Text = (listChampions[0].stats.totalMinionKills / listChampions[0].stats.totalSessionsPlayed).ToString(); } else //UNDER LV30 { WLlabel.Text = "-"; avgKDAlabel.Text = "-"; avgPentakillsLabel.Text = "-"; avgMinionsLabel.Text = "-"; } ChampionsInfoGrid.DataSource = dt; foreach (DataGridViewColumn column in ChampionsInfoGrid.Columns) { column.SortMode = DataGridViewColumnSortMode.NotSortable; //column.Width = 75; } //ChampionsInfoGrid.Sort(ChampionsInfoGrid.Columns[1], ListSortDirection.Descending); if (ChampionsInfoGrid.Rows.Count == 0) { ChampionSearchTextBox.Enabled = false; } else { ChampionSearchTextBox.Enabled = true; } #endregion //-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------// #region GetDivison string DivisionResult = ""; Image DivisionImage = new Bitmap(LoLAssistant.Properties.Resources.provisional); try { WebClient DivisionClient = new WebClient(); string s = "https://" + regionsComboBox.Text.ToLower() + ".api.pvp.net/api/lol/" + regionsComboBox.Text.ToLower().ToLower() + "/v2.5/league/by-summoner/" + summonerInfo.id + "/entry?api_key=" + apiKey; Stream DivisionData = DivisionClient.OpenRead(s); StreamReader DivisionReader = new StreamReader(DivisionData); DivisionResult = DivisionReader.ReadLine(); } catch (WebException ex) { if (ex.Status == WebExceptionStatus.ProtocolError) { HttpWebResponse response = (HttpWebResponse)ex.Response; if (response.StatusCode == HttpStatusCode.NotFound) { DivisionImage = new Bitmap(LoLAssistant.Properties.Resources.provisional); } } } if (summonerInfo.summonerLevel == 30 && DivisionResult != "") { DivisionResult = DivisionResult.Replace("{\"" + summonerInfo.id + "\":", string.Empty); DivisionResult = DivisionResult.Replace("}]}]}", "}]}]"); List <Division> divisions = JsonConvert.DeserializeObject <List <Division> >(DivisionResult); foreach (Division div in divisions) { if (div.queue == "RANKED_SOLO_5x5") { DivisionLabel.Text = div.tier + " " + div.entries[0].division + " " + "(" + div.entries[0].leaguePoints + "lp)"; switch (div.tier) { case "BRONZE": DivisionImage = new Bitmap(LoLAssistant.Properties.Resources.bronze); break; case "SILVER": DivisionImage = new Bitmap(LoLAssistant.Properties.Resources.silver); break; case "GOLD": DivisionImage = new Bitmap(LoLAssistant.Properties.Resources.gold); break; case "PLATINUM": DivisionImage = new Bitmap(LoLAssistant.Properties.Resources.platinum); break; case "DIAMOND": DivisionImage = new Bitmap(LoLAssistant.Properties.Resources.diamond); break; case "MASTER": DivisionImage = new Bitmap(LoLAssistant.Properties.Resources.master); break; case "CHALLENGER": DivisionImage = new Bitmap(LoLAssistant.Properties.Resources.challenger); break; } } } } else //UNRANKED OR NOT 30LV { DivisionImage = new Bitmap(LoLAssistant.Properties.Resources.provisional); DivisionLabel.Text = "UNRANKED"; } DivisionImage = new Bitmap(DivisionImage, new Size(150, 150)); DivisionPictureBox.Image = DivisionImage; #endregion //-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------// #region PageNavigation basicPage.Hide(); SummonerInfoPanel.Show(); SummonerInfoPanel.BringToFront(); LoadCircle.Visible = false; //PAGE NAVIGATION TypeLabel.Text = "Ranked Statistics"; TypeLabel.Visible = true; #endregion } catch (WebException ex) { if (ex.Status == WebExceptionStatus.ProtocolError) { var response = (HttpWebResponse)ex.Response; if (response.StatusCode == HttpStatusCode.NotFound) { MessageLabel.Visible = true; MessageLabel.Text = "Summoner does not exist!"; emptyTextBoxControlTimer.Enabled = true; LoadCircle.Visible = false; } } } } }