private static bool CheckAmountInput(string amount, string userName) // eos position 6
        {
            bool    isNotDecimal = false;
            decimal num          = 0.00m;

            if (!decimal.TryParse(amount, out num))
            {
                Console.Clear();
                string message = "Not valid input!";
                ConsoleLayout.Attention(message, 0);

                ConsoleLayout.Position(2);
                Console.WriteLine("To choose a correct amount please press 'Enter'");

                ConsoleLayout.Position(4);
                Console.WriteLine("To go back to menou please type 'M' and press enter");

                string message1 = "What's this?";
                ConsoleLayout.Speech(message1, -4);

                ConsoleLayout.Position(6);
                string userinput = Convert.ToString(Console.ReadLine());


                if ((userinput == "M") || (userinput == "m"))
                {
                    ShowMenus.ChooseUser(userName);
                }

                isNotDecimal = true;
                Console.Clear();
            }
            return(isNotDecimal);
        }
        private static bool CheckUsernameToTransfer(string userName, string userToTransfer)// eos position 6
        {
            string query           = "SELECT COUNT (username) FROM users WHERE username = '******'";
            int    result          = Convert.ToInt32(AddQuerryInt(query));
            bool   invalidUsername = false;

            if (result == 0.000)
            {
                Console.Clear();

                string message = "The user you are looking for does not exists.";
                ConsoleLayout.Attention(message, 0);

                ConsoleLayout.Position(2);
                Console.WriteLine("To choose an other username please press 'Enter'");

                ConsoleLayout.Position(4);
                Console.WriteLine(" To go back to menou please type 'M'");

                string message1 = "Who's that?";
                ConsoleLayout.Speech(message1, -4);

                ConsoleLayout.Position(6);
                string userinput = Convert.ToString(Console.ReadLine());

                if ((userinput == "M") || (userinput == "m"))
                {
                    ShowMenus.ChooseUser(userName);
                }
                invalidUsername = true;
            }
            return(invalidUsername);
        }
        public static decimal ViewOthersAccount(string userName)
        {
            string usernameToTransfer = "";

            do
            {
                Console.Clear();

                ConsoleLayout.Position(0);
                Console.WriteLine("Please choose the username account you wish to view");

                ConsoleLayout.Position(2);
                usernameToTransfer = Console.ReadLine();
            } while (CheckUsernameToTransfer(userName, usernameToTransfer));

            decimal account = 0;

            string query = "SELECT amount FROM accounts WHERE EXISTS (SELECT username FROM users WHERE (id = accounts.user_id) AND (username = '******'))";

            account = Convert.ToDecimal(AddQuerry(query));

            ConsoleLayout.Position(8);
            Console.WriteLine("USER: {0} AMOUNT: {1} ", usernameToTransfer, account);

            ConsoleLayout.Position(10);
            Console.ReadLine();
            Login.CloseConnection();

            return(account);
        }
        public static void Withdraw(string userName)
        {
            string userToWithdraw = "";
            string message1       = "Please choose the name of the user you wish to withdraw from: ";

            userToWithdraw = CheckUserToTransferMethod(userName, userToWithdraw, message1);

            string amount   = "";
            string message2 = "Please insert the amount to be withdrawn";

            amount = CheckAmountMethod(userName, amount, message2);

            decimal amountToWithdraw = Convert.ToDecimal(amount);

            string  query1 = "SELECT amount FROM accounts WHERE EXISTS (SELECT username FROM users WHERE (id = accounts.user_id) and (username = '******'))";
            decimal availableUsersAmount = Convert.ToDecimal(AddQuerry(query1));

            while (availableUsersAmount < amountToWithdraw)
            {
                Console.Clear();
                string message = "Sorry, no available amount to withdraw, try again!";
                ConsoleLayout.Attention(message, 0);
                System.Threading.Thread.Sleep(2000);
                amount           = CheckAmountMethod(userName, amount, message2);
                amountToWithdraw = Convert.ToDecimal(amount);
            }

            string  query2       = "SELECT amount FROM accounts WHERE EXISTS (SELECT username FROM users WHERE (id = accounts.user_id) and (username = '******'))";
            decimal adminsAmount = Convert.ToDecimal(AddQuerry(query2));

            decimal usersNewbal  = availableUsersAmount - amountToWithdraw;
            decimal adminsNewBal = amountToWithdraw + adminsAmount;
            decimal newBalance   = 0;

            string query3 = "UPDATE accounts SET amount = " + usersNewbal + " WHERE exists (SELECT username FROM users WHERE (id = accounts.user_id) AND (username = '******')); UPDATE accounts SET amount = " + adminsNewBal + "WHERE exists (SELECT username FROM users WHERE (id = accounts.user_id) and (username = '******'))";

            ExecuteQuery(query3);
            string query4 = "SELECT amount FROM accounts WHERE EXISTS (SELECT username FROM users WHERE (id = accounts.user_id) AND (username = '******'))";

            newBalance = Convert.ToDecimal(AddQuerry(query4));

            ConsoleLayout.Position(6);
            Console.WriteLine("Transaction was successfully completed!");
            ConsoleLayout.Position(8);
            Console.WriteLine("New bank balance: {0} euros", newBalance);
            System.Threading.Thread.Sleep(3000);

            Login.CloseConnection();

            DateTime    time        = DateTime.Now;
            BankAccount Transaction = new BankAccount(time, "admin", amountToWithdraw, KindOfTransaction.Withdrawal, userToWithdraw);

            BankAccount.AddList("admin", Transaction);
        }
        public static void DepositTo(string userName)
        {
            string receiversUsername = "";
            string message           = "Please enter the username you wish to deposit to: ";

            receiversUsername = CheckUserToTransferMethod(userName, receiversUsername, message);

            string amount   = "";
            string message2 = "Please enter the amount you wish to transfer: ";

            amount = CheckAmountMethod(userName, amount, message2);

            decimal amountToTransfer = Convert.ToDecimal(amount);

            string  query1 = "SELECT amount FROM accounts WHERE EXISTS(SELECT username FROM users WHERE id = accounts.user_id AND username = '******')";
            decimal availableDepositersAmount = Convert.ToDecimal(AddQuerry(query1));

            while (availableDepositersAmount < amountToTransfer)
            {
                Console.Clear();
                string message1 = "Sorry, no available amount to transfer, try again!";
                ConsoleLayout.Attention(message1, 0);
                System.Threading.Thread.Sleep(2000);
                amount           = CheckAmountMethod(userName, amount, message2);
                amountToTransfer = Convert.ToDecimal(amount);
            }

            string  query2           = "SELECT amount FROM accounts WHERE EXISTS(SELECT username FROM users WHERE id = accounts.user_id AND username = '******')";
            decimal receiversAccount = Convert.ToDecimal(AddQuerry(query2));

            decimal depositorsNewbal = availableDepositersAmount - amountToTransfer;
            decimal receiversNewBal  = receiversAccount + amountToTransfer;
            decimal newBalance       = 0;

            string query3 = "UPDATE accounts SET amount = " + depositorsNewbal + " WHERE EXISTS (SELECT username FROM users WHERE (id = accounts.user_id) AND (username = '******')); UPDATE accounts SET amount = " + receiversNewBal + "WHERE exists (SELECT username FROM users WHERE (id = accounts.user_id) and (username = '******'))";

            ExecuteQuery(query3);
            string query4 = "SELECT amount FROM accounts WHERE EXISTS (SELECT username FROM users WHERE (id = accounts.user_id) AND (username = '******'))";

            newBalance = Convert.ToDecimal(AddQuerry(query4));
            ConsoleLayout.Position(8);
            Console.WriteLine("Transaction was successfully completed!");
            ConsoleLayout.Position(9);
            Console.WriteLine("New bank balance: {0}", newBalance);
            System.Threading.Thread.Sleep(3000);

            Login.CloseConnection();

            DateTime    time        = DateTime.Now;
            BankAccount Transaction = new BankAccount(time, userName, amountToTransfer, KindOfTransaction.Deposit, receiversUsername);

            BankAccount.AddList(userName, Transaction);
        }
        public static decimal ViewMyAccount(string username)
        {
            string  query   = "SELECT amount FROM accounts WHERE EXISTS (SELECT username FROM users WHERE (id = accounts.user_id) AND (username = '******'))";
            decimal account = Convert.ToDecimal(AddQuerry(query));

            ConsoleLayout.Position(0);
            Console.WriteLine("You current balance is: {0}", account);

            ConsoleLayout.Position(2);
            Console.ReadLine();
            Login.CloseConnection();
            return(account);
        }
        private static string CheckAmountMethod(string userName, string amount, string message)
        {
            do
            {
                Console.Clear();
                ConsoleLayout.Position(0);
                Console.WriteLine(message);
                //System.Threading.Thread.Sleep(2000);
                ConsoleLayout.Position(2);
                amount = Convert.ToString(Console.ReadLine());
            }while (CheckAmountInput(amount, userName));

            return(amount);
        }
        private static string CheckUserToTransferMethod(string userName, string receiversUsername, string message)
        {
            do
            {
                Console.Clear();

                ConsoleLayout.Position(0);
                Console.WriteLine(message);

                ConsoleLayout.Position(2);
                receiversUsername = Convert.ToString(Console.ReadLine());
            }while (CheckUsernameToTransfer(userName, receiversUsername));

            return(receiversUsername);
        }
        public static void Welcome()
        {
            Console.BackgroundColor = ConsoleColor.DarkMagenta;
            Console.Clear();
            Console.ForegroundColor = ConsoleColor.White;

            Login.EncryptPasswordOnSQL();
            string title = @"      



                                X
                                X X
                                X X X
                         XXXXXXXX X X
                           XXXXXXXX X         C#X                C#X
                             XXXXXXXX       XXXXXXX            XXXXXXXX
                                     X    XXX      XXX       XXX      XXX
                                       X XX          XXX   XXX          XX
                                        XX              XXX              XX
                                        XX               X               XX
                                        XX     WELCOME                   XX
                                         XX          TO                 XX
                                          XXX         BEAUTY-LINE     XXX
                                           XXXX                     XXXX
                                              XC#X                XC#X
                                                 XXX             XXXX
                                                    XXX        XXX    X
                                                       XX     XX        X
                                                         XXXXX            X X
                                                          C#               C#X
                                                                          XXC#X 
                                MORE HEALTH                                        );(
                                      MORE BEAUTY                .-.     .-.     .           
                                            MORE WELLNESS ... _.'   `._.'   `._.'       
                                ";



            Console.WriteLine(title);
            string message = "Hello gorgeous girl!!!\nWelcome to beauty line!";

            ConsoleLayout.Speech(message);
            Console.Clear();
        }
        public static void ExitApplication(string userName)
        {
            ConsoleLayout.Position(0);
            string title = @"
                                      _                _                
                                     | |              | |            |||
                                     | |         _    | |         _  |||
                                     |/ \_|   | |/    |/ \_|   | |/  |||
                                      \_/  \_/|/|__/   \_/  \_/|/|__/ooo
                                             /|               /|        
                                             \|               \|        ";

            Console.WriteLine(title);
            string message = "Bye bye" + userName;

            ConsoleLayout.Speech(message);
            ConsoleLayout.Position(12);
            Environment.Exit(0);
        }
Example #11
0
        public static void SendToFile(string user)
        {
            List <BankAccount> listBankAccount = new List <BankAccount>();
            BankAccount        transaction     = new BankAccount();

            listBankAccount = UsersMenu.listBankAccount;

            StreamWriter tw = new StreamWriter(@"C:\Users\Antonia\Desktop\BankTransactionsProject\Transaction_Statements\" + FileName(user) + ".txt");

            using (tw)
            {
                foreach (BankAccount s in listBankAccount)
                {
                    tw.WriteLine(s);
                }
            }

            Console.Clear();
            ConsoleLayout.Position(0);
            Console.WriteLine("Your statement has been sent to your Bank Account Statements!");
            Console.ReadLine();
        }
        public static void CheckUser(SqlConnection sqlconn)
        {
            Welcome();
            int result = 0;
            int i      = 2;

            do
            {
                // Console.WriteLine("{0," + Console.WindowWidth / 2 + "}", " ");
                ConsoleLayout.Position(0);
                Console.WriteLine("Please enter your username");

                ConsoleLayout.Position(2);
                string userName = Convert.ToString(Console.ReadLine());

                ConsoleLayout.Position(4);
                Console.WriteLine("Please enter your password");

                ConsoleLayout.Position(6);
                string passWord = GenerateSHA256String(Hide());


                //sc.Parameters.AddWithValue("@password", GetHashedText(pass.Text));

                SqlCommand cmd = new SqlCommand("SELECT COUNT (*) FROM users WHERE username = @username AND password = @password", sqlconn);
                cmd.Parameters.AddWithValue("@username", userName);
                cmd.Parameters.AddWithValue("@password", passWord);
                result = (int)cmd.ExecuteScalar();

                if (result > 0)
                {
                    ConsoleLayout.Position(10);
                    Console.WriteLine("Successful Connection");

                    System.Threading.Thread.Sleep(1000);
                    Console.Clear();
                    ShowMenus.ChooseUser(userName);
                    break;
                }
                else if (i == 0)
                {
                    string message1 = "Where is your mind?";
                    ConsoleLayout.Speech(message1, 0);
                    string message = "Sorry, invalid user!!!";
                    ConsoleLayout.Attention(message, 10);

                    ConsoleLayout.Position(12);
                    Environment.Exit(0);
                }
                else
                {
                    i--;
                    string message = "Unsuccessfull Connection";
                    ConsoleLayout.Attention(message, 10);
                    ConsoleLayout.Position(12);
                    Console.WriteLine("Please try again, {0} tries left!!!", i + 1);

                    System.Threading.Thread.Sleep(1000);
                    Console.Clear();
                }
            }while ((result == 0) && (i >= 0));
        }
Example #13
0
        public static void ChooseUser(string userName)
        {
            if ((userName == "admin") || (userName == "ADMIN"))
            {
                string[] menuItems = { "View my account", "View Members’ bank accounts", "Deposit to Member's bank account", "Withdaw from Member's bank account", "Send to file today's statement", "Exit the application" };

                short          curItem = 0, c;
                ConsoleKeyInfo key;
                do
                {
                    Console.Clear();

                    ConsoleLayout.Position(0);
                    Console.WriteLine("~*~*~*~  Hello {0}!  ~*~*~*~ \t", userName);

                    int leftOffSet = (Console.WindowWidth / 3) - 20;
                    int topOffSet  = (Console.WindowHeight / 3) + 1;
                    Console.SetCursorPosition(leftOffSet, topOffSet);
                    Console.WriteLine("Please Choose an action to perform and press enter \t\t\t \n");

                    for (c = 0; c < menuItems.Length; c++)
                    {
                        if (curItem == c)
                        {
                            Console.BackgroundColor = ConsoleColor.Yellow;
                            Console.ForegroundColor = ConsoleColor.DarkGray;

                            //Console.Write(String.Format("{0," + Console.WindowWidth / 2 + "}", ">> "));
                            Console.WriteLine(String.Format("{0," + Console.WindowWidth / 2 + "}", menuItems[c]));
                            //Console.Write(">> ");
                            //Console.WriteLine(menuItems[c]);

                            Console.BackgroundColor = ConsoleColor.DarkMagenta;
                            Console.ForegroundColor = ConsoleColor.White;
                        }
                        else
                        {
                            Console.WriteLine(String.Format("{0," + Console.WindowWidth / 2 + "}", menuItems[c]));
                            //Console.WriteLine(menuItems[c]);
                        }
                    }
                    Console.WriteLine("\b");

                    key = Console.ReadKey(true);

                    if (key.Key.ToString() == "DownArrow")
                    {
                        curItem++;
                        if (curItem > menuItems.Length - 1)
                        {
                            curItem = 0;
                        }
                    }
                    else if (key.Key.ToString() == "UpArrow")
                    {
                        curItem--;
                        if (curItem < 0)
                        {
                            curItem = Convert.ToInt16(menuItems.Length - 1);
                        }
                    }
                } while (key.KeyChar != 13);

                switch (curItem)
                {
                case 0:
                    Console.Clear();
                    UsersMenu.ViewMyAccount(userName);
                    ChooseUser(userName);
                    break;

                case 1:
                    Console.Clear();
                    UsersMenu.ViewOthersAccount(userName);
                    ChooseUser(userName);
                    break;

                case 2:
                    Console.Clear();
                    UsersMenu.DepositTo(userName);
                    ChooseUser(userName);
                    break;

                case 3:
                    Console.Clear();
                    UsersMenu.Withdraw(userName);
                    ChooseUser(userName);
                    break;

                case 4:
                    BankAccount.FileName(userName);
                    BankAccount.SendToFile(userName);
                    ChooseUser(userName);
                    Console.Clear();
                    break;

                case 5:
                    Console.Clear();
                    UsersMenu.ExitApplication(userName);
                    //System.Threading.Thread.Sleep(2000);
                    //Environment.Exit(0);
                    break;
                }
            }
            else
            {
                string[] menuItems = { "View my account", "Deposit to Cooperative’s internal bank account", "Deposit to Member's bank account", "Send to file today's statement", "Exit the application" };

                short          curItem = 0, c;
                ConsoleKeyInfo key;
                do
                {
                    Console.Clear();

                    ////Console.WriteLine(String.Format("{0," + Console.WindowWidth / 3 + "}", "\tHello {0}!"), userName);
                    ConsoleLayout.Position(0);
                    Console.WriteLine("~*~*~*~  Hello {0}!  ~*~*~*~ \t", userName);

                    ////Console.WriteLine(String.Format("{0," + Console.WindowWidth / 2 + "}", "Please Choose an action to perform and press enter"));
                    int leftOffSet = (Console.WindowWidth / 3) - 20;
                    int topOffSet  = (Console.WindowHeight / 3) + 2;
                    Console.SetCursorPosition(leftOffSet, topOffSet);
                    Console.WriteLine("Please Choose an action to perform and press enter \t\t\t \n");

                    for (c = 0; c < menuItems.Length; c++)
                    {
                        if (curItem == c)
                        {
                            Console.BackgroundColor = ConsoleColor.Yellow;
                            Console.ForegroundColor = ConsoleColor.DarkGray;

                            //Console.Write(String.Format("{0," + Console.WindowWidth / 2 + "}", ">> "));
                            Console.WriteLine(String.Format("{0," + Console.WindowWidth / 2 + "}", menuItems[c]));
                            //Console.Write(">> ");
                            //Console.WriteLine(menuItems[c]);

                            Console.BackgroundColor = ConsoleColor.DarkMagenta;
                            Console.ForegroundColor = ConsoleColor.White;
                        }
                        else
                        {
                            Console.WriteLine(String.Format("{0," + Console.WindowWidth / 2 + "}", menuItems[c]));
                            //Console.WriteLine(menuItems[c]);
                        }
                    }
                    Console.WriteLine("\b");

                    key = Console.ReadKey(true);

                    if (key.Key.ToString() == "DownArrow")
                    {
                        curItem++;
                        if (curItem > menuItems.Length - 1)
                        {
                            curItem = 0;
                        }
                    }
                    else if (key.Key.ToString() == "UpArrow")
                    {
                        curItem--;
                        if (curItem < 0)
                        {
                            curItem = Convert.ToInt16(menuItems.Length - 1);
                        }
                    }
                } while (key.KeyChar != 13);

                switch (curItem)
                {
                case 0:
                    Console.Clear();
                    UsersMenu.ViewMyAccount(userName);
                    ChooseUser(userName);
                    break;

                case 1:
                    Console.Clear();
                    UsersMenu.DepositToCooperative(userName);
                    ChooseUser(userName);
                    break;

                case 2:
                    Console.Clear();
                    UsersMenu.DepositTo(userName);
                    ChooseUser(userName);
                    break;

                case 3:
                    Console.Clear();
                    BankAccount.FileName(userName);
                    BankAccount.SendToFile(userName);
                    ChooseUser(userName);
                    break;

                case 4:
                    Console.Clear();
                    UsersMenu.ExitApplication(userName);
                    break;
                }
            }
        }