public static void ShowAccountStatement() { string filePath = SearchAccount.SearchAccountInfo(); if (filePath != null) { SearchAccount.DisplayAccountDetails(filePath); string accountInfo = Utility.GenerateEmailBodyWithAccountInfo(filePath); string transactionInfo = Utility.GetLatestFiveTransaction(filePath); // Split account info to find the email id to which mail is supposed to be sent string[] accountInfoArray = accountInfo.Split('\n'); string[] emailLine = accountInfoArray[6].Split(' '); string sendTo = emailLine[1]; string emailBody = accountInfo + transactionInfo; Console.WriteLine(transactionInfo); Console.WriteLine("Email Statement (y/n)?"); string input = Console.ReadLine(); if (input.ToLower().Equals("y")) { Email.SendEmail(emailBody, sendTo); Console.WriteLine("Email sent successfully!..."); } } Console.WriteLine("Press any key to continue..."); Console.Read(); Console.Clear(); MainMenu.ShowMenu(); }
public static void DeleteUserAccount() { string filePath = SearchAccount.SearchAccountInfo(); if (filePath != null) { SearchAccount.DisplayAccountDetails(filePath); Console.WriteLine("Delete (y/n)?"); string input = Console.ReadLine(); if (input.ToLower().Equals("y")) { File.Delete(filePath); Console.WriteLine("Account Deleted!..."); Console.WriteLine("Press Enter to continue..."); Console.ReadLine(); } } Console.Clear(); MainMenu.ShowMenu(); }
/// <summary> /// A switch case in this method will decide what to show to the user based on the input, /// Respective methods will be called based on the input /// </summary> /// <param name="number">The Operation the user selects from the screen</param> private static void RedirectUser(int number) { switch (number) { case 1: CreateAccount.GetAccountInfoFromUser(); break; case 2: SearchAccount.DisplayAccountDetails(); break; case 3: Deposit.DepositAmount(); break; case 4: Withdraw.WithdrawAmount(); break; case 5: AccountStatement.ShowAccountStatement(); break; case 6: DeleteAccount.DeleteUserAccount(); break; case 7: Console.WriteLine("Exiting console..."); Environment.Exit(0); break; default: break; } }
/// <summary> /// The Method used to deposit to an account /// </summary> public static void DepositAmount() { int depositAmount = 0; string filePath = SearchAccount.SearchAccountInfo(); if (filePath != null) { depositAmount = GetDepositAmount(); } else { Console.Clear(); MainMenu.ShowMenu(); } ArrayList fileContents = new ArrayList(); try { using (StreamReader sr = File.OpenText(filePath)) { string s = ""; while ((s = sr.ReadLine()) != null) { fileContents.Add(s); } } // Write to the file the updated info File.WriteAllText(filePath, string.Empty); foreach (string line in fileContents) { using (StreamWriter outputFile = new StreamWriter(filePath, true)) { if (line.Contains("Account Balance: ")) { string[] arr = line.Split(' '); string balance = arr[arr.Length - 1]; int currentBalance = 0; int.TryParse(balance, out currentBalance); currentBalance += depositAmount; outputFile.WriteLine("Account Balance: " + currentBalance); } else if (line.Contains("Transaction:")) { outputFile.WriteLine(line); outputFile.WriteLine("Deposit " + depositAmount + " " + DateTime.Now.ToString("dddd, dd MMMM yyyy HH:mm:ss")); } else { outputFile.WriteLine(line); } } } Console.WriteLine("Amount Deposited"); Console.WriteLine("Press Any Key To Continue..."); Console.Read(); Console.Clear(); MainMenu.ShowMenu(); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } }
/// <summary> /// The Method used to deposit to an account /// </summary> public static void WithdrawAmount() { int withdrawAmount = 0; string filePath = SearchAccount.SearchAccountInfo(); if (filePath != null) { withdrawAmount = GetWithdrawAmount(); } else { Console.Clear(); MainMenu.ShowMenu(); } ArrayList fileContents = new ArrayList(); try { using (StreamReader sr = File.OpenText(filePath)) { string s = ""; while ((s = sr.ReadLine()) != null) { //Console.WriteLine(s); fileContents.Add(s); } } //Console.WriteLine(fileContents[1]); // Contains Account Balance Line in the txt file // Split the account balance line to get the current balance string[] accountBalanceLine = fileContents[1].ToString().Split(' '); // Check if withdrawal amount is more than current balance int accBalance; bool validWithdrawAmount = false; string strBalance = accountBalanceLine[accountBalanceLine.Length - 1]; // Balance should be in last index int.TryParse(strBalance, out accBalance); if (accBalance - withdrawAmount < 0) { // Not enough balance do { Console.WriteLine("Insufficient balance"); Console.WriteLine("Current balance is: " + accBalance); withdrawAmount = GetWithdrawAmount(); if (accBalance - withdrawAmount >= 0) { // Valid ammount validWithdrawAmount = true; } } while (validWithdrawAmount != true); } // Write to the file the updated info // Clear the file File.WriteAllText(filePath, string.Empty); foreach (string line in fileContents) { using (StreamWriter outputFile = new StreamWriter(filePath, true)) { if (line.Contains("Account Balance: ")) { string[] arr = line.Split(' '); string balance = arr[arr.Length - 1]; int currentBalance = 0; int.TryParse(balance, out currentBalance); currentBalance -= withdrawAmount; outputFile.WriteLine("Account Balance: " + currentBalance); } else if (line.Contains("Transaction:")) { outputFile.WriteLine(line); outputFile.WriteLine("Withdraw " + withdrawAmount + " " + DateTime.Now.ToString("dddd, dd MMMM yyyy HH:mm:ss")); } else { outputFile.WriteLine(line); } } } Console.WriteLine("Amount Withdrawn"); Console.WriteLine("Press any key to continue..."); Console.Read(); Console.Clear(); MainMenu.ShowMenu(); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } }