[MySQL Student App] Add comments

This commit is contained in:
Alex Thomassen 2019-04-11 15:26:05 +02:00
parent fc275c2f5e
commit 15fb78c1d3
Signed by: Alex
GPG Key ID: 10BD786B5F6FF5DE
3 changed files with 20 additions and 12 deletions

View File

@ -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)

View File

@ -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<PoststedItem>().FirstOrDefault(x => x.PostnummerInt == postnummer);
var poststedIndex = listPoststed.Items.IndexOf(poststed);
listPoststed.SelectedIndex = poststedIndex;
_studentId = Convert.ToInt32(values[0]);

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="MetroSet_UI" version="1.0.3" targetFramework="net461" />
</packages>