基本上,我需要将resulta + resultb + resultc + 之前定义的propertyPrice 加在一起以获得总计,然后在文本框中显示总计。结果a/b/c 是根据propertyPrice * 一个常数计算的,房产价格由用户输入。
我没有尝试捕获就做到了,并且得到了格式异常。
int propertyPrice;
if (Int32.TryParse(propertyPriceTextBox.Text, out propertyPrice))
{
stateSalesTaxTextBox.Text = (stateSalesTax * propertyPrice).ToString("c");
if (residentialRadioButton.Checked == true)
comissionTextBox.Text = (residentialCom * propertyPrice).ToString("c");
if (commercialRadioButton.Checked == true)
comissionTextBox.Text = (commercialCom * propertyPrice).ToString("c");
if (hillsRadioButton.Checked == true)
countySalesTaxTextBox.Text = (hilssTax * propertyPrice).ToString("c");
if (pascoRadioButton.Checked == true)
countySalesTaxTextBox.Text = (pascoTax * propertyPrice).ToString("c");
if (polkRadioButton.Checked == true)
countySalesTaxTextBox.Text = (polkTax * propertyPrice).ToString("c");
decimal resulta;
decimal resultb;
decimal resultc;
try
{
resulta = decimal.Parse(countySalesTaxTextBox.Text);
resultb = decimal.Parse(stateSalesTaxTextBox.Text);
resultc = decimal.Parse(comissionTextBox.Text);
}
catch (FormatException)
{
}
decimal totalPrice = (resulta + resultb + resultc + propertyPrice);
totalPriceTextBox.Text = totalPrice.ToString("c");
}