private void buttonAjouter_Click(object sender, EventArgs e) { int x = 1; try { int nb = Convert.ToInt32(textBoxQtVendu.Text); } catch (Exception exp0) { MessageBox.Show("Veuillez saisir une quantité valide ", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); x = 0; } if (x == 1) { if (Convert.ToInt32(textBoxQtRestante.Text) < Convert.ToInt32(textBoxQtVendu.Text)) { MessageBox.Show("La quantité que vous avez saisi est supérieure à celle du stock \n " + "veuillez entrer une quantité valide", "Error", MessageBoxButtons.OK, icon: MessageBoxIcon.Error); } else { VenteService.Vente vente = new VenteService.Vente(); vente.date_ajout = DateTime.Now; vente.quantite_vendu = Convert.ToInt32(textBoxQtVendu.Text); ProduitService.Produit produit = (ProduitService.Produit)comboBox_prod.SelectedItem; vente.id_produit = produit.id_produit; VenteService.add(vente); int Qt = Convert.ToInt32(textBoxQtRestante.Text) - Convert.ToInt32(textBoxQtVendu.Text); VenteService.updateQuantity(Qt, produit.id_produit); MessageBox.Show("Le Produit " + produit.nom + " a été Vendu .", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); btnCancel.PerformClick(); VenteServiceWCFClient ven = new VenteServiceWCFClient(); dataGridViewVente.DataSource = ven.listeVente(); comboBox_prod.Items.Clear(); ProduitServiceWCFClient serviceproduit = new ProduitServiceWCFClient(); List <ProduitService.Produit> produits = new List <ProduitService.Produit>(serviceproduit.findAvaibleProducts()); foreach (ProduitService.Produit p in produits) { comboBox_prod.Items.Add(p); } comboBox_prod.DisplayMember = "nom"; comboBox_prod.ValueMember = "id_produit"; } } }
private void btnValider_Click(object sender, EventArgs e) { if (comboBox_prod.Text != "") { textBoxQtVendu.Enabled = true; ProduitServiceWCFClient serviceproduit = new ProduitServiceWCFClient(); ProduitService.Produit produit = (ProduitService.Produit)comboBox_prod.SelectedItem; textBoxQtRestante.Text = Convert.ToString(produit.quantite); textBoxPrixVente.Text = Convert.ToString(produit.prix_vente); } else { MessageBox.Show("Veuillez Choisir un Produit !", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information); } }