示例#1
0
        /// <summary>
        /// Display the sub form to allow add of an item
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnAddInv_Click(object sender, EventArgs e)
        {
            Krusty         emptyOne = new Krusty();
            formProperties subForm  = new formProperties(ref emptyOne);

            subForm.ShowDialog();
            //we return from the subform
            if (emptyOne.ProdName != null)
            {
                // create a Krusty inventory object with the data
                kItems[fileIndex] = emptyOne;
                // add the Krusty inventory object to the list box on our form
                lstBxInventory.Items.Add(kItems[fileIndex]);
                fileIndex++;
                lblMessage.Text = "Krusty item added!";
            }
            else
            {
                lblMessage.Text = "Krusty add cancelled";
            }
        }
示例#2
0
        /// <summary>
        /// Update an inventory item
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            if (lstBxInventory.SelectedIndex == -1)
            {
                MessageBox.Show("Select an item", "Krusty");
            }
            else
            {
                //save the index of the selected item
                int thisListItem = lstBxInventory.SelectedIndex;
                //create an instance of a Krusty with this item
                Krusty thisKrusty = kItems[thisListItem];

                //create an instance of the Properties form
                //pass in the Krusty by reference
                formProperties subForm = new formProperties(ref thisKrusty);
                subForm.ShowDialog();

                //update the Krusty array and list box with the new values
                kItems[thisListItem] = thisKrusty;
                lstBxInventory.Items[thisListItem] = thisKrusty;
                lblMessage.Text = "Inventory item updated";
            }
        }