private void DgButton_Delete(object sender, RoutedEventArgs e)
        {
            try
            {
                viewProductDetail row = (viewProductDetail)dgStockAdjustment.SelectedItem;

                if (row == null)
                {
                    return;
                }
                if (MessageBox.Show(String.Format("Delete '{0}' ?", row.ProductName), "Confirm delete", MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.Yes) == MessageBoxResult.No)
                {
                    return;
                }

                db.StockItems.Remove(db.StockItems.Where(x => x.Id == row.StockItemId).Single());
                db.SaveChanges();
                this.RefreshDataGrid();
            }
            catch (Exception ex)
            {
                string asd = ex.Message;
                MessageBox.Show("Please select valid row \n" + asd, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
        private void Add(viewProductDetail Sender, SoldItem Receiver)
        {
            // one row will be added in the Sold Items Table and the transferred product will be decreased
            Receiver.ProductName   = Sender.ProductName;
            Receiver.Strength      = Sender.Strength;
            Receiver.GenericName   = Sender.GenericName;
            Receiver.Quantity      = int.Parse(txtQuantity.Text);
            Receiver.PackSize      = Sender.PackSize;
            Receiver.QtyPackSize   = Sender.QtyPackSize;
            Receiver.ReorderLevel  = Sender.ReorderLevel;
            Receiver.BatchNo       = Sender.BatchNo;
            Receiver.ExpiryDate    = Sender.ExpiryDate;
            Receiver.DateSold      = dpDateSold.SelectedDate == null ? DateTime.Today : dpDateSold.SelectedDate;
            Receiver.Location      = Sender.Location;
            Receiver.MajorSupplier = Sender.MajorSupplier;
            Receiver.Origin        = Sender.Origin;
            Receiver.CostPerUnit   = Sender.CostPerUnit;
            Receiver.TotalCost     = Receiver.Quantity * Receiver.QtyPackSize * Receiver.CostPerUnit;

            Sender.Quantity  = Sender.Quantity - int.Parse(txtQuantity.Text);
            Sender.TotalCost = Sender.Quantity * Sender.QtyPackSize * Sender.CostPerUnit;
            db.SaveChanges();

            db.SoldItems.Add(Receiver);
            db.SaveChanges();
        }
        private void Update(StockItem temp, StockItem Receiver)
        {
            // Both entities will be updated one will be increased other would be decreased
            temp.Quantity  = temp.Quantity - int.Parse(txtQuantity.Text);
            temp.TotalCost = temp.Quantity * temp.CostPerUnit;

            Receiver.Quantity  = Receiver.Quantity + int.Parse(txtQuantity.Text);
            Receiver.TotalCost = Receiver.Quantity * Receiver.QtyPackSize * Receiver.CostPerUnit;
            db.SaveChanges();
        }
        private void btnAdd_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                Invoice invoice = new Invoice();
                invoice.TimeStamp = DateTime.Now;
                Decimal TotalTax      = 0;
                Decimal TotalDiscount = 0;
                Decimal TotalPrice    = 0;
                foreach (InvoiceItem i in invoiceList)
                {
                    TotalTax      = TotalTax + Convert.ToDecimal(i.Tax);
                    TotalPrice    = TotalPrice + Convert.ToDecimal(i.SellingPrice);
                    TotalDiscount = TotalDiscount + Convert.ToDecimal(i.Discount);
                }
                invoice.TotalDiscount = TotalDiscount;
                invoice.TotalTax      = TotalTax;
                invoice.TotalAmount   = TotalPrice;
                db.Invoices.Add(invoice);
                db.SaveChanges();

                foreach (InvoiceItem i in invoiceList)
                {
                    i.InvoiceId = invoice.Id;
                    StockItem updateStockItemQty = db.StockItems.Where(x => x.Id == i.StockItemId).Single();
                    if (updateStockItemQty != null)
                    {
                        updateStockItemQty.Quantity = updateStockItemQty.Quantity - i.Qty;
                        db.SaveChanges();
                    }

                    db.InvoiceItems.Add(i);
                }
                db.SaveChanges();
                dgInvoice.ItemsSource = null;
                invoiceList           = null;
                viewInvoiceList       = null;
                btnDone.Visibility    = Visibility.Visible;
                txtProductName.Focus();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        private void btnDelete_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                tblBankAccount row = (tblBankAccount)dgAccounts.SelectedItem;

                if (row == null || row.Id < 1)
                {
                    return;
                }
                if (MessageBox.Show(String.Format("Delete '{0}' ?", row.AccountTitle), "Confirm delete", MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.Yes) == MessageBoxResult.No)
                {
                    return;
                }
                db.tblBankAccounts.Remove(row);
                db.SaveChanges();
                this.RefreshDataGrid();
            }
            catch
            {
            }
        }
        private void btnDelete_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                Supplier row = (Supplier)dgSupplier.SelectedItem;

                if (row == null || row.Id < 1)
                {
                    return;
                }
                if (MessageBox.Show(String.Format("Delete '{0}' ?", row.SupplierName), "Confirm delete", MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.Yes) == MessageBoxResult.No)
                {
                    return;
                }
                db.Suppliers.Remove(row);
                db.SaveChanges();
                this.RefreshDataGrid();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemple #7
0
        private void DgButton_Delete(object sender, RoutedEventArgs e)
        {
            try
            {
                Product row = (Product)dgRegister.SelectedItem;

                if (row == null || row.Id < 1)
                {
                    return;
                }
                if (MessageBox.Show(String.Format("Delete '{0}' ?", row.ProductName), "Confirm delete", MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.Yes) == MessageBoxResult.No)
                {
                    return;
                }
                db.Products.Remove(row);
                db.SaveChanges();
                this.RefreshDataGrid();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Please select valid row.\n" + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
        private void btnAdd_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                Stock stock = new Stock();
                stock.Timestamp = DateTime.Now;
                decimal grandTotal = 0;
                foreach (StockItem s in stockList)
                {
                    grandTotal = grandTotal + Convert.ToDecimal(s.TotalCost);
                }
                stock.GrandTotal = grandTotal;
                db.Stocks.Add(stock);
                db.SaveChanges();

                foreach (StockItem s in stockList)
                {
                    s.StockId = stock.Id;
                    StockItem stockItem = db.StockItems.Where(x => x.ProductId == s.ProductId && x.WarehouseNo == s.WarehouseNo).Single();
                    if (stockItem != null)
                    {
                        // Stock already exist, Update operation
                        stockItem.Quantity      = stockItem.Quantity + s.Quantity;
                        stockItem.TotalCost     = stockItem.TotalCost + s.TotalCost;
                        stockItem.Strength      = s.Strength;
                        stockItem.PackSize      = s.PackSize;
                        stockItem.QtyPackSize   = s.QtyPackSize;
                        stockItem.ReorderLevel  = s.ReorderLevel;
                        stockItem.BatchNo       = s.BatchNo;
                        stockItem.ExpiryDate    = s.ExpiryDate;
                        stockItem.Location      = s.Location;
                        stockItem.MajorSupplier = s.MajorSupplier;
                        stockItem.CostPerUnit   = s.CostPerUnit;
                    }
                    else
                    {
                        // Not Matched, Insert Operation
                        db.StockItems.Add(s);
                    }
                    db.SaveChanges();
                }

                List <StockItemsForReporting> stockItemsforReporting = new List <StockItemsForReporting>();
                foreach (StockItem si in stockList)
                {
                    StockItemsForReporting stockItemforReporting = new StockItemsForReporting();
                    stockItemforReporting.StockId = stock.Id;

                    stockItemforReporting.ProductId     = si.ProductId;
                    stockItemforReporting.Strength      = si.Strength;
                    stockItemforReporting.Quantity      = si.Quantity;
                    stockItemforReporting.PackSize      = si.PackSize;
                    stockItemforReporting.QtyPackSize   = si.QtyPackSize;
                    stockItemforReporting.ReorderLevel  = si.ReorderLevel;
                    stockItemforReporting.BatchNo       = si.BatchNo;
                    stockItemforReporting.ExpiryDate    = si.ExpiryDate;
                    stockItemforReporting.Location      = si.Location;
                    stockItemforReporting.MajorSupplier = si.MajorSupplier;
                    stockItemforReporting.CostPerUnit   = si.CostPerUnit;
                    stockItemforReporting.TotalCost     = si.TotalCost;
                    stockItemforReporting.WarehouseNo   = si.WarehouseNo;

                    stockItemsforReporting.Add(stockItemforReporting);
                }

                db.StockItemsForReportings.AddRange(stockItemsforReporting);
                db.SaveChanges();

                dgStockIn.ItemsSource = null;
                stockList             = null;
                viewStockList         = null;
                btnDone.Visibility    = Visibility.Visible;
                txtProductName.Focus();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + "\n" + ex.InnerException);
            }
        }