62 lines
1.8 KiB
C#
62 lines
1.8 KiB
C#
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;
|
|
|
|
namespace CarManagerV2
|
|
{
|
|
public partial class MainForm : Form
|
|
{
|
|
List<Car> cars = new List<Car>();
|
|
|
|
public MainForm()
|
|
{
|
|
InitializeComponent();
|
|
SafeManager.initializeFile("cars.csv");
|
|
cars = SafeManager.readCars("cars.csv");
|
|
refreshCars(cars);
|
|
}
|
|
|
|
private void refreshCars(List<Car> cars)
|
|
{
|
|
flpCars.Controls.Clear();
|
|
foreach (Car car in cars)
|
|
{
|
|
CarCard card = new CarCard();
|
|
card.CarName = $"{car.Make} {car.Model} ({car.Id})";
|
|
card.CarDetails = $"{car.Year}, {car.Mileage} km, ${car.Price}";
|
|
card.CarImage = ImageManager.GetImage(car);
|
|
card.CardClicked += (s, e) =>
|
|
{
|
|
Console.WriteLine($"Card clicked: {car.Id}");
|
|
CarDetailsForm detailsForm = new CarDetailsForm(car);
|
|
detailsForm.FormClosed += (s2, e2) =>
|
|
{
|
|
// refresh cars
|
|
Console.WriteLine("Refreshing cars...");
|
|
cars = SafeManager.readCars("cars.csv");
|
|
refreshCars(cars);
|
|
};
|
|
detailsForm.ShowDialog();
|
|
};
|
|
flpCars.Controls.Add(card);
|
|
}
|
|
}
|
|
|
|
private void CarDetailsForm_Load(object sender, EventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
private void MainForm_Load(object sender, EventArgs e)
|
|
{
|
|
|
|
}
|
|
}
|
|
}
|