public void Run() { BankFileHandler myBankFileHandler = new BankFileHandler(); Bank myBank; try { myBank = myBankFileHandler.ReadBankData("C:\\Users\\ellen\\source\\repos\\" + "Tidigare kurser\\C-sharp\\Inlämningsuppgifter" + "\\BankApp_Inlamn2\\" + "BankApp_Inlamn2\\bankdata.txt"); } catch (FileNotFoundException) { Console.WriteLine("FileNotFoundException: Filen hittades inte"); throw; } do { PrintMenu(); SwitchForMenuChoice(myBank, myBankFileHandler); } while (runBank); }
public void SwitchForMenuChoice(Bank bank, BankFileHandler fileHandler) { switch (ParseMenuChoice()) { case 0: Console.WriteLine("*Avsluta och spara*"); fileHandler.WriteBankData(bank); Thread.Sleep(8000); runBank = false; break; case 1: Console.WriteLine("*Sök kund*"); StringParseForCustomerSearch(bank); break; case 2: Console.WriteLine("*Visa kundbild*"); bool found = false; do { Customer customerProfile = bank.FindCustomerOnAccountOrCustomerId(bank); if (customerProfile != null) { PrintCustomerProfile(customerProfile); decimal totalSaldo = PrintAccountsAndTotal(customerProfile, bank); found = true; } } while (!found); break; case 3: Console.WriteLine("*Skapa kund*"); Customer newCustomer = ReadDataForNewCustomer(); bank.CreateNewCustomerAndAccountIds(newCustomer); break; case 4: Console.WriteLine("*Ta bort kund*"); Customer customerProfileToShow = bank.FindCustomerOnAccountOrCustomerId(bank); if (customerProfileToShow != null) { PrintCustomerProfile(customerProfileToShow); //fixa bank.DeleteCustomer(customerProfileToShow, bank); } break; case 5: Console.WriteLine("*Skapa konto*"); customerProfileToShow = bank.FindCustomerOnAccountOrCustomerId(bank); PrintCustomerProfile(customerProfileToShow); int customerId = customerProfileToShow.CustomerId; Account newAccount = bank.CreateNewAccount(customerId); break; case 6: Console.WriteLine("*Ta bort konto*"); customerProfileToShow = bank.FindCustomerOnAccountOrCustomerId(bank); PrintReducedCustomerProfile(customerProfileToShow); decimal total = PrintAccountsAndTotal(customerProfileToShow, bank); Console.WriteLine("\nKONTO ATT RADERA"); int searchedAccountId = IntParseToSearchAccount(bank); bank.DeleteAccount(searchedAccountId); break; case 7: Console.WriteLine("*Insättning*"); Console.WriteLine("TILL: "); int toAccount = IntParseToSearchAccount(bank); decimal amount = ParseForDepositAmount(toAccount, bank); break; case 8: Console.WriteLine("*Uttag*"); Console.WriteLine("FRÅN: "); int fromAccount = IntParseToSearchAccount(bank); amount = ParseForWithDrawAmount(fromAccount, bank); break; case 9: Console.WriteLine("*Överföring*"); Console.WriteLine("FRÅN: "); fromAccount = IntParseToSearchAccount(bank); Console.WriteLine("TILL: "); toAccount = IntParseToSearchAccount(bank); amount = ParseForTransactionAmount(fromAccount, toAccount, bank); break; default: Console.WriteLine("*Default case*"); break; } }