/// <summary>
        /// Button to remove an item from the inventory
        /// </summary>
        private void btnRemoveItem_Click(object sender, EventArgs e)
        {
            // if there is no item selected
            if (lvInventory.SelectedIndices == null || lvInventory.SelectedIndices.Count == 0)
            {
                // Let the user know they need to select an item
                MessageBox.Show(this, "No item selected. Please select and item from list to remove it from inventory.");
            }
            else
            {
                // Ask the user if htey are sure they want to permanently remove the item
                DialogResult result = MessageBox.Show(this, "Are you sure you want to permanently remove the selected item?", "Warning", MessageBoxButtons.YesNo);

                // If the user reports 'yes'...
                if (result == DialogResult.Yes)
                {
                    // Get the SKU number from the list
                    long.TryParse(lvInventory.SelectedItems[0].SubItems[2].ToString().Substring(
                                      18, lvInventory.SelectedItems[0].SubItems[2].ToString().Length - 19), out long sku);

                    // Remove the item from the inventory
                    inventory.RemoveItem(inventory.IndexOf(sku));

                    // Refresh the list
                    FillList(inventory);
                }
                else
                {
                    // Otherwise, let the user no item has been removed
                    MessageBox.Show(this, "No item removed.");
                }
            }
        }
        /// <summary>
        /// Method to populate the fields
        /// </summary>
        private void populateFields()
        {
            // Iterate through the combolist
            for (int i = 0; i < cmbDepartment.Items.Count; i++)
            {
                // if the department is found...
                if (cmbDepartment.Items[i].ToString().Equals(_inventory.GetItem(_inventory.IndexOf(_sku)).department.ToString()))
                {
                    // assign the selected index
                    cmbDepartment.SelectedIndex = i;

                    // Iterate through the department list
                    foreach (KeyValuePair <int, string> kvp in departments.DepartmentList)
                    {
                        // If the department name matches...
                        if (kvp.Value.Equals(cmbDepartment.Items[i].ToString()))
                        {
                            // Set the department field to the correct department number
                            txtDepartmentNumber.Text = kvp.Key.ToString();
                        }
                    }
                }
            }

            // set comboindex to the selected index
            comboIndex = cmbDepartment.SelectedIndex;

            // Set the other fields to the correct values
            txtDescription.Text = _inventory.GetItem(_inventory.IndexOf(_sku)).description;
            txtName.Text        = _inventory.GetItem(_inventory.IndexOf(_sku)).name;
            txtPrice.Text       = (_inventory.GetItem(_inventory.IndexOf(_sku)).price / 100.00).ToString();
            txtQty.Text         = _inventory.GetItem(_inventory.IndexOf(_sku)).count.ToString();
            txtSku.Text         = _inventory.GetItem(_inventory.IndexOf(_sku)).sku.ToString();
        }
Beispiel #3
0
        /// <summary>
        /// Button to restock items.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnRestock_Click(object sender, System.EventArgs e)
        {
            // In the qty is blank...
            if (txtQty.Text == "")
            {
                // Let the use know they must set the qty first.
                MessageBox.Show(this, "QTY must be set first.");
                return;
            }

            // If the Item list is not selected
            if (lvItemList.SelectedIndices == null || lvItemList.SelectedIndices.Count == 0)
            {
                // Let hte use know they need to select an item to continue
                MessageBox.Show(this, "You must select an item before you can do that.");
                return;
            }

            // Get the SKU from the list
            long.TryParse(lvItemList.SelectedItems[0].SubItems[1].ToString().Substring(
                              18, lvItemList.SelectedItems[0].SubItems[1].ToString().Length - 19), out long sku);

            // Get the quantity from the textbox
            int.TryParse(txtQty.Text, out int qty);

            // If the SKU is 0
            if (sku == 0)
            {
                // Let the user know there s an issue with the SKU
                MessageBox.Show(this, "SKU number is not right, please recheck selection and try again.");
                return;
            }

            // If the QTY is 0...
            if (qty == 0)
            {
                // Let the user know the QTY cannot be zero
                MessageBox.Show(this, "Quantity cannot be 0.");
            }

            // Iterate through each item in the restock inventory list
            foreach (Item item in _restockInventory)
            {
                // If the SKU matches one...
                if (item.sku == sku)
                {
                    // Let the user know they can't add the same item to the list.
                    MessageBox.Show(this, "Item already exists in restock list.");
                    return;
                }
            }

            // Iterate through the invnetory
            foreach (Item item in _inventory)
            {
                // If the SKU matches a SKU...
                if (item.sku == sku)
                {
                    // Get a copy of hte item...
                    Item newItem = item.Copy();

                    // Add the copy to the restock Inventory
                    _restockInventory.AddItem(newItem);

                    // Change the quantity of that item
                    _restockInventory.GetItem(_restockInventory.IndexOf(sku)).count = qty;

                    // Clear the restock list
                    lvRestockList.Items.Clear();

                    // Fill the restock list with updated restock inventory
                    FillRestockList(_restockInventory);
                    return;
                }
            }
        }