private void SupprimerClient_Click(object sender, RoutedEventArgs e) { string[] recetteClient = Compte.getdata("select NomR from recette where IDcreateur like'" + Compte.Verifcommande(ClientSuppr.Text) + "';").Split(','); if (recetteClient != null) { for (int i = 0; i < recetteClient.Length; i++) { string[] produitRecette = Compte.getdata("select keyutilise from utilise where NomR like'" + recetteClient[i].Trim(',', ' ') + "';").Split(','); if (produitRecette != null) { for (int j = 0; j < produitRecette.Length; j++) { if (produitRecette[j] != null && produitRecette[j] != "") { Compte.lirecommande("delete from utilise where keyutilise like '" + produitRecette[j].Trim(',', ' ') + "';"); } } Compte.lirecommande("delete from recette where NomR like '" + recetteClient[i] + "';"); } } } Compte.lirecommande("delete from client where IDclient like '" + Compte.Verifcommande(ClientSuppr.Text) + "';"); MessageBox.Show("Le compte a bien été supprimé ainsi ces recettes associé."); }
//COMMANDE static void payement(string idclient, string NomR) //id du client et nom de la recette { int prixr = Compte.GetDataInt("select Prixplat from recette where NomR like '" + NomR + "';"); int soldclient = Compte.GetDataInt("select soldeclient from client where IDclient like '" + idclient + "';"); int diffprix = soldclient - prixr; Compte.lirecommande("update client set soldeclient='" + diffprix + "' where IDclient like'" + idclient + "';"); // on change le montant d'argent du client }
static void remunerationcdr(string NomR) // fonction qui rémunère un cdr lorsque ça recette est commandé { string idcdr = Compte.getdata("select IDcreateur from recette where NomR like '" + NomR + "';").Trim(','); int montantcdr = Compte.GetDataInt("select Remunerationcdr from recette where NomR like '" + NomR + "';"); int soldcdr = Compte.GetDataInt("select distinct soldeclient from client natural join recette where recette.IDcreateur=client.IDclient and recette.NomR like '" + NomR + "'; "); soldcdr += montantcdr; Compte.lirecommande("update client set soldeclient='" + soldcdr + "' where IDclient like '" + idcdr + "';"); }
private void CreerRecette(object sender, RoutedEventArgs e) { if (liste_aliment_recette.Items.Count != 0) { bool rep = true; for (int i = 0; i < PrixVente.Text.Length; i++) { if (!char.IsDigit(PrixVente.Text[i])) { rep = false; } } if (rep && NomRecette.Text != "" && NomRecette.Text != null && PrixVente.Text != "" && PrixVente.Text != null && DescriptionProduit.Text != "" && DescriptionProduit.Text != null && DescriptionProduit.Text.Length <= 256 && Compte.GetDataInt("select count(NomR) from recette where NomR like '" + Compte.Verifcommande(NomRecette.Text) + "';") == 0) { if (!produitexist(Compte.Verifcommande(NomRecette.Text))) { if (Convert.ToInt32(PrixVente.Text) >= 10 && Convert.ToInt32(PrixVente.Text) <= 40) { Compte.lirecommande("INSERT INTO `cooking`.`recette` (`NomR`,`Type`,`Descriptif`,`Prixplat`,`Remunerationcdr`,`Nombreplatcommande`,`IDcreateur`) VALUES('" + Compte.Verifcommande(NomRecette.Text) + "', '" + Compte.Verifcommande(typedeplat.Text) + "', '" + Compte.Verifcommande(DescriptionProduit.Text) + "', " + PrixVente.Text + ", '2', '0', '" + Compte.Verifcommande(compte_utilise.Identifiant) + "');"); //RECETTE CREER foreach (Produit p in liste_aliment_recette.Items) { if (p != null) { p.Stockmini = (p.Stockmini / 2) + (3 * p.Quantite); p.Stockmaxi += (2 * p.Quantite); Compte.lirecommande("INSERT INTO `cooking`.`utilise` (`keyutilise`,`quantitep`,`IDproduit`,`NomR`) VALUES ('" + p.IDproduit + Compte.Verifcommande(NomRecette.Text) + "','" + p.Quantite + "','" + p.IDproduit + "','" + Compte.Verifcommande(NomRecette.Text) + "');"); Compte.lirecommande("update produit set stockmini='" + p.Stockmini + "' where IDproduit like '" + p.IDproduit + "';"); Compte.lirecommande("update produit set stockmaxi='" + p.Stockmaxi + "' where IDproduit like '" + p.IDproduit + "';"); } } MessageBox.Show("Félicitation, vous venez de créer votre recette !\n\nResume :Nom de la recette :" + Compte.Verifcommande(NomRecette.Text) + "\nProduit utilise avec quantite : " + Compte.getdata("select IDproduit,quantitep from utilise where NomR like '" + Compte.Verifcommande(NomRecette.Text) + "'; ") + "\nType de produit : " + Compte.Verifcommande(typedeplat.Text) + "\n Prix :" + PrixVente.Text); ViderRecette(sender, e); } else { MessageBox.Show("Le prix de vente n'est pas correcte, veuillez recommencer"); } } else { MessageBox.Show("Ce produit existe déjà veuillez changer de nom."); } } else { MessageBox.Show("Erreur, veuillez compléter correctement toutes les données demandés svp."); } } else { MessageBox.Show("Veuillez ajouter des produits à votre recette."); } }
private void SupprimerRecette_Click(object sender, RoutedEventArgs e) { string[] produitRecette = Compte.getdata("select keyutilise from utilise where NomR like'" + Compte.Verifcommande(RecetteSuppr.Text) + "';").Split(','); if (produitRecette != null) { for (int j = 0; j < produitRecette.Length; j++) { if (produitRecette[j] != null && produitRecette[j] != "") { Compte.lirecommande("delete from utilise where keyutilise like '" + produitRecette[j].Trim(',', ' ') + "';"); } } Compte.lirecommande("delete from recette where NomR like '" + Compte.Verifcommande(RecetteSuppr.Text) + "';"); MessageBox.Show("La recette a bien été supprimé."); } }
private void MiseAjourStock_Click(object sender, RoutedEventArgs e) { List <Commande> listcommande = Commande.commandeSurDuree(30); List <Plat> listplat = Commande.ListPlatDansListCommande(listcommande); List <Produit> listproduit = Produit.ProduitUtiliserDansPlat(listplat); string[] toutproduit = Compte.getdata("select distinct nomproduit from produit;").Split(','); for (int i = 0; i < toutproduit.Length; i++) { if (toutproduit[i] != null && toutproduit[i] != "") { Produit temp = new Produit(toutproduit[i]); if (!temp.Contenue(listproduit)) { Compte.lirecommande("update produit set stockmini='" + temp.Stockmini / 2 + "' where IDproduit like'" + temp.IDproduit + "';"); Compte.lirecommande("update produit set stockmaxi='" + temp.Stockmaxi / 2 + "' where IDproduit like'" + temp.IDproduit + "';"); } } } MessageBox.Show("Les stocks max et min des produits non utilisé ont été divisé par 2."); }
static void miseajournbrecette(string id, string NomR) // permet de mettre à jour le nombre de plat commandé par recette et la renum en cook && renum cook { int nbcommandé = Compte.GetDataInt("select Nombreplatcommande from recette where NomR like '" + NomR + "';"); nbcommandé += 1; // on augmente de 1 car une commande à été faite Compte.lirecommande("update recette set Nombreplatcommande='" + nbcommandé + "' where NomR like '" + NomR + "';"); if (nbcommandé == 10) { int prixr = Compte.GetDataInt("select Prixplat from recette where NomR like '" + NomR + "';"); prixr += 2; //on augmente le prix de la recette de 2 cook si elle a été commandé plus de 10 fois Compte.lirecommande("update recette set Prixplat='" + prixr + "' where NomR like '" + NomR + "';"); } if (nbcommandé == 50) { int prixr = Compte.GetDataInt("select Prixplat from recette where NomR like '" + NomR + "';"); prixr += 3; //on augmente le prix de la recette de 3 cook si elle a été commandé plus de 50 fois Compte.lirecommande("update recette set Prixplat='" + prixr + "' where NomR like '" + NomR + "';"); int remuncdr = 4; //on augmente la renum du cdr à 4 cook si elle a été commandé plus de 50 fois Compte.lirecommande("update recette set Remunerationcdr='" + remuncdr + "' where NomR like '" + NomR + "';"); } }
private void Reapprovisionnement_Click(object sender, RoutedEventArgs e) { string nomfichier = "Commande_" + DateTime.Today.ToString().Remove(10).Replace('/', '.') + ".xml"; for (int i = 0; i < ProduitReapro.Count; i++) { if (ProduitReapro[i] != null) { int quantiteACommander = ProduitReapro[i].Stockmaxi - ProduitReapro[i].Stock; Compte.lirecommande("update produit set stock='" + ProduitReapro[i].Stockmaxi + "' where IDproduit like '" + ProduitReapro[i].IDproduit + "';"); ProduitReapro[i].Stock = ProduitReapro[i].Stockmaxi; Compte.lirecommande("INSERT INTO `cooking`.`fournis` (`numerocommande`,`Reffournisseur`,`IDproduit`,`quantitefournis`,`DateF`) VALUES ('" + (Compte.GetDataInt("select count(numerocommande) from fournis;") + 1) + "','" + ProduitReapro[i].Reffournisseur + "','" + ProduitReapro[i].IDproduit + "','" + quantiteACommander + "','" + DateTime.Today.ToString().Remove(10) + "');"); MessageBox.Show("reaprovisionement de " + ProduitReapro[i].Nomproduit + " effectue !"); ProduitReapro.Remove(ProduitReapro[i]); } } commandefournisseur("select * from fournis where DateF like '" + DateTime.Today.ToString().Remove(10) + "';", nomfichier); RecapCommande.Add(nomfichier); ListeProduitRapro.ItemsSource = ProduitReapro; int temp = 0; for (int i = 0; i < RecapCommande.Count; i++) { if (nomfichier == RecapCommande[i]) { temp++; if (temp > 1) { RecapCommande.Remove(RecapCommande[i]); } } } ListeCommande.ItemsSource = RecapCommande; }
private void Commander(object sender, RoutedEventArgs e) { if (liste_panier.Items.Count != 0) { bool quantiteok = true; List <Produit> produit_stock = new List <Produit>(); foreach (Plat o in liste_panier.Items) { if (o != null) { List <Produit> produitaajouter = Produit.ProduitUtiliserDansPlat(o); foreach (Produit pro in produitaajouter) { if (o != null) { produit_stock.Add(pro); } } } } List <Produit> produit_utilise = Produit.FusionListeProduit(produit_stock); for (int i = 0; i < produit_utilise.Count; i++) { if (Compte.GetDataInt("select stock from produit where IDproduit like'" + produit_utilise[i].IDproduit + "';") < produit_utilise[i].Stock) { quantiteok = false; } } int diffprix = compte_utilise.PointCooking - prix_total; if (diffprix >= 0 && quantiteok) { for (int i = 0; i < produit_utilise.Count; i++) { Compte.lirecommande("update produit set stock='" + (Compte.GetDataInt("select stock from produit where IDproduit like '" + produit_utilise[i].IDproduit + "';") - produit_utilise[i].Stock) + "' where IDproduit like '" + produit_utilise[i].IDproduit + "';"); } MessageBox.Show("Commande réussie ! \nNous procédons à la livraison de suite !", "Etat de la commande"); foreach (Plat o in liste_panier.Items) { if (o != null) { payement(compte_utilise.Identifiant, o.NomR); miseajournbrecette(compte_utilise.Identifiant, o.NomR); o.Renomme = Compte.getdata("select Nombreplatcommande from recette where NomR like '" + o.NomR + "';").Trim(','); o.Prix = Compte.GetDataInt("select Prixplat from recette where NomR like '" + o.NomR + "';"); remunerationcdr(o.NomR); if (Compte.getdata("select IDcreateur from recette where NomR like '" + o.NomR + "';").Trim(',') == compte_utilise.Identifiant) { compte_utilise.PointCooking = Compte.GetDataInt("select soldeclient from client where IDclient like '" + compte_utilise.Identifiant + "'; "); } Compte.lirecommande("INSERT INTO `cooking`.`commande` (`IDcommande`,`Datec`,`Quantitec`,`prixc`,`IDclient`,`NomR`) VALUES ('" + +(Compte.GetDataInt("select count(IDcommande)from commande;") + 1) + "','" + DateTime.Today.ToString().Remove(10) + "','1','" + o.Prix + "','" + compte_utilise.Identifiant + "','" + o.NomR + "');"); } } compte_utilise.PointCooking = diffprix; solde_cook.Text = "" + compte_utilise.PointCooking; ViderPanier(sender, e); } else { if (diffprix < 0) { MessageBox.Show("Vous ne disposez pas assez de crédit cooking pour effectuer l'achat."); } else { MessageBox.Show("Rupture de stock d'un ou plusieur aliments compris dans vos plats.\nDésolé pour la gêne occasionné, veuillez recommencer plus tard svp."); } } } else { MessageBox.Show("Votre panier est vide"); } }
/// <summary> /// fonction pour créer un compte dans la bdd /// </summary> /// <param name="nom"></param> /// <param name="prenom"></param> /// <param name="id"></param> /// <param name="mdp"></param> static void creacompte(string nom, string prenom, string id, string mdp) { string requetecrea = "INSERT INTO `cooking`.`client` (`IDclient`,`Nom`,`prenom`,`MDPcompte`,`soldeclient`) VALUES('" + Compte.Verifcommande(id) + "','" + Compte.Verifcommande(nom) + "','" + Compte.Verifcommande(prenom) + "','" + Compte.Verifcommande(mdp) + "','0');"; Compte.lirecommande(requetecrea); }