HF is almost done
This commit is contained in:
@@ -1,10 +1,13 @@
|
||||
using System;
|
||||
using Microsoft.Win32;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Controls.Primitives;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
@@ -18,11 +21,161 @@ namespace ValasztasGUI
|
||||
/// <summary>
|
||||
/// Interaction logic for MainWindow.xaml
|
||||
/// </summary>
|
||||
|
||||
public static class Eredmeny
|
||||
{
|
||||
public static List<Kepviselo> kepviselok = new List<Kepviselo>();
|
||||
}
|
||||
|
||||
public class Kepviselo
|
||||
{
|
||||
public int Kerulet;
|
||||
public int Szavazat;
|
||||
public string VezetekNev;
|
||||
public string KeresztNev;
|
||||
public string Part;
|
||||
|
||||
public Kepviselo(int kerulet, int szavazat,
|
||||
string vezetekNev, string keresztNev,
|
||||
string part)
|
||||
{
|
||||
this.Kerulet = kerulet;
|
||||
this.Szavazat = szavazat;
|
||||
this.VezetekNev = vezetekNev;
|
||||
this.KeresztNev = keresztNev;
|
||||
this.Part = part;
|
||||
}
|
||||
|
||||
public string adatokKiir()
|
||||
{
|
||||
return $"{this.VezetekNev};{this.KeresztNev};{this.Kerulet};{this.Part};{this.Szavazat}";
|
||||
}
|
||||
public static List<Kepviselo> LoadFromTxt(string path)
|
||||
{
|
||||
List<Kepviselo> kepviselok = new List<Kepviselo>();
|
||||
|
||||
FileStream fileStream = new FileStream(path, FileMode.Open, FileAccess.Read);
|
||||
StreamReader streamReader = new StreamReader(fileStream);
|
||||
|
||||
var lines = streamReader.ReadToEnd().Split('\n');
|
||||
|
||||
foreach (var item in lines)
|
||||
{
|
||||
string[] data = item.Split(' ');
|
||||
Kepviselo kepviselo = new Kepviselo(Convert.ToInt32(data[0]), Convert.ToInt32(data[1]), data[2], data[3], data[4]);
|
||||
kepviselok.Add(kepviselo);
|
||||
}
|
||||
|
||||
streamReader.Close();
|
||||
fileStream.Close();
|
||||
|
||||
return kepviselok;
|
||||
}
|
||||
|
||||
public static void SzavazatKiir(List<Kepviselo> kepviselok, string[] nev)
|
||||
{
|
||||
foreach (var item in kepviselok)
|
||||
{
|
||||
if (item.VezetekNev == nev[0] && item.KeresztNev == nev[1])
|
||||
{
|
||||
Console.WriteLine($"{item.VezetekNev} {item.KeresztNev} nevű képviselőjelölt {item.Szavazat} darab szavazatot kapott.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Console.WriteLine("Ilyen nevű képviselőjelölt nem szerepel a nyilvántartásban!");
|
||||
}
|
||||
|
||||
public static void Legtobb(List<Kepviselo> kepviselok)
|
||||
{
|
||||
List<Kepviselo> legjobbkepviselok = new List<Kepviselo>();
|
||||
Kepviselo kepviselo = kepviselok[0];
|
||||
|
||||
foreach (var item in kepviselok)
|
||||
{
|
||||
if (item.Szavazat > kepviselo.Szavazat)
|
||||
{
|
||||
kepviselo = item;
|
||||
}
|
||||
}
|
||||
|
||||
legjobbkepviselok.Add(kepviselo);
|
||||
|
||||
foreach (var item in kepviselok)
|
||||
{
|
||||
if (item.Szavazat == kepviselo.Szavazat && item.KeresztNev != kepviselo.KeresztNev && item.VezetekNev != kepviselo.VezetekNev)
|
||||
{
|
||||
legjobbkepviselok.Add(item);
|
||||
}
|
||||
}
|
||||
|
||||
string fuggetlen = "független";
|
||||
|
||||
foreach (var item in legjobbkepviselok)
|
||||
{
|
||||
Console.WriteLine($"" +
|
||||
$"A legtöbb szavazatot kapta: " +
|
||||
$"\t{item.VezetekNev} {item.KeresztNev} {(item.Part == "-" ? fuggetlen : item.Part)}");
|
||||
}
|
||||
}
|
||||
|
||||
public static void ValosztokeruletiGyoztesek(List<Kepviselo> kepviselok)
|
||||
{
|
||||
var asd = kepviselok.OrderBy(x => x.Szavazat).OrderBy(x => x.Kerulet).GroupBy(x => x.Kerulet);
|
||||
|
||||
StreamWriter streamWriter = new StreamWriter("kepviselok.txt", false);
|
||||
|
||||
foreach (var item in asd)
|
||||
{
|
||||
Kepviselo kepviselo = item.Last();
|
||||
streamWriter.WriteLine($"{kepviselo.Kerulet} {kepviselo.VezetekNev} {kepviselo.KeresztNev} {kepviselo.Part}");
|
||||
}
|
||||
|
||||
streamWriter.Close();
|
||||
}
|
||||
|
||||
}
|
||||
public partial class MainWindow : Window
|
||||
{
|
||||
public MainWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void MenuItem_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
this.Close();
|
||||
}
|
||||
|
||||
private void informatoin_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
|
||||
MessageBox.Show("Helyhatósági választásokat elemző program", "Névjegy");
|
||||
}
|
||||
|
||||
private void jeloltekListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void keruletButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void open_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
OpenFileDialog dialog = new OpenFileDialog();
|
||||
dialog.ShowDialog();
|
||||
|
||||
string path = dialog.FileName;
|
||||
|
||||
Eredmeny.kepviselok = Kepviselo.LoadFromTxt(path);
|
||||
|
||||
foreach (var item in Eredmeny.kepviselok)
|
||||
{
|
||||
jeloltekListBox.Items.Add(item.adatokKiir());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user