嗨,大家好我有这个银行帐户项目,显示用户选择索引时的帐户信息。这些信息包括账户的当前余额。然后我也有存款模拟,我存入的数额应该加起来到目前的余额。我不知道为什么它不做这项工作。C#银行帐户存款
我有我的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;
}
看起来'savings1'和'account'是您正在操作的'BankAccount'类的两个单独实例。我没有看到有关'savings1'实例的更新。详细说明如何填充/刷新'savings1'实例。 – niksofteng
你也在做双重存款。一旦进入'Deposite'方法,然后在'depositButton_Click'中再次设置'account.Balance'。我祈祷不要在最终的代码中完成。 :) – niksofteng
哦,我在这里获得了savings1实例, public partial class Form1:Form { List savings = new List (); SavingsAccount savings1 = new SavingsAccount(“0001”,“31-1000”,100m,0.01); –
tapsilog