-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfrmSettings.cs
177 lines (156 loc) · 8.09 KB
/
frmSettings.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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
using MySql.Data.MySqlClient;
using SMS_Sender.Properties;
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 SMS_Sender
{
public partial class frmSettings : Form
{
public frmSettings()
{
InitializeComponent();
}
private void picModifier_Click(object sender, EventArgs e)
{
if (MessageBox.Show("Voulez-vous vraiment modifier les paramètres ?", "Paramètres", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
if (string.IsNullOrEmpty(txtIp.Text) || string.IsNullOrEmpty(txtMode.Text) || string.IsNullOrEmpty(txtpassword.Text) || string.IsNullOrEmpty(txtport.Text) || string.IsNullOrEmpty(txtusername.Text) || string.IsNullOrEmpty(txtdatabase.Text))
{
MessageBox.Show("Il y a des champs obligatoire à remplir avant modification ? ", "Paramètres", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
Settings.Default.ip = txtIp.Text;
Settings.Default.username = txtusername.Text;
Settings.Default.password = txtpassword.Text;
Settings.Default.database = txtdatabase.Text;
Settings.Default.port = txtport.Text;
Settings.Default.mode = txtMode.Text;
//enregistrement
Settings.Default.Save();
MessageBox.Show("Successfull, l'application va rédemarrer", "Paramètres", MessageBoxButtons.OK, MessageBoxIcon.Information);
Application.Restart();
}
}
}
private void frmParametres_Load(object sender, EventArgs e)
{
// instaciation des valeurs par defaut du server
txtIp.Text = Settings.Default.ip;
txtdatabase.Text = Settings.Default.database;
txtusername.Text = Settings.Default.username;
txtpassword.Text = Settings.Default.password;
txtport.Text = Settings.Default.port;
txtMode.Text = Settings.Default.mode;
// instaciation des valeurs par defaut de la bs
txtTable.Text = Settings.Default.table;
txtChamp1.Text = Settings.Default.champ1;
txtChamp2.Text = Settings.Default.champ2;
txtChamp3.Text = Settings.Default.champ3;
txtChamp4.Text = Settings.Default.champ4;
txtChamp5.Text = Settings.Default.champ5;
}
private void picTester_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(txtIp.Text) || string.IsNullOrEmpty(txtMode.Text) || string.IsNullOrEmpty(txtpassword.Text) || string.IsNullOrEmpty(txtport.Text) || string.IsNullOrEmpty(txtusername.Text) || string.IsNullOrEmpty(txtdatabase.Text))
{
MessageBox.Show("Il y a des champs obligatoire à remplir avant modification ? ", "Paramètres", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
try
{
MySqlConnection conn = new MySqlConnection();
string connection_string = "server=" + txtIp.Text + "; port=" + txtport.Text + "; user=" + txtusername.Text + "; password=" + txtpassword.Text + "; database=" + txtdatabase.Text + "";
conn = new MySqlConnection(connection_string);
if (conn.State == ConnectionState.Closed)
{
conn.Open();
MessageBox.Show("Connexion établie", "Connexion", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
conn.Close();
MessageBox.Show("Connexion échouer", "Connexion", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
catch (Exception Ex)
{
MessageBox.Show("Connexion échouer " + Ex.Message, "Connexion", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void picSaveBD_Click(object sender, EventArgs e)
{
if (MessageBox.Show("Voulez-vous vraiment modifier les paramètres ?", "Paramètres", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
if (string.IsNullOrEmpty(txtTable.Text) || string.IsNullOrEmpty(txtChamp1.Text) || string.IsNullOrEmpty(txtChamp2.Text) || string.IsNullOrEmpty(txtChamp3.Text) || string.IsNullOrEmpty(txtChamp4.Text) || string.IsNullOrEmpty(txtChamp5.Text))
{
MessageBox.Show("Il y a des champs obligatoire à remplir avant modification ? ", "Paramètres", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
Settings.Default.table = txtTable.Text;
Settings.Default.champ1 = txtChamp1.Text;
Settings.Default.champ2 = txtChamp2.Text;
Settings.Default.champ3 = txtChamp3.Text;
Settings.Default.champ4 = txtChamp4.Text;
Settings.Default.champ5 = txtChamp5.Text;
//enregistrement
Settings.Default.Save();
MessageBox.Show("Successfull, l'application va rédemarrer", "Paramètres", MessageBoxButtons.OK, MessageBoxIcon.Information);
Application.Restart();
}
}
}
private void picTestedBD_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(txtTable.Text) || string.IsNullOrEmpty(txtChamp1.Text) || string.IsNullOrEmpty(txtChamp2.Text) || string.IsNullOrEmpty(txtChamp3.Text) || string.IsNullOrEmpty(txtChamp4.Text) || string.IsNullOrEmpty(txtChamp5.Text))
{
MessageBox.Show("Il y a des champs obligatoire à remplir avant modification ? ", "Paramètres", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
try
{
MySqlConnection conn = new MySqlConnection();
string connection_string = "server=" + txtIp.Text + "; port=" + txtport.Text + "; user=" + txtusername.Text + "; password=" + txtpassword.Text + "; database=" + txtdatabase.Text + "";
conn = new MySqlConnection(connection_string);
if (conn.State == ConnectionState.Closed)
{
conn.Open();
MessageBox.Show("Connexion établie à la base de données", "Connexion", MessageBoxButtons.OK, MessageBoxIcon.Information);
//datatable
DataTable dt = new DataTable();
MySqlDataAdapter sda = new MySqlDataAdapter("SELECT * FROM " + txtTable.Text + ";", conn);
sda.Fill(dt);
if (dt.Rows.Count > 0)
{
MessageBox.Show("Il y a des données dans la table", "Accès à la table", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
MessageBox.Show("Il y a pas des données dans la table", "Accès à la table", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
else
{
conn.Close();
MessageBox.Show("Connexion échouer", "Connexion", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
catch (Exception Ex)
{
MessageBox.Show("Connexion échouer " + Ex.Message, "Connexion", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}
}