public void OnLogInfo(LoginInfoEventArgs e)
 {
     if (LogInfo != null)
     {
         LogInfo(this, e);
     }
 }
 public void LoginDBEvent(object sender, LoginInfoEventArgs e)
 {
     if (CheckTPassword(e) && CheckTUsrname(e))
     {
         CreateUserT(e);
         Console.Clear();
         App.BootstrapTeacherView(e.User);
         App.Start();
     }
     else if (CheckSPassword(e) && CheckSUsrname(e))
     {
         CreateUserS(e);
         Console.Clear();
         App.BootstrapStudentView(e.User);
         App.Start();
     }
     else
     {
         Console.SetCursorPosition(Console.WindowWidth / 2 - 10, Console.WindowHeight / 2 + 11);
         Console.ForegroundColor = ConsoleColor.Red;
         Console.WriteLine("                                   ");
         Console.SetCursorPosition(Console.WindowWidth / 2 - 10, Console.WindowHeight / 2 + 11);
         Console.WriteLine("* Wrong username or password");
         Console.SetCursorPosition(0, 0);
         Console.ForegroundColor = ConsoleColor.White;
     }
 }
        public bool CheckTUsrname(LoginInfoEventArgs e)
        {
            OleDbCommand aCommandPT = new OleDbCommand("SELECT * from Teachers", aConnection);
            bool         valid      = false;

            try
            {
                aConnection.Open();
                OleDbDataReader aReader = aCommandPT.ExecuteReader();
                while (aReader.Read())
                {
                    if (e.Username == aReader.GetString(4))
                    {
                        valid = true;
                        break;
                    }
                }
                aReader.Close();
                aConnection.Close();
            }
            catch (OleDbException eOl)
            {
                Console.WriteLine("Error: {0}", eOl.Errors[0].Message);
                aConnection.Close();
            }
            return(valid);
        }
        public void CreateUserS(LoginInfoEventArgs e)
        {
            OleDbCommand aCommand = new OleDbCommand("SELECT * from Students" +
                                                     " WHERE username = @par1 AND `password` = @par2", aConnection);

            aCommand.Parameters.AddRange(new[] {
                new OleDbParameter("@par1", e.Username),
                new OleDbParameter("@par2", e.Password)
            });

            try
            {
                aConnection.Open();
                OleDbDataReader aReader = aCommand.ExecuteReader();
                while (aReader.Read())
                {
                    int    fieldID   = aReader.GetInt32(0);
                    string firstName = aReader.GetString(1);
                    string lastName  = aReader.GetString(2);
                    string subject   = aReader.GetString(3);
                    string letterID  = aReader.GetString(7);

                    e.User = new Model.User(e.Password, e.Username, letterID,
                                            firstName, lastName, fieldID, subject);
                }
                aReader.Close();
                aConnection.Close();
            }
            catch (OleDbException ex)
            {
                Console.WriteLine("Error: {0}", ex.Errors[0].Message);
                aConnection.Close();
            }
        }