-4
我试图将数量和价格文本框中的值相乘,然后将其传递到每次按下添加按钮时都会更新的总文本框中。以下是我迄今为止所尝试的。在每次迭代按钮按下累积总计
如何让它在我的总文本框中显示产品并积累它?例如。在数量4和价格4读取16,然后,如果我投放量2,价格2它将读取20
private void add_btn_Click(object sender, EventArgs e)
{
try
{
if (customer_textBox.Text == "")
{
MessageBox.Show(
"Please enter valid Customer");
}
if (quantity_textBox.Text == "")
{
MessageBox.Show(
"Please enter valid Quantity");
}
if (price_per_item_textBox.Text == "")
{
MessageBox.Show(
"Please enter valid Price");
}
else
{
decimal total = Decimal.Parse(total_textBox.Text);
total = int.Parse(quantity_textBox.Text) * int.Parse(price_per_item_textBox.Text);
total += total;
total_textBox.Text = total.ToString();
}
quantity_textBox.Clear();
customer_textBox.Clear();
price_per_item_textBox.Clear();
item_textBox.Clear();
}
catch (FormatException)
{
}
total_textBox.Focus();
}