-
Notifications
You must be signed in to change notification settings - Fork 0
/
Report.cs
122 lines (107 loc) · 3.67 KB
/
Report.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
using MySql.Data.MySqlClient;
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;
namespace Forms
{
public partial class Report : Form
{
MySqlConnection conn = new MySqlConnection("server=localhost;user=root;database=Barbershop;password=147852369;charset=utf8;");
public Report()
{
InitializeComponent();
}
private void Report_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
OpenConnection();
DateTime thisDay = DateTime.Today;
int visits = 0;
double score = 0;
double Consumables = 0;
string sql = "select Money, Visitors, Date,Consumables from report where " +
"TIMESTAMPDIFF(DAY,Date,'" + thisDay.ToString("yyyy.MM.dd") + "') < "+Convert.ToInt16(comboBox1.Text)+";";
MySqlCommand command = new MySqlCommand(sql,conn);
MySqlDataReader reader = command.ExecuteReader();
while (reader.Read())
{
Consumables+= Convert.ToDouble(reader[3]);
score += Convert.ToDouble(reader[0]);
visits+=Convert.ToInt16(reader[1]);
}
label5.Text = score.ToString();
label7.Text = visits.ToString();
label10.Text = (Consumables / Convert.ToInt32(comboBox1.Text)).ToString();
if (visits > 0)
{
label4.Text = Math.Round((score / visits), 2).ToString();
}
else
{
MessageBox.Show("За данный период не было клиентов", "Отчёт");
}
CloseConnection();
reader.Close();
}
public void OpenConnection()
{
if (conn.State == ConnectionState.Closed)
{
conn.Open();
}
}
public void CloseConnection()
{
if (conn.State == ConnectionState.Open)
{
conn.Close();
}
}
private void button2_Click(object sender, EventArgs e)
{
this.Hide();
Form1 obj = new Form1();
obj.Show();
}
private void button3_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void Report_FormClosed(object sender, FormClosedEventArgs e)
{
Application.Exit();
}
private void button4_Click(object sender, EventArgs e)
{
this.Hide();
Edit_Reprot obj = new Edit_Reprot();
obj.Show();
}
private void button5_Click(object sender, EventArgs e)
{
DateTime thisDay = DateTime.Today;
string sql_report = "INSERT INTO `barbershop`.`report` (`Date`, `Visitors`, `Money`,`Consumables`) VALUES ('" + thisDay.ToString("yyyy.MM.dd") + "'," +
" '0', '0', '"+Convert.ToDouble(textBox1.Text)+"');";
try
{
OpenConnection();
MySqlCommand command = new MySqlCommand(sql_report, conn);
command.ExecuteScalar();
CloseConnection();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка!");
throw;
}
}
}
}