/// <summary>
        /// Once product is selected, changes list of that products.
        /// In addition changes list of larger products being consumed.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ConsumeProductBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            Product        product  = (Product)consumeProductBox.SelectedItem;
            List <Product> products = ProductDb.GetProductsInRange(product.ProductID, product.Height, product.Width, product.Length);

            produceProductBox.DataSource = products.ToList();
        }
Beispiel #2
0
        /// <summary>
        /// Updates the invoice list.
        /// </summary>
        private void UpdateInvoiceList()
        {
            invoiceListBox.DataSource = null;
            List <Invoice> invoices = ProductDb.GetAllInvoices();

            invoiceListBox.DataSource = invoices.ToList();
        }
 /// <summary>
 /// Button to add a customer to the list and database.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void AddCustomerBtn_Click(object sender, EventArgs e)
 {
     if (Validator.IsPresent(firstNameTxtBox) && Validator.IsPresent(lastNameTxtBox) &&
         Validator.IsPresent(addressTxtBox) && Validator.IsPresent(cityTxtBox) &&
         Validator.IsPresent(stateTxtBox) && Validator.IsInt(zipCodeTxtBox.Text))
     {
         Customer customer = new Customer()
         {
             Business         = businessTxtBox.Text,
             ContactFirstName = firstNameTxtBox.Text,
             ContactLastName  = lastNameTxtBox.Text,
             Address          = addressTxtBox.Text,
             City             = cityTxtBox.Text,
             State            = stateTxtBox.Text,
             ZipCode          = Convert.ToInt32(zipCodeTxtBox.Text)
         };
         try
         {
             ProductDb.AddCustomer(customer);
             messageLbl.Text = $"{customer.ContactFirstName} {customer.ContactLastName} was added successfully.";
             ClearTxtBoxes();
         }
         catch (SqlException)
         {
             messageLbl.Text = "Failed to add customer.";
         }
     }
     else
     {
         MessageBox.Show("All fields are required except business.",
                         "Warning",
                         MessageBoxButtons.OK,
                         MessageBoxIcon.Warning);
     }
 }
Beispiel #4
0
        private void UpdateInventoryForm_Load(object sender, EventArgs e)
        {
            List <Product> products = ProductDb.GetAllProducts();

            productListBox.DataSource    = products;
            productListBox.DisplayMember = nameof(Product.ToString);
        }
        /// <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);
            }
        }
Beispiel #6
0
        /// <summary>
        /// Opens Microsoft Excel to view spreadsheet of the invoice.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ViewInvoiceBtn_Click(object sender, EventArgs e)
        {
            Invoice invoice = (Invoice)invoiceListBox.SelectedItem;

            if (invoice != null)
            {
                Customer                customer  = ProductDb.GetCustomer(invoice.Customers[0].CustomerID);
                List <Product>          products  = ProductDb.GetInvoiceProducts(invoice.InvoiceID);
                List <InvoiceLineItems> lineItems = ProductDb.GetInvoiceQuantities(invoice.InvoiceID);

                // Setting up the excel spreadsheet
                object Nothing = System.Reflection.Missing.Value;
                var    app     = new Microsoft.Office.Interop.Excel.Application();
                app.Visible = true;
                Workbook  workbook  = app.Workbooks.Add(Nothing);
                Worksheet worksheet = (Worksheet)workbook.Sheets[1];
                worksheet.Name = "Worksheet";

                // Formats the columns to be bold and font to 20
                worksheet.Cells[1, 1].EntireColumn.Font.Bold = true;
                worksheet.Cells[1, 1].EntireColumn.Font.Size = 20;
                worksheet.Cells[1, 2].EntireColumn.Font.Bold = true;
                worksheet.Cells[1, 2].EntireColumn.Font.Size = 20;
                worksheet.Cells[1, 3].EntireColumn.Font.Bold = true;
                worksheet.Cells[1, 3].EntireColumn.Font.Size = 20;

                // Fills in the cells with the invoice number and customer information
                worksheet.Cells[1, 1] = "Invoice number: " + invoice.InvoiceID;
                worksheet.Cells[3, 1] = customer.Business;
                worksheet.Cells[4, 1] = customer.ContactFirstName + " " + customer.ContactLastName;
                worksheet.Cells[5, 1] = customer.Address;
                worksheet.Cells[6, 1] = customer.City + ", " + customer.State + " " + customer.ZipCode;

                worksheet.Cells[7, 2] = "Product";
                worksheet.Cells[7, 3] = "Quantity";

                // Goes through a loop and fills in product information
                int count  = 8;
                int column = 2;
                for (int i = 0; i < products.Count; i++)
                {
                    worksheet.Cells[count, column]     = products[i].InvoiceDisplayString();
                    worksheet.Cells[count, column + 1] = lineItems[i].Quantity;
                    count++;
                }
                count++;

                worksheet.Cells[count, column]     = "Date Shipped:";
                worksheet.Cells[count + 1, column] = invoice.ShipDate;

                // Adjusts all the cells size to fit the text
                worksheet.Columns.AutoFit();
            }
            else
            {
                MessageBox.Show("There are no invoices to display", "Warning!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
Beispiel #7
0
        /// <summary>
        /// Updates the product list.
        /// </summary>
        private void UpdateList()
        {
            productListBox.DataSource = null;
            productListBox.Items.Clear();
            List <Product>        products         = ProductDb.GetAllProducts();
            IEnumerable <Product> distinctProducts = products.Distinct <Product>();

            productListBox.DataSource = distinctProducts.ToList();
        }
        private void UpdateInvoiceForm_Load(object sender, EventArgs e)
        {
            List <Invoice> invoices = ProductDb.GetAllInvoices();

            invoiceCmbBox.DataSource = invoices.ToList();

            List <Product> products = ProductDb.GetAllProducts();

            productCmbBox.DataSource = products.ToList();
        }
Beispiel #9
0
        /// <summary>
        /// Loads main form.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Form1_Load(object sender, EventArgs e)
        {
            List <Product>        products         = ProductDb.GetAllProducts();
            IEnumerable <Product> distinctProducts = products.Distinct <Product>();

            productListBox.DataSource = distinctProducts.ToList();

            List <Invoice> invoices = ProductDb.GetAllInvoices();

            invoiceListBox.DataSource = invoices.ToList();
        }
Beispiel #10
0
        /// <summary>
        /// Deletes Product from Database.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void DeleteBtn_Click(object sender, EventArgs e)
        {
            Product product = (Product)productListBox.SelectedItem;

            if (product != null)
            {
                ProductDb.Delete(product.ProductID);
                UpdateList();
            }
            else
            {
                MessageBox.Show("There are no products to delete", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Beispiel #11
0
        /// <summary>
        /// Launches the Consume Product form.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ConsumeBtn_Click(object sender, EventArgs e)
        {
            List <Product> product = ProductDb.GetAllProducts();

            if (product.Any())
            {
                ConsumeUnitsForm consumeUnits = new ConsumeUnitsForm();
                consumeUnits.ShowDialog();
                UpdateList();
            }
            else
            {
                MessageBox.Show("There are no products in the database", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Beispiel #12
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();
            }
        }
 /// <summary>
 /// Adds a product with the category White Wood.
 /// </summary>
 /// <param name="product"></param>
 private void AddProductToDatabase(Product product)
 {
     try
     {
         product.Category.Add(ProductDb.GetCategory(WhiteWood));
         if (!ProductDb.CheckForExistingProduct(product))
         {
             ProductDb.Add(product);
             ClearTxtBoxesAndCheckBoxes();
             messageLbl.Text = $"{product.Height} x {product.Width} x {product.Length} added successfully";
         }
         else
         {
             messageLbl.Text = "Product already exists in database";
         }
     }
     catch (SqlException)
     {
         messageLbl.Text = "Failed to add Product";
     }
 }
 /// <summary>
 /// Adds a product with multiple categories.
 /// </summary>
 /// <param name="p"></param>
 /// <param name="treatmentLevel"></param>
 /// <param name="treatmentType"></param>
 private void AddProductToDatabase(Product p, int treatmentLevel, int treatmentType)
 {
     try
     {
         p.Category.Add(ProductDb.GetCategory(treatmentLevel));
         p.Category.Add(ProductDb.GetCategory(treatmentType));
         if (!ProductDb.CheckForExistingProduct(p))
         {
             ProductDb.Add(p);
             ClearTxtBoxesAndCheckBoxes();
             messageLbl.Text = $"{p.Height} x {p.Width} x {p.Length} added successfully";
         }
         else
         {
             messageLbl.Text = "Product already exists in database";
         }
     }
     catch (SqlException)
     {
         messageLbl.Text = "Failed to add Product";
     }
 }
Beispiel #17
0
        /// <summary>
        /// Button to create an Invoice.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void CreateInvoiceBtn_Click(object sender, EventArgs e)
        {
            Customer customer = (Customer)customerComboBox1.SelectedItem;

            if (customer != null)
            {
                Invoice invoice = new Invoice();
                invoice.Customers.Add(customer);
                try
                {
                    ProductDb.Add(invoice);
                    messageLbl.Text = "Invoice Created";
                }
                catch (SqlException)
                {
                    messageLbl.Text = "Failed to create invoice";
                }
            }
            else
            {
                MessageBox.Show("No customer selected", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
Beispiel #18
0
        private void CreateInvoiceForm_Load(object sender, EventArgs e)
        {
            List <Customer> customers = ProductDb.GetAllCustomers();

            customerComboBox1.DataSource = customers.ToList();
        }
        private void ConsumeUnitsForm_Load(object sender, EventArgs e)
        {
            List <Product> products = ProductDb.GetAllProducts();

            consumeProductBox.DataSource = products;
        }