Я пытаюсь получить отсортированные столбцы ранжирования из dataGridView5.Columns для правильной замены моего столбца datagridview1.
В идеале я хочу найти соответствие между двумя таблицами данных на основе некоторой логики:
То есть, если команды = Против И PG содержит заголовок столбца PG RANK, ТОГДА PG RANK = OPPAgainstRank. На картинке написано 1000 слов, так что, надеюсь, это объяснит лучше, чем я.
Спасибо
public void DVP()
{
var doc = new HtmlWeb().Load("https://basketballmonster.com/dfsdvp.aspx");
HtmlAgilityPack.HtmlNodeCollection teams = doc.DocumentNode.SelectNodes("//td[@class ='tdc']");
HtmlAgilityPack.HtmlNodeCollection pg_points = doc.DocumentNode.SelectNodes(".//table[@class='datatable']//tr//td[4]");
HtmlAgilityPack.HtmlNodeCollection sg_points = doc.DocumentNode.SelectNodes(".//table[@class='datatable']//tr//td[5]");
HtmlAgilityPack.HtmlNodeCollection sf_points = doc.DocumentNode.SelectNodes(".//table[@class='datatable']//tr//td[6]");
HtmlAgilityPack.HtmlNodeCollection pf_points = doc.DocumentNode.SelectNodes(".//table[@class='datatable']//tr//td[7]");
HtmlAgilityPack.HtmlNodeCollection c_points = doc.DocumentNode.SelectNodes(".//table[@class='datatable']//tr//td[8]");
DataTable dvp = new DataTable();
dvp.Columns.Add("Teams", typeof(string));
dvp.Columns.Add("PG", typeof(string));
dvp.Columns.Add("PG RANK", typeof(int));
dvp.Columns.Add("SG", typeof(string));
dvp.Columns.Add("SG RANK", typeof(int));
dvp.Columns.Add("SF", typeof(string));
dvp.Columns.Add("SF RANK", typeof(int));
dvp.Columns.Add("PF", typeof(string));
dvp.Columns.Add("PF RANK", typeof(int));
dvp.Columns.Add("C", typeof(string));
dvp.Columns.Add("C RANK", typeof(int));
for (int i = 0; i < teams.Count; i++)
{
DataRow row = dvp.NewRow();
var aux = i / 30;
row["Teams"] = (teams[i].InnerText);
row["PG"] = (pg_points[i].InnerText);
row["SG"] = (sg_points[i].InnerText);
row["SF"] = (sf_points[i].InnerText);
row["PF"] = (pf_points[i].InnerText);
row["C"] = (c_points[i].InnerText);
dvp.Rows.Add(row);
dataGridView5.DataSource = null;
dataGridView5.DataSource = dvp;
foreach (DataGridViewRow row3 in dataGridView5.Rows)
{
//teams
if (row3.Cells["Teams"].Value.ToString().Contains("ATL"))
{
row3.Cells["Teams"].Value = "Atlanta Hawks";
}
if (row3.Cells["Teams"].Value.ToString().Contains("BOS"))
{
row3.Cells["Teams"].Value = "Boston Celtics";
}
if (row3.Cells["Teams"].Value.ToString().Contains("BKN"))
{
row3.Cells["Teams"].Value = "Brooklyn Nets";
}
if (row3.Cells["Teams"].Value.ToString().Contains("CHA"))
{
row3.Cells["Teams"].Value = "Charlotte Hornets";
}
if (row3.Cells["Teams"].Value.ToString().Contains("CHI"))
{
row3.Cells["Teams"].Value = "Chicago Bulls";
}
if (row3.Cells["Teams"].Value.ToString().Contains("CLE"))
{
row3.Cells["Teams"].Value = "Cleveland Cavaliers";
}
if (row3.Cells["Teams"].Value.ToString().Contains("DAL"))
{
row3.Cells["Teams"].Value = "Dallas Mavericks";
}
if (row3.Cells["Teams"].Value.ToString().Contains("DEN"))
{
row3.Cells["Teams"].Value = "Denver Nuggets";
}
if (row3.Cells["Teams"].Value.ToString().Contains("DET"))
{
row3.Cells["Teams"].Value = "Detroit Pistons";
}
if (row3.Cells["Teams"].Value.ToString().Contains("GSW"))
{
row3.Cells["Teams"].Value = "Golden State Warriors";
}
if (row3.Cells["Teams"].Value.ToString().Contains("vs HOU"))
{
row3.Cells["Teams"].Value = "Houston Rockets";
}
if (row3.Cells["Teams"].Value.ToString().Contains("vs IND"))
{
row3.Cells["Teams"].Value = "Indiana Pacers";
}
if (row3.Cells["Teams"].Value.ToString().Contains("vs LAC"))
{
row3.Cells["Teams"].Value = "LA Clippers";
}
if (row3.Cells["Teams"].Value.ToString().Contains("vs LAL"))
{
row3.Cells["Teams"].Value = "Los Angeles Lakers";
}
if (row3.Cells["Teams"].Value.ToString().Contains("vs MEM"))
{
row3.Cells["Teams"].Value = "Memphis Grizzlies";
}
if (row3.Cells["Teams"].Value.ToString().Contains("vs MIA"))
{
row3.Cells["Teams"].Value = "Miami Heat";
}
if (row3.Cells["Teams"].Value.ToString().Contains("vs MIL"))
{
row3.Cells["Teams"].Value = "Milwaukee Bucks";
}
if (row3.Cells["Teams"].Value.ToString().Contains("vs MIN"))
{
row3.Cells["Teams"].Value = "Minnesota Timberwolves";
}
if (row3.Cells["Teams"].Value.ToString().Contains("vs NOR"))
{
row3.Cells["Teams"].Value = "New Orleans Pelicans";
}
if (row3.Cells["Teams"].Value.ToString().Contains("vs NYK"))
{
row3.Cells["Teams"].Value = "New York Knicks";
}
if (row3.Cells["Teams"].Value.ToString().Contains("vs OKC"))
{
row3.Cells["Teams"].Value = "Oklahoma City Thunder";
}
if (row3.Cells["Teams"].Value.ToString().Contains("vs ORL"))
{
row3.Cells["Teams"].Value = "Orlando Magic";
}
if (row3.Cells["Teams"].Value.ToString().Contains("vs PHI"))
{
row3.Cells["Teams"].Value = "Philadelphia Sixers";
}
if (row3.Cells["Teams"].Value.ToString().Contains("vs PHO"))
{
row3.Cells["Teams"].Value = "Phoenix Suns";
}
if (row3.Cells["Teams"].Value.ToString().Contains("vs POR"))
{
row3.Cells["Teams"].Value = "Portland Trail Blazers";
}
if (row3.Cells["Teams"].Value.ToString().Contains("vs SAC"))
{
row3.Cells["Teams"].Value = "Sacramento Kings";
}
if (row3.Cells["Teams"].Value.ToString().Contains("vs SAS"))
{
row3.Cells["Teams"].Value = "San Antonio Spurs";
}
if (row3.Cells["Teams"].Value.ToString().Contains("vs TOR"))
{
row3.Cells["Teams"].Value = "Toronto Raptors";
}
if (row3.Cells["Teams"].Value.ToString().Contains("vs UTA"))
{
row3.Cells["Teams"].Value = "Utah Jazz";
}
if (row3.Cells["Teams"].Value.ToString().Contains("vs WAS"))
{
row3.Cells["Teams"].Value = "Washington Wizards";
}
}
foreach (DataGridViewRow row1 in dataGridView1.Rows)
{
if (row1.Cells["Against"].Value.ToString().Contains(row["Teams"].ToString()) && row1.Cells["Position"].Value.ToString() == "PG")
{
row1.Cells["OppAgainstRank"].Value = pg_points[i].InnerText;
}
if (row1.Cells["Against"].Value.ToString().Contains(row["Teams"].ToString()) && row1.Cells["Position"].Value.ToString() == "SG")
{
row1.Cells["OppAgainstRank"].Value = sg_points[i].InnerText;
}
if (row1.Cells["Against"].Value.ToString().Contains(row["Teams"].ToString()) && row1.Cells["Position"].Value.ToString() == "SF")
{
row1.Cells["OppAgainstRank"].Value = sf_points[i].InnerText;
}
if (row1.Cells["Against"].Value.ToString().Contains(row["Teams"].ToString()) && row1.Cells["Position"].Value.ToString() == "PF")
{
row1.Cells["OppAgainstRank"].Value = pf_points[i].InnerText;
}
if (row1.Cells["Against"].Value.ToString().Contains(row["Teams"].ToString()) && row1.Cells["Position"].Value.ToString() == "C")
{
row1.Cells["OppAgainstRank"].Value = c_points[i].InnerText;
}
}
// ADD RANKING
this.dataGridView5.Sort(this.dataGridView5.Columns["PG"], System.ComponentModel.ListSortDirection.Descending);
for (int x = 0; x < dataGridView5.Rows.Count; x++)
{
dataGridView5.Rows[x].Cells["PG RANK"].Value = Convert.ToString(x + 1);
}
this.dataGridView5.Sort(this.dataGridView5.Columns["SG"], System.ComponentModel.ListSortDirection.Descending);
for (int x = 0; x < dataGridView5.Rows.Count; x++)
{
dataGridView5.Rows[x].Cells["SG RANK"].Value = Convert.ToString(x + 1);
}
this.dataGridView5.Sort(this.dataGridView5.Columns["SF"], System.ComponentModel.ListSortDirection.Descending);
for (int x = 0; x < dataGridView5.Rows.Count; x++)
{
dataGridView5.Rows[x].Cells["SF RANK"].Value = Convert.ToString(x + 1);
}
this.dataGridView5.Sort(this.dataGridView5.Columns["PF"], System.ComponentModel.ListSortDirection.Descending);
for (int x = 0; x < dataGridView5.Rows.Count; x++)
{
dataGridView5.Rows[x].Cells["PF RANK"].Value = Convert.ToString(x + 1);
}
this.dataGridView5.Sort(this.dataGridView5.Columns["C"], System.ComponentModel.ListSortDirection.Descending);
for (int x = 0; x < dataGridView5.Rows.Count; x++)
{
dataGridView5.Rows[x].Cells["C RANK"].Value = Convert.ToString(x + 1);
}
}
}