private void add_care_Click(object sender, EventArgs e)// przypisanie auta opiekunowi z listy { bool confirm = false; try { var result = MessageBox.Show("Czy napewno chcesz dodać opieke?", "Potwierdzenie", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.Yes) { int row = dataGridView_Worker.CurrentCell.RowIndex; int row1 = dataGridView_veh.CurrentCell.RowIndex; int selected_worker_id = (int)dataGridView_Worker.Rows[row].Cells[0].Value; var car_id = (int)dataGridView_veh.Rows[row1].Cells[0].Value; var keeper = (from x in db.WorkerSet_Keepers where x.keeper_id == selected_worker_id select x).Any(); if (!keeper) { WorkerSet_Keeper keeperr = new WorkerSet_Keeper() { keeper_id = selected_worker_id, worker_id = selected_worker_id, }; db.WorkerSet_Keepers.InsertOnSubmit(keeperr); db.SubmitChanges(); } int keeper_id = selected_worker_id; CareSet care = new CareSet() { date_from = DateTime.Today, date_to = Convert.ToDateTime("1999 - 01 - 01 00:00:00.000"), Vehicle_vehicle_id = car_id, Keeper_worker_id = keeper_id, }; db.CareSets.InsertOnSubmit(care); db.SubmitChanges(); confirm = true; } } catch { MessageBox.Show("Bład przypisania auta do opiekuna", "Błąd", MessageBoxButtons.OK, MessageBoxIcon.Error); } if (confirm) { MessageBox.Show("Przypisano auto opiekunowi", "Potwierdzenie", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } fillDataGridView(); }
private void button_reserv_Click(object sender, EventArgs e) { if (comboBox_service.SelectedIndex == -1 || string.IsNullOrEmpty(textBox_description.Text)) { MessageBox.Show("Wybierz przyczynę serwisu i opisz problem", "Error check", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { int row = dataGridView_care_car_DB.CurrentCell.RowIndex; car_id = (int)dataGridView_care_car_DB.Rows[row].Cells[0].Value; var count_Reservations = db.ReservationSets .Where(x => x.Vehicle_vehicle_id == car_id && x.Worker_worker_id == user_id && ((x.date_from <= dateTimePicker_from_date_reserv.Value && x.date_to >= dateTimePicker_from_date_reserv.Value) || (x.date_from <= dateTimePicker_to_date_reserv.Value && x.date_to >= dateTimePicker_to_date_reserv.Value))) .Select(x => x.reservation_id) .Count(); if (count_Reservations == 0) { try { string company_name; VehicleSet vechicle = db.VehicleSets.Where(x => x.vehicle_id == car_id).First(); //vechicle.available = "no"; CareSet care_id = db.CareSets .Where(x => x.Vehicle_vehicle_id == car_id) .First(); company_name = comboBox_Company_name.Text; CompanySet company_id = db.CompanySets .Where(x => x.name == company_name) .First(); try { ServiceSet service = new ServiceSet() { is_repair = false, name = comboBox_service.Text, description = textBox_description.Text }; db.ServiceSets.InsertOnSubmit(service); db.SubmitChanges(); } catch (Exception) { MessageBox.Show("Nie udało się oddać auta do serwisu", "Error check", MessageBoxButtons.OK, MessageBoxIcon.Error); } try { ServiceSet service = db.ServiceSets.OrderByDescending(p => p.service_id).First(); Care_serviceSet newservice = new Care_serviceSet() { date_from = dateTimePicker_from_date_reserv.Value, data_to = Convert.ToDateTime("1999-01-01 00:00:00.000"), Care_care_id = care_id.care_id, Service_service_id = service.service_id, price = -10, Company_company_id = company_id.company_id }; db.Care_serviceSets.InsertOnSubmit(newservice); db.SubmitChanges(); MessageBox.Show("Zarezerwowałeś pojazd od " + dateTimePicker_from_date_reserv.Value.ToShortDateString(), "Good Reservation", MessageBoxButtons.OK, MessageBoxIcon.Information); fillDataGridView(); } catch (Exception) { MessageBox.Show("Nie dodało się do bazy care_service", "Error check", MessageBoxButtons.OK, MessageBoxIcon.Error); } try { WorkerSet worker; try { var people = (from x in db.ReservationSets where ((x.date_from >= dateTimePicker_from_date_reserv.Value && x.date_from <= dateTimePicker_to_date_reserv.Value) || (x.date_to >= dateTimePicker_from_date_reserv.Value && x.date_to <= dateTimePicker_to_date_reserv.Value) || (x.date_from >= dateTimePicker_from_date_reserv.Value && x.date_to <= dateTimePicker_to_date_reserv.Value)) && x.Vehicle_vehicle_id == vechicle.vehicle_id && x.Worker_worker_id != user_id select x.Worker_worker_id).Distinct(); string peoples = "Powiadom następujące osoby o wysyłaniu pojazdu na serwis w terminie ich rezerwacji, oraz poproś o usunięcie owej rezerwacji: \n "; foreach (int id in people) { worker = db.WorkerSets.Where(x => x.worker_id == id).SingleOrDefault(); peoples += worker.name + " " + worker.surname + " nr telefonu do pracownika: " + worker.phone_nr.ToString() + "\n"; } if (peoples == "Powiadom następujące osoby o wysyłaniu pojazdu na serwis w terminie ich rezerwacji, oraz poproś o usunięcie owej rezerwacji: \n ") { } else { MessageBox.Show(peoples, "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (Exception) { } ReservationSet newreserv = new ReservationSet() { date_from = dateTimePicker_from_date_reserv.Value, date_to = dateTimePicker_to_date_reserv.Value, purpose = "Serwis", Worker_worker_id = user_id, Vehicle_vehicle_id = vechicle.vehicle_id }; db.ReservationSets.InsertOnSubmit(newreserv); db.SubmitChanges(); } catch (Exception) { MessageBox.Show("Nie udało się stworzyć rezerwacji", "Error check", MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (Exception) { MessageBox.Show("Zaznacz samochód", "Error check", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show("Masz już zarezerwowane auto w takim okresie", "Error Reservation", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
private void button_send_to_service_Click(object sender, EventArgs e) { if (Combobox_service.SelectedIndex == -1 || string.IsNullOrEmpty(textBox_description.Text)) { MessageBox.Show("Wybierz przyczynę serwisu i opisz problem", "Error check", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { try { int row = dataGridView_care_car_DB.CurrentCell.RowIndex; car_id = (int)dataGridView_care_car_DB.Rows[row].Cells[0].Value; string company_name; VehicleSet vechicle = db.VehicleSets.Where(x => x.vehicle_id == car_id).First(); vechicle.available = "Serwis"; CareSet care_id = db.CareSets .Where(x => x.Vehicle_vehicle_id == car_id) .First(); company_name = comboBox_Company_name.Text; CompanySet company_id = db.CompanySets .Where(x => x.name == company_name) .First(); try { ServiceSet service = new ServiceSet() { is_repair = false, name = Combobox_service.Text, description = textBox_description.Text }; db.ServiceSets.InsertOnSubmit(service); db.SubmitChanges(); } catch (Exception) { MessageBox.Show("Nie udało się oddać auta do serwisu", "Error check", MessageBoxButtons.OK, MessageBoxIcon.Error); } try { ServiceSet service = db.ServiceSets.OrderByDescending(p => p.service_id).First(); Care_serviceSet newservice = new Care_serviceSet() { date_from = DateTime.Today, data_to = Convert.ToDateTime("1999 - 01 - 01 00:00:00.000"), Care_care_id = care_id.care_id, Service_service_id = service.service_id, price = -10, Company_company_id = company_id.company_id }; db.Care_serviceSets.InsertOnSubmit(newservice); db.SubmitChanges(); fillDataGridView(); fillDataGridView2(); } catch (Exception) { MessageBox.Show("Nie dodało się do bazy care_service", "Error check", MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (Exception) { MessageBox.Show("Zaznacz samochód", "Error check", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }