private void UpdateInventory(int index, int numWanted) { // declare our variables int itemNo; string prodName; int qty; decimal price; // update the quantity of the inventory item kItems[index].Qty = kItems[index].Qty - numWanted; // get the data from the inventory item itemNo = kItems[index].ItemNo; prodName = kItems[index].ProdName; price = kItems[index].Price; for (int i = 0; i < numWanted; i++) { kCart[lastCartItem] = new Krusty(itemNo, prodName, 1, price); lstBxCart.Items.Add(kCart[lastCartItem]); // update item number for next item lastCartItem++; } }
private void btnCalc_Click(object sender, EventArgs e) { decimal temp; temp = Krusty.CalculateSubTotal(kCart); lblSubtotal.Text = temp.ToString("C"); temp = Krusty.CalculateTax(kCart); lblTax.Text = temp.ToString("C"); totalAmtDue = Krusty.CalculateTotal(kCart); lblTotal.Text = totalAmtDue.ToString("C"); }
private void ProcessInputLine(string kInItem, int kIndex) { // split the line into our fields string[] fields = kInItem.Split(','); // get each field from the split array // convert as necessary int itemNo = Convert.ToInt32(fields[0]); string prodName = fields[1]; int qty = Convert.ToInt32(fields[2]); decimal price = Convert.ToDecimal(fields[3]); // create a Krusty inventory object with the data kItems[kIndex] = new Krusty(itemNo, prodName, qty, price); // add the Krusty inventory object to the list box on our form lstBxInventory.Items.Add(kItems[kIndex]); }
}//deletes an item from our list and array private Krusty[] RemoveFromArray(Krusty[] theItems, int removeAt) { //allocate a temp array Krusty[] tempArray = new Krusty[theItems.Length - 1]; //set up our index int i = 0; //use for our theItems array int j = 0; //use for new temp array while (i < theItems.Length) { if (i != removeAt) //keep this one { tempArray[j] = theItems[i]; j++; } //end of if i++; } //end of while return(tempArray); }
/// <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"; } }
/// <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"; } }
public formProperties(ref Krusty thisOne) { InitializeComponent(); globalOne = thisOne; }