嗨,大家好我有這個銀行帳戶項目,顯示用戶選擇索引時的帳戶信息。這些信息包括賬戶的當前餘額。然後我也有存款模擬,我存入的數額應該加起來到目前的餘額。我不知道爲什麼它不做這項工作。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