//Ajout d'une ligne de bon de distribution public static void Ajouter(NouvelleBonDistribution frm) { try { int numArticle = int.Parse(frm.TxtNumArticle.Text); int quantite = int.Parse(frm.TxtQuantite.Text); //Avant d'aller plus loin, verifier si l'article est en stock ou possede la qte demandée Article article = GestionArticle.Rechercher(numArticle); if (article != null) { StockCentral stockCentral = article.StockCentral; if (stockCentral != null) { if (stockCentral.qte >= quantite) { BonDistribution bonDistribution = frm.Session["bonDistribution"] as BonDistribution; LigneBonDistribution ligne = RechercherLigneBonDistribution(numArticle, bonDistribution.LigneBonDistributions); if (ligne == null) { ligne = new LigneBonDistribution { numArticle = numArticle, quantite = quantite, //Article=article }; bonDistribution.LigneBonDistributions.Add(ligne); } else { ligne.quantite += quantite; } frm.GridViewDistribution.DataSource = bonDistribution.LigneBonDistributions; frm.GridViewDistribution.DataBind(); frm.TxtNumArticle.Text = ""; frm.TxtNom.Text = ""; frm.TxtQuantite.Text = ""; frm.LblResultatEnregistrer.Text = ""; frm.LblResultatTxtQuantite.Text = "Article a été ajouté dans la liste bon distribution"; } else { //Message: Quantite insufisante, la quantite en etock est : stockCentral.qte frm.LblResultatTxtQuantite.Text = "Quantite insufisante! La quantite en etock est : " + stockCentral.qte; } } else { //Message: Cet article n'est pas en stock, Veuillez commander SVP! frm.LblResultatTxtQuantite.Text = "Cet article n'est pas en stock, Veuillez commander SVP!"; } } } catch (Exception e) { frm.LblResultatTxtQuantite.Text = "Champ oblitatoire et en numérique!"; } }
//Recevoir une commande public static void RecevoirCommande(RecevoirCommande frm) { try { //Recuperation du numero de commande int numCommande = int.Parse(frm.Session["numCommande"].ToString()); using (var sim = new SIM_Context()) { //Recuperation de l'objet commande Commande commande = sim.Commandes.Find(numCommande); if (commande != null) { foreach (LigneCommande l in commande.LigneCommandes) { //Selectionner l'article Article article = l.Article; //Selectionner le StockCentral lié à l'article StockCentral stockCentral = sim.StockCentrals.Find(article.numArticle); if (stockCentral != null)//L'article est deja en stock { //Mise à jour de la quantite en stock stockCentral.qte += l.quantite; } else { //Premiere commande pour cet article sim.StockCentrals.Add( new StockCentral { numArticle = article.numArticle, qte = l.quantite, qteCritique = 0 } ); } } int result = sim.SaveChanges(); frm.Session.Remove("numCommande"); frm.LblResultatNumeroCommande.Text = ""; frm.LblResultatRecevoir.Text = "La commande a été reçu avec succes!"; frm.BtnRecevoir.Enabled = false; frm.BtnImprimer.Enabled = false; } } } catch (Exception) { frm.LblResultatRecevoir.Text = "Le numéro de la commande invalide"; } }