Compare commits
4 Commits
2aeee0a009
...
4404ac3c7b
| Author | SHA1 | Date | |
|---|---|---|---|
| 4404ac3c7b | |||
| c70407b40b | |||
| d733e49698 | |||
| 160352383a |
@@ -1,8 +1,4 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace CarManagerV3
|
namespace CarManagerV3
|
||||||
{
|
{
|
||||||
@@ -11,14 +7,84 @@ namespace CarManagerV3
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class Car
|
public class Car
|
||||||
{
|
{
|
||||||
public int Id;
|
private int id;
|
||||||
public string Make;
|
private string make;
|
||||||
public string Model;
|
private string model;
|
||||||
public int Year;
|
private int year;
|
||||||
public string Color;
|
private string color;
|
||||||
public int Mileage;
|
private int mileage;
|
||||||
public decimal Price;
|
private decimal price;
|
||||||
public int Order;
|
private int order;
|
||||||
|
|
||||||
|
public int Id { get => id;
|
||||||
|
set {
|
||||||
|
if (value < 0) throw new ArgumentException("Id cannot be negative.");
|
||||||
|
id = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Make { get => make;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(value)) throw new ArgumentException("Make cannot be empty.");
|
||||||
|
make = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Model { get => model;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(value)) throw new ArgumentException("Model cannot be empty.");
|
||||||
|
model = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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.");
|
||||||
|
year = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Color { get => color;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(value)) throw new ArgumentException("Color cannot be empty.");
|
||||||
|
color = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int Mileage { get => mileage;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (value < 0) throw new ArgumentException("Mileage cannot be negative.");
|
||||||
|
mileage = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public decimal Price { get => price;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (value < 0) throw new ArgumentException("Price cannot be negative.");
|
||||||
|
price = 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.
|
||||||
@@ -38,6 +104,7 @@ namespace CarManagerV3
|
|||||||
/// <param name="order">The order.</param>
|
/// <param name="order">The order.</param>
|
||||||
public Car(int id, string make, string model, int year, string color, int mileage, decimal price, int order = 0)
|
public Car(int id, string make, string model, int year, string color, int mileage, decimal price, int order = 0)
|
||||||
{
|
{
|
||||||
|
// Sets the properties using the setters to ensure validation is applied.
|
||||||
this.Id = id;
|
this.Id = id;
|
||||||
this.Make = make;
|
this.Make = make;
|
||||||
this.Model = model;
|
this.Model = model;
|
||||||
|
|||||||
80
CarManagerV3/CarDetailsForm.Designer.cs
generated
80
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
|
||||||
//
|
//
|
||||||
@@ -120,15 +128,18 @@
|
|||||||
this.tbxMake.Size = new System.Drawing.Size(473, 22);
|
this.tbxMake.Size = new System.Drawing.Size(473, 22);
|
||||||
this.tbxMake.TabIndex = 1;
|
this.tbxMake.TabIndex = 1;
|
||||||
this.tbxMake.TextChanged += new System.EventHandler(this.tbxMake_TextChanged);
|
this.tbxMake.TextChanged += new System.EventHandler(this.tbxMake_TextChanged);
|
||||||
|
this.tbxMake.Leave += new System.EventHandler(this.tbxMake_Leave);
|
||||||
//
|
//
|
||||||
// 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
|
||||||
//
|
//
|
||||||
@@ -138,42 +149,51 @@
|
|||||||
this.tbxModel.Size = new System.Drawing.Size(473, 22);
|
this.tbxModel.Size = new System.Drawing.Size(473, 22);
|
||||||
this.tbxModel.TabIndex = 2;
|
this.tbxModel.TabIndex = 2;
|
||||||
this.tbxModel.TextChanged += new System.EventHandler(this.tbxModel_TextChanged);
|
this.tbxModel.TextChanged += new System.EventHandler(this.tbxModel_TextChanged);
|
||||||
|
this.tbxModel.Leave += new System.EventHandler(this.tbxModel_Leave);
|
||||||
//
|
//
|
||||||
// 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
|
||||||
//
|
//
|
||||||
@@ -220,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,
|
||||||
@@ -239,6 +259,7 @@
|
|||||||
this.tbxColor.Size = new System.Drawing.Size(473, 22);
|
this.tbxColor.Size = new System.Drawing.Size(473, 22);
|
||||||
this.tbxColor.TabIndex = 4;
|
this.tbxColor.TabIndex = 4;
|
||||||
this.tbxColor.TextChanged += new System.EventHandler(this.tbxColor_TextChanged);
|
this.tbxColor.TextChanged += new System.EventHandler(this.tbxColor_TextChanged);
|
||||||
|
this.tbxColor.Leave += new System.EventHandler(this.tbxColor_Leave);
|
||||||
//
|
//
|
||||||
// nudMileage
|
// nudMileage
|
||||||
//
|
//
|
||||||
@@ -269,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);
|
||||||
@@ -287,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();
|
||||||
|
|
||||||
@@ -312,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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,4 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.ComponentModel;
|
|
||||||
using System.Data;
|
|
||||||
using System.Drawing;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
|
||||||
@@ -25,38 +19,93 @@ 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}";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Updates a car property safely by executing the update action and reverting it if an exception occurs.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="updateAction">The update action.</param>
|
||||||
|
/// <param name="revertAction">The action to perform when the update fails.</param>
|
||||||
|
private void SafeUpdate(Action updateAction, Action revertAction)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
updateAction();
|
||||||
|
}
|
||||||
|
catch (ArgumentException ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show(ex.Message, "Invalid Input", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
revertAction();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//private string ValueOrFormer(string newValue, string oldValue)
|
||||||
|
//{
|
||||||
|
// return string.IsNullOrWhiteSpace(newValue) ? oldValue : newValue;
|
||||||
|
//}
|
||||||
|
|
||||||
|
private T ValueOrFormer<T>(T newValue, T oldValue)
|
||||||
|
{
|
||||||
|
if (newValue is string str)
|
||||||
|
{
|
||||||
|
return string.IsNullOrWhiteSpace(str) ? oldValue : newValue;
|
||||||
|
}
|
||||||
|
return newValue;
|
||||||
|
}
|
||||||
|
|
||||||
private void tbxMake_TextChanged(object sender, EventArgs e)
|
private void tbxMake_TextChanged(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
car.Make = tbxMake.Text;
|
SafeUpdate(
|
||||||
|
() => car.Make = ValueOrFormer(tbxMake.Text, car.Make),
|
||||||
|
() => tbxMake.Text = car.Make
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void tbxModel_TextChanged(object sender, EventArgs e)
|
private void tbxModel_TextChanged(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
car.Model = tbxModel.Text;
|
SafeUpdate(
|
||||||
|
() => car.Model = ValueOrFormer(tbxModel.Text, car.Model),
|
||||||
|
() => tbxModel.Text = car.Model
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void nudYear_ValueChanged(object sender, EventArgs e)
|
private void nudYear_ValueChanged(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
car.Year = (int)nudYear.Value;
|
SafeUpdate(
|
||||||
|
() =>
|
||||||
|
{
|
||||||
|
car.Year = (int)ValueOrFormer(nudYear.Value, car.Year);
|
||||||
|
tbxAge.Text = car.AgeString;
|
||||||
|
},
|
||||||
|
() => nudYear.Value = car.Year
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void tbxColor_TextChanged(object sender, EventArgs e)
|
private void tbxColor_TextChanged(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
car.Color = tbxColor.Text;
|
SafeUpdate(
|
||||||
|
() => car.Color = ValueOrFormer(tbxColor.Text, car.Color),
|
||||||
|
() => tbxColor.Text = car.Color
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void nudMileage_ValueChanged(object sender, EventArgs e)
|
private void nudMileage_ValueChanged(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
car.Mileage = (int)nudMileage.Value;
|
SafeUpdate(
|
||||||
|
() => car.Mileage = (int)nudMileage.Value,
|
||||||
|
() => nudMileage.Value = car.Mileage
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void nudPrice_ValueChanged(object sender, EventArgs e)
|
private void nudPrice_ValueChanged(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
car.Price = nudPrice.Value;
|
SafeUpdate(
|
||||||
|
() => car.Price = nudPrice.Value,
|
||||||
|
() => nudPrice.Value = car.Price
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async void btnSave_Click(object sender, EventArgs e)
|
private async void btnSave_Click(object sender, EventArgs e)
|
||||||
@@ -113,5 +162,22 @@ namespace CarManagerV3
|
|||||||
}
|
}
|
||||||
return base.ProcessCmdKey(ref msg, keyData);
|
return base.ProcessCmdKey(ref msg, keyData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void tbxMake_Leave(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
tbxMake.Text = ValueOrFormer(tbxMake.Text, car.Make);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void tbxModel_Leave(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
tbxModel.Text = ValueOrFormer(tbxModel.Text, car.Model);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void tbxColor_Leave(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
tbxColor.Text = ValueOrFormer(tbxColor.Text, car.Color);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Linq;
|
|
||||||
using System.Linq.Expressions;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace CarManagerV3
|
namespace CarManagerV3
|
||||||
{
|
{
|
||||||
@@ -63,7 +58,15 @@ namespace CarManagerV3
|
|||||||
{
|
{
|
||||||
Console.Error.WriteLine($"Error loading image: {ex.Message}");
|
Console.Error.WriteLine($"Error loading image: {ex.Message}");
|
||||||
}
|
}
|
||||||
return Image.FromFile("images/no_image_available.png");
|
try
|
||||||
|
{
|
||||||
|
return Image.FromFile("images/no_image_available.png");
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Console.Error.WriteLine($"Error loading fallback image: {ex.Message}");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
21
CarManagerV3/MainForm.Designer.cs
generated
21
CarManagerV3/MainForm.Designer.cs
generated
@@ -70,7 +70,7 @@
|
|||||||
this.flpCars.AutoScroll = true;
|
this.flpCars.AutoScroll = true;
|
||||||
this.flpCars.AutoScrollMargin = new System.Drawing.Size(0, 200);
|
this.flpCars.AutoScrollMargin = new System.Drawing.Size(0, 200);
|
||||||
this.flpCars.Dock = System.Windows.Forms.DockStyle.Fill;
|
this.flpCars.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||||
this.flpCars.Location = new System.Drawing.Point(3, 67);
|
this.flpCars.Location = new System.Drawing.Point(3, 71);
|
||||||
this.flpCars.Name = "flpCars";
|
this.flpCars.Name = "flpCars";
|
||||||
this.flpCars.Size = new System.Drawing.Size(796, 412);
|
this.flpCars.Size = new System.Drawing.Size(796, 412);
|
||||||
this.flpCars.TabIndex = 1;
|
this.flpCars.TabIndex = 1;
|
||||||
@@ -83,7 +83,7 @@
|
|||||||
this.tableLayoutPanel2.Controls.Add(this.tbxSearch, 0, 0);
|
this.tableLayoutPanel2.Controls.Add(this.tbxSearch, 0, 0);
|
||||||
this.tableLayoutPanel2.Controls.Add(this.btnNewCar, 1, 0);
|
this.tableLayoutPanel2.Controls.Add(this.btnNewCar, 1, 0);
|
||||||
this.tableLayoutPanel2.Dock = System.Windows.Forms.DockStyle.Fill;
|
this.tableLayoutPanel2.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||||
this.tableLayoutPanel2.Location = new System.Drawing.Point(3, 27);
|
this.tableLayoutPanel2.Location = new System.Drawing.Point(3, 31);
|
||||||
this.tableLayoutPanel2.Name = "tableLayoutPanel2";
|
this.tableLayoutPanel2.Name = "tableLayoutPanel2";
|
||||||
this.tableLayoutPanel2.RowCount = 1;
|
this.tableLayoutPanel2.RowCount = 1;
|
||||||
this.tableLayoutPanel2.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F));
|
this.tableLayoutPanel2.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F));
|
||||||
@@ -112,11 +112,12 @@
|
|||||||
//
|
//
|
||||||
// menuStrip1
|
// menuStrip1
|
||||||
//
|
//
|
||||||
|
this.menuStrip1.ImageScalingSize = new System.Drawing.Size(20, 20);
|
||||||
this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||||
this.fileToolStripMenuItem});
|
this.fileToolStripMenuItem});
|
||||||
this.menuStrip1.Location = new System.Drawing.Point(0, 0);
|
this.menuStrip1.Location = new System.Drawing.Point(0, 0);
|
||||||
this.menuStrip1.Name = "menuStrip1";
|
this.menuStrip1.Name = "menuStrip1";
|
||||||
this.menuStrip1.Size = new System.Drawing.Size(802, 24);
|
this.menuStrip1.Size = new System.Drawing.Size(802, 28);
|
||||||
this.menuStrip1.TabIndex = 3;
|
this.menuStrip1.TabIndex = 3;
|
||||||
this.menuStrip1.Text = "menuStrip1";
|
this.menuStrip1.Text = "menuStrip1";
|
||||||
//
|
//
|
||||||
@@ -130,48 +131,48 @@
|
|||||||
this.recentFilesToolStripMenuItem,
|
this.recentFilesToolStripMenuItem,
|
||||||
this.revealInFileExplorerToolStripMenuItem});
|
this.revealInFileExplorerToolStripMenuItem});
|
||||||
this.fileToolStripMenuItem.Name = "fileToolStripMenuItem";
|
this.fileToolStripMenuItem.Name = "fileToolStripMenuItem";
|
||||||
this.fileToolStripMenuItem.Size = new System.Drawing.Size(37, 20);
|
this.fileToolStripMenuItem.Size = new System.Drawing.Size(46, 24);
|
||||||
this.fileToolStripMenuItem.Text = "File";
|
this.fileToolStripMenuItem.Text = "File";
|
||||||
//
|
//
|
||||||
// openToolStripMenuItem
|
// openToolStripMenuItem
|
||||||
//
|
//
|
||||||
this.openToolStripMenuItem.Name = "openToolStripMenuItem";
|
this.openToolStripMenuItem.Name = "openToolStripMenuItem";
|
||||||
this.openToolStripMenuItem.Size = new System.Drawing.Size(187, 22);
|
this.openToolStripMenuItem.Size = new System.Drawing.Size(238, 26);
|
||||||
this.openToolStripMenuItem.Text = "Open";
|
this.openToolStripMenuItem.Text = "Open";
|
||||||
this.openToolStripMenuItem.Click += new System.EventHandler(this.openToolStripMenuItem_Click);
|
this.openToolStripMenuItem.Click += new System.EventHandler(this.openToolStripMenuItem_Click);
|
||||||
//
|
//
|
||||||
// saveToolStripMenuItem
|
// saveToolStripMenuItem
|
||||||
//
|
//
|
||||||
this.saveToolStripMenuItem.Name = "saveToolStripMenuItem";
|
this.saveToolStripMenuItem.Name = "saveToolStripMenuItem";
|
||||||
this.saveToolStripMenuItem.Size = new System.Drawing.Size(187, 22);
|
this.saveToolStripMenuItem.Size = new System.Drawing.Size(238, 26);
|
||||||
this.saveToolStripMenuItem.Text = "Save";
|
this.saveToolStripMenuItem.Text = "Save";
|
||||||
this.saveToolStripMenuItem.Click += new System.EventHandler(this.saveToolStripMenuItem_Click);
|
this.saveToolStripMenuItem.Click += new System.EventHandler(this.saveToolStripMenuItem_Click);
|
||||||
//
|
//
|
||||||
// saveAsToolStripMenuItem
|
// saveAsToolStripMenuItem
|
||||||
//
|
//
|
||||||
this.saveAsToolStripMenuItem.Name = "saveAsToolStripMenuItem";
|
this.saveAsToolStripMenuItem.Name = "saveAsToolStripMenuItem";
|
||||||
this.saveAsToolStripMenuItem.Size = new System.Drawing.Size(187, 22);
|
this.saveAsToolStripMenuItem.Size = new System.Drawing.Size(238, 26);
|
||||||
this.saveAsToolStripMenuItem.Text = "Save as";
|
this.saveAsToolStripMenuItem.Text = "Save as";
|
||||||
this.saveAsToolStripMenuItem.Click += new System.EventHandler(this.saveAsToolStripMenuItem_Click);
|
this.saveAsToolStripMenuItem.Click += new System.EventHandler(this.saveAsToolStripMenuItem_Click);
|
||||||
//
|
//
|
||||||
// importToolStripMenuItem
|
// importToolStripMenuItem
|
||||||
//
|
//
|
||||||
this.importToolStripMenuItem.Name = "importToolStripMenuItem";
|
this.importToolStripMenuItem.Name = "importToolStripMenuItem";
|
||||||
this.importToolStripMenuItem.Size = new System.Drawing.Size(187, 22);
|
this.importToolStripMenuItem.Size = new System.Drawing.Size(238, 26);
|
||||||
this.importToolStripMenuItem.Text = "Import";
|
this.importToolStripMenuItem.Text = "Import";
|
||||||
this.importToolStripMenuItem.Click += new System.EventHandler(this.importToolStripMenuItem_Click);
|
this.importToolStripMenuItem.Click += new System.EventHandler(this.importToolStripMenuItem_Click);
|
||||||
//
|
//
|
||||||
// recentFilesToolStripMenuItem
|
// recentFilesToolStripMenuItem
|
||||||
//
|
//
|
||||||
this.recentFilesToolStripMenuItem.Name = "recentFilesToolStripMenuItem";
|
this.recentFilesToolStripMenuItem.Name = "recentFilesToolStripMenuItem";
|
||||||
this.recentFilesToolStripMenuItem.Size = new System.Drawing.Size(187, 22);
|
this.recentFilesToolStripMenuItem.Size = new System.Drawing.Size(238, 26);
|
||||||
this.recentFilesToolStripMenuItem.Text = "Recent Files";
|
this.recentFilesToolStripMenuItem.Text = "Recent Files";
|
||||||
this.recentFilesToolStripMenuItem.Click += new System.EventHandler(this.recentFilesToolStripMenuItem_Click);
|
this.recentFilesToolStripMenuItem.Click += new System.EventHandler(this.recentFilesToolStripMenuItem_Click);
|
||||||
//
|
//
|
||||||
// revealInFileExplorerToolStripMenuItem
|
// revealInFileExplorerToolStripMenuItem
|
||||||
//
|
//
|
||||||
this.revealInFileExplorerToolStripMenuItem.Name = "revealInFileExplorerToolStripMenuItem";
|
this.revealInFileExplorerToolStripMenuItem.Name = "revealInFileExplorerToolStripMenuItem";
|
||||||
this.revealInFileExplorerToolStripMenuItem.Size = new System.Drawing.Size(187, 22);
|
this.revealInFileExplorerToolStripMenuItem.Size = new System.Drawing.Size(238, 26);
|
||||||
this.revealInFileExplorerToolStripMenuItem.Text = "Reveal in File Explorer";
|
this.revealInFileExplorerToolStripMenuItem.Text = "Reveal in File Explorer";
|
||||||
this.revealInFileExplorerToolStripMenuItem.Click += new System.EventHandler(this.revealInFileExplorerToolStripMenuItem_Click);
|
this.revealInFileExplorerToolStripMenuItem.Click += new System.EventHandler(this.revealInFileExplorerToolStripMenuItem_Click);
|
||||||
//
|
//
|
||||||
|
|||||||
@@ -1,10 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel;
|
|
||||||
using System.Data;
|
using System.Data;
|
||||||
using System.Drawing;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,4 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.ComponentModel;
|
|
||||||
using System.Data;
|
|
||||||
using System.Drawing;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
|
||||||
namespace CarManagerV3
|
namespace CarManagerV3
|
||||||
|
|||||||
@@ -1,7 +1,4 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
|
||||||
namespace CarManagerV3
|
namespace CarManagerV3
|
||||||
|
|||||||
@@ -2,8 +2,6 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace CarManagerV3
|
namespace CarManagerV3
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user