private void ChangeUiThemeAndSave(object sender, RoutedEventArgs routedEventArgs) { LocalStorage.Save("uiTheme", ThemeToggle.IsOn); var rootFrame = Window.Current.Content as Frame; rootFrame.RequestedTheme = ThemeToggle.IsOn ? ElementTheme.Dark : ElementTheme.Light; FluentDesign.SetTransparentTitleBar(LocalStorage.Read <bool>("uiTheme") ? Colors.White : Color.FromArgb(255, 40, 40, 40)); }
public async void LoadCurrentUserInfo() { UserLoadingRing.IsActive = true; ShowNotificationsToggle.IsEnabled = false; // Get local storage data currentUserId = LocalStorage.Read <int>("currentUserId"); ThemeToggle.IsOn = LocalStorage.Read <bool>("uiTheme"); // Set theme var rootFrame = Window.Current.Content as Frame; rootFrame.RequestedTheme = ThemeToggle.IsOn ? ElementTheme.Dark : ElementTheme.Light; // Extend into title bar FluentDesign.SetTransparentTitleBar(LocalStorage.Read <bool>("uiTheme") ? Colors.White : Color.FromArgb(255, 40, 40, 40)); // Make the switch toggleable ThemeToggle.Toggled += ChangeUiThemeAndSave; // Query the database new Task(async() => { var currentUser = new User() { UserID = currentUserId }; //bool cuNotifications; using (var connection = new SqlConnection(Helpers.FunctionsAndInterfaces.connectionString)) { connection.Open(); var query = $"SELECT Name, Surname, Email, ShowNotifications FROM Users INNER JOIN UserSettings ON Users.UserID = UserSettings.UserID WHERE Users.UserID = {currentUserId};"; using (var command = new SqlCommand(query, connection)) { using (var reader = command.ExecuteReader()) { try { while (reader.Read()) { currentUser.Name = reader.GetString(0); currentUser.Surname = reader.GetString(1); currentUser.Email = reader.GetString(2); //cuNotifications = reader.GetBoolean(3); } } catch (Exception e) { await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.High, async() => { await new MessageDialog($"{e.Message}").ShowAsync(); ThemeToggle.IsOn = true; NoUserHero.Visibility = Visibility.Visible; currentUserId = -1; }); return; } } } connection.Close(); } await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { UserLoadingRing.IsActive = false; CurrentUserEmail.Text = currentUser.Email.Length > 0 ? currentUser.Email : "ERR"; CurrentUserName.Text = currentUser.FullName.Length > 0 ? currentUser.FullName : "ERR"; //ShowNotificationsToggle.IsOn = cuNotifications; //ShowNotificationsToggle.IsEnabled = true; }); }).Start(); new Task(async() => { AllCourses.Clear(); using (var connection = new SqlConnection(Helpers.FunctionsAndInterfaces.connectionString)) { connection.Open(); var query = $"SELECT Courses.CourseID, Courses.Name, ShortName, StudyYear, StudyName, CourseColor FROM Courses JOIN UserCourses ON Courses.CourseID = UserCourses.CourseID WHERE UserID = {currentUserId};"; using (var command = new SqlCommand(query, connection)) { using (var reader = command.ExecuteReader()) { while (reader.Read()) { AllCourses.Add(new Classes.Course { CourseID = reader.GetInt32(0), Name = reader.GetString(1), ShortName = reader.GetString(2), StudyYear = reader.GetInt32(3), StudyName = reader.GetString(4), CourseColor = reader.GetString(5) }); } } } connection.Close(); } await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { UserLoadingRing.IsActive = false; if (AllCourses.Count > 0) { CourseListView.ItemsSource = AllCourses.OrderBy(n => n.Name); } else { NoCoursesHero.Visibility = Visibility.Visible; AddCourseTopButton.Visibility = Visibility.Collapsed; } }); }).Start(); using (var connection = new SqlConnection(Helpers.FunctionsAndInterfaces.connectionString)) { connection.Open(); const string query = "SELECT COUNT(*) FROM Users;"; using (var command = new SqlCommand(query, connection)) { using (var reader = command.ExecuteReader()) { while (reader.Read()) { noOfUsers = reader.GetInt32(0); } } } connection.Close(); } SwitchActiveUser.Visibility = noOfUsers > 1 ? Visibility.Visible : Visibility.Collapsed; SwitchActiveUserSeparator.Visibility = noOfUsers > 1 ? Visibility.Visible : Visibility.Collapsed; }