Пример #1
0
        private void printNewVehicleDialog()
        {
            object newVehicle = new object();

            try
            {
                string registrationNumber = string.Empty;
                string userName           = string.Empty;
                string userPhoneNumber    = string.Empty;
                string model             = string.Empty;
                string vehicleType       = string.Empty;
                string wheelsManufacture = string.Empty;
                int    wheelsAirPressure = 0;
                bool   isElectric        = false;

                registrationNumber = getRegistrationNumber();
                Console.Clear();
                m_Garage.AddVehicleInfo("i_RegistrationNumber", registrationNumber);

                userName = getUserName();
                Console.Clear();
                m_Garage.AddVehicleInfo("i_OwnerName", userName);

                userPhoneNumber = getUserPhoneNumber();
                Console.Clear();
                m_Garage.AddVehicleInfo("i_OwnerPhoneNumber", userPhoneNumber);

                vehicleType = getVehicleType();
                Console.Clear();
                m_Garage.AddVehicleInfo("Vehicle Type", vehicleType);

                model = getVehicleModel();
                Console.Clear();
                m_Garage.AddVehicleInfo("i_Model", model);

                isElectric = askIfElectricVehicle();
                m_Garage.AddVehicleInfo("i_IsEnergySource", isElectric);
                Console.Clear();

                Vehicle vehicle = m_Garage.EnterNewVehicle();
                newVehicle = vehicle;

                wheelsManufacture = getWheelsManufacture();
                Console.Clear();
                m_Garage.AddVehicleInfo("i_WheelsManufacture", wheelsManufacture);

                wheelsAirPressure = getWheelsAirPressure(ref vehicle);
                Console.Clear();
                m_Garage.AddVehicleInfo("i_WheelsCurrentAirPressure", wheelsAirPressure);

                printSpecificVehicleDialog(ref vehicle);
                m_Garage.UpdateVehicleData(ref vehicle);
            }
            catch (ValueOutOfRangeException i_ValueOutOfRangeException)
            {
                Console.WriteLine(i_ValueOutOfRangeException.Message);
                m_Garage.RemoveVehicle(ref newVehicle);
            }
            catch (ArgumentException i_ArgumentException)
            {
                switch (i_ArgumentException.Message)
                {
                case "Registration_Number_Exists":
                    Console.WriteLine("Error: Vehicle is already in the garage. Changing vehicle status to 'In Repair'.");
                    break;

                case "User choice":
                    Console.WriteLine("Error: Your option selection does not exists.");
                    break;

                default:
                    Console.WriteLine(i_ArgumentException.Message);
                    break;
                }
            }
            catch (FormatException)
            {
                Console.WriteLine("Error: Input format does not match the format type required.{0}", Environment.NewLine);
            }
            catch (Exception i_Ex)
            {
                if (i_Ex.Message == "Invalid data input")
                {
                    Console.WriteLine("Error: {0}.{1}", i_Ex.Message, Environment.NewLine);
                }
                else
                {
                    Console.WriteLine(i_Ex.Message);
                }
            }
            finally
            {
                m_Garage.ClearVehicleInfo();
            }
        }