private void searchVehicleButton_Click(object sender = null, EventArgs e = null) { isSearch = true; Vehicle vehicle = new Vehicle(); //get the search criteria that the user input vehicle.Model = (Model)modelDropDownBox.SelectedItem; vehicle.used = usedCheckBox.Checked; vehicle.sold = soldCheckBox.Checked; vehicle.year = DateUtil.HandleYearString(yearTextBox.Text.ToString()); //check if theres a minimum price to search by decimal?minPrice = null; if (!minPriceTextBox.Text.ToString().Equals("Min")) { minPrice = getDecimalPriceFromString(minPriceTextBox.Text.ToString()); } //check if theres a maximum price to search by decimal?maxPrice = null; if (!maxPriceTextBox.Text.ToString().Equals("Max")) { maxPrice = getDecimalPriceFromString(maxPriceTextBox.Text.ToString()); } updateVehiclesComboBox(VehicleDAO.SearchVehicles(vehicle, minPrice, maxPrice)); }
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 removeVehicle_Click(object sender, EventArgs e) { var confirmResult = MessageBox.Show("Are you sure to delete this vehicle?", "Confirm Deletion of Vehicle", MessageBoxButtons.YesNo); if (confirmResult == DialogResult.Yes) { VehicleDAO.RemoveVehicle((Vehicle)vehiclesListBox.SelectedItem); Vehicle deletedVehicle = (Vehicle)vehiclesListBox.SelectedItem; vehicles.Remove(deletedVehicle); vehiclesListBox.DataSource = null; vehiclesListBox.DataSource = vehicles; Console.WriteLine("Vehicle successfully deleted"); } }
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 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"); } } }
public ZoneServiceImp(ZoneDAO zoneDAO, FlowDAO flowDAO, VehicleDAO vehicleDAO) { this.zoneDAO = zoneDAO; this.flowDAO = flowDAO; this.vehicleDAO = vehicleDAO; }
//confirm that we're ready to save the Vehicle we're editing/adding private void confirmButton_Click(object sender, EventArgs e) { decimal price; try { price = Decimal.Parse(priceTextBox.Text.ToString()); if (price > 0) { //if adding if (mode == ADD_VEHICLE) { //create the Vehicle object Vehicle vehicle = new Vehicle(); vehicle.Model = (Model)modelDropDown.SelectedItem; vehicle.sold = soldCheckBox.Checked; vehicle.used = usedCheckBox.Checked; vehicle.year = DateUtil.HandleYearString(yearTextBox.Text.ToString()); vehicle.price = price; //check that the user hasn't entered an invalid year if (vehicle.year != DateUtil.INVALID_YEAR) { //save the vehicle VehicleDAO.AddVehicle(vehicle); //add the new vehicle to the list so it shows when the user goes back to the VehiclesForm VehiclesForm vehiclesForm = (VehiclesForm)parentForm; vehiclesForm.vehicles.Add(vehicle); closeForm(); } else { //if the date is invalid, ask the user to enter it again without saving the vehicle MessageBox.Show("Please enter a valid year", "Invalid Year Value", MessageBoxButtons.OK); } } else if (mode == EDIT_VEHICLE) { //reassign all of the fields of the current Vehicle object with the information the user entered CurrentVehicle.Model = (Model)modelDropDown.SelectedItem; CurrentVehicle.sold = soldCheckBox.Checked; CurrentVehicle.used = usedCheckBox.Checked; CurrentVehicle.year = DateUtil.HandleYearString(yearTextBox.Text.ToString()); CurrentVehicle.price = price; //make sure an invalid year isn't entered if (CurrentVehicle.year != DateUtil.INVALID_YEAR) { //update the vehicle in the database VehicleDAO.EditVehicle(CurrentVehicle); closeForm(); } else { //if the date is invalid, ask the user to enter it again without saving the vehicle MessageBox.Show("Please enter a valid year", "Invalid Year Value", MessageBoxButtons.OK); } } } else { MessageBox.Show("Invalid Price", "Invalid Price", MessageBoxButtons.OK); } } catch { MessageBox.Show("Invalid Input", "Invalid Input", MessageBoxButtons.OK); } }
public BatchServiceImpl(BatchDAO batchDAO, UserDAO userDAO, VehicleDAO vehicleDAO) { this.userDAO = userDAO; this.batchDAO = batchDAO; this.vehicleDAO = vehicleDAO; }
public InspectionDAOImp(VehicleDAO vehicleDAO) { inspectionMapper = new InspectionMapper(); this.vehicleDAO = vehicleDAO; }
private void allVehiclesButton_Click(object sender = null, EventArgs e = null) { isSearch = false; updateVehiclesComboBox(VehicleDAO.GetAllVehicles()); }
public InspectionServiceImpl(InspectionDAO inspectionDAO, VehicleDAO vehicleDAO) { this.inspectionDAO = inspectionDAO; this.vehicleDAO = vehicleDAO; }
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 VehicleServiceImpl(VehicleDAO vehicleDAO, FlowDAO flowDAO, ZoneDAO zoneDAO) { this.vehicleDAO = vehicleDAO; this.flowDAO = flowDAO; this.zoneDAO = zoneDAO; }