开发者

How to search Complex Arraylist & Insert at given point

I am trying to create a simple appplication that can read from a text file and write to the text file. I have a main form which is shown below, also i have a secondary form also shown below; there are also getter and setter classes for Customers, accounts and Transactions. What i would like to do is search for a Customer based on any data held, but mostly there account number. How would i get it to return the correct customer with ALL of there information. Linked to this it would be good to use the search as a point for inserting say a new account.

Below is the main form for pritning out the customer and getting the information from the file.

    //create account if all ok
    if (allInputOK)
    {
        //create Account
        Account temp = new Account(tempAccSortCode, tempAccNumber, tempAccNickName, tempAccDate, tempAccCurBal, tempAccOverDraft, tempNumTrans);

        //add to array
        Form1.accDetails.Add(temp);

        //finish up
        MessageBox.Show("Success Account added ");
        resetForm();
    }
}

    foreach (Customer c in bankDetails) 
    {
        lstOutput.Items.Add(" ");
        lstOutput.Items.Add(c.getCustomerNumber() + " " + c.getCustomerTitle() + " " + c.getFirstName()
                           + " " + c.getInitials() + " " + c.getSurname() + " " + c.getDateOfBirth()
                           + " " + c.getHouseNameNumber() + " " + c.getStreetName() + " " + c.getArea()
                           + " " + c.getCit开发者_如何学JAVAyTown() + " " + c.getCounty() + " " + c.getPostcode()
                           + " " + c.getPassword() + " " + c.getNumberAccounts());
        foreach (Account a in c.Accounts) 
        {
            lstOutput.Items.Add("\t" + a.getAccSort() + " " + a.getAccNumber() + " " + a.getAccNick() + " " + a.getAccDate()
                               + " " + a.getAccCurBal() + " " + a.getAccOverDraft() + " " + a.getAccNumTrans());

            foreach (Transaction t in a.Transactions) 
            {
                lstOutput.Items.Add("\t \t" + t.getDate() + " " + t.getType() + " " + t.getDescription() + " " + t.getAmount()
                                   + " " + t.getBalAfter());
            }
        }
    }

In the above code for adding an account, where is adds it to the class Account and the arraylist i think is incorrect with the rest of the program on the main form which uses an underlying list to store the customer information and there accounts/transactions.

EDIT: the above code snippet shows the adding of a new account, however it doesnt seem to be working as i need to find the correct customer by searching the customer array, and then inserting it into the correct place. The second snippet of code shows the arraylist with the underlying lists connected to each customer.


Where to begin?

Generally, for querying objects you can use Linq to Objects.

Also, I would recommend against using text files to keep track of things. They are fine at first, but quickly grow unwieldy and slow. On top of that, what if your app crashes before you saved? Look into a "light database" like SQLite (yes, that's one 'L').

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜