feat: reordering
This commit is contained in:
@@ -37,6 +37,8 @@ namespace CarManagerV3
|
||||
showOpenFileDialog();
|
||||
}
|
||||
|
||||
refreshRecents();
|
||||
|
||||
}
|
||||
|
||||
public void showOpenFileDialog()
|
||||
@@ -56,7 +58,7 @@ namespace CarManagerV3
|
||||
this.Text = "Car Manager - " + System.IO.Path.GetFileName(filepath);
|
||||
|
||||
// Sort by Car.Order. If equal, sort by ID
|
||||
_cars = _cars.Count > 0 ? _cars.OrderBy(c => c.Order).ThenBy(c => c.Id).ToList() : _cars;
|
||||
_cars = _cars.Count > 0 ? _cars.OrderBy(c => c.Order).ToList() : _cars;
|
||||
|
||||
if (updateGlobal)
|
||||
{
|
||||
@@ -79,7 +81,7 @@ namespace CarManagerV3
|
||||
continue;
|
||||
}
|
||||
// compare details
|
||||
Console.WriteLine($"[L] Checking car: {car.Id} | Car Color: {car.Color} | Ex Color: {existingCar.Color}");
|
||||
// Console.WriteLine($"[L] Checking car: {car.Id} | Car Color: {car.Color} | Ex Color: {existingCar.Color}");
|
||||
if (existingCar.IsChanged(car))
|
||||
{
|
||||
Console.WriteLine($"[L] Updating car: {car.Id}");
|
||||
@@ -90,14 +92,14 @@ namespace CarManagerV3
|
||||
else
|
||||
{
|
||||
// no changes
|
||||
Console.WriteLine($"[L] No changes for car: {car.Id}");
|
||||
// Console.WriteLine($"[L] No changes for car: {car.Id}");
|
||||
flpCars.Controls.SetChildIndex(existing, _cars.IndexOf(car));
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
card.CarName = $"{car.Make} {car.Model}";
|
||||
card.CarDetails = $"{car.Year}, {car.Mileage} km, ${car.Price}";
|
||||
card.CarDetails = $"({car.Order}) {car.Year}, {car.Mileage} km, ${car.Price}";
|
||||
card.Car = car.Clone();
|
||||
card.LoadImage();
|
||||
// clear existing event handlers to prevent multiple subscriptions
|
||||
@@ -125,6 +127,42 @@ namespace CarManagerV3
|
||||
detailsForm.ShowDialog();
|
||||
};
|
||||
|
||||
ContextMenu cm = new ContextMenu();
|
||||
cm.MenuItems.Add(new MenuItem("Move Up", (s, e) =>
|
||||
{
|
||||
int order = car.Order;
|
||||
// find car with order just less than this one
|
||||
Car other = cars.Where(c => c.Order < order).OrderByDescending(c => c.Order).FirstOrDefault();
|
||||
if (other != null)
|
||||
{
|
||||
Console.WriteLine($"Swapping order of {car.ToString()} ({car.Order}) and {other.ToString()} ({other.Order})");
|
||||
int temp = car.Order;
|
||||
car.Order = other.Order;
|
||||
other.Order = temp;
|
||||
SafeManager.SaveCars(filepath, cars);
|
||||
refreshCars(cars);
|
||||
}
|
||||
}));
|
||||
|
||||
cm.MenuItems.Add(new MenuItem("Move Down", (s, e) =>
|
||||
{
|
||||
|
||||
int order = car.Order;
|
||||
// find car with order just greater than this one
|
||||
Car other = cars.Where(c => c.Order > order).OrderBy(c => c.Order).FirstOrDefault();
|
||||
if (other != null)
|
||||
{
|
||||
Console.WriteLine($"Swapping order of {car.ToString()} ({car.Order}) and {other.ToString()} ({other.Order})");
|
||||
int temp = car.Order;
|
||||
car.Order = other.Order;
|
||||
other.Order = temp;
|
||||
SafeManager.SaveCars(filepath, cars);
|
||||
refreshCars(cars);
|
||||
}
|
||||
}));
|
||||
|
||||
card.ContextMenu = cm;
|
||||
|
||||
if (isNew)
|
||||
{
|
||||
flpCars.Controls.Add(card);
|
||||
@@ -217,7 +255,7 @@ namespace CarManagerV3
|
||||
dlgOpen.Filter = "CSV Files (*.csv)|*.csv|All Files (*.*)|*.*";
|
||||
dlgOpen.Title = "Open Car Data File";
|
||||
// Default to users documents
|
||||
dlgOpen.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
|
||||
dlgOpen.InitialDirectory = SafeManager.getRecentFolder();
|
||||
|
||||
DialogResult result = dlgOpen.ShowDialog();
|
||||
if (result == DialogResult.OK)
|
||||
@@ -263,7 +301,7 @@ namespace CarManagerV3
|
||||
dlgSave.Filter = "CSV Files (*.csv)|*.csv|All Files (*.*)|*.*";
|
||||
dlgSave.Title = "Save Car Data File As";
|
||||
// Default to users documents
|
||||
dlgSave.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
|
||||
dlgSave.InitialDirectory = SafeManager.getRecentFolder();
|
||||
DialogResult result = dlgSave.ShowDialog();
|
||||
|
||||
if (result == DialogResult.OK)
|
||||
@@ -296,7 +334,7 @@ namespace CarManagerV3
|
||||
dlgOpen.Filter = "CSV Files (*.csv)|*.csv|All Files (*.*)|*.*";
|
||||
dlgOpen.Title = "Import Car Data File";
|
||||
// Default to users documents
|
||||
dlgOpen.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
|
||||
dlgOpen.InitialDirectory = SafeManager.getRecentFolder();
|
||||
DialogResult dlgResult = dlgOpen.ShowDialog();
|
||||
if (dlgResult == DialogResult.OK)
|
||||
{
|
||||
@@ -320,7 +358,7 @@ namespace CarManagerV3
|
||||
dlgSave.Filter = "CSV Files (*.csv)|*.csv|All Files (*.*)|*.*";
|
||||
dlgSave.Title = "Save Merged Car Data File As";
|
||||
// Default to users documents
|
||||
dlgSave.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
|
||||
dlgSave.InitialDirectory = SafeManager.getRecentFolder();
|
||||
DialogResult saveResult = dlgSave.ShowDialog();
|
||||
if (saveResult == DialogResult.OK)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user