diff --git a/CarManagerV3/Car.cs b/CarManagerV3/Car.cs index c4a7667..bedd414 100644 --- a/CarManagerV3/Car.cs +++ b/CarManagerV3/Car.cs @@ -19,6 +19,7 @@ namespace CarManagerV3 private int mileage; private decimal price; private int order; + private int age; public int Id { get => id; set { @@ -46,9 +47,7 @@ namespace CarManagerV3 public int Year { get => year; set { - 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; } } @@ -79,6 +78,19 @@ namespace CarManagerV3 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: Add buying price and automatic calculation of profit/loss with selling price suggestion. //TODO: Add Buying Date. diff --git a/CarManagerV3/CarDetailsForm.Designer.cs b/CarManagerV3/CarDetailsForm.Designer.cs index a2e7c2a..4fd6bbb 100644 --- a/CarManagerV3/CarDetailsForm.Designer.cs +++ b/CarManagerV3/CarDetailsForm.Designer.cs @@ -47,12 +47,16 @@ 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.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(); this.SuspendLayout(); // // tableLayoutPanel1 @@ -62,6 +66,8 @@ 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(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.label1, 0, 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.label6, 0, 6); 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.nudMileage, 1, 5); 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.Location = new System.Drawing.Point(0, 0); this.tableLayoutPanel1.Name = "tableLayoutPanel1"; @@ -106,11 +112,13 @@ // label1 // this.label1.AutoSize = true; + this.label1.Dock = System.Windows.Forms.DockStyle.Fill; this.label1.Location = new System.Drawing.Point(3, 200); 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.Text = "Make:"; + this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; // // tbxMake // @@ -125,11 +133,13 @@ // label2 // this.label2.AutoSize = true; + this.label2.Dock = System.Windows.Forms.DockStyle.Fill; this.label2.Location = new System.Drawing.Point(3, 230); 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.Text = "Model:"; + this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; // // tbxModel // @@ -144,38 +154,46 @@ // label3 // this.label3.AutoSize = true; + this.label3.Dock = System.Windows.Forms.DockStyle.Fill; this.label3.Location = new System.Drawing.Point(3, 260); 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.Text = "Year:"; + this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; // // label4 // this.label4.AutoSize = true; + this.label4.Dock = System.Windows.Forms.DockStyle.Fill; this.label4.Location = new System.Drawing.Point(3, 290); 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.Text = "Color:"; + this.label4.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; // // label5 // this.label5.AutoSize = true; + this.label5.Dock = System.Windows.Forms.DockStyle.Fill; this.label5.Location = new System.Drawing.Point(3, 320); 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.Text = "Mileage:"; + this.label5.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; // // label6 // this.label6.AutoSize = true; + this.label6.Dock = System.Windows.Forms.DockStyle.Fill; this.label6.Location = new System.Drawing.Point(3, 350); 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.Text = "Price:"; + this.label6.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; // // flowLayoutPanel1 // @@ -222,7 +240,7 @@ // // 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[] { 3000, 0, @@ -272,6 +290,44 @@ this.nudPrice.ThousandsSeparator = true; 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 // this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F); @@ -290,6 +346,8 @@ ((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(); this.ResumeLayout(false); this.PerformLayout(); @@ -315,6 +373,9 @@ private System.Windows.Forms.NumericUpDown nudPrice; private System.Windows.Forms.PictureBox pbxCarImage; private System.Windows.Forms.Label lblID; + private System.Windows.Forms.TableLayoutPanel tableLayoutPanel2; + private System.Windows.Forms.Label lblAge; + private System.Windows.Forms.TextBox tbxAge; } } diff --git a/CarManagerV3/CarDetailsForm.cs b/CarManagerV3/CarDetailsForm.cs index 5661b1b..c05e53a 100644 --- a/CarManagerV3/CarDetailsForm.cs +++ b/CarManagerV3/CarDetailsForm.cs @@ -25,6 +25,7 @@ namespace CarManagerV3 tbxColor.Text = car.Color; nudMileage.Value = car.Mileage; nudPrice.Value = car.Price; + tbxAge.Text = car.AgeString; pbxCarImage.Image = ImageManager.GetImage(car); lblID.Text = $"ID: {car.Id}"; } @@ -79,9 +80,12 @@ namespace CarManagerV3 private void nudYear_ValueChanged(object sender, EventArgs e) { - Console.WriteLine("Year value changed: " + nudYear.Value); 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 ); }