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

Binary file not shown.

View File

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1"/>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8"/>
</startup>
</configuration>

View File

@@ -51,7 +51,15 @@ namespace PoloClubApp
/// <returns>List of wearable devices.</returns>
public List<Device> GetAllWearables()
{
return devices.Where(d => d is IWearable).ToList();
List<Device> wearables = new List<Device>();
foreach (Device device in devices)
{
if (device is IWearable)
{
wearables.Add(device);
}
}
return wearables;
}
/// <summary>
@@ -62,8 +70,8 @@ namespace PoloClubApp
/// <exception cref="Exception">Thrown if device is not found.</exception>
public void AssignDevice(int id, string playerName)
{
var device = GetDeviceById(id) ?? throw new Exception("Device not found");
var waterResistance = (device as IWearable)?.GetWaterResistanceMeters();
Device device = GetDeviceById(id) ?? throw new Exception("Device not found");
int? waterResistance = (device as IWearable)?.GetWaterResistanceMeters();
device.AssignDevice(playerName, waterResistance);
}
@@ -74,7 +82,7 @@ namespace PoloClubApp
/// <returns>True if successful, false if device not found.</returns>
public bool ReturnDevice(int id)
{
var device = GetDeviceById(id);
Device device = GetDeviceById(id);
return device?.ReturnDevice() ?? false;
}
@@ -95,8 +103,8 @@ namespace PoloClubApp
/// <returns>Formatted report lines.</returns>
public List<string> GenerateReportPerPlayer(string playerName)
{
var assignedDevices = GetAllAssignedDevicesByPlayer(playerName);
var report = new List<string>
List<Device> assignedDevices = GetAllAssignedDevicesByPlayer(playerName);
List<string> report = new List<string>
{
$"List of devices assigned to {playerName}",
"Phones",

View File

@@ -59,7 +59,7 @@ namespace PoloClubApp {
/// </summary>
/// <returns>True if assigned, false otherwise.</returns>
public bool IsAssigned(){
return !string.IsNullOrEmpty(PlayerName);
return !string.IsNullOrEmpty(PlayerName);
}
/// <summary>
@@ -68,17 +68,16 @@ namespace PoloClubApp {
/// <param name="playerName">Name of the player to assign to.</param>
/// <param name="waterResistanceMeters">Water resistance for wearables (nullable).</param>
/// <exception cref="Exception">Throws when assignment fails.</exception>
public void AssignDevice(string playerName, int? waterResistanceMeters)
{
if (IsAssigned())
public void AssignDevice(string playerName, int? waterResistanceMeters){
if (IsAssigned()){
throw new Exception("Device is already assigned");
if (this is IWearable && waterResistanceMeters < 3)
}
if (this is IWearable && waterResistanceMeters < 3){
throw new Exception("Water resistance must be 3 meters or more for wearables");
if (Id == 0)
}
if (Id == 0){
throw new Exception("Invalid device ID");
}
PlayerName = playerName;
}
@@ -87,11 +86,11 @@ namespace PoloClubApp {
/// </summary>
/// <returns>True if successful, false if device wasn't assigned.</returns>
public bool ReturnDevice(){
if (!IsAssigned())
return false;
PlayerName = null;
return true;
if (!IsAssigned()){
return false;
}
PlayerName = null;
return true;
}
}
}

View File

@@ -8,7 +8,7 @@
<OutputType>WinExe</OutputType>
<RootNamespace>PoloClubApp</RootNamespace>
<AssemblyName>PoloClubApp</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>

View File

@@ -202,7 +202,6 @@
//
// saveFileDialog1
//
this.saveFileDialog1.FileOk += new System.ComponentModel.CancelEventHandler(this.saveFileDialog1_FileOk);
//
// PoloClubAppForm
//
@@ -215,7 +214,6 @@
this.Controls.Add(this.lbOverview);
this.Name = "PoloClubAppForm";
this.Text = "Form1";
this.Load += new System.EventHandler(this.PoloClubAppForm_Load);
this.groupBox1.ResumeLayout(false);
this.groupBox2.ResumeLayout(false);
this.groupBox2.PerformLayout();

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());
}
}
}
}

View File

@@ -12,7 +12,7 @@ namespace PoloClubApp.Properties {
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.13.0.0")]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.12.0.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));

View File

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1"/>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8"/>
</startup>
</configuration>

View File

@@ -1 +1 @@
2dd441a6dcab245f72940a1e3dc8fb177864ab58
90cb8bf3ebafd798eee9d80691d19f1b5819e6787f258fb71804932ed0b5e337

View File

@@ -27,3 +27,13 @@ C:\Users\Rens\Downloads\PoloClubApp\obj\Debug\PoloClubApp.csproj.GenerateResourc
C:\Users\Rens\Downloads\PoloClubApp\obj\Debug\PoloClubApp.csproj.CoreCompileInputs.cache
C:\Users\Rens\Downloads\PoloClubApp\obj\Debug\PoloClubApp.exe
C:\Users\Rens\Downloads\PoloClubApp\obj\Debug\PoloClubApp.pdb
C:\Users\Gebruiker\T2\CS\CS1 PoloClubApp_RensPastoor\obj\Debug\PoloClubApp.csproj.AssemblyReference.cache
C:\Users\Gebruiker\T2\CS\CS1 PoloClubApp_RensPastoor\obj\Debug\PoloClubApp.PoloClubAppForm.resources
C:\Users\Gebruiker\T2\CS\CS1 PoloClubApp_RensPastoor\obj\Debug\PoloClubApp.Properties.Resources.resources
C:\Users\Gebruiker\T2\CS\CS1 PoloClubApp_RensPastoor\obj\Debug\PoloClubApp.csproj.GenerateResource.cache
C:\Users\Gebruiker\T2\CS\CS1 PoloClubApp_RensPastoor\obj\Debug\PoloClubApp.csproj.CoreCompileInputs.cache
C:\Users\Gebruiker\T2\CS\CS1 PoloClubApp_RensPastoor\obj\Debug\PoloClubApp.exe
C:\Users\Gebruiker\T2\CS\CS1 PoloClubApp_RensPastoor\obj\Debug\PoloClubApp.pdb
C:\Users\Gebruiker\T2\CS\CS1 PoloClubApp_RensPastoor\bin\Debug\PoloClubApp.exe.config
C:\Users\Gebruiker\T2\CS\CS1 PoloClubApp_RensPastoor\bin\Debug\PoloClubApp.exe
C:\Users\Gebruiker\T2\CS\CS1 PoloClubApp_RensPastoor\bin\Debug\PoloClubApp.pdb