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
 public SimulationOfBus(PO.Bus b)
 {
     MyBus  = b;
     worker = new BackgroundWorker();
     worker.WorkerReportsProgress = true;
     worker.DoWork                    += Worker_DoWork;
     worker.ProgressChanged           += Worker_ProgressChanged;
     worker.RunWorkerCompleted        += Complate;
     worker.WorkerSupportsCancellation = true;
 }
Ejemplo n.º 3
0
        /// <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);
            }
        }
Ejemplo n.º 4
0
 /// <summary>
 /// a window constractor
 /// </summary>
 /// <param name="isAdd">if is update or add</param>
 /// <param name="bus">if it update -the bus to update</param>
 public AddBus(bool isAdd = false, PO.Bus bus = default)
 {
     InitializeComponent();
     MyBus = bus;
     if (isAdd)
     {
         MyBus = new PO.Bus();
     }
     DataContext = MyBus;
     Add         = isAdd;
     if (isAdd == false)
     {
         licenum.IsReadOnly = true;
     }
 }
Ejemplo n.º 5
0
        /// <summary>
        /// an event to start refueling the bus
        /// </summary>

        private void BusRefuel_Click(object sender, RoutedEventArgs e)
        {
            PO.Bus MyBus = ((Button)sender).DataContext as PO.Bus;
            if (MyBus.Upstatus != BO.Status.DurringDrive && MyBus.Upstatus != BO.Status.InTreatment && MyBus.Upstatus != BO.Status.Refueling)
            {
                if (MyBus.simulation == null)
                {
                    MyBus.simulation = new SimulationOfBus(MyBus);
                }
                MyBus.simulation.Refuling();
                bl.UpdateBusDetails(MyBus);
                int i = listBuses.IndexOf(MyBus);
                listBuses.Remove(MyBus);
                listBuses.Insert(i, MyBus);
            }
            else
            {
                MessageBox.Show("The bus is busy :(", "wait!", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }