Пример #1
0
        //
        // GET: /Client/Create
        public ActionResult Create()
        {
            Client client = new Client();

            var cli = db.Client.Max(a => a.Id_client) + 1;

            client.Code_client = MyGlobalVariables.FormatCode("CLT", cli);
            return View(client);
        }
Пример #2
0
 public ActionResult Create(Client client, string Categorie)
 {
     if (ModelState.IsValid)
     {
         var clt = from c in db.Client
                  where c.Code_client == client.Code_client
                  select c;
         if (clt.ToList().Count > 0)
         {
             ModelState.AddModelError("", "Le code que vous avez specifié est déjà utilisé");
         }
         else
         {
             client.Categorie_client = Categorie;
             db.Client.Add(client);
             db.SaveChanges();
             return RedirectToAction("Index");
         }
     }
     return View(client);
 }
Пример #3
0
 public ActionResult Edit(Client client, string Categorie)
 {
     if (ModelState.IsValid)
     {
         client.Categorie_client = Categorie;
         db.Entry(client).State = EntityState.Modified;
         db.SaveChanges();
         return RedirectToAction("Index");
     }
     return View(client);
 }
        public ActionResult Insert(short idm, string article)
        {
            ModelState.Clear();

            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_vente customer = new Liste_produit_vente
            {
                Id_article = short.Parse(v),
                Id_facture = idm
            };
            Facture_vente Fa = new Facture_vente();
            Fa = db.Facture_vente.Find(idm);

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

                Client client = new Client();

                client = db.Client.Find(db.Facture_vente.Find(idm).Id_client);

                //Perform model binding (fill the customer properties and validate it).
                if (TryUpdateModel(customer))
                {
                    if (Fa.Type_facture.Trim() == "Bon de commande".Trim())
                    {
                        if (client.Categorie_client.Trim() == "Grossiste".Trim())
                        {
                            customer.Prix = Art.Prix_grossiste;
                        }
                        else
                        {
                            customer.Prix = Art.Prix_detaillant;
                        }
                        customer.Prix_Total = customer.Prix * customer.Quantite;
                        db.Liste_produit_vente.Add(customer);
                        db.SaveChanges();
                        return RedirectToAction("Index", new { idm = customer.Id_facture });
                    }
                    else
                    {
                        //The model is valid - insert the customer and redisplay the grid.
                        if (Art.Qte_article < customer.Quantite)
                        {
                            ModelState.AddModelError("", "La quantité est supérieure à la quantité en stock");
                        }
                        else
                        {

                            if (client.Categorie_client.Trim() == "Grossiste".Trim())
                            {
                                customer.Prix = Art.Prix_grossiste;
                            }
                            else
                            {
                                customer.Prix = Art.Prix_detaillant;
                            }

                            customer.Prix_Total = customer.Prix * customer.Quantite;
                            db.Liste_produit_vente.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_facture });
                        }
                    }
                }

                if (customer.Quantite > 0)
                {
                    if (Fa.Type_facture.Trim() == "Bon de commande".Trim())
                    {
                        if (client.Categorie_client.Trim() == "Grossiste".Trim())
                        {
                            customer.Prix = Art.Prix_grossiste;
                        }
                        else
                        {
                            customer.Prix = Art.Prix_detaillant;
                        }
                        customer.Prix_Total = customer.Prix * customer.Quantite;
                        db.Liste_produit_vente.Add(customer);
                        db.SaveChanges();
                        return RedirectToAction("Index", new { idm = customer.Id_facture });
                    }
                    else
                    {
                        if (Art.Qte_article < customer.Quantite)
                        {
                            ModelState.AddModelError("", "La quantité est supérieure à la quantité en stock");
                        }
                        else
                        {
                            if (client.Categorie_client.Trim() == "Grossiste".Trim())
                            {
                                customer.Prix = Art.Prix_grossiste;
                            }
                            else
                            {
                                customer.Prix = Art.Prix_detaillant;
                            }

                            customer.Prix_Total = customer.Prix * customer.Quantite;
                            db.Liste_produit_vente.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();
                            return RedirectToAction("Index", new { idm = customer.Id_facture });
                        }
                    }
                }
            }
            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["Fa"] = db.Facture_vente.Find(idm);

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