Esempio n. 1
0
        }//deleteService

        //Utility method to get user input and update attributes of a service
        private void updateService(UserInterface ui, Service aService
                                   , bool retainOldValue)
        {
            try
            {
                String input;

                //Get value for code if it has not already been set
                if (aService.getCode() == null)  //code may not be changed
                {
                    input = ui.promptForString("Code: ");
                    aService.setCode(input);
                }

                //get value for name
                input = ui.promptForString("Name: ");
                if (input.Length == 0 && retainOldValue)
                {
                    aService.setName(aService.getName());    //ensure valid name
                }
                else
                {
                    aService.setName(input);
                }

                //get value for fee
                double fee;
                if (retainOldValue)
                {
                    fee = ui.promptForDouble("Fee: ", aService.getFee());
                }
                else
                {
                    fee = ui.promptForDouble("Fee: ");
                }
                aService.setFee(fee);
            }
            catch (ArgumentException ex)
            {
                ui.errorMessage(ex.Message);
                ui.message("Current details:");
                ui.message(aService.toFormattedString());
                ui.message("\nPlease repeat input.  "
                           + "Press Enter for details that are correct.");
                updateService(ui, aService, true);    //Give the user another chance
            }
        }//updateService