private void TabControl_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (!(e.OriginalSource is TabControl)) { return; } NotificationLabel.Content = ""; if (MyRentalsTab.IsSelected) { List <Rent> myRentals = new RentDAO().GetRents(userId: UserManager.CurrentUser.Id); if (myRentals.Count == 0) { NotificationLabel.ShowError("You don't have any rentals"); } MyRentalsTable.ItemsSource = myRentals; } else if (MyFinesTab.IsSelected) { List <Damage> myDamages = new DamageDAO().GetDamages(userId: UserManager.CurrentUser.Id); if (myDamages.Count == 0) { NotificationLabel.ShowSuccess("You don't have any fines to pay"); } MyFinesTable.ItemsSource = myDamages; } else if (RentACarTab.IsSelected) { IEnumerable <Vehicle> myVehicles = new VehicleDAO().GetVehicles().Where((v) => v.UserId == null); if (myVehicles != null & myVehicles.Count() == 0) { NotificationLabel.ShowError("There are no more vehicles available"); } VehicleTable.ItemsSource = myVehicles.ToList <Vehicle>(); } else if (RentACarTab.IsSelected) { IEnumerable <Vehicle> myVehicles = new VehicleDAO().GetVehicles().Where((v) => v.UserId == 0); if (myVehicles != null & myVehicles.Count() == 0) { NotificationLabel.ShowError("There are no more vehicles available"); } VehicleTable.ItemsSource = myVehicles.ToList <Vehicle>(); } else if (SettingsTab.IsSelected) { CardTypeComboBox.ItemsSource = Enum.GetValues(typeof(BankAccount.CardTypes)); User currentUser = UserManager.CurrentUser; try { UserDetails details = new UserDetailsDAO().GetUserDetails(userId: currentUser.Id).First(); UsernameBox.Text = currentUser.Username; NameBox.Text = currentUser.Name; SurnameBox.Text = currentUser.Surname; EmailBox.Text = details.Email; StreetBox.Text = details.Street; CityBox.Text = details.City; ZipCodeBox.Text = details.ZipCode; CountryBox.Text = details.Country; BirthDatePicker.SelectedDate = details.BirthDate; } catch (Exception ex) { DebugLog.WriteLine(ex); NotificationLabel.ShowError("A problem occured! Could not retrieve your data!"); return; } try { BankAccount bankAccount = new BankAccountDAO().GetBankAccounts(userId: currentUser.Id).First(); IBANBox.Text = Encryption.Decrypt(bankAccount.Iban); SecurityNumberBox.Text = bankAccount.SecurityNumber.ToString(); CardTypeComboBox.SelectedItem = bankAccount.CardType == BankAccount.CardTypes.CREDIT ? CardTypeComboBox.Items.GetItemAt(0) : CardTypeComboBox.Items.GetItemAt(1); BankNameBox.Text = bankAccount.BankName; ExpiryDatePicker.SelectedDate = bankAccount.ExpiryDate; } catch (InvalidOperationException ex) { return;//no bankaccount for this user } catch (Exception ex) { NotificationLabel.ShowError("Could not retrieve bank account information"); } } }
private void TabControl_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (!(e.OriginalSource is TabControl)) { return; } NotificationLabel.Content = ""; if (AllRentalsTab.IsSelected) { List <Rent> allRentals = new RentDAO().GetRents(); if (allRentals.Count == 0) { NotificationLabel.ShowError("There aren't any rentals"); } AllRentalsTable.ItemsSource = allRentals; } else if (AllFinesTab.IsSelected) { List <Damage> allDamages = new DamageDAO().GetDamages(); if (allDamages.Count == 0) { NotificationLabel.ShowSuccess("There are no fines"); } try { List <User> users = new UserDAO().GetUsers(function: User.Function.USER.ToString()); FineUserBox.ItemsSource = users; LicenseCategoryComboBox.ItemsSource = Enum.GetValues(typeof(Vehicle.LicenseCategories)); } catch (Exception ex) { NotificationLabel.ShowError("Something went wrong with retrieving data"); DebugLog.WriteLine(ex); } AllDamagesTable.ItemsSource = allDamages; } else if (AllCarsTab.IsSelected) { List <Vehicle> myVehicles = new VehicleDAO().GetVehicles(); if (myVehicles != null & myVehicles.Count() == 0) { NotificationLabel.ShowError("No vehicles to display"); } try { List <User> users = new UserDAO().GetUsers(function: User.Function.USER.ToString()); users.Add(new User() { Id = -1, Username = "******" }); UserBox.ItemsSource = users; LicenseCategoryComboBox.ItemsSource = Enum.GetValues(typeof(Vehicle.LicenseCategories)); } catch (Exception ex) { NotificationLabel.ShowError("Something went wrong with retrieving data"); DebugLog.WriteLine(ex); } VehicleTable.ItemsSource = myVehicles; } else if (SettingsTab.IsSelected) { User currentUser = UserManager.CurrentUser; try { UserDetails details = new UserDetailsDAO().GetUserDetails(userId: currentUser.Id).First(); UsernameBox.Text = currentUser.Username; NameBox.Text = currentUser.Name; SurnameBox.Text = currentUser.Surname; EmailBox.Text = details.Email; StreetBox.Text = details.Street; CityBox.Text = details.City; ZipCodeBox.Text = details.ZipCode; CountryBox.Text = details.Country; BirthDatePicker.SelectedDate = details.BirthDate; } catch (Exception ex) { DebugLog.WriteLine(ex); NotificationLabel.ShowError("A problem occured! Could not retrieve your data!"); return; } } else if (AllUsersTab.IsSelected) { try { AllUsersTable.ItemsSource = new UserDAO().GetUsers(); } catch (Exception ex) { DebugLog.WriteLine(ex); NotificationLabel.ShowError("Could not retrieve all users"); } } }