Пример #1
0
        private void DgButton_Delete(object sender, RoutedEventArgs e)
        {
            try
            {
                viewProductDetail row = (viewProductDetail)dgStockIn.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;
                }

                viewStockList.Remove(row);
                stockList.Remove(stockList.Where(x => x.ProductId == row.ProductId).Single());
                if (stockList.Count == 0)
                {
                    btnAdd.Visibility = Visibility.Hidden;
                }
            }
            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 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 btnTransfer_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (EditId == -1)
                {
                    MessageBox.Show("Please Select a row first.", "Error", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                    return;
                }
                SoldItem          Receiver = new SoldItem();
                viewProductDetail Sender   = new viewProductDetail();

                Sender = GetStockItems()[EditId];

                if (int.Parse(txtQuantity.Text) > Sender.Quantity)
                {
                    MessageBox.Show("Mentioned Quantity is more than the total quantity.", "Error", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                    return;
                }

                this.Add(Sender, Receiver);

                this.RefreshDataGrid();
                this.ClearFields();
                btnSold.Visibility = Visibility.Visible;
            }
            catch (Exception ex) { MessageBox.Show(ex.Message + "\n" + ex.StackTrace); }
        }
Пример #5
0
        private void PopulateTxtBoxes(viewProductDetail product)
        {
            if (product != null)
            {
                txtProductName.Text       = product.ProductName;
                txtGenericName.Text       = product.GenericName;
                txtOrigin.Text            = product.Origin;
                txtAvailableQuantity.Text = Convert.ToString(product.Quantity);

                // lblCurrentQty.Content = "Current Qty: " + temp.Quantity.ToString();
                txtQuantity.Focus();
                btnDone.Visibility = Visibility.Hidden;
            }
        }
Пример #6
0
 private void btnSearchStockItem_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         StockItemsInvoiceDialog dlg = new StockItemsInvoiceDialog();
         dlg.ShowDialog();
         tempstockItem = dlg.temp;
         PopulateTxtBoxes(tempstockItem);
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
 private void dgStockItems_PreviewKeyDown(object sender, KeyEventArgs e)
 {
     if (e.Key == Key.Enter)
     {
         e.Handled = true;
         temp      = dgStockItems.SelectedItem as viewProductDetail;
         if (temp != null)
         {
             this.Close();
         }
         else
         {
             MessageBox.Show("No Product Selected", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
         }
     }
 }
        private void DgButton_Update(object sender, RoutedEventArgs e)
        {
            rowToUpdate = null;
            rowToUpdate = dgStockAdjustment.SelectedItem as viewProductDetail;

            txtProductName.Text   = rowToUpdate.ProductName;
            txtGenericName.Text   = rowToUpdate.GenericName;
            txtOrigin.Text        = rowToUpdate.Origin;
            txtStrength.Text      = rowToUpdate.Strength;
            txtQuantity.Text      = rowToUpdate.Quantity.ToString();
            txtPackSize.Text      = rowToUpdate.PackSize;
            txtQtyPackSize.Text   = rowToUpdate.QtyPackSize.ToString();
            txtReorderLevel.Text  = rowToUpdate.ReorderLevel.ToString();
            txtBatchNo.Text       = rowToUpdate.BatchNo;
            dpExpiryDate.Text     = rowToUpdate.ExpiryDate.ToString();
            txtLocation.Text      = rowToUpdate.Location;
            txtMajorSupplier.Text = rowToUpdate.MajorSupplier;
            txtCostPerUnit.Text   = rowToUpdate.CostPerUnit.ToString();
            cmbWarehouseNo.Text   = rowToUpdate.WarehouseNo.ToString();
        }
Пример #9
0
        private void btnTransfer_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (EditId == -1)
                {
                    MessageBox.Show("Please Select a row first.", "Error", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                    return;
                }
                if (txtFromWarehouse.Text == cmbWarehouseNo2.Text)
                {
                    MessageBox.Show("Warehouses cannot be same.", "Error", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                    return;
                }

                temp = GetStockItems()[EditId];

                if (int.Parse(txtQuantity.Text) > temp.Quantity)
                {
                    MessageBox.Show("Mentioned Quantity is more than the total quantity.", "Error", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                    return;
                }
                viewProductDetail Receiver = new viewProductDetail();
                if (GetStockItems().Where(x => x.WarehouseNo == int.Parse(cmbWarehouseNo2.Text) && x.ProductId == temp.ProductId).Count() > 0)
                {
                    Receiver = GetStockItems().Where(x => x.WarehouseNo == int.Parse(cmbWarehouseNo2.Text) && x.ProductName == temp.ProductName).FirstOrDefault();
                    // Product exists in the other warehouse therefore update operation
                    this.Update(db.StockItems.Where(x => x.Id == temp.StockItemId).SingleOrDefault(), db.StockItems.Where(x => x.Id == Receiver.StockItemId).SingleOrDefault());
                }
                else
                {
                    //Add Operation in the other warehouse
                    Receiver = temp;
                    this.Add(db.StockItems.Where(x => x.Id == temp.StockItemId).SingleOrDefault(), db.StockItems.Where(x => x.Id == Receiver.StockItemId).SingleOrDefault());
                }
                this.RefreshDataGrid();
                this.ClearFields();
                btnDone.Visibility = Visibility.Visible;
            }
            catch (Exception ex) { MessageBox.Show(ex.Message + "\n" + ex.StackTrace); }
        }
Пример #10
0
        private void btnAddToStockList_Click(object sender, RoutedEventArgs e)
        {
            if (txtProductName.Text.Length < 1)
            {
                MessageBox.Show("Please select a product.", "Incomplete Entry", MessageBoxButton.OK, MessageBoxImage.Information);
                return;
            }
            if (txtQuantity.Text.Length < 1)
            {
                MessageBox.Show("Please Enter the required field 'Quantity'", "Incomplete Entry", MessageBoxButton.OK, MessageBoxImage.Information);
                return;
            }
            if (txtCostPerUnit.Text.Length < 1)
            {
                MessageBox.Show("Please Enter the required field 'CostPerUnit'", "Incomplete Entry", MessageBoxButton.OK, MessageBoxImage.Information);
                return;
            }
            if (cmbWarehouseNo.Text.Length < 1)
            {
                MessageBox.Show("Please Enter the required field 'Warehouse No.'", "Incomplete Entry", MessageBoxButton.OK, MessageBoxImage.Information);
                return;
            }


            viewProductDetail temp = new viewProductDetail();

            temp.ProductId     = product.Id;
            temp.ProductName   = product.ProductName;
            temp.GenericName   = product.GenericName;
            temp.Origin        = product.Origin;
            temp.Strength      = txtStrength.Text.Length < 1 ? "" : txtStrength.Text;
            temp.Quantity      = int.Parse(txtQuantity.Text); // required
            temp.PackSize      = txtPackSize.Text.Length < 1 ? "" : txtPackSize.Text;
            temp.QtyPackSize   = txtQtyPackSize.Text.Length < 1 ? 0 : int.Parse(txtQtyPackSize.Text);
            temp.ReorderLevel  = txtReorderLevel.Text.Length < 1 ? 0 : int.Parse(txtReorderLevel.Text);
            temp.BatchNo       = txtBatchNo.Text.Length < 1 ? "" : txtBatchNo.Text;
            temp.ExpiryDate    = dpExpiryDate.SelectedDate;
            temp.Location      = txtLocation.Text.Length < 1 ? "" : txtLocation.Text;
            temp.MajorSupplier = txtMajorSupplier.Text.Length < 1 ? "" : txtMajorSupplier.Text;
            temp.CostPerUnit   = decimal.Parse(txtCostPerUnit.Text); // required
            temp.TotalCost     = (Convert.ToDecimal(temp.Quantity)) * (Convert.ToDecimal(temp.QtyPackSize)) * temp.CostPerUnit;
            temp.WarehouseNo   = int.Parse(cmbWarehouseNo.Text);     // required

            //Give warning if product already exist in stock
            StockItem checkStockItem = db.StockItems.Where(x => x.ProductId == temp.ProductId && x.WarehouseNo == temp.WarehouseNo).Single();

            if (checkStockItem != null && checkStockItem.Quantity > 0)
            {
                if (MessageBox.Show(String.Format("'{0}' already exists in Stock and has Quantity '{1}'. If you continue this quantity will be added in the new quantity. Would you like to continue?", temp.ProductName, checkStockItem.Quantity), "Confirm Update", MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.Yes) == MessageBoxResult.No)
                {
                    return;
                }
            }

            StockItem stockItem = new StockItem();

            stockItem.ProductId     = temp.ProductId;
            stockItem.Strength      = temp.Strength;
            stockItem.Quantity      = Convert.ToInt32(temp.Quantity);
            stockItem.PackSize      = temp.PackSize;
            stockItem.QtyPackSize   = temp.QtyPackSize;
            stockItem.ReorderLevel  = temp.ReorderLevel;
            stockItem.BatchNo       = temp.BatchNo;
            stockItem.ExpiryDate    = temp.ExpiryDate;
            stockItem.Location      = temp.Location;
            stockItem.MajorSupplier = temp.MajorSupplier;
            stockItem.CostPerUnit   = temp.CostPerUnit;
            stockItem.TotalCost     = temp.TotalCost;
            stockItem.WarehouseNo   = Convert.ToInt32(temp.WarehouseNo);

            viewStockList.Add(temp);
            stockList.Add(stockItem);
            AddToDataGrid();
            ClearFields();
            btnAdd.Visibility  = Visibility.Visible;
            btnDone.Visibility = Visibility.Hidden;
        }