コード例 #1
0
 private void Rent_Click(object sender, RoutedEventArgs e)
 {
     if (RentalCardGrid.SelectedItem != null)
     {
         if (rentalCarViewModel.SelectedCar.Available)
         {
             if (user.Balance >= numeric_numOfDays.Value * rentalCarViewModel.SelectedCar.PricePerDay)
             {
                 rentalCarViewModel.SelectedCar.AvailableFrom = DateTime.Now;
                 rentalCarViewModel.SelectedCar.AvailableFrom = rentalCarViewModel.SelectedCar.AvailableFrom.AddDays((int)numeric_numOfDays.Value);
                 rentalCarViewModel.SelectedCar.Available     = false;
                 rentalCarViewModel.SelectedCar.RentedID      = user.ID;
                 user.Pay(rentalCarViewModel.SelectedCar.PricePerDay * numeric_numOfDays.Value);
                 rentalCarViewModel.SerializeCars();
                 user.Serialize();
                 Find_Click(sender, e);
                 ShowMsg("Rental success", "The car is successfully rented");
             }
             else
             {
                 ShowMsg("Rental error", "There are not enough funds on your balance for this rent");
             }
         }
         else
         {
             ShowMsg("Rental error", "The selected car is not available");
             RentalCar.UpdateCarsStatus(this.rentalCarViewModel.Cars.ToList());
         }
     }
     else
     {
         ShowMsg("Rental error", "You have not chosen the car you want to rent");
     }
 }
コード例 #2
0
 private void Remove_Click(object sender, RoutedEventArgs e)
 {
     if (RentalCardGrid.SelectedItem != null)
     {
         if (rentalCarViewModel.SelectedCar.Available)
         {
             rentalCarViewModel.RemoveCar(rentalCarViewModel.SelectedCar);
             rentalCarViewModel.SerializeCars();
             Find_Click(sender, e);
             ShowMsg("Removing car", "The car is successfully removed");
         }
         else
         {
             ShowMsg("Removing error", "The selected car is not available");
         }
     }
     else
     {
         ShowMsg("Removing error", "You have not chosen the car you want to remove");
     }
 }
コード例 #3
0
        private void Save_Click(object sender, RoutedEventArgs e)
        {
            bool brand_valide = false, model_valide = false, license_plate_valide = false;

            if (txtbox_carBrand.Text.Length > 2)
            {
                brand_valide = true;
                for (int i = 0; i < txtbox_carBrand.Text.Length; i++)
                {
                    if (char.IsDigit(txtbox_carBrand.Text[i]))
                    {
                        brand_valide = false;
                        break;
                    }
                }
            }
            if (!brand_valide)
            {
                ShowMsg("Error adding car", "Entered the wrong car brand. The car brand must be longer than 2 letters and not contain other characters!");
            }

            if (txtbox_carModel.Text.Length > 2)
            {
                model_valide = true;
            }
            else
            {
                ShowMsg("Error adding car", "Entered the wrong car brand. The car brand must be longer than 2 letters and not contain other characters!");
            }

            var num_reg = new Regex(@"^[A-Z]{2}\d{4}[A-Z]{2}$");

            if (num_reg.IsMatch(txtbox_licensePlate.Text))
            {
                license_plate_valide = true;
                foreach (var car in rentalCarViewModel.Cars)
                {
                    if (car.LicensePlate == txtbox_licensePlate.Text && car.LicensePlate != rentalCar.LicensePlate)
                    {
                        license_plate_valide = false;
                        break;
                    }
                }
                if (!license_plate_valide)
                {
                    ShowMsg("Error adding car", "A car with such a license plate is already there!");
                }
            }
            else
            {
                ShowMsg("Error adding car", "The license plate of the car is incorrect");
            }
            if (brand_valide && model_valide && license_plate_valide)
            {
                rentalCar.Brand         = txtbox_carBrand.Text;
                rentalCar.LicensePlate  = txtbox_licensePlate.Text;
                rentalCar.Model         = txtbox_carModel.Text;
                rentalCar.Type          = comboBox_carType.Text;
                rentalCar.PricePerDay   = numeric_pricePerDay.Value;
                rentalCar.Available     = true;
                rentalCar.AvailableFrom = DateTime.Now;
                rentalCarViewModel.AddNewCar(rentalCar);
                rentalCarViewModel.SerializeCars();
                ShowMsg("Adding car", "Car added successfully");
                this.Close();
            }
        }