//adds iceCream to ouput text private void AddToOutput() { if (iceCreamNameFound) { int charLocation = OutputLabel.Text.IndexOf("*", StringComparison.Ordinal); if (charLocation == 0 || charLocation == OutputLabel.Text.Length - 1) { textBox1.Text = String.Empty; return; } int ammount = int.Parse(OutputLabel.Text.Substring(0, charLocation)); string name = OutputLabel.Text.Substring(charLocation + 1); for (int i = 0; i < ex.getIceCreamList().Count; i++) { if (ex.getIceCreamList()[i].getname() == name) { IceCream select = new IceCream(ex.getIceCreamList()[i].getID(), ex.getIceCreamList()[i].getname(), ex.getIceCreamList()[i].gettype()); select.setAmount(ammount); selectedData.addToList(select); break; } } reDrawOutput(); } else { textBox1.Text = String.Empty; } canPrint(); }
//remove from list public void removeFromList(IceCream iceCream) { for (int i = 0; i < iceCreamList.Count; i++) { if (iceCreamList[i].getname() == iceCream.getname()) { if (iceCreamList[i].getamount() - iceCream.getamount() <= 0) { iceCreamList.RemoveAt(i); return; } else { int oldAmmount = iceCreamList[i].getamount(); iceCreamList[i].setAmount(oldAmmount - iceCream.getamount()); return; } } } }
//remove from list button private void deleteButton_Click(object sender, EventArgs e) { if (textBox1.Text == string.Empty) { string s = "Naozaj chcete zmazať všetko?"; InitializePopup(s); if (answer) { outputTextBox.Text = string.Empty; selectedData.resetIceCream(); answer = false; return; } else { answer = false; return; } } int charLocation = OutputLabel.Text.IndexOf("*", StringComparison.Ordinal); int ammount = int.Parse(OutputLabel.Text.Substring(0, charLocation)); string name = OutputLabel.Text.Substring(charLocation + 1); for (int i = 0; i < ex.getIceCreamList().Count; i++) { if (ex.getIceCreamList()[i].getname() == name) { IceCream select = new IceCream(ex.getIceCreamList()[i].getID(), ex.getIceCreamList()[i].getname(), ex.getIceCreamList()[i].gettype()); select.setAmount(ammount); selectedData.removeFromList(select); break; } } reDrawOutput(); }
//add to list public void addToList(IceCream iceCream) { bool iceCreaFound = false; if (iceCreamList.Count > 0) { for (int i = 0; i < iceCreamList.Count; i++) { if (iceCreamList[i].getname() == iceCream.getname()) { int newAmmount = iceCreamList[i].getamount() + iceCream.getamount(); iceCreamList[i].setAmount(newAmmount); iceCreaFound = true; } } } if (!iceCreaFound) { iceCreamList.Add(iceCream); } }
public void AddOrEditData(IceCream c) { if (c.getID() == 0) { IceCream last = IceCreamList[IceCreamList.Count - 1]; c.setID(IceCreamList[IceCreamList.Count - 1].getID()); IceCreamList[IceCreamList.Count - 1] = c; last.setID(IceCreamList[IceCreamList.Count - 1].getID() + 1); IceCreamList.Add(last); return; } else { for (int i = 0; i < IceCreamList.Count; i++) { if (IceCreamList[i].getID() == c.getID()) { IceCreamList[i] = c; return; } } } }