Exemplo n.º 1
0
        public async Task <CommandeDto> GetCommande()
        {
            if (AuthentificationService.Instance.isLogged)
            {
                _httpClient.DefaultRequestHeaders.Authorization =
                    new AuthenticationHeaderValue("Bearer", AuthentificationService.Instance.Token);


                var reponse = await _httpClient.GetAsync($"commandes/afficher");

                if (reponse.IsSuccessStatusCode)
                {
                    using (var stream = await reponse.Content.ReadAsStreamAsync())
                    {
                        CommandeDto commande = await JsonSerializer.DeserializeAsync <CommandeDto>(stream,
                                                                                                   new JsonSerializerOptions()
                        {
                            PropertyNameCaseInsensitive = true
                        });

                        return(commande);
                    }
                }
                else
                {
                    return(null);
                }
            }


            return(null);
        }
        public CommandeDto UpdateCommande(CommandeDto commandeDto)
        {
            var commande = Context.Commande.Where(p => p.Id == commandeDto.Id).FirstOrDefault();;

            commande.Libelle        = commandeDto.Libelle;
            commande.Etat           = (int)commandeDto.Etat;
            commande.DateCreation   = (DateTime)commandeDto.DateCreation;
            commande.DateValidation = (DateTime)commandeDto.DateValidation;

            Context.SaveChanges();

            return(commandeDto);
        }
 public void CreateNewCommande(CommandeDto commande)
 {
     Context.Commande.Add(new Commande()
     {
         Id             = commande.Id,
         Libelle        = commande.Libelle,
         Etat           = (int)commande.Etat,
         DateCreation   = (DateTime)commande.DateCreation,
         DateValidation = (DateTime)commande.DateValidation,
         Client         = Context.Client.Where(c => c.Id == commande.Client.Id).FirstOrDefault()
     });
     Context.SaveChanges();
 }
Exemplo n.º 4
0
        private void ButtonAddProduct_Click(object sender, EventArgs e)
        {
            ProduitDto produit = _produitsService.GetProduits().Where(c => c.Id == Convert.ToInt32(comboBoxProduits.SelectedValue)).FirstOrDefault();

            if (produit != null)
            {
                if (numericUpDownQty.Value >= 1)
                {
                    if (produit.Quantite >= numericUpDownQty.Value)
                    {
                        int    qty    = Decimal.ToInt32(numericUpDownQty.Value);
                        double prixHT = (double)produit.PrixHT;
                        double taxe   = (double)produit.Taxe;
                        totalPriceHT          += Math.Round(qty * prixHT, 2);
                        totalPriceTT          += Math.Round(qty * prixHT * (1 + taxe), 2);
                        labelTotalPrices.Text  = "Prix Total HT : " + totalPriceHT + "€\n";
                        labelTotalPrices.Text += "Prix Total TT : " + totalPriceTT + "€\n";
                        CommandeDto        commande        = _commandesService.GetCommandes().Where(c => c.Id == selectedCommandId).FirstOrDefault();
                        ProduitCommandeDto produitCommande = new ProduitCommandeDto()
                        {
                            Quantite = qty,
                            Produit  = produit,
                            Commande = commande
                        };
                        produitsDansCommande.Add(produitCommande);
                        labelProductInCommand.Text += qty + " " + produit.Libelle + " " + produit.PrixHT * qty + "€\n";
                        numericUpDownQty.Value      = 1;
                        List <ProduitDto> produitRestant = new List <ProduitDto>();
                        var produits = _produitsService.GetProduits().ToList();
                        foreach (ProduitDto prod in produits)
                        {
                            bool isInList = produitsDansCommande.Exists(pc => pc.Produit.Id == prod.Id);
                            if (!isInList)
                            {
                                produitRestant.Add(prod);
                            }
                        }
                        comboBoxProduits.DataSource = produitRestant;
                    }
                    else
                    {
                        MessageBox.Show("La quantité en stock est insuffisante.\nIl reste " + produit.Quantite + " " + produit.Libelle, "ERROR");
                    }
                }
            }
        }
Exemplo n.º 5
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            int         clientId = Convert.ToInt32(comboBoxClient.SelectedValue);
            ClientDto   client   = _clientsService.GetClients().Where(c => c.Id == clientId).FirstOrDefault();
            CommandeDto commande = new CommandeDto()
            {
                Libelle        = textBoxLibelle.Text.Trim(),
                Etat           = 0,
                DateCreation   = DateTime.Now,
                DateValidation = DateTime.Now,
                Client         = client,
            };

            _commandesService.CreateNewCommande(commande);

            UpdateDataGrid();

            textBoxLibelle.ResetText();
        }
Exemplo n.º 6
0
        private void ButtonAddLivraison_Click(object sender, EventArgs e)
        {
            AdresseDto  adresse  = _adressesService.GetAdresses().Where(a => a.Id == Convert.ToInt32(comboBoxAdresse.SelectedValue)).FirstOrDefault();
            CommandeDto commande = _commandesService.GetCommandes().Where(c => c.Id == Convert.ToInt32(comboBoxCommande.SelectedValue)).FirstOrDefault();
            SalarieDto  salarie  = _salariesService.GetSalaries().Where(s => s.Id == Convert.ToInt32(comboBoxSalarie.SelectedValue)).FirstOrDefault();
            VehiculeDto vehicule = _vehiculesService.GetVehicules().Where(v => v.Id == Convert.ToInt32(comboBoxVehicule.SelectedValue)).FirstOrDefault();

            LivraisonDto livraison = new LivraisonDto()
            {
                DateLivraison = null,
                Adresse       = adresse,
                Commande      = commande,
                Salarie       = salarie,
                Vehicule      = vehicule
            };

            _livraisonsService.CreateNewLivraison(livraison);

            UpdateDataGrid();
        }
Exemplo n.º 7
0
        private void ButtonValidateCommand_Click(object sender, EventArgs e)
        {
            CommandeDto commande = _commandesService.GetCommandes().Where(c => c.Id == selectedCommandId).FirstOrDefault();

            commande.Etat           = 1;
            commande.DateValidation = DateTime.Now;
            _commandesService.UpdateCommande(commande);
            foreach (ProduitCommandeDto produitCommande in produitsDansCommande)
            {
                _produitCommandeService.CreateNewProduitCommands(produitCommande);
            }
            areHidden = false;
            HideOrShowElements();
            totalPriceHT = 0;
            totalPriceTT = 0;
            labelTotalPrices.ResetText();
            if (produitsDansCommande.Count > 0)
            {
                produitsDansCommande.Clear();
                labelProductInCommand.Text = "";
            }
            UpdateDataGrid();
        }
Exemplo n.º 8
0
        private void GridLivraisons_CellContentClick_1(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex >= 0)
            {
                int          id        = Convert.ToInt32(gridLivraisons.Rows[e.RowIndex].Cells[0].Value);
                LivraisonDto livraison = _livraisonsService.GetLivraisons().Where(l => l.Id == id).FirstOrDefault();
                buttonConfirmLivraison.Hide();

                if (e.ColumnIndex == 2)
                {
                    AdresseDto adresse       = _adressesService.GetAdresses().Where(a => a.Id == livraison.Adresse.Id).FirstOrDefault();
                    string     adresseToShow = "";
                    adresseToShow += adresse.Id + "\n";
                    adresseToShow += adresse.Rue1 + "\n";
                    if (!String.IsNullOrEmpty(adresse.Rue2))
                    {
                        adresseToShow += adresse.Rue2 + "\n";
                    }
                    adresseToShow += adresse.Ville + "\n";
                    adresseToShow += adresse.CodePostal + "\n";
                    adresseToShow += adresse.Pays + "\n";

                    MessageBox.Show(adresseToShow, "Adresse de destination");
                }
                else if (e.ColumnIndex == 3)
                {
                    totalPriceHT = 0;
                    totalPriceTT = 0;
                    string      productToShow = "";
                    CommandeDto commande      = _commandesService.GetCommandes().Where(c => c.Id == livraison.Commande.Id).FirstOrDefault();
                    List <ProduitCommandeDto> produitCommande = _produitCommandeService.GetProduitCommandes().Where(pc => pc.Commande.Id == commande.Id).ToList();

                    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 if (e.ColumnIndex == 4)
                {
                    SalarieDto salarie       = _salariesService.GetSalaries().Where(s => s.Id == livraison.Salarie.Id).FirstOrDefault();
                    string     salarieToShow = "";
                    salarieToShow += salarie.Id + "\n";
                    salarieToShow += salarie.Nom + "\n";
                    salarieToShow += salarie.Prenom + "\n";
                    salarieToShow += salarie.Permis + "\n";
                    salarieToShow += salarie.Email + "\n";
                    salarieToShow += salarie.Telephone + "\n";


                    MessageBox.Show(salarieToShow, "Informations de " + salarie.Nom + " " + salarie.Prenom);
                }
                else if (e.ColumnIndex == 5)
                {
                    VehiculeDto vehicule       = _vehiculesService.GetVehicules().Where(v => v.Id == livraison.Vehicule.Id).FirstOrDefault();
                    string      vehiculeToShow = "";
                    vehiculeToShow += vehicule.Id + "\n";
                    vehiculeToShow += vehicule.Immatriculation + "\n";
                    vehiculeToShow += vehicule.CarteGrise + "\n";
                    vehiculeToShow += vehicule.Modele + "\n";
                    vehiculeToShow += vehicule.Marque + "\n";

                    MessageBox.Show(vehiculeToShow, "Informations du véhicule");
                }
                else
                {
                    if (livraison.DateLivraison == null)
                    {
                        buttonConfirmLivraison.Show();
                        selectedLivraisonId = id;
                    }
                    else
                    {
                        buttonConfirmLivraison.Hide();
                    }
                }
            }
        }
Exemplo n.º 9
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();
                    }
                }
            }
        }