feat: Better car creation

This commit is contained in:
2026-02-24 08:57:47 +01:00
parent 4404ac3c7b
commit f6b70fa387
7 changed files with 71 additions and 20 deletions

15
.idea/.idea.CarManagerV3/.idea/.gitignore generated vendored Normal file
View File

@@ -0,0 +1,15 @@
# Default ignored files
/shelf/
/workspace.xml
# Rider ignored files
/contentModel.xml
/.idea.CarManagerV3.iml
/modules.xml
/projectSettingsUpdater.xml
# Ignored default folder with query files
/queries/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml
# Editor-based HTTP Client requests
/httpRequests/

View File

@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding" addBOMForNewFiles="with BOM under Windows, with no BOM otherwise" />
</project>

View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="UserContentModel">
<attachedFolders />
<explicitIncludes />
<explicitExcludes />
</component>
</project>

6
.idea/.idea.CarManagerV3/.idea/vcs.xml generated Normal file
View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>

View File

@@ -43,20 +43,20 @@
this.btnSave = new System.Windows.Forms.Button(); this.btnSave = new System.Windows.Forms.Button();
this.btnDelete = new System.Windows.Forms.Button(); this.btnDelete = new System.Windows.Forms.Button();
this.lblID = new System.Windows.Forms.Label(); this.lblID = new System.Windows.Forms.Label();
this.nudYear = new System.Windows.Forms.NumericUpDown();
this.tbxColor = new System.Windows.Forms.TextBox(); this.tbxColor = new System.Windows.Forms.TextBox();
this.nudMileage = new System.Windows.Forms.NumericUpDown(); this.nudMileage = new System.Windows.Forms.NumericUpDown();
this.nudPrice = new System.Windows.Forms.NumericUpDown(); this.nudPrice = new System.Windows.Forms.NumericUpDown();
this.tableLayoutPanel2 = new System.Windows.Forms.TableLayoutPanel(); this.tableLayoutPanel2 = new System.Windows.Forms.TableLayoutPanel();
this.nudYear = new System.Windows.Forms.NumericUpDown();
this.lblAge = new System.Windows.Forms.Label(); this.lblAge = new System.Windows.Forms.Label();
this.tbxAge = new System.Windows.Forms.TextBox(); this.tbxAge = new System.Windows.Forms.TextBox();
this.tableLayoutPanel1.SuspendLayout(); this.tableLayoutPanel1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pbxCarImage)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.pbxCarImage)).BeginInit();
this.flowLayoutPanel1.SuspendLayout(); this.flowLayoutPanel1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.nudYear)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.nudMileage)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.nudMileage)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.nudPrice)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.nudPrice)).BeginInit();
this.tableLayoutPanel2.SuspendLayout(); this.tableLayoutPanel2.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.nudYear)).BeginInit();
this.SuspendLayout(); this.SuspendLayout();
// //
// tableLayoutPanel1 // tableLayoutPanel1
@@ -238,19 +238,6 @@
this.lblID.TabIndex = 2; this.lblID.TabIndex = 2;
this.lblID.Text = "ID"; this.lblID.Text = "ID";
// //
// nudYear
//
this.nudYear.Location = new System.Drawing.Point(3, 3);
this.nudYear.Maximum = new decimal(new int[] {
3000,
0,
0,
0});
this.nudYear.Name = "nudYear";
this.nudYear.Size = new System.Drawing.Size(120, 22);
this.nudYear.TabIndex = 3;
this.nudYear.ValueChanged += new System.EventHandler(this.nudYear_ValueChanged);
//
// tbxColor // tbxColor
// //
this.tbxColor.Dock = System.Windows.Forms.DockStyle.Fill; this.tbxColor.Dock = System.Windows.Forms.DockStyle.Fill;
@@ -307,6 +294,19 @@
this.tableLayoutPanel2.Size = new System.Drawing.Size(473, 24); this.tableLayoutPanel2.Size = new System.Drawing.Size(473, 24);
this.tableLayoutPanel2.TabIndex = 10; this.tableLayoutPanel2.TabIndex = 10;
// //
// nudYear
//
this.nudYear.Location = new System.Drawing.Point(3, 3);
this.nudYear.Maximum = new decimal(new int[] {
3000,
0,
0,
0});
this.nudYear.Name = "nudYear";
this.nudYear.Size = new System.Drawing.Size(120, 22);
this.nudYear.TabIndex = 3;
this.nudYear.ValueChanged += new System.EventHandler(this.nudYear_ValueChanged);
//
// lblAge // lblAge
// //
this.lblAge.AutoSize = true; this.lblAge.AutoSize = true;
@@ -343,11 +343,11 @@
((System.ComponentModel.ISupportInitialize)(this.pbxCarImage)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.pbxCarImage)).EndInit();
this.flowLayoutPanel1.ResumeLayout(false); this.flowLayoutPanel1.ResumeLayout(false);
this.flowLayoutPanel1.PerformLayout(); this.flowLayoutPanel1.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.nudYear)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.nudMileage)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.nudMileage)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.nudPrice)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.nudPrice)).EndInit();
this.tableLayoutPanel2.ResumeLayout(false); this.tableLayoutPanel2.ResumeLayout(false);
this.tableLayoutPanel2.PerformLayout(); this.tableLayoutPanel2.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.nudYear)).EndInit();
this.ResumeLayout(false); this.ResumeLayout(false);
this.PerformLayout(); this.PerformLayout();

View File

@@ -7,7 +7,7 @@ namespace CarManagerV3
public partial class CarDetailsForm : Form public partial class CarDetailsForm : Form
{ {
Car car; public Car car;
public CarDetailsForm(Car car) public CarDetailsForm(Car car)
{ {
@@ -21,7 +21,14 @@ namespace CarManagerV3
nudPrice.Value = car.Price; nudPrice.Value = car.Price;
tbxAge.Text = car.AgeString; tbxAge.Text = car.AgeString;
pbxCarImage.Image = ImageManager.GetImage(car); pbxCarImage.Image = ImageManager.GetImage(car);
lblID.Text = $"ID: {car.Id}"; if (car.Id == 0)
{
lblID.Text = "New Car";
}
else
{
lblID.Text = $"ID: {car.Id}";
}
} }
/// <summary> /// <summary>
@@ -118,7 +125,12 @@ namespace CarManagerV3
msgbox.Show(); msgbox.Show();
await Task.Run(() => await Task.Run(() =>
{ {
StateManager.UpdateCar(car); if(car.Id == 0) {
car = StateManager.CreateCar(car.Make, car.Model, car.Year, car.Color, car.Mileage, car.Price);
}
else {
StateManager.UpdateCar(car);
}
Console.WriteLine("Saved car: " + car.Id); Console.WriteLine("Saved car: " + car.Id);
}); });
Console.WriteLine("Car saved. " + car.Id); Console.WriteLine("Car saved. " + car.Id);
@@ -133,6 +145,12 @@ namespace CarManagerV3
private void btnDelete_Click(object sender, EventArgs e) private void btnDelete_Click(object sender, EventArgs e)
{ {
if(car.Id == 0)
{
//just close form if car is not saved yet
this.Close();
return;
}
//are you sure? //are you sure?
var result = MessageBox.Show("Are you sure you want to delete this car?", "Delete Car", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); var result = MessageBox.Show("Are you sure you want to delete this car?", "Delete Car", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
if (result == DialogResult.Yes) if (result == DialogResult.Yes)

View File

@@ -135,7 +135,7 @@ namespace CarManagerV3
private void btnNewCar_Click(object sender, EventArgs e) private void btnNewCar_Click(object sender, EventArgs e)
{ {
Car foocar = StateManager.CreateCar("New", "Car", 2020, "White", 0, 20000); Car foocar = new Car(0, "New", "Car", 2020, "White", 0, 20000);
CarDetailsForm detailsForm = new CarDetailsForm(foocar); CarDetailsForm detailsForm = new CarDetailsForm(foocar);
detailsForm.FormClosed += (s2, e2) => detailsForm.FormClosed += (s2, e2) =>
{ {