void Stend_FinishedWork(object sender, StendState stendState) { foreach (Stand stend in this.stends) { if (stend.StendState != StendState.NotWork) { return; } } this.managerState = ManagerState.NotWork; foreach (Stand stend in this.stends) { profit += stend.ProductPrice * stend.CountOfSelledProduct; Console.WriteLine("Стенд {0} продал {1} товаров по цене {2} и прибыль со стенда составляет {3}", stend.ProductName, stend.CountOfSelledProduct, stend.ProductPrice, stend.ProductPrice * stend.CountOfSelledProduct); } Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Все стенды прошло {0} человек", this.countOfBuyersFromAllStends.Count); foreach (Buyer b in this.countOfBuyersFromAllStends) { Console.WriteLine("Покупатель с id={0}", b.ID); } Console.WriteLine("Общая прибыль составляет ${0}", this.profit); Console.ForegroundColor = ConsoleColor.White; if (this.FinishedWork != null) { this.FinishedWork(this, ManagerState.NotWork); } }
public void EndToWork() { this.StendState = FoodMarket.StendState.Finishing; }
public void StartToWork() { this.StendState = StendState.Work; lock (colorLocked) { Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("Стенд {0} начал работу", this.ProductName); Console.ForegroundColor = ConsoleColor.White; } foreach (Thread thread in this.sellersTread) { thread.Start(); } while (true) { Thread.Sleep(1000); lock (colorLocked) { Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("На стенде {0} очередь в {1} человек. Рентабельность стенда: {2}", this.ProductName, this.Buyers.Count, this.Profylability); Console.ForegroundColor = ConsoleColor.White; } if (this.buyers.Count != 0) { foreach (Seller seller in this.sellers) { if (true == seller.IsFree) { if (this.buyers.Count == 0) { break; } lock (colorLocked) { Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("Стенд {0} отдал продавцу покупателя с id={1}", this.ProductName, this.buyers.Peek().ID); Console.ForegroundColor = ConsoleColor.White; seller.PassBuyer(this.buyers.Dequeue()); } if (this.buyers.Count != 0) { this.Profylability = this.ProductPrice * this.sellers.Count / this.Buyers.Count; } else { this.Profylability = this.ProductPrice * this.sellers.Count / 1; } } } continue; } if (this.StendState == StendState.Work) { lock (colorLocked) { Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("Стенд {0} пустует, но работает", this.ProductName); Console.ForegroundColor = ConsoleColor.White; } continue; } if (true == this.IsAllSellersFree()) { foreach (Seller seller in this.sellers) { seller.NoMoreBuyers(); } this.StendState = FoodMarket.StendState.NotWork; if (this.FinishedWork != null) { this.FinishedWork(this, StendState.NotWork); } break; } } }