大家好,我有这个银行账户项目,它在用户选择索引时显示账户信息。此信息包括帐户的当前余额。然后我还有存款模拟,我存款的金额应该加到当前余额中。我不明白为什么它不做这项工作。
我的 selectedindex 有这个代码,它可以提取帐户信息。
private void accountNumComboBox_SelectedIndexChanged(object sender, EventArgs e)
{
if (accountNumComboBox.SelectedIndex == 0)
{
ownerIdLabel.Text = "0001";
balanceLabel.Text = savings1.Balance.ToString("c");
interestLabel.Text = (string.Format("{0}%", savings1.Interest));
interestRLabel.Text = "Interest Rate:";
}
我有存款按钮的代码
private void depositButton_Click(object sender, EventArgs e)
{
decimal amount;
if (decimal.TryParse(depositTextBox.Text, out amount))
{
account.Deposit(amount);
account.Balance += amount;
depositTextBox.Clear();
}
else
{
MessageBox.Show("Pls enter valid amount.");
}
}
我输入的金额不会加到 balancelabel.Text 中的当前余额。非常感谢你的帮助。
编辑:我也在我的 BankAccount 课程中得到了这个
public decimal Balance
{
get { return _balance; }
set { _balance = value; }
}
public BankAccount(decimal intialBalance, string ownerId, string accountNumber)
{
_balance = intialBalance;
_customerId = ownerId;
_accountNumber = accountNumber;
}
public void Deposit(decimal amount)
{
if ( amount>0)
_balance += amount;
else
throw new Exception("Credit must be > zero");
}
public void Withdraw(decimal amount)
{
_balance -= amount;
}