cs1 improvements

This commit is contained in:
renspastoor
2025-06-12 11:57:48 +02:00
parent 1086760c4a
commit 3d69c8b93d
21 changed files with 278 additions and 261 deletions

View File

@@ -19,14 +19,14 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace PoloClubApp {
public partial class PoloClubAppForm : Form {
// Provide your answers here
private void btnViewAllWearables_Click(object sender, EventArgs e){
List<Device> wearables = myClub.GetAllWearables();
lbOverview.Items.Clear();
foreach (Device wearable in wearables)
{
foreach (Device wearable in wearables){
lbOverview.Items.Add(wearable.GetDetails());
}
}
@@ -34,16 +34,19 @@ namespace PoloClubApp {
private void btnAssign_Click(object sender, EventArgs e){
try {
if (string.IsNullOrWhiteSpace(tbPlayerName.Text)){
MessageBox.Show("Please enter a player name");
MessageBox.Show("Please enter a player name.");
return;
}
if (cbDevice.SelectedItem == null){
MessageBox.Show("Please select a device.");
return;
}
if (!int.TryParse(cbDevice.SelectedItem.ToString(), out int deviceId)){
MessageBox.Show("Invalid device selection. Please select a valid device.");
return;
}
int deviceId = int.Parse(cbDevice.SelectedItem.ToString());
myClub.AssignDevice(deviceId, tbPlayerName.Text);
MessageBox.Show("Device assigned successfully");
}
catch (FormatException){
MessageBox.Show("Please select a valid device");
MessageBox.Show("Device assigned successfully.");
}
catch (Exception ex){
MessageBox.Show($"Error assigning device: {ex.Message}");
@@ -62,17 +65,15 @@ namespace PoloClubApp {
}
}
private void btnGeneratePlayerTextReport_Click(object sender, EventArgs e){
List<string> report = myClub.GenerateReportPerPlayer(tbPlayerName.Text);
private void btnGeneratePlayerTextReport_Click(object sender, EventArgs e)
{
List<string> report = myClub.GenerateReportPerPlayer(tbPlayerNameForFile.Text);
lbOverview.Items.Clear();
foreach (string line in report){
lbOverview.Items.Add(line);
}
}
// -----The provided code below will not be graded, therefore should not be changed-----
private Club myClub;
@@ -103,12 +104,13 @@ namespace PoloClubApp {
}
}
private void btnViewAllDevices_Click(object sender, EventArgs e){
private void btnViewAllDevices_Click(object sender, EventArgs e)
{
this.lbOverview.Items.Clear();
foreach (Device dev in myClub.GetAllDevices()){
foreach (Device dev in myClub.GetAllDevices())
{
this.lbOverview.Items.Add(dev.GetDetails());
}
}
}
}