private void LoadPurchaseStoreFields(PurchaseStore thePurchaseStore)
 {
     CategoryCBX.Text = thePurchaseStore.Product.SubCategory.Category.CategoryName;
     SubCategoryCBX.Text = thePurchaseStore.Product.SubCategory.SubCategoryName;
     ProductCbx.Text = thePurchaseStore.Product.ProductName;
     if (thePurchaseStore.PurchasePrice != null)
     {
         decimal purchasePrice = (decimal) thePurchaseStore.PurchasePrice;
         AchatPriceTxt.Text = purchasePrice.ToString("###,###.00");
     }
     if (thePurchaseStore.UnitsOnOrder != null)
     {
         decimal unitsOnOrder = (decimal) thePurchaseStore.UnitsOnOrder;
         UnitsOnOrderTxt.Text = unitsOnOrder.ToString("###,###.00");
     }
     if (thePurchaseStore.VentePriceGros != null)
     {
         decimal ventePrice = (decimal) thePurchaseStore.VentePriceGros;
         VentePriceCbx.Text = ventePrice.ToString("###,###.00");
     }
     if (thePurchaseStore.Discount != null)
     {
         decimal discount = (decimal) thePurchaseStore.Discount;
         DiscountTxt.Text = discount.ToString("###,###.00");
     }
     if (thePurchaseStore.TotalPriceAchat != null)
     {
         decimal totalPriceAchat = (decimal) thePurchaseStore.TotalPriceAchat;
         TotalPriceAchatTxt.Text = totalPriceAchat.ToString("###,###.00");
     }
 }
 private void Afficher(PurchaseStore purchaseDetails)
 {
     QuantiteSaleTxtBox.Text = purchaseDetails.UnitsOnOrder.ToString();
 }
        private void CreatePurchase(float getDicount, string etatPayement, string modePayement,
            string modeAchat, string commandNum, string factureNum, float facturePriceHt,
            string remarque, Provider provider, DateTime commandeDtae, float tvaValue)
        {
            try
            {
                var gestionDb = new GcdbEntities();
                Provider getProvider = gestionDb.Providers.FirstOrDefault(c => c.SupplierID == provider.SupplierID);
                if(getProvider==null)return;
                var newPurchase = new Purchase
                {
                    TvaValue = tvaValue,
                    FacturePrice = facturePriceHt,
                    PurchaseMontant = _total,
                    EtatPaiement = etatPayement,
                    ModePaiement = modePayement,
                    ModeAchat = modeAchat,
                    CommandeNum = commandNum,
                    FactureNum = factureNum,
                    PurchaseDate = AchatDateDte.DateTime.Date,
                    CommandeDate = commandeDtae,
                    Status = 0,
                    Provider = getProvider,
                    SupplierID = provider.SupplierID,
                    Description = remarque,
                    Discount = (float?) getDicount,
                    Timbre = (double?) _timbre
                };
                foreach (var entitys in _productsSelSelected)
                {
                    var getId = Getid(entitys, tvaValue);
                    Product getProduct = gestionDb.Products.FirstOrDefault(c => c.ProductID == entitys.ProductId);
                    if(getProduct==null)continue;
                    var nwStore = new PurchaseStore
                    {
                        Product = getProduct,
                        ProductID = entitys.ProductId,
                        PurchasePrice = entitys.PurchasePrice,
                        TotalPriceAchat = entitys.TotalPriceAchat,
                        UnitsOnOrder = (double?) entitys.UnitsOnOrder,
                        VentePriceGros = entitys.VentePriceGros,
                        VentePriceDetail = entitys.VentePriceDetail,
                        VentePriceComptoire = entitys.VentePriceComptoire,
                        Discount = entitys.Discount,
                        TvaValue = tvaValue,
                        StockStoreID = getId
                    };
                    newPurchase.PurchaseStores.Add(nwStore);
                }
                gestionDb.Purchases.Add(newPurchase);
                gestionDb.SaveChanges();
            }
            catch (Exception e)
            {

                MessageBox.Show(e.ToString());
            }
        }