feat: display car age
This commit is contained in:
@@ -19,6 +19,7 @@ namespace CarManagerV3
|
|||||||
private int mileage;
|
private int mileage;
|
||||||
private decimal price;
|
private decimal price;
|
||||||
private int order;
|
private int order;
|
||||||
|
private int age;
|
||||||
|
|
||||||
public int Id { get => id;
|
public int Id { get => id;
|
||||||
set {
|
set {
|
||||||
@@ -46,9 +47,7 @@ namespace CarManagerV3
|
|||||||
public int Year { get => year;
|
public int Year { get => year;
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
|
|
||||||
if (value < 1886 || value > DateTime.Now.Year + 1) throw new ArgumentException("Year must be between 1886 and next year.");
|
if (value < 1886 || value > DateTime.Now.Year + 1) throw new ArgumentException("Year must be between 1886 and next year.");
|
||||||
Console.WriteLine($"Updating year to {year}");
|
|
||||||
year = value;
|
year = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -79,6 +78,19 @@ namespace CarManagerV3
|
|||||||
|
|
||||||
public int Order { get => order; set => order = value; }
|
public int Order { get => order; set => order = value; }
|
||||||
|
|
||||||
|
public int Age { get => DateTime.Now.Year - year; }
|
||||||
|
public string AgeString
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
int age = this.Age;
|
||||||
|
if (age == 0) return "New";
|
||||||
|
else if (age == 1) return "1 year";
|
||||||
|
else if (age < 0) return "From the future!";
|
||||||
|
else return $"{age} years";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//TODO: Make Id read-only CUID. Allows for better integrity, especially when merging.
|
//TODO: Make Id read-only CUID. Allows for better integrity, especially when merging.
|
||||||
//TODO: Add buying price and automatic calculation of profit/loss with selling price suggestion.
|
//TODO: Add buying price and automatic calculation of profit/loss with selling price suggestion.
|
||||||
//TODO: Add Buying Date.
|
//TODO: Add Buying Date.
|
||||||
|
|||||||
77
CarManagerV3/CarDetailsForm.Designer.cs
generated
77
CarManagerV3/CarDetailsForm.Designer.cs
generated
@@ -47,12 +47,16 @@
|
|||||||
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.lblAge = new System.Windows.Forms.Label();
|
||||||
|
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.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.SuspendLayout();
|
this.SuspendLayout();
|
||||||
//
|
//
|
||||||
// tableLayoutPanel1
|
// tableLayoutPanel1
|
||||||
@@ -62,6 +66,8 @@
|
|||||||
this.tableLayoutPanel1.ColumnCount = 2;
|
this.tableLayoutPanel1.ColumnCount = 2;
|
||||||
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle());
|
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle());
|
||||||
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle());
|
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle());
|
||||||
|
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F));
|
||||||
|
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F));
|
||||||
this.tableLayoutPanel1.Controls.Add(this.pbxCarImage, 0, 0);
|
this.tableLayoutPanel1.Controls.Add(this.pbxCarImage, 0, 0);
|
||||||
this.tableLayoutPanel1.Controls.Add(this.label1, 0, 1);
|
this.tableLayoutPanel1.Controls.Add(this.label1, 0, 1);
|
||||||
this.tableLayoutPanel1.Controls.Add(this.tbxMake, 1, 1);
|
this.tableLayoutPanel1.Controls.Add(this.tbxMake, 1, 1);
|
||||||
@@ -72,10 +78,10 @@
|
|||||||
this.tableLayoutPanel1.Controls.Add(this.label5, 0, 5);
|
this.tableLayoutPanel1.Controls.Add(this.label5, 0, 5);
|
||||||
this.tableLayoutPanel1.Controls.Add(this.label6, 0, 6);
|
this.tableLayoutPanel1.Controls.Add(this.label6, 0, 6);
|
||||||
this.tableLayoutPanel1.Controls.Add(this.flowLayoutPanel1, 0, 7);
|
this.tableLayoutPanel1.Controls.Add(this.flowLayoutPanel1, 0, 7);
|
||||||
this.tableLayoutPanel1.Controls.Add(this.nudYear, 1, 3);
|
|
||||||
this.tableLayoutPanel1.Controls.Add(this.tbxColor, 1, 4);
|
this.tableLayoutPanel1.Controls.Add(this.tbxColor, 1, 4);
|
||||||
this.tableLayoutPanel1.Controls.Add(this.nudMileage, 1, 5);
|
this.tableLayoutPanel1.Controls.Add(this.nudMileage, 1, 5);
|
||||||
this.tableLayoutPanel1.Controls.Add(this.nudPrice, 1, 6);
|
this.tableLayoutPanel1.Controls.Add(this.nudPrice, 1, 6);
|
||||||
|
this.tableLayoutPanel1.Controls.Add(this.tableLayoutPanel2, 1, 3);
|
||||||
this.tableLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill;
|
this.tableLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||||
this.tableLayoutPanel1.Location = new System.Drawing.Point(0, 0);
|
this.tableLayoutPanel1.Location = new System.Drawing.Point(0, 0);
|
||||||
this.tableLayoutPanel1.Name = "tableLayoutPanel1";
|
this.tableLayoutPanel1.Name = "tableLayoutPanel1";
|
||||||
@@ -106,11 +112,13 @@
|
|||||||
// label1
|
// label1
|
||||||
//
|
//
|
||||||
this.label1.AutoSize = true;
|
this.label1.AutoSize = true;
|
||||||
|
this.label1.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||||
this.label1.Location = new System.Drawing.Point(3, 200);
|
this.label1.Location = new System.Drawing.Point(3, 200);
|
||||||
this.label1.Name = "label1";
|
this.label1.Name = "label1";
|
||||||
this.label1.Size = new System.Drawing.Size(44, 16);
|
this.label1.Size = new System.Drawing.Size(59, 30);
|
||||||
this.label1.TabIndex = 1;
|
this.label1.TabIndex = 1;
|
||||||
this.label1.Text = "Make:";
|
this.label1.Text = "Make:";
|
||||||
|
this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
|
||||||
//
|
//
|
||||||
// tbxMake
|
// tbxMake
|
||||||
//
|
//
|
||||||
@@ -125,11 +133,13 @@
|
|||||||
// label2
|
// label2
|
||||||
//
|
//
|
||||||
this.label2.AutoSize = true;
|
this.label2.AutoSize = true;
|
||||||
|
this.label2.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||||
this.label2.Location = new System.Drawing.Point(3, 230);
|
this.label2.Location = new System.Drawing.Point(3, 230);
|
||||||
this.label2.Name = "label2";
|
this.label2.Name = "label2";
|
||||||
this.label2.Size = new System.Drawing.Size(48, 16);
|
this.label2.Size = new System.Drawing.Size(59, 30);
|
||||||
this.label2.TabIndex = 3;
|
this.label2.TabIndex = 3;
|
||||||
this.label2.Text = "Model:";
|
this.label2.Text = "Model:";
|
||||||
|
this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
|
||||||
//
|
//
|
||||||
// tbxModel
|
// tbxModel
|
||||||
//
|
//
|
||||||
@@ -144,38 +154,46 @@
|
|||||||
// label3
|
// label3
|
||||||
//
|
//
|
||||||
this.label3.AutoSize = true;
|
this.label3.AutoSize = true;
|
||||||
|
this.label3.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||||
this.label3.Location = new System.Drawing.Point(3, 260);
|
this.label3.Location = new System.Drawing.Point(3, 260);
|
||||||
this.label3.Name = "label3";
|
this.label3.Name = "label3";
|
||||||
this.label3.Size = new System.Drawing.Size(39, 16);
|
this.label3.Size = new System.Drawing.Size(59, 30);
|
||||||
this.label3.TabIndex = 5;
|
this.label3.TabIndex = 5;
|
||||||
this.label3.Text = "Year:";
|
this.label3.Text = "Year:";
|
||||||
|
this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
|
||||||
//
|
//
|
||||||
// label4
|
// label4
|
||||||
//
|
//
|
||||||
this.label4.AutoSize = true;
|
this.label4.AutoSize = true;
|
||||||
|
this.label4.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||||
this.label4.Location = new System.Drawing.Point(3, 290);
|
this.label4.Location = new System.Drawing.Point(3, 290);
|
||||||
this.label4.Name = "label4";
|
this.label4.Name = "label4";
|
||||||
this.label4.Size = new System.Drawing.Size(42, 16);
|
this.label4.Size = new System.Drawing.Size(59, 30);
|
||||||
this.label4.TabIndex = 6;
|
this.label4.TabIndex = 6;
|
||||||
this.label4.Text = "Color:";
|
this.label4.Text = "Color:";
|
||||||
|
this.label4.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
|
||||||
//
|
//
|
||||||
// label5
|
// label5
|
||||||
//
|
//
|
||||||
this.label5.AutoSize = true;
|
this.label5.AutoSize = true;
|
||||||
|
this.label5.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||||
this.label5.Location = new System.Drawing.Point(3, 320);
|
this.label5.Location = new System.Drawing.Point(3, 320);
|
||||||
this.label5.Name = "label5";
|
this.label5.Name = "label5";
|
||||||
this.label5.Size = new System.Drawing.Size(59, 16);
|
this.label5.Size = new System.Drawing.Size(59, 30);
|
||||||
this.label5.TabIndex = 7;
|
this.label5.TabIndex = 7;
|
||||||
this.label5.Text = "Mileage:";
|
this.label5.Text = "Mileage:";
|
||||||
|
this.label5.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
|
||||||
//
|
//
|
||||||
// label6
|
// label6
|
||||||
//
|
//
|
||||||
this.label6.AutoSize = true;
|
this.label6.AutoSize = true;
|
||||||
|
this.label6.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||||
this.label6.Location = new System.Drawing.Point(3, 350);
|
this.label6.Location = new System.Drawing.Point(3, 350);
|
||||||
this.label6.Name = "label6";
|
this.label6.Name = "label6";
|
||||||
this.label6.Size = new System.Drawing.Size(41, 16);
|
this.label6.Size = new System.Drawing.Size(59, 30);
|
||||||
this.label6.TabIndex = 8;
|
this.label6.TabIndex = 8;
|
||||||
this.label6.Text = "Price:";
|
this.label6.Text = "Price:";
|
||||||
|
this.label6.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
|
||||||
//
|
//
|
||||||
// flowLayoutPanel1
|
// flowLayoutPanel1
|
||||||
//
|
//
|
||||||
@@ -222,7 +240,7 @@
|
|||||||
//
|
//
|
||||||
// nudYear
|
// nudYear
|
||||||
//
|
//
|
||||||
this.nudYear.Location = new System.Drawing.Point(68, 263);
|
this.nudYear.Location = new System.Drawing.Point(3, 3);
|
||||||
this.nudYear.Maximum = new decimal(new int[] {
|
this.nudYear.Maximum = new decimal(new int[] {
|
||||||
3000,
|
3000,
|
||||||
0,
|
0,
|
||||||
@@ -272,6 +290,44 @@
|
|||||||
this.nudPrice.ThousandsSeparator = true;
|
this.nudPrice.ThousandsSeparator = true;
|
||||||
this.nudPrice.ValueChanged += new System.EventHandler(this.nudPrice_ValueChanged);
|
this.nudPrice.ValueChanged += new System.EventHandler(this.nudPrice_ValueChanged);
|
||||||
//
|
//
|
||||||
|
// tableLayoutPanel2
|
||||||
|
//
|
||||||
|
this.tableLayoutPanel2.ColumnCount = 3;
|
||||||
|
this.tableLayoutPanel2.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 33.33333F));
|
||||||
|
this.tableLayoutPanel2.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 33.33333F));
|
||||||
|
this.tableLayoutPanel2.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 33.33333F));
|
||||||
|
this.tableLayoutPanel2.Controls.Add(this.nudYear, 0, 0);
|
||||||
|
this.tableLayoutPanel2.Controls.Add(this.lblAge, 1, 0);
|
||||||
|
this.tableLayoutPanel2.Controls.Add(this.tbxAge, 2, 0);
|
||||||
|
this.tableLayoutPanel2.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||||
|
this.tableLayoutPanel2.Location = new System.Drawing.Point(68, 263);
|
||||||
|
this.tableLayoutPanel2.Name = "tableLayoutPanel2";
|
||||||
|
this.tableLayoutPanel2.RowCount = 1;
|
||||||
|
this.tableLayoutPanel2.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F));
|
||||||
|
this.tableLayoutPanel2.Size = new System.Drawing.Size(473, 24);
|
||||||
|
this.tableLayoutPanel2.TabIndex = 10;
|
||||||
|
//
|
||||||
|
// lblAge
|
||||||
|
//
|
||||||
|
this.lblAge.AutoSize = true;
|
||||||
|
this.lblAge.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||||
|
this.lblAge.Location = new System.Drawing.Point(160, 0);
|
||||||
|
this.lblAge.Name = "lblAge";
|
||||||
|
this.lblAge.RightToLeft = System.Windows.Forms.RightToLeft.No;
|
||||||
|
this.lblAge.Size = new System.Drawing.Size(151, 24);
|
||||||
|
this.lblAge.TabIndex = 4;
|
||||||
|
this.lblAge.Text = "Age";
|
||||||
|
this.lblAge.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
|
||||||
|
//
|
||||||
|
// tbxAge
|
||||||
|
//
|
||||||
|
this.tbxAge.Enabled = false;
|
||||||
|
this.tbxAge.Location = new System.Drawing.Point(317, 3);
|
||||||
|
this.tbxAge.Name = "tbxAge";
|
||||||
|
this.tbxAge.ReadOnly = true;
|
||||||
|
this.tbxAge.Size = new System.Drawing.Size(100, 22);
|
||||||
|
this.tbxAge.TabIndex = 5;
|
||||||
|
//
|
||||||
// CarDetailsForm
|
// CarDetailsForm
|
||||||
//
|
//
|
||||||
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F);
|
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F);
|
||||||
@@ -290,6 +346,8 @@
|
|||||||
((System.ComponentModel.ISupportInitialize)(this.nudYear)).EndInit();
|
((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.PerformLayout();
|
||||||
this.ResumeLayout(false);
|
this.ResumeLayout(false);
|
||||||
this.PerformLayout();
|
this.PerformLayout();
|
||||||
|
|
||||||
@@ -315,6 +373,9 @@
|
|||||||
private System.Windows.Forms.NumericUpDown nudPrice;
|
private System.Windows.Forms.NumericUpDown nudPrice;
|
||||||
private System.Windows.Forms.PictureBox pbxCarImage;
|
private System.Windows.Forms.PictureBox pbxCarImage;
|
||||||
private System.Windows.Forms.Label lblID;
|
private System.Windows.Forms.Label lblID;
|
||||||
|
private System.Windows.Forms.TableLayoutPanel tableLayoutPanel2;
|
||||||
|
private System.Windows.Forms.Label lblAge;
|
||||||
|
private System.Windows.Forms.TextBox tbxAge;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ namespace CarManagerV3
|
|||||||
tbxColor.Text = car.Color;
|
tbxColor.Text = car.Color;
|
||||||
nudMileage.Value = car.Mileage;
|
nudMileage.Value = car.Mileage;
|
||||||
nudPrice.Value = car.Price;
|
nudPrice.Value = car.Price;
|
||||||
|
tbxAge.Text = car.AgeString;
|
||||||
pbxCarImage.Image = ImageManager.GetImage(car);
|
pbxCarImage.Image = ImageManager.GetImage(car);
|
||||||
lblID.Text = $"ID: {car.Id}";
|
lblID.Text = $"ID: {car.Id}";
|
||||||
}
|
}
|
||||||
@@ -79,9 +80,12 @@ namespace CarManagerV3
|
|||||||
|
|
||||||
private void nudYear_ValueChanged(object sender, EventArgs e)
|
private void nudYear_ValueChanged(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
Console.WriteLine("Year value changed: " + nudYear.Value);
|
|
||||||
SafeUpdate(
|
SafeUpdate(
|
||||||
() => car.Year = (int)ValueOrFormer(nudYear.Value, car.Year),
|
() =>
|
||||||
|
{
|
||||||
|
car.Year = (int)ValueOrFormer(nudYear.Value, car.Year);
|
||||||
|
tbxAge.Text = car.AgeString;
|
||||||
|
},
|
||||||
() => nudYear.Value = car.Year
|
() => nudYear.Value = car.Year
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user