diff --git a/.idea/.idea.CarManagerV3/.idea/.gitignore b/.idea/.idea.CarManagerV3/.idea/.gitignore
new file mode 100644
index 0000000..e545e1d
--- /dev/null
+++ b/.idea/.idea.CarManagerV3/.idea/.gitignore
@@ -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/
diff --git a/.idea/.idea.CarManagerV3/.idea/encodings.xml b/.idea/.idea.CarManagerV3/.idea/encodings.xml
new file mode 100644
index 0000000..df87cf9
--- /dev/null
+++ b/.idea/.idea.CarManagerV3/.idea/encodings.xml
@@ -0,0 +1,4 @@
+
+
+
+
\ No newline at end of file
diff --git a/.idea/.idea.CarManagerV3/.idea/indexLayout.xml b/.idea/.idea.CarManagerV3/.idea/indexLayout.xml
new file mode 100644
index 0000000..7b08163
--- /dev/null
+++ b/.idea/.idea.CarManagerV3/.idea/indexLayout.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/.idea.CarManagerV3/.idea/vcs.xml b/.idea/.idea.CarManagerV3/.idea/vcs.xml
new file mode 100644
index 0000000..35eb1dd
--- /dev/null
+++ b/.idea/.idea.CarManagerV3/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/CarManagerV3/CarDetailsForm.Designer.cs b/CarManagerV3/CarDetailsForm.Designer.cs
index 4fd6bbb..893a8aa 100644
--- a/CarManagerV3/CarDetailsForm.Designer.cs
+++ b/CarManagerV3/CarDetailsForm.Designer.cs
@@ -43,20 +43,20 @@
this.btnSave = new System.Windows.Forms.Button();
this.btnDelete = new System.Windows.Forms.Button();
this.lblID = new System.Windows.Forms.Label();
- this.nudYear = new System.Windows.Forms.NumericUpDown();
this.tbxColor = new System.Windows.Forms.TextBox();
this.nudMileage = new System.Windows.Forms.NumericUpDown();
this.nudPrice = new System.Windows.Forms.NumericUpDown();
this.tableLayoutPanel2 = new System.Windows.Forms.TableLayoutPanel();
+ this.nudYear = new System.Windows.Forms.NumericUpDown();
this.lblAge = new System.Windows.Forms.Label();
this.tbxAge = new System.Windows.Forms.TextBox();
this.tableLayoutPanel1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pbxCarImage)).BeginInit();
this.flowLayoutPanel1.SuspendLayout();
- ((System.ComponentModel.ISupportInitialize)(this.nudYear)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.nudMileage)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.nudPrice)).BeginInit();
this.tableLayoutPanel2.SuspendLayout();
+ ((System.ComponentModel.ISupportInitialize)(this.nudYear)).BeginInit();
this.SuspendLayout();
//
// tableLayoutPanel1
@@ -238,19 +238,6 @@
this.lblID.TabIndex = 2;
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
//
this.tbxColor.Dock = System.Windows.Forms.DockStyle.Fill;
@@ -307,6 +294,19 @@
this.tableLayoutPanel2.Size = new System.Drawing.Size(473, 24);
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
//
this.lblAge.AutoSize = true;
@@ -343,11 +343,11 @@
((System.ComponentModel.ISupportInitialize)(this.pbxCarImage)).EndInit();
this.flowLayoutPanel1.ResumeLayout(false);
this.flowLayoutPanel1.PerformLayout();
- ((System.ComponentModel.ISupportInitialize)(this.nudYear)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.nudMileage)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.nudPrice)).EndInit();
this.tableLayoutPanel2.ResumeLayout(false);
this.tableLayoutPanel2.PerformLayout();
+ ((System.ComponentModel.ISupportInitialize)(this.nudYear)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
diff --git a/CarManagerV3/CarDetailsForm.cs b/CarManagerV3/CarDetailsForm.cs
index 05d4481..bbd3e0d 100644
--- a/CarManagerV3/CarDetailsForm.cs
+++ b/CarManagerV3/CarDetailsForm.cs
@@ -7,7 +7,7 @@ namespace CarManagerV3
public partial class CarDetailsForm : Form
{
- Car car;
+ public Car car;
public CarDetailsForm(Car car)
{
@@ -21,7 +21,14 @@ namespace CarManagerV3
nudPrice.Value = car.Price;
tbxAge.Text = car.AgeString;
pbxCarImage.Image = ImageManager.GetImage(car);
- lblID.Text = $"ID: {car.Id}";
+ if (car.Id == 0)
+ {
+ lblID.Text = "New Car";
+ }
+ else
+ {
+ lblID.Text = $"ID: {car.Id}";
+ }
}
///
@@ -118,7 +125,12 @@ namespace CarManagerV3
msgbox.Show();
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("Car saved. " + car.Id);
@@ -133,6 +145,12 @@ namespace CarManagerV3
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?
var result = MessageBox.Show("Are you sure you want to delete this car?", "Delete Car", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
if (result == DialogResult.Yes)
diff --git a/CarManagerV3/MainForm.cs b/CarManagerV3/MainForm.cs
index a0448bf..f22ba3f 100644
--- a/CarManagerV3/MainForm.cs
+++ b/CarManagerV3/MainForm.cs
@@ -135,7 +135,7 @@ namespace CarManagerV3
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);
detailsForm.FormClosed += (s2, e2) =>
{