//public Account(int aNumber, string aType, string aOwner, double aBalance) //{ // this.Number = aNumber; // this.Type = aType; // this.Owner = aOwner; // this.Balance = aBalance; //} public void AddAccount() { string filepath = (@"C:\Users\Giannis\Documents\accounts.txt"); Read_Write_toFile read = new Read_Write_toFile(); string[,] accountlist = read.ReadFile(filepath); Console.Write("Enter account number:\t"); Number = int.Parse(Console.ReadLine()); Console.Write("Enter account type:\t"); Type = Console.ReadLine(); Console.Write("Enter account owner:\t"); Owner = Console.ReadLine(); Console.Write("Enter account balance:\t"); Balance = double.Parse(Console.ReadLine()); // Create a new array with the new created account string[,] newAccount = new string[, ] { { Number.ToString(), Type, Owner, Balance.ToString() } }; string[,] updatedArray = new string[accountlist.GetLength(0) + 1, newAccount.GetLength(1)]; // Copy the old accounts array and the new account into the larger array Array.Copy(accountlist, 0, updatedArray, 0, accountlist.Length); Array.Copy(newAccount, 0, updatedArray, accountlist.Length, newAccount.Length); Console.WriteLine("Account successfully created!\n"); Read_Write_toFile.WriteFile(filepath, updatedArray); }
public static void Deposit() { string filepath = (@"C:\Users\Giannis\Documents\accounts.txt"); Read_Write_toFile read = new Read_Write_toFile(); string[,] accountlist = read.ReadFile(filepath); Console.Write("To account:\t"); int to = int.Parse(Console.ReadLine()); for (int i = 0; i < accountlist.GetLength(0); i++) { if ((int.Parse(accountlist[i, 0]).Equals(to))) { Console.Write("Amount:\t\t"); double amount = double.Parse(Console.ReadLine()); if (amount > 0) { double result = double.Parse(accountlist[i, 3]); result += amount; accountlist[i, 3] = result.ToString(); Console.WriteLine("Deposit succesful!\nAccount No.{0} new balance is {1}\n", to, accountlist[i, 3]); } } } Read_Write_toFile.WriteFile(filepath, accountlist); }
public static void Transaction() { string filepath = (@"C:\Users\Giannis\Documents\accounts.txt"); Read_Write_toFile read = new Read_Write_toFile(); string[,] accountlist = read.ReadFile(filepath); Console.Write("From account:\t"); int from = int.Parse(Console.ReadLine()); for (int i = 0; i < accountlist.GetLength(0); i++) { if ((int.Parse(accountlist[i, 0]).Equals(from))) { double fromBalance = double.Parse(accountlist[i, 3]); Console.Write("To account:\t"); int to = int.Parse(Console.ReadLine()); for (int j = 0; j < accountlist.GetLength(0); j++) { if ((int.Parse(accountlist[j, 0]).Equals(to)) && (from != to)) { double toBalance = double.Parse(accountlist[j, 3]); Console.Write("Amount:\t\t"); double amount = double.Parse(Console.ReadLine()); if (amount > 0) { fromBalance -= amount; toBalance += amount; accountlist[i, 3] = fromBalance.ToString(); accountlist[j, 3] = toBalance.ToString(); Console.WriteLine("Transaction completed!\n{0} were transfered from No.{1} to No.{2}", amount, from, to); break; } } } } } Read_Write_toFile.WriteFile(filepath, accountlist); }
public void DeleteAccount() { Console.Write("Enter account number to delete: \t"); var choise = Console.ReadLine(); string filepath = (@"C:\Users\Giannis\Documents\accounts.txt"); Read_Write_toFile read = new Read_Write_toFile(); List <string> temp = read.ReadFile(filepath).Cast <string>().ToList(); int index = temp.FindIndex(a => a.Equals(choise)); if (temp.Contains(choise)) { temp.RemoveRange(index, 4); Console.WriteLine("Account No.{0} deleted successfully!\n", choise); } else { Console.WriteLine("Account number not found!\n"); } string[] accounts = temp.ToArray(); int height = accounts.GetLength(0) / 4; string[,] updatedArray = Make2DArray(accounts, height, 4); Read_Write_toFile.WriteFile(filepath, updatedArray); }