Example #1
0
        //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);
        }
Example #2
0
        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);
        }
Example #3
0
        public static void Vault()
        {
            string            filepath = (@"C:\Users\Giannis\Documents\accounts.txt");
            Read_Write_toFile read     = new Read_Write_toFile();

            string[,] accountlist = read.ReadFile(filepath);
            List <double> vault = new List <double>();

            for (int i = 0; i < accountlist.GetLength(0); i++)
            {
                vault.Add(double.Parse(accountlist[i, 3]));
            }
            double sum = vault.Sum();

            Console.WriteLine("The bank vault contains {0} SEK\n", sum);
        }
Example #4
0
        public void Display()
        {
            string            filepath = (@"C:\Users\Giannis\Documents\accounts.txt");
            Read_Write_toFile read     = new Read_Write_toFile();

            string[,] accountlist = new string[0, 0];
            accountlist           = read.ReadFile(filepath);
            for (int i = 0; i < accountlist.GetLength(0); i++)
            {
                string s1 = accountlist[i, 0];
                string s2 = accountlist[i, 1];
                string s3 = accountlist[i, 2];
                string s4 = accountlist[i, 3];
                Console.WriteLine("{0}  --  {1}  --  {2}  --  {3}", s1, s2, s3, s4);
            }
            Console.WriteLine("");
        }
Example #5
0
        public void Display()
        {
            string            filepath = (@"C:\Users\Giannis\Documents\accounts.txt");
            Read_Write_toFile read     = new Read_Write_toFile();

            string[,] accountlist = read.ReadFile(filepath);
            for (int i = 0; i < accountlist.GetLength(0); i++)
            {
                string s1 = accountlist[i, 0];
                string s2 = accountlist[i, 1];
                string s3 = accountlist[i, 2];
                string s4 = accountlist[i, 3];
                Console.WriteLine("{0}  --  {1}  --  {2}  --  {3}", s1, s2, s3, s4);
            }
            Console.WriteLine("");
            //var dateTime = DateTime.Now;
            //int year = dateTime.Year;
            //int month = dateTime.Month;
            //int day = dateTime.Day;
            //var date = string.Format("{0}/{1}/{2}", year, month, day);
            //Console.WriteLine(date);
        }
Example #6
0
        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);
        }
Example #7
0
        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);
        }
Example #8
0
        static void Main(string[] args)
        {
            string            filepath = (@"C:\Users\Giannis\Documents\accounts.txt");
            Account           test     = new Account();
            Read_Write_toFile read     = new Read_Write_toFile();

            string[,] accountlist = read.ReadFile(filepath);
            bool exit = false;

            while (!exit)
            {
                Console.WriteLine("[1] Add account \n[3] Transfer amount \n[6] Show accounts \n[7] Close account \n[8] Show bank vault \n[X] Close the program");
                Console.Write("\nChoose an option: ");
                string option = Console.ReadLine();
                switch (option)
                {
                case "1":
                    Console.Clear();
                    test.AddAccount(accountlist);
                    break;

                case "3":
                    Console.Clear();
                    //Console.Write("From account number: \t");
                    //int from = int.Parse(Console.ReadLine());
                    //Console.Write("Enter amount: \t\t");
                    //double amount = double.Parse(Console.ReadLine());
                    //Console.Write("To account number: \t");
                    //int to = int.Parse(Console.ReadLine());
                    //foreach (Account acc in accountlist)
                    //{
                    //    if (acc.Number==from)
                    //    {
                    //        acc.Withdraw(amount);
                    //    }
                    //}
                    break;

                case "6":
                    Console.Clear();
                    test.Display();
                    break;

                case "7":
                    Console.Clear();
                    test.DeleteAccount();
                    break;

                case "8":
                    Console.Clear();

                    break;

                case "x":
                case "X":
                    exit = true;
                    break;

                default:
                    Console.Clear();
                    break;
                }
            }
            Console.ReadLine();
        }