6 Commits

6 changed files with 138 additions and 18 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; using System.Net.Http.Json;
namespace PizzaExpress_Client namespace PizzaExpress_Client
@@ -12,7 +13,7 @@ namespace PizzaExpress_Client
private readonly TextBox _txtId, _txtNome, _txtPrezzo, _txtRicerca, _txtNote; private readonly TextBox _txtId, _txtNome, _txtPrezzo, _txtRicerca, _txtNote;
private readonly ComboBox _cmbCategoria, _cmbStato; private readonly ComboBox _cmbCategoria, _cmbStato;
private readonly Button _btnAggiungi, _btnAggiorna, _btnElimina, _btnElenco, _btnCosto, _btnNuovaPizza; private readonly Button _btnAggiungi, _btnAggiorna, _btnElimina, _btnElenco, _btnIngredienti, _btnNuovaPizza;
public GestionePizzeForm() public GestionePizzeForm()
{ {
@@ -29,7 +30,7 @@ namespace PizzaExpress_Client
MaximizeBox = false; MaximizeBox = false;
StartPosition = FormStartPosition.CenterScreen; StartPosition = FormStartPosition.CenterScreen;
_httpClient = new HttpClient { BaseAddress = new Uri("http://localhost:5000/") }; _httpClient = new HttpClient { BaseAddress = new Uri(Properties.Settings.Default.serverUrl) };
// ====================================================== // ======================================================
// PANNELLO SUPERIORE // PANNELLO SUPERIORE
@@ -48,16 +49,16 @@ namespace PizzaExpress_Client
AutoSize = true AutoSize = true
}; };
_btnCosto = new Button _btnIngredienti = new Button
{ {
Text = "Costo", Text = "Ingredienti",
Location = new Point(900, 15), Location = new Point(870, 15),
Size = new Size(70, 30) Size = new Size(104, 30)
}; };
_btnCosto.Click += BtnCosto_Click; _btnIngredienti.Click += BtnIngredienti_Click;
pnlTop.Controls.Add(lblTitolo); pnlTop.Controls.Add(lblTitolo);
pnlTop.Controls.Add(_btnCosto); pnlTop.Controls.Add(_btnIngredienti);
// ====================================================== // ======================================================
// PANNELLO SINISTRO // PANNELLO SINISTRO
@@ -196,9 +197,9 @@ namespace PizzaExpress_Client
Padding = new Padding(0, 10, 0, 0) Padding = new Padding(0, 10, 0, 0)
}; };
_btnAggiungi = new Button { Text = "Aggiungi", Width = 120 }; _btnAggiungi = new Button { Text = "Aggiungi", Width = 120, Enabled = false };
_btnAggiorna = new Button { Text = "Aggiorna", Width = 120 }; _btnAggiorna = new Button { Text = "Aggiorna", Width = 120, Enabled = false };
_btnElimina = new Button { Text = "Elimina", Width = 120 }; _btnElimina = new Button { Text = "Elimina", Width = 120, Enabled = false };
_btnAggiungi.Click += async (s, e) => await AggiungiPizza(); _btnAggiungi.Click += async (s, e) => await AggiungiPizza();
_btnAggiorna.Click += async (s, e) => await AggiornaPizza(); _btnAggiorna.Click += async (s, e) => await AggiornaPizza();
@@ -269,6 +270,11 @@ namespace PizzaExpress_Client
_cmbCategoria.Text = p.Categoria; _cmbCategoria.Text = p.Categoria;
_txtNote.Text = p.Note; _txtNote.Text = p.Note;
_cmbStato.Text = p.Stato; _cmbStato.Text = p.Stato;
_btnAggiungi.Enabled = false;
_btnElimina.Enabled = true;
_btnAggiorna.Enabled = true;
_btnIngredienti.Enabled = true;
} }
// ====================================================================== // ======================================================================
@@ -361,7 +367,7 @@ namespace PizzaExpress_Client
} }
// ====================================================================== // ======================================================================
private void BtnCosto_Click(object? sender, EventArgs e) private async void BtnIngredienti_Click(object? sender, EventArgs e)
{ {
if (_lstPizze.SelectedItem == null) if (_lstPizze.SelectedItem == null)
{ {
@@ -369,14 +375,31 @@ namespace PizzaExpress_Client
return; return;
} }
var s = _lstPizze.SelectedItem.ToString(); var pizza = _tutteLePizze[_lstPizze.SelectedIndex];
var parts = s.Split('-');
if (parts.Length >= 3) try
{ {
string nome = parts[1].Trim(); var dati = await _httpClient.GetFromJsonAsync<RispostaIngredienti>($"api/ingredienti/da-pizza?nome={pizza.Nome}");
string prezzo = parts[2].Replace("€", "").Trim();
MessageBox.Show($"La pizza {nome} costa {prezzo}€."); 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);
} }
} }
@@ -388,6 +411,11 @@ namespace PizzaExpress_Client
_txtNote.Clear(); _txtNote.Clear();
_cmbCategoria.SelectedIndex = -1; _cmbCategoria.SelectedIndex = -1;
_cmbStato.SelectedIndex = -1; _cmbStato.SelectedIndex = -1;
_btnAggiungi.Enabled = true;
_btnElimina.Enabled = false;
_btnAggiorna.Enabled = false;
_btnIngredienti.Enabled = false;
} }
} }
} }

View File

@@ -9,4 +9,19 @@
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup> </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> </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; }
}
}