3 Commits

6 changed files with 123 additions and 5 deletions

15
App.config Normal file
View File

@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="PizzaExpress_Client.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
</sectionGroup>
</configSections>
<userSettings>
<PizzaExpress_Client.Properties.Settings>
<setting name="serverUrl" serializeAs="String">
<value>http://localhost:5000</value>
</setting>
</PizzaExpress_Client.Properties.Settings>
</userSettings>
</configuration>

View File

@@ -1,3 +1,4 @@
using System.Configuration;
using System.Net.Http.Json;
namespace PizzaExpress_Client
@@ -29,7 +30,7 @@ namespace PizzaExpress_Client
MaximizeBox = false;
StartPosition = FormStartPosition.CenterScreen;
_httpClient = new HttpClient { BaseAddress = new Uri("http://localhost:5000/") };
_httpClient = new HttpClient { BaseAddress = new Uri(Properties.Settings.Default.serverUrl) };
// ======================================================
// PANNELLO SUPERIORE
@@ -273,7 +274,7 @@ namespace PizzaExpress_Client
_btnAggiungi.Enabled = false;
_btnElimina.Enabled = true;
_btnAggiorna.Enabled = true;
_btnCosto.Enabled = true;
_btnIngredienti.Enabled = true;
}
// ======================================================================
@@ -366,7 +367,7 @@ namespace PizzaExpress_Client
}
// ======================================================================
private void BtnIngredienti_Click(object? sender, EventArgs e)
private async void BtnIngredienti_Click(object? sender, EventArgs e)
{
if (_lstPizze.SelectedItem == null)
{
@@ -374,7 +375,32 @@ namespace PizzaExpress_Client
return;
}
MessageBox.Show("Funzionalità Ingredienti non ancora implementata.");
var pizza = _tutteLePizze[_lstPizze.SelectedIndex];
try
{
var dati = await _httpClient.GetFromJsonAsync<RispostaIngredienti>($"api/ingredienti/da-pizza?nome={pizza.Nome}");
if (dati == null)
{
MessageBox.Show("Errore nella risposta del server.");
return;
}
if (dati.ingredienti.Count == 0)
{
MessageBox.Show($"La pizza {dati.pizza} non ha ingredienti associati.");
return;
}
else
{
MessageBox.Show($"Ingredienti {dati.pizza}:\n- " + string.Join("\n- ", dati.ingredienti));
}
}
catch (Exception nigga)
{
MessageBox.Show($"{nigga.Message}", "Errore nella richiesta", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void PulisciCampi()
@@ -389,7 +415,7 @@ namespace PizzaExpress_Client
_btnAggiungi.Enabled = true;
_btnElimina.Enabled = false;
_btnAggiorna.Enabled = false;
_btnCosto.Enabled = false;
_btnIngredienti.Enabled = false;
}
}
}

View File

@@ -9,4 +9,19 @@
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<Compile Update="Properties\Settings.Designer.cs">
<DesignTimeSharedInput>True</DesignTimeSharedInput>
<AutoGen>True</AutoGen>
<DependentUpon>Settings.settings</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<None Update="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
</ItemGroup>
</Project>

38
Properties/Settings.Designer.cs generated Normal file
View File

@@ -0,0 +1,38 @@
//------------------------------------------------------------------------------
// <auto-generated>
// Il codice è stato generato da uno strumento.
// Versione runtime:4.0.30319.42000
//
// Le modifiche apportate a questo file possono provocare un comportamento non corretto e andranno perse se
// il codice viene rigenerato.
// </auto-generated>
//------------------------------------------------------------------------------
namespace PizzaExpress_Client.Properties {
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.11.0.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
public static Settings Default {
get {
return defaultInstance;
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("http://localhost:5000")]
public string serverUrl {
get {
return ((string)(this["serverUrl"]));
}
set {
this["serverUrl"] = value;
}
}
}
}

View File

@@ -0,0 +1,9 @@
<?xml version='1.0' encoding='utf-8'?>
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" GeneratedClassNamespace="PizzaExpress_Client.Properties" GeneratedClassName="Settings">
<Profiles />
<Settings>
<Setting Name="serverUrl" Type="System.String" Scope="User">
<Value Profile="(Default)">http://localhost:5000</Value>
</Setting>
</Settings>
</SettingsFile>

15
RispostaIngredienti.cs Normal file
View File

@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PizzaExpress_Client
{
internal class RispostaIngredienti
{
public string pizza { get; set; }
public List<string> ingredienti { get; set; }
public string fonte { get; set; }
}
}