示例#1
0
        private void AddRent()
        {
            try
            {
                Rent rent;
                rent = new Rent();
                Car car;
                car = _readRepositoryCar.GetById(int.Parse(textBoxCarId.Text)).FirstOrDefault();
                if (car.available == false)
                {
                    MessageBox.Show("samochod jest niedostepny");
                }
                else
                {
                    Car newCar;
                    newCar           = car;
                    newCar.available = false;
                    _writeRepositoryCar.Edit(car, newCar);

                    User user;
                    user            = _readRepositoryUser.GetById(int.Parse(textBoxUserId.Text)).FirstOrDefault();
                    rent.User       = user;
                    rent.Car        = car;
                    rent.Expense    = 0;
                    rent.DateOfHire = DateTime.Today;
                    rent.DateOfEnd  = null;
                    _writeRepositoryRent.Create(rent);
                }
            }
            catch
            {
                MessageBox.Show("Niepoprawne Dane");
            }
        }
 private void EditCar()
 {
     try
     {
         int id;
         id = int.Parse(dataGridViewCar.SelectedRows[0].Cells[0].Value.ToString());
         Car car;
         car = _readRepositoryCar.GetById(id).FirstOrDefault();
         Car newCar;
         newCar = car;
         if (textBoxVin.Text != "")
         {
             newCar.Vin = textBoxVin.Text;
         }
         if (textBoxBrand.Text != "")
         {
             newCar.Brand = textBoxBrand.Text;
         }
         if (textBoxModel.Text != "")
         {
             newCar.Model = textBoxModel.Text;
         }
         if (comboBoxFuel.Text != "")
         {
             newCar.Fuel = comboBoxFuel.Text;
         }
         if (textBoxYear.Text != "")
         {
             newCar.Year = int.Parse(textBoxYear.Text);
         }
         if (textBoxDescription.Text != "")
         {
             newCar.Description = textBoxDescription.Text;
         }
         if (comboBoxAvaliable.Text != "")
         {
             if (comboBoxAvaliable.Text == "True")
             {
                 newCar.available = true;
             }
             else
             {
                 newCar.available = false;
             }
         }
         if (textBoxCoast.Text != "")
         {
             newCar.Cost = float.Parse(textBoxDescription.Text);
         }
         _writeRepositorycar.Edit(car, newCar);
     }
     catch
     {
         MessageBox.Show("Nie podales pewnie zadnych danych do zmiany,lub nie zaznaczyles nic w dataGridView");
         throw;
     }
 }