/// <summary>
        /// Sets a ship date and adjusts in stock quantity and sold quantities.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ProductShippedBtn_Click(object sender, EventArgs e)
        {
            Invoice invoice = (Invoice)invoiceCmbBox.SelectedItem;

            if (invoice != null)
            {
                invoice.ShipDate = DateTime.Now;
                ProductDb.Update(invoice);

                List <Product>          products  = ProductDb.GetInvoiceProducts(invoice.InvoiceID);
                List <InvoiceLineItems> lineItems = ProductDb.GetInvoiceQuantities(invoice.InvoiceID);

                for (int i = 0; i < products.Count; i++)
                {
                    products[i].OnHand -= lineItems[i].Quantity;
                    products[i].Sold   -= lineItems[i].Quantity;
                    ProductDb.Update(products[i]);
                }
                messageLbl.Text = $"Ship Date set to {DateTime.Now}";
            }
            else
            {
                MessageBox.Show("No invoice selected", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
Esempio n. 2
0
 /// <summary>
 /// Changes the number of units on hand.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void AddBtn_Click(object sender, EventArgs e)
 {
     if (Validator.IsShort(unitTxtBox.Text))
     {
         Product product = (Product)productListBox.SelectedItem;
         short   units   = Convert.ToInt16(unitTxtBox.Text);
         product.OnHand += units;
         ProductDb.Update(product);
         Close();
     }
     else
     {
         MessageBox.Show("Must put in a valid number", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
        /// <summary>
        /// Adds a product to an invoice.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void AddBtn_Click(object sender, EventArgs e)
        {
            Invoice invoice = (Invoice)invoiceCmbBox.SelectedItem;

            if (invoice != null)
            {
                Product product = (Product)productCmbBox.SelectedItem;
                if (product == null)
                {
                    MessageBox.Show("No product selected", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }

                InvoiceLineItems invoiceLineItems = new InvoiceLineItems();
                invoiceLineItems.ProductID = product.ProductID;
                invoiceLineItems.InvoiceID = invoice.InvoiceID;

                if (Validator.IsShort(quantityTxtBox.Text))
                {
                    short quantity = Convert.ToInt16(quantityTxtBox.Text);
                    invoiceLineItems.Quantity = quantity;

                    try
                    {
                        ProductDb.AddInvoiceLineItem(invoiceLineItems);
                        product.Sold += quantity;
                        ProductDb.Update(product);
                        quantityTxtBox.Text = String.Empty;
                        messageLbl.Text     = "Product added successfully";
                    }
                    catch (SqlException)
                    {
                        messageLbl.Text = "Failed to add product";
                    }
                }
            }
            else
            {
                MessageBox.Show("No invoice is selected", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
        /// <summary>
        /// The button that initiates consumption of products.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ConsumeBtn_Click(object sender, EventArgs e)
        {
            Product consumedProduct = (Product)consumeProductBox.SelectedItem;
            Product producedProduct = (Product)produceProductBox.SelectedItem;

            if (Validator.IsByte(consumeNumber.Text) && Validator.IsByte(produceUnits.Text))
            {
                byte numberToConsume = Convert.ToByte(consumeNumber.Text);
                byte numberToProduce = Convert.ToByte(produceUnits.Text);
                if (consumedProduct.OnHand < numberToConsume)
                {
                    MessageBox.Show("There is not enough units to consume");
                    return;
                }
                consumedProduct.OnHand -= numberToConsume;
                producedProduct.OnHand += numberToProduce;
                ProductDb.Update(consumedProduct);
                ProductDb.Update(producedProduct);
                Close();
            }
        }