Esempio n. 1
0
 public static BankAccount FindBankObjectfromCustNo(Int32 CustAccountNo)
 //*******************************************************************************************************************************************
 {           // now we can shuffle thru the hashtable itself to find the Object file to load - SuperFast
     foreach (BankAccount v in BankAccount.BankAccountsLinkedList)
     {
         if (v.CustAccountNumber == CustAccountNo)
         {
             // got it, so load it into memory
             Int32       BankAccountNumber = v.BankAccountNumber;
             string      path = v.FullFileName.ToString( );
             BankAccount B    = SerializeData.ReadBankAccountFromDisk(path);
             return(B);
         }
     }
     return(null);
 }
        //******************************************************************************************//

        //************************************************************************************************************************************************
        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);
        }
Esempio n. 3
0
        //************************************************************************************************************************************************
        public static void ReWriteBankLinkedList( )
        //************************************************************************************************************************************************
        {
            // iterate thru bankaccount objects and add threm to our linkedList
            string dir = BankAccount.ReadBankFilePath( );

            string[] files = System.IO.Directory.GetFiles(dir, "*.bnk");
            // iterate thru all the files on disk, startinmg at 1
            // Iterate trhu them and handle as required
            int count = 0;

            foreach (var fi in files)
            {
                bool result = fi.Contains("BankObject");
                if (!result)
                {
                    continue;
                }
                {
                    using
                        BankAccount B = (BankAccount)SerializeData.ReadBankAccountFromDisk(fi);

                    // As we have red it in, we need to delete it so we do not
                    // duplicate it when saving all files at end of a user sessoin.
                    if (B != null)
                    {
                        BankAccount.BankAccountsLinkedList.AddLast(B);     // Add this one to our linked list of customers.
                        BankTransaction newbankaccount = new BankTransaction(B.DateOpened, B.AccountType, B.CustAccountNumber,
                                                                             B.BankAccountNumber, B.Balance, "Customer account updated successfuly", B.Status);
                        BankTransaction.allBankTransactions.AddLast(newbankaccount);
                    }
                    count++;
                }
            }
            // save linked list to disk in text format
            Lists.SaveAllBankAccountListData( );
        }
Esempio n. 4
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);
        }
Esempio n. 5
0
        //======================================================================
        private void rewrite_Click(object sender, EventArgs e)
        //======================================================================
        {
            string output = "";

            if (notes.Text == "" || AccountNumber.Text == "" || AccountBalance.Text == "" || OpenDate.Text == "" || Interest.Text == "" || custno.Text == "")
            {
                MessageBox.Show("One or more data items are Empty - All fields must be completed before saving it ..." +
                                "\nRecommeded action is to use the DropDown list to reselect a valid Bank Account", "Data Validation ERROR");
                info.Text = "One or more data items are Empty - All fields must be completed before saving it ..."; return;
            }
            string stat;

            if (status.Text == "Active")
            {
                stat = "1";
            }
            else
            {
                stat = "0";
            }
            int type = AccountType.SelectedIndex + 1;

            // format is "Bank A/c #  + "," + Customer A/c # + "," + A/c Type + "," + Balance + "," + Date Opened (short) + "," + Date Closed (short) + "," + Interest + "," + Status (0/1)+ "\r\n"
            output  = AccountNumber.Text + "," + custno.Text + "," + type.ToString() + "," + AccountBalance.Text + ",";
            output += Convert.ToDateTime(OpenDate.Text).ToShortDateString() + "," + Convert.ToDateTime("01/01/0001").ToShortDateString() + "," + Interest.Text;
            output += "," + stat + "\r\n";
            string path = BankAccount.ReadBankFilePath();

            path += "Textfiles\\BankObject" + AccountNumber.Text + ".txt";
            if (File.Exists(path))
            {
                File.Delete(path);      // you gotta delete them first, else it appends the data constantly
            }
            File.AppendAllText(path, output);

            // update the bank object
            path  = BankAccount.ReadBankFilePath();
            path += "Bankobject" + AccountNumber.Text + ".bnk";

            // read the bank a/c in fresh from disk so it is clean
            BankAccount Bank = SerializeData.ReadBankAccountFromDisk(path);

            if (Bank == null)
            {
                MessageBox.Show("Bank Account Object file cannot be loaded (or saved)!", "Bank Object Error"); return;
            }
            Int32 bankno = Bank.BankAccountNumber;

            // update the Bank object
            Bank.AccountType = Convert.ToInt16(AccountType.SelectedIndex);
            Bank.AccountType++;// cos th reindex starts at ZERO !!
            Bank.Balance      = Convert.ToDecimal(AccountBalance.Text);
            Bank.InterestRate = Convert.ToDecimal(Interest.Text);
            string banknostring = Bank.BankAccountNumber.ToString();

            //Update the version in Bank Array
            int index = DataArray.ArrayFindBank(Bank);

            DataArray.BankNo[index] = Bank;

            // Update the version in our Bank LinkedList
            foreach (var B in BankAccount.BankAccountsLinkedList)
            {
                if (B.BankAccountNumber == bankno)
                {   // got it, rpelace with our new one
                    BankAccount.BankAccountsLinkedList.Remove(B);
                    BankAccount.BankAccountsLinkedList.AddLast(Bank);
                    break;
                }
            }
            // This saves the bank LinkedList to both an object file and a Text file
            Lists.SaveAllBankAccountListData();
            // write theBank object to disk
            SerializeData.WriteBankAccountToDiskAndText(Bank, path);
            // Add a bank Transaction
            BankTransaction newbankaccount = new BankTransaction(Bank.DateOpened, Bank.AccountType, Bank.CustAccountNumber,
                                                                 Bank.BankAccountNumber, Bank.Balance, "Bank details edited from Textfile input", Bank.Status);

            BankTransaction.allBankTransactions.AddLast(newbankaccount);
            // that's it ***ALL***all Bank Data structures have been updated
            info.Text = "Bank Account data has been fully updated throughout System";
        }