/// <summary> /// Initializes a new instance. /// </summary> public Model(PreControl preControl, MainControl mainControl, EndControl endControl, Vehicle[] vehicles = null) { vehicles = vehicles ?? new[] { new Vehicle { Kind = VehicleKind.OverheightVehicle }, new Vehicle { Kind = VehicleKind.OverheightVehicle }, new Vehicle { Kind = VehicleKind.HighVehicle } }; VehicleSet = new VehicleSet(vehicles); VehicleSet.FinishedObserver = new FinishedObserverDisabled(); SetupController(preControl); SetupController(mainControl); SetupController(endControl); HeightControl = new HeightControl(preControl, mainControl, endControl); Bind(nameof(VehicleSet.IsTunnelClosed), nameof(HeightControl.TrafficLights.IsRed)); }
private void button_blocked_Click(object sender, EventArgs e) { //if car is in service try { int row = dataGridView_care_car_DB.CurrentCell.RowIndex; int car_id = (int)dataGridView_care_car_DB.Rows[row].Cells[0].Value; VehicleSet veh = db.VehicleSets.Where(v => v.vehicle_id == car_id).First(); if (veh.available == "yes") { veh.available = "no"; db.SubmitChanges(); fillDataGridView(); } else if (veh.available == "Serwis") { MessageBox.Show("Auto jest na Serwisie", "Information available", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { MessageBox.Show("Auto jest juz niedostępne", "Information available", MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (Exception) { MessageBox.Show("Zaznacz samochód, który chcesz blokować", "Error check", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void button_repaired_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(textBox_price.Text)) { MessageBox.Show("Wpisz poniesiony koszt na naprawę", "Error check", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { try { int row = dataGridView_cars_on_service.CurrentCell.RowIndex; int car_id = (int)dataGridView_cars_on_service.Rows[row].Cells[0].Value; int service_id = (int)dataGridView_cars_on_service.Rows[row].Cells[1].Value; Care_serviceSet care = db.Care_serviceSets.Where(p => p.ServiceSet.service_id == service_id).First(); care.data_to = DateTime.Today; Check_vehicleSet check = db.Check_vehicleSets.Where(p => p.Vehicle_vehicle_id == car_id).First(); ServiceSet service = db.ServiceSets.Where(p => p.service_id == service_id).First(); service.is_repair = true; VehicleSet veh = db.VehicleSets.Where(p => p.vehicle_id == car_id).First(); veh.available = "yes"; if (service.name == "Wymiana oleju + filtry") { check.oil_change_mileage += 15000; } else if (service.name == "Wymiana rozrzadu") { check.timing_gear_mileage += 15000; } else if (service.name == "Przegląd") { check.tech_review.AddYears(1); } care.price = Convert.ToDouble(textBox_price.Text); db.SubmitChanges(); fillDataGridView(); fillDataGridView2(); textBox_price.Clear(); } catch (Exception) { MessageBox.Show("Zaznacz samochód, który został naprawiony", "Error check", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
private void button_unblocking_Click(object sender, EventArgs e) { try { int row = dataGridView_care_car_DB.CurrentCell.RowIndex; int car_id = (int)dataGridView_care_car_DB.Rows[row].Cells[0].Value; var chceck_serv = db.Care_serviceSets.Where(v => v.CareSet.Vehicle_vehicle_id == car_id && v.ServiceSet.is_repair == false).Any(); if (chceck_serv) { MessageBox.Show("Nie można odblokować auta będącego w serwsie", "Error check", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { VehicleSet veh = db.VehicleSets.Where(v => v.vehicle_id == car_id).First(); if (veh.available == "no") { veh.available = "yes"; db.SubmitChanges(); fillDataGridView(); } else if (veh.available == "Serwis") { MessageBox.Show("Auto jest na Serwisie", "Information available", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { MessageBox.Show("Auto jest juz dostępne", "Information available", MessageBoxButtons.OK, MessageBoxIcon.Information); } } } catch (Exception) { MessageBox.Show("Zaznacz samochód, który chcesz blokować", "Error check", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void button_confirm_end_rent_Click(object sender, EventArgs e) { try { var rent = (from x in db.RentSets where x.rent_id == rent_id select x).Single(); if (!string.IsNullOrEmpty(textBox_mileage.Text)) { if (rent.mileage_start < Convert.ToInt32(textBox_mileage.Text)) { rent.mileage_end = Convert.ToInt32(textBox_mileage.Text); try { VehicleSet veh = (from x in db.VehicleSets where x.vehicle_id == car_id select x).Single(); veh.mileage = Convert.ToInt32(textBox_mileage.Text); db.SubmitChanges(); MessageBox.Show("Zakończenie rezerwacji zakończyło się powodzeniem", "Ending Rent", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception) { MessageBox.Show("Nie udało się nadpisać przebiegu pojazdu", "Error Ending Rent", MessageBoxButtons.OK, MessageBoxIcon.Error); } mileage1 = Convert.ToInt32(textBox_mileage.Text) - Convert.ToInt32(dataGridView_my_rents.Rows[row].Cells[6].Value.ToString()); if (comboBox_type_cost.SelectedIndex == -1) { db.SubmitChanges(); } else if (comboBox_type_cost.Text == "Tankowanie") { litres = Convert.ToDouble(textBox_litres.Text); PurchaseSet car = new PurchaseSet() { Rent_rent_id = rent_id, price = Convert.ToDouble(textBox_all_cost.Text), type = "Paliwo", purchase_date = rent.date_to, litres = Convert.ToDouble(textBox_litres.Text), mileage = mileage1 }; db.PurchaseSets.InsertOnSubmit(car); db.SubmitChanges(); } else if (comboBox_type_cost.Text == "Tankowanie oraz inne") { litres = Convert.ToDouble(textBox_litres.Text); PurchaseSet car = new PurchaseSet() { Rent_rent_id = rent_id, price = Convert.ToDouble(textBox_all_cost.Text), type = textBox_other.Text, purchase_date = rent.date_to, litres = litres, mileage = mileage1 }; db.PurchaseSets.InsertOnSubmit(car); db.SubmitChanges(); } else if (comboBox_type_cost.Text == "Inne") { PurchaseSet car = new PurchaseSet() { Rent_rent_id = rent_id, price = Convert.ToDouble(textBox_all_cost.Text), type = textBox_other.Text, purchase_date = rent.date_to, litres = 0, mileage = mileage1 }; db.PurchaseSets.InsertOnSubmit(car); db.SubmitChanges(); } fillDataGridView(); litres_and_other_hide(); } else { MessageBox.Show("Przebieg po jest mniejszy niż przed", "Error Ending Rent", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show("Wpisz przebieg po zakończeniu jazd", "Error Ending Rent", MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (Exception) { MessageBox.Show("Zaznacz wypożyczenie", "Error Ending Rent", MessageBoxButtons.OK, MessageBoxIcon.Error); } // czyszczenie textBox_mileage.Clear(); textBox_other.Clear(); textBox_litres.Clear(); textBox_all_cost.Clear(); }
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_add_car_Click(object sender, EventArgs e) { double consump = 0; bool confirm = false; try { if (textBox_avg_fuel.Text.Contains(".")) { consump = Convert.ToDouble(textBox_avg_fuel.Text.Replace('.', ',')); } else { consump = Convert.ToDouble(textBox_avg_fuel.Text); } } catch { MessageBox.Show("Bład dodania auta", "Błąd", MessageBoxButtons.OK, MessageBoxIcon.Error); } using (DataBaseDataContext db = new DataBaseDataContext()) { string plate = textBox_license.Text; string plateV1 = plate.ToUpper(); try { VehicleSet car = new VehicleSet() { brand = textBox_brand.Text, model = textBox_model.Text, version = comboBox_car_version.Text, equipment = "", licence_plate = plateV1, fuel_type = comboBox_type_of_fuel.Text, avg_consumption = Convert.ToDouble(consump), available = "yes", mileage = Convert.ToInt32(textBox_mileage.Text) }; db.VehicleSets.InsertOnSubmit(car); db.SubmitChanges(); VehicleSet newcar = db.VehicleSets.OrderByDescending(p => p.vehicle_id).First(); Check_vehicleSet check = new Check_vehicleSet() { tech_review = dateTimePicker_date_tech.Value, oil_change = dateTimePicker_oil_date.Value, oil_change_mileage = Convert.ToInt32(textBox_oil_km.Text), timing_gear = dateTimePicker_gear_date.Value, timing_gear_mileage = Convert.ToInt32(textBox_gear_km.Text), Vehicle_vehicle_id = newcar.vehicle_id, }; db.Check_vehicleSets.InsertOnSubmit(check); db.SubmitChanges(); confirm = true; } catch { MessageBox.Show("Bład dodania auta", "Błąd", MessageBoxButtons.OK, MessageBoxIcon.Error); } if (confirm) { MessageBox.Show("Dodano auto", "Potwierdzenie", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); textBox_age.Clear(); textBox_avg_fuel.Clear(); textBox_brand.Clear(); textBox_license.Clear(); textBox_mileage.Clear(); textBox_model.Clear(); textBox_oil_km.Clear(); textBox_gear_km.Clear(); } } }
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); } } }