Example #1
0
        public static int RebuildBankListsFromText( )
        {
            int    count = 0;
            string fi    = BankAccount.ReadBankFilePath( ) + "Textfiles\\BankAccountListData.txt";

            if (File.Exists(fi))
            {
                string input = File.ReadAllText(fi);          // you gotta delete them first, else it appends the data constantly
                char[] ch1   = { '\r' };
                char[] ch2   = { ',' };
                //				char [ ] ch3 = { '~' };
                string[] record = input.Split(ch1);
                string[] BAccts;

                DataArray.ArrayClearBank( );
                BankAccount.BankAccountsLinkedList.Clear( );
                // record now has an array of strings that were split on \t
                // this means we should have at least one, possibly multiple  B.Accs  in the last element
                // iterate through and split these out of record into string[] Item2
                for (int i = 0; i < record.Length; i++)
                {
                    string str = record[i];
                    //This should give us x strings,, the first one can be ignored
                    //, the rest will be bank account numbers cos the format is  "xxxxxx,xxxx,yyyy,~4455554544~65645
                    // and we are after the data immediately past the first ~
                    string[] Item2 = str.Split(ch2);
                    // check.  The plit always gives us ~ONE element, even though it is empty
                    if (Item2.Length == 1 && Item2[0].Length == 0)
                    {
                        break;  // Were all done here
                    }
                    BAccts = Item2[7].Split('~');
                    // go get em (one or more B Accts in a BAccts[] string[]
                    if (BAccts.Length > 1)
                    {   // got one or more - do something with them ?
                    }
                    //Baacts MAY contain a leading EMPTY string, so beware
                    // by here , we have an array of strings of Bank accounts owned by this customer. ?
                    for (int x = 0; x < record.Length; x++)
                    {
                        // get a string from string[] array Item1[]
                        BankAccount B = new BankAccount( );
                        if (B != null)
                        {
                            B.AccountType       = Convert.ToInt16(Item2[x]);
                            B.CustAccountNumber = Convert.ToInt32(Item2[x + 1]);
                            B.BankAccountNumber = Convert.ToInt32(Item2[x + 2]);
                            B.Balance           = Convert.ToDecimal(Item2[x + 3]);
                            B.DateClosed        = Convert.ToDateTime(Item2[x + 4]);
                            B.InterestRate      = Convert.ToDecimal(Item2[x + 6]);
                            // We dont seem to save this ?????
                            B.Status = 1;
                            BankAccount.BankAccountsLinkedList.AddLast(B);     // Add this one to our linked list of customers.
                            DataArray.ArrayAddBank(B);
                            SerializeData.WriteBankAccountToDiskAndText(B, fi);
                            count++;
                            break;
                        }
                    }
                    // save linked list to disk in text format
                    Lists.SaveAllBankAccountListData( );
                }
            }
            return(count);
        }