private void submitButton_Click(object sender, System.EventArgs e) { FuelEconomy milage = new FuelEconomy(); milage.milesPerGallon = Convert.ToDecimal(milageTextBox.Text); Weight weight = new Weight(); weight.kilograms = Convert.ToDecimal(weightTextBox.Text); Weight loadWeight = new Weight(); if (loadCheckBox.Checked) { loadWeight.kilograms = Convert.ToDecimal(loadWeightTextBox.Text); } Volume maxFuel = new Volume(); maxFuel.litres = Convert.ToDecimal(maxFuelTextBox.Text); LorryServices lorryServiceObj = new LorryServices(); lorryServiceObj.Add( vehicleNameTextBox.Text, numberPlateTextBox.Text, milage, weight, loadCheckBox.Checked, loadWeight, maxFuel, Convert.ToInt32(maxPassengersTextBox.Text) ); (Owner as LorryFormView).FillLorryList(); Close(); }
public void Add() { Console.WriteLine("Add lorry"); Console.Write("Name: "); string vehicleName = Console.ReadLine(); string numberPlateEntry, numberPlate = null; while (numberPlate == null) { Console.Write("Number plate: "); numberPlateEntry = Console.ReadLine().Replace(" ", ""); if (numberPlateEntry.Length != 7) { Console.WriteLine("Invalid numberplate length"); } else { numberPlate = numberPlateEntry; } } Console.Write("Milage (Miles/Gallon): "); FuelEconomy milage = new FuelEconomy(); milage.milesPerGallon = Convert.ToDecimal(Console.ReadLine()); Console.Write("Weight (kg): "); Weight weight = new Weight(); weight.kilograms = Convert.ToDecimal(Console.ReadLine()); bool hasLoad = false, validLoadInput = false; Weight loadWeight = new Weight(); while (!validLoadInput) { Console.Write("Has load (Y/N):"); switch (Console.ReadKey().KeyChar) { case 'y': hasLoad = true; validLoadInput = true; Console.Write("Load weight (kg): "); loadWeight.kilograms = Convert.ToDecimal(Console.ReadLine()); break; case 'n': hasLoad = false; validLoadInput = true; break; default: Console.WriteLine("\nInvalid input"); break; } } Console.Write("Maximum fuel (litres): "); Volume maximumFuel = new Volume(); maximumFuel.litres = Convert.ToDecimal(Console.ReadLine()); Console.Write("Maximum passengers: "); int maximumPassengers = Convert.ToInt32(Console.ReadLine()); Lorry addedLorry = lorryServicesObj.Add(vehicleName, numberPlate, milage, weight, hasLoad, loadWeight, maximumFuel, maximumPassengers); SelectById(addedLorry.Id); }