Пример #1
0
        public ActionResult Create(Article article, string test)
        {
            var ar = from a in db.Article
                     where a.Code_article == article.Code_article
                     select a;

            if (ModelState.IsValid)
            {
              try
               {
                    if (ar.ToList().Count>0)
                    {
                        ModelState.AddModelError("", "Le code que vous avez specifié est déjà utilisé");
                    }
                    else
                    {
                        article.Qte_article = 0;
                        int px = test.IndexOf("-") + 2;
                        int p = test.Length - px;
                        string v = test.Substring(px, p);
                        article.Id_famille = short.Parse(v);
                        db.Article.Add(article);
                        db.SaveChanges();
                        return RedirectToAction("Index");
                   }
               }
                catch
                {
                    ModelState.AddModelError("", "La famille de l'article est incorrecte");
                }
            }

            //ViewBag.Id_famille = new SelectList(db.Famille_article, "Id_famille", "Libelle_famille", article.Id_famille);
               // ViewData["Famille"] = new SelectList(db.Famille_article, "Id_famille", "Libelle_famille", article.Id_famille);
            var familles = db.Famille_article.ToList();

            List<String> listToBind = new List<String>();

            foreach (var item in familles)
            {
                listToBind.Add(item.Libelle_famille + " - " + item.Id_famille);
            }

            ViewData["Famille"] = listToBind;
            return View(article);
        }
Пример #2
0
        //
        // GET: /Article/Create
        public ActionResult Create()
        {
            // ViewBag.Id_famille = new SelectList(db.Famille_article, "Id_famille", "Libelle_famille");

            var familles = db.Famille_article.ToList();
            Article article = new Article();

            var art = db.Article.Max(a => a.Id_article) + 1;

            article.Code_article = MyGlobalVariables.FormatCode("ART", art);

            List<String> listToBind = new List<String>();

            foreach (var item in familles)
            {
                listToBind.Add(item.Libelle_famille + " - " + item.Id_famille);
            }

            ViewData["Famille"] = listToBind;

            return View(article);
        }
Пример #3
0
        public ActionResult Edit(int id, Facture_achat facture_achat, string type="")
        {
            Facture_achat fa = new Facture_achat();
              try
               {
               fa = db.Facture_achat.Find(facture_achat.Id_facture);
               if (type == "")
               fa.Type_facture = facture_achat.Type_facture;
               else
               {
              if (fa.Type_facture == "Bon de commande")
              {
                var lp = from l in db.Liste_produit_achat.Include(l => l.Article)
                         where l.Id_facture == fa.Id_facture
                         select l;
                 IList<Liste_produit_achat> ListP = lp.ToList();
                 // using (var context = new STOCKONEntities())
                //  {
                  foreach (Liste_produit_achat listep in ListP)
                  {
                      Article article = new Article();
                      article = listep.Article;
                    article.Qte_article = article.Qte_article + listep.Quantite;
                    db.Entry(article).State = EntityState.Modified;
                    db.SaveChanges();
                  }
              //    }

              }

              fa.Type_facture = type;

               }

                db.Entry(fa).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Index");
               }
             catch
            {
                return View(fa);
            }
        }
Пример #4
0
        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());
        }
Пример #5
0
        public ActionResult Edit(int id, Facture_vente facture_vente, string type)
        {
            Facture_vente fa = new Facture_vente();
            try
               {
                fa = db.Facture_vente.Find(facture_vente.Id_facture);
                if (facture_vente.Type_facture == "Facture comptabilisée")
                {
                    fa.Type_facture = facture_vente.Type_facture;
                    db.Entry(fa).State = EntityState.Modified;
                    db.SaveChanges();
                    return RedirectToAction("Index");
                }
                else
                {
                    if (fa.Type_facture == "Bon de commande")
                    {
                        Article article = new Article();

                        var lp = from l in db.Liste_produit_vente.Include(l => l.Article)
                                 where l.Id_facture == fa.Id_facture
                                 select l;

                        if (VerifQ(lp.ToList()) == true)
                        {
                            ModelState.AddModelError("", "Les quantités en stock ne permettent pas de satisfaire cette démande : transformation impossible");
                            return View(fa);
                        }
                        else
                        {
                            IList<Liste_produit_vente> ListeP = lp.ToList();
                        foreach (Liste_produit_vente listep in ListeP)
                        {
                            listep.Article.Qte_article = listep.Article.Qte_article - listep.Quantite;
                            db.Entry(listep.Article).State = EntityState.Modified;
                            db.SaveChanges();
                        }
                        fa.Type_facture = type;
                        db.Entry(fa).State = EntityState.Modified;
                        db.SaveChanges();
                        return RedirectToAction("Index");

                        }

                        return RedirectToAction("Index");

                    }
                    else
                    {
                        fa.Type_facture = type;
                        db.Entry(fa).State = EntityState.Modified;
                        db.SaveChanges();
                        return RedirectToAction("Index");
                    }

                }
               }
            catch
            {
                return View(fa);
            }
        }
Пример #6
0
        public ActionResult Edit(Article article, string test)
        {
            if (ModelState.IsValid)
            {
                //Article articles = new Article();

                  //articles  = db.Article.Find(article.Id_article);
                 //article.Qte_article = articles.Qte_article;
                try
                {
                    article.Qte_article = 0;
                    int px = test.IndexOf("-") + 2;
                    int p = test.Length - px;
                    string v = test.Substring(px, p);
                    article.Id_famille = short.Parse(v);

                    db.Entry(article).State = EntityState.Modified;
                    db.SaveChanges();
                    return RedirectToAction("Index");
                }
                catch
                {
                    ModelState.AddModelError("", "La famille de l'article est incorrecte");
                }
            }
            var familles = db.Famille_article.ToList();

            List<String> listToBind = new List<String>();

            foreach (var item in familles)
            {
                listToBind.Add(item.Libelle_famille + " - " + item.Id_famille);
            }

            ViewData["Famille"] = listToBind;
               // ViewBag.Id_famille = new SelectList(db.Famille_article, "Id_famille", "Libelle_famille", article.Id_famille);
            return View(article);
        }
        public ActionResult Insert(short idm, string article)
        {
            //Create a new instance of the Customer class.
            try
            {
                int px = article.IndexOf("-") + 2;
                int p = article.Length - px;
                string v = article.Substring(px, p);

                Liste_produit_achat customer = new Liste_produit_achat
                {
                    Id_article = short.Parse(v),
                    Id_facture = idm
                };

                Facture_achat Fa = new Facture_achat();
                Fa = db.Facture_achat.Find(idm);

                Article Art = new Article();
                Art = db.Article.Find(customer.Id_article);

                //Perform model binding (fill the customer properties and validate it).
                if (TryUpdateModel(customer))
                {
                    //The model is valid - insert the customer and redisplay the grid.
                    customer.Prix_total = customer.Prix * customer.Quantite;
                    db.Liste_produit_achat.Add(customer);
                    db.SaveChanges();

                    if (Fa.Type_facture.Trim() == "Bon de commande".Trim())
                    { }
                    else
                    {
                        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_facture });
                }

                if (customer.Quantite > 0)
                {
                    customer.Prix_total = customer.Prix * customer.Quantite;
                    db.Liste_produit_achat.Add(customer);
                    db.SaveChanges();
                    if (Fa.Type_facture.Trim() == "Bon de commande".Trim())
                    { }
                    else
                    {
                        Art.Qte_article = Art.Qte_article + customer.Quantite;
                        db.Entry(Art).State = EntityState.Modified;
                        db.SaveChanges();
                    }
                    return RedirectToAction("Index", new { idm = customer.Id_facture });
                }
                //The model is invalid - render the current view to show any validation errors.
            }
            catch
            {
                ModelState.AddModelError("", "l'article est incorrect");
            }
            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["Fa"] = db.Facture_achat.Find(idm);

            var liste_produit = from l in db.Liste_produit_achat.Include(l => l.Article).Include(l => l.Facture_achat)
                                where l.Id_facture == idm
                                select l;
            return View("index",liste_produit.ToList());
        }