-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStatistics.cs
133 lines (117 loc) · 5.06 KB
/
Statistics.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Kursov
{
public partial class Statistics : Form
{
public Statistics()
{
InitializeComponent();
LoadData();
}
public SqlConnection sqlcon = new SqlConnection(@"Data Source=LAPTOP-8RIM0556\SQLEXPRESS;Initial Catalog=Tennis;Integrated Security=True");
public void LoadData()
{
sqlcon.Open();
string query = @"Select Tournament.Name_Tournament,Country.Country_Name ,Tournament.Date_Start,Tournament.Date_Finish
from Tournament inner join Start_Table on Tournament.ID_Tournament=Start_Table.Tournament_info
inner join Country on Tournament.Country_info=Country.ID_Country";
SqlCommand com = new SqlCommand(query, sqlcon);
SqlDataReader reader = com.ExecuteReader();
List<string[]> data = new List<string[]> ();
while (reader.Read())
{
data.Add(new string[3]);
data[data.Count - 1][0] = reader[0].ToString();//Tournament Name
data[data.Count - 1][1] = reader[1].ToString();//Tournament Country
data[data.Count - 1][2] = reader[2].ToString().Substring(0,10)+"-" + reader[3].ToString().Substring(0,10);//Tournament Date
}
int x = 0;
foreach (string[]c in data)
{
Start_Table.RowCount += 1;
Start_Table[0, x].Value = c[0];
Start_Table[1, x].Value = c[1];
Start_Table[2, x].Value = c[2];
x++;
}
reader.Close();
sqlcon.Close();
}
public string dateTournStart = "";
public string dateTournFinish = "";
public int idTourn = 0;
private void Start_Table_CellClick(object sender, DataGridViewCellEventArgs e)
{
//string valuejj = Start_Table.CurrentCell.Value.ToString();
sqlcon.Open();
int col = Start_Table.CurrentCell.ColumnIndex;
int row = Start_Table.CurrentCell.RowIndex;
if (col == 0)
{
dateTournStart = Start_Table[col + 2, row].Value.ToString().Substring(0,10);
dateTournFinish = Start_Table[col + 2, row].Value.ToString().Substring(11);
string query = @"Select ID_Tournament from Tournament where Name_Tournament = '" + Start_Table.CurrentCell.Value.ToString() +
"'and Date_Start = '" + dateTournStart + "'and Date_Finish= '" + dateTournFinish + "'";
SqlCommand com = new SqlCommand(query, sqlcon);
SqlDataReader reader = com.ExecuteReader();
while(reader.Read())
idTourn = (int)reader[0];
reader.Close();
List<string[]> description = new List<string[]>();
List<int> idMatch = new List<int>();
query = @"Select Match_Stage, Match_Score, ID_Match from Match where
ID_Tournament = '" + idTourn + "'";
com = new SqlCommand(query, sqlcon);
reader = com.ExecuteReader();
while (reader.Read())
{
description.Add(new string[2]);
description[description.Count - 1][0] = reader[0].ToString();//Match Stage
description[description.Count - 1][1] = reader[1].ToString();//Match Score
//description[description.Count - 1][2] = reader[2].ToString() + "-" + reader[3].ToString();//Tennis Players
idMatch.Add((int)reader[2]);
}
reader.Close();
int x = 0;
foreach (string[] c in description)
{
Matches.RowCount += 1;
Matches[0, x].Value = c[0];
Matches[1, x].Value = c[1];
// Matches[2, x].Value = c[2];
x++;
}
x = 0;
foreach(int c in idMatch)
{
string check = "";
query = @"Select TennisPlayers.Surname from TennisPlayers
inner join Match_Tennis_Player on TennisPlayers.ID_TennisPlayers = Match_Tennis_Player.ID_Player
where Match_Tennis_Player.ID_Match ='"+c+"'";
com = new SqlCommand(query, sqlcon);
reader = com.ExecuteReader();
while (reader.Read())
{
check += reader[0].ToString()+" ";
}
reader.Close();
Matches[2, x].Value = check;
x++;
}
sqlcon.Close();
}
}
private void Button1_Click(object sender, EventArgs e)
{
}
}
}