static void ImportVehicles() { Util.PrintClear(); //if (GarageHandler.GarageMissing()) //{ // Util.MsgBox("Message", "Garage is missing"); // return; //} //if (GarageHandler.GarageIsFull()) //{ // Util.MsgBox("Message", "Garage is full"); // return; //} var cnt = 0; string errLst = ""; var vehicles = GarageHandler.Import(); foreach (var v in vehicles) { //ToDo extra arg Func<string,string> Util.Input if (GarageHandler.AddVehicle(v, out var err)) { cnt++; } else { errLst += "\n" + err; } } Util.MsgBox("Import", string.Format($"Succesfully imported {cnt} (of {vehicles.Count}) vehicles. {errLst}")); }
static void CreateTestVehicles() { Util.PrintClear(); //if (GarageHandler.GarageMissing()) //{ // Util.MsgBox("Message", "Garage is missing"); // return; //} //if (GarageHandler.GarageIsFull()) //{ // Util.MsgBox("Message", "Garage is full"); // return; //} var cnt = 0; string errLst = ""; var vehicles = VehicleHandler.GetTestVehicles(); foreach (var v in vehicles) { if (GarageHandler.AddVehicle(v, out var err)) { cnt++; } else { errLst += "\n" + err; } } Util.MsgBox("Create test vehicles", string.Format($"Succesfully created {cnt} (of {vehicles.Length}) vehicles. {errLst}")); }
//if (GarageHandler.GarageMissing()) //{ // Util.MsgBox("Message", "Garage is missing"); // return; //} static void AddVehicle() { Util.PrintClear(); //if (GarageHandler.GarageMissing()) //{ // Util.MsgBox("Message", "Garage is missing"); // return; //} //if (GarageHandler.GarageIsFull()) //{ // Util.MsgBox("Message", "Garage is full"); // return; //} string errMsg = ""; var type = Util.Input("1. Airplane (ai)\n2. Motorcycle (mo)\n3. Car (ca)\n4. Bus (bu)\n5. Boat (bo)\n\nPlease specify type of Vehicle: "); Vehicle vehicle = (Vehicle)VehicleHandler.BuildVehicle(type, out errMsg); string str; if (errMsg == "" && GarageHandler.AddVehicle(vehicle, out errMsg)) { str = string.Format($"Adding vehicle was succesfull"); } else { str = string.Format($"Sorry, adding of vehicle faild. {errMsg}"); } Util.MsgBox("Add Vehicle", str); }
static void ExportVehicles() { //if (GarageHandler.GarageMissing()) //{ // Util.MsgBox("Message", "Garage is missing"); // return; //} GarageHandler.Export(); Util.MsgBox("Message", "Vehicles in garage exported"); }
private static void FindVehicleByRegNr() { Util.PrintClear(); //if (GarageHandler.GarageMissing()) //{ // Util.MsgBox("Message", "Garage is missing"); // return; //} var regNr = Util.Input("Specify reg.nr of Vehicle: "); Util.MsgBox("Find vehicle by regNr", string.Format($"{GarageHandler.ListVehicle(regNr)}")); }
static void CreateGarage() { Util.PrintClear(); var cap = Util.ConvInt(Util.Input( (GarageHandler.GarageMissing() ? "" : "Warning, a positive value will delete existing garage!\n") + "Please specify capacity of new garage: ")); if (cap >= 0) { GarageHandler.SetUpGarage(cap); Util.MsgBox("New garage", string.Format($"{GarageHandler.ListGarageCapacity()}")); } else { Util.MsgBox("Warning", "No new garage was not created because you enter a negative capacity"); } }
private static void RemoveVehicle() { Util.PrintClear(); //if (GarageHandler.GarageMissing()) //{ // Util.MsgBox("Message", "Garage is missing"); // return; //} var regNr = Util.Input("Please specify reg.nr of Vehicle: "); string str; if (GarageHandler.RemoveVehicle(regNr)) { str = string.Format($"Removal of vehicle with Reg.nr:{regNr} was succesfull"); } else { str = string.Format($"Sorry, removal of vehicle with Reg.nr:{regNr} faild"); } Util.MsgBox("Vehicle removal", str); }
private static void FindVehicle() //=> Util.MsgBox("Find vehicle", "Not implemented"); { Util.PrintClear(); //if (GarageHandler.GarageMissing()) //{ // Util.MsgBox("Message", "Garage is missing"); // return; //} var search = Util.Input("Enter all values to match( \"4,Red\" or \"NoWheels=4;Color=Red\" )\nPlease specify search string: "); Util.MsgBox("Find vehicles by search string (" + search + ")", string.Format($"{GarageHandler.ListVehicleG(search)}")); }
static void PrintGarage() => Util.MsgBox("Garage inv", GarageHandler.ListVehicles());
private static void PrintGarageStat() => Util.MsgBox("Garage stat", GarageHandler.StatsVehiclesInGarage() + GarageHandler.ListGarageCapacity());
internal static IVehicle BuildVehicle(string type, out string txtErr) //,string regNr { txtErr = ""; Vehicle vehicle = null; switch (type.ToLower()) { case "airplane": case "ai": case "1": vehicle = new Airplane(); break; case "motorcycle": case "mo": case "2": vehicle = new Motorcycle(); break; case "car": case "ca": case "3": vehicle = new Car(); break; case "bus": case "bu": case "4": vehicle = new Bus(); break; case "boat": case "bo": case "5": vehicle = new Boat(); break; default: break; } if (vehicle != null) { foreach (var p in vehicle.GetVehicleProperties()) { var nameP = (string)p?.GetType().GetProperty("NameP")?.GetValue(p, null); if (nameP == "Type") { continue; } var typeP = (string)p?.GetType().GetProperty("TypeP")?.GetValue(p, null); var label = string.Format($"{nameP}: "); Util.PrintL(); //ToDo Func<> arg string strValue = Util.Input(label); //ToDo Func<> arg if (nameP == "RegNr") //ToDo; unique { if (GarageHandler.ListVehicles(strValue).Length > 0) { txtErr = "Vehicle already exists."; return(null); } } var obj = vehicle; PropertyInfo prop = obj.GetType().GetProperty(nameP, BindingFlags.Public | BindingFlags.Instance); if (null != prop && prop.CanWrite) //ToDo check prop.GetCustomAttribute for DisplayName { if (typeP == "Int32") { prop.SetValue(obj, Util.ConvInt(strValue), null); } if (typeP == "String") { prop.SetValue(obj, strValue, null); } if (typeP == "Single") { prop.SetValue(obj, Util.ConvFloat(strValue), null); } if (typeP == "Boolean") { prop.SetValue(obj, (strValue == "true" || strValue == "1"), null); } } } } return(vehicle); }