public void BuyCar(Dispather disp) { Console.WriteLine("Enter Car"); string str = Console.ReadLine(); Vehicle value = null; for (int i = 0; i < affordable.Count; i++) { var CurrentVeh = affordable[i]; if (CurrentVeh.Name == str) { value = CurrentVeh; break; } } if (value != null) { value.Messenger += Go; value.Messenger += ShowSystem; value.Move(); affordable.Remove(value); WhereMyCar.tehnics.Remove(value); Sum = Sum - value.Price; disp.Cassa = disp.Cassa + value.Price; } }
public void SayToDispather(Dispather disp) { affordable.Clear(); WhereMyCar = disp.thehnics; foreach (var teh in WhereMyCar.tehnics) { if (teh.Price <= Sum) { affordable.Add(teh); } } ShowTeh(); }
//create collection client hardcor public static void CollectionClients(Dispather name) { Client cli = new Client("Mishael", "Saha", 22, Gender.man, 15000); Client cli1 = new Client("Furst", "Mistik", 18, Gender.woman, 200); Client cli2 = new Client("Chelyadko", "Alexey", 27, Gender.man, 7000); Client cli3 = (Client)cli1.Clone(); cli3.Age = 22; cli3.FirstName = "Nivarov"; cli3.Gender = (int)Gender.man; name.AddClient(cli); name.AddClient(cli1); name.AddClient(cli2); name.AddClient(cli3); }
public static Client AddMyClient(Dispather disp, string firstname, string lastname) { int Age; int Summ; Console.WriteLine("Enter Age"); int.TryParse(Console.ReadLine(), out Age); Console.WriteLine("Gender"); Gender gender; Enum.TryParse(Console.ReadLine(), out gender); Console.WriteLine("Enter Summ"); int.TryParse(Console.ReadLine(), out Summ); Client client = new Client(firstname, lastname, Age, gender, Summ); disp.AddClient(client); Console.WriteLine($"Hello {lastname},{firstname}"); return(client); }
static void Main(string[] args) { //method communicated with delegate void TestDrive(string text) { Console.WriteLine("I'll start the engine"); Console.WriteLine("The movement is over"); } //create dispether Dispather ivanov = new Dispather("Ivanov", "Sergey", 29, Gender.man, 5); CollectionClients(ivanov); //create collection car Program my = new Program(); var list = my.CollectionVehicle(); while (true) { ivanov.thehnics = list; //create delegate menu MyDelegate1 Menu = new MyDelegate1(my.ShowMenu); //delegate invocation Menu?.Invoke(); //menu selection Operation op; Enum.TryParse(Console.ReadLine(), out op); switch (op) { //Become A Client case Operation.BecomeAClient: { var fulname = AddNameClient(); AddMyClient(ivanov, fulname.Item1, fulname.Item2); } break; //Show All Vehicle case Operation.ShowAllVehicle: { list.Show(); } break; //Sort By Price case Operation.SortByPrice: { list.tehnics.Sort(); list.Show(); } break; //Buy Car case Operation.BuyTechniks: { var fulname = AddNameClient(); Client CurrentUser = null; foreach (var item in ivanov.client) { if (item.FirstName == fulname.Item1 && item.LastName == fulname.Item2) { CurrentUser = item; } break; } if (CurrentUser != null) { CurrentUser.SayToDispather(ivanov); CurrentUser.BuyCar(ivanov); } else { Client client = AddMyClient(ivanov, fulname.Item1, fulname.Item2); client.SayToDispather(ivanov); client.BuyCar(ivanov); } } break; //Show Clients case Operation.ShowClients: { ivanov.Showweed += Disp; ivanov.ShowClients(); } break; //Add Car case Operation.AddTehnics: { list.Show(); Car mycar = AddMyCar(); list.Addtehnics(mycar); Console.WriteLine($"Add car {mycar.Name}"); list.Show(); } break; //Delete Car MyCollection case Operation.DeleteTehnics: { list.Show(); Console.WriteLine("Enter name Car"); string str = Console.ReadLine(); Vehicle CurentCount = null; foreach (var item in list.tehnics) { if (item.Name == str) { CurentCount = item; } } list.tehnics.Remove(CurentCount); list.Show(); } break; //Take a car for a test drive case Operation.TetsDrive: { list.Show(); Console.WriteLine("select a car"); string str = Console.ReadLine(); foreach (var item in list.tehnics) { if (item.Name == str) { Console.WriteLine(item.ToString()); Car myCar = new Car(); myCar = item as Car; myCar.Drive += TestDrive; systemPoolLog = new EventLog(); myCar.Drive += ShowSystem; myCar.Start(); } } } break; default: break; } Console.WriteLine(); } }