public void AddSupplyOffer(SupplyOffer supplyOffer)
 {
     using (SalesDB db = new SalesDB())
     {
         db.SuppliesOffers.Add(supplyOffer);
         db.SaveChanges();
     }
 }
 public void UpdateSupplyOffer(SupplyOffer supplyOffer)
 {
     using (SalesDB db = new SalesDB())
     {
         db.Entry(supplyOffer).State = EntityState.Modified;
         db.SaveChanges();
     }
 }
 public void DeleteSupplyOffer(SupplyOffer supplyOffer)
 {
     using (SalesDB db = new SalesDB())
     {
         db.SuppliesOffers.Attach(supplyOffer);
         db.SuppliesOffers.Remove(supplyOffer);
         db.SaveChanges();
     }
 }
        private void ExecuteSave()
        {
            Mouse.OverrideCursor = Cursors.Wait;
            DateTime _dt = DateTime.Now;

            _supplyOfferServ.AddSupplyOffer(_newSupplyOffer);
            int _supplyOfferID = _supplyOfferServ.GetLastSupplyOfferID();

            foreach (var item in _supplyOfferCategories)
            {
                SupplyOfferCategory _supplyOfferCategory = new SupplyOfferCategory
                {
                    CategoryID             = item.CategoryID,
                    Cost                   = item.Cost,
                    CostAfterDiscount      = item.CostAfterDiscount,
                    CostAfterTax           = item.CostAfterTax,
                    CostTotal              = item.CostTotal,
                    CostTotalAfterDiscount = item.CostTotalAfterDiscount,
                    CostTotalAfterTax      = item.CostTotalAfterTax,
                    Discount               = item.Discount,
                    DiscountValue          = item.DiscountValue,
                    DiscountValueTotal     = item.DiscountValueTotal,
                    SupplyOfferID          = _supplyOfferID,
                    Qty           = item.Qty,
                    Tax           = item.Tax,
                    TaxValue      = item.TaxValue,
                    TaxValueTotal = item.TaxValueTotal
                };
                _supplyOfferCategoryServ.AddSupplyOfferCategory(_supplyOfferCategory);
            }
            DS ds = new DS();

            ds.Sale.Rows.Clear();
            int i = 0;

            foreach (var item in _supplyOfferCategories)
            {
                ds.Sale.Rows.Add();
                ds.Sale[i]["Client"]     = _selectedClient.Name;
                ds.Sale[i]["Serial"]     = i + 1;
                ds.Sale[i]["Category"]   = item.Category + " " + item.Company;
                ds.Sale[i]["Qty"]        = item.Qty;
                ds.Sale[i]["Price"]      = Math.Round(Convert.ToDecimal(item.CostAfterTax), 2);
                ds.Sale[i]["TotalPrice"] = Math.Round(Convert.ToDecimal(item.CostTotalAfterTax), 2);
                ds.Sale[i]["BillPrice"]  = Math.Round(Convert.ToDecimal(_newSupplyOffer.CostAfterTax), 2);
                i++;
            }
            ReportWindow      rpt            = new ReportWindow();
            SupplyOfferReport supplyOfferRPT = new SupplyOfferReport();

            supplyOfferRPT.SetDataSource(ds.Tables["Sale"]);
            rpt.crv.ViewerCore.ReportSource = supplyOfferRPT;
            Mouse.OverrideCursor            = null;
            _currentWindow.Hide();
            rpt.ShowDialog();

            NewSupplyOffer         = new SupplyOffer();
            NewSupplyOfferCategory = new SupplyOfferCategoryVM();
            SupplyOfferCategories  = new ObservableCollection <SupplyOfferCategoryVM>();
            NewSupplyOffer.Date    = DateTime.Now;
            OldCosts = new ObservableCollection <SupplyCategory>();
            _currentWindow.ShowDialog();
        }