private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex < 0) { return; } if (e.ColumnIndex == 5) { var db = new dbContext(); int id = (int)dataGridView1.Rows[e.RowIndex].Cells[0].Value; var commande = db.Commandes.Where(c => c.NCommande == id).FirstOrDefault(); if (commande != null && commande.statut == false) { Form1.SetMessageLog("La commande N " + commande.NCommande + " est arrivée"); dataGridView1.Rows[e.RowIndex].Cells[5].Value = "Arrivé"; commande.statut = true; db.SaveChanges(); dataGridView1.Rows[e.RowIndex].Cells[5].Style.BackColor = Color.Green; dataGridView1.Rows[e.RowIndex].Cells[5].Style.SelectionBackColor = Color.Green; dataGridView1.Rows[e.RowIndex].Selected = true; var produits_commande = db.Produit_commande.Where(p => p.NCommande == id).ToList(); foreach (var item in produits_commande) { double addDate = (item.Produit.dureeValidite_jour == null) ? 10 : (double)item.Produit.dureeValidite_jour; DateTime dateExpire = DateTime.Now.AddDays(addDate) == null?Convert.ToDateTime("07/12/1999") : DateTime.Now.AddDays(addDate); Stock_Magazin stockNewProduit = new Stock_Magazin() { codeMagazin = 1, codeProduit = item.codeProduit, quantite = item.quantite, dateExpiration = dateExpire }; db.Stock_Magazin.Add(stockNewProduit); db.SaveChanges(); } } } if (e.ColumnIndex == 6) { DialogResult rs = MessageBox.Show("La commande sera supprimer definitivement, Continue?", "Supprimer", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (rs != DialogResult.Yes) { return; } var db = new dbContext(); int id = (int)dataGridView1.Rows[e.RowIndex].Cells[0].Value; var commande = db.Commandes.Where(c => c.NCommande == id).FirstOrDefault(); if (commande != null) { db.Commandes.Remove(commande); db.SaveChanges(); refrechDataGrid(db.Commandes.ToList <Commande>()); } } }
private void Ajouter_Click(object sender, EventArgs e) { var db = new dbContext(); if (fournisseur.nomFournisseur != null) { try { var prod = db.Produits.ToList <Produit>()[comboBox1.SelectedIndex]; Stock_Magazin stock = new Stock_Magazin(); stock.codeProduit = prod.codeProduit; stock.codeMagazin = 1; stock.dateExpiration = dateExpirePick.Value; stock.quantite = Convert.ToInt32(tbQuantite.Text); db.Stock_Magazin.Add(stock); db.SaveChanges(); MessageBox.Show("Produit ajouté!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); //refrech flowlayoutpanel1 if (formParent.filter == 0) { formParent.btnViewAll_Click(null, null); } else if (formParent.filter == 1) { formParent.btnDisponible_Click(null, null); } else if (formParent.filter == 2) { formParent.btnNonDisponible_Click(null, null); } Form1.SetMessageLog("L'ajout d'un nouveau stock de " + prod.libelle + ", quantité: " + stock.quantite + ", date d'expiration: " + stock.dateExpiration); } catch (Exception exc) { MessageBox.Show("Error! " + exc.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } else { MessageBox.Show("Veuillez remplir tous les champs demandés", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }