/// <summary> /// Bij het aanmaken van de lokale database wordt de eerder toegewezen auto opgehaald indien deze bestaat. /// </summary> public async Task HaalToegewezenAutoOp() { ASSIGNEDVEHICLE auto = new ASSIGNEDVEHICLE(); try { var toegewezen = await db.QueryAsync<ASSIGNEDVEHICLE>("SELECT * FROM DSS_ASSIGNEDVEHICLE"); auto = toegewezen.Any() ? toegewezen.First() : new ASSIGNEDVEHICLE { Id = 0, Number = String.Empty, Brand_Id = 0, Engine_Id = 0, Kilometerstand = String.Empty, Oliepeil = String.Empty, Transmission_Id = 0 }; } catch (SQLiteException) { paLogging.log.Critical("Bij het ophalen van de toegewezen wagen werd ontdekt dat de database niet correct ogpevuld werd."); return; } catch (Exception ex) { paLogging.log.Critical(String.Format("Kon de toegewezen wagen niet ophalen.\n{0}", ex.Message)); } completeAuto = new CompleteAuto(auto.Id, auto.Number); completeAuto.SetBrand(await GetMerk(auto.Brand_Id)); completeAuto.SetEngine(await GetMotor(auto.Engine_Id)); completeAuto.SetFuel(await GetBrandstof(completeAuto.Motor_Brandstof_Id)); completeAuto.SetTransmissie(await GetTransmissie(auto.Transmission_Id)); }
/// <summary> /// Vult de database met de gekozen toegewezen auto uit de autolijst op dmv een LINQ query en het nummer van de auto. /// </summary> /// <param name="number"></param> /// <returns>String resultaat</returns> public async Task<String> SetToegewezenAuto(string number) { try { await db.DropTableAsync<ASSIGNEDVEHICLE>(); //Tabel ASSIGNEDVEHICLE verwijderen await db.CreateTableAsync<ASSIGNEDVEHICLE>(); //Tabel ASSIGNEDVEHICLE aanmaken ASSIGNEDVEHICLE auto = (await GetAuto(number)).GetASSIGNEDVEHICLE(); completeAuto = new CompleteAuto(auto.Id, auto.Number); completeAuto.SetBrand(await GetMerk(auto.Brand_Id)); completeAuto.SetEngine(await GetMotor(auto.Engine_Id)); completeAuto.SetFuel(await GetBrandstof(completeAuto.Motor_Brandstof_Id)); completeAuto.SetTransmissie(await GetTransmissie(auto.Transmission_Id)); await db.InsertAsync(auto); return "Tablet is met succes toegewezen aan de auto"; } catch (Exception e) { paLogging.log.Error("Fout bij het ophalen van de voertuigen uit de database\nFoutmelding: " + e.Message); return "Er is iets fout gelopen. Probeer later opnieuw..."; } }
/// <summary> /// Haalt de toegewezen auto op. Dit is een complete instantie met alle gebundelde gegevens over /// de huidige toegewezen auto. Als deze niet bestaat wordt een leeg (niet null) object van de complete auto /// terug gegeven. /// </summary> /// <returns>Een CompleteAuto instantie</returns> public async Task<CompleteAuto> GetToegewezenAuto() { if (completeAuto == null) { var auto = await db.QueryAsync<ASSIGNEDVEHICLE>("SELECT * FROM DSS_ASSIGNEDVEHICLE"); if (auto.Count > 0) { completeAuto = new CompleteAuto(auto[0].Id, auto[0].Number, auto[0].Oliepeil); completeAuto.SetBrand(await GetMerk(auto[0].Brand_Id)); completeAuto.SetEngine(await GetMotor(auto[0].Engine_Id)); completeAuto.SetFuel(await GetBrandstof(completeAuto.Motor_Brandstof_Id)); completeAuto.SetTransmissie(await GetTransmissie(auto[0].Transmission_Id)); } } return completeAuto; }