//Обработка прихода и ухода сотрудника private void Employee_State(EmployeeEvent sender, Person person, TimeStateEventArgs time) { MessageGreet GreetByPerson = new MessageGreet(person.Greet); MessageBye ByeByPerson = new MessageBye(person.Bye); if (sender == employeeEvent) { if (employeeEvent.State == true) { Console.WriteLine("[{0} came to office]", person.Name); if (GreetByUs != null & GreetByUs != GreetByPerson) { GreetByUs(person, time); } GreetByUs += GreetByPerson; ByeByUs += ByeByPerson; } if (employeeEvent.State == false) { Console.WriteLine("[{0} leave from office]", person.Name); ByeByUs -= ByeByPerson; if (ByeByUs != null & ByeByUs != ByeByPerson) { ByeByUs(person); } } } }
public Office() { GreetByUs = null; ByeByUs = null; timeEvent = new TimeOfDayEvent(); employeeEvent = new EmployeeEvent(); timeEvent.TimeEvent += Time_State; employeeEvent.Employee += Employee_State; }
////public static void GoWork (String name) //public void GoWork(String name) //{ //} public static void PersonCame(Person person, DateTime date) { if (person != null) { Console.WriteLine("{0} has come", person.Name); if (greetByUs != null) { greetByUs(person.Name, date); } greetByUs += new Message(person.Greet); sayGoodbyeByUs += person.SayGoodbye; } }
static void PersonLeft(object sender, EventArgs e) { var person = sender as Person; if (person != null) { greetByUs -= person.Greet; sayGoodbyeByUs -= person.SayGoodbye; Console.WriteLine("{0} has left", person.Name); if (sayGoodbyeByUs != null) { sayGoodbyeByUs(person.Name); } } }
public void AddWorker(Person person, int hour) { workers.Add(person); person.Came += new EventHandler(Person_Came); person.OnCame(); if (greetByUs != null) { greetByUs(person, hour); } MessageHello greetByPerson = new MessageHello(person.Greet); greetByUs += greetByPerson; MessageBye byeByPerson = new MessageBye(person.GoodBye); byeByUs += byeByPerson; }
public void RemoveWorker(Person person) { MessageHello greetByPerson = new MessageHello(person.Greet); greetByUs -= greetByPerson; person.Came -= new EventHandler(Person_Came); workers.Remove(person); person.Gone += new EventHandler(Person_Gone); person.IsGone(); MessageBye byeByPerson = new MessageBye(person.GoodBye); byeByUs -= byeByPerson; if (byeByUs != null) { byeByUs(person); } person.Gone -= new EventHandler(Person_Gone); }