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 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 AddFine_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 { try { Damage damage = new Damage() { FineAmount = Double.Parse(FineAmountBox.Text), UserId = ((User)FineUserBox.SelectedItem).Id, VehicleId = ((Vehicle)VehicleBox.SelectedItem).Id, Date = DatePicker.SelectedDate.Value, Paid = PaidCheckBox.IsChecked.Value }; new DamageDAO().Insert(damage); ((List <Damage>)AllDamagesTable.ItemsSource).Add(damage); AllDamagesTable.Items.Refresh(); } catch (Exception ex) { DebugLog.WriteLine(ex); NotificationLabel.ShowError("Could not add fine"); } } }
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 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); } } }
private void RefreshFines_Click(object sender, System.Windows.RoutedEventArgs e) { try { List <Damage> damages = new DamageDAO().GetDamages(); AllDamagesTable.ItemsSource = damages; } catch (Exception ex) { DebugLog.WriteLine(ex); NotificationLabel.ShowError("Could not refresh entries"); } }
private void RefreshCars_Click(object sender, System.Windows.RoutedEventArgs e) { try { List <Vehicle> vehicles = new VehicleDAO().GetVehicles(); VehicleTable.ItemsSource = vehicles; } catch (Exception ex) { DebugLog.WriteLine(ex); NotificationLabel.ShowError("Could not refresh entries"); } }
private void RefreshRentals_Click(object sender, System.Windows.RoutedEventArgs e) { try { List <Rent> allRentals = new RentDAO().GetRents(); AllRentalsTable.ItemsSource = allRentals; } catch (Exception ex) { NotificationLabel.ShowError("Could not refresh entries"); DebugLog.WriteLine(ex); } }
private void SaveVehicleEdits_Click(object sender, System.Windows.RoutedEventArgs e) { if (string.IsNullOrEmpty(TypeBox.Text.Trim()) || string.IsNullOrEmpty(PriceDayBox.Text.Trim()) || string.IsNullOrEmpty(PriceHourBox.Text.Trim()) || LicenseCategoryComboBox.SelectedItem == null || RevisionDatePicker.SelectedDate == null || string.IsNullOrEmpty(DescriptionBox.Text.Trim())) { NotificationLabel.ShowError("All fields are required"); } else { if (currentVehicle == null) { NotificationLabel.ShowError("Please double click on Vehicle first"); return; } try { currentVehicle.Type = TypeBox.Text.Trim(); currentVehicle.PriceDay = Double.Parse(PriceDayBox.Text); currentVehicle.PriceHour = double.Parse(PriceHourBox.Text); if (UserBox.SelectedItem == null) { currentVehicle.UserId = null; } else if (((User)UserBox.SelectedItem).Id == -1) { currentVehicle.UserId = null; } else { currentVehicle.UserId = ((User)UserBox.SelectedItem).Id; } currentVehicle.LicenseCategory = (Vehicle.LicenseCategories)LicenseCategoryComboBox.SelectedItem; currentVehicle.NextRevision = RevisionDatePicker.SelectedDate.Value; currentVehicle.Damaged = DamagedCheckBox.IsChecked.Value; currentVehicle.Description = DescriptionBox.Text; new VehicleDAO().Update(currentVehicle); VehicleTable.Items.Refresh(); } catch (Exception ex) { DebugLog.WriteLine(ex); NotificationLabel.ShowError("Could not update vehicle"); } } }
private void AddVehicle_Click(object sender, System.Windows.RoutedEventArgs e) { if (string.IsNullOrEmpty(TypeBox.Text.Trim()) || string.IsNullOrEmpty(PriceDayBox.Text.Trim()) || string.IsNullOrEmpty(PriceHourBox.Text.Trim()) || LicenseCategoryComboBox.SelectedItem == null || RevisionDatePicker.SelectedDate == null || string.IsNullOrEmpty(DescriptionBox.Text.Trim())) { NotificationLabel.ShowError("All fields are required"); } else { try { Vehicle newVehicle = new Vehicle(); newVehicle.Type = TypeBox.Text.Trim(); newVehicle.PriceDay = Double.Parse(PriceDayBox.Text); newVehicle.PriceHour = double.Parse(PriceHourBox.Text); if (UserBox.SelectedItem == null) { newVehicle.UserId = null; } else if (((User)UserBox.SelectedItem).Id == -1) { newVehicle.UserId = null; } else { newVehicle.UserId = ((User)UserBox.SelectedItem).Id; } newVehicle.LicenseCategory = (Vehicle.LicenseCategories)LicenseCategoryComboBox.SelectedItem; newVehicle.NextRevision = RevisionDatePicker.SelectedDate.Value; newVehicle.Damaged = DamagedCheckBox.IsChecked.Value; newVehicle.Description = DescriptionBox.Text; new VehicleDAO().Insert(newVehicle); ((List <Vehicle>)VehicleTable.ItemsSource).Add(newVehicle); VehicleTable.Items.Refresh(); } catch (Exception ex) { DebugLog.WriteLine(ex); NotificationLabel.ShowError("Could not update vehicle"); } } }
private void SaveBankAccountDetails() { if (string.IsNullOrEmpty(IBANBox.Text.Trim()) && string.IsNullOrEmpty(SecurityNumberBox.Text.Trim()) && CardTypeComboBox.SelectedItem == null && string.IsNullOrEmpty(BankNameBox.Text.Trim()) && ExpiryDatePicker.SelectedDate == null) { return; } else if (!string.IsNullOrEmpty(IBANBox.Text.Trim()) && !string.IsNullOrEmpty(SecurityNumberBox.Text.Trim()) && CardTypeComboBox.SelectedItem != null && !string.IsNullOrEmpty(BankNameBox.Text.Trim()) && ExpiryDatePicker.SelectedDate != null) { try { List <BankAccount> userBankAccounts = new BankAccountDAO().GetBankAccounts(userId: UserManager.CurrentUser.Id); BankAccount account = new BankAccount() { Iban = Encryption.Encrypt(IBANBox.Text.Trim()), SecurityNumber = Int32.Parse(SecurityNumberBox.Text.Trim()), CardType = (BankAccount.CardTypes)CardTypeComboBox.SelectedItem, BankName = BankNameBox.Text.Trim(), ExpiryDate = ExpiryDatePicker.SelectedDate.Value, UserId = UserManager.CurrentUser.Id }; if (userBankAccounts.Count > 0) { account.Id = userBankAccounts.First().Id; new BankAccountDAO().Update(account); } else { new BankAccountDAO().Insert(account); } } catch (Exception ex) { DebugLog.WriteLine(ex); NotificationLabel.ShowError("A problem occured while trying to save settings!"); } } else { NotificationLabel.ShowError("All bank account information fields are mandatory"); } }
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 !"); } } }
// Use this for initialization void Start() { shooter = GetComponentInChildren <Shooter>(); health = GetComponent <Health>(); eyesCamera = GetComponentInChildren <Camera>(); ipID = Network.player.ipAddress.ToString(); notifictaionLabel = Text.FindObjectOfType <NotificationLabel>(); scoreBoard = Text.FindObjectOfType <Score>(); bulletsManager = BulletsManager.FindObjectOfType <BulletsManager>(); bulletsParent = GameObject.Find("BulletsParent"); if (!bulletsParent) { bulletsParent = new GameObject("BulletsParent"); } //bodyColor = myColorManager.ChooseRandomColor(); //gunColor = myColorManager.ChooseRandomColor(); CmdChangeColor(ipID); //CmdChangeColor(ipID, bodyColor, gunColor); }
private void PopulateComboBoxes() { try { List <User> users = new UserDAO().GetUsers(function: User.Function.USER.ToString()); users.Add(new User() { Id = -1, Username = "******" }); FineUserBox.ItemsSource = users; UserBox.ItemsSource = users; LicenseCategoryComboBox.ItemsSource = Enum.GetValues(typeof(Vehicle.LicenseCategories)); VehicleBox.ItemsSource = new VehicleDAO().GetVehicles(); } catch (Exception ex) { NotificationLabel.ShowError("Something went wrong with retrieving data"); DebugLog.WriteLine(ex); } }
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 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"); } } }
public void ValidatePasswordFromDatabase() { Connection cc = new Connection(); try { SqlDataAdapter sda = new SqlDataAdapter("select [UserId],[Username],[Password],[EmployeeName],[EmployeePhone],[EmployeeEmail],[EmployeeDesignation],[AllowInternetLogin] from [mbo].[PSUsers] where Username='******' and password='******'", cc.con); DataTable dt = new DataTable(); sda.Fill(dt); if (dt.Rows.Count == 1) { User _user = new User() { Userid = dt.Rows[0]["UserId"].ToString(), Username = dt.Rows[0]["Username"].ToString(), EmployeeName = dt.Rows[0]["EmployeeName"].ToString(), EmployeeEmail = dt.Rows[0]["EmployeeEmail"].ToString(), EmployeeDesignation = dt.Rows[0]["EmployeeDesignation"].ToString(), AllowInternet = dt.Rows[0]["AllowInternetLogin"].ToString(), }; user = _user; if (InternetradioButton.Checked == true) { mm = new MainForm(user); if (dt.Rows[0]["AllowInternetLogin"].ToString() == "1") { NotificationLabel.Text = "Welcome " + user.EmployeeName; NotificationLabel.Show(); mm.WindowState = FormWindowState.Minimized; mm.Show(); timer1.Start(); } else { MessageBox.Show("You Are Not Allowed to Login via Internet", "Blocked", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { NotificationLabel.Text = "Welcome " + user.EmployeeName; NotificationLabel.Show(); mm = new MainForm(user); mm.WindowState = FormWindowState.Minimized; mm.Show(); timer1.Start(); } } else { NotificationLabel.Text = "Login Faild"; NotificationLabel.Show(); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
private void UserNameTextBox_TextChanged(object sender, EventArgs e) { NotificationLabel.Hide(); }
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 PasswordTextBox_TextChanged(object sender, EventArgs e) { NotificationLabel.Hide(); }