private void button_rent_Click(object sender, EventArgs e)
        {
            try
            {
                int row = dataGridView_veh_DB.CurrentCell.RowIndex;
                car_id = (int)dataGridView_veh_DB.Rows[row].Cells[0].Value;


                if (comboBox_purpose_of_rent.Text == "Służbowy" || comboBox_purpose_of_rent.Text == "Prywatny" || comboBox_purpose_of_rent.Text == "Delegacja")
                {
                    var counter_modulo = db.RentSets
                                         .Where(x => x.Worker_worker_id == user_id &&
                                                ((x.date_from <= time_from &&
                                                  x.date_to >= time_from) ||
                                                 (x.date_from <= time_to &&
                                                  x.date_to >= time_to)) && x.mileage_end == 0)
                                         .Select(x => x.rent_id)
                                         .Count();


                    if (counter_modulo == 0)
                    {
                        try
                        {
                            ReservationSet newReserv = new ReservationSet()
                            {
                                purpose            = comboBox_purpose_of_rent.Text,
                                date_from          = time_from,
                                date_to            = time_to,
                                Worker_worker_id   = user_id,
                                Vehicle_vehicle_id = car_id
                            };
                            db.ReservationSets.InsertOnSubmit(newReserv);
                            db.SubmitChanges();
                        }
                        catch (Exception)
                        {
                            MessageBox.Show("Nie udało się dokonać wypożyczenia pojazdu", "Error Rent", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }

                        try
                        {
                            var mileage_st = (from x in db.VehicleSets
                                              where x.vehicle_id == car_id
                                              select x.mileage)
                                             .Single();

                            ReservationSet reserv = db.ReservationSets
                                                    .Where(x => x.date_to == time_to &&
                                                           x.date_from == time_from &&
                                                           x.Vehicle_vehicle_id == car_id)
                                                    .First();
                            RentSet newRent = new RentSet()
                            {
                                purpose                    = comboBox_purpose_of_rent.Text,
                                date_from                  = time_from,
                                date_to                    = time_to,
                                mileage_start              = mileage_st,
                                Worker_worker_id           = user_id,
                                Reservation_reservation_id = reserv.reservation_id,
                                Vehicle_vehicle_id         = car_id
                            };
                            db.RentSets.InsertOnSubmit(newRent);
                            db.SubmitChanges();

                            MessageBox.Show("Wypożyczyłeś pojazd od dzisiaj do " + time_to.Date.ToShortDateString(), "Good Rent", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            fillDataGridView();
                        }
                        catch (Exception)
                        {
                            MessageBox.Show("Nie udało się dokonać wypożyczenia pojazdu", "Error Rent", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                    else

                    {
                        MessageBox.Show("Masz już wypożyczone auto w takim okresie", "Błąd", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                else
                {
                    MessageBox.Show("Wybierz cel wypożyczenia", "Error Car", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            catch (Exception)
            {
                MessageBox.Show("Zaznacz auto które chcesz wypożyczyć", "Error Car", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void button_rent_Click(object sender, EventArgs e)
        {
            try
            {
                if (row == -1)
                {
                    MessageBox.Show("Zaznacz rezerwację", "Good Rent", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    var time_from = Convert.ToDateTime(dataGridView_my_reservation.Rows[row].Cells[4].Value.ToString());
                    var time_to   = Convert.ToDateTime((string)dataGridView_my_reservation.Rows[row].Cells[5].Value.ToString());


                    var counter_modulo = db.RentSets
                                         .Where(x => x.Worker_worker_id == user_id &&
                                                ((x.date_from <= time_from &&
                                                  x.date_to >= time_from) ||
                                                 (x.date_from <= time_to &&
                                                  x.date_to >= time_to)))
                                         .Select(x => x.rent_id)
                                         .Count();

                    if (time_from > DateTime.Today)
                    {
                        MessageBox.Show("Jeszcze nie możesz wypożyczyć tego samochodu, możesz to zrobić: \n" + time_from.ToShortDateString(), "Good Rent", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else
                    {
                        if (counter_modulo == 0)
                        {
                            RentSet newRent = new RentSet()
                            {
                                purpose                    = dataGridView_my_reservation.Rows[row].Cells[7].Value.ToString(),
                                date_from                  = Convert.ToDateTime(dataGridView_my_reservation.Rows[row].Cells[4].Value),
                                date_to                    = Convert.ToDateTime(dataGridView_my_reservation.Rows[row].Cells[5].Value),
                                mileage_start              = Convert.ToInt32(dataGridView_my_reservation.Rows[row].Cells[8].Value),
                                Worker_worker_id           = user_id,
                                Reservation_reservation_id = Convert.ToInt32(dataGridView_my_reservation.Rows[row].Cells[9].Value),
                                Vehicle_vehicle_id         = Convert.ToInt32(dataGridView_my_reservation.Rows[row].Cells[0].Value),
                                mileage_end                = 0
                            };

                            db.RentSets.InsertOnSubmit(newRent);
                            db.SubmitChanges();

                            MessageBox.Show("Wypożyczyłeś samochód, bezpiecznej jazdy", "Good Rent", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            fillDataGridView();
                        }
                        else

                        {
                            MessageBox.Show("Masz już wypożyczone auto w takim okresie", "Błąd", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                }
            }
            catch (Exception)
            {
                MessageBox.Show("Coś się popsuło i nie było mnie słychać", "Good Rent", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            clear();
        }