Exemplo n.º 1
0
        private static void ChangeLanguage()
        {
            Console.WriteLine(Literals.getLiterals("Input the language code or 123 to exit"));
            string pattern = "^[a-z]{2}$";

            try
            {
                string str = Console.ReadLine();
                if (str.Equals("123"))
                {
                    Console.Clear(); return;
                }
                if (Regex.IsMatch(str, pattern, RegexOptions.IgnoreCase))
                {
                    Literals.TranslateMenu(str);
                }
                else
                {
                    Console.WriteLine(Literals.getLiterals("Invalid language code pattern"));
                    Console.ReadKey(true);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(Literals.getLiterals("Invalid language code or lost internet connection"));
                Console.ReadKey(true);
            }
            Console.Clear();
        }
Exemplo n.º 2
0
        private static int RunFirstMenu()
        {
            int select = 0;

            while (select == 0)
            {
                Console.WriteLine(Literals.getLiterals("1. Change currency"));
                Console.WriteLine(Literals.getLiterals("2. Change language"));
                Console.WriteLine(Literals.getLiterals("3. Export to file"));
                Console.WriteLine(Literals.getLiterals("4. Add category"));
                Console.WriteLine(Literals.getLiterals("5. Remove category"));
                Console.WriteLine(Literals.getLiterals("6. Add account"));
                Console.WriteLine(Literals.getLiterals("7. Remove account"));
                Console.WriteLine(Literals.getLiterals("8. Transactions per month"));
                Console.WriteLine(Literals.getLiterals("9. Back"));
                try
                {
                    select = Int32.Parse(Console.ReadKey(true).KeyChar.ToString());
                    if (select < 1 || select > 9)
                    {
                        throw new Exception();
                    }
                }
                catch (Exception)
                {
                    select = 0;
                }
                Console.Clear();
            }
            return(select);
        }
Exemplo n.º 3
0
        private static int RunFirstMenu()
        {
            int select = 0;

            while (select == 0)
            {
                PrintFrontScreen();
                Console.WriteLine(Literals.getLiterals("1. Increase balance"));
                Console.WriteLine(Literals.getLiterals("2. Decrease balance"));
                Console.WriteLine(Literals.getLiterals("3. Options"));
                Console.WriteLine(Literals.getLiterals("4. Exit"));
                try
                {
                    select = Int32.Parse(Console.ReadKey(true).KeyChar.ToString());
                    if (select < 1 || select > 4)
                    {
                        throw new Exception();
                    }
                }
                catch (Exception)
                {
                    select = 0;
                }
                Console.Clear();
            }
            return(select);
        }
Exemplo n.º 4
0
 public static void PrintFrontScreen()
 {
     Console.ForegroundColor = ConsoleColor.Yellow;
     Console.Write(Literals.getLiterals("Currency") + " - " + CurrencyModule.Currency.ToUpper() + "   " + Literals.getLiterals("Total balance") + " - " + Accounts.OverAllBalance.ToString("#.##") + "   ");
     Console.ForegroundColor = ConsoleColor.Magenta;
     Console.WriteLine(Literals.getLiterals("Total expences") + " - " + Categories.TotalExpense.ToString("#.##"));
     Console.ForegroundColor = ConsoleColor.Green;
     categories.Show();
 }
Exemplo n.º 5
0
        private void ChangeBalance(int a)
        {
            int    amount = 0;
            bool   exists = false;
            string input  = "";

            while (amount <= 0 || exists == false)
            {
                Accounts.Show();
                Console.WriteLine(Literals.getLiterals("Input the name of account or it's identity describer , or 123 to exit"));
                input = Console.ReadLine();
                if (input.CompareTo("123") == 0)
                {
                    Console.Clear();
                    break;
                }
                exists = Accounts.AccountExists(input);
                if (exists)
                {
                    Console.WriteLine(Literals.getLiterals("Input amount"));
                    try
                    {
                        amount = Int32.Parse(Console.ReadLine().ToString());
                        if (amount <= 0)
                        {
                            throw new Exception();
                        }
                        if (a == 1)
                        {
                            Accounts.IncreaseAccountAmount(input, amount);
                        }
                        else if (a == -1)
                        {
                            AccountNameId = input;
                            Amount        = amount;
                        }
                    }
                    catch (Exception)
                    {
                        amount = 0;
                    }
                }
                else
                {
                    Console.WriteLine(Literals.getLiterals("Account does not exist"));
                    Console.ReadKey(true);
                }
                Console.Clear();
            }
        }
Exemplo n.º 6
0
        private void AddAccount()
        {
            string pattern = "^[A-Za-z0-9]{3,20}$";

            while (true)
            {
                Accounts.Show();
                Console.WriteLine(Literals.getLiterals("Input the name of account or it's identity describer , or 123 to exit"));
                string idName = Console.ReadLine();
                if (idName.Equals("123"))
                {
                    Console.Clear(); break;
                }
                int amount = 0;
                if (Regex.IsMatch(idName, pattern, RegexOptions.IgnoreCase))
                {
                    if (!Accounts.AccountExists(idName))
                    {
                        try
                        {
                            Console.WriteLine(Literals.getLiterals("Input amount"));
                            amount = Int32.Parse(Console.ReadLine().ToString());
                            if (amount <= 0)
                            {
                                throw new Exception();
                            }
                            Accounts.AddAccount(idName, amount);
                            Console.Clear();
                            break;
                        }
                        catch (Exception)
                        {
                            amount = 0;
                        }
                    }
                    else
                    {
                        Console.WriteLine(Literals.getLiterals("Account exists"));
                        Console.ReadKey(true);
                    }
                }
                else
                {
                    Console.WriteLine(Literals.getLiterals("Invalid account pattern"));
                    Console.ReadKey(true);
                }
                Console.Clear();
            }
        }
Exemplo n.º 7
0
        private void RemoveAccount()
        {
            string pattern = "^[A-Za-z0-9]{3,20}$";

            while (true)
            {
                Accounts.Show();
                Console.WriteLine(Literals.getLiterals("Input the name of account or it's identity describer , or 123 to exit"));
                string idName = Console.ReadLine();
                int    amount = 0;
                if (idName.Equals("123"))
                {
                    Console.Clear(); break;
                }

                if (Regex.IsMatch(idName, pattern, RegexOptions.IgnoreCase))
                {
                    if (Accounts.AccountExists(idName))
                    {
                        try
                        {
                            Accounts.RemoveAccount(idName);
                            Console.Clear();
                            break;
                        }
                        catch (Exception)
                        {
                            amount = 0;
                        }
                    }
                    else
                    {
                        Console.WriteLine(Literals.getLiterals("Account does not exist"));
                        Console.ReadKey(true);
                    }
                }
                else
                {
                    Console.WriteLine(Literals.getLiterals("Invalid account pattern"));
                    Console.ReadKey(true);
                }
                Console.Clear();
            }
        }
Exemplo n.º 8
0
 private void TransactionsPerMonth()
 {
     while (true)
     {
         try
         {
             Console.WriteLine(Literals.getLiterals("Input month"));
             int month = Int32.Parse(Console.ReadLine());
             Console.WriteLine(Literals.getLiterals("Input year"));
             int year = Int32.Parse(Console.ReadLine());
             LinkedList <Payment> linkedList = Payments.TransactionsPerMonth(month, year);
             if (linkedList == null)
             {
                 Console.WriteLine(Literals.getLiterals("Nothing to show for this month : ") + month + "." + year);
                 Console.ReadKey(true);
                 Console.Clear();
                 break;
             }
             else
             {
                 Console.WriteLine("---------------------------------------------------------------");
                 foreach (Payment pay in linkedList)
                 {
                     Console.Write(Literals.getLiterals("Account :") + " " + pay.AccountNameId + " | ");
                     Console.Write(Literals.getLiterals("Category :") + " " + pay.CategoryNameId + " | ");
                     Console.Write(Literals.getLiterals("Expence amount :") + " " + pay.Amount.ToString("#.##") + " | ");
                     Console.Write(Literals.getLiterals("Currency :") + " " + CurrencyModule.Currency.ToUpper() + " | ");
                     Console.WriteLine(Literals.getLiterals("Date :") + " " + pay.DateTime.ToString("yyyy.MM.dd.HH.mm.ss"));
                 }
                 Console.WriteLine("---------------------------------------------------------------");
                 Console.ReadKey(true);
                 Console.Clear();
                 break;
             }
         }
         catch (Exception)
         {
             Console.WriteLine(Literals.getLiterals("Only numeric input !"));
             Console.ReadKey(true);
         }
         Console.Clear();
     }
 }
Exemplo n.º 9
0
        private void RemoveCategory()
        {
            string pattern = "^[A-Za-z0-9]{3,20}$";

            while (true)
            {
                categories.Show();
                Console.WriteLine(Literals.getLiterals("Input the name of category or it's identity describer , or 123 to exit"));
                string idName = Console.ReadLine();
                if (idName.Equals("123"))
                {
                    Console.Clear(); break;
                }


                if (Regex.IsMatch(idName, pattern, RegexOptions.IgnoreCase))
                {
                    if (Categories.CategoryExists(idName))
                    {
                        Categories.RemoveCategory(idName);
                        Console.Clear();
                        break;
                    }
                    else
                    {
                        Console.WriteLine(Literals.getLiterals("Category does not exists"));
                        Console.ReadKey(true);
                    }
                    Console.Clear();
                }
                else
                {
                    Console.WriteLine(Literals.getLiterals("Invalid category pattern"));
                    Console.ReadKey(true);
                }
            }
        }
Exemplo n.º 10
0
        private static void ChangeCurrency()
        {
            string input   = "";
            string pattern = "^[a-z]{3}$";

            while (true)
            {
                Console.WriteLine(Literals.getLiterals("Input the currency code or 123 to exit"));
                input = Console.ReadLine();
                if (input.Equals("123"))
                {
                    Console.Clear(); return;
                }

                if (Regex.IsMatch(input, pattern, RegexOptions.IgnoreCase))
                {
                    //try
                    //{
                    CurrencyModule.ChangeCurrency(input);
                    Console.Clear();
                    break;
                    //}
                    // catch(Exception e)
                    //{
                    Console.WriteLine(Literals.getLiterals("Invalid currency code"));
                    Console.ReadKey(true);
                    //}
                }
                else
                {
                    Console.WriteLine(Literals.getLiterals("Invalid currency code pattern"));
                    Console.ReadKey(true);
                }
                Console.Clear();
            }
        }
Exemplo n.º 11
0
        private void DecreaseBalanceMenu()
        {
            ChangeBalance(-1);
            if (String.IsNullOrEmpty(AccountNameId))
            {
                return;
            }
            string categoryNameId = "";

            while (!Categories.CategoryExists(categoryNameId))
            {
                if (!Accounts.EnoughFunds(AccountNameId, Amount))
                {
                    Console.WriteLine(Literals.getLiterals("Not enough funds !"));
                    Console.ReadKey(true);
                    return;
                }
                categories.Show();
                Console.WriteLine(Literals.getLiterals("Input the name of category or it's identity describer , or 123 to exit"));
                categoryNameId = Console.ReadLine();
                if (categoryNameId.CompareTo("123") == 0)
                {
                    break;
                }
                if (Categories.CategoryExists(categoryNameId))
                {
                    TransactionServicecs.Transfer(AccountNameId, categoryNameId, Amount);
                }
                else
                {
                    Console.WriteLine(Literals.getLiterals("Category does not exist"));
                    Console.ReadKey(true);
                }
                Console.Clear();
            }
        }