private void BtnAddDeliveredMerchandise_Click(object sender, RoutedEventArgs e) // Adds incoming deliveries to stock { var parent = (sender as Button).Parent; TextBox valueToAdd = parent.GetChildrenOfType <TextBox>().First(x => x.Name == "TxtBoxAddQty"); TextBlock valueToCheck = parent.GetChildrenOfType <TextBlock>().First(x => x.Name == "QTY"); TextBlock itemToAdd = parent.GetChildrenOfType <TextBlock>().First(x => x.Name == "ItemName"); string toConvert = valueToAdd.Text; int intValueToAdd = 0; int intValueToCheck = Convert.ToInt32(valueToCheck.Text); // Add incoming deliveries to stock if (int.TryParse(toConvert, out intValueToAdd)) { if (intValueToAdd > intValueToCheck) { MessageToUser($"Enter the correct number of stock to submit, maximum number to submit is: {intValueToCheck} "); valueToAdd.Text = ""; } else { StockClass merch = null; foreach (var item in _app.GetDefaultStockList()) { if (item.ItemName == itemToAdd.Text) { merch = item; } } store.AddToStock(merch, intValueToAdd); MessageToUser($"You have added: {valueToAdd.Text} {itemToAdd.Text} to your stock"); valueToAdd.Text = ""; } } else { MessageToUser("You must enter an integer"); } }
private void BtnAddDeliveredMerchandise_Click(object sender, RoutedEventArgs e) { var parent = (sender as Button).Parent; TextBox valueToAdd = parent.GetChildrenOfType <TextBox>().First(x => x.Name == "TxtBoxAddQty"); TextBlock valueToCheck = parent.GetChildrenOfType <TextBlock>().First(x => x.Name == "QTY"); TextBlock itemToAdd = parent.GetChildrenOfType <TextBlock>().First(x => x.Name == "ItemName"); int intValueToAdd = Convert.ToInt32(valueToAdd.Text); int intValueToCheck = Convert.ToInt32(valueToCheck.Text); if (intValueToAdd > intValueToCheck) { MessageToUser($"Ange rätt antal att in leverera, max antal att in leverera: {intValueToCheck} "); valueToAdd.Text = ""; } else { StockClass merch = new StockClass(); foreach (var item in StockList) { if (item.ItemName == itemToAdd.Text) { merch = item; } } StoreClass.AddToStock(merch, intValueToAdd); MessageToUser($"You have added: {valueToAdd.Text} {itemToAdd.Text} to your stock"); valueToAdd.Text = ""; } Debug.WriteLine(valueToAdd.Text); Debug.WriteLine(valueToCheck.Text); }