From 15fb78c1d34a680142fc0e48c6a918f4e03a857c Mon Sep 17 00:00:00 2001 From: Alex Thomassen Date: Thu, 11 Apr 2019 15:26:05 +0200 Subject: [PATCH] [MySQL Student App] Add comments --- .../MySQLStoredProcedureStudent/Poststed.cs | 12 ++++-------- .../MySQLStoredProcedureStudent/StudentForm.cs | 16 ++++++++++++---- .../MySQLStoredProcedureStudent/packages.config | 4 ++++ 3 files changed, 20 insertions(+), 12 deletions(-) create mode 100644 MySQLStoredProcedureStudent/MySQLStoredProcedureStudent/packages.config diff --git a/MySQLStoredProcedureStudent/MySQLStoredProcedureStudent/Poststed.cs b/MySQLStoredProcedureStudent/MySQLStoredProcedureStudent/Poststed.cs index c9a7a8f..77157a8 100644 --- a/MySQLStoredProcedureStudent/MySQLStoredProcedureStudent/Poststed.cs +++ b/MySQLStoredProcedureStudent/MySQLStoredProcedureStudent/Poststed.cs @@ -1,13 +1,7 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; +using MySql.Data.MySqlClient; +using System; using System.Data; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using System.Windows.Forms; -using MySql.Data.MySqlClient; namespace MySQLStoredProcedureStudent { @@ -72,6 +66,7 @@ namespace MySQLStoredProcedureStudent var id = int.Parse(items[0].ToString()); var name = items[1].ToString(); + // This method is practically the same as used in the StudentForm. var fylkeItem = new FylkeItem(id, name); listFylke.Items.Add(fylkeItem); } @@ -98,6 +93,7 @@ namespace MySQLStoredProcedureStudent GridFill(); ClearFields(); + // Update the parent form (StudentForm) when adding a new poststed. _parentForm.UpdatePoststedList(); } catch (Exception ex) diff --git a/MySQLStoredProcedureStudent/MySQLStoredProcedureStudent/StudentForm.cs b/MySQLStoredProcedureStudent/MySQLStoredProcedureStudent/StudentForm.cs index 8eaaed4..a47aa7e 100644 --- a/MySQLStoredProcedureStudent/MySQLStoredProcedureStudent/StudentForm.cs +++ b/MySQLStoredProcedureStudent/MySQLStoredProcedureStudent/StudentForm.cs @@ -48,6 +48,9 @@ namespace MySQLStoredProcedureStudent var postnummer = int.Parse(items[0].ToString()); var poststed = items[1].ToString(); + // PoststedItem is used as a model so that the ToString method can be overridden + // The override allows us to display the postnummer and poststed in a "custom" format. + // Without this, the poststed field in the form would only display the postnummer. var poststedItem = new PoststedItem(postnummer, poststed); listPoststed.Items.Add(poststedItem); } @@ -153,8 +156,8 @@ namespace MySQLStoredProcedureStudent values[i] = cells[i].Value.ToString(); } - txtFirstName.Text = values[1]; - txtLastName.Text = values[2]; + txtLastName.Text = values[1]; + txtFirstName.Text = values[2]; txtAddress.Text = values[3]; txtPhone.Text = values[4]; numAge.Value = Convert.ToInt32(values[5]); @@ -164,16 +167,21 @@ namespace MySQLStoredProcedureStudent { listGender.SelectedIndex = 0; } - // gender == "M" + // gender == "F" else { listGender.SelectedIndex = 1; } + // Complicated way of selecting the poststed in the list + // Basically: + // - We convert the "postnummer" from a string + // - The list items are converted (in a variable) to a list of PoststedItem models + // - Then we filter based on the postnummer + // - Then we find the index of the poststed in said list, based on the filtered PoststedItem models. var postnummer = Convert.ToInt32(values[7]); var poststed = listPoststed.Items.Cast().FirstOrDefault(x => x.PostnummerInt == postnummer); var poststedIndex = listPoststed.Items.IndexOf(poststed); - listPoststed.SelectedIndex = poststedIndex; _studentId = Convert.ToInt32(values[0]); diff --git a/MySQLStoredProcedureStudent/MySQLStoredProcedureStudent/packages.config b/MySQLStoredProcedureStudent/MySQLStoredProcedureStudent/packages.config new file mode 100644 index 0000000..2718860 --- /dev/null +++ b/MySQLStoredProcedureStudent/MySQLStoredProcedureStudent/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file