public bool AddCar(Car car) { if (car != null) { OwnedCars.Add(car); return true; } return false; }
private void UpdateFromTextDatabase() { List<string> listCars = new List<string>(); List<string> listBankAccounts = new List<string>(); List<string> listOwners = new List<string>(); getTextFromFile(listCars, "carsdatabase.txt"); getTextFromFile(listBankAccounts, "bankaccountdatabase.txt"); getTextFromFile(listOwners, "ownerdatabase.txt"); foreach(string ownerString in listOwners) { string[] dataOwner = ownerString.Split(','); Bankaccount ownerBankAccount = getBankaccount(listBankAccounts, dataOwner[1]); if (ownerBankAccount != null) { Owners.Add(new Owner(dataOwner[0], ownerBankAccount, dataOwner[2])); } else { newAccountNumber++; newAuthenticationNumber++; if (newAccountNumber > 9999) { newAuthenticationNumber = 1; } string newAccountNumberString = newAccountNumber.ToString(); string newAuthenticationNumberString = newAuthenticationNumber.ToString(); while (newAuthenticationNumberString.Length < 3) { newAuthenticationNumberString = "0" + newAuthenticationNumberString; } Bankaccount bankaccount = new Bankaccount(newAccountNumberString, newAuthenticationNumberString, 0); Owners.Add(new Owner(dataOwner[0], bankaccount, dataOwner[2])); } } foreach (string carString in listCars) { string[] data = carString.Split(','); TypeOfFuel fueltype = TypeOfFuel.Unknown; switch (data[1]) { case "Petrol": fueltype = TypeOfFuel.Petrol; break; case "Diesel": fueltype = TypeOfFuel.Diesel; break; case "LPG": fueltype = TypeOfFuel.LPG; break; } foreach (Owner owner in Owners) { if (owner.Name == data[4]) { Car car = new Car(data[0], fueltype, data[2], Convert.ToDouble(data[3]), owner); AllCars.Add(car); owner.OwnedCars.Add(car); break; } } } }