コード例 #1
0
        public static int RebuildBankDataFromTextFiles( )
        //************************************************************************************************************************************************
        {
            // iterate thru reading bankaccount objects from disk and add them to our LinkedList and /BankArray
            int    count = 0;
            string dir   = BankAccount.ReadBankFilePath( );

            dir += "Textfiles\\";
            string[] files = Directory.GetFiles(dir);
            // clear the lists- JIC
            DataArray.ArrayClearBank( );                 // Clear ( );
            BankAccount.BankAccountsLinkedList.Clear( );

            foreach (var fi in files)
            {
                bool result = fi.Contains("BankObject");
                if (!result)
                {
                    continue;
                }
                else
                {
                    string      input = File.ReadAllText(fi);
                    char[]      ch    = { ',' };
                    string[]    items = input.Split(ch);
                    BankAccount B     = new BankAccount( );
                    B.BankAccountNumber = Convert.ToInt32(items[0]);
                    B.CustAccountNumber = Convert.ToInt32(items[1]);
                    B.AccountType       = Convert.ToInt16(items[2]);
                    B.Balance           = Convert.ToDecimal(items[3]);
                    B.DateOpened        = Convert.ToDateTime(items[4]);
                    B.DateClosed        = Convert.ToDateTime(items[5]);
                    B.Balance           = Convert.ToDecimal(items[6]);
                    B.Status            = Convert.ToInt16(items[7]);
                    //Write it back as OBj and TXT - yes even though we onlt just read it in.
                    SerializeData.WriteBankAccountToDiskAndText(B, B.FullFileName);
                    // add each one to our new List so we cna use the Enumeration later
                    try
                    {
                        BankAccount.BankAccountsLinkedList.AddLast(B);
                        DataArray.ArrayAddBank(B);
                        if (BankAccount.BankDict != null)
                        {
                            if (!BankAccount.BankDict.ContainsKey(B.BankAccountNumber))
                            {
                                BankAccount.BankDict.Add(B.BankAccountNumber, B);
                            }
                        }
                    }
                    catch
                    { new Exception(" Failed to update LinkeList or Bank array in RebuildBankDataFromTextFiles at line 311"); }
                    count++;
                    B.Dispose( );
                }
            }
            // This saves the bank LinkedList to both an object file and a Text file
            Lists.SaveAllBankAccountListData( );
            BankListChangedEvent?.Invoke(null, "ALLDATA REBUILT FROM TEXTFILES");
            return(count);
        }
コード例 #2
0
        //=========================================================================//
        public static int RebuildBankArrayFromLinkedList( )
        //=========================================================================//
        {
            int count = 0;

            DataArray.ArrayClearBank( );
            foreach (BankAccount Bank in BankAccount.BankAccountsLinkedList)
            {
                if (Bank ! != null)
                {
                    DataArray.ArrayAddBank(Bank); count++;
                }
            }
            return(count);
        }
コード例 #3
0
        //******************************************************************************************//

        //************************************************************************************************************************************************
        public static int RebuildBankLinkedListFromObjects()
        //************************************************************************************************************************************************
        {
            // iterate thru reading bankaccount objects from disk and add them to our linkedList
            int    count = 0;
            string dir   = ReadBankFilePath();

            string[] files = Directory.GetFiles(dir, "*.bnk");
            // clear the lists- JIC
            DataArray.ArrayClearBank();    // Clear ( );
            foreach (var fi in files)
            {
                bool result = fi.Contains("BankObject");
                if (!result)
                {
                    continue;
                }
                {
                    BankAccount B = SerializeData.ReadBankAccountFromDisk(fi);
                    //BankAccount B = directories . GetBankObjectFromPath ( fi );
                    // add each one to our new List so we cna use the Enumeration later
                    if (B != null)
                    {
                        try
                        {
                            count++;
                            BankAccountsLinkedList.AddLast(B);
                            DataArray.ArrayAddBank(B);
                            if (BankAccount.BankDict != null)
                            {
                                if (!BankAccount.BankDict.ContainsKey(B.BankAccountNumber))
                                {
                                    BankAccount.BankDict.Add(B.BankAccountNumber, B);
                                }
                            }
                        }
                        catch { }
                        new Exception(" Failed ot update LinkeList of sortedlist in RebuildCustLinkedList atliner 366");
                    }
                    B.Dispose();
                }
            }
            // This saves the bank LinkedList to both an object file and a Text file
            Lists.SaveAllBankAccountListData();
            BankListChangedEvent?.Invoke(null, "ALLDATA REBUILT FROM OBJECTS");
            return(count);
        }
コード例 #4
0
        // Save the new customer data as an Object and add it to the Customer List
        // plus create a BankAccount object and add it to the BankAccount List
        // and add a bak transaction
        //*************************************************************************************************************************************************//
        private void SaveBankButton_Click(object sender, EventArgs e)
        //*************************************************************************************************************************************************//
        {
            if (AccountNo.Text.Length == 0 || AccountBalance.Text.Length == 0 || Interest.Text.Length == 0 || OpenDate.Text.Length == 0 || fname.Text.Length == 0 ||
                lname.Text.Length == 0 || day.Text.Length == 0 || month.Text.Length == 0 || year.Text.Length == 0)
            {
                MessageBox.Show("One or more fields are empty, All fields must be populated", "User Input Error");
                return;
            }
            Int16 type = 0;

            if (AccountType.Text.Contains("Normal"))
            {
                type = 1;
            }
            if (AccountType.Text.Contains("Savings"))
            {
                type = 2;
            }
            if (AccountType.Text.Contains("Deposit"))
            {
                type = 3;
            }
            if (AccountType.Text.Contains("Business"))
            {
                type = 4;
            }

            //====================BANK ACCOUNT ========================================
            // READ BANK OBJECT FROM DISK and update it
            // Bank should be valid as it is a global in this file ?
            if (allbankaccounts.SelectedIndex == -1)
            {
                MessageBox.Show("The Bank Account list does not appear to have an item selected\nWe No data has been changed, but we are UNABLE to continue with update...", "Database system ERROR");
                return;
            }
            string target = allbankaccounts.Items[allbankaccounts.SelectedIndex].ToString();

            char[]   ch        = { '\t' };
            char[]   dashch    = { '-' };
            string[] tempacno  = target.Split(ch);
            Int32    accountno = Convert.ToInt32(tempacno[0]);

            Bank = Search.FindBankObjectfromBankNo(accountno);
            int    actype         = Convert.ToInt16(AccountType.SelectedIndex + 1);
            string actypeselected = AccountType.SelectedItem.ToString();

            string[] newselaccount = actypeselected.Split(dashch);
            if (newselaccount[0] != tempacno[1])
            {   // the type of account has been changed - handle it
                for (int i = 0; i < allbankaccounts.Items.Count; i++)
                {
                    string temp = "";
                    temp = allbankaccounts.Items[i].ToString();
                    string[] thisentry = temp.Split(ch);
                    if (thisentry[0] == tempacno[0] && thisentry[1] != newselaccount[0])
                    {
                        listupdateneeded = false;   //This simply avoids the auto update of the listbox, set back to true afterwards
                        allbankaccounts.Items.RemoveAt(i);
                        temp = Bank.BankAccountNumber.ToString() + "\t" + actype.ToString();
                        allbankaccounts.Items.Add(temp);
                        allbankaccounts.SelectedIndex = i;
                        listupdateneeded = true;
                        break;
                    }
                }
            }
            // Thkis call sends Event data to Bankaccount.cs so the handlers can handle it
            // cos we cannot call them directly in BankAccount.cs
            BankAccount.SendBankEventData(Bank, "BANKACCOUNT MODIFIED");

            // we need to  delete the old account and insert the new details  in our ArrayList
            int index = DataArray.ArrayFindBank(Bank);

            DataArray.BankNo.RemoveAt(index);
            BankAccount.BankDict.Remove(index);

            Bank.Balance      = Convert.ToDecimal(AccountBalance.Text);
            Bank.InterestRate = Convert.ToDecimal(Interest.Text);
            Bank.DateOpened   = Convert.ToDateTime(OpenDate.Text);
            Bank.AccountType  = Convert.ToInt16(actype);
            //SAVE BANK OBJECT BACK TO DISK
            SerializeData.WriteBankAccountToDiskAndText(Bank, Bank.FullFileName);
            DataArray.ArrayAddBank(Bank);
            if (BankAccount.BankDict != null)
            {
                if (!BankAccount.BankDict.ContainsKey(Bank.BankAccountNumber))
                {
                    BankAccount.BankDict.Add(Bank.BankAccountNumber, Bank);
                }
            } // handle the Linkedlist as well

            // CREATE A NEW BANK TRANSACTION
            BankTransaction newbankaccount = new BankTransaction();

            newbankaccount.TransDate         = DateTime.Now;
            newbankaccount.AccountType       = Bank.AccountType;
            newbankaccount.CustAccountNumber = Bank.CustAccountNumber;
            newbankaccount.BankAccountNumber = Bank.BankAccountNumber;
            newbankaccount.Transamount       = Bank.Balance;
            newbankaccount.Notes             = "Opening Balance";
            newbankaccount.Status            = Bank.Status;
            BankTransaction.allBankTransactions.AddLast(newbankaccount);
            //Update the Customer HASH TABLE
            CustomerBalanceHashTable.UpdateCustBalHashTable(Bank.CustAccountNumber.ToString(), Bank.Balance);

            //NOW UPDATE CUSTOMER RECORD
            Cust = Customer.GetCustomerAccount(Bank.CustAccountNumber.ToString());
            if (Cust == null)
            {
                MessageBox.Show("Unable to find the Customer Record from LinkedList", "Database system ERROR"); return;
            }
            else
            {
                // we need to  delete the old Customer account and insert the new details  in our ArrayList
                int indx = DataArray.ArrayFindCust(Cust);
                DataArray.CustNo.RemoveAt(indx);
                Customer.CustDict.Remove(indx);
                // Now update the Customer record so we can add it to the array
                Cust.FirstName = fname.Text;
                Cust.LastName  = lname.Text;
                Cust.DOB       = Convert.ToDateTime(day.Text + "/" + month.Text + "/" + year.Text);
                if (Cust.accountnums[0] == Convert.ToInt32(Bank.BankAccountNumber))
                {
                    Cust.accounttypes[0] = type;
                }
                else if (Cust.accountnums[1] == Convert.ToInt32(Bank.BankAccountNumber))
                {
                    Cust.accounttypes[1] = type;
                }
                else if (Cust.accountnums[2] == Convert.ToInt32(Bank.BankAccountNumber))
                {
                    Cust.accounttypes[2] = type;
                }
                else if (Cust.accountnums[3] == Convert.ToInt32(Bank.BankAccountNumber))
                {
                    Cust.accounttypes[3] = type;
                }
                Cust.Address1     = addr1.Text;
                Cust.Address2     = addr2.Text;
                Cust.Town         = town.Text;
                Cust.County       = county.Text;
                Cust.PostCode     = postcode.Text;
                Cust.PhoneNumber  = phone.Text;
                Cust.MobileNumber = mobile.Text;

                // SAVE CUSTOMER OBJECT BACK TO DISK
                Customer.WriteCustObjectToDiskAndText(Cust, Cust.FullFileName);
                try
                {   // update Customer Linked List & ArrayList
                    Customer.CustomersLinkedList.Remove(Cust);
                    Customer.CustomersLinkedList.AddLast(Cust);
                    // save our Customer LinkedList to disk as binary and txt files
                    Lists.SaveAllCustomerListData(Customer.CustomerFilePath + "CustSortedListData.cust");
                    DataArray.ArrayAddCust(Cust);
                    if (Customer.CustDict != null)
                    {
                        if (!Customer.CustDict.ContainsKey(Cust.CustomerNumber))
                        {
                            Customer.CustDict.Add(Cust.CustomerNumber, Cust);
                        }
                    }
                }
                catch { new Exception("Customer Linked List coukld not be updated in bankaccountEdit.cs cline 103"); }
            }

            MessageBox.Show("Bank & Customer  accounts have been updated successfully...,", "Bank account Edit Facility");
        }
コード例 #5
0
        //=========================================================================//
        //EXTERNAL
        public Int16 LoadArraysFromDisk(out int Bcount, out int Ccount)
        //=========================================================================//
        {
            //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            // We iterate through all Bank .BNK files cos we can also read the relevant
            // Customer #  from it, and then load that to the Customer array - Clever eh ?
            //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            Int16 count = 0;

            Bcount = 0;
            Ccount = 0;
            Int32[] custno     = new int[100];
            int     custcount  = 0;
            bool    duplicated = false;
            // start with BankAccounts
            string dir  = BankAccount.ReadBankFilePath();
            string dir2 = Customer.GetCustFilePath();

            string[] bankfiles = System.IO.Directory.GetFiles(dir, "Bankobject*.bnk");
            // initilaize our check array
            for (int i = 0; i < 100; i++)
            {
                custno[i] = 0;
            }
            // Iterate trhu them and handle as required
            foreach (var fi in bankfiles)
            {
                bool result = fi.Contains("BankObject");
                if (result)
                {
                    // Got a bank account object
                    BankAccount B = (BankAccount)SerializeData.ReadBankAccountFromDisk(fi);
                    if (B != null)
                    {
                        DataArray.ArrayAddBank(B);     // Add to bank ArrayList
                        if (BankAccount.BankDict != null)
                        {
                            if (!BankAccount.BankDict.ContainsKey(B.BankAccountNumber))
                            {
                                BankAccount.BankDict.Add(B.BankAccountNumber, B);
                            }
                        }
                        Bcount++;
                        BankAccount.BankAccountsLinkedList.AddLast(B);
                        Customer C = (Customer)SerializeData.ReadCustomerDiskObject(dir2 + "Custobj" + B.CustAccountNumber + ".cust");
                        if (C != null)
                        {
                            // add to our test array
                            // check to see if it has been added before ?
                            for (int i = 0; i < custcount; i++)
                            {
                                if (custno[i] == C.CustomerNumber)
                                {
                                    duplicated = true;
                                    break;
                                }
                            }
                            custno[custcount++] = C.CustomerNumber;
                            if (!duplicated)
                            {
                                DataArray.ArrayAddCust(C);     // The one and only Customer ArrayList addition in this Fn()
                                if (Customer.CustDict != null)
                                {
                                    if (!Customer.CustDict.ContainsKey(C.CustomerNumber))
                                    {
                                        Customer.CustDict.Add(C.CustomerNumber, C);
                                    }
                                }

                                Ccount++;
                                Customer.CustomersLinkedList.AddLast(C);
                            }

                            /*							// Handle multiple a/c's held by this customer
                             *                                                                                  if ( C . accountnums [ 1 ] != 0 )
                             *                                                                                  {
                             *                                                                                          BankAccount Bk = ( BankAccount ) SerializeData . ReadBankAccountFromDisk ( dir + "Bankobject" + C . accountnums [ 1 ] + ".bnk" );
                             *                                                                                          DataArray . ArrayAddBank ( Bk );// Add to bank ArrayList
                             *                                                                                          Bcount++;
                             *                                                                                          Bk . Dispose ( );
                             *                                                                                  }
                             *                                                                                  if ( C . accountnums [ 2 ] != 0 )
                             *                                                                                  {
                             *                                                                                          BankAccount Bk = ( BankAccount ) SerializeData . ReadBankAccountFromDisk ( dir + "Bankobject" + C . accountnums [ 2 ] + ".bnk" );
                             *                                                                                          DataArray . ArrayAddBank ( Bk );// Add to bank ArrayList
                             *                                                                                          Bcount++;
                             *                                                                                          Bk . Dispose ( );
                             *                                                                                  }
                             *                                                                                  if ( C . accountnums [ 3 ] != 0 )
                             *                                                                                  {
                             *                                                                                          BankAccount Bk = ( BankAccount ) SerializeData . ReadBankAccountFromDisk ( dir + "Bankobject" + C . accountnums [ 3 ] + ".bnk" );
                             *                                                                                          DataArray . ArrayAddBank ( Bk );// Add to bank ArrayList
                             *                                                                                          Bcount++;
                             *                                                                                          Bk . Dispose ( );
                             *                                                                                  }
                             */
//                            if (C != null)
//                             C.Dispose();
                        }
                        //                  if (B != null)
                        //                   B.Dispose();
                    }
                    count++;
                }
            }
            // save our Customer LinkedList to disk as binary and txt files
            Lists.SaveAllCustomerListData(Customer.CustomerFilePath + "CustSortedListData.cust");
            // sort the arrays in Ascending v0 - 9
            SortArray.SortBankArray(0);
            return(count);
        }
コード例 #6
0
        // Save the new customer data as an Object and add it to the Customer List
        // plus create a BankAccount object and add it to the BankAccount List
        //*************************************************************************************************************//
        private void SaveCustButton_Click(object sender, EventArgs e)
        //*************************************************************************************************************//
        {
            if (!dirty)
            {
                MessageBox.Show("No changes appear to have been made ?... \nPlease make any changes needed, and then try again" +
                                "", " FULL Customer EDIT entry System");
                return;
            }
            try
            {
                int test = Convert.ToInt16(day.Text);
                test = Convert.ToInt16(month.Text);
                test = Convert.ToInt16(year.Text);
            }
            catch { new Exception("Date of Birth entry data is invalid..." + day + "/" + month + "/" + year); }

            /*
             *                      if ( AccountType. Text. Contains ( "Normal" ) ) type = 1;
             *                      if ( AccountType. Text. Contains ( "Savings" ) ) type = 2;
             *                      if ( AccountType. Text. Contains ( "Deposit" ) ) type = 3;
             *                      if ( AccountType. Text. Contains ( "Business" ) ) type = 4;
             */
            if (day.Text == "" | month.Text == "" | year.Text == "")
            {
                MessageBox.Show("The DOB date you have entered is not valid... Please correct this", " New Customer entry System");
                return;
            }
            if (Convert.ToInt16(day.Text) < 0 | Convert.ToInt16(day.Text) > 31 | Convert.ToInt16(month.Text) < 0 | Convert.ToInt16(month.Text) > 12
                | Convert.ToInt16(year.Text) < 1920 | Convert.ToInt16(year.Text) > DateTime.Now.Year)
            {
                MessageBox.Show("The DOB date you have entered is not valid... Please correct this", " New Customer entry System"); return;
            }
            string dob = day.Text + "/" + month.Text + "/" + year.Text;

            /// make sure our DOB data is sound, else we crqash everywhere
            try { DateTime DOB = Convert.ToDateTime(dob); }
            catch
            { MessageBox.Show("The DOB date you have entered is not valid... Please correct this", " New Customer entry System"); return; }
            if (lname.Text == "")
            {
                MessageBox.Show("You must enter a valid Last Name... Please correct this", " New Customer entry System"); return;
            }
            if (town.Text == "")
            {
                MessageBox.Show("You must enter a valid Town... Please correct this", " New Customer entry System"); return;
            }
            if (county.Text == "")
            {
                MessageBox.Show("You must enter a valid County... Please correct this", " New Customer entry System"); return;
            }
            if (pcode.Text == "")
            {
                MessageBox.Show("You must enter a valid PostCode... Please correct this", " New Customer entry System"); return;
            }

            if (!dirty)
            {
                MessageBox.Show("No changes appear to have been made, so saving it is not required", "Data Validation Warning ");
                return;
            }
            if (Cust != null)
            {
                // first grab the ArrayList entry index using original data
                int index = DataArray.ArrayFindCust(Cust);
                if (index == -1)
                {
                    MessageBox.Show("This Customer account details cannot be found in ArrayList...,", "Customer FULL Edit facility");
                    return;
                }
                // go ahead and update the object
                Cust.FirstName    = fname.Text;
                Cust.LastName     = lname.Text;
                Cust.Address1     = addr1.Text;
                Cust.Address2     = addr2.Text;
                Cust.Town         = town.Text;
                Cust.County       = county.Text;
                Cust.PostCode     = pcode.Text;
                Cust.PhoneNumber  = tel.Text;
                Cust.MobileNumber = mob.Text;


                // Update Customer Object on disk
                Customer.WriteCustObjectToDiskAndText(Cust, Cust.FullFileName);
                // update  Now we can actually the ArrayList
                DataArray.CustNo.RemoveAt(index);
                DataArray.ArrayAddCust(Cust);

                /*
                 * // already updated previously
                 * // update Customer  LinkedList
                 * foreach ( var L in Customer . CustomersLinkedList )
                 * {
                 *  if ( L . CustomerNumber == Convert . ToInt32 ( AccountNo . Text ) )
                 *  {   // got it
                 *      if ( Customer . CustomersLinkedList . Contains ( L ) )
                 *      {
                 *          Customer . CustomersLinkedList . Remove ( L );
                 *          Customer . CustomersLinkedList . AddLast ( Cust );
                 *      }
                 *      break;
                 *  }
                 * }
                 */
                // get the bank account for this customer
                // and update the relevant fields
                string   s    = accountnums.SelectedItem.ToString( );
                char[]   c    = { '\t' };
                string[] opts = s.Split(c);
                Bank = Search.FindBankObjectfromBankNo(opts[0]);
                // Find the original Bank object in ArrayList
                int indx = DataArray.ArrayFindBank(Bank);
                if (indx == -1)
                {
                    MessageBox.Show("This Bank  account details cannot be found in ArrayList...,", "Customer FULL Edit facility");
                    return;
                }
                try
                {
                    DataArray.BankNo.RemoveAt(indx);
                    // I do this in case the value is formatted eg : 1,235.76 !!  which definitely does not compuute easily !!
                    Bank.Balance      = Convert.ToDecimal(Convert.ToDecimal(AccountBalance.Text).ToString( ));
                    Bank.InterestRate = Convert.ToDecimal(Interest.Text);
                    // save the changes to our bank account
                    SerializeData.WriteBankAccountToDiskAndText(Bank, Bank.FullFileName);
                }
                catch
                {
                    MessageBox.Show("This Bank  account details cannot be updated , Data system is NOW inconsistent !...,", "Customer FULL Edit facility");
                    return;
                }
                // Now we can update ArrayList safely
                if (indx != -1)
                {
                    DataArray.ArrayAddBank(Bank);
                }
                // Write a transaction record too....
                BankTransaction newbankaccount = new BankTransaction( );
                newbankaccount.TransDate         = DateTime.Now;
                newbankaccount.AccountType       = Bank.AccountType;
                newbankaccount.CustAccountNumber = Bank.CustAccountNumber;
                newbankaccount.BankAccountNumber = Bank.BankAccountNumber;
                newbankaccount.Transamount       = Bank.Balance;
                newbankaccount.Notes             = "Opening Balance";
                newbankaccount.Status            = Bank.Status;
                BankTransaction.allBankTransactions.AddLast(newbankaccount);

                //our TWO hash tables do not hold any data that can be changed

                // update the interest  in BankAccount LinkedList in case it hs been chnaged
                foreach (var BL in BankAccount.BankAccountsLinkedList)
                {
                    if (BL.CustAccountNumber == Convert.ToInt32(AccountNo.Text))
                    {
                        BL.InterestRate = Convert.ToDecimal(Interest.Text);                                 // this is the ONLY thing we can update in a bank account
                        break;
                    }
                }
                dirty = false;
            }
            MessageBox.Show("This Customer account details have been updated successfully...,", "Customer FULL Edit facility");
        }
コード例 #7
0
        //****************************************************************************************************************************
        // this handles making a deposit call. creating the unique a/c #...
        // and creates a transaction record, and adds it to the linkedlist
        //**********************************************************************************************************//
        public static BankAccount CreateNewBankAccount(BankAccount bank, string CustNo, Int16 accounttype, decimal amount, decimal interest, string reason = "")
        //**********************************************************************************************************//
        {
            // create unique account number and set it in the account.
            bank.BankAccountNumber = GetBankAccountNumberSeed();// this post increments it's value internally
            bank.CustAccountNumber = Convert.ToInt32(CustNo);
            bank.Balance           = amount;
            bank.AccountType       = accounttype;
            bank.DateOpened        = DateTime.Today.Date;
            bank.InterestRate      = interest;
            //
            //This call increments the file numbering seed data
            bank.FileName = "BankObject" + bank.BankAccountNumber + ".bnk";
            // add full filename to the object
            bank.FullFileName = BankAccount.ReadBankFilePath() + bank.FileName;

            //This call increments the total banks seed data
            // Even though we do NOT need its content here.
            IncrementTotalBanks();

            // Ensure we save the file to disk for the Bank  object itself
            SerializeData.WriteBankAccountToDiskAndText(bank, bank.FullFileName);

            BankTransaction newbankaccount = new BankTransaction();

            newbankaccount.TransDate         = DateTime.Now;
            newbankaccount.AccountType       = bank.AccountType;
            newbankaccount.CustAccountNumber = bank.CustAccountNumber;
            newbankaccount.BankAccountNumber = bank.BankAccountNumber;
            newbankaccount.Transamount       = (decimal)bank.Balance;
            if (reason == "")
            {
                newbankaccount.Notes = "Opening Balance";
            }
            else
            {
                if (reason.Contains("Secondary Bank account  for Customer"))
                {
                    reason += bank.BankAccountNumber.ToString();
                }
                newbankaccount.Notes = reason;
            }
            newbankaccount.Status = bank.Status;
            // Add a transaction record
            BankTransaction.allBankTransactions.AddLast(newbankaccount);
            BankAccountsLinkedList.AddLast(bank);
            DataArray.ArrayAddBank(bank);
            // Update our new Dictionary system
            if (BankAccount.BankDict != null)
            {
                if (!BankAccount.BankDict.ContainsKey(bank.BankAccountNumber))
                {
                    BankAccount.BankDict.Add(bank.BankAccountNumber, bank);
                }
            }
            // This saves the bank LinkedList to both an object file and a Text file
            Lists.SaveAllBankAccountListData();

            //Add data ot our TWO hash tables
            // First the Customer hash tables
            try
            {
                if (CustomerBalanceHashTable.FindHashCustBalEntry(bank.CustAccountNumber.ToString()))
                {
                    CustomerBalanceHashTable.DeleteHashCustBalEntry(bank.CustAccountNumber.ToString());
                }
                CustomerBalanceHashTable.AddHashCustBalEntry(bank.CustAccountNumber.ToString(), bank.Balance);

                if (CustomerFileHashTable.CustFileNoHashTable.ContainsKey(bank.CustAccountNumber))
                {
                    CustomerFileHashTable.CustFileNoHashTable.Remove(bank.CustAccountNumber.ToString());
                }
                CustomerFileHashTable.CustFileNoHashTable.Add(bank.CustAccountNumber.ToString(), bank.FullFileName.ToString());
            }
            catch
            {
            }
            BankArrayChangedEvent?.Invoke(bank, "NEW BANKACCOUNT");
            return(bank);
        }
コード例 #8
0
ファイル: Lists.cs プロジェクト: chopperaddict/BankTestSystem
        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);
                            if (BankAccount.BankDict != null)
                            {
                                if (!BankAccount.BankDict.ContainsKey(B.BankAccountNumber))
                                {
                                    BankAccount.BankDict.Add(B.BankAccountNumber, B);
                                }
                            }
                            SerializeData.WriteBankAccountToDiskAndText(B, fi);
                            count++;
                            break;
                        }
                    }
                    // save linked list to disk in text format
                    Lists.SaveAllBankAccountListData( );
                }
            }
            return(count);
        }