Ejemplo n.º 1
0
 private void buttonBookingAdd_Click(object sender, EventArgs e)
 {
     if (listBoxVehicle.SelectedItem != null)
     {
         //check, if the customer or the vehicle has open bookings
         if (DBController.TryCheckOpenBookingsCustomer(FormController.CurrentCustomer, out bool cresult) && !cresult)
         {
             if (listBoxVehicle.SelectedItem is Vehicle v && DBController.TryCheckOpenBookingVehicle(v, out bool vresult) && !vresult && v.Available)
             {
                 Booking b = new Booking(FormController.CurrentCustomer, v, DateTime.Now, new DateTime(0), v.Mileage, 0, true);
                 if (DBController.TryAddBooking(b))
                 {
                     Feedback.SuccessOpenBooking();
                 }
                 else
                 {
                     Feedback.ErrorDatabaseConnection();
                 }
             }
             else
             {
                 Feedback.ErrorNotAvailableVehicle();
             }
         }
         else
         {
             Feedback.ErrorAlreadyOpenBooking();
         }
     }
 private void UpdateTable()
 {
     listBoxBooking.Items.Clear();
     if (!DBController.TryGetAllBookingsOfCustomer(FormController.CurrentCustomer, out List <Booking> bookings))
     {
         Feedback.ErrorDatabaseConnection();
         return;
     }
     listBoxBooking.Items.AddRange(bookings.ToArray());
 }
 internal void UpdateTable()
 {
     listBoxUser.Items.Clear();
     Placeholer();
     if (!DBController.TryGetAllCustomers(out List <Customer> customers))
     {
         Feedback.ErrorDatabaseConnection();
         return;
     }
     listBoxUser.Items.AddRange(customers.ToArray());
 }
 internal void UpdateTable()
 {
     listBoxVehicle.Items.Clear();
     Placeholer();
     if (!DBController.TryGetAllVehicles(out List <Vehicle> vehicles))
     {
         Feedback.ErrorDatabaseConnection();
         return;
     }
     listBoxVehicle.Items.AddRange(vehicles.ToArray());
 }
 private void buttonVehicleDelete_Click(object sender, EventArgs e)
 {
     if (listBoxVehicle.SelectedItem != null)
     {
         if (listBoxVehicle.SelectedItem is Vehicle vehicle)
         {
             if (DBController.TryCheckOpenBookingVehicle(vehicle, out bool result))
             {
                 //If car isn't booked
                 if (!result)
                 {
                     DialogResult dialog = Feedback.AskVehicleDelete();
                     if (dialog == DialogResult.Yes)
                     {
                         //Try delete vehicle
                         if (DBController.TryDeleteVehicle(vehicle))
                         {
                             if (!DBController.TryCheckVehicleTypeIsNeeded(vehicle))
                             {
                                 Feedback.ErrorDatabaseVehicleTypeDelete();
                             }
                             Feedback.SuccessVehicleDelete();
                             FormController.MainView.UpdateVehicleList();
                         }
                         else
                         {
                             Feedback.ErrorDatabaseVehicleDelete();
                         }
                     }
                 }
                 else                         //If car is booked
                 {
                     Feedback.ErrorDatabaseBookedVehicleDelete();
                 }
             }
             else                     //If check fails
             {
                 Feedback.ErrorDatabaseConnection();
             }
         }
         else                 //If selected item isn't a vehicle
         {
             Feedback.ErrorNoValidSelectedItem();
         }
     }
     else             //If selected item is null
     {
         Feedback.ErrorNoSelectedItem();
     }
 }
Ejemplo n.º 6
0
 internal void UpdateTable()
 {
     listBoxVehicle.Items.Clear();
     Placeholer();
     if (!DBController.TryGetAvailableVehicles(out List <Vehicle> vehicles))
     {
         Feedback.ErrorDatabaseConnection();
         return;
     }
     foreach (Vehicle item in vehicles)
     {
         if (item.Available)
         {
             listBoxVehicle.Items.Add(item);
         }
     }
 }
 private void buttonCloseCurrentBooking_Click(object sender, EventArgs e)
 {
     // Check if the user input in the textbox is valid
     if (double.TryParse(watermarkTextBoxEndMileage.Text, out double userInput) && listBoxBooking.SelectedItem is Booking b && userInput >= b.StartMileage)
     {
         // Close the booking locally
         b.Close(DateTime.Now, userInput);
         // Close the booking in the database
         if (DBController.TryCloseBooking(b))
         {
             Feedback.SuccessCloseBooking(b.CalculateCost());
             UpdateForm();
         }
         else
         {
             Feedback.ErrorDatabaseConnection();
         }
     }
Ejemplo n.º 8
0
        private void login()
        {
            if (!DBController.TryGetCustomerByEmail(txtEmail.Text, out Customer c))
            {
                Feedback.ErrorDatabaseConnection();
                return;
            }

            if (c != null)
            {
                if (SecurePasswordHasher.Verify(txtPassword.Text, c.PasswordHash))
                {
                    FormController.CurrentCustomer = c;
                    c = null;
                    FormController.StartView.Close();
                    return;
                }
            }
            Feedback.ErrorInvalidLogin();
        }
        private bool testForInvalidValues()
        {
            if (string.IsNullOrWhiteSpace(txtName.TextWithoutWatermark))
            {
                Feedback.ErrorInvalidName();
                return(false);
            }
            if (string.IsNullOrWhiteSpace(txtLastName.TextWithoutWatermark))
            {
                Feedback.ErrorInvaliLastdName();
                return(false);
            }
            if (string.IsNullOrWhiteSpace(txtEmail.TextWithoutWatermark) || !txtEmail.TextWithoutWatermark.Contains("@") || !txtEmail.TextWithoutWatermark.Contains("."))
            {
                Feedback.ErrorInvaliEmail();
                return(false);
            }
            if (string.IsNullOrWhiteSpace(txtPhoneNumber.TextWithoutWatermark) || !txtPhoneNumber.TextWithoutWatermark.Any(char.IsDigit))
            {
                Feedback.ErrorInvalidTel();
                return(false);
            }
            if (!DateTime.TryParse(txtBirthDate.TextWithoutWatermark, out DateTime birthDate))
            {
                Feedback.ErrorInvalidDate();
                return(false);
            }
            if ((DateTime.Today.Date - birthDate.Date) < new TimeSpan(365 * 18, 6 * 18, 0, 0))            //min. Alter
            {
                Feedback.ErrorInvalidAge();
                return(false);
            }
            if (string.IsNullOrWhiteSpace(txtStreet.TextWithoutWatermark))
            {
                Feedback.ErrorInvalidStreet();
                return(false);
            }
            if (string.IsNullOrWhiteSpace(txtHouseNumber.TextWithoutWatermark))
            {
                Feedback.ErrorInvalidHouseNumber();
                return(false);
            }
            if (string.IsNullOrWhiteSpace(txtPlz.TextWithoutWatermark) || !txtPlz.TextWithoutWatermark.All(char.IsDigit))
            {
                Feedback.ErrorInvalidPLZ();
                return(false);
            }
            if (string.IsNullOrWhiteSpace(txtCity.TextWithoutWatermark))
            {
                Feedback.ErrorInvalidCity();
                return(false);
            }
            if (string.IsNullOrWhiteSpace(txtCountry.TextWithoutWatermark))
            {
                Feedback.ErrorInvalidCountry();
                return(false);
            }
            if (!DBController.TryGetAllCustomers(out List <Customer> customers))
            {
                Feedback.ErrorDatabaseConnection();
                return(false);
            }

            if (txtEmail.TextWithoutWatermark != customerOld.EmailAddress)
            {
                foreach (Customer c in customers)
                {
                    if (txtEmail.TextWithoutWatermark == c.EmailAddress)
                    {
                        Feedback.ErrorAlreadyExistingEmail();
                        return(false);
                    }
                }
            }
            return(true);
        }