Exemplo n.º 1
0
        public void Start()
        {
            PeopleManager manager = new PeopleManager();
            var           loop    = true;

            while (loop)
            {
                Console.Clear();
                UI.PrintMainMenu();
                var choice = Console.ReadKey(true).Key;

                switch (choice)
                {
                case ConsoleKey.D1:
                    manager.AddPerson();
                    break;

                case ConsoleKey.D2:
                    manager.PrintAll();
                    break;

                case ConsoleKey.D3:
                    var filter = GetFilter();
                    Console.Clear();
                    manager.PrintWhere(filter);
                    Console.ReadKey(true);
                    break;

                default:
                    InvalidInput.Invoke();
                    Console.ReadKey(true);
                    break;
                }
            }
        }
 public override void OnClick(IDialogInterface dialog, int which)
 {
     switch ((DialogButtonType)which)
     {
     case DialogButtonType.Positive:
         if (!int.TryParse(EditText.Text, out int result))
         {
             InvalidInput?.Invoke(this, new InvalidInputEventArgs("Please enter a valid number"));
             EditText.ClearFocus();
         }
         else if (result < MinValue)
         {
             InvalidInput?.Invoke(this, new InvalidInputEventArgs("Value must be at least " + MinValue));
             EditText.ClearFocus();
         }
         else if (result > MaxValue)
         {
             InvalidInput?.Invoke(this, new InvalidInputEventArgs("Value must be at most " + MaxValue));
             EditText.ClearFocus();
         }
         else
         {
             base.OnClick(dialog, which);
         }
         break;
     }
 }
Exemplo n.º 3
0
        public void AddMc()
        {
            bool loop = true;

            Console.Clear();
            Motorcycle motorcycle = new Motorcycle();

            Console.WriteLine("Enter the info for the MC");
            Console.Write("Manufacturer: ");
            motorcycle.Manufacturer = Console.ReadLine();
            Console.Write("Model: ");
            motorcycle.Model = Console.ReadLine();
            Console.Write("Type: ");
            motorcycle.Type = Console.ReadLine();
            while (loop)
            {
                Console.Write("Year: ");

                InvalidInput += CheckYear;
                int  input;
                bool isValid = int.TryParse(Console.ReadLine(), out input);

                if (input < 1970)
                {
                    InvalidInput.Invoke("Choose a year between 1970-2017");
                }
                else if (input > 2017)
                {
                    InvalidInput.Invoke("Choose a year between 1970-2017");
                }
                else
                {
                    motorcycle.Year = input;
                    McList.Add(motorcycle);
                    loop = false;
                }
            }
        }