}//end of function ////Constructor for the bank class- initalises instance variables //public Bank() //{ // //creating an instance of DAL1 // DAL1 dbAccess = new DAL1(); // bankManager = new Dictionary<string, Manager>(); // bankCustomer = new Dictionary<string, Customer>(); // bankManager = dbAccess.loadManagers(); // bankCustomer = dbAccess.loadCustomers(); // atmid = "HBOS01"; // exchange = 1.12M; // timesused = 0; // withdrawls = 0; // totalbalance = 10000; // failedlogins = 0; // cards = 0; //}// end of constructor public Bank() { //creating an instance of DAL1 DAL2 dbAccess = new DAL2(); bankManager = new Dictionary<string, Manager>(); bankCustomer = new Dictionary<string, Customer>(); dbAccess.loadAllPersonData(); bankManager = dbAccess.getBankManagers(); bankCustomer = dbAccess.getBankCustomers(); atmid = "HBOS01"; exchange = 1.12M; timesused = 0; withdrawls = 0; totalbalance = 10000; failedlogins = 0; cards = 0; }// end of constructor
}//end of retrieveAllAccountData method //start if loadAllPersonData Method //loads data from database into datatables public void loadAllPersonData() { //initialising variables. DAL2 myDB; DataTable personTable; DataTable accountTable; //setting variable values myDB = new DAL2(); personTable = myDB.retrieveAllPersonData(); accountTable = myDB.retrieveAllAccountData(); //start of for loop //iterates through each row in the table and poplulates 'persontable' with values in //bank.accdb for( int i =0; i <= personTable.Rows.Count -1; i++) { //setting variables values using data from table. string id = Convert.ToString(personTable.Rows[i][0]); string fname = Convert.ToString(personTable.Rows[i][1]); string sname = Convert.ToString(personTable.Rows[i][2]); string address = Convert.ToString(personTable.Rows[i][3]); string email = Convert.ToString(personTable.Rows[i][5]); string telno = Convert.ToString(personTable.Rows[i][4]); string role = Convert.ToString(personTable.Rows[i][6]); string machinepin = Convert.ToString(personTable.Rows[i][7]); //start of if //if role is manager add new manager to table. if (role == "M") { Manager newManager = new Manager (id, fname, sname, address, email, telno, machinepin); bankManagers.Add(id, newManager); } //else if role is customer add new customer to table. else if (role == "C") { Customer newCustomer = new Customer (id, fname, sname, address, email, telno); bankCustomers.Add(id, newCustomer); }//end of elseif }//end of for loop. //start of for loop //takes data from account table and populates datatable with it //iterates through each row for (int i = 0; i <= accountTable.Rows.Count - 1; i++) { string accountNumber = Convert.ToString(accountTable.Rows[i][0]); decimal balance = Convert.ToDecimal(accountTable.Rows[i][1]); string pin = Convert.ToString(accountTable.Rows[i][2]); string id = Convert.ToString(accountTable.Rows[i][3]); //creating instance of account class, customer class Account newAccount = new Account(accountNumber, balance, pin); Customer accountCustomer = bankCustomers[id]; accountCustomer.addAccount(newAccount); }//end of loop }//end of method.