protected override void OnNavigatedTo(NavigationEventArgs e)
        {

            try
            {
                base.OnNavigatedTo(e);
                parentId = (int)e.Parameter;

                objParentViewModel = new ParentViewModel();
                objRegister = new Register();

                objRegister = objParentViewModel.getParentDetails(parentId);

                lblParentID.Text = "" + objRegister.Id;
                txtEnterNewName.Text = "" + objRegister.Name;
                txtEnterNewSurname.Text = "" + objRegister.Surname;
                txtEnterNewEmail.Text = "" + objRegister.Email;
                txtEnterNewPhoneNo.Text = "" + objRegister.PhoneNo;
                txtEnterNewPassword.Text = "" + objRegister.Password;




                base.OnNavigatedTo(e);

            }
            catch (Exception)
            {

            }


        }
        //Get object containing user details
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            try
            {
                base.OnNavigatedTo(e);
                objReg = (Register)e.Parameter;

                lblGetId.Text = "" + objReg.Id;
                lblGetName_Surname.Text = "" + objReg.Name + " " + objReg.Surname; 

            }
            catch (Exception)
            {

            }

            


        }
        //Display the ID of the parent currently logged in
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            try
            {
                base.OnNavigatedTo(e);
                getTheId = (int)e.Parameter;

                objRegister = new Register();
                objParentViewModel = new ParentViewModel();

                objRegister = objParentViewModel.getParentDetails(getTheId);


                lblParentIdenNum.Text = "" + objRegister.Name + " " +objRegister.Surname;
            }
            catch(Exception)
            {

            }
           

        }
        //This buttons controls the Login fuctionalities
        private void btnLogin1_Click(object sender, RoutedEventArgs e)
        {
            //Ojbjects for ParentViewModel and Register classes
            objParent = new ParentViewModel();
            objReg = new Register();
            objMenu = new MenuPage();

            //this.Frame.Navigate(typeof(MenuPage));
            string username = txtUsername.Text;
            string password = pwbEnterPassword.Password;

            //String ErrorMessage
            string messageToDisplay = "";
            
           

                    if ((!username.Equals("")) && (!password.Equals("")))
                    {
                        try
                        {
                            string findTheAtSign = "@";
                            string findThePeriod = ".";
                            bool isFoundAtSign = false;
                            bool isFoundPeriod = false;
                            for (int x = 0; x < username.Length; x++)
                            {
                                isFoundAtSign = username.Contains(findTheAtSign);
                                isFoundPeriod = username.Contains(findThePeriod);
                                
                            }

                            if((isFoundAtSign == true) && (isFoundPeriod == true))
                            {
                                 //Get all parent details matching user supplied information
                                var confirm = objParent.getParent(username, password);
                                if(confirm != null)
                                {

                                    this.Frame.Navigate(typeof(MenuPage), confirm.Id);
                                    int iden = Convert.ToInt32(confirm.Id);//confirm.Id;
                                    objMenu.getID(iden);

                                    messageToDisplay = "Welcome " + confirm.Name + " " + confirm.Surname +
                                                       "\nYour user ID is: " + confirm.Id;
                                    messageBox(messageToDisplay);

                                
                                
                                }
                                 else
                                {
                                    messageToDisplay = "Invalid user details entered!" +
                                                       "\nPlease ensure that the username and password entered are correct...";
                                    messageBox(messageToDisplay);
                                }

                            }
                            else
                            {
                                messageToDisplay = "Invalid email address entered!";
                                messageBox(messageToDisplay);
                            }
                                

                            
                            
                        }
                        catch(Exception ex)
                        {
                            string ErrorMessage = "Error: " + ex.Message;
                            messageBox(ErrorMessage);
                        }
                        
                    }
                    else
                    {
                        //Enter error message box here!
                        string ErrorMessage = "Please ensure that all text fields are entered!";
                        messageBox(ErrorMessage);
                        //this.Frame.Navigate(typeof(MainPage));
                        
                    }
                
           
            
            //Verify that user inputs are not empty first
        
        }
        private void btnVerifyUserDetails_Click(object sender, RoutedEventArgs e)
        {
            bool isFoundAtSign = false;
            bool isFoundPeriod = false;

            objReg = new Register();
            objParentViewModel = new ParentViewModel();
            
            getEmail = txtConfirmEmail.Text;
            getPhoneNum = txtConfirmPhoneNo.Text;

            
            if((!getEmail.Equals("")) && (!getPhoneNum.Equals("")))
            {

                //Check whether email address is correct
                string findTheAtSign = "@";
                string findThePeriod = ".";
                for (int x = 0; x < getEmail.Length; x++)
                {
                    isFoundAtSign = getEmail.Contains(findTheAtSign);
                    isFoundPeriod = getEmail.Contains(findThePeriod);
                }

                //check the phone number for validity
                int count = 0;
                for (int z = 0; z < getPhoneNum.Length; z++)
                {
                    count = count + 1;
                }

                int verifyNum;
                bool isNumerical = int.TryParse(getPhoneNum, out verifyNum);

                if ((isFoundAtSign == true) && (isFoundPeriod == true))
                {
                    if (count == 10)
                   {
                        if(isNumerical == true)
                        {
                            try
                            {
                                objReg = objParentViewModel.checkUserExistence(getEmail, getPhoneNum);
                            }
                            catch (Exception)
                            {

                            }

                            if (objReg != null)
                            {
                                this.Frame.Navigate(typeof(ResetPasswordPage), objReg);
                                msg = "User account details found in the database!" +
                                      "\nProceed to reset your password.";
                                messageBox(msg);
                            }
                            else
                            {
                                this.Frame.Navigate(typeof(VerifyUserPage));
                                msg = "Information entered did not match anything in the database!" +
                                      "\nEnsure that the information is correct!";
                                messageBox(msg);
                            }
                        }
                        else
                        {
                            msg = "Please enter numeric characters only for the phone number!";
                            messageBox(msg);
                        }
                   }
                   else
                   {
                       msg = "Phone number must be ten (10) characters long!" +
                             "\nThe number you entered is: (" + count + ") characters long!";
                       messageBox(msg);
                   }
                }
                else
                {
                    msg = "Invalid email address entered!" +
                          "\nPlease ensure that the email address contains these characters: (@) and (.)";
                    messageBox(msg);
                }




                

            }
            else
            {
                msg = "Please ensure that all text fields are filled in before proceeding!";
                messageBox(msg);
            }

        }
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            string getId = lblParentID.Text;
            int convID = Convert.ToInt32(getId);
            string updateName = txtEnterNewName.Text;
            string updateSurname = txtEnterNewSurname.Text;
            string updateEmail = txtEnterNewEmail.Text;
            string updatePhone = txtEnterNewPhoneNo.Text;
            string updatePassword = txtEnterNewPassword.Text;

            bool isFoundAtSign = false;
            bool isFoundPeriod = false;


            if ((!updateName.Equals("")) && (!updateSurname.Equals("")) && (!updateEmail.Equals("")) && (!updatePhone.Equals("")) && (!updatePassword.Equals("")))
            {
                objRegister = new Register();
                int updateResult = 0;
                objParentViewModel = new ParentViewModel();

                //Check whether email address is correct
                string findTheAtSign = "@";
                string findThePeriod = ".";
                for (int x = 0; x < updateEmail.Length; x++)
                {
                    isFoundAtSign = updateEmail.Contains(findTheAtSign);
                    isFoundPeriod = updateEmail.Contains(findThePeriod);
                }

                //check the phone number for validity
                int count = 0;
                for (int z = 0; z < updatePhone.Length; z++)
                {
                    count = count + 1;
                }

                int verifyNum;
                bool isNumerical = int.TryParse(updatePhone, out verifyNum);

                if ((isFoundAtSign == true) && (isFoundPeriod == true))
                {
                    if (count == 10)
                    {
                        if (isNumerical == true)
                        {
                            try
                            {
                                updateResult = objParentViewModel.updateParentDetails(convID, updateName, updateSurname, updateEmail, updatePhone, updatePassword);
                            }
                            catch (Exception)
                            {

                            }

                            if (updateResult > 0)
                            {
                                this.Frame.Navigate(typeof(MenuPage), parentId);
                                msg = "Update was successful!";
                                messageBox(msg);
                            }
                            else
                            {
                                msg = "Update was unsuccessful!";
                                messageBox(msg);
                            }
                        }
                        else
                        {
                            msg = "Please enter numeric characters only for the phone number! ";
                            messageBox(msg);
                        }
                    }
                    else
                    {
                        msg = "Phone number must be ten (10) characters long!" +
                              "\nThe number you entered is: (" + count + ") characters long!";
                        messageBox(msg);
                    }
                }
                else
                {
                    msg = "Invalid email address entered!" +
                          "\nPlease ensure that the email address contains these characters: (@) and (.)";
                    messageBox(msg);
                }

            }
            else
            {
                msg = "Please ensure that all text fields are filled in!";
                messageBox(msg);
            }
        }
 //Check whether the user exixts in the database
 public Register checkUserExistence(string email, string phoneNo)
 {
     reg = new Register();
     using (var db = new SQLite.SQLiteConnection(app.dbPath))
     {
        reg = db.Query<Register>("Select * from Parents where Email='" + email + "' and PhoneNo='" + phoneNo + "'").FirstOrDefault();
     }
     return reg;
 }
        //Retrive all Parent details from the database where email and password match user inputs
        public Register getParent(string email, string password)
        {
            reg = new Register();
            using(var db = new SQLite.SQLiteConnection(app.dbPath))
            {

                reg = db.Query<Register>("Select * from Parents where Email ='" +email+ "' and Password ='******'").FirstOrDefault();

                /*
                  var _register = db.Query<Register>("Select * from Parents where Email ='" + email + "' and Password ='******'").FirstOrDefault;
                  return reg;
                */

            }
            return reg;
        }
        //Retrive all Parent details from the database to check whether email address exists
        public Register checkUserExistence()
        {
            reg = new Register();
            using (var db = new SQLite.SQLiteConnection(app.dbPath))
            {

                reg = db.Query<Register>("Select * from Parents").FirstOrDefault();


            }
            return reg;
        }