Пример #1
0
 private void PopulateFields(TypesOfCars car)
 {
     labId.Text        = car.id.ToString();
     tbMake.Text       = car.Make;
     tbModel.Text      = car.Model;
     tbVIN.Text        = car.VIN;
     tbYear.Text       = car.Year.ToString();
     tbLicenseNum.Text = car.LicensePlateNumber;
 }
Пример #2
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                //Added Validation for make and model
                if (string.IsNullOrWhiteSpace(tbMake.Text) ||
                    string.IsNullOrWhiteSpace(tbModel.Text))
                {
                    MessageBox.Show("Please ensure that you provide a make and a model");
                }
                else
                {
                    //if(isEditMode == true)
                    if (isEditMode)
                    {
                        //Edit Code here
                        var id  = int.Parse(labId.Text);
                        var car = _db.TypesOfCars.FirstOrDefault(q => q.id == id);
                        car.Model = tbModel.Text;
                        car.Make  = tbMake.Text;
                        car.VIN   = tbVIN.Text;
                        car.Year  = int.Parse(tbYear.Text);
                        car.LicensePlateNumber = tbLicenseNum.Text;
                    }
                    else
                    {
                        //Added validation for make and model of cars being added

                        // Add Code Here
                        var newCar = new TypesOfCars
                        {
                            LicensePlateNumber = tbLicenseNum.Text,
                            Make  = tbMake.Text,
                            Model = tbModel.Text,
                            VIN   = tbVIN.Text,
                            Year  = int.Parse(tbYear.Text)
                        };

                        _db.TypesOfCars.Add(newCar);
                    }
                    _db.SaveChanges();
                    _manageVehicleListing.PopulateGrid();
                    MessageBox.Show("Operation Completed. Refresh Grid To see Changes");
                    Close();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show($"Error: {ex.Message}");
            }
        }
Пример #3
0
 public AddEditVehicle(TypesOfCars carToEdit, ManageVehicleListing manageVehicleListing = null)
 {
     InitializeComponent();
     labTitle.Text         = "Edit Vehicle";
     this.Text             = "Edit Vehicle";
     _manageVehicleListing = manageVehicleListing;
     if (carToEdit == null)
     {
         MessageBox.Show("Please ensure that you selected a valid record to edit");
         Close();
     }
     else
     {
         isEditMode = true;
         _db        = new CarRentalEntities1();
         PopulateFields(carToEdit);
     }
 }