-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStatistics.cs
More file actions
141 lines (117 loc) · 4.59 KB
/
Statistics.cs
File metadata and controls
141 lines (117 loc) · 4.59 KB
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
133
134
135
136
137
138
139
140
141
using Microsoft.Data.SqlClient;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Windows.Forms.DataVisualization.Charting;
namespace ConstHard
{
public partial class Statistics : Form
{
public Statistics()
{
InitializeComponent();
}
private void userstat_Click(object sender, EventArgs e)
{
string connectionString = @"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\temp\Register.mdf;Integrated Security=True;Connect Timeout=30";
string query = @"
SELECT r.Username, COUNT(t.Id) AS TaskCount
FROM Tasks t
JOIN Registpeople r ON t.CreatedByUserId = r.Id
WHERE t.Status = 'Finalized'
GROUP BY r.Username
ORDER BY r.Username";
DataTable dt = new DataTable();
try
{
using (SqlConnection conn = new SqlConnection(connectionString))
using (SqlCommand cmd = new SqlCommand(query, conn))
using (SqlDataAdapter adapter = new SqlDataAdapter(cmd))
{
adapter.Fill(dt);
}
}
catch (Exception ex)
{
MessageBox.Show("Error loading statistics: " + ex.Message);
return;
}
// Diagram tisztítása
chart1.Series.Clear();
chart1.ChartAreas.Clear();
chart1.Legends.Clear();
// ChartArea létrehozása
chart1.ChartAreas.Add(new ChartArea("MainArea"));
Legend legend = new Legend("UsersLegend");
legend.Docking = Docking.Right;
chart1.Legends.Add(legend);
// Színek tömbje
Color[] colors = new Color[] { Color.Green, Color.Purple, Color.Brown, Color.Cyan, Color.Magenta};
for (int i = 0; i < dt.Rows.Count; i++)
{
string username = dt.Rows[i]["Username"].ToString();
int taskCount = Convert.ToInt32(dt.Rows[i]["TaskCount"]);
Series series = new Series(username)
{
ChartType = SeriesChartType.Column,
Color = colors[i % colors.Length],
IsValueShownAsLabel = true,
Legend = "UsersLegend"
};
// Egy pontot adunk hozzá a series-hez (a feladatok számával)
series.Points.AddXY(username, taskCount);
chart1.Series.Add(series);
}
// Tengelyek beállítása
var chartArea = chart1.ChartAreas[0];
chartArea.AxisX.Interval = 5;
chartArea.AxisY.Title = "Number of finalized tasks";
chartArea.AxisY.Interval = 1;
chart1.Invalidate();
}
private void taskstatus_Click(object sender, EventArgs e)
{
string connectionString = "Data Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename=C:\\temp\\Register.mdf;Integrated Security=True;Connect Timeout=30";
string query = @"
SELECT Status, COUNT(*) AS TaskCount
FROM Tasks
GROUP BY Status";
using (SqlConnection connection = new SqlConnection(connectionString))
using (SqlCommand command = new SqlCommand(query, connection))
{
try
{
connection.Open();
SqlDataReader reader = command.ExecuteReader();
chart2.Series.Clear();
chart2.Titles.Clear();
chart2.Titles.Add("Tasks by Status");
Series series = new Series();
series.ChartType = SeriesChartType.Pie;
series.IsValueShownAsLabel = true;
while (reader.Read())
{
string status = reader["Status"].ToString();
int count = Convert.ToInt32(reader["TaskCount"]);
series.Points.AddXY(status, count);
}
chart2.Series.Add(series);
}
catch (Exception ex)
{
MessageBox.Show("Error loading task status chart: " + ex.Message);
}
}
}
public DataTable GetFinalizedTaskCountsPerUser(string connectionString)
{
throw new NotImplementedException();
}
}
}