public void RefreshTimerTick(object sender, EventArgs e)
        {
            DataHandling.GetTasksFull();
            DataHandling.GetNotifications();
            int oldNoOfNotifications = noOfNotifications;

            noOfNotifications = 0;
            bool seenByUser = false;

            foreach (DataStructures.NotificationStruct notification in DataStructures.notificationRows)
            {
                bool notificationForUser = false;
                seenByUser = false;

                foreach (string username in notification.notificationRecipients)
                {
                    if (username.Equals(Application.Current.Properties["username"]) == true)
                    {
                        notificationForUser = true;
                    }
                }

                foreach (string username in notification.readByRecipients)
                {
                    if ((username.Equals(Application.Current.Properties["username"]) == true) && (notificationForUser == true))
                    {
                        seenByUser = true;
                    }
                }

                if ((notificationForUser == true) && (seenByUser == false))
                {
                    noOfNotifications++;
                }
            }

            if (noOfNotifications != 0)
            {
                NotificationsButton.Content = "Notifications (" + noOfNotifications + ")";

                if (noOfNotifications > oldNoOfNotifications)
                {
                    /*
                     * XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastImageAndText02);
                     *
                     * XmlNodeList stringElements = toastXml.GetElementsByTagName("text");
                     *
                     * stringElements[0].AppendChild(toastXml.CreateTextNode("New Notification(s)"));
                     * //stringElements[1].AppendChild(toastXml.CreateTextNode("Open Premier Task Management to see what's changed"));
                     *
                     * string imagePath = "/assets/Premier_P_Logo_Red_RGB_Small_Trans.png";
                     * XmlNodeList imageElements = toastXml.GetElementsByTagName("image");
                     * imageElements[0].Attributes.GetNamedItem("src").NodeValue = imagePath;
                     *
                     * ToastNotification toast = new ToastNotification(toastXml);
                     *
                     * ToastNotificationManager.CreateToastNotifier(APP_ID).Show(toast);
                     */
                }
            }
            else
            {
                NotificationsButton.Content = "Notifications";
            }

            for (int i = CalendarGrid.Children.Count - 1; i > 0; i--)
            {
                if (CalendarGrid.Children[i].GetType() == typeof(Grid))
                {
                    Grid grid = (Grid)CalendarGrid.Children[i];
                    CalendarGrid.Children.Remove(grid);
                }
            }

            LoadTasksIntoCalendar();
        }
        //Log in as User
        private void LogInButtonClick(object sender, RoutedEventArgs e)
        {
            Security      security      = new Security();
            SqlConnection sqlConnection = new SqlConnection(Properties.Settings.Default.PDMDatabaseConnectionString);
            SqlCommand    sqlCommand    = new SqlCommand("GetSaltAndHashSP", sqlConnection);

            sqlCommand.CommandType = CommandType.StoredProcedure;

            sqlCommand.Parameters.AddWithValue("@username", (string)UsernameTextBox.Text);

            SqlParameter returnedSalt      = new SqlParameter("@passwordSalt", SqlDbType.NVarChar);
            SqlParameter returnedHash      = new SqlParameter("@passwordHash", SqlDbType.NVarChar);
            SqlParameter returnedUserFound = new SqlParameter("@userFound", SqlDbType.Int);

            returnedSalt.Direction      = ParameterDirection.Output;
            returnedHash.Direction      = ParameterDirection.Output;
            returnedUserFound.Direction = ParameterDirection.Output;
            returnedSalt.Size           = 256;
            returnedHash.Size           = 256;

            sqlCommand.Parameters.Add(returnedSalt);
            sqlCommand.Parameters.Add(returnedHash);
            sqlCommand.Parameters.Add(returnedUserFound);

            try
            {
                sqlConnection.Open();
                int i = sqlCommand.ExecuteNonQuery();


                string databaseSalt = sqlCommand.Parameters["@passwordSalt"].Value.ToString();
                string databaseHash = sqlCommand.Parameters["@passwordHash"].Value.ToString();
                int    userFound    = (int)sqlCommand.Parameters["@userFound"].Value;

                UsernameExistsLabel.Content    = "";
                PasswordIncorrectLabel.Content = "";


                string passwordhash = security.HashPassword(PasswordTextBox.Password, databaseSalt);

                Console.WriteLine(databaseSalt);
                Console.WriteLine(databaseHash);
                Console.WriteLine(passwordhash);

                if (databaseHash.Equals(passwordhash))
                {
                    Console.WriteLine("Log In Success");

                    MainWindow.Username = UsernameTextBox.Text;

                    //Sets welcome string to User
                    SqlCommand getUser = new SqlCommand("GetNamesSP", sqlConnection);
                    getUser.CommandType = CommandType.StoredProcedure;
                    getUser.Parameters.AddWithValue("@username", UsernameTextBox.Text);
                    SqlParameter forename = new SqlParameter("@forename", SqlDbType.NVarChar);
                    SqlParameter surname  = new SqlParameter("@surname", SqlDbType.NVarChar);
                    forename.Direction = ParameterDirection.Output;
                    surname.Direction  = ParameterDirection.Output;
                    forename.Size      = 30;
                    surname.Size       = 40;
                    getUser.Parameters.Add(forename);
                    getUser.Parameters.Add(surname);

                    int    x          = getUser.ExecuteNonQuery();
                    string forenameDB = getUser.Parameters["@forename"].Value.ToString();
                    string surnameDB  = getUser.Parameters["@surname"].Value.ToString();

                    System.Windows.Application.Current.Properties["username"]             = getUser.Parameters["@username"].Value.ToString();
                    System.Windows.Application.Current.Properties["forename"]             = getUser.Parameters["@forename"].Value.ToString();
                    System.Windows.Application.Current.Properties["surname"]              = getUser.Parameters["@surname"].Value.ToString();
                    System.Windows.Application.Current.Resources["WelcomeTextString"]     = "Welcome, " + System.Windows.Application.Current.Properties["forename"];
                    System.Windows.Application.Current.Resources["BlurEffectRadius"]      = (double)0;
                    System.Windows.Application.Current.Resources["LogInButtonVisibility"] = Visibility.Hidden;

                    sqlConnection.Close();

                    DataHandling.GetTasksFull();
                    DataHandling.GetNotifications();

                    foreach (DataStructures.NotificationStruct notification in DataStructures.notificationRows)
                    {
                        if (notification.readByRecipients.Contains(Application.Current.Properties["username"]) != true)
                        {
                            MainWindow.noOfNotifications++;
                        }
                    }

                    foreach (Window window in Application.Current.Windows)
                    {
                        if (window.GetType() == typeof(MainWindow))
                        {
                            if (MainWindow.noOfNotifications != 0)
                            {
                                (window as MainWindow).NotificationsButton.Content = "Notifications (" + MainWindow.noOfNotifications + ")";
                            }
                            else
                            {
                                (window as MainWindow).NotificationsButton.Content = "Notifications";
                            }
                        }
                    }


                    Close();
                }
                else
                {
                    if (userFound == 0)
                    {
                        UsernameExistsLabel.Content = "User not found.";
                        Console.WriteLine("User not found.");
                    }
                    else
                    {
                        PasswordIncorrectLabel.Content = "Incorrect Password";
                        Console.WriteLine("Incorrect password.");
                    }


                    Console.WriteLine("Log In Failed");
                }


                sqlConnection.Close();
            } catch (SqlException sqle)
            {
                MessageBox.Show("Server unavailable.");
            }
        }