示例#1
0
        static void Main(string[] args)
        {
            TimeOfCame t1 = new TimeOfCame { TimeCame = DateTime.Parse("6:00") };
            TimeOfCame t2 = new TimeOfCame { TimeCame = DateTime.Parse("9:00") };
            TimeOfCame t3 = new TimeOfCame { TimeCame = DateTime.Parse("12:00") };
            TimeOfCame t4 = new TimeOfCame { TimeCame = DateTime.Parse("19:00") };

            Person john = new Person { Name = "Egor", TimeCame = t1 };
            Person bill = new Person { Name = "Albina", TimeCame = t2 };
            Person hugo = new Person { Name = "Kirill", TimeCame = t3 };
            Person ivan = new Person { Name = "Bulat", TimeCame = t4 };

            john.Came += Handler1;
            john.MyMethod1();
            bill.Came += Handler1;
            bill.MyMethod1();
            hugo.Came += Handler1;
            hugo.MyMethod1();

            bill.Leave += Handler2;
            bill.MyMethod2();
            ivan.Came += Handler1;
            ivan.MyMethod1();
            hugo.Leave += Handler2;
            hugo.MyMethod2();
            ivan.Leave += Handler2;
            ivan.MyMethod2();
            john.Leave += Handler2;
            john.MyMethod2();

            Console.ReadKey();
        }
示例#2
0
 public virtual void OnCame(Person p, TimeOfCame t)
 {
     if (p.Came != null)
     {
         p.Came(p, t);
     }
 }
示例#3
0
 public virtual void OnLeave(Person p)
 {
     if (p.Leave != null)
     {
         p.Leave(p);
     }
 }
示例#4
0
        static void Main(string[] args)
        {
            Office Office1 = new Office();

            Person john = new Person { Name = "John"};
            Person bill = new Person { Name = "Bill"};
            Person hugo = new Person { Name = "Hugo"};
            Person ivan = new Person { Name = "Ivan"};

            TimeOfCame t1 = new TimeOfCame { TimeCame = DateTime.Parse("7:00") };
            TimeOfCame t2 = new TimeOfCame { TimeCame = DateTime.Parse("11:00") };
            TimeOfCame t3 = new TimeOfCame { TimeCame = DateTime.Parse("14:00") };
            TimeOfCame t4 = new TimeOfCame { TimeCame = DateTime.Parse("22:00") };

            Office1.ComePerson(john, t1);

            Office1.ComePerson(bill, t2);

            Office1.ComePerson(hugo, t3);

            Office1.LeavePerson(bill);

            Office1.ComePerson(ivan,t4);

            Office1.LeavePerson(hugo);

            Office1.LeavePerson(ivan);

            Office1.LeavePerson(john);

            Console.ReadKey();
        }
示例#5
0
 static void LeaveHandler(Person p)
 {
     if (Part != null)
     {
         Part(p);
     }
 }
示例#6
0
 static void CameHandler(Person p, TimeOfCame t)
 {
     if (Greet != null)
     {
         Greet(p, t);
     }
 }
示例#7
0
 static void Handler2(Person p)
 {
     if (Part != null)
     {
         Console.WriteLine("[{0} ушел домой]\n", p.Name);
         Part(p);
     }
     else
     {
         Console.WriteLine("[{0} ушел домой]\n", p.Name);
     }
 }
示例#8
0
 static void Handler1(Person p, TimeOfCame t)
 {
     if (Greet != null)
     {
         Console.WriteLine("[{0} пришел на работу]\n", p.Name);
         Greet(p, p.TimeCame);
     }
     else
     {
         Console.WriteLine("[{0} пришел на работу]\n", p.Name);
     }
 }
示例#9
0
 public void Greeting(Person anotherPerson, TimeOfCame t)
 {
     if (t.TimeCame.Hour < 12)
     {
         Console.WriteLine("Доброе утро, {0}! - сказал {1}", anotherPerson.Name, Name);
     }
     else if (t.TimeCame.Hour > 17)
     {
         Console.WriteLine("Добрый вечер, {0}! - сказал {1}", anotherPerson.Name, Name);
     }
     else
     {
         Console.WriteLine("Добрый день, {0}! - сказал {1}", anotherPerson.Name, Name);
     }
 }
示例#10
0
 public void Greeting(Person anotherPerson, TimeOfCame t)
 {
     if (t.TimeCame.Hour < 12)
     {
         Console.WriteLine("Good morning, {0}! - said {1}", anotherPerson.Name, Name);
     }
     else if (t.TimeCame.Hour > 17)
     {
         Console.WriteLine("Good evening, {0}! - said {1}", anotherPerson.Name, Name);
     }
     else
     {
         Console.WriteLine("Good afternoon, {0}! - said {1}", anotherPerson.Name, Name);
     }
 }
示例#11
0
 public void LeavePerson(Person p)
 {
     Console.WriteLine("[{0} gone to home]\n", p.Name);
     ListPerson.Remove(p);
     foreach (var elem in ListPerson)
     {
         MessageLeave part = new MessageLeave(elem.Parting);
         Part += part;
     }
     p.Leave += LeaveHandler;
     p.OnLeave(p);
     foreach (var elem in ListPerson)
     {
         MessageLeave part = new MessageLeave(elem.Parting);
         Part -= part;
     }
 }
示例#12
0
        public void ComePerson(Person p, TimeOfCame TimeCame)
        {
            Console.WriteLine("[{0} came to work]\n", p.Name);

            foreach (var elem in ListPerson)
            {
                MessageCome greet = new MessageCome(elem.Greeting);
                Greet += greet;
            }

            p.Came += CameHandler;
            p.OnCame(p, TimeCame);

            foreach (var elem in ListPerson)
            {
                MessageCome greet = new MessageCome(elem.Greeting);
                Greet -= greet;
            }

            ListPerson.Add(p);
        }
示例#13
0
 public void Parting(Person anotherPerson)
 {
     Console.WriteLine("Досвидания, {0}! - сказал {1}", anotherPerson.Name, Name);
 }
示例#14
0
 public void LeaveHandler(Person p)
 {
     MessageLeave part = new MessageLeave(this.Parting);
     part(p);
 }
示例#15
0
 public void CameHandler(Person p, TimeOfCame t)
 {
     MessageCome greet = new MessageCome(this.Greeting);
     greet(p, t);
 }
示例#16
0
 public void Parting(Person anotherPerson)
 {
     Console.WriteLine("Good bye, {0}! - said {1}", anotherPerson.Name, Name);
 }