【发布时间】:2017-05-23 08:43:20
【问题描述】:
我有一个帐户列表,每个帐户都包含名称、帐号和余额。我现在拥有的是一个包含帐户列表和交易表单按钮的主表单。因此,当用户从列表中选择一个帐户时,他们可以单击按钮打开 Transaction 表单。
我正在努力做的是在交易表格上输入一个值以从所选帐户余额中添加/扣除......完成后会在列表中更新。有人可以帮忙吗?
类:
- Dashboard.cs - 包含打开交易表单的列表和交易按钮。
- Account.cs - 设置帐户信息。
- Transaction.cs - 将数据传递给帐户类。
- AccountList.cs - 创建列表。
Dashboard.cs(主窗体):
//Current Desposit/Withdraw button
private void btn_DepositWithdraw_Click(object sender, EventArgs e)
{
Transaction TransactionForm = new Transaction();
//Display form but only process results if OK is pressed
if (TransactionForm.ShowDialog() == DialogResult.OK)
{
//Update the item in the list
}
}
//The selected item in the list
public void list_Accounts_SelectedIndexChanged(object sender, EventArgs e)
{
//get index of selected account
int index = list_Accounts.SelectedIndex;
Account a = (Account)list_Accounts.Items[index];
//Update text on the Dashboard form
txt_AccountName.Text = a.AccountName + " #" + a.AccountNo;
txt_CurrentBalance.Text = "£" + a.Balance;
}
Account.cs:
[Serializable]
public class Account
{
//Set the Variable
public string AccountName { get; set; }
public string AccountNo { get; set; }
public string Balance { get; set; }
public string Interest { get; set; }
public string NewBalance { get; set; }
public Account()
{
AccountName = "Account Name not inserted!";
AccountNo = "Account Number not inserted!";
Balance = "Balance not inserted!";
}
public Account(string name, string accNo, string staBal, string interest)
{
AccountName = name;
AccountNo = accNo;
Balance = staBal;
Interest = interest;
}
public override string ToString()
{
return String.Format("{0} #{1}", AccountName, AccountNo);
}
}
[Serializable]
public class CurrentAcc : Account
{
public CurrentAcc()
{
}
public CurrentAcc(string name, string accNo, string staBal, string interest) : base(name, accNo, staBal, interest)
{
}
public override string ToString()
{
return base.ToString() + String.Format("{0,-17}", " (Current Account)");
}
}
[Serializable]
public class SavingsAcc : Account
{
public SavingsAcc()
{
}
public SavingsAcc(string name, string accNo, string staBal, string interest) : base(name, accNo, staBal, interest)
{
}
public override string ToString()
{
return base.ToString() + String.Format("{0,-17}", " (Savings Account)");
}
}
[Serializable]
public class Deposit : Account
{
}
[Serializable]
public class Withdraw : Account
{
}
Transaction.cs:
public string NewTransactionInformation()
{
Account nt;
if (radio_Deposit.Checked)
{
nt = new Deposit(input_Amount.Text);
}
else
{
nt = new Withdraw(input_Amount.Text);
}
return nt;
}
AccountList.cs:
class AccountList
{
private List<Account> allaccounts;
public List<Account> AllAccounts
{
get { return allaccounts; }
}
public AccountList()
{
allaccounts = new List<Account>();
}
public void AddCurrent(Account a)
{
allaccounts.Add(a);
}
}
【问题讨论】:
标签: c# asp.net list transactions