public IActionResult Index(string currentFilter, int?pageNumber)
        {
            if (HttpContext.Session.GetString("SessionUser") == null || HttpContext.Session.GetString("Token") == null)
            {
                return(RedirectToAction("Logout", "Account"));
            }

            ProduitCategoriecs produitCategories = new ProduitCategoriecs();

            var token = HttpContext.Session.GetString("Token");

            IEnumerable <Produits> produits = _produitsService.GetProduits(token);

            produitCategories.categories = _categoriesService.GetCategories(token);

            ViewData["CurrentFilter"] = currentFilter;

            if (currentFilter == null || currentFilter.Contains("All"))
            {
                IEnumerable <Produits> produit0 = produits.Where(x => float.Parse(x.Stock) > 0);
                produitCategories.produits = PaginatedList <Produits> .CreateAsync(produit0, pageNumber ?? 1, 5);
            }
            else
            {
                IEnumerable <Produits> produitCate = produits.Where(x => x.CategorieName == currentFilter && int.Parse(x.Stock) > int.Parse("0"));

                produitCategories.produits = PaginatedList <Produits> .CreateAsync(produitCate, pageNumber ?? 1, 5);
            }

            return(View(produitCategories));
        }
Пример #2
0
        public ProduitUC()
        {
            InitializeComponent();

            var categories = _categorieService.GetCategories().ToList();

            comboBoxCategories.DataSource = categories;
            var products = _produitsService.GetProduits().ToList();

            comboBoxProducts.DataSource = products;

            comboBoxCategories.DropDownStyle = ComboBoxStyle.DropDownList;
            comboBoxProducts.DropDownStyle   = ComboBoxStyle.DropDownList;

            this.UpdateDataGrid();

            if (products.Count > 0)
            {
                gridProducts.Columns[0].Width    = 30;
                gridProducts.Columns[0].ReadOnly = true;
                gridProducts.Columns[2].Width    = 75;
                gridProducts.Columns[3].Width    = 75;
                gridProducts.Columns[4].Width    = 75;
                gridProducts.Columns[4].ReadOnly = true;
                gridProducts.Columns[5].ReadOnly = true;
            }
        }
Пример #3
0
        private void GridCommandes_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex >= 0)
            {
                int id = Convert.ToInt32(gridCommandes.Rows[e.RowIndex].Cells[0].Value);

                if (e.ColumnIndex == 5)
                {
                    CommandeDto commande     = _commandesService.GetCommandes().Where(c => c.Id == id).FirstOrDefault();
                    ClientDto   client       = _clientsService.GetClients().Where(c => c.Id == commande.Client.Id).FirstOrDefault();
                    string      clientToShow = "";
                    clientToShow += client.Id + "\n";
                    clientToShow += client.Nom + "\n";
                    clientToShow += client.Prenom + "\n";
                    clientToShow += client.Adresse.Rue1 + "\n";
                    if (!String.IsNullOrEmpty(client.Adresse.Rue2))
                    {
                        clientToShow += client.Adresse.Rue2 + "\n";
                    }
                    clientToShow += client.Adresse.Ville + "\n";
                    clientToShow += client.Adresse.CodePostal + "\n";
                    clientToShow += client.Adresse.Pays + "\n";
                    MessageBox.Show(clientToShow, "Informations de " + commande.Client.Nom + " " + commande.Client.Prenom);
                }
                else if (e.ColumnIndex == 6)
                {
                    totalPriceHT = 0;
                    totalPriceTT = 0;
                    string      productToShow = "";
                    CommandeDto commande      = _commandesService.GetCommandes().Where(c => c.Id == id).FirstOrDefault();
                    List <ProduitCommandeDto> produitCommande = _produitCommandeService.GetProduitCommandes().Where(pc => pc.Commande.Id == commande.Id).ToList();
                    if (produitCommande.Count > 0)
                    {
                        foreach (ProduitCommandeDto produit in produitCommande)
                        {
                            if (produit.Quantite > 1)
                            {
                                produit.Produit.Libelle += "s";
                            }
                            productToShow += produit.Quantite + " " + produit.Produit.Libelle + " à " + produit.Produit.PrixHT * produit.Quantite + "€\n";
                            double prixHT = (double)produit.Produit.PrixHT;
                            double taxe   = (double)produit.Produit.Taxe;
                            totalPriceHT += Math.Round(produit.Quantite * prixHT, 2);
                            totalPriceTT += Math.Round(produit.Quantite * prixHT * (1 + taxe), 2);
                        }
                        productToShow += "\n";
                        productToShow += "______________________ \n";
                        productToShow += "\n";
                        productToShow += "Prix HT : " + totalPriceHT + "€\n";
                        productToShow += "Prix TT : " + totalPriceTT + "€\n";

                        MessageBox.Show(productToShow, "Produits dans " + commande.Libelle);
                    }
                    else
                    {
                        MessageBox.Show("Il n'y a pas de produits dans cette commande pour le moment", "Erreur");
                    }
                }
                else
                {
                    selectedCommandId = id;
                    CommandeDto commande = _commandesService.GetCommandes().Where(c => c.Id == id).FirstOrDefault();
                    if (commande.Etat == 0)
                    {
                        totalPriceHT = 0;
                        totalPriceTT = 0;
                        labelTotalPrices.ResetText();
                        areHidden = true;
                        HideOrShowElements();
                        if (produitsDansCommande.Count > 0)
                        {
                            produitsDansCommande.Clear();
                            labelProductInCommand.Text = "";
                        }
                        labelLibelleCommande.Text = commande.Id + " - " + commande.Libelle;

                        var produits = _produitsService.GetProduits().ToList();
                        comboBoxProduits.DataSource = produits;
                    }
                    else
                    {
                        areHidden = false;
                        HideOrShowElements();
                    }
                }
            }
        }