Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 33be97e894 | |||
| cb6c007480 | |||
| b55d2a40db | |||
| 248b12a6b0 | |||
| de1c6821c1 |
15
App.config
Normal file
15
App.config
Normal 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>
|
||||
@@ -1,3 +1,4 @@
|
||||
using System.Configuration;
|
||||
using System.Net.Http.Json;
|
||||
|
||||
namespace PizzaExpress_Client
|
||||
@@ -12,7 +13,7 @@ namespace PizzaExpress_Client
|
||||
private readonly TextBox _txtId, _txtNome, _txtPrezzo, _txtRicerca, _txtNote;
|
||||
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()
|
||||
{
|
||||
@@ -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
|
||||
@@ -48,17 +49,16 @@ namespace PizzaExpress_Client
|
||||
AutoSize = true
|
||||
};
|
||||
|
||||
_btnCosto = new Button
|
||||
_btnIngredienti = new Button
|
||||
{
|
||||
Text = "Costo",
|
||||
Location = new Point(900, 15),
|
||||
Size = new Size(70, 30),
|
||||
Enabled = false
|
||||
Text = "Ingredienti",
|
||||
Location = new Point(870, 15),
|
||||
Size = new Size(104, 30)
|
||||
};
|
||||
_btnCosto.Click += BtnCosto_Click;
|
||||
_btnIngredienti.Click += BtnIngredienti_Click;
|
||||
|
||||
pnlTop.Controls.Add(lblTitolo);
|
||||
pnlTop.Controls.Add(_btnCosto);
|
||||
pnlTop.Controls.Add(_btnIngredienti);
|
||||
|
||||
// ======================================================
|
||||
// PANNELLO SINISTRO
|
||||
@@ -274,7 +274,7 @@ namespace PizzaExpress_Client
|
||||
_btnAggiungi.Enabled = false;
|
||||
_btnElimina.Enabled = true;
|
||||
_btnAggiorna.Enabled = true;
|
||||
_btnCosto.Enabled = true;
|
||||
_btnIngredienti.Enabled = true;
|
||||
}
|
||||
|
||||
// ======================================================================
|
||||
@@ -367,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)
|
||||
{
|
||||
@@ -375,14 +375,31 @@ namespace PizzaExpress_Client
|
||||
return;
|
||||
}
|
||||
|
||||
var s = _lstPizze.SelectedItem.ToString();
|
||||
var parts = s.Split('-');
|
||||
var pizza = _tutteLePizze[_lstPizze.SelectedIndex];
|
||||
|
||||
if (parts.Length >= 3)
|
||||
try
|
||||
{
|
||||
string nome = parts[1].Trim();
|
||||
string prezzo = parts[2].Replace("€", "").Trim();
|
||||
MessageBox.Show($"La pizza {nome} costa {prezzo}€.");
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -398,7 +415,7 @@ namespace PizzaExpress_Client
|
||||
_btnAggiungi.Enabled = true;
|
||||
_btnElimina.Enabled = false;
|
||||
_btnAggiorna.Enabled = false;
|
||||
_btnCosto.Enabled = false;
|
||||
_btnIngredienti.Enabled = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
38
Properties/Settings.Designer.cs
generated
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
9
Properties/Settings.settings
Normal file
9
Properties/Settings.settings
Normal 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
15
RispostaIngredienti.cs
Normal 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; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user