private void pbUpButton_Click(object sender, RoutedEventArgs e) { BO.LineStation lineStation = ((sender as Button).DataContext as BO.LineStation); BO.Line line = cbLineNum.SelectedItem as BO.Line; bl.MoveStationUpInLine(line.ID, lineStation.StationCode); UpdateLinesView(sender, e); }
public LineViewInfo(BO.Line line) { InitializeComponent(); try { if (line == null) { Close(); } line = myBL.GetLine(line.Id); // Get the line updated from database } catch (BO.BadLineException ex) { MessageBox.Show("Error: " + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); Close(); } textBlockLineInfo.Text = $"Line number: {line.Code}"; textBlockArea.Text = $"Area: {line.Area.ToString().ToLower()}"; myLineStationsList = new ObservableCollection <BO.LineStation>(line.LineStations); lvLineStations.ItemsSource = myLineStationsList; newLineStation = new BO.LineStation() // Set with defult values { LineId = line.Id, // Set the line station with the id of the line shown LineStationIndex = -1, IsDeleted = false, NextStation = -1, PrevStation = -1, Station = -1 }; }
/// <summary> /// This function is responsible for the process of receiving and checking the input /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void stopListBoxB_SelectionChanged(object sender, SelectionChangedEventArgs e) { tempStopB = (BO.LineStation)stopListBoxB.SelectedItem; stopBLabel.DataContext = tempStopB; sIndex = stopListBoxB.SelectedIndex; stopBPicked = true; if (stopAPicked) { try { var a = new BO.SequentialStopInfo(); a.Distance = bl.DistanceCalculate(tempLine.Number, tempStopA.Code, tempStopB.Code); a.TravelTime = bl.TravelTimeCalculate(tempLine.Number, tempStopA.Code, tempStopB.Code); distance_Binding.DataContext = a; travel_time_Binding.DataContext = a; if (a.Distance == -1) { throw new Exception(); } } catch (Exception) { MessageBox.Show("Please enter information about the distance and travel time between the following stations: " + bl.GetNameByStopCode(tempStopA.Code) + " " + bl.GetNameByStopCode(tempStopB.Code)); } } }
/// <summary> /// Defines actions to be performed when a button is pressed /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Delete_Click(object sender, RoutedEventArgs e) { Button a = (Button)sender; tempStation = (BO.LineStation)a.DataContext; bl.DeleteLineStation(tempStation.Code, managingLine.Id, tempStation.NumberInLine); stopsList.ItemsSource = managingLine.Stops; stopsList.Items.Refresh(); }
private void pbAddStations_Click(object sender, RoutedEventArgs e) { foreach (int stationCode in stationsToAdd) { BO.LineStation newLineStation = new BO.LineStation { LineID = line.ID, StationCode = stationCode }; bl.AddLineStation(newLineStation); } this.Close(); }
/// <summary> /// window ctor /// </summary> /// <param name="first">the first station</param> /// <param name="second">the second station</param> public UpdateTimeAndDistance(BO.LineStation first, BO.LineStation second) { InitializeComponent(); try { bl = BLFactory.GetBL(); } catch (BO.MissingData ex) // missing data { MessageBox.Show(ex.Message); } firstStation = first; secondStation = second; MainGrid.DataContext = first; SecondSt.DataContext = second; }
/// <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; }
/// <summary> /// an event to delete a line station /// </summary> private void DeleteStations_Click(object sender, RoutedEventArgs e) { BO.LineStation s = ((Button)sender).DataContext as BO.LineStation; foreach (var item in stationInLine) { if (item.IndexInLine > s.IndexInLine) { item.IndexInLine -= 1; } } MyLine.RouteLength--; bl.DeleteLineStationsBy(it => it.LineId == s.ID); stationInLine.Remove(s); if (stationInLine != null && stationInLine.Count() > 0) { MyLine.FirstStation = stationInLine.First().Station.Code; MyLine.LastStation = stationInLine.Last().Station.Code; stationInLine.Last().Distance = 0; stationInLine.Last().DrivingTime = TimeSpan.Zero; } MyLine.StationsRoute = stationInLine; bl.UpdateLine(MyLine); }
private void lineList_SelectionChanged(object sender, SelectionChangedEventArgs e) { tempStation = (BO.LineStation)stopsList.SelectedItem; }