private void initCompo(Produit p)
 {
     InitializeComponent();
     tbLibelle.Text         = p.libelle;
     tb_Prix_Achat.Text     = p.prixAchat.ToString();
     tb_Prix_Vente.Text     = p.prixVente.ToString();
     tbDescription.Text     = p.description;
     tbQuantite.Enabled     = false;
     dateExpirePick.Enabled = false;
     try
     {
         pictureBox1.Image = p.img != null?Image.FromStream(new MemoryStream(p.img)) : Properties.Resources.loading_product;
     }
     catch (System.Exception exc)
     {
         MessageBox.Show("error! product has no img" + exc.Message);
     }
 }
        private void labelHiden_TextChanged(object sender, EventArgs e)
        {
            if (labelHiden.Text != "")
            {
                nbCommandes++;
                labelNbCommande.Text = nbCommandes + "";
                int idProduit        = int.Parse(labelHiden.Text.Split(' ')[0]);
                int quantiteDemander = int.Parse(labelHiden.Text.Split(' ')[1]);
                pictureBox.Image = Properties.Resources.closed_box;
                Produit p = produitVentes.Where(pa => pa.codeProduit == idProduit).FirstOrDefault <Produit>();
                if (p == null)
                {
                    return;
                }
                var dbase = new dbContext();
                ElementPagnierVentes elmnt = new ElementPagnierVentes();
                elmnt.Title       = p.libelle;
                elmnt.MaxQuantite = 10000;
                elmnt.Gain        = (p.prixVente - p.prixAchat) * quantiteDemander;
                elmnt.Id          = p.codeProduit;
                elmnt.Icon        = p.img != null?Image.FromStream(new MemoryStream(p.img)) : Properties.Resources.loading_product;

                elmnt.Description    = p.description;
                elmnt.Quantite       = quantiteDemander;
                elmnt.QuntiteProduit = quantiteDemander + "";
                elmnt.PrixUnit       = p.prixAchat;
                elmnt.PrixTotal      = p.prixAchat * quantiteDemander + "";
                foreach (Control item in flowLayoutPagnierProduitCommandes.Controls)
                {
                    ElementPagnierVentes epv = (ElementPagnierVentes)item;
                    if (epv.Id == elmnt.Id)
                    {
                        epv.Quantite         = quantiteDemander;
                        labelNbCommande.Text = --nbCommandes + "";
                        return;
                    }
                }
                flowLayoutPagnierProduitCommandes.Controls.Add(elmnt);
                labelHiden.Text = "";
            }
            labelHiden.Text = "";
        }
Example #3
0
        private void initCompo(Produit p, int nbProds)
        {
            InitializeComponent();
            lblnbProduits.Visible = !isDeatilleFournisseur;
            this.btnEdit.Visible  = isDeatilleFournisseur;
            this.lblProdName.Text = p.libelle;
            //  this.prodImg.Image = p.img != null ? Image.FromStream(new MemoryStream(p.img)) : Properties.Resources.loading_product;
            this.prodImg.Image = p.img != null?Image.FromStream(new MemoryStream(p.img)) : Properties.Resources.loading_product;

            this.lblProdDescri.Text = p.description;
            if (isDeatilleFournisseur)
            {
                this.lblprix.Text = p.prixAchat.ToString() + "dh";
            }
            else
            {
                this.lblprix.Text = p.prixVente.ToString() + "dh";
            }
            this.lblnbProduits.Text = "Stock: " + nbProds;//nbProds.ToString();
        }
Example #4
0
        private void listBoxItemProduct_TextChanged(object sender, EventArgs e)
        {
            if (listBoxItemProduct.Text != "")
            {
                var dbase = new dbContext();
                this.pictureBoxBasket.Image = Properties.Resources.cart__full;
                Produit p = produitVentes.Where(pa => pa.codeProduit == int.Parse(listBoxItemProduct.Text.Split(' ')[0])).ToList()[0];
                labelBasket.Text = ++nbProduitInBasket + "";
                var stock_produit_tables = dbase.Stock_Magazin.Where(s => s.Produit.libelle == p.libelle).ToList();
                int quantity             = 0;
                foreach (var elm in stock_produit_tables)
                {
                    quantity += elm.quantite;
                }
                ElementPagnierVentes elmnt = new ElementPagnierVentes();
                elmnt.Title       = p.libelle;
                elmnt.MaxQuantite = quantity;
                elmnt.Gain        = (p.prixVente - p.prixAchat) * int.Parse(listBoxItemProduct.Text.Split(' ')[1]);
                elmnt.Id          = p.codeProduit;
                elmnt.Icon        = p.img != null?Image.FromStream(new MemoryStream(p.img)) : Properties.Resources.loading_product;

                elmnt.Description    = p.description;
                elmnt.Quantite       = int.Parse(listBoxItemProduct.Text.Split(' ')[1]);
                elmnt.QuntiteProduit = listBoxItemProduct.Text.Split(' ')[1];
                elmnt.PrixUnit       = p.prixVente;
                elmnt.PrixTotal      = p.prixVente * int.Parse(listBoxItemProduct.Text.Split(' ')[1]) + "";
                foreach (Control item in flowLayoutPagnierProduitVentes.Controls)
                {
                    ElementPagnierVentes epv = (ElementPagnierVentes)item;
                    if (epv.Id == elmnt.Id)
                    {
                        epv.Quantite     = int.Parse(listBoxItemProduct.Text.Split(' ')[1]);
                        labelBasket.Text = --nbProduitInBasket + "";

                        return;
                    }
                }
                flowLayoutPagnierProduitVentes.Controls.Add(elmnt);
                listBoxItemProduct.Text = "";
            }
        }
        private void tbSearch_TextChanged(object sender, EventArgs e)
        {
            string    filterDeCherche = comboBoxFilterCommande.Text;
            string    serachText      = searchBar.Text.ToLower();
            dbContext db = new dbContext();

            if (this.isInListeCommande)
            {
                List <Commande> queryCommande = new List <Commande>();
                switch (filterDeCherche)
                {
                case "Ncommande":
                    queryCommande = db.Commandes.Where(n => n.NCommande.ToString().ToLower().Contains(serachText)).ToList();
                    break;

                case "Fournisseur":
                    Fournisseur fournisser = db.Fournisseurs.Where(f => f.nomFournisseur.ToString().ToLower().Contains(serachText) ||
                                                                   f.prenomFournisseur.ToString().ToLower().Contains(serachText)).FirstOrDefault <Fournisseur>();
                    if (fournisser == null)
                    {
                        break;
                    }
                    int idFournisseur = fournisser.idFournisseur;
                    queryCommande = db.Commandes.Where(n => n.idFournisseur == idFournisseur).ToList();
                    break;

                case "Produit":
                    queryCommande.Clear();
                    Produit produit = db.Produits.Where(f => f.libelle.ToString().ToLower().Contains(serachText)).FirstOrDefault <Produit>();
                    if (produit == null)
                    {
                        break;
                    }
                    int idProduit         = produit.codeProduit;
                    var produit_Commandes = db.Produit_commande
                                            .Where(n => n.codeProduit == idProduit)
                                            .GroupBy(g => g.NCommande);
                    foreach (var item in produit_Commandes)
                    {
                        queryCommande.Add(db.Commandes.Where(c => c.NCommande == item.Key).FirstOrDefault <Commande>());
                    }

                    break;

                default:
                    queryCommande = db.Commandes.Where(n => n.NCommande.ToString().ToLower().Contains(serachText)).ToList();
                    break;
                }
                if (serachText == "")
                {
                    queryCommande = db.Commandes.ToList();
                }
                refrechDataGrid(queryCommande);
            }
            else
            {
                string cle      = searchBar.Text.ToLower();
                var    dbase    = new dbContext();
                var    stock    = dbase.Stock_Magazin.ToList <Stock_Magazin>();
                int    quantity = 0;
                flowLayoutPanel1.Controls.Clear();
                foreach (var prod in produitVentes)
                {
                    if (prod.libelle.ToLower().IndexOf(cle.ToLower()) == -1)
                    {
                        continue;
                    }
                    quantity = stock.FindAll(s => s.codeProduit.Equals(prod.codeProduit)).Sum(stk => stk.quantite);
                    this.flowLayoutPanel1.Controls.Add(new produit_Vente(prod, quantity, true, flowLayoutPagnierProduitCommandes));
                }
            }
        }
 public produit_Vente(Produit p, FlowLayoutPanel flowLayout = null)
 {
     this.IdProduit = p.codeProduit;
     InitializeComp2(p);
 }
        private void Ajouter_Click(object sender, EventArgs e)
        {
            var db = new dbContext();

            if (tb_Prix_Achat.Text == "" || tb_Prix_Vente.Text == "" || tbLibelle.Text == "" || tbDescription.Text == "")
            {
                MessageBox.Show("Remplire tous les chapms", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            if (isDetailFournisseur)
            {
                Decimal prix_Achat, prix_Vente;
                try
                {
                    string[] pat = tb_Prix_Achat.Text.Split('.');
                    string[] pvt = tb_Prix_Vente.Text.Split('.');
                    string   pa  = tb_Prix_Achat.Text;
                    string   pv  = tb_Prix_Vente.Text;
                    if (tb_Prix_Achat.Text.Split('.').Length > 1)
                    {
                        pa = pa.Replace(".", ",").Trim();
                    }
                    if (tb_Prix_Vente.Text.Split('.').Length > 1)
                    {
                        pv = pv.Replace(".", ",").Trim();
                    }
                    prix_Achat = Convert.ToDecimal(pa);
                    prix_Vente = Convert.ToDecimal(pv);
                }
                catch (Exception)
                {
                    MessageBox.Show("Le prix doit être un nombre decimal", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }


                try
                {
                    Produit prod = db.Produits.Where(p => p.codeProduit == this.prod2Edit.codeProduit).FirstOrDefault <Produit>();
                    if (prod != null)
                    {
                        prod.idFournisseur = prod.Fournisseur.idFournisseur;
                        prod.libelle       = tbLibelle.Text;
                        prod.prixAchat     = prix_Achat;
                        prod.prixVente     = prix_Vente;
                        prod.description   = tbDescription.Text;
                        prod.img           = (byte[])(new ImageConverter()).ConvertTo(pictureBox1.Image, typeof(byte[]));
                    }
                    else
                    {
                        MessageBox.Show("Opération Non effectuer", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                    db.SaveChanges();
                    formParent2.remplireLayout(db);
                    this.Close();
                }
                catch (Exception exc)
                {
                    MessageBox.Show("Error! " + exc.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
        }
        private void Ajouter_Click(object sender, EventArgs e)
        {
            var     db = new dbContext();
            Decimal prix_Achat, prix_Vente;

            if (tb_Prix_Achat.Text == "" || tb_Prix_Vente.Text == "" || tbLibelle.Text == "" || tbDescription.Text == "")
            {
                MessageBox.Show("Remplire tous les chapms", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            try
            {
                string[] pat = tb_Prix_Achat.Text.Split('.');
                string[] pvt = tb_Prix_Vente.Text.Split('.');
                string   pa  = tb_Prix_Achat.Text;
                string   pv  = tb_Prix_Vente.Text;
                if (tb_Prix_Achat.Text.Split('.').Length > 1)
                {
                    pa = pa.Replace(".", ",").Trim();
                }
                if (tb_Prix_Vente.Text.Split('.').Length > 1)
                {
                    pv = pv.Replace(".", ",").Trim();
                }
                prix_Achat = Convert.ToDecimal(pa);
                prix_Vente = Convert.ToDecimal(pv);
            }
            catch (Exception)
            {
                MessageBox.Show("Le prix doit être un nombre decimal", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            int dv = 1;

            try
            {
                dv = Convert.ToInt32(textBoxDV.Text);
            }
            catch (Exception)
            {
                MessageBox.Show("Le duréé doit être un nombre un eniter", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            try
            {
                Produit prod = new Produit();
                if (prod != null)
                {
                    prod.idFournisseur      = idFournisseurAajouter;
                    prod.libelle            = tbLibelle.Text;
                    prod.prixAchat          = prix_Achat;
                    prod.prixVente          = prix_Vente;
                    prod.description        = tbDescription.Text;
                    prod.dureeValidite_jour = dv;
                    using (MemoryStream mStream = new MemoryStream())
                    {
                        if (pictureBox1.Image != null)
                        {
                            pictureBox1.Image.Save(mStream, pictureBox1.Image.RawFormat);
                            prod.img = mStream.ToArray();
                        }
                        else
                        {
                            prod.img = null;
                        }
                    }
                }
                else
                {
                    MessageBox.Show("Opération Non effectuer", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
                var fournisseur = db.Fournisseurs.Where(f => f.idFournisseur == idFournisseurAajouter).FirstOrDefault();
                Form1.SetMessageLog($"L'ajout d'un nouveau produit '{tbLibelle.Text}' au liste des produits du  fournisseur {fournisseur.nomFournisseur} {fournisseur.prenomFournisseur} ");
                db.Produits.Add(prod);
                db.SaveChanges();
                formParent2.remplireLayout(db);
                this.Close();
            }
            catch (Exception exc)
            {
                MessageBox.Show("Error! " + exc.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                throw exc;
            }
        }
Example #9
0
 public Form_Ajouter_Produit(Produit p, Form1 formParent)
 {
     prod2Edit       = p;
     this.formParent = formParent;
     initCompo(p);
 }
 public FormProdDescri(Produit p, Form1 formParent)
 {
     this.formParent  = formParent;
     this.currentProd = p;
     initCompo(p);
 }