oop_AM-6/WebClient/WpfWebClient/FoodplaceForm.xaml.cs

88 lines
2.9 KiB
C#
Raw Normal View History

2018-07-01 15:32:50 +02:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
2018-07-28 13:47:47 +02:00
using System.Windows.Navigation;
2018-07-01 15:32:50 +02:00
using System.Windows.Shapes;
2018-07-28 13:47:47 +02:00
using WpfWebClient.ServiceReferenceEHEC;
2018-07-01 15:32:50 +02:00
namespace WpfWebClient
{
/// <summary>
2018-07-28 13:47:47 +02:00
/// Interaction logic for FoodplaceForm.xaml
2018-07-01 15:32:50 +02:00
/// </summary>
2018-07-28 13:47:47 +02:00
public partial class FoodplaceForm : Page
2018-07-01 15:32:50 +02:00
{
2018-07-28 13:47:47 +02:00
public FoodplaceForm()
2018-07-01 15:32:50 +02:00
{
InitializeComponent();
WpfWebClient.ServiceReferenceEHEC.ServiceClient client = new WpfWebClient.ServiceReferenceEHEC.ServiceClient();
// Retrieve all cities and save them into "citylist"
List<WpfWebClient.ServiceReferenceEHEC.City> citylist = new List<ServiceReferenceEHEC.City>(client.GetCities());
// Display all cities with name in Combobox
ComboBoxFPCities.ItemsSource = citylist;
ComboBoxFPCities.DisplayMemberPath = "Name";
2018-09-20 21:36:41 +02:00
client.Close();
2018-07-01 15:32:50 +02:00
}
2018-08-06 23:25:32 +02:00
private void btnAddFoodPlace_Click(object sender, RoutedEventArgs e)
{
WpfWebClient.ServiceReferenceEHEC.ServiceClient client = new WpfWebClient.ServiceReferenceEHEC.ServiceClient();
2018-08-12 20:33:28 +02:00
// create new foodplace from user input
2018-08-06 23:25:32 +02:00
2018-08-12 20:33:28 +02:00
FoodPlace fp = new FoodPlace();
2018-08-06 23:25:32 +02:00
2018-08-19 18:37:09 +02:00
// check if any box is empty
2018-08-19 15:58:02 +02:00
2018-08-19 18:37:09 +02:00
if (ComboBoxFPCities.SelectedIndex == -1)
{
System.Windows.MessageBox.Show("Please select a city", "INFO", MessageBoxButton.OK, MessageBoxImage.Information);
}
if (txtFoodPlaceName.Text == null)
{
System.Windows.MessageBox.Show("Please enter a name for the food place", "INFO", MessageBoxButton.OK, MessageBoxImage.Information);
}
if (txtFoodPlaceHouseNumber.Text == null)
{
System.Windows.MessageBox.Show("Please enter a house number", "INFO", MessageBoxButton.OK, MessageBoxImage.Information);
}
if (txtFoodPlaceStreetName.Text == null)
{
System.Windows.MessageBox.Show("Please enter a street name", "INFO", MessageBoxButton.OK, MessageBoxImage.Information);
}
else
{
2018-08-12 20:33:28 +02:00
fp.Streetname = txtFoodPlaceStreetName.Text;
fp.Streetnumber = txtFoodPlaceHouseNumber.Text;
2018-08-19 15:58:02 +02:00
fp.Name = txtFoodPlaceName.Text;
2018-08-12 20:33:28 +02:00
fp.Description = txtFoodPlaceDescription.Text;
fp.City = (City)ComboBoxFPCities.SelectedValue;
2018-08-06 23:25:32 +02:00
2018-08-12 20:33:28 +02:00
client.WriteFoodPlace(fp);
2018-08-19 18:37:09 +02:00
// Show success msgbox
System.Windows.MessageBox.Show("Success", "INFO", MessageBoxButton.OK, MessageBoxImage.Information);
}
2018-08-06 23:25:32 +02:00
client.Close();
}
2018-07-01 15:32:50 +02:00
}
}