using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FaceTransfer
{
    class ConnectionClass
    {
        private static MySqlConnection connection;

        private static string server;
        private static string database;
        private static string uid;
        private static string password;


        public MySqlConnection Connection()
        {
            server = "utopia-industries-rr.c5qech8o9lgg.us-east-1.rds.amazonaws.com";
            database = "hrms";
            uid = "uind_hrms_user";
            password = "UINDHRMS01";
            string connectionString;
            connectionString = "SERVER=" + server + ";" + "DATABASE=" +
            database + ";" + "UID=" + uid + ";" + "PASSWORD=" + password + ";";

            connection = new MySqlConnection(connectionString);
            return connection;
        }
        public bool OpenConnection()
        {
            try
            {

                connection.Open();
                Console.WriteLine("Connected !");
                return true;

            }
            catch (MySqlException ex)
            {
                switch (ex.Number)
                {
                    case 0:
                        Console.WriteLine("Cannot connect to server.  Contact administrator");
                        break;

                    case 1045:
                        Console.WriteLine("Invalid username/password, please try again");
                        break;
                }
                return false;
            }
        }


        public bool CloseConnection()
        {
            try
            {
                connection.Close();
                return true;
            }
            catch (MySqlException ex)
            {
                Console.WriteLine(ex.Message);
                return false;
            }
        }
    }
}
