示例#1
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");
        }
示例#2
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);
        }