public bool GetUpdateProduct() { bool IsVaild = false; using (SimpleSaleDbContext _contex = new SimpleSaleDbContext()) { Product p = new Product(); string givenBarcode = txtGetBarcode.Text.ToString(); p = _contex.Products.FirstOrDefault(x => x.Barcode == givenBarcode); txtUpdateProductName.Text = p.ProductName.ToString(); txtUpdateProductDescription.Text = p.ProductDescription.ToString(); txtUpdateProductPurchasePrice.Text = p.PurchasePrice.ToString(); txtUpdateProductSellingPrice.Text = p.SellingPrice.ToString(); if (p != null) { IsVaild = true; return(IsVaild); } else { IsVaild = false; MessageBox.Show("Could Not Find Product To Update"); return(IsVaild); } } }
public void CreateNewProduct() { using (SimpleSaleDbContext _contex = new SimpleSaleDbContext()) { Product p = new Product(); p.ProductName = txtProductName.Text.ToString(); p.Barcode = txtBarcode.Text.ToString(); p.ProductDescription = txtProductDescription.Text.ToString(); p.PurchasePrice = Decimal.Parse(txtProductPurchasePrice.Text); p.SellingPrice = Decimal.Parse(txtProductSellingPrice.Text); //Checks for duplication using the products Barcode if (_contex.Products.ToList().Any(x => x.Barcode == p.Barcode)) { MessageBox.Show("Product Already Exsits in table products."); return; } else { _contex.Products.Add(p); _contex.SaveChanges(); MessageBox.Show("Product Successfully Added"); txtProductName.Clear(); txtBarcode.Clear(); txtProductDescription.Clear(); txtProductPurchasePrice.Clear(); txtProductSellingPrice.Clear(); PopulateDataGridWithProductsList(); } } }
public void CreateSaleItem() { using (SimpleSaleDbContext _context = new SimpleSaleDbContext()) { //Handles product Qty int quantity = 1; if (txtgetItemQuantity.Text != null && txtgetItemQuantity.Text != "") { quantity = int.Parse(txtgetItemQuantity.Text); } Product product = _context.Products .FirstOrDefault(x => x.Barcode == txtgetAddItemToCartBarcode.Text .ToString()); if (product == null) { MessageBox.Show("Please enter a valid product barcode", "Error - No Value", MessageBoxButton.OK, MessageBoxImage.Error); txtgetAddItemToCartBarcode.Focus(); } else { ValueAddedTax vat = _context.ValueAddedTaxes.FirstOrDefault(y => y.Id == 4); DiscountProduct discountOnProduct = _context.DiscountOnProducts.FirstOrDefault(z => z.ProductId == product.Id); Discount discount = new Discount(); if (discountOnProduct == null) { discount.DiscountName = "No Discount"; discount.DiscountValue = 0; } else { discount = _context.Discounts.FirstOrDefault(z => z.Id == discountOnProduct.DiscountId); } SaleItem saleItem = new SaleItem(); saleItem.ProductId = product.Id; saleItem.ValueAddedTaxId = vat.Id; saleItem.DiscountId = discount.Id; saleItem.Item = product.ProductName; saleItem.Barcode = product.Barcode; saleItem.Quantity = quantity; saleItem.UnitPrice = product.SellingPrice; saleItem.Discount = (saleItem.UnitPrice * saleItem.Quantity) * (discount.DiscountValue / 100); saleItem.PriceVat = saleItem.UnitPrice + (saleItem.UnitPrice * vat.VATValue / 100); saleItem.ItemsPrice = (saleItem.Quantity * saleItem.PriceVat) - saleItem.Discount; dgSaleItem.Items.Add(saleItem); saleItemsList.Add(saleItem); } } }
public void GetProductToDelete() { using (SimpleSaleDbContext _context = new SimpleSaleDbContext()) { var p = _context.Products .FirstOrDefault(x => x.Barcode == txtGetDeleteBarcode.Text.ToString()); lblDeleteInFoName.Text = p.ProductName.ToString(); lblDeleteInFoBarcode.Text = p.Barcode.ToString(); } }
public void DeleteProduct() { using (SimpleSaleDbContext _context = new SimpleSaleDbContext()) { var p = _context.Products.FirstOrDefault(x => x.Barcode == lblDeleteInFoBarcode.Text.ToString()); _context.Remove(p); _context.SaveChanges(); lblDeleteInFoBarcode.Text = ""; lblDeleteInFoName.Text = ""; txtGetDeleteBarcode.Clear(); MessageBox.Show("Product Successfully Deleted!!!"); } }
public void GetItems() { List <Product> products = new List <Product>(); using (SimpleSaleDbContext _context = new SimpleSaleDbContext()) { products = _context.Products.ToList(); } foreach (var p in products) { cbItems.Items.Add(p.Barcode + " " + p.ProductName + " " + string.Format("{0:c}", p.SellingPrice)); } }
public void AddNewDicount() { using (SimpleSaleDbContext _context = new SimpleSaleDbContext()) { Discount discount = new Discount(); discount.DiscountName = txtDiscountName.Text.ToString(); discount.DiscountValue = decimal.Parse(txtDicountValue.Text); _context.Discounts.Add(discount); txtDiscountName.Clear(); txtDicountValue.Clear(); MessageBox.Show("Discount Successfully Added To Table", "Discount"); } }
public void AddNewVat() { using (SimpleSaleDbContext _context = new SimpleSaleDbContext()) { ValueAddedTax vat = new ValueAddedTax(); vat.VATName = txtVatName.Text.ToString(); vat.VATValue = Convert.ToDecimal(txtVatValue.Text.ToString()); _context.ValueAddedTaxes.Add(vat); _context.SaveChanges(); txtVatName.Clear(); txtVatValue.Clear(); MessageBox.Show("VAT Successfully Added To Table", "VAT"); } }
public void PopulateDataGridWithProductsList() { using (SimpleSaleDbContext _context = new SimpleSaleDbContext()) { List <Product> products = new List <Product>(); products = _context.Products.ToList(); dgSearchedProducts.ItemsSource = products; dgSearchedProducts.Columns[0].Header = "Name"; dgSearchedProducts.Columns[1].Header = "Bar Code"; dgSearchedProducts.Columns[2].Header = "Description"; dgSearchedProducts.Columns[3].Header = "Purchase Price"; dgSearchedProducts.Columns[4].Header = "Selling Price"; dgSearchedProducts.Columns[5].Visibility = Visibility.Collapsed; dgSearchedProducts.Columns[6].Visibility = Visibility.Collapsed; dgSearchedProducts.Columns[7].Visibility = Visibility.Collapsed; dgSearchedProducts.Columns[8].Visibility = Visibility.Collapsed; dgSearchedProducts.Columns[9].Visibility = Visibility.Collapsed; } }
public void UpdateProduct() { using (SimpleSaleDbContext _context = new SimpleSaleDbContext()) { var p = _context.Products.FirstOrDefault(x => x.Barcode == txtGetBarcode.Text.ToString()); p.ProductName = txtUpdateProductName.Text.ToString(); p.Barcode = txtGetBarcode.Text.ToString(); p.ProductDescription = txtUpdateProductDescription.Text.ToString(); p.PurchasePrice = Decimal.Parse(txtUpdateProductPurchasePrice.Text.ToString()); p.SellingPrice = Decimal.Parse(txtUpdateProductSellingPrice.Text.ToString()); _context.SaveChanges(); txtUpdateProductName.Clear(); txtUpdateProductDescription.Clear(); txtUpdateProductPurchasePrice.Clear(); txtUpdateProductSellingPrice.Clear(); txtGetBarcode.Clear(); PopulateDataGridWithProductsList(); MessageBox.Show("Product Successfully Updated"); } }
public void SearchProducts() { using (SimpleSaleDbContext _context = new SimpleSaleDbContext()) { List <Product> products = new List <Product>(); string searchPhrase = sbSearchProduct.Text.ToString(); products = _context.Products.Where(x => x.ProductName.Contains(searchPhrase)).ToList(); dgSearchedProducts.ItemsSource = products; dgSearchedProducts.Columns[0].Header = "Name"; dgSearchedProducts.Columns[1].Header = "Bar Code"; dgSearchedProducts.Columns[2].Header = "Description"; dgSearchedProducts.Columns[3].Header = "Purchase Price"; dgSearchedProducts.Columns[4].Header = "Selling Price"; dgSearchedProducts.Columns[5].Visibility = Visibility.Collapsed; dgSearchedProducts.Columns[6].Visibility = Visibility.Collapsed; dgSearchedProducts.Columns[7].Visibility = Visibility.Collapsed; dgSearchedProducts.Columns[8].Visibility = Visibility.Collapsed; dgSearchedProducts.Columns[9].Visibility = Visibility.Collapsed; } }
public void CreateSale() { Sale newSale = new Sale(); newSale.SaleSubTotal = GetCartSubTotal(); newSale.SaleTotalTax = GetCartVatTotal(); newSale.SaleTotalTax = GetCartTotal(); if (newSale.SaleSubTotal < 0) { MessageBox.Show("Please provide a subtotal.", "Error - Invaild Value", MessageBoxButton.OK, MessageBoxImage.Error); } else if (newSale.SaleTotalTax < 0) { MessageBox.Show("Please provide a tax total.", "Error - Invaild Value", MessageBoxButton.OK, MessageBoxImage.Error); } else if (newSale.SaleTotal < 0) { MessageBox.Show("Please provide a total.", "Error - Invaild Value", MessageBoxButton.OK, MessageBoxImage.Error); } else { using (SimpleSaleDbContext _context = new SimpleSaleDbContext()) { _context.Sales.Add(newSale); _context.SaveChanges(); Sale sale = _context.Sales.OrderBy(p => p.DateCreated).LastOrDefault(); if (sale == null) { MessageBox.Show("Unable to find Sale.", "Error - Null Return"); return; } else { if (dgSaleItem.Items.Count <= 0) { MessageBox.Show("No items in cart, Please add items to cart", "Error - Empty Value", MessageBoxButton.OK, MessageBoxImage.Error); return; } else { foreach (SaleItem item in dgSaleItem.Items) { item.SaleId = sale.Id; _context.SalesItems.Add(item); _context.SaveChanges(); } Receipt newReceipt = new Receipt(); newReceipt.SaleId = sale.Id; newReceipt.AmountTendered = decimal.Parse(txtAmountTendred.Text.Remove(0, 1)); newReceipt.Change = CalculateChange(); if (CalculateChange() < 0) { MessageBox.Show("Amount tendred is below total amount, Please enter a amount greater than the total.", "Error - Amount Invalid", MessageBoxButton.OK, MessageBoxImage.Error); txtAmountTendred.Focus(); return; } else { _context.Receipts.Add(newReceipt); _context.SaveChanges(); dgSaleItem.Items.Clear(); lblDiscountTotal.Text = string.Empty; lblSubTotal.Text = string.Empty; lblTotalVat.Text = string.Empty; lblPriceTotalVat.Text = string.Empty; txtSaleGrandTotal.Clear(); txtAmountTendred.Clear(); } } } } } }