feat: GUID
This commit is contained in:
@@ -25,13 +25,26 @@ namespace CarManagerV3
|
||||
|
||||
SafeManager.InitializeFile(filepath);
|
||||
StateManager.setFilePath(filepath);
|
||||
List<Car> _cars = SafeManager.ReadCars(filepath);
|
||||
|
||||
refreshCars(_cars);
|
||||
refreshRecents();
|
||||
try
|
||||
{
|
||||
List<Car> _cars = SafeManager.ReadCars(filepath);
|
||||
cars = _cars;
|
||||
refreshCars(_cars, false);
|
||||
}
|
||||
catch (LegacyException)
|
||||
{
|
||||
Console.Error.WriteLine("Legacy file format detected. Prompting user to select a new file.");
|
||||
showOpenFileDialog();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void showOpenFileDialog()
|
||||
{
|
||||
openToolStripMenuItem.PerformClick();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Refreshes the cars displayed in the flow layout panel.
|
||||
/// </summary>
|
||||
@@ -135,7 +148,7 @@ namespace CarManagerV3
|
||||
|
||||
private void btnNewCar_Click(object sender, EventArgs e)
|
||||
{
|
||||
Car foocar = new Car(0, "New", "Car", 2020, "White", 0, 20000);
|
||||
Car foocar = new Car("0", "New", "Car", 2020, "White", 0, 20000);
|
||||
CarDetailsForm detailsForm = new CarDetailsForm(foocar);
|
||||
detailsForm.FormClosed += (s2, e2) =>
|
||||
{
|
||||
@@ -226,6 +239,10 @@ namespace CarManagerV3
|
||||
SafeManager.AddRecentPath(filepath);
|
||||
refreshRecents();
|
||||
}
|
||||
catch (LegacyException)
|
||||
{
|
||||
showOpenFileDialog();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show("Error loading file: " + ex.Message);
|
||||
@@ -294,13 +311,6 @@ namespace CarManagerV3
|
||||
// merge cars
|
||||
foreach (Car car in importedCars)
|
||||
{
|
||||
// check if car with same ID exists
|
||||
if (cars.Any(c => c.Id == car.Id))
|
||||
{
|
||||
// assign new ID
|
||||
int newId = cars.Count > 0 ? cars.Max(c => c.Id) + 1 : 1;
|
||||
car.Id = newId;
|
||||
}
|
||||
cars.Add(car);
|
||||
}
|
||||
DialogResult mergeAsNewFileResult = MessageBox.Show("Do you want to save the merged cars as a new file?", "Save As New File", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
|
||||
@@ -330,6 +340,10 @@ namespace CarManagerV3
|
||||
refreshCars(cars);
|
||||
MessageBox.Show("File imported successfully.", "Import File", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
}
|
||||
catch (LegacyException)
|
||||
{
|
||||
MessageBox.Show("The file you are trying to import is in a legacy format that is no longer supported. Please convert the file to the new format and try again.", "Import Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show("Error importing file: " + ex.Message);
|
||||
|
||||
Reference in New Issue
Block a user