private void IssueInvoice_Click(object sender, System.Windows.RoutedEventArgs e) { if (AllRentalsTable.SelectedItem == null) { NotificationLabel.ShowError("Please first select a rental!"); } else { try { Rent rent = (Rent)AllRentalsTable.SelectedItem; Invoice invoice = new Invoice() { Date = DateTime.Now, TotalAmount = rent.TotalAmount, VatAmount = rent.TotalAmount * Invoice.VAT, UserId = rent.UserId }; new InvoiceDAO().Insert(invoice); NotificationLabel.ShowSuccess("Invoice has been stored in database"); } catch (Exception ex) { DebugLog.WriteLine(ex); NotificationLabel.ShowError("Problem occured! Could not issue invoice"); } } }
private void RentPayButton_Click(object sender, System.Windows.RoutedEventArgs e) { Rent selectedRent = MyRentalsTable.SelectedItem != null ? MyRentalsTable.SelectedItem as Rent : null; if (selectedRent != null) { //todo implement pay logic if (!selectedRent.Paid) { try { //todo retrieve bankaccount selectedRent.Paid = true; new RentDAO().Update(selectedRent); MyRentalsTable.Items.Refresh(); NotificationLabel.ShowSuccess("Payment successful !"); } catch (Exception ex) { DebugLog.WriteLine(ex); NotificationLabel.ShowError("Could not process paying"); selectedRent.Paid = false; } } } else { NotificationLabel.ShowError("Nothing selected"); } }
private void SaveDamageChanges_Click(object sender, System.Windows.RoutedEventArgs e) { if (string.IsNullOrEmpty(FineAmountBox.Text.Trim()) || FineUserBox.SelectedItem == null || VehicleBox.SelectedItem == null || DatePicker.SelectedDate == null) { NotificationLabel.ShowError("All fields are required"); } else { if (currentDamage == null) { NotificationLabel.ShowError("Please double click on Fine first"); return; } try { currentDamage.FineAmount = Double.Parse(FineAmountBox.Text); currentDamage.UserId = ((User)FineUserBox.SelectedItem).Id; currentDamage.VehicleId = ((Vehicle)VehicleBox.SelectedItem).Id; currentDamage.Date = DatePicker.SelectedDate.Value; currentDamage.Paid = PaidCheckBox.IsChecked.Value; new DamageDAO().Update(currentDamage); AllDamagesTable.Items.Refresh(); NotificationLabel.ShowSuccess("Fine updated successfully"); } catch (Exception ex) { DebugLog.WriteLine(ex); NotificationLabel.ShowError("Could not update fine"); } } }
private void SetPaidButton_Click(object sender, System.Windows.RoutedEventArgs e) { if (AllRentalsTable.SelectedItem == null) { NotificationLabel.ShowError("Please select a rental first !"); } Rent rent = (Rent)AllRentalsTable.SelectedItem; if (rent.Paid) { NotificationLabel.ShowError("Rental already paid"); return; } else { try { rent.Paid = true; new RentDAO().Update(rent); NotificationLabel.ShowSuccess("Set paid successful !"); AllRentalsTable.Items.Refresh(); } catch (Exception ex) { DebugLog.WriteLine(ex); NotificationLabel.ShowError("A problem occured !"); } } }
private void RentCar_Click(object sender, System.Windows.RoutedEventArgs e) { Vehicle selectedVehicle = VehicleTable.SelectedItem != null ? VehicleTable.SelectedItem as Vehicle : null; if (selectedVehicle != null) { //todo implement pay logic try { List <BlackList> blackLists = new BlackListDAO().GetBlackLists(userId: UserManager.CurrentUser.Id); if (blackLists.Count != 0) { if (blackLists.First().Banned) { NotificationLabel.ShowError("You are banned! You cannot make a rental!"); } } List <BankAccount> list = new BankAccountDAO().GetBankAccounts(userId: UserManager.CurrentUser.Id); if (list.Count == 0) { NotificationLabel.ShowError("Please go to settings and add your bank account info"); return; } new RentDAO().Insert(new Rent() { BeginTime = DateTime.Now, Returned = false, Paid = false, VehicleId = selectedVehicle.Id, VehicleName = selectedVehicle.Name, UserId = UserManager.CurrentUser.Id }); selectedVehicle.UserId = UserManager.CurrentUser.Id; new VehicleDAO().Update(selectedVehicle); ((List <Vehicle>)VehicleTable.ItemsSource).Remove((Vehicle)VehicleTable.SelectedItem); MyFinesTable.Items.Refresh(); NotificationLabel.ShowSuccess("Rental successful !"); } catch (Exception ex) { DebugLog.WriteLine(ex); NotificationLabel.ShowError("Could not process rental"); selectedVehicle.UserId = null; } } else { NotificationLabel.ShowError("Nothing selected"); } }
private void SaveSettings_Click(object sender, System.Windows.RoutedEventArgs e) { if (!SaveAccountDetails()) { return; } else { SaveBankAccountDetails(); } NotificationLabel.ShowSuccess("Saved successfuly!"); }
private void SaveSettings_Click(object sender, System.Windows.RoutedEventArgs e) { if (string.IsNullOrEmpty(UsernameBox.Text.Trim()) || string.IsNullOrEmpty(NameBox.Text.Trim()) || string.IsNullOrEmpty(SurnameBox.Text.Trim()) || string.IsNullOrEmpty(StreetBox.Text.Trim()) || string.IsNullOrEmpty(ZipCodeBox.Text.Trim()) || string.IsNullOrEmpty(EmailBox.Text.Trim()) || string.IsNullOrEmpty(CountryBox.Text.Trim()) || string.IsNullOrEmpty(CityBox.Text.Trim()) || BirthDatePicker.SelectedDate == null) { NotificationLabel.ShowError("All account information fields required!"); } else { UserDAO userDAO = new UserDAO(); UserDetailsDAO userDetailsDAO = new UserDetailsDAO(); User user = UserManager.CurrentUser; user.Username = UsernameBox.Text; user.Name = NameBox.Text; user.Surname = SurnameBox.Text; try { UserDetails userDetails = user.UserDetails == null ? user.UserDetails : new UserDetailsDAO().GetUserDetails(userId: user.Id).First(); userDetails.City = CityBox.Text; userDetails.Country = CountryBox.Text; userDetails.Email = EmailBox.Text; userDetails.Street = StreetBox.Text; userDetails.ZipCode = ZipCodeBox.Text; userDetails.BirthDate = BirthDatePicker.SelectedDate.Value; userDAO.Update(user); userDetailsDAO.Update(userDetails); NotificationLabel.ShowSuccess("Account Information has been updated !"); } catch (Exception ex) { DebugLog.WriteLine(ex); NotificationLabel.ShowError("A problem occured while trying to save settings!"); } } }
private void AddToBlackList_Click(object sender, System.Windows.RoutedEventArgs e) { if (AllUsersTable.SelectedItem == null) { NotificationLabel.ShowError("Please select a User first"); return; } User selectedUser = (User)AllUsersTable.SelectedItem; try { List <BlackList> blackLists = new BlackListDAO().GetBlackLists(userId: selectedUser.Id); if (blackLists.Count == 0) { new BlackListDAO().Insert(new BlackList() { UserId = selectedUser.Id, Warnings = 1 }); NotificationLabel.ShowSuccess("User added to blacklist!"); } else { string additionalMessage = ""; BlackList blackList = blackLists[0]; blackList.Warnings++; new BlackListDAO().Update(blackList); if (blackList.Banned) { additionalMessage = " He is now banned"; } NotificationLabel.ShowSuccess("User warnings increased to " + blackList.Warnings + " !" + additionalMessage); } } catch (Exception ex) { DebugLog.WriteLine(ex); NotificationLabel.ShowError("Could not add User to Blacklist"); } }
private void SetReturnedButton_Click(object sender, System.Windows.RoutedEventArgs e) { if (AllRentalsTable.SelectedItem == null) { NotificationLabel.ShowError("Please select a rental first !"); } Rent rent = (Rent)AllRentalsTable.SelectedItem; if (rent.Returned) { NotificationLabel.ShowError("Car already returned"); return; } else { try { Vehicle vehicle = new VehicleDAO().GetVehicles(id: rent.VehicleId).First(); rent.Returned = true; rent.EndTime = DateTime.Now; double totalAmount = (rent.EndTime.Value - rent.BeginTime).TotalHours * vehicle.PriceHour; rent.TotalAmount = totalAmount = totalAmount * rent.Discount; new RentDAO().Update(rent); NotificationLabel.ShowSuccess("Set returned successful !"); AllRentalsTable.Items.Refresh(); vehicle.UserId = null; new VehicleDAO().Update(vehicle); } catch (InvalidOperationException ex) { DebugLog.WriteLine(ex); NotificationLabel.ShowError("A problem occured vehicle userid could not be modified!"); } catch (Exception ex) { DebugLog.WriteLine(ex); NotificationLabel.ShowError("A problem occured !"); } } }
private void ConfirmButton_Click(object sender, RoutedEventArgs e) { if (string.IsNullOrEmpty(UsernameBox.Text.Trim())) { NotificationLabel.ShowError("Please fill in username !"); UsernameBox.Focus(); } else if (string.IsNullOrEmpty(PasswordBox.Password)) { NotificationLabel.ShowError("Please type in new Password !"); PasswordBox.Focus(); } else if (string.IsNullOrEmpty(RepeatPasswordBox.Password) || !RepeatPasswordBox.Password.Equals(PasswordBox.Password)) { NotificationLabel.ShowError("Please Confirm new Password"); RepeatPasswordBox.Focus(); } else { UserDAO dao = new UserDAO(); try { User user = dao.GetUsers(username: UsernameBox.Text.Trim()).First(); user.Password = PasswordBox.Password; dao.Update(user); NotificationLabel.ShowSuccess("Password changed successfully"); } catch (System.InvalidOperationException ie) { DebugLog.WriteLine(ie); NotificationLabel.ShowError("Username does not exist !"); } catch (Exception ex) { DebugLog.WriteLine(ex); NotificationLabel.ShowError("Could not update user !"); } } }
private void FinePay_Click(object sender, System.Windows.RoutedEventArgs e) { Damage selectedDamage = MyFinesTable.SelectedItem != null ? MyFinesTable.SelectedItem as Damage : null; if (selectedDamage != null) { //todo implement pay logic if (!selectedDamage.Paid) { try { List <BankAccount> list = new BankAccountDAO().GetBankAccounts(userId: UserManager.CurrentUser.Id); if (list.Count == 0) { NotificationLabel.ShowError("Please go to settings and add your bank account info"); return; } //todo retrieve bankaccount selectedDamage.Paid = true; new DamageDAO().Update(selectedDamage); MyFinesTable.Items.Refresh(); NotificationLabel.ShowSuccess("Payment successful !"); } catch (Exception ex) { DebugLog.WriteLine(ex); NotificationLabel.ShowError("Could not process paying"); selectedDamage.Paid = false; MyFinesTable.Items.Refresh(); } } } else { NotificationLabel.ShowError("Nothing selected"); } }
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 RegisterButton_Click(object sender, RoutedEventArgs e) { if (string.IsNullOrEmpty(UsernameBox.Text.Trim()) || string.IsNullOrEmpty(PasswordBox.Password) || string.IsNullOrEmpty(NameBox.Text.Trim()) || string.IsNullOrEmpty(SurnameBox.Text.Trim()) || string.IsNullOrEmpty(StreetBox.Text.Trim()) || string.IsNullOrEmpty(ZipCodeBox.Text.Trim()) || string.IsNullOrEmpty(EmailBox.Text.Trim()) || string.IsNullOrEmpty(CountryBox.Text.Trim()) || string.IsNullOrEmpty(CityBox.Text.Trim()) || BirthDatePicker.SelectedDate == null || FunctionComboBox.SelectedItem == null) { NotificationLabel.ShowError("All fields required!"); } else { if (selectedFunction == User.Function.ADMIN || selectedFunction == User.Function.OPERATOR) { if (string.IsNullOrEmpty(AccessKeyBox.Password)) { NotificationLabel.ShowError("Please enter access key to register as " + selectedFunction + " !"); return; } if (!Encryption.GenerateSaltedHash(AccessKeyBox.Password).Equals(AccessKey)) { NotificationLabel.ShowError("Access key incorrect"); return; } } User user = new User() { Username = UsernameBox.Text, Password = Encryption.GenerateSaltedHash(PasswordBox.Password), Name = NameBox.Text, Surname = SurnameBox.Text, UserFunction = selectedFunction, }; UserDetails userDetails = new UserDetails() { City = CityBox.Text, Country = CountryBox.Text, Email = EmailBox.Text, Street = StreetBox.Text, ZipCode = ZipCodeBox.Text, BirthDate = BirthDatePicker.SelectedDate.Value, }; UserDAO userDAO = new UserDAO(); UserDetailsDAO userDetailsDAO = new UserDetailsDAO(); DebugLog.WriteLine(userDAO == null); try { userDAO.Insert(user); userDetails.UserId = user.Id; userDetailsDAO.Insert(userDetails); user.UserDetails = userDetails; userDAO.Update(user); NotificationLabel.ShowSuccess("Registration successful!"); } catch (Exception ex) { DebugLog.WriteLine(ex); NotificationLabel.ShowError("Username already taken!"); } } }
private void LoginButton_Click(object sender, RoutedEventArgs e) { if (string.IsNullOrEmpty(UsernameBox.Text.Trim())) { NotificationLabel.ShowError("Please fill in username !"); } else if (string.IsNullOrEmpty(PasswordBox.Password)) { NotificationLabel.ShowError("Please fill in password !"); } else { //check if username exists try { UserDAO dao = new UserDAO(); //throws exception if user non existent User currentUser = dao.GetUsers(username: UsernameBox.Text.Trim()).First(); string hash = Encryption.GenerateSaltedHash(PasswordBox.Password); if (hash.Equals(currentUser.Password)) { NotificationLabel.ShowSuccess("Authentication succeeded !"); UserManager.CurrentUser = currentUser; switch (currentUser.UserFunction) { case User.Function.ADMIN: { UserControlManager.Instance.CurrentUserControl = new AdminControl(); } break; case User.Function.USER: { UserControlManager.Instance.CurrentUserControl = new MyUserControl(); } break; case User.Function.OPERATOR: { UserControlManager.Instance.CurrentUserControl = new OperatorControl(); } break; //todo add function operator } } else { PasswordBox.Focus(); NotificationLabel.ShowError("Password invalid !"); PasswordBox.Focus(); } } catch (InvalidOperationException ie) { DebugLog.WriteLine(ie); NotificationLabel.ShowError("Username doesen't exist !"); UsernameBox.Focus(); } catch (Exception ex) { DebugLog.WriteLine(ex); NotificationLabel.ShowError("Sorry, something went wrong !"); UsernameBox.Focus(); } } }
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"); } } }