-
Notifications
You must be signed in to change notification settings - Fork 0
/
Edit_Reprot.cs
99 lines (90 loc) · 2.84 KB
/
Edit_Reprot.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
using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Forms
{
public partial class Edit_Reprot : Form
{
MySqlCommand command;
MySqlConnection conn = new MySqlConnection("server=localhost;user=root;database=Barbershop;password=147852369;charset=utf8;");
DataTable tb;
public Edit_Reprot()
{
InitializeComponent();
CultureInfo.CurrentCulture = CultureInfo.GetCultureInfo("en-US");
string sql = "SELECT * FROM barbershop.report;";
ExecuteQuery(sql);
}
private void Edit_Reprot_Load(object sender, EventArgs e)
{
}
public void OpenConnection()
{
if (conn.State == ConnectionState.Closed)
{
conn.Open();
}
}
public void CloseConnection()
{
if (conn.State == ConnectionState.Open)
{
conn.Close();
}
}
public void ExecuteQuery(string query)
{
try
{
dataGridView1.DataSource = null;
OpenConnection();
tb = new DataTable();
MySqlDataAdapter adapter = new MySqlDataAdapter(query, conn);
adapter.Fill(tb);
dataGridView1.DataSource = tb;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
throw;
}
finally
{
CloseConnection();
}
}
private void button1_Click(object sender, EventArgs e)
{
try
{
string sql = "DELETE FROM barbershop.report where Date='" + Convert.ToDateTime(dataGridView1.CurrentRow.Cells[0].Value).ToString("yyyy/MM/dd")
+ "' and Visitors='" + dataGridView1.CurrentRow.Cells[1].Value + "' and " +
" Money = '" + dataGridView1.CurrentRow.Cells[2].Value + "'; SELECT* FROM barbershop.report;" ;
ExecuteQuery(sql);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка");
throw;
}
}
private void button2_Click(object sender, EventArgs e)
{
this.Hide();
Report obj = new Report();
obj.Show();
}
private void Edit_Reprot_FormClosed(object sender, FormClosedEventArgs e)
{
Application.Exit();
}
}
}