-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclassProduct.php
157 lines (137 loc) · 5.29 KB
/
classProduct.php
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
<?php
class Produit {
public $idProduit;
private $nom;
private $pa;
private $pv;
private $pvmin;
private $quantite;
private $quantiteMin;
private $description;
public $message;
function __construct($nom, $pa, $pv, $pvmin, $quantite, $quantiteMin, $description) {
$this->nom = $nom;
$this->pa = $pa;
$this->pv = $pv;
$this->pvmin = $pvmin;
$this->quantite = $quantite;
$this->quantiteMin = $quantiteMin;
$this->description = $description;
}
function insererProduct() {
include 'connexion.php';
$sql = ("INSERT INTO Produit (Nom, PrixAchat, PrixVente, PrixVmin, QuantiteStock, QuantiteStockMin, DescriptionP) values ('".$this->nom."', '".$this->pa."', '".$this->pv."', '".$this->pvmin."', '".$this->quantite."', '".$this->quantiteMin."', '".$this->description."')");
if(mysqli_query($db, $sql)){
}else{
$this->message = mysqli_error($db);
}
}
function updateProduct() {
include 'connexion.php';
$updC= ("UPDATE `Produit` SET `Nom` = '".$this->nom."' WHERE idProduit =$this->idProduit");
if(mysqli_query($db,$updC)){echo"";}else{
$this->message = mysqli_error($db);
return;
}
$updC1= ("UPDATE `Produit` SET `PrixAchat` = $this->pa WHERE idProduit =$this->idProduit");
if(mysqli_query($db,$updC1)){echo"";}else{
$this->message = mysqli_error($db);
return;
}
$updC2= ("UPDATE `Produit` SET PrixVente = $this->pv WHERE idProduit =$this->idProduit");
if(mysqli_query($db,$updC2)){echo"";}else{
$this->message = mysqli_error($db);
return;
}
$updC3= ("UPDATE `Produit` SET PrixVmin = $this->pvmin WHERE idProduit =$this->idProduit");
if(mysqli_query($db,$updC3)){echo"";}else{
$this->message = mysqli_error($db);
return;
}
$updC4= ("UPDATE `Produit` SET QuantiteStock = $this->quantite WHERE idProduit =$this->idProduit");
if(mysqli_query($db,$updC4)){echo"";}else{
$this->message = mysqli_error($db);
return;
}
$updC5= ("UPDATE `Produit` SET QuantiteStockMin = $this->quantiteMin WHERE idProduit =$this->idProduit");
if(mysqli_query($db,$updC5)){echo"";}else{
$this->message = mysqli_error($db);
return;
}
$updC6= ("UPDATE `Produit` SET DescriptionP = '".$this->description."' WHERE idProduit =$this->idProduit");
if(mysqli_query($db,$updC6)){echo"";}else{
$this->message = mysqli_error($db);
return;
}
}
function deleteProduct() {
include 'connexion.php';
$delete = ("DELETE FROM Produit WHERE idProduit =$this->idProduit");
if (mysqli_query($db, $delete)){echo"";} else {
$this->message = mysqli_error($db);
return;
}
}
}
$q = $_REQUEST["q"];
$tabC = explode("::", $q);
$autre = '';
if (end($tabC) == 'add') {
if ($q !== "") {
$hint = $q;
$produit = new Produit($tabC[0], $tabC[1], $tabC[2], $tabC[3], $tabC[4], $tabC[5], $tabC[6]);
$produit->insererProduct();
$autre = $produit->message;
if( $produit->message) {
$hint = $autre;
}
}
$sucess = '<div class="alert alert-success" role="alert">
Insertion fait avec success
</div>';
$error = '<div class="alert alert-danger" role="alert">
Erreur '.$autre.'
</div>';
echo $hint == $autre ? $error : $sucess;
}
if(end($tabC) == 'update') {
$id= $tabC[7];
if ($q !== "") {
$hint = $q;
$produit = new Produit($tabC[0], $tabC[1], $tabC[2], $tabC[3], $tabC[4], $tabC[5], $tabC[6]);
$produit->idProduit = $id;
$produit->updateProduct();
$autre = $produit->message;
if( $produit->message) {
$hint = $autre;
}
}
$sucess = '<div class="alert alert-success" role="alert">
Modification fait avec success
</div>';
$error = '<div class="alert alert-danger" role="alert">
Erreur '.$autre.'
</div>';
echo $hint == $autre ? $error : $sucess;
}
if(end($tabC) == 'delete') {
$idCaisse = $tabC[4];
if ($q !== "") {
$hint = $q;
$salaire = new Produit(1, 2, 3, 4,5,6,7);
$salaire->idProduit = $tabC[0];
$salaire->deleteProduct();
$autre = $salaire->message;
if( $salaire->message) {
$hint = $autre;
}
}
$sucess = '<div class="alert alert-success" role="alert">
Suppression fait avec success
</div>';
$error = '<div class="alert alert-danger" role="alert">
Erreur '.$autre.'
</div>';
echo $hint == $autre ? $error : $sucess;
}
?>