Ejemplo n.º 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);
                    }
                    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);
        }
Ejemplo n.º 2
0
        //*******************************************************************************************//
        public static bool DeleteBankAccount(string accountNo)
        //**********************************************************************************************************//
        {
            bool result = false;

            //First we need the relevant bank account object
            foreach (var Bank in BankAccountsLinkedList)
            {
                // check for matching AccountNumber in each BankAccount Object
                if (Bank.CustAccountNumber == Convert.ToInt32(accountNo))
                {   // Found the BankAccount object we want to close
                    // first, remove it from the LinkedList
                    BankAccountsLinkedList.Remove(Bank);
                    // now do the bankno array
                    int index = DataArray.ArrayFindBank(Bank);
                    DataArray.BankNo.RemoveAt(index);
                    // Update our new Dictionary system
                    if (BankDict != null)
                    {
                        BankDict.Remove(index);
                    }

                    // Then delete the bank object itself
                    //                    Bank.Dispose();
                    // Finally,we need to add a transactions record for this account
                    BankTransaction bt = new BankTransaction();
                    bt.TransDate         = DateTime.Now;
                    bt.AccountType       = 9;
                    bt.CustAccountNumber = Convert.ToInt32(accountNo);
                    bt.BankAccountNumber = Bank.BankAccountNumber;
                    bt.Transamount       = 0;
                    bt.Notes             = "Account has been closed";
                    bt.Status            = 2; // closed

                    BankTransaction.allBankTransactions.AddLast(bt);
                    result = true;
                    //Trigger our event
                    BankListChangedEvent?.Invoke(Bank, "BANKACCOUNT DELETED");
                    break;
                }
            }
            if (!result)
            {
                MessageBox.Show("Failed to delete the entry from the Transactions list...");
                return(false);
            }
            else
            {
                return(true);
            }
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 4
0
        //******************************************************************************************//
        // called from Deposit and withdrawl only so far  to update BankACcount LinkedList
        // This automatically updates the current Bank account Balance, so beware of doing it again elsewhere
        public static bool UpdateBankLinkedList(Int32 Bankno, decimal deposit)
        {
            bool result = false;

            foreach (var B in BankAccount.BankAccountsLinkedList)
            {
                if (B.BankAccountNumber == Bankno)
                {   // got it
                    BankAccount.BankAccountsLinkedList.Remove(B);
                    B.Balance += deposit;
                    BankAccount.BankAccountsLinkedList.AddLast(B);
                    // This saves the bank LinkedList to both an object file and a Text file
                    Lists.SaveAllBankAccountListData();
                    BankListChangedEvent?.Invoke(B, "DEPOSIT");
                    result = true;
                    break;
                }
            }
            return(result);
        }