From c7076476f6ff3b8b584f20a3f0987ae13fa2206b Mon Sep 17 00:00:00 2001 From: Frozd <59323943+frozdbyte@users.noreply.github.com> Date: Fri, 28 Nov 2025 09:52:24 +0100 Subject: [PATCH] initial --- .gitignore | 3 +- CarManagerV2/Car.cs | 6 +- CarManagerV2/CarCard.Designer.cs | 87 +++++++++++++++---------- CarManagerV2/CarCard.cs | 5 -- CarManagerV2/CarDetailsForm.Designer.cs | 21 +++--- CarManagerV2/CarDetailsForm.cs | 9 +-- CarManagerV2/ImageManager.cs | 14 ++-- CarManagerV2/MainForm.Designer.cs | 2 - CarManagerV2/MainForm.cs | 24 ++----- CarManagerV2/SafeManager.cs | 10 +-- CarManagerV2/StateManager.cs | 30 ++++----- 11 files changed, 103 insertions(+), 108 deletions(-) diff --git a/.gitignore b/.gitignore index 9491a2f..ef15bd2 100644 --- a/.gitignore +++ b/.gitignore @@ -360,4 +360,5 @@ MigrationBackup/ .ionide/ # Fody - auto-generated XML schema -FodyWeavers.xsd \ No newline at end of file +FodyWeavers.xsd +IAF42_Kaulmann_CarmanagerV2.zip diff --git a/CarManagerV2/Car.cs b/CarManagerV2/Car.cs index 99743a8..e79fcbf 100644 --- a/CarManagerV2/Car.cs +++ b/CarManagerV2/Car.cs @@ -41,18 +41,18 @@ namespace CarManagerV2 return $"{make} {model} ({year})"; } - public string toCsvString() + public string ToCsvString() { return $"{id};{make};{model};{year};{color};{mileage};{price}"; } - public static Car fromCsvString(string csv) + public static Car FromCsvString(string csv) { 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])); } - 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; } diff --git a/CarManagerV2/CarCard.Designer.cs b/CarManagerV2/CarCard.Designer.cs index 3d55785..1dd74e0 100644 --- a/CarManagerV2/CarCard.Designer.cs +++ b/CarManagerV2/CarCard.Designer.cs @@ -29,57 +29,77 @@ private void InitializeComponent() { System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(CarCard)); - this.pbxCar = new System.Windows.Forms.PictureBox(); - this.lblCarName = new System.Windows.Forms.Label(); + this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel(); 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(); this.SuspendLayout(); // - // pbxCar + // tableLayoutPanel1 // - this.pbxCar.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) - | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - 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, 130); - this.pbxCar.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom; - this.pbxCar.TabIndex = 0; - this.pbxCar.TabStop = false; - // - // lblCarName - // - this.lblCarName.AutoSize = true; - 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, 136); - this.lblCarName.Name = "lblCarName"; - this.lblCarName.Size = new System.Drawing.Size(148, 27); - this.lblCarName.TabIndex = 1; - this.lblCarName.Text = "Skoda Fabia"; + this.tableLayoutPanel1.AutoSize = true; + this.tableLayoutPanel1.ColumnCount = 1; + this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F)); + this.tableLayoutPanel1.Controls.Add(this.lblCarDetails, 0, 2); + this.tableLayoutPanel1.Controls.Add(this.lblCarName, 0, 1); + this.tableLayoutPanel1.Controls.Add(this.pbxCar, 0, 0); + this.tableLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill; + this.tableLayoutPanel1.Location = new System.Drawing.Point(0, 0); + this.tableLayoutPanel1.MaximumSize = new System.Drawing.Size(210, 0); + this.tableLayoutPanel1.Name = "tableLayoutPanel1"; + this.tableLayoutPanel1.RowCount = 3; + this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 130F)); + 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(210, 200); + this.tableLayoutPanel1.TabIndex = 0; // // lblCarDetails // 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.Size = new System.Drawing.Size(101, 16); - this.lblCarDetails.TabIndex = 2; + this.lblCarDetails.TabIndex = 5; 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 // this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoSize = true; this.BackColor = System.Drawing.SystemColors.Control; - this.Controls.Add(this.lblCarDetails); - this.Controls.Add(this.lblCarName); - this.Controls.Add(this.pbxCar); + this.Controls.Add(this.tableLayoutPanel1); this.Name = "CarCard"; - this.Size = new System.Drawing.Size(210, 192); - this.Load += new System.EventHandler(this.CarCard_Load); + this.Size = new System.Drawing.Size(210, 200); + this.tableLayoutPanel1.ResumeLayout(false); + this.tableLayoutPanel1.PerformLayout(); ((System.ComponentModel.ISupportInitialize)(this.pbxCar)).EndInit(); this.ResumeLayout(false); this.PerformLayout(); @@ -88,8 +108,9 @@ #endregion - private System.Windows.Forms.PictureBox pbxCar; - private System.Windows.Forms.Label lblCarName; + private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1; private System.Windows.Forms.Label lblCarDetails; + private System.Windows.Forms.Label lblCarName; + private System.Windows.Forms.PictureBox pbxCar; } } diff --git a/CarManagerV2/CarCard.cs b/CarManagerV2/CarCard.cs index ac7fae0..0b83486 100644 --- a/CarManagerV2/CarCard.cs +++ b/CarManagerV2/CarCard.cs @@ -58,10 +58,5 @@ namespace CarManagerV2 this.CardClicked(this, EventArgs.Empty); } } - - private void CarCard_Load(object sender, EventArgs e) - { - - } } } diff --git a/CarManagerV2/CarDetailsForm.Designer.cs b/CarManagerV2/CarDetailsForm.Designer.cs index 8a86027..f5b7a7d 100644 --- a/CarManagerV2/CarDetailsForm.Designer.cs +++ b/CarManagerV2/CarDetailsForm.Designer.cs @@ -42,11 +42,11 @@ this.flowLayoutPanel1 = new System.Windows.Forms.FlowLayoutPanel(); this.btnSave = 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.tbxColor = new System.Windows.Forms.TextBox(); this.nudMileage = new System.Windows.Forms.NumericUpDown(); this.nudPrice = new System.Windows.Forms.NumericUpDown(); - this.lblID = new System.Windows.Forms.Label(); this.tableLayoutPanel1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.pbxCarImage)).BeginInit(); this.flowLayoutPanel1.SuspendLayout(); @@ -209,6 +209,15 @@ this.btnDelete.UseVisualStyleBackColor = true; 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 // this.nudYear.Location = new System.Drawing.Point(68, 263); @@ -260,15 +269,6 @@ this.nudPrice.ThousandsSeparator = true; 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 // this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F); @@ -279,7 +279,6 @@ this.MaximizeBox = false; this.Name = "CarDetailsForm"; this.Text = "Details"; - this.Load += new System.EventHandler(this.Form1_Load); this.tableLayoutPanel1.ResumeLayout(false); this.tableLayoutPanel1.PerformLayout(); ((System.ComponentModel.ISupportInitialize)(this.pbxCarImage)).EndInit(); diff --git a/CarManagerV2/CarDetailsForm.cs b/CarManagerV2/CarDetailsForm.cs index a5e1959..da5ca9c 100644 --- a/CarManagerV2/CarDetailsForm.cs +++ b/CarManagerV2/CarDetailsForm.cs @@ -29,11 +29,6 @@ namespace CarManagerV2 lblID.Text = $"ID: {car.Id}"; } - private void Form1_Load(object sender, EventArgs e) - { - - } - private void tbxMake_TextChanged(object sender, EventArgs e) { car.Make = tbxMake.Text; @@ -71,7 +66,7 @@ namespace CarManagerV2 var msgbox = new PleaseWait(); msgbox.Show(); Application.DoEvents(); - StateManager.updateCar(car); + StateManager.UpdateCar(car); Image fooimg = ImageManager.GetImage(car); msgbox.Close(); this.Close(); @@ -85,7 +80,7 @@ namespace CarManagerV2 if (result == DialogResult.Yes) { Console.WriteLine("Deleting car: " + car.Id); - StateManager.removeCar(car); + StateManager.RemoveCar(car); this.Close(); } } diff --git a/CarManagerV2/ImageManager.cs b/CarManagerV2/ImageManager.cs index 6a969f5..55d923c 100644 --- a/CarManagerV2/ImageManager.cs +++ b/CarManagerV2/ImageManager.cs @@ -10,7 +10,7 @@ namespace CarManagerV2 internal class ImageManager { - public static void initializeImageFolder() + public static void InitializeImageFolder() { string path = "images"; 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 fileName = $"{car.Make}_{car.Model}_{car.Year}_{car.Color}.png"; @@ -28,9 +28,9 @@ namespace CarManagerV2 public static Image GetImage(Car car) { - initializeImageFolder(); - fetchImage(car); - string path = getImagePath(car); + InitializeImageFolder(); + FetchImage(car); + string path = GetImagePath(car); // does image exist? 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 // 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 - string path = getImagePath(car); + string path = GetImagePath(car); if (System.IO.File.Exists(path)) { return; diff --git a/CarManagerV2/MainForm.Designer.cs b/CarManagerV2/MainForm.Designer.cs index dbfca79..c4d3178 100644 --- a/CarManagerV2/MainForm.Designer.cs +++ b/CarManagerV2/MainForm.Designer.cs @@ -52,7 +52,6 @@ this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle()); this.tableLayoutPanel1.Size = new System.Drawing.Size(800, 450); this.tableLayoutPanel1.TabIndex = 0; - this.tableLayoutPanel1.Paint += new System.Windows.Forms.PaintEventHandler(this.tableLayoutPanel1_Paint); // // flpCars // @@ -109,7 +108,6 @@ this.MinimumSize = new System.Drawing.Size(818, 497); this.Name = "MainForm"; this.Text = "Carmanager 2"; - this.Load += new System.EventHandler(this.MainForm_Load); this.tableLayoutPanel1.ResumeLayout(false); this.tableLayoutPanel2.ResumeLayout(false); this.tableLayoutPanel2.PerformLayout(); diff --git a/CarManagerV2/MainForm.cs b/CarManagerV2/MainForm.cs index ca1adb8..9df1d55 100644 --- a/CarManagerV2/MainForm.cs +++ b/CarManagerV2/MainForm.cs @@ -17,8 +17,8 @@ namespace CarManagerV2 public MainForm() { InitializeComponent(); - SafeManager.initializeFile("cars.csv"); - List _cars = SafeManager.readCars("cars.csv"); + SafeManager.InitializeFile("cars.csv"); + List _cars = SafeManager.ReadCars("cars.csv"); refreshCars(_cars); } @@ -97,7 +97,7 @@ namespace CarManagerV2 // refresh cars Application.DoEvents(); Console.WriteLine("Refreshing cars..."); - List __cars = SafeManager.readCars("cars.csv"); + List __cars = SafeManager.ReadCars("cars.csv"); refreshCars(__cars); }; 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) { - 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); detailsForm.FormClosed += (s2, e2) => { // refresh cars Console.WriteLine("Refreshing cars..."); - cars = SafeManager.readCars("cars.csv"); + cars = SafeManager.ReadCars("cars.csv"); refreshCars(cars); }; detailsForm.ShowDialog(); diff --git a/CarManagerV2/SafeManager.cs b/CarManagerV2/SafeManager.cs index 63b4d94..af6561f 100644 --- a/CarManagerV2/SafeManager.cs +++ b/CarManagerV2/SafeManager.cs @@ -10,7 +10,7 @@ namespace CarManagerV2 { internal class SafeManager { - public static void initializeFile(string path) + public static void InitializeFile(string path) { if (!File.Exists(@path)) { @@ -22,7 +22,7 @@ namespace CarManagerV2 } } - public static List readCars(string path) + public static List ReadCars(string path) { List cars = new List(); using (StreamReader reader = new StreamReader(@path)) @@ -32,19 +32,19 @@ namespace CarManagerV2 { // Process the line if (line == "") continue; - cars.Add(Car.fromCsvString(line)); + cars.Add(Car.FromCsvString(line)); } } return cars; } - public static void saveCars(string path, List cars) + public static void SaveCars(string path, List cars) { using (StreamWriter writer = new StreamWriter(@path)) { foreach (Car car in cars) { - writer.WriteLine(car.toCsvString()); + writer.WriteLine(car.ToCsvString()); } } } diff --git a/CarManagerV2/StateManager.cs b/CarManagerV2/StateManager.cs index 9a6854a..60839eb 100644 --- a/CarManagerV2/StateManager.cs +++ b/CarManagerV2/StateManager.cs @@ -11,48 +11,48 @@ namespace CarManagerV2 static List cars = new List(); - 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); } public static List 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); - 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"); - Car existingCar = getCarById(car.Id); + cars = SafeManager.ReadCars("cars.csv"); + Car existingCar = GetCarById(car.Id); if (existingCar == null) return; 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) { int index = cars.IndexOf(existingCar); cars[index] = car; 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; Car newCar = new Car(newId, make, model, year, color, mileage, price); - addCar(newCar); + AddCar(newCar); return newCar; } }