Ejemplo n.º 1
0
 //
 // Remove Product from Form
 //
 public bool RemoveProduct(string ID)
 {
     if (ID != "" & ID != null)
     {
         List <Product> product = database.SelectProduct(ID);
         if (product.Count > 0)
         {
             database.Remove(product[0]);
             return(true);
         }
         else
         {
             return(false);
         }
     }
     else
     {
         return(false);
     }
 }
        //
        // Transfer Between Grids
        //

        // Transfer from Warehouse to Machine
        private void pictureBox2_Click(object sender, EventArgs e)
        {
            string quantityString = tbQuantityTransferToMachine.Text;
            string product        = tbProductTransferToMachine.Text;

            try
            {
                if (quantityString != "" & quantityString != null &
                    product != "" & product != null)
                {
                    int quantity = int.Parse(quantityString);
                    if (quantity > 0)
                    {
                        List <Product> stockList     = database.SelectProduct(product);
                        int            stockQuantity = stockList.Count;
                        if (quantity <= stockQuantity)
                        {
                            int machineMaxStock     = machine.MaxCapacity;
                            int machineCurrentStock = machine.products.Count;
                            int maxTransferCapacity = machineMaxStock - machineCurrentStock;
                            if (quantity <= maxTransferCapacity)
                            {
                                this.controller.TransferWarehouseToMachine(product, quantity, machine);
                                refreshPage();
                            }
                            else
                            {
                                MessageBox.Show("There is only enough room for " + Convert.ToString(maxTransferCapacity) + " in the machine. Adjusting Quantity.");
                                tbQuantityTransferToMachine.Text = Convert.ToString(maxTransferCapacity);
                            }
                        }
                        else
                        {
                            MessageBox.Show("There are only " + Convert.ToString(stockQuantity) + " in stock. Adjusting Quantity.");
                            tbQuantityTransferToMachine.Text = Convert.ToString(stockQuantity);
                        }
                    }
                    else
                    {
                        MessageBox.Show("Please enter a quantity greater than 0.");
                    }
                }
                else
                {
                    MessageBox.Show("Please select a product and enter a quantity.");
                }
            }
            catch (Exception exception)
            {
                MessageBox.Show("Invalid Entry - Please select a product and enter a quantity.\n" + exception.Message);
            }
        }