示例#1
0
 /// <summary>
 /// MakeDeposit function is independent of any user input information from Account class constructor used for opening an bank account.
 /// It allows user login to their account page with password/username to make deposit. After deposit is made,
 /// updated user account information will be re-write into the same txt file (with the file name of "account_number.txt").
 /// </summary>
 public void MakeDeposit()
 {
     accInfo = File.ReadAllLines($"{accNum}.txt");                      //after user login and the relevent user account number was validated, open the relevent account txt file and store all account information into an string array
     Console.WriteLine($"{accInfo[4]}, enter your deposit amount : ");  //rais a prompt to ask usr enter an ammount for deposit
     Deposit    = int.Parse(Console.ReadLine());                        //store the user input deposit ammount in to Deposit property
     ValueEvent = new DepositWithDrawEvent(loadEvent.ChangeCurrentBal); //refer ChangeCurrentBal functioin in MyEvent class to ValueEvent
     ValueEvent?.Invoke(accInfo[4], "deposit", deposit);                //invoke ValueEvent to output a deposit prompt
     CurrentBalance = int.Parse(accInfo[16]) + deposit;                 //change user current balance by summing the original current balance to user input deposit
     if (deposit != 0)                                                  //if user input deposit is not 0, refer the OutputAccBal function from MyEvent class to OutputEvent, and invoke the event
     {
         OutputEvent = new OutPutCurrentBal(loadEvent.OutputAccBal);
         OutputEvent?.Invoke(accInfo[4], currentBalance);
     }
     Deposit     = int.Parse(accInfo[12]) + deposit;                       //get user total deposit ammount by summing all deposit value
     accInfo[0]  = currDTFormat[15];                                       //re-assign datetime to account info array
     accInfo[12] = deposit.ToString();                                     //re-assign total deposit value
     accInfo[16] = currentBalance.ToString();                              //re-assign current balance
     File.WriteAllLines($"{accNum}.txt", accInfo);                         //re-write all account info from arry to the account txt file
 }
示例#2
0
 /// <summary>
 /// MakeWithdraw function is independent of any user input information from Account class constructor used for opening an bank account.
 /// It allows user login to their account page with password/username to make withdraw. After withdraw is made,
 /// updated user account information will be re-write into the same txt file (with the file name of "account_number.txt").
 /// </summary>
 public void MakeWithdraw()
 {
     accInfo        = File.ReadAllLines($"{accNum}.txt");  //after user login and the user account number was validated, store all account information into an string array
     CurrentBalance = int.Parse(accInfo[16]);              //assign current balance value from array before user input the withdraw ammount
     Console.WriteLine($"{accInfo[4]}, enter your withdraw amount : ");
     Withdraw   = int.Parse(Console.ReadLine());           //get user input withdraw
     ValueEvent = new DepositWithDrawEvent(loadEvent.ChangeCurrentBal);
     ValueEvent?.Invoke(accInfo[4], "withdraw", withdraw); //rais enent
     CurrentBalance = int.Parse(accInfo[16]) - withdraw;   //change user current balance
     if (withdraw != 0)                                    //if withdraw is not 0, rais event
     {
         OutputEvent = new OutPutCurrentBal(loadEvent.OutputAccBal);
         OutputEvent?.Invoke(accInfo[4], currentBalance);
     }
     Withdraw    = int.Parse(accInfo[14]) + withdraw;                       //get the total withdraw
     accInfo[0]  = currDTFormat[15];                                        //update the array
     accInfo[14] = withdraw.ToString();
     accInfo[16] = currentBalance.ToString();
     File.WriteAllLines($"{accNum}.txt", accInfo);                          //re-write account info to its relevent txt file
 }