예제 #1
0
        public String AddOrder(Order order)
        {
            _gestionDb = new GcdbEntities();
            if (IsOrderExist(order)) return "Ordre existe déjà";

            _gestionDb.Orders.Add(order);
            _gestionDb.SaveChanges();

            return "Order ajouter avec succes";
        }
예제 #2
0
        public int GetLastOrder(Order ordre)
        {
            try
            {
                _gestionDb = new GcdbEntities();
                return _gestionDb.Orders.ToList().Last().OrderID;
            }
            catch (Exception)
            {

                return -1;
            }
        }
        public List<OrderDetail> GetOrderDetailsByOrder(Order ordre)
        {
            try
            {
                _gestionDb = new GcdbEntities();
                return _gestionDb.OrderDetails.Where(od => (od.OrderID == ordre.OrderID)).ToList();
            }
            catch (Exception)
            {

                return null;
            }
        }
        public Facture GetFactureByOrdre(Order ordre)
        {
            try
            {
                _gestionDb = new GcdbEntities();

                return _gestionDb.Factures.First(fact => fact.OrdresID == ordre.OrderID);
            }
            catch (Exception)
            {
                return null;
            }
        }
        private void Calculate(Order ordre)
        {
            _total = 0;
            _ttc = 0;
            _discount = 0;
            _tva = 0;
            var orderDetailsClient = new OrderDetailsClient();
            var lisstOrderDetailses = orderDetailsClient.GetOrderDetailsByOrder(ordre);
            foreach (OrderDetail entity in lisstOrderDetailses)
            {
                _total += entity.UnitPrice * entity.Quantity;// a refaire en cas de comande distribuée
            }
            _tva = GetTva();
            _discount = getDiscount() * _total;

            _timbre = _total / 100;
            if (_timbre > 2500) _timbre = 2500;
            if (!CbPayment.Text.Equals("Espèce")) _timbre = 0;

            _ttc = _total - _discount + (_total * _tva) + _timbre;
        }
예제 #6
0
        private static bool IsOrderExist(Order order)
        {
            try
            {

                GcdbEntities gestionDb = new GcdbEntities();

                var requete = from t in gestionDb.Orders
                              where t.OrderID.Equals(order.OrderID)
                              select t;

                 return requete.Any();
            }
            catch (Exception)
            {
                return false;
            }
        }
예제 #7
0
        public Double GetTotalOrders(Order ordre)
        {
            try
            {
                _gestionDb = new GcdbEntities();

                var list = from od in _gestionDb.OrderDetails
                           where (ordre.OrderID == od.OrderID)
                           select od;
                Double somme = 0;

                foreach (OrderDetail od in list) somme += (Double)od.UnitPrice * od.Quantity;

                return somme;
            }
            catch (Exception)
            {
                return 0;
            }
        }
 private Order GetTheOrder(Order thisOrder)
 {
     try
     {
         return gestionDb.Orders.FirstOrDefault(c => c.OrderID == thisOrder.OrderID);
     }
     catch (Exception)
     {
         return null;
     }
 }
        private void CreateVente(List<ProduitsSel> productSelSelected, string remarque, Customer customer, DateTime dateTime, decimal tvaValue, Employee newEmployee)
        {
            try
            {

                Customer getCustomer = gestionDb.Customers.FirstOrDefault(c => c.CustomerID==customer.CustomerID);
                if(getCustomer!=null)
                {
                    Order newOrder = new Order
                    {
                        OrderDate = dateTime,
                        CommandeDate = dateTime,
                        CustomerID = getCustomer.CustomerID,
                        Customer = getCustomer,
                        TvaValue = tvaValue,
                        Description = remarque,
                        Status = 0,
                    };
                    foreach (var entity in productSelSelected)
                    {
                        OrderDetail newOrderDetail = new OrderDetail
                        {

                            ProductID = entity.TheProduct.ProductID,
                            Quantity = (int) entity.UnitsOnOrder,
                            UnitPrice = entity.UnitePrice,
                            TotalPrice = entity.TotalPrice,
                        };
                        newOrder.OrderDetails.Add(newOrderDetail);
                    }
                    gestionDb.Orders.Add(newOrder);
                    gestionDb.SaveChanges();
                    theOrder= newOrder;
                }
                else theOrder = null;
            }
            catch (Exception exe)
            {
                MessageBox.Show(exe.ToString());
                theOrder= null;
            }
        }