function
This commit is contained in:
@@ -18,6 +18,7 @@ namespace CarManagerV2
|
|||||||
|
|
||||||
public Car(int id, string make, string model, int year, string color, int mileage, decimal price)
|
public Car(int id, string make, string model, int year, string color, int mileage, decimal price)
|
||||||
{
|
{
|
||||||
|
this.id = id;
|
||||||
this.make = make;
|
this.make = make;
|
||||||
this.model = model;
|
this.model = model;
|
||||||
this.year = year;
|
this.year = year;
|
||||||
@@ -50,6 +51,7 @@ namespace CarManagerV2
|
|||||||
Console.WriteLine(csv);
|
Console.WriteLine(csv);
|
||||||
string[] parts = csv.Split(';');
|
string[] parts = csv.Split(';');
|
||||||
Console.WriteLine(parts.Length);
|
Console.WriteLine(parts.Length);
|
||||||
|
Console.WriteLine($"Fetched ID: {parts[0]}");
|
||||||
return new Car(int.Parse(parts[0]), parts[1], parts[2], int.Parse(parts[3]), parts[4], int.Parse(parts[5]), decimal.Parse(parts[6]));
|
return new Car(int.Parse(parts[0]), parts[1], parts[2], int.Parse(parts[3]), parts[4], int.Parse(parts[5]), decimal.Parse(parts[6]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,9 +33,23 @@ namespace CarManagerV2
|
|||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
this.Cursor = Cursors.Hand;
|
this.Cursor = Cursors.Hand;
|
||||||
|
|
||||||
|
foreach (Control ctrl in this.Controls)
|
||||||
|
{
|
||||||
|
ctrl.Click += ForwardClick;
|
||||||
|
foreach (Control inner in ctrl.Controls) // In case you have nested controls
|
||||||
|
inner.Click += ForwardClick;
|
||||||
|
}
|
||||||
|
|
||||||
this.Click += (s, e) => this.OnCardClicked();
|
this.Click += (s, e) => this.OnCardClicked();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void ForwardClick(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
// Raise your CardClicked event no matter what got clicked
|
||||||
|
CardClicked?.Invoke(this, EventArgs.Empty);
|
||||||
|
}
|
||||||
|
|
||||||
public event EventHandler CardClicked;
|
public event EventHandler CardClicked;
|
||||||
private void OnCardClicked()
|
private void OnCardClicked()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -37,38 +37,41 @@ namespace CarManagerV2
|
|||||||
|
|
||||||
private void tbxMake_TextChanged(object sender, EventArgs e)
|
private void tbxMake_TextChanged(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
this.car.Make = tbxMake.Text;
|
car.Make = tbxMake.Text;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void tbxModel_TextChanged(object sender, EventArgs e)
|
private void tbxModel_TextChanged(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
this.car.Model = tbxModel.Text;
|
car.Model = tbxModel.Text;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void nudYear_ValueChanged(object sender, EventArgs e)
|
private void nudYear_ValueChanged(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
this.car.Year = (int)nudYear.Value;
|
car.Year = (int)nudYear.Value;
|
||||||
|
Console.WriteLine(car.Year);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void tbxColor_TextChanged(object sender, EventArgs e)
|
private void tbxColor_TextChanged(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
this.car.Color = tbxColor.Text;
|
car.Color = tbxColor.Text;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void nudMileage_ValueChanged(object sender, EventArgs e)
|
private void nudMileage_ValueChanged(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
this.car.Mileage = (int)nudMileage.Value;
|
car.Mileage = (int)nudMileage.Value;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void nudPrice_ValueChanged(object sender, EventArgs e)
|
private void nudPrice_ValueChanged(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
this.car.Price = nudPrice.Value;
|
car.Price = nudPrice.Value;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void btnSave_Click(object sender, EventArgs e)
|
private void btnSave_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
// save car to cars.csv and close form
|
// save car to cars.csv and close form
|
||||||
StateManager.updateCar(this.car);
|
Console.WriteLine("Saving car: " + car.Id);
|
||||||
|
Console.WriteLine("Car year: " + car.Year);
|
||||||
|
StateManager.updateCar(car);
|
||||||
this.Close();
|
this.Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -78,7 +81,7 @@ namespace CarManagerV2
|
|||||||
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)
|
||||||
{
|
{
|
||||||
StateManager.removeCar(this.car);
|
StateManager.removeCar(car);
|
||||||
this.Close();
|
this.Close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,15 +28,17 @@ namespace CarManagerV2
|
|||||||
foreach (Car car in cars)
|
foreach (Car car in cars)
|
||||||
{
|
{
|
||||||
CarCard card = new CarCard();
|
CarCard card = new CarCard();
|
||||||
card.CarName = $"{car.Make} {car.Model}";
|
card.CarName = $"{car.Make} {car.Model} ({car.Id})";
|
||||||
card.CarDetails = $"{car.Year}, {car.Mileage} km, ${car.Price}";
|
card.CarDetails = $"{car.Year}, {car.Mileage} km, ${car.Price}";
|
||||||
card.CarImage = ImageManager.GetImage(car);
|
card.CarImage = ImageManager.GetImage(car);
|
||||||
card.CardClicked += (s, e) =>
|
card.CardClicked += (s, e) =>
|
||||||
{
|
{
|
||||||
|
Console.WriteLine($"Card clicked: {car.Id}");
|
||||||
CarDetailsForm detailsForm = new CarDetailsForm(car);
|
CarDetailsForm detailsForm = new CarDetailsForm(car);
|
||||||
detailsForm.FormClosed += (s2, e2) =>
|
detailsForm.FormClosed += (s2, e2) =>
|
||||||
{
|
{
|
||||||
// refresh cars
|
// refresh cars
|
||||||
|
Console.WriteLine("Refreshing cars...");
|
||||||
cars = SafeManager.readCars("cars.csv");
|
cars = SafeManager.readCars("cars.csv");
|
||||||
refreshCars(cars);
|
refreshCars(cars);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -40,8 +40,10 @@ namespace CarManagerV2
|
|||||||
Car existingCar = getCarById(car.Id);
|
Car existingCar = getCarById(car.Id);
|
||||||
if (existingCar != null)
|
if (existingCar != null)
|
||||||
{
|
{
|
||||||
cars.Remove(existingCar);
|
int index = cars.IndexOf(existingCar);
|
||||||
cars.Add(car);
|
cars[index] = car;
|
||||||
|
Console.WriteLine("Updated car: " + existingCar.Id);
|
||||||
|
SafeManager.saveCars("cars.csv", cars);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user