finished HW #1
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
<Window x:Class="ValasztasGUI.View.Statisztika"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:local="clr-namespace:ValasztasGUI.View"
|
||||
mc:Ignorable="d"
|
||||
Title="Statisztika" Height="450" Width="800">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="10*"></RowDefinition>
|
||||
<RowDefinition Height="10*"></RowDefinition>
|
||||
<RowDefinition Height="10*"></RowDefinition>
|
||||
<RowDefinition Height="10*"></RowDefinition>
|
||||
<RowDefinition Height="10*"></RowDefinition>
|
||||
<RowDefinition Height="40*"></RowDefinition>
|
||||
<RowDefinition Height="10*"></RowDefinition>
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition></ColumnDefinition>
|
||||
<ColumnDefinition></ColumnDefinition>
|
||||
<ColumnDefinition></ColumnDefinition>
|
||||
<ColumnDefinition></ColumnDefinition>
|
||||
<ColumnDefinition></ColumnDefinition>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Label Grid.Row="0" Grid.Column="1" Grid.ColumnSpan="3">
|
||||
Összes szavazásra jogosultpolgár száma:
|
||||
</Label>
|
||||
<TextBox Grid.Row="0" Grid.Column="4" Margin="10" Name="szavazasraJogosultakSzamaTextBox">
|
||||
|
||||
</TextBox>
|
||||
|
||||
<Button Grid.Row="1" Grid.Column="4" Content="Statisztika kitöltése" Margin="10" Name="szavazasraJogosultakSzamaButton" Click="szavazasraJogosultakSzamaButton_Click">
|
||||
|
||||
</Button>
|
||||
|
||||
<Label Grid.Row="2" Grid.Column="1" Grid.ColumnSpan="3">
|
||||
Az induló képviselőjelöltek száma:
|
||||
</Label>
|
||||
<TextBox Grid.Row="2" Grid.Column="4" Margin="10" Name="kepviselokSzamaTextBox">
|
||||
|
||||
</TextBox>
|
||||
|
||||
<Label Grid.Row="3" Grid.Column="0" VerticalAlignment="Center">
|
||||
A választáson szavazott (fő):
|
||||
</Label>
|
||||
<TextBox Grid.Row="3" Grid.Column="1" Margin="10" Name="szavazottakTextBox"></TextBox>
|
||||
<Label Grid.Row="3" Grid.Column="2" VerticalAlignment="Center" HorizontalAlignment="Center">
|
||||
ez a jogosultak
|
||||
</Label>
|
||||
<TextBox Grid.Row="3" Grid.Column="3" Margin="10" Name="szazalekTextBox"></TextBox>
|
||||
<Label Grid.Row="3" Grid.Column="4" VerticalAlignment="Center" HorizontalAlignment="Center">
|
||||
%-a
|
||||
</Label>
|
||||
|
||||
<Label Grid.Row="4" Grid.Column="0" VerticalAlignment="Top" HorizontalAlignment="Left" Grid.ColumnSpan="3">
|
||||
Az egyes pártokra leadott szavazatok aránya:
|
||||
</Label>
|
||||
<ListBox Grid.Row="5" Grid.Column="0" Grid.ColumnSpan="3" Name="szavazatiaranyokListBox">
|
||||
|
||||
</ListBox>
|
||||
|
||||
<Button Grid.Row="6" Grid.Column="2" Margin="10" Content="Bezár" Click="Button_Click">
|
||||
</Button>
|
||||
</Grid>
|
||||
</Window>
|
||||
@@ -0,0 +1,66 @@
|
||||
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.Shapes;
|
||||
|
||||
namespace ValasztasGUI.View
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for Statisztika.xaml
|
||||
/// </summary>
|
||||
public partial class Statisztika : Window
|
||||
{
|
||||
public Statisztika()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void Button_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
this.Close();
|
||||
}
|
||||
|
||||
private void szavazasraJogosultakSzamaButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
bool szam = Int32.TryParse(szavazasraJogosultakSzamaTextBox.Text, out int result );
|
||||
|
||||
if (!szam)
|
||||
{
|
||||
MessageBox.Show("Hiba az összes jogosult megadásában!", "Hiba", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
kepviselokSzamaTextBox.Text = $"{Eredmeny.kepviselok.Count}";
|
||||
|
||||
int totalszavazatok = Eredmeny.kepviselok.Sum(x => x.Szavazat);
|
||||
szavazottakTextBox.Text = $"{totalszavazatok}";
|
||||
|
||||
double szazalek = ((double)totalszavazatok / (double)result) * 100;
|
||||
szazalekTextBox.Text = szazalek.ToString("0.##");
|
||||
|
||||
|
||||
var partokTeljesitmenye = Eredmeny.kepviselok.GroupBy(x => x.Part).Select(g => new
|
||||
{
|
||||
Part = g.Key,
|
||||
Szazalek = ((double)g.Count() / (double)totalszavazatok) * 10000
|
||||
})
|
||||
.OrderByDescending(x => x.Szazalek)
|
||||
.Select(x => (x.Part, x.Szazalek))
|
||||
.ToList();
|
||||
|
||||
foreach (var item in partokTeljesitmenye)
|
||||
{
|
||||
szavazatiaranyokListBox.Items.Add($"{(item.Part == "-" ? "független" : item.Part)} {item.Szazalek.ToString("0.##")}%");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user