private void button_add_company_Click(object sender, EventArgs e) { DataBaseDataContext db = new DataBaseDataContext(); bool confirm = false; if (textBox_name.Text == "" || textBox_city_post.Text == "" || textBox_city.Text == "" || textBox_number_phone.Text == "" || textBox_number_service.Text == "" || textBox_street.Text == "" || textBox_what_are_they_doing.Text == "") { MessageBox.Show("Wymagane są wszystkie pola", "Błąd", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { try { CompanySet newcompany = new CompanySet() { name = textBox_name.Text, description = textBox_what_are_they_doing.Text, address = textBox_street.Text + " " + textBox_number_service.Text + " " + textBox_city.Text + " " + textBox_city_post.Text, phone_nr = textBox_number_phone.Text }; db.CompanySets.InsertOnSubmit(newcompany); db.SubmitChanges(); confirm = true; } catch { MessageBox.Show("Bład dodania firmy do bazy", "Błąd", MessageBoxButtons.OK, MessageBoxIcon.Error); } if (confirm) { MessageBox.Show("Dodano nową firmę", "Potwierdzenie", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); textBox_name.Clear(); textBox_city_post.Clear(); textBox_city.Clear(); textBox_number_phone.Clear(); textBox_number_service.Clear(); textBox_street.Clear(); textBox_what_are_they_doing.Clear(); 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); } } }