예제 #1
0
        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();
                }
            }
        }
예제 #2
0
 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!!!");
     }
 }
예제 #3
0
        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");
            }
        }
예제 #4
0
        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");
            }
        }
예제 #5
0
        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();
                            }
                        }
                    }
                }
            }
        }