/// <summary> /// this function happend when thread done is runing /// the function clean the progress bar, update the bus to be ready and all the implicit as a result of that. /// </summary> private void Worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { state = BusState.Ready; mainW.UpdatePB(_licNum, 0); mainW.UpdateTime(_licNum); mainW.UpdateColor(this); if (busDat != null) { busDat.UpdateInfo(); BusDat.updateColor(); } }
/// <summary> /// This function refuels the bus and lowers it's KmFromfuel to 0. /// </summary> public void ReFual() { worker = new BackgroundWorker(); worker.WorkerReportsProgress = true; worker.DoWork += Worker_DoWork; worker.ProgressChanged += Worker_ProgressChanged; worker.RunWorkerCompleted += Worker_RunWorkerCompleted; worker.RunWorkerAsync(12); state = BusState.Refueling; _kmFromFuel = 0; mainW.UpdateColor(this); if (BusDat != null) { BusDat.updateColor(); } UpdateEarns(-500); }
/// <summary> /// this function make a thread for make the operetion of driving of bus /// </summary> /// <param name="Length">the length of the drive</param> /// <param name="passengers">the number of passengers in the current drive </param> public void Drive(int Length, int passengers) { worker = new BackgroundWorker(); worker.WorkerReportsProgress = true; worker.DoWork += Worker_DoWork; worker.ProgressChanged += Worker_ProgressChanged; worker.RunWorkerCompleted += Worker_RunWorkerCompleted; worker.RunWorkerAsync(Length); state = BusState.Driving; mainW.UpdateColor(this); if (BusDat != null) { BusDat.updateColor(); } UpdateEarns(passengers * 20 - Length); totalPass += passengers; drives++; }
/// <summary> /// This function treatments the bus and lowers it's KmFromtreat to 0. /// </summary> public void Treatment() { worker = new BackgroundWorker(); worker.WorkerReportsProgress = true; worker.DoWork += Worker_DoWork; worker.ProgressChanged += Worker_ProgressChanged; worker.RunWorkerCompleted += Worker_RunWorkerCompleted; worker.RunWorkerAsync(144); state = BusState.Treatment; _kmFromtreat = 0; _kmFromFuel = 0;//that how we undrstood the assignment - when make treatment make refuel too. _lastTreat = DateTime.Now; mainW.UpdateColor(this); if (BusDat != null) { BusDat.updateColor(); } UpdateEarns(-2000); }