示例#1
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;
                }
            }
        }