Хорошо, тогда, возможно, это поможет:
Обновите класс Customer с помощью свойства универсального списка учетных записей.
private int numberAccounts;
public List<Account> Accounts {
get;
protected set;
}
public Customer(string theCustomerNumber, string theCustomerTitle, string theFirstName, string theInitials, string theSurname, string theDateOfBirth, string theHouseNameNumber, string theStreetName, string theArea, string theCityTown, string theCounty, string thePostcode, string thePassword, string theNumberAccounts)
{
customerNumber = theCustomerNumber;
customerTitle = theCustomerTitle;
firstName = theFirstName;
initials = theInitials;
surname = theSurname;
dateOfBirth = theDateOfBirth;
houseNameNumber = theHouseNameNumber;
streetName = theStreetName;
area = theArea;
cityTown = theCityTown;
county = theCounty;
postcode = thePostcode;
password = thePassword;
setNumberAccounts(theNumberAccounts);
Accounts = new List<Account>();
}
Обновите учетную запись с помощью свойства общего списка транзакций
public List<Transaction> Transactions {
get;
protected set;
}
public Account(string theAccSort, string theAccNumber, string theAccNick,
string theAccDate, string theAccCurBal, string theAccOverDraft,
string theAccNumTrans)
{
accSort = theAccSort;
setAccNumber(theAccNumber);
accNick = theAccNick;
accDate = theAccDate;
setAccCurBal(theAccCurBal);
setAccOverDraft(theAccOverDraft);
setAccNumTrans(theAccNumTrans);
Transactions = new List<Transaction>();
}
Закомментируйте ваш метод "readData ()" и замените его следующим:
private void readData() {
///read all the data into memory (if you can)
string[] _data = File.ReadAllLines(inputDataFile);
Queue<String> _lines = new Queue<string>();
foreach (string _line in _data) {
_lines.Enqueue(_line.Trim()); //put it into a queue for convience
}
///iterate through the data and extract the details based on
///known record delimiters.
while (_lines.Count > 0) {
Customer _customer = new Customer(
_lines.Dequeue(),
_lines.Dequeue(),
_lines.Dequeue(),
_lines.Dequeue(),
_lines.Dequeue(),
_lines.Dequeue(),
_lines.Dequeue(),
_lines.Dequeue(),
_lines.Dequeue(),
_lines.Dequeue(),
_lines.Dequeue(),
_lines.Dequeue(),
_lines.Dequeue(),
_lines.Dequeue());
int _numberOfAccounts = _customer.getNumberAccounts();
for (int i = 1; i <= _numberOfAccounts; i++) {
Account _account = new Account(
_lines.Dequeue(),
_lines.Dequeue(),
_lines.Dequeue(),
_lines.Dequeue(),
_lines.Dequeue(),
_lines.Dequeue(),
_lines.Dequeue());
int _numberOfTransactions = _account.getAccNumTrans();
for (int j = 1; j <= _numberOfTransactions; j++) {
Transaction _transaction = new Transaction(
_lines.Dequeue(),
_lines.Dequeue(),
_lines.Dequeue(),
_lines.Dequeue(),
_lines.Dequeue());
_account.Transactions.Add(_transaction);
}
_customer.Accounts.Add(_account);
}
///update the legacy part of the system.
bankDetails.Add(_customer);
foreach (Account _account in _customer.Accounts) {
accDetails.Add(_account);
foreach (Transaction _transaction in _account.Transactions) {
tranDetails.Add(_transaction);
}
}
}
}
РЕДАКТИРОВАТЬ: Закомментируйте ваш метод "showListsOfCust" и поместите его на место
private void showListsOfCust() {
listBox1.Items.Clear();
foreach (Customer c in bankDetails) {
listBox1.Items.Add(c.getCustomerNumber() + " " + c.getCustomerTitle() + " " + c.getFirstName()
+ " " + c.getInitials() + " " + c.getSurname() + " " + c.getDateOfBirth()
+ " " + c.getHouseNameNumber() + " " + c.getStreetName() + " " + c.getArea()
+ " " + c.getCityTown() + " " + c.getCounty() + " " + c.getPostcode()
+ " " + c.getPassword() + " " + c.getNumberAccounts());
foreach (Account a in c.Accounts) {
listBox1.Items.Add(a.getAccSort() + " " + a.getAccNumber() + " " + a.getAccNick() + " " + a.getAccDate()
+ " " + a.getAccCurBal() + " " + a.getAccOverDraft() + " " + a.getAccNumTrans());
foreach (Transaction t in a.Transactions) {
listBox1.Items.Add(t.getDate() + " " + t.getType() + " " + t.getDescription() + " " + t.getAmount()
+ " " + t.getBalAfter());
}
}
}
}