/// <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 show the update bus window /// </summary> public void UpDateBus_Click(object sender, RoutedEventArgs e) { PO.Bus b = ((Button)sender).DataContext as PO.Bus; AddBus upBus = new AddBus(false, b); if (upBus.ShowDialog() == true) { bl.UpdateBusDetails(b); b.Status(1); int i = listBuses.IndexOf((PO.Bus)b); listBuses.Remove((PO.Bus)b); listBuses.Insert(i, (PO.Bus)b); } }