Ejemplo n.º 1
0
        /// <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");
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// an event that opens the add window
        /// </summary>
        private void Add_Click(object sender, RoutedEventArgs e)
        {
            AddTrip trip = new AddTrip(true, isBus, Index);

            if (trip.ShowDialog() == true)
            {
                trips.Add(trip.MyTrip);
                bl.AddBusOnTrip(trip.MyTrip);
                busTrips.ItemsSource = trips;
            }
        }