//прави поръчка при кликане на продукт void newProduct_Click(object sender, EventArgs e) { Product prod = (Product)((Button)sender).Tag; //access the product that was passed in newProduct.Tag || casting it because it will think it's a generic object Drinks drink; Extras extra; int index; Currency = prod.Currency; PriceTotal = PriceTotal + (decimal)prod.Price; if (prod.GetType() == typeof(Drinks)) { drink = new Drinks(); drink.Name = prod.Name; drink.Price = prod.Price; bindingProductList.Add(drink); } else { extraPressed = true; } if (listProducts.SelectedItem == null && extraPressed) { extra = new Extras(); extra.Name = prod.Name; extra.Price = prod.Price; bindingProductList.Add(extra); listProducts.ClearSelected(); } else if (listProducts.SelectedItem.GetType() == typeof(Drinks) && extraPressed) { drink = listProducts.SelectedItem as Drinks; extra = new Extras(); extra.Name = prod.Name; extra.Price = prod.Price; drink.ExtrasList.Add(extra); extra.IsExtraOfDrink = true; index = bindingProductList.IndexOf(drink); bindingProductList.Insert(index + 1, extra); } else if (listProducts.SelectedItem.GetType() == typeof(Extras) && extraPressed) { //extra = new Extras(prod.Name, prod.Price); extra = new Extras(); extra.Name = prod.Name; extra.Price = prod.Price; bindingProductList.Add(extra); } else { listProducts.ClearSelected(); } extraPressed = false; }