/// <summary> /// an event that opens the delte window /// </summary> private void Delete_Click(object sender, RoutedEventArgs e) { BO.BusOnTrip b = ((Button)sender).DataContext as BO.BusOnTrip; bl.DeleteBusOnTrip(b.ID); trips.Remove(b); MessageBox.Show("The Trip: " + b.ID + " deleted succsesfully!", "Done succusesfully", MessageBoxButton.OK, MessageBoxImage.Information); }
/// <summary> /// a window constructor /// </summary> /// <param name="ADD">is add or update</param> /// <param name="fromBus">is the window open from bus</param> /// <param name="busOn">if it is update the trip to update</param> public AddTrip(bool ADD, bool fromBus, int index = 0, BO.BusOnTrip busOn = default) { InitializeComponent(); MyTrip = busOn; Add = ADD; if (ADD) { MyTrip = new BO.BusOnTrip(); MyTrip.ID = bl.GetBusOnId(); } else { cmbLines.SelectedValue = MyTrip.LineId; } DataContext = MyTrip; buses = new ObservableCollection <BO.Bus>(bl.GetAllBus()); cmbLicens.ItemsSource = buses; if (fromBus) { cmbLicens.SelectedIndex = index; cmbLicens.IsEnabled = false; } else { cmbLines.SelectedIndex = index; cmbLines.IsEnabled = false; } cmbLicens.DisplayMemberPath = "LicensNumber"; cmbLines.ItemsSource = bl.GetAllLines(); cmbLines.DisplayMemberPath = "LineCode"; ato.Text = new TimeSpan(DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second).ToString(); }
/// <summary> /// an event to start a traveling the bus /// </summary> public void BusDrive_Click(object sender, RoutedEventArgs e) { PO.Bus MyBus = ((Button)sender).DataContext as PO.Bus; Button btn = (Button)sender; TextBox tb = ((StackPanel)btn.Parent).FindName("drive") as TextBox; int time = 0; double distance = 0; if (MyBus.Upstatus == BO.Status.Ready) { try { if (cmbLines.SelectedItem == null) { MessageBox.Show("Please choose a line for drive"); } else { var listRouth = (cmbLines.SelectedItem as BO.Line).StationsRoute.ToList(); if (listRouth != null && listRouth.Count() > 0) { distance = bl.GetDistanceBetweenStations(listRouth[0].Station.Code, listRouth[listRouth.Count - 1].Station.Code, (cmbLines.SelectedItem as BO.Line).ID); time = (int)(bl.GetTimeBetweenStations(listRouth[0].Station.Code, listRouth[listRouth.Count - 1].Station.Code, (cmbLines.SelectedItem as BO.Line).ID).TotalSeconds); if (MyBus.Upstatus == BO.Status.Ready && MyBus.Status((int)distance / 1000)) { if (MyBus.simulation == null) { MyBus.simulation = new SimulationOfBus(MyBus); } MyBus.simulation.Driving((int)(time * 0.98)); int index = listBuses.IndexOf(MyBus); listBuses.Remove(MyBus); listBuses.Insert(index, MyBus); bl.Drive(MyBus, (int)distance / 1000); bl.UpdateBusDetails(MyBus); BO.BusOnTrip busOnTrip = new BO.BusOnTrip { LicensNumber = MyBus.LicensNumber, ActualTakeOff = new TimeSpan(DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second), LineNumber = (cmbLines.SelectedItem as BO.Line).LineCode, LineId = (cmbLines.SelectedItem as BO.Line).ID, ID = bl.GetBusOnId(), PrevStation = (cmbLines.SelectedItem as BO.Line).StationsRoute.ToList()[0].Station.Code, DriverId = MyUser.UserName }; bl.AddBusOnTrip(busOnTrip); GoToTrip(busOnTrip, (cmbLines.SelectedItem as BO.Line)); } else { MessageBox.Show("The Bus is not ready to drive"); } } } } catch (Exception ex) { MessageBox.Show(ex.Message); } } else { MessageBox.Show("The Bus is not ready to drive"); } }
/// <summary> /// an event to get the bus on a trip /// </summary> public void GoToTrip(BO.BusOnTrip b, BO.Line l) { PO.CurrentStation current = new PO.CurrentStation { TripStartTime = b.ActualTakeOff, EndStationName = l.StationsRoute.ToList().Last().Station.Address, UplineStations = l.StationsRoute, LineID = l.ID, LineNum = l.LineCode }; PO.CurrentStation.LineTimings.Add(current); if (current.simulation == null) { current.simulation = new SimulationOfTrip(current); } current.simulation.Starting(); }
/// <summary> /// an event that opens the updade window /// </summary> private void Update_Click(object sender, RoutedEventArgs e) { BO.BusOnTrip b = ((Button)sender).DataContext as BO.BusOnTrip; AddTrip upTrip = new AddTrip(false, true, Index, b); if (upTrip.ShowDialog() == true) { bl.UpdateBusOnTrip(b); int i = trips.IndexOf(b); trips.Remove(b); trips.Insert(i, b); busTrips.ItemsSource = trips; } }