Ejemplo n.º 1
0
    /*
     * creating a pet, creating a clinic, adding a pet to a clinic,
     * releasing a pet from a clinic, printing information about a specific
     * room in a clinic or printing information about all rooms in a clinic.
     */

    public void Interpret()
    {
        List <string> cmdArgs = Console.ReadLine()
                                .Split(' ')
                                .ToList();

        string command = cmdArgs[0];

        cmdArgs.RemoveAt(0);

        switch (command)
        {
        case "Create":
            if (cmdArgs[0] == "Pet")
            {
                cmdArgs.RemoveAt(0);
                Pet.CreatePet(cmdArgs);
            }
            else if (cmdArgs[0] == "Clinic")
            {
                cmdArgs.RemoveAt(0);
                Clinic.CreateClinic(cmdArgs);
            }
            break;

        case "Add":
            string addResult = Clinic.AddPetToClinic(cmdArgs[0], cmdArgs[1]).ToString();
            Console.WriteLine(addResult.ToLower());
            break;

        case "Release":
            string result = Clinic.ReleasePetFromClinic(cmdArgs[0]).ToString();
            Console.WriteLine(result.ToLower());
            break;

        case "HasEmptyRooms":
            string resultFrom = Clinic.HasEmptyRooms(cmdArgs[0]).ToString();
            Console.WriteLine(resultFrom.ToLower());
            break;

        case "Print":
            if (cmdArgs.Count == 1)
            {
                Clinic.PrintEveryRoomInClinic(cmdArgs[0]);
            }
            else
            {
                Clinic.PrintClinicRoom(cmdArgs[0], int.Parse(cmdArgs[1]));
            }
            break;

        default:
            Console.WriteLine("No such a command!");
            return;
        }
    }
        private void ParseCommand(string[] command)
        {
            var firstCommand  = command[0];
            var secondCommand = command[1];

            switch (firstCommand)
            {
            case "Create":
                var name   = command[2];
                var number = int.Parse(command[3]);
                if (secondCommand == "Pet")
                {
                    this.pets[name] = new Pet(name, number, command[4]);
                }
                else
                {
                    var clinic = new Clinic(name, number);
                    clinic.CreateClinic();
                    this.clinics[name] = clinic;
                }
                break;

            case "Add":
                name = command[2];
                Console.WriteLine(this.clinics[name].Add(this.pets[secondCommand]));
                break;

            case "Release":
                Console.WriteLine(this.clinics[secondCommand].Release());
                break;

            case "HasEmptyRooms":
                Console.WriteLine(this.clinics[secondCommand].HasEmptyRooms());
                break;

            case "Print":
                if (command.Length == 2)
                {
                    this.clinics[secondCommand].Print();
                }
                else
                {
                    this.clinics[secondCommand].PrintRoom(int.Parse(command[2]) - 1);
                }
                break;
            }
        }
Ejemplo n.º 3
0
 public void SaveExecute()
 {
     if (String.IsNullOrEmpty(Clinic.Name) || String.IsNullOrEmpty(Clinic.DateOfConstruction.ToString()) || String.IsNullOrEmpty(Clinic.Owner) || String.IsNullOrEmpty(Clinic.Address) ||
         String.IsNullOrEmpty(Clinic.NumberOfFloors.ToString()) || String.IsNullOrEmpty(Clinic.NumberOfRoomsPerFloor.ToString()) || String.IsNullOrEmpty(Clinic.Terrace.ToString()) ||
         String.IsNullOrEmpty(Clinic.Yard.ToString()) || String.IsNullOrEmpty(Clinic.NumberOfAccessPointsForAmbulanceCars.ToString()) || String.IsNullOrEmpty(Clinic.NumberOfAccessPointsForInvalids.ToString()) ||
         Clinic.NumberOfRoomsPerFloor == 0)
     {
         MessageBox.Show("Please fill all fields.", "Notification");
     }
     else
     {
         try
         {
             MessageBoxResult result = MessageBox.Show("Are you sure you want to save the clinic?", "Confirmation", MessageBoxButton.YesNo, MessageBoxImage.Question);
             if (result == MessageBoxResult.Yes)
             {
                 bool isCreated = newClinic.CreateClinic(Clinic);
                 if (isCreated)
                 {
                     MessageBox.Show("Clinic is created.", "Notification", MessageBoxButton.OK);
                     clinicView.Close();
                     AdministratorView adminView = new AdministratorView();
                     adminView.ShowDialog();
                 }
                 else
                 {
                     MessageBox.Show("Clinic cannot be created.", "Notification", MessageBoxButton.OK);
                     clinicView.Close();
                 }
             }
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.ToString());
         }
     }
 }