feat: GUID

This commit is contained in:
2026-03-02 14:23:15 +01:00
parent f6b70fa387
commit 48be020dc4
7 changed files with 158 additions and 44 deletions

View File

@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
namespace CarManagerV3
{
@@ -17,6 +18,10 @@ namespace CarManagerV3
// TODO: If no recent file paths are found, prompt user to select a file path instead of using a hardcoded default in the program folder.
static string filePath = "cars.csv";
static bool hasConfirmedMigration = false;
/// <summary>
/// Gets a car by its identifier.
/// </summary>
@@ -24,7 +29,7 @@ namespace CarManagerV3
/// <returns>
/// A <see cref="Car"/> object if found; otherwise, null.
/// </returns>
public static Car GetCarById(int id)
public static Car GetCarById(string id)
{
cars = SafeManager.ReadCars(filePath);
return cars.FirstOrDefault(c => c.Id == id);
@@ -96,8 +101,8 @@ namespace CarManagerV3
public static Car CreateCar(string make, string model, int year, string color, int mileage, decimal price)
{
cars = SafeManager.ReadCars(filePath);
int newId = cars.Count > 0 ? cars.Max(c => c.Id) + 1 : 1;
Car newCar = new Car(newId, make, model, year, color, mileage, price);
int newOrder = cars.Count > 0 ? cars.Max(c => c.Order) + 1 : 1;
Car newCar = new Car("", make, model, year, color, mileage, price, newOrder);
AddCar(newCar);
return newCar;
}
@@ -109,7 +114,21 @@ namespace CarManagerV3
/// <param name="path">The path.</param>
public static void setFilePath(string path)
{
// Reset migration confirmation when changing file path, as the new file may also require migration.
hasConfirmedMigration = false;
filePath = path;
}
public static bool askForMigration()
{
if (hasConfirmedMigration)
{
return true;
}
DialogResult result = MessageBox.Show("The file you are trying to open is in an older format. Do you want to attempt to migrate it to the new format? If you choose not to migrate, the file will not be opened.", "Migration Needed", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
hasConfirmedMigration = result == DialogResult.Yes;
return hasConfirmedMigration;
}
}
}