-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUpdateClient.xaml.cs
More file actions
86 lines (84 loc) · 3.3 KB
/
Copy pathUpdateClient.xaml.cs
File metadata and controls
86 lines (84 loc) · 3.3 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
using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
namespace VeloMax
{
/// <summary>
/// Logique d'interaction pour UpdateClient.xaml
/// </summary>
public partial class UpdateClient : Window
{
int IdClient;
MySqlConnection Connection;
public UpdateClient(Client client, MySqlConnection connection)
{
InitializeComponent();
IdClient = client.Id;
Connection = connection;
entrepriseCheckBox.IsChecked = client.EstEntreprise;
siretTextBox.Text = client.Siret;
nomTextBox.Text = client.Nom;
prenomTextBox.Text = client.Prenom;
mailTextBox.Text = client.Mail;
telephoneTextBox.Text = client.Telephone;
rueTextBox.Text = client.Rue;
villeTextBox.Text = client.Ville;
codePostalTextBox.Text = client.CodePostal;
provinceTextBox.Text = client.Province;
estAbonneCheckBox.IsChecked = client.EstAbonne;
}
private void updateClientBtn_Click(object sender, RoutedEventArgs e)
{
Connection.Open();
try
{
bool estEntreprise = entrepriseCheckBox.IsChecked == true;
string siret = siretTextBox.Text;
string nom = nomTextBox.Text;
string prenom = prenomTextBox.Text;
string mail = mailTextBox.Text;
string telephone = telephoneTextBox.Text;
string rue = rueTextBox.Text;
string ville = villeTextBox.Text;
string codePostal = codePostalTextBox.Text;
string province = provinceTextBox.Text;
bool estAbonne = estAbonneCheckBox.IsChecked == true;
string request = $"UPDATE client SET estCompagnie={estEntreprise}, siret='{siret}', nom='{nom}', prenom='{prenom}', mail='{mail}', telephone='{telephone}', " +
$"rue='{rue}', ville='{ville}', codePostal='{codePostal}', province='{province}', estAbonne={estAbonne} WHERE id={IdClient};";
MySqlCommand cmd = new MySqlCommand(request, Connection);
cmd.ExecuteNonQuery();
MessageBox.Show("Data Updated !");
if (estAbonne)
{
Connection.Close();
ClientAbonnement clientAbonnement = new ClientAbonnement(IdClient, Connection);
clientAbonnement.ShowDialog();
}
else
{
request = $"UPDATE client SET idAbonnement = NULL WHERE id = {IdClient};";
cmd = new MySqlCommand(request, Connection);
cmd.ExecuteNonQuery();
Connection.Close();
}
this.Close();
}
catch
{
Connection.Close();
MessageBox.Show("Les Champs renseignes ne sont pas valides");
}
}
}
}