feature/cuid #1

Merged
frozd merged 5 commits from feature/cuid into master 2026-03-03 11:33:29 +01:00
10 changed files with 119 additions and 34 deletions
Showing only changes of commit 272ed999d8 - Show all commits

View File

@@ -209,7 +209,7 @@ namespace CarManagerV3
/// </returns> /// </returns>
public bool IsChanged(Car other) public bool IsChanged(Car other)
{ {
return this.Make != other.Make || this.Model != other.Model || this.Year != other.Year || this.Color != other.Color || this.Mileage != other.Mileage || this.Price != other.Price || this.Color != other.Color; return this.Make != other.Make || this.Model != other.Model || this.Year != other.Year || this.Color != other.Color || this.Mileage != other.Mileage || this.Price != other.Price || this.Color != other.Color || this.Order != other.Order;
} }
/// <summary> /// <summary>

View File

@@ -59,7 +59,7 @@
// lblCarDetails // lblCarDetails
// //
this.lblCarDetails.AutoSize = true; this.lblCarDetails.AutoSize = true;
this.lblCarDetails.Location = new System.Drawing.Point(3, 184); this.lblCarDetails.Location = new System.Drawing.Point(3, 174);
this.lblCarDetails.Name = "lblCarDetails"; this.lblCarDetails.Name = "lblCarDetails";
this.lblCarDetails.Size = new System.Drawing.Size(101, 16); this.lblCarDetails.Size = new System.Drawing.Size(101, 16);
this.lblCarDetails.TabIndex = 5; this.lblCarDetails.TabIndex = 5;
@@ -72,7 +72,7 @@
this.lblCarName.Font = new System.Drawing.Font("Arial", 13.8F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.lblCarName.Font = new System.Drawing.Font("Arial", 13.8F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.lblCarName.Location = new System.Drawing.Point(3, 130); this.lblCarName.Location = new System.Drawing.Point(3, 130);
this.lblCarName.Name = "lblCarName"; this.lblCarName.Name = "lblCarName";
this.lblCarName.Size = new System.Drawing.Size(204, 54); this.lblCarName.Size = new System.Drawing.Size(204, 44);
this.lblCarName.TabIndex = 4; this.lblCarName.TabIndex = 4;
this.lblCarName.Text = "Skoda Fabia fdsdfsdfsdfsdf"; this.lblCarName.Text = "Skoda Fabia fdsdfsdfsdfsdf";
this.lblCarName.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; this.lblCarName.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;

View File

@@ -38,12 +38,14 @@ namespace CarManagerV3
foreach (Control ctrl in this.Controls) foreach (Control ctrl in this.Controls)
{ {
ctrl.Click += ForwardClick; ctrl.MouseClick += ForwardClick;
foreach (Control inner in ctrl.Controls) // In case you have nested controls foreach (Control inner in ctrl.Controls)
inner.Click += ForwardClick; {
inner.MouseClick += ForwardClick;
}
} }
this.Click += (s, e) => this.OnCardClicked(); this.MouseClick += (s, e) => this.OnCardClicked(s, e);
} }
public async void LoadImage() public async void LoadImage()
@@ -59,15 +61,22 @@ namespace CarManagerV3
}); });
} }
private void ForwardClick(object sender, EventArgs e) private void ForwardClick(object sender, MouseEventArgs e)
{ {
// Raise your CardClicked event no matter what got clicked // Raise your CardClicked event no matter what got clicked
if (e.Button == MouseButtons.Right) return;
Console.WriteLine($"Forwarding click from {sender.GetType().Name}");
CardClicked?.Invoke(this, EventArgs.Empty); CardClicked?.Invoke(this, EventArgs.Empty);
} }
public event EventHandler CardClicked; public event EventHandler CardClicked;
private void OnCardClicked() private void OnCardClicked(object sender, MouseEventArgs e)
{ {
Console.WriteLine($"Card clicked at {e.Location} with button {e.Button}");
if (e.Button == MouseButtons.Right) return;
Console.WriteLine($"Card clicked: {this.CarName}");
if (this.CardClicked != null) if (this.CardClicked != null)
{ {
this.CardClicked(this, EventArgs.Empty); this.CardClicked(this, EventArgs.Empty);

View File

@@ -121,7 +121,7 @@
<data name="pbxCar.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64"> <data name="pbxCar.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value> <value>
iVBORw0KGgoAAAANSUhEUgAABLAAAALuCAYAAAC+de9yAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAL iVBORw0KGgoAAAANSUhEUgAABLAAAALuCAYAAAC+de9yAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAL
EgAACxIB0t1+/AAA/7JJREFUeF7s/fuXZ8dZ349K5gs2dggQCJeYXAADx+IWooRLwsUc8Jc44QBfgpwE EQAACxEBf2RfkQAA/7JJREFUeF7s/fuXZ8dZ349K5gs2dggQCJeYXAADx+IWooRLwsUc8Jc44QBfgpwE
MNiAbQIYI3yRrZHUv50VlhewCHG8tIyQLVmyaY/m0jM9PT09Mz33W3dPT09Pz4zGwsn5S3RWXZ6n3s+7 MNiAbQIYI3yRrZHUv50VlhewCHG8tIyQLVmyaY/m0jM9PT09Mz33W3dPT09Pz4zGwsn5S3RWXZ6n3s+7
an96ZBvb2O/3Ws/au+61a9duTb30VH3uuUeSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmS an96ZBvb2O/3Ws/au+61a9duTb30VH3uuUeSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmS
JEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmS JEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmS
@@ -5505,7 +5505,7 @@
<data name="pbxCar.InitialImage" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64"> <data name="pbxCar.InitialImage" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value> <value>
iVBORw0KGgoAAAANSUhEUgAABLAAAALuCAYAAAC+de9yAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAL iVBORw0KGgoAAAANSUhEUgAABLAAAALuCAYAAAC+de9yAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAL
EgAACxIB0t1+/AAA/7JJREFUeF7s/fuXZ8dZ349K5gs2dggQCJeYXAADx+IWooRLwsUc8Jc44QBfgpwE EQAACxEBf2RfkQAA/7JJREFUeF7s/fuXZ8dZ349K5gs2dggQCJeYXAADx+IWooRLwsUc8Jc44QBfgpwE
MNiAbQIYI3yRrZHUv50VlhewCHG8tIyQLVmyaY/m0jM9PT09Mz33W3dPT09Pz4zGwsn5S3RWXZ6n3s+7 MNiAbQIYI3yRrZHUv50VlhewCHG8tIyQLVmyaY/m0jM9PT09Mz33W3dPT09Pz4zGwsn5S3RWXZ6n3s+7
an96ZBvb2O/3Ws/au+61a9duTb30VH3uuUeSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmS an96ZBvb2O/3Ws/au+61a9duTb30VH3uuUeSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmS
JEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmS JEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmS

View File

@@ -68,7 +68,7 @@
<Compile Include="CarCard.Designer.cs"> <Compile Include="CarCard.Designer.cs">
<DependentUpon>CarCard.cs</DependentUpon> <DependentUpon>CarCard.cs</DependentUpon>
</Compile> </Compile>
<Compile Include="Class1.cs" /> <Compile Include="LegacyException.cs" />
<Compile Include="MainForm.cs"> <Compile Include="MainForm.cs">
<SubType>Form</SubType> <SubType>Form</SubType>
</Compile> </Compile>
@@ -139,5 +139,8 @@
<Install>false</Install> <Install>false</Install>
</BootstrapperPackage> </BootstrapperPackage>
</ItemGroup> </ItemGroup>
<ItemGroup>
<Folder Include="Manager\" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project> </Project>

View File

@@ -1,12 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CarManagerV3
{
internal class LegacyException : Exception
{
}
}

View File

@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CarManagerV3
{
/// <summary>
/// LegacyException is a custom exception class used to indicate that a file is in a legacy format that cannot be read by the current version of the application. It is thrown when the SafeManager encounters a file format that it does not recognize, allowing the application to handle this specific case separately from other types of exceptions.
/// </summary>
/// <seealso cref="System.Exception" />
internal class LegacyException : Exception
{
}
}

View File

@@ -37,6 +37,8 @@ namespace CarManagerV3
showOpenFileDialog(); showOpenFileDialog();
} }
refreshRecents();
} }
public void showOpenFileDialog() public void showOpenFileDialog()
@@ -56,7 +58,7 @@ namespace CarManagerV3
this.Text = "Car Manager - " + System.IO.Path.GetFileName(filepath); this.Text = "Car Manager - " + System.IO.Path.GetFileName(filepath);
// Sort by Car.Order. If equal, sort by ID // 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) if (updateGlobal)
{ {
@@ -79,7 +81,7 @@ namespace CarManagerV3
continue; continue;
} }
// compare details // 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)) if (existingCar.IsChanged(car))
{ {
Console.WriteLine($"[L] Updating car: {car.Id}"); Console.WriteLine($"[L] Updating car: {car.Id}");
@@ -90,14 +92,14 @@ namespace CarManagerV3
else else
{ {
// no changes // 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)); flpCars.Controls.SetChildIndex(existing, _cars.IndexOf(car));
continue; continue;
} }
} }
card.CarName = $"{car.Make} {car.Model}"; 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.Car = car.Clone();
card.LoadImage(); card.LoadImage();
// clear existing event handlers to prevent multiple subscriptions // clear existing event handlers to prevent multiple subscriptions
@@ -125,6 +127,42 @@ namespace CarManagerV3
detailsForm.ShowDialog(); 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) if (isNew)
{ {
flpCars.Controls.Add(card); flpCars.Controls.Add(card);
@@ -217,7 +255,7 @@ namespace CarManagerV3
dlgOpen.Filter = "CSV Files (*.csv)|*.csv|All Files (*.*)|*.*"; dlgOpen.Filter = "CSV Files (*.csv)|*.csv|All Files (*.*)|*.*";
dlgOpen.Title = "Open Car Data File"; dlgOpen.Title = "Open Car Data File";
// Default to users documents // Default to users documents
dlgOpen.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); dlgOpen.InitialDirectory = SafeManager.getRecentFolder();
DialogResult result = dlgOpen.ShowDialog(); DialogResult result = dlgOpen.ShowDialog();
if (result == DialogResult.OK) if (result == DialogResult.OK)
@@ -263,7 +301,7 @@ namespace CarManagerV3
dlgSave.Filter = "CSV Files (*.csv)|*.csv|All Files (*.*)|*.*"; dlgSave.Filter = "CSV Files (*.csv)|*.csv|All Files (*.*)|*.*";
dlgSave.Title = "Save Car Data File As"; dlgSave.Title = "Save Car Data File As";
// Default to users documents // Default to users documents
dlgSave.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); dlgSave.InitialDirectory = SafeManager.getRecentFolder();
DialogResult result = dlgSave.ShowDialog(); DialogResult result = dlgSave.ShowDialog();
if (result == DialogResult.OK) if (result == DialogResult.OK)
@@ -296,7 +334,7 @@ namespace CarManagerV3
dlgOpen.Filter = "CSV Files (*.csv)|*.csv|All Files (*.*)|*.*"; dlgOpen.Filter = "CSV Files (*.csv)|*.csv|All Files (*.*)|*.*";
dlgOpen.Title = "Import Car Data File"; dlgOpen.Title = "Import Car Data File";
// Default to users documents // Default to users documents
dlgOpen.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); dlgOpen.InitialDirectory = SafeManager.getRecentFolder();
DialogResult dlgResult = dlgOpen.ShowDialog(); DialogResult dlgResult = dlgOpen.ShowDialog();
if (dlgResult == DialogResult.OK) if (dlgResult == DialogResult.OK)
{ {
@@ -320,7 +358,7 @@ namespace CarManagerV3
dlgSave.Filter = "CSV Files (*.csv)|*.csv|All Files (*.*)|*.*"; dlgSave.Filter = "CSV Files (*.csv)|*.csv|All Files (*.*)|*.*";
dlgSave.Title = "Save Merged Car Data File As"; dlgSave.Title = "Save Merged Car Data File As";
// Default to users documents // Default to users documents
dlgSave.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); dlgSave.InitialDirectory = SafeManager.getRecentFolder();
DialogResult saveResult = dlgSave.ShowDialog(); DialogResult saveResult = dlgSave.ShowDialog();
if (saveResult == DialogResult.OK) if (saveResult == DialogResult.OK)
{ {

View File

@@ -104,6 +104,7 @@ namespace CarManagerV3
} }
MessageBox.Show($"Warning: {failedLines.Count} lines in the file could not be parsed and were skipped. Check the console for details.", "Parsing Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); MessageBox.Show($"Warning: {failedLines.Count} lines in the file could not be parsed and were skipped. Check the console for details.", "Parsing Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
} }
cars = StateManager.normalizeOrders(cars);
cars = cars.OrderBy(c => c.Order).ToList(); cars = cars.OrderBy(c => c.Order).ToList();
if (isLegacy) if (isLegacy)
{ {
@@ -213,6 +214,25 @@ namespace CarManagerV3
return paths; return paths;
} }
/// <summary>
/// Gets the folder of the most recently opened file, or the users documents folder if no recent files.
/// </summary>
/// <returns></returns>
public static string getRecentFolder()
{
List<string> recentPaths = GetRecentPaths();
if (recentPaths.Count > 0)
{
string recentFile = recentPaths[0];
if (File.Exists(recentFile))
{
return Path.GetDirectoryName(recentFile);
}
}
return Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
}
} }
} }

View File

@@ -119,6 +119,17 @@ namespace CarManagerV3
filePath = path; filePath = path;
} }
public static List<Car> normalizeOrders(List<Car> cars)
{
// Normalize the Order field of all cars to be sequential starting from 1, while keeping the relative order the same.
var orderedCars = cars.OrderBy(c => c.Order).ToList();
for (int i = 0; i < orderedCars.Count; i++)
{
orderedCars[i].Order = i + 1;
}
return orderedCars;
}
public static bool askForMigration() public static bool askForMigration()
{ {
if (hasConfirmedMigration) if (hasConfirmedMigration)