BO.BusLine BusLineDoBoAdapter(DO.BusLine lineDo) { BO.BusLine lineBo = new BO.BusLine(); lineDo.CopyPropertiesTo(lineBo); DO.BusLine busLine = dl.GetLine(lineBo.BusLineNumber, AreasAdapter(lineBo.Area)); List <int> request = (from station in dl.GetAllLineStationsBy(s => s.LineId == busLine.Id) orderby station.RankInLine select station.StationKey).ToList(); lineBo.AllStationsOfLine = request; for (int i = 0; i < lineBo.AllStationsOfLine.Count() - 1; i++) { DO.BusStation station1 = BusStationBoDoAdapter(GetBusStation(lineBo.AllStationsOfLine.ElementAt(i))); DO.BusStation station2 = BusStationBoDoAdapter(GetBusStation(lineBo.AllStationsOfLine.ElementAt(i + 1))); lineBo.TotalDistance += dl.GetFollowingStations(station1, station2).Distance; lineBo.TotalTime += dl.GetFollowingStations(station1, station2).AverageJourneyTime; } lineBo.TotalDistance = Math.Round(lineBo.TotalDistance /= 1000); lineBo.AllLineTripsOfLine = (from lt in GetAllLineTripsBy(t => t.LineId == busLine.Id) orderby lt.StartTimeRange select lt).ToList(); return(lineBo); }
/// <summary> /// open the window of the busLine info /// </summary> private void ShowLinesInfo() { BO.BusLine busLine = LinesDataGrid.SelectedItem as BO.BusLine; if (busLine != null)//prevent delete+double click { LineInfo win = new LineInfo(busLine); win.ShowDialog(); ShowLines(); } }
public void UpdateBusLine(int id, Action <DO.BusLine> action) { try { BO.BusLine line = GetBusLine(id); dl.UpdateLine(BusLineBoDoAdapter(line), action); } catch (DO.InexistantLineException ex) { throw new BO.InexistantLineException("This Line not exist", ex); } }
public void UpdateBusLine(BO.BusLine line) { try { DeleteBusLine(line); AddBusLine(line); } catch (DO.InexistantLineException ex) { throw new BO.InexistantLineException("This Line not exist", ex); } }
public void AddBusLine(BO.BusLine newLine) { //1. Verify if all stations of list exists foreach (int item in newLine.AllStationsOfLine) { try { dl.GetStation(item); } catch (DO.InexistantStationException ex) { throw new BO.InexistantStationException("Please create station and then add it to line", ex); } } for (int i = 0; i < (newLine.AllStationsOfLine.Count() - 1); i++) { //2. Add FollowingStations if it's necessary DO.BusStation station1 = dl.GetStation(newLine.AllStationsOfLine.ElementAt(i)); DO.BusStation station2 = dl.GetStation(newLine.AllStationsOfLine.ElementAt(i + 1)); if (dl.GetFollowingStations(station1, station2) == null) { dl.AddFollowingStations(station1, station2); } newLine.TotalTime += dl.GetFollowingStations(station1, station2).AverageJourneyTime; } dl.AddLine(BusLineBoDoAdapter(newLine));//add line to can then add lisStations with LineId (attributed in dl.AddLine) //3. Create corresponding line stations int lineId = dl.GetLine(newLine.BusLineNumber, AreasAdapter(newLine.Area)).Id; for (int i = 0; i < newLine.AllStationsOfLine.Count(); i++) { int stationKey = GetBusStation(newLine.AllStationsOfLine.ElementAt(i)).BusStationKey; if (GetLineStation(lineId, stationKey) == null) { AddLineStation(new BO.LineStation { LineId = lineId, StationKey = stationKey, RankInLine = i + 1 }); } } //4. Create corresponding trip line foreach (BO.LineTrip item in newLine.AllLineTripsOfLine) { item.LineId = lineId; AddLineTrip(item); } }
public void DeleteBusLine(BO.BusLine lineBo) { try { dl.DeleteLine(BusLineBoDoAdapter(lineBo)); dl.DeleteLineStation(s => s.LineId == lineBo.Id); dl.DeleteLineTrip(t => t.LineId == lineBo.Id); } catch (DO.InexistantLineException ex) { throw new BO.InexistantLineException("This Line not exist", ex); } }
/// <summary> /// window ctor /// </summary> /// <param name="busline"></param> public NewTripInfo(BO.BusLine busline) { InitializeComponent(); try { bl = BLFactory.GetBL(); busLine = busline; } catch (BO.MissingData ex) //creating bo failed { MessageBox.Show(ex.Message); } }
/// <summary> /// delete BusLine from the data /// </summary> /// <param name="sender">sender of the event</param> /// <param name="e">e of the argument</param> private void DeleteLine(object sender, RoutedEventArgs e) { try { Button bt = sender as Button; BO.BusLine LineToDel = bt.DataContext as BO.BusLine; bl.DeleteBusLine(LineToDel); ShowLines(); } catch (BO.BusLineNotFound ex) // can't find the BusLine { MessageBox.Show(ex.Message + string.Format(" wrong {0} Line to delete", ex.LineNumber), "Object not found", MessageBoxButton.OK, MessageBoxImage.Error); } }
/// <summary> /// ctor of the window that get BO.bus /// </summary> /// <param name="busLine">bus that sending from the win that call this win</param> public LineInfo(BusLine busLine) { InitializeComponent(); try { bl = BLFactory.GetBL(); } catch (BO.MissingData ex) // create BO failed { MessageBox.Show(ex.Message); } curBusLine = busLine; AreasCB.ItemsSource = Enum.GetValues(typeof(BO.Areas)); UpdateData(); }
internal TimeSpan DurationOfTravel(BO.BusLine line, int stationKey) { int rankOfStation = dl.GetLineStation(line.Id, stationKey).RankInLine; IEnumerable <DO.LineStation> stations = (from lineStat in dl.GetAllLineStationsBy(l => l.LineId == line.Id).ToList() where lineStat.RankInLine <= rankOfStation select lineStat).ToList(); TimeSpan travelDuration = new TimeSpan(); for (int i = 0; i < stations.Count() - 1; i++) { DO.BusStation station1 = BusStationBoDoAdapter(GetBusStation(stations.ElementAt(i).StationKey)); DO.BusStation station2 = BusStationBoDoAdapter(GetBusStation(stations.ElementAt(i + 1).StationKey)); travelDuration += dl.GetFollowingStations(station1, station2).AverageJourneyTime; } return(travelDuration); }
public IEnumerable <LineTiming> ListArrivalOfLine(int lineId, TimeSpan hour, int stationKey) { //Calcul of TravelTime between first station of line and our station BO.BusLine line = GetBusLine(lineId); TimeSpan durationOfTravel = DurationOfTravel(line, stationKey); DO.LineTrip myLineTrip = dl.GetLineTrip(lineId, hour); List <LineTiming> listTiming = new List <LineTiming>(); //initialize list of all timing for the specified line while (myLineTrip.StartTimeRange + durationOfTravel < hour) { myLineTrip.StartTimeRange += myLineTrip.Frequency; //we can change value of StartTimeRange thanks to Clone() } for (TimeSpan i = myLineTrip.StartTimeRange; i <= hour;) { listTiming.Add(new LineTiming { TripStart = i, LineId = myLineTrip.LineId, ExpectedTimeTillArrive = CalculateTimeOfArrival(i, durationOfTravel) }); i += myLineTrip.Frequency; } //if station is the first we want to show 2 nexts departures if (stationKey == line.FirstStationKey) { listTiming.Add(new LineTiming { TripStart = myLineTrip.StartTimeRange, LineId = myLineTrip.LineId, ExpectedTimeTillArrive = myLineTrip.StartTimeRange }); myLineTrip.StartTimeRange += myLineTrip.Frequency; listTiming.Add(new LineTiming { TripStart = myLineTrip.StartTimeRange, LineId = myLineTrip.LineId, ExpectedTimeTillArrive = myLineTrip.StartTimeRange }); } return(listTiming); }
/// <summary> /// update the data according to the data of the bus that sending to the window /// </summary> private void UpdateData() { try { curBusLine = bl.GetUpdatedBOBusLine(curBusLine.DOLineId); lineStations = new ObservableCollection <BO.LineStation>(curBusLine.LineStations); newStations = new ObservableCollection <BO.Station>(bl.GetAllStationsNotInLine(curBusLine.DOLineId)); trips = new ObservableCollection <LineTrip>(bl.GetAllLineTripsInLine(curBusLine)); mainGrid.DataContext = curBusLine; LineDataGrid.ItemsSource = lineStations; TripsDataGrid.ItemsSource = trips; NewStationsComboBox.DataContext = newStations; ExistingStations.DataContext = lineStations; } catch (BO.BusLineNotFound ex) // can't get the updated bus from bl { MessageBox.Show(ex.Message + string.Format(" Line: {0}", ex.LineNumber), "Object Not Found", MessageBoxButton.OK, MessageBoxImage.Error); } catch (BO.MissingData ex) // missing data { MessageBox.Show(ex.Message); } }
DO.BusLine BusLineBoDoAdapter(BO.BusLine lineBo) { DO.BusLine lineDo = new DO.BusLine(); lineBo.CopyPropertiesTo(lineDo); return(lineDo); }