예제 #1
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (isEditMode)
            {
                //edit code
                var id  = int.Parse(lblid.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 = tbLicense.Text;
            }
            else
            {
                //add code
                var newCar = new typesOfCar
                {
                    licensePlateNumber = tbLicense.Text,
                    make  = tbMake.Text,
                    model = tbModel.Text,
                    vin   = tbVin.Text,
                    year  = int.Parse(tbYear.Text)
                };
                _db.typesOfCars.Add(newCar);
            }
            _db.SaveChanges();
            _manageVehicle.PopulateGrid();
            MessageBox.Show("Done");
            Close();
        }
예제 #2
0
 private void PopulateFields(typesOfCar car)
 {
     lblid.Text     = car.id.ToString();
     tbMake.Text    = car.make;
     tbModel.Text   = car.model;
     tbVin.Text     = car.vin;
     tbYear.Text    = car.year.ToString();
     tbLicense.Text = car.licensePlateNumber;
 }
예제 #3
0
        public AddEditVehicle(typesOfCar carToEdit, ManageVehicleListing manageVehicle = null)
        {
            InitializeComponent();
            lbltitle.Text = "Edit Vehicle";
            this.Text     = "Edit Vehicle";

            if (carToEdit == null)
            {
                MessageBox.Show("Please ensure that  u selected a valid record to edit");
                Close();
            }
            else
            {
                isEditMode     = true;
                _manageVehicle = manageVehicle;
                _db            = new carRentalEntities();
                PopulateFields(carToEdit);
            }
        }