Exemplo n.º 1
0
        private void DEletebtn_OnClick(object sender, RoutedEventArgs e)
        {
            var custmer = InvoiceDg.SelectedItem as Customer;

            if (custmer == null)
            {
                return;
            }
            var result = MessageBox.Show("Est vous sûr de vouloir supprimer cet enregistrement", "Warning", MessageBoxButton.YesNo, MessageBoxImage.Warning);

            if (!result.ToString().Equals("Yes"))
            {
                return;
            }

            using (var db = new ObjectContext())
            {
                db.Delete(custmer);
                InvoiceDg.ItemsSource = db.Customers.ToList();
            }
        }
Exemplo n.º 2
0
        private void DEletebtn_OnClick(object sender, RoutedEventArgs e)
        {
            var stock = InvoiceDg.SelectedItem as Stock;

            if (stock == null)
            {
                return;
            }
            var result = MessageBox.Show("Est vous sûr de vouloir supprimer cet enregistrement!", "Warning", MessageBoxButton.YesNo, MessageBoxImage.Warning);

            if (!result.ToString().Equals("Yes"))
            {
                return;
            }

            using (var db = new ObjectContext())
            {
                db.Delete(stock);

                var product = db.Products.FirstOrDefault(x => x.Id == stock.Product_Id);
                if (product != null)
                {
                    if (product.Qnt >= stock.Qnt)
                    {
                        product.Qnt -= stock.Qnt;
                    }
                    else
                    {
                        product.Qnt = 0;
                    }
                    db.Update(product);
                }
                InvoiceDg.ItemsSource = db.Stocks.LoadWith(x => x.Product).LoadWith(x => x.Supplier)
                                        .ToList();
            }
        }