Пример #1
0
        private bool SaveAccountDetails()
        {
            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!");
                return(false);
            }
            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;

                DebugLog.WriteLine(userDAO == null);

                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);

                    UserLabel.Content = "Welcome User " + UserManager.CurrentUser.Name + " "
                                        + UserManager.CurrentUser.Surname;

                    return(true);
                }
                catch (Exception ex)
                {
                    DebugLog.WriteLine(ex);
                    NotificationLabel.ShowError("A problem occured while trying to save settings!");
                    return(false);
                }
            }
        }
Пример #2
0
        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!");
                }
            }
        }
Пример #3
0
        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");
                }
            }
        }
Пример #4
0
        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!");
                }
            }
        }
Пример #5
0
        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");
                }
            }
        }