/// <summary> /// an event to add the station /// </summary> private void AddAdjStation_Click(object sender, RoutedEventArgs e) { AddAdj ad = new AddAdj(Adjs, MyStation.Code); if (ad.ShowDialog() == true) { foreach (BO.Station item in ad.Selected) { BO.AdjacentStation adjacent = new BO.AdjacentStation { AdjStation = item, AverageTime = ad.adj.AverageTime, Distance = ad.adj.Distance }; Adjs.Insert(0, adjacent); MyStation.AdjacentStations = Adjs; bl.AddAdjacentStations(adjacent, item.Code); } } }
/// <summary> /// an event to open the add station in line winndow /// </summary> private void AddStation_Click(object sender, RoutedEventArgs e) { BO.LineStation ToAdd = new BO.LineStation() { Station = bl.GetStation(((Stat)cmbxStation.SelectedItem).Code), Distance = 0, DrivingTime = TimeSpan.Zero, ID = bl.GetLineStationId(), IndexInLine = MyLine.RouteLength, LineId = MyLine.ID }; bl.AddLineStation(ToAdd); stationInLine.Add(ToAdd); MyLine.RouteLength++; if (Adj != null) { Adj.Distance = int.Parse(txbDist.Text); Adj.AverageTime = TimeSpan.Parse(txbTime.Text); stationInLine.Last().Distance = Adj.Distance; stationInLine.Last().DrivingTime = Adj.AverageTime; try { if (Adj.AdjStation.Code != stationInLine.Last().Station.Code) { bl.AddAdjacentStations(Adj, stationInLine.Last().Station.Code); } } catch (BO.BadAdjacentStationsException) { bl.UpdateAdjacentStations(Adj, stationInLine.Last().Station.Code); } } RestStations.Remove(RestStations.First(it => it.Code == ToAdd.Station.Code)); cmbxStation.SelectedItem = RestStations[0]; bl.UpdateLineStationId(); MyLine.StationsRoute = stationInLine; MyLine.FirstStation = stationInLine.FirstOrDefault().Station.Code; MyLine.LastStation = stationInLine.Last().Station.Code; }