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

121 lines
3.7 KiB
C#
Raw Permalink Normal View History

2018-06-03 17:24:48 +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;
using System.Windows.Navigation;
using System.Windows.Shapes;
2018-06-10 19:34:30 +02:00
using WpfWebClient.ServiceReferenceEHEC;
2018-08-19 15:58:20 +02:00
using WpfWebClient.Helper;
2018-06-03 17:24:48 +02:00
namespace WpfWebClient
{
/// <summary>
/// Interaction logic for Home.xaml
/// </summary>
public partial class Home : Page
{
public Home()
{
InitializeComponent();
2018-06-03 17:24:48 +02:00
}
2018-06-10 19:34:30 +02:00
private void btnRandomStrainGenerator_Click(object sender, RoutedEventArgs e)
{
// create new client connection
WpfWebClient.ServiceReferenceEHEC.ServiceClient client = new WpfWebClient.ServiceReferenceEHEC.ServiceClient();
2018-08-12 20:33:28 +02:00
// msgbox to confirm action
if (MessageBox.Show("This could take a while, are you sure?", "More strains?",
MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
{
2018-08-12 20:33:28 +02:00
// Get the number of words and letters per word.
int num_letters = int.Parse(txtNumLetters.Text);
int num_words = int.Parse(txtNumStrains.Text);
// Make an array of the letters we will use.
char[] letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".ToCharArray();
// Make a random number generator.
Random rand = new Random();
2018-08-12 20:33:28 +02:00
// Make the words.
for (int i = 1; i <= num_words; i++)
{
2018-08-12 20:33:28 +02:00
// Make a word.
string word = "";
for (int j = 1; j <= num_letters; j++)
{
// Pick a random number between 0 and 25
// to select a letter from the letters array.
int letter_num = rand.Next(2, letters.Length - 1);
2018-08-12 20:33:28 +02:00
// Append the letter.
word += letters[letter_num];
}
2018-08-12 20:33:28 +02:00
// Write the strains into a list
List<string> generatedStrains = new List<string>();
2018-08-12 20:33:28 +02:00
generatedStrains.Add(word);
2018-08-12 20:33:28 +02:00
foreach (var item in generatedStrains)
{
Strain s = new Strain();
s.Name = "EHEC-"+ item;
2018-08-12 20:33:28 +02:00
client.WriteStrain(s);
}
}
}
2018-08-12 20:33:28 +02:00
// Show success msgbox
System.Windows.MessageBox.Show("Success", "INFO", MessageBoxButton.OK, MessageBoxImage.Information);
client.Close();
2018-08-19 15:58:20 +02:00
}
private void btnCreateTestdata_Click(object sender, RoutedEventArgs e)
2018-08-19 15:58:20 +02:00
{
// create new client connection
WpfWebClient.ServiceReferenceEHEC.ServiceClient client = new WpfWebClient.ServiceReferenceEHEC.ServiceClient();
// create a bunch of foodplaces
2018-08-19 15:58:20 +02:00
var foodplaces = GenerateTestData.CreateFoodPlaces();
foreach (var f in foodplaces)
{
client.WriteFoodPlace(f);
}
// create a bunch of people at foodplaces
2018-09-02 18:28:24 +02:00
var patientsatfps = GenerateTestData.CreatePatientAtFoodPlaces(int.Parse(txtNumberofTestdata.Text));
2018-08-30 21:07:15 +02:00
foreach (var f in patientsatfps)
{
client.WriteRelation(f);
}
2018-08-19 15:58:20 +02:00
// Show success msgbox
System.Windows.MessageBox.Show("Success", "INFO", MessageBoxButton.OK, MessageBoxImage.Information);
2018-08-19 15:58:20 +02:00
client.Close();
2018-08-19 15:58:20 +02:00
}
2018-06-03 17:24:48 +02:00
}
}