initial
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -360,4 +360,5 @@ MigrationBackup/
|
|||||||
.ionide/
|
.ionide/
|
||||||
|
|
||||||
# Fody - auto-generated XML schema
|
# Fody - auto-generated XML schema
|
||||||
FodyWeavers.xsd
|
FodyWeavers.xsd
|
||||||
|
IAF42_Kaulmann_CarmanagerV2.zip
|
||||||
|
|||||||
@@ -41,18 +41,18 @@ namespace CarManagerV2
|
|||||||
return $"{make} {model} ({year})";
|
return $"{make} {model} ({year})";
|
||||||
}
|
}
|
||||||
|
|
||||||
public string toCsvString()
|
public string ToCsvString()
|
||||||
{
|
{
|
||||||
return $"{id};{make};{model};{year};{color};{mileage};{price}";
|
return $"{id};{make};{model};{year};{color};{mileage};{price}";
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Car fromCsvString(string csv)
|
public static Car FromCsvString(string csv)
|
||||||
{
|
{
|
||||||
string[] parts = csv.Split(';');
|
string[] parts = csv.Split(';');
|
||||||
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]));
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool isChanged(Car other)
|
public bool IsChanged(Car other)
|
||||||
{
|
{
|
||||||
return make != other.make || model != other.model || year != other.year || color != other.color || mileage != other.mileage || price != other.price;
|
return make != other.make || model != other.model || year != other.year || color != other.color || mileage != other.mileage || price != other.price;
|
||||||
}
|
}
|
||||||
|
|||||||
87
CarManagerV2/CarCard.Designer.cs
generated
87
CarManagerV2/CarCard.Designer.cs
generated
@@ -29,57 +29,77 @@
|
|||||||
private void InitializeComponent()
|
private void InitializeComponent()
|
||||||
{
|
{
|
||||||
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(CarCard));
|
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(CarCard));
|
||||||
this.pbxCar = new System.Windows.Forms.PictureBox();
|
this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel();
|
||||||
this.lblCarName = new System.Windows.Forms.Label();
|
|
||||||
this.lblCarDetails = new System.Windows.Forms.Label();
|
this.lblCarDetails = new System.Windows.Forms.Label();
|
||||||
|
this.lblCarName = new System.Windows.Forms.Label();
|
||||||
|
this.pbxCar = new System.Windows.Forms.PictureBox();
|
||||||
|
this.tableLayoutPanel1.SuspendLayout();
|
||||||
((System.ComponentModel.ISupportInitialize)(this.pbxCar)).BeginInit();
|
((System.ComponentModel.ISupportInitialize)(this.pbxCar)).BeginInit();
|
||||||
this.SuspendLayout();
|
this.SuspendLayout();
|
||||||
//
|
//
|
||||||
// pbxCar
|
// tableLayoutPanel1
|
||||||
//
|
//
|
||||||
this.pbxCar.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
|
this.tableLayoutPanel1.AutoSize = true;
|
||||||
| System.Windows.Forms.AnchorStyles.Left)
|
this.tableLayoutPanel1.ColumnCount = 1;
|
||||||
| System.Windows.Forms.AnchorStyles.Right)));
|
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F));
|
||||||
this.pbxCar.Image = ((System.Drawing.Image)(resources.GetObject("pbxCar.Image")));
|
this.tableLayoutPanel1.Controls.Add(this.lblCarDetails, 0, 2);
|
||||||
this.pbxCar.ImageLocation = "";
|
this.tableLayoutPanel1.Controls.Add(this.lblCarName, 0, 1);
|
||||||
this.pbxCar.Location = new System.Drawing.Point(3, 3);
|
this.tableLayoutPanel1.Controls.Add(this.pbxCar, 0, 0);
|
||||||
this.pbxCar.Name = "pbxCar";
|
this.tableLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||||
this.pbxCar.Size = new System.Drawing.Size(204, 130);
|
this.tableLayoutPanel1.Location = new System.Drawing.Point(0, 0);
|
||||||
this.pbxCar.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
|
this.tableLayoutPanel1.MaximumSize = new System.Drawing.Size(210, 0);
|
||||||
this.pbxCar.TabIndex = 0;
|
this.tableLayoutPanel1.Name = "tableLayoutPanel1";
|
||||||
this.pbxCar.TabStop = false;
|
this.tableLayoutPanel1.RowCount = 3;
|
||||||
//
|
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 130F));
|
||||||
// lblCarName
|
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle());
|
||||||
//
|
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle());
|
||||||
this.lblCarName.AutoSize = true;
|
this.tableLayoutPanel1.Size = new System.Drawing.Size(210, 200);
|
||||||
this.lblCarName.Font = new System.Drawing.Font("Arial", 13.8F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
this.tableLayoutPanel1.TabIndex = 0;
|
||||||
this.lblCarName.Location = new System.Drawing.Point(3, 136);
|
|
||||||
this.lblCarName.Name = "lblCarName";
|
|
||||||
this.lblCarName.Size = new System.Drawing.Size(148, 27);
|
|
||||||
this.lblCarName.TabIndex = 1;
|
|
||||||
this.lblCarName.Text = "Skoda Fabia";
|
|
||||||
//
|
//
|
||||||
// lblCarDetails
|
// lblCarDetails
|
||||||
//
|
//
|
||||||
this.lblCarDetails.AutoSize = true;
|
this.lblCarDetails.AutoSize = true;
|
||||||
this.lblCarDetails.Location = new System.Drawing.Point(5, 163);
|
this.lblCarDetails.Location = new System.Drawing.Point(3, 184);
|
||||||
this.lblCarDetails.Name = "lblCarDetails";
|
this.lblCarDetails.Name = "lblCarDetails";
|
||||||
this.lblCarDetails.Size = new System.Drawing.Size(101, 16);
|
this.lblCarDetails.Size = new System.Drawing.Size(101, 16);
|
||||||
this.lblCarDetails.TabIndex = 2;
|
this.lblCarDetails.TabIndex = 5;
|
||||||
this.lblCarDetails.Text = "2009 - 13.000km";
|
this.lblCarDetails.Text = "2009 - 13.000km";
|
||||||
//
|
//
|
||||||
|
// lblCarName
|
||||||
|
//
|
||||||
|
this.lblCarName.AutoSize = true;
|
||||||
|
this.lblCarName.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||||
|
this.lblCarName.Font = new System.Drawing.Font("Arial", 13.8F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
||||||
|
this.lblCarName.Location = new System.Drawing.Point(3, 130);
|
||||||
|
this.lblCarName.Name = "lblCarName";
|
||||||
|
this.lblCarName.Size = new System.Drawing.Size(204, 54);
|
||||||
|
this.lblCarName.TabIndex = 4;
|
||||||
|
this.lblCarName.Text = "Skoda Fabia fdsdfsdfsdfsdf";
|
||||||
|
this.lblCarName.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
|
||||||
|
//
|
||||||
|
// pbxCar
|
||||||
|
//
|
||||||
|
this.pbxCar.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||||
|
this.pbxCar.Image = ((System.Drawing.Image)(resources.GetObject("pbxCar.Image")));
|
||||||
|
this.pbxCar.ImageLocation = "";
|
||||||
|
this.pbxCar.Location = new System.Drawing.Point(3, 3);
|
||||||
|
this.pbxCar.Name = "pbxCar";
|
||||||
|
this.pbxCar.Size = new System.Drawing.Size(204, 124);
|
||||||
|
this.pbxCar.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
|
||||||
|
this.pbxCar.TabIndex = 3;
|
||||||
|
this.pbxCar.TabStop = false;
|
||||||
|
//
|
||||||
// CarCard
|
// CarCard
|
||||||
//
|
//
|
||||||
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F);
|
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F);
|
||||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
this.AutoSize = true;
|
this.AutoSize = true;
|
||||||
this.BackColor = System.Drawing.SystemColors.Control;
|
this.BackColor = System.Drawing.SystemColors.Control;
|
||||||
this.Controls.Add(this.lblCarDetails);
|
this.Controls.Add(this.tableLayoutPanel1);
|
||||||
this.Controls.Add(this.lblCarName);
|
|
||||||
this.Controls.Add(this.pbxCar);
|
|
||||||
this.Name = "CarCard";
|
this.Name = "CarCard";
|
||||||
this.Size = new System.Drawing.Size(210, 192);
|
this.Size = new System.Drawing.Size(210, 200);
|
||||||
this.Load += new System.EventHandler(this.CarCard_Load);
|
this.tableLayoutPanel1.ResumeLayout(false);
|
||||||
|
this.tableLayoutPanel1.PerformLayout();
|
||||||
((System.ComponentModel.ISupportInitialize)(this.pbxCar)).EndInit();
|
((System.ComponentModel.ISupportInitialize)(this.pbxCar)).EndInit();
|
||||||
this.ResumeLayout(false);
|
this.ResumeLayout(false);
|
||||||
this.PerformLayout();
|
this.PerformLayout();
|
||||||
@@ -88,8 +108,9 @@
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
private System.Windows.Forms.PictureBox pbxCar;
|
private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1;
|
||||||
private System.Windows.Forms.Label lblCarName;
|
|
||||||
private System.Windows.Forms.Label lblCarDetails;
|
private System.Windows.Forms.Label lblCarDetails;
|
||||||
|
private System.Windows.Forms.Label lblCarName;
|
||||||
|
private System.Windows.Forms.PictureBox pbxCar;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -58,10 +58,5 @@ namespace CarManagerV2
|
|||||||
this.CardClicked(this, EventArgs.Empty);
|
this.CardClicked(this, EventArgs.Empty);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void CarCard_Load(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
21
CarManagerV2/CarDetailsForm.Designer.cs
generated
21
CarManagerV2/CarDetailsForm.Designer.cs
generated
@@ -42,11 +42,11 @@
|
|||||||
this.flowLayoutPanel1 = new System.Windows.Forms.FlowLayoutPanel();
|
this.flowLayoutPanel1 = new System.Windows.Forms.FlowLayoutPanel();
|
||||||
this.btnSave = new System.Windows.Forms.Button();
|
this.btnSave = new System.Windows.Forms.Button();
|
||||||
this.btnDelete = new System.Windows.Forms.Button();
|
this.btnDelete = new System.Windows.Forms.Button();
|
||||||
|
this.lblID = new System.Windows.Forms.Label();
|
||||||
this.nudYear = new System.Windows.Forms.NumericUpDown();
|
this.nudYear = new System.Windows.Forms.NumericUpDown();
|
||||||
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.lblID = new System.Windows.Forms.Label();
|
|
||||||
this.tableLayoutPanel1.SuspendLayout();
|
this.tableLayoutPanel1.SuspendLayout();
|
||||||
((System.ComponentModel.ISupportInitialize)(this.pbxCarImage)).BeginInit();
|
((System.ComponentModel.ISupportInitialize)(this.pbxCarImage)).BeginInit();
|
||||||
this.flowLayoutPanel1.SuspendLayout();
|
this.flowLayoutPanel1.SuspendLayout();
|
||||||
@@ -209,6 +209,15 @@
|
|||||||
this.btnDelete.UseVisualStyleBackColor = true;
|
this.btnDelete.UseVisualStyleBackColor = true;
|
||||||
this.btnDelete.Click += new System.EventHandler(this.btnDelete_Click);
|
this.btnDelete.Click += new System.EventHandler(this.btnDelete_Click);
|
||||||
//
|
//
|
||||||
|
// lblID
|
||||||
|
//
|
||||||
|
this.lblID.AutoSize = true;
|
||||||
|
this.lblID.Location = new System.Drawing.Point(343, 5);
|
||||||
|
this.lblID.Name = "lblID";
|
||||||
|
this.lblID.Size = new System.Drawing.Size(20, 16);
|
||||||
|
this.lblID.TabIndex = 2;
|
||||||
|
this.lblID.Text = "ID";
|
||||||
|
//
|
||||||
// nudYear
|
// nudYear
|
||||||
//
|
//
|
||||||
this.nudYear.Location = new System.Drawing.Point(68, 263);
|
this.nudYear.Location = new System.Drawing.Point(68, 263);
|
||||||
@@ -260,15 +269,6 @@
|
|||||||
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);
|
||||||
//
|
//
|
||||||
// lblID
|
|
||||||
//
|
|
||||||
this.lblID.AutoSize = true;
|
|
||||||
this.lblID.Location = new System.Drawing.Point(343, 5);
|
|
||||||
this.lblID.Name = "lblID";
|
|
||||||
this.lblID.Size = new System.Drawing.Size(20, 16);
|
|
||||||
this.lblID.TabIndex = 2;
|
|
||||||
this.lblID.Text = "ID";
|
|
||||||
//
|
|
||||||
// CarDetailsForm
|
// CarDetailsForm
|
||||||
//
|
//
|
||||||
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F);
|
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F);
|
||||||
@@ -279,7 +279,6 @@
|
|||||||
this.MaximizeBox = false;
|
this.MaximizeBox = false;
|
||||||
this.Name = "CarDetailsForm";
|
this.Name = "CarDetailsForm";
|
||||||
this.Text = "Details";
|
this.Text = "Details";
|
||||||
this.Load += new System.EventHandler(this.Form1_Load);
|
|
||||||
this.tableLayoutPanel1.ResumeLayout(false);
|
this.tableLayoutPanel1.ResumeLayout(false);
|
||||||
this.tableLayoutPanel1.PerformLayout();
|
this.tableLayoutPanel1.PerformLayout();
|
||||||
((System.ComponentModel.ISupportInitialize)(this.pbxCarImage)).EndInit();
|
((System.ComponentModel.ISupportInitialize)(this.pbxCarImage)).EndInit();
|
||||||
|
|||||||
@@ -29,11 +29,6 @@ namespace CarManagerV2
|
|||||||
lblID.Text = $"ID: {car.Id}";
|
lblID.Text = $"ID: {car.Id}";
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Form1_Load(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private void tbxMake_TextChanged(object sender, EventArgs e)
|
private void tbxMake_TextChanged(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
car.Make = tbxMake.Text;
|
car.Make = tbxMake.Text;
|
||||||
@@ -71,7 +66,7 @@ namespace CarManagerV2
|
|||||||
var msgbox = new PleaseWait();
|
var msgbox = new PleaseWait();
|
||||||
msgbox.Show();
|
msgbox.Show();
|
||||||
Application.DoEvents();
|
Application.DoEvents();
|
||||||
StateManager.updateCar(car);
|
StateManager.UpdateCar(car);
|
||||||
Image fooimg = ImageManager.GetImage(car);
|
Image fooimg = ImageManager.GetImage(car);
|
||||||
msgbox.Close();
|
msgbox.Close();
|
||||||
this.Close();
|
this.Close();
|
||||||
@@ -85,7 +80,7 @@ namespace CarManagerV2
|
|||||||
if (result == DialogResult.Yes)
|
if (result == DialogResult.Yes)
|
||||||
{
|
{
|
||||||
Console.WriteLine("Deleting car: " + car.Id);
|
Console.WriteLine("Deleting car: " + car.Id);
|
||||||
StateManager.removeCar(car);
|
StateManager.RemoveCar(car);
|
||||||
this.Close();
|
this.Close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ namespace CarManagerV2
|
|||||||
internal class ImageManager
|
internal class ImageManager
|
||||||
{
|
{
|
||||||
|
|
||||||
public static void initializeImageFolder()
|
public static void InitializeImageFolder()
|
||||||
{
|
{
|
||||||
string path = "images";
|
string path = "images";
|
||||||
if (!System.IO.Directory.Exists(path))
|
if (!System.IO.Directory.Exists(path))
|
||||||
@@ -19,7 +19,7 @@ namespace CarManagerV2
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string getImagePath(Car car)
|
public static string GetImagePath(Car car)
|
||||||
{
|
{
|
||||||
string basePath = "images/";
|
string basePath = "images/";
|
||||||
string fileName = $"{car.Make}_{car.Model}_{car.Year}_{car.Color}.png";
|
string fileName = $"{car.Make}_{car.Model}_{car.Year}_{car.Color}.png";
|
||||||
@@ -28,9 +28,9 @@ namespace CarManagerV2
|
|||||||
|
|
||||||
public static Image GetImage(Car car)
|
public static Image GetImage(Car car)
|
||||||
{
|
{
|
||||||
initializeImageFolder();
|
InitializeImageFolder();
|
||||||
fetchImage(car);
|
FetchImage(car);
|
||||||
string path = getImagePath(car);
|
string path = GetImagePath(car);
|
||||||
// does image exist?
|
// does image exist?
|
||||||
if (System.IO.File.Exists(path))
|
if (System.IO.File.Exists(path))
|
||||||
{
|
{
|
||||||
@@ -43,13 +43,13 @@ namespace CarManagerV2
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void fetchImage(Car car)
|
public static void FetchImage(Car car)
|
||||||
{
|
{
|
||||||
// Fetch the image from https://cdn.imagin.studio/getimage and save it to images/Make_Model_Year.webp
|
// Fetch the image from https://cdn.imagin.studio/getimage and save it to images/Make_Model_Year.webp
|
||||||
// use params like this: ?customer=hrjavascript-mastery&zoomType=fullscreen&make={make}&modelFamily={model}&modelYear={year}&angle=front&paintDescription={color}&fileType=png
|
// use params like this: ?customer=hrjavascript-mastery&zoomType=fullscreen&make={make}&modelFamily={model}&modelYear={year}&angle=front&paintDescription={color}&fileType=png
|
||||||
|
|
||||||
// check if the image already exists
|
// check if the image already exists
|
||||||
string path = getImagePath(car);
|
string path = GetImagePath(car);
|
||||||
if (System.IO.File.Exists(path))
|
if (System.IO.File.Exists(path))
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
|
|||||||
2
CarManagerV2/MainForm.Designer.cs
generated
2
CarManagerV2/MainForm.Designer.cs
generated
@@ -52,7 +52,6 @@
|
|||||||
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle());
|
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle());
|
||||||
this.tableLayoutPanel1.Size = new System.Drawing.Size(800, 450);
|
this.tableLayoutPanel1.Size = new System.Drawing.Size(800, 450);
|
||||||
this.tableLayoutPanel1.TabIndex = 0;
|
this.tableLayoutPanel1.TabIndex = 0;
|
||||||
this.tableLayoutPanel1.Paint += new System.Windows.Forms.PaintEventHandler(this.tableLayoutPanel1_Paint);
|
|
||||||
//
|
//
|
||||||
// flpCars
|
// flpCars
|
||||||
//
|
//
|
||||||
@@ -109,7 +108,6 @@
|
|||||||
this.MinimumSize = new System.Drawing.Size(818, 497);
|
this.MinimumSize = new System.Drawing.Size(818, 497);
|
||||||
this.Name = "MainForm";
|
this.Name = "MainForm";
|
||||||
this.Text = "Carmanager 2";
|
this.Text = "Carmanager 2";
|
||||||
this.Load += new System.EventHandler(this.MainForm_Load);
|
|
||||||
this.tableLayoutPanel1.ResumeLayout(false);
|
this.tableLayoutPanel1.ResumeLayout(false);
|
||||||
this.tableLayoutPanel2.ResumeLayout(false);
|
this.tableLayoutPanel2.ResumeLayout(false);
|
||||||
this.tableLayoutPanel2.PerformLayout();
|
this.tableLayoutPanel2.PerformLayout();
|
||||||
|
|||||||
@@ -17,8 +17,8 @@ namespace CarManagerV2
|
|||||||
public MainForm()
|
public MainForm()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
SafeManager.initializeFile("cars.csv");
|
SafeManager.InitializeFile("cars.csv");
|
||||||
List<Car> _cars = SafeManager.readCars("cars.csv");
|
List<Car> _cars = SafeManager.ReadCars("cars.csv");
|
||||||
refreshCars(_cars);
|
refreshCars(_cars);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,7 +97,7 @@ namespace CarManagerV2
|
|||||||
// refresh cars
|
// refresh cars
|
||||||
Application.DoEvents();
|
Application.DoEvents();
|
||||||
Console.WriteLine("Refreshing cars...");
|
Console.WriteLine("Refreshing cars...");
|
||||||
List<Car> __cars = SafeManager.readCars("cars.csv");
|
List<Car> __cars = SafeManager.ReadCars("cars.csv");
|
||||||
refreshCars(__cars);
|
refreshCars(__cars);
|
||||||
};
|
};
|
||||||
detailsForm.ShowDialog();
|
detailsForm.ShowDialog();
|
||||||
@@ -106,30 +106,16 @@ namespace CarManagerV2
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void CarDetailsForm_Load(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private void MainForm_Load(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private void tableLayoutPanel1_Paint(object sender, PaintEventArgs e)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private void btnNewCar_Click(object sender, EventArgs e)
|
private void btnNewCar_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
Car foocar = StateManager.createCar("New", "Car", 2020, "White", 0, 20000);
|
Car foocar = StateManager.CreateCar("New", "Car", 2020, "White", 0, 20000);
|
||||||
CarDetailsForm detailsForm = new CarDetailsForm(foocar);
|
CarDetailsForm detailsForm = new CarDetailsForm(foocar);
|
||||||
detailsForm.FormClosed += (s2, e2) =>
|
detailsForm.FormClosed += (s2, e2) =>
|
||||||
{
|
{
|
||||||
// refresh cars
|
// refresh cars
|
||||||
Console.WriteLine("Refreshing cars...");
|
Console.WriteLine("Refreshing cars...");
|
||||||
cars = SafeManager.readCars("cars.csv");
|
cars = SafeManager.ReadCars("cars.csv");
|
||||||
refreshCars(cars);
|
refreshCars(cars);
|
||||||
};
|
};
|
||||||
detailsForm.ShowDialog();
|
detailsForm.ShowDialog();
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ namespace CarManagerV2
|
|||||||
{
|
{
|
||||||
internal class SafeManager
|
internal class SafeManager
|
||||||
{
|
{
|
||||||
public static void initializeFile(string path)
|
public static void InitializeFile(string path)
|
||||||
{
|
{
|
||||||
if (!File.Exists(@path))
|
if (!File.Exists(@path))
|
||||||
{
|
{
|
||||||
@@ -22,7 +22,7 @@ namespace CarManagerV2
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<Car> readCars(string path)
|
public static List<Car> ReadCars(string path)
|
||||||
{
|
{
|
||||||
List<Car> cars = new List<Car>();
|
List<Car> cars = new List<Car>();
|
||||||
using (StreamReader reader = new StreamReader(@path))
|
using (StreamReader reader = new StreamReader(@path))
|
||||||
@@ -32,19 +32,19 @@ namespace CarManagerV2
|
|||||||
{
|
{
|
||||||
// Process the line
|
// Process the line
|
||||||
if (line == "") continue;
|
if (line == "") continue;
|
||||||
cars.Add(Car.fromCsvString(line));
|
cars.Add(Car.FromCsvString(line));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return cars;
|
return cars;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void saveCars(string path, List<Car> cars)
|
public static void SaveCars(string path, List<Car> cars)
|
||||||
{
|
{
|
||||||
using (StreamWriter writer = new StreamWriter(@path))
|
using (StreamWriter writer = new StreamWriter(@path))
|
||||||
{
|
{
|
||||||
foreach (Car car in cars)
|
foreach (Car car in cars)
|
||||||
{
|
{
|
||||||
writer.WriteLine(car.toCsvString());
|
writer.WriteLine(car.ToCsvString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,48 +11,48 @@ namespace CarManagerV2
|
|||||||
|
|
||||||
static List<Car> cars = new List<Car>();
|
static List<Car> cars = new List<Car>();
|
||||||
|
|
||||||
public static Car getCarById(int id)
|
public static Car GetCarById(int id)
|
||||||
{
|
{
|
||||||
cars = SafeManager.readCars("cars.csv");
|
cars = SafeManager.ReadCars("cars.csv");
|
||||||
return cars.FirstOrDefault(c => c.Id == id);
|
return cars.FirstOrDefault(c => c.Id == id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<Car> Cars { get { return cars; } set { cars = value; } }
|
public static List<Car> Cars { get { return cars; } set { cars = value; } }
|
||||||
|
|
||||||
public static void addCar(Car car)
|
public static void AddCar(Car car)
|
||||||
{
|
{
|
||||||
cars = SafeManager.readCars("cars.csv");
|
cars = SafeManager.ReadCars("cars.csv");
|
||||||
cars.Add(car);
|
cars.Add(car);
|
||||||
SafeManager.saveCars("cars.csv", cars);
|
SafeManager.SaveCars("cars.csv", cars);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void removeCar(Car car)
|
public static void RemoveCar(Car car)
|
||||||
{
|
{
|
||||||
cars = SafeManager.readCars("cars.csv");
|
cars = SafeManager.ReadCars("cars.csv");
|
||||||
Car existingCar = getCarById(car.Id);
|
Car existingCar = GetCarById(car.Id);
|
||||||
if (existingCar == null) return;
|
if (existingCar == null) return;
|
||||||
cars.Remove(existingCar);
|
cars.Remove(existingCar);
|
||||||
SafeManager.saveCars("cars.csv", cars);
|
SafeManager.SaveCars("cars.csv", cars);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void updateCar(Car car)
|
public static void UpdateCar(Car car)
|
||||||
{
|
{
|
||||||
Car existingCar = getCarById(car.Id);
|
Car existingCar = GetCarById(car.Id);
|
||||||
if (existingCar != null)
|
if (existingCar != null)
|
||||||
{
|
{
|
||||||
int index = cars.IndexOf(existingCar);
|
int index = cars.IndexOf(existingCar);
|
||||||
cars[index] = car;
|
cars[index] = car;
|
||||||
Console.WriteLine("Updated car: " + existingCar.Id);
|
Console.WriteLine("Updated car: " + existingCar.Id);
|
||||||
SafeManager.saveCars("cars.csv", cars);
|
SafeManager.SaveCars("cars.csv", cars);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Car createCar(string make, string model, int year, string color, int mileage, decimal price)
|
public static Car CreateCar(string make, string model, int year, string color, int mileage, decimal price)
|
||||||
{
|
{
|
||||||
cars = SafeManager.readCars("cars.csv");
|
cars = SafeManager.ReadCars("cars.csv");
|
||||||
int newId = cars.Count > 0 ? cars.Max(c => c.Id) + 1 : 1;
|
int newId = cars.Count > 0 ? cars.Max(c => c.Id) + 1 : 1;
|
||||||
Car newCar = new Car(newId, make, model, year, color, mileage, price);
|
Car newCar = new Car(newId, make, model, year, color, mileage, price);
|
||||||
addCar(newCar);
|
AddCar(newCar);
|
||||||
return newCar;
|
return newCar;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user