// // GET: /Mouvement_stock/Create public ActionResult Create() { Mouvement_stock mouvement_stock = new Mouvement_stock(); var mv = db.Mouvement_stock.Max(a => a.ID_mouvement) + 1; mouvement_stock.Code_mouvement = MyGlobalVariables.FormatCode("MVS", mv); return View(mouvement_stock); }
public ActionResult Create(Mouvement_stock mouvement_stock, string TypeM) { mouvement_stock.Type_mouvement = TypeM; if (ModelState.IsValid) { db.Mouvement_stock.Add(mouvement_stock); db.SaveChanges(); return RedirectToAction("Index", "Default1", new { idm = mouvement_stock.ID_mouvement }); // return RedirectToAction("AddProduit",new {idm = mouvement_stock.ID_mouvement }); } return View(mouvement_stock); }
public ActionResult Insert(short idm, string article) { try { int px = article.IndexOf("-") + 2; int p = article.Length - px; string v = article.Substring(px, p); //Create a new instance of the Customer class. Liste_produit customer = new Liste_produit { Id_article = short.Parse(v), Id_operation = idm }; Article Art = new Article(); Mouvement_stock Mv = new Mouvement_stock(); Art = db.Article.Find(customer.Id_article); Mv = db.Mouvement_stock.Find(idm); //Perform model binding (fill the customer properties and validate it). if (TryUpdateModel(customer)) { if (Mv.Type_mouvement == "Sortie de stock") { if (Art.Qte_article < customer.Quantite) { ModelState.AddModelError("", "La quantité est supérieure à la quantité en stock"); } else { //The model is valid - insert the customer and redisplay the grid. customer.Prix_Total = customer.Quantite * customer.Prix; db.Liste_produit.Add(customer); db.SaveChanges(); //modiification de la qte d'article Art.Qte_article = Art.Qte_article - customer.Quantite; db.Entry(Art).State = EntityState.Modified; db.SaveChanges(); //GridRouteValues() is an extension method which returns the //route values defining the grid state - current page, sort expression, filter etc. return RedirectToAction("Index", new { idm = customer.Id_operation }); } } else { //The model is valid - insert the customer and redisplay the grid. customer.Prix_Total = customer.Quantite * customer.Prix; db.Liste_produit.Add(customer); db.SaveChanges(); //modiification de la qte d'article Art.Qte_article = Art.Qte_article + customer.Quantite; db.Entry(Art).State = EntityState.Modified; db.SaveChanges(); //GridRouteValues() is an extension method which returns the //route values defining the grid state - current page, sort expression, filter etc. return RedirectToAction("Index", new { idm = customer.Id_operation }); } } if (customer.Quantite > 0) { if (Mv.Type_mouvement == "Sortie de stock") { if (Art.Qte_article < customer.Quantite) { ModelState.AddModelError("", "La quantité est supérieure à la quantité en stock"); } else { //The model is valid - insert the customer and redisplay the grid. customer.Prix_Total = customer.Quantite * customer.Prix; db.Liste_produit.Add(customer); db.SaveChanges(); //modiification de la qte d'article Art.Qte_article = Art.Qte_article - customer.Quantite; db.Entry(Art).State = EntityState.Modified; db.SaveChanges(); //GridRouteValues() is an extension method which returns the //route values defining the grid state - current page, sort expression, filter etc. return RedirectToAction("Index", new { idm = customer.Id_operation }); } } else { //The model is valid - insert the customer and redisplay the grid. customer.Prix_Total = customer.Quantite * customer.Prix; db.Liste_produit.Add(customer); db.SaveChanges(); //modiification de la qte d'article Art.Qte_article = Art.Qte_article + customer.Quantite; db.Entry(Art).State = EntityState.Modified; db.SaveChanges(); //GridRouteValues() is an extension method which returns the //route values defining the grid state - current page, sort expression, filter etc. return RedirectToAction("Index", new { idm = customer.Id_operation }); } } } catch { ModelState.AddModelError("", "l'article est incorrect"); } //The model is invalid - render the current view to show any validation errors. var articles = db.Article; ViewData["articles"] = articles.ToList(); List<String> listToBind = new List<String>(); Preference preference = new Preference(); preference = db.Preference.Find(1); if (preference.CRecherche.Trim() == "Code article".Trim()) { foreach (var item in articles.ToList()) { listToBind.Add(item.Code_article + " - " + item.Id_article); } } else { foreach (var item in articles.ToList()) { listToBind.Add(item.Libelle_article + " - " + item.Id_article); } } ViewData["art"] = listToBind; ViewData["op"] = db.Mouvement_stock.Find(idm); var liste_produit = from l in db.Liste_produit.Include(l => l.Article).Include(l => l.Mouvement_stock) where l.Id_operation == idm select l ; return View("Index", liste_produit.ToList()); }
public ActionResult Edit(Mouvement_stock mouvement_stock) { if (ModelState.IsValid) { db.Entry(mouvement_stock).State = EntityState.Modified; db.SaveChanges(); return RedirectToAction("Index"); } return View(mouvement_stock); }
private ModelFacture CreatefactureM(short id) { ModelFacture modelfacture = new ModelFacture(); Mouvement_stock Ms = new Mouvement_stock(); Preference preference = new Preference(); var facture = from l in db.Mouvement_stock where l.ID_mouvement == id select l; var ListeP = from l in db.Liste_produit.Include(l => l.Article) where l.Id_operation == id select l; preference = db.Preference.Find(1); Ms = facture.ToList().ElementAt(0); modelfacture.Num_Facture = Ms.Code_mouvement; modelfacture.Type_Op = Ms.Type_mouvement; modelfacture.Date_Facture = Ms.Date_mouvement.ToShortDateString(); modelfacture.Nom_E = preference.Nom; modelfacture.Adresse_E = preference.Adresse; modelfacture.Numtel_E = preference.Num_telephone; modelfacture.Liste_produit = ListeP.ToList(); return modelfacture; }