added doga
This commit is contained in:
156
20240422_doga/WindowsFormsApp1/Form1.cs
Normal file
156
20240422_doga/WindowsFormsApp1/Form1.cs
Normal file
@@ -0,0 +1,156 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using System.IO;
|
||||
|
||||
namespace WindowsFormsApp1
|
||||
{
|
||||
public partial class Form1 : Form
|
||||
{
|
||||
public Form1()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void Form1_Load(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void kilépésToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
this.Close();
|
||||
}
|
||||
|
||||
private void megnyitásToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
openFileDialog1.ShowDialog();
|
||||
Data.path = openFileDialog1.FileName;
|
||||
KepviselokBetoltes();
|
||||
}
|
||||
|
||||
public void KepviselokBetoltes()
|
||||
{
|
||||
FileStream fs = new FileStream(Data.path, FileMode.Open, FileAccess.Read);
|
||||
StreamReader streamReader = new StreamReader(fs);
|
||||
|
||||
string sor = streamReader.ReadLine();
|
||||
while (sor != null)
|
||||
{
|
||||
string[] elemek = sor.Split(' ');
|
||||
string nev =$"{elemek[2]} {elemek[3]}";
|
||||
string part = elemek[4];
|
||||
int szavazatok = Convert.ToInt32(elemek[1]);
|
||||
int kerulet = Convert.ToInt32(elemek[0]);
|
||||
Kepviselo kepviselo = new Kepviselo(nev, kerulet, szavazatok, part);
|
||||
Data.kepviselok.Add(kepviselo);
|
||||
|
||||
sor = streamReader.ReadLine();
|
||||
}
|
||||
|
||||
streamReader.Close();
|
||||
fs.Close();
|
||||
|
||||
foreach (var item in Data.kepviselok)
|
||||
{
|
||||
listBox1.Items.Add(item.nev);
|
||||
}
|
||||
}
|
||||
|
||||
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
Data.index = listBox1.SelectedIndex;
|
||||
textBox1.Text = Data.kepviselok[Data.index].nev;
|
||||
textBox2.Text = Data.kepviselok[Data.index].valasztokerulet.ToString();
|
||||
textBox3.Text = Data.kepviselok[Data.index].part;
|
||||
textBox4.Text = Data.kepviselok[Data.index].szavazatok.ToString();
|
||||
}
|
||||
|
||||
private void button1_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (listBox1.SelectedIndex == -1)
|
||||
{
|
||||
MessageBox.Show("Hiba! Nincs kiválasztott képviselő.");
|
||||
return;
|
||||
}
|
||||
|
||||
listBox2.Items.Clear();
|
||||
|
||||
int kerulet = Data.kepviselok[Data.index].valasztokerulet;
|
||||
|
||||
foreach (var item in Data.kepviselok)
|
||||
{
|
||||
if (item.valasztokerulet == kerulet)
|
||||
{
|
||||
string formatted = $"{item.nev} ({item.szavazatok} szavazat)";
|
||||
listBox2.Items.Add(formatted);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void súgóToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
MessageBox.Show($" Helyhatósági választásokat elemző program");
|
||||
|
||||
}
|
||||
|
||||
private void statisztikaToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void nyertesekToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
FileStream fs = new FileStream("nyertesek.txt", FileMode.Create, FileAccess.Write);
|
||||
StreamWriter streamWriter = new StreamWriter(fs);
|
||||
|
||||
//0: érték
|
||||
//1: index
|
||||
List<(int, int)> lista = new List<(int, int)>();
|
||||
|
||||
for (int i = 0; i < Data.kepviselok.Count; i++)
|
||||
{
|
||||
lista.Add((Data.kepviselok[i].szavazatok,i));
|
||||
}
|
||||
|
||||
lista.Sort();
|
||||
|
||||
for (int i = 0; i < 8; i++)
|
||||
{
|
||||
streamWriter.WriteLine(Data.kepviselok[lista[i].Item2].nev);
|
||||
}
|
||||
|
||||
streamWriter.Close();
|
||||
fs.Close();
|
||||
}
|
||||
}
|
||||
|
||||
public static class Data
|
||||
{
|
||||
public static string path;
|
||||
public static List<Kepviselo> kepviselok = new List<Kepviselo>();
|
||||
public static int index;
|
||||
}
|
||||
|
||||
public class Kepviselo
|
||||
{
|
||||
public string nev;
|
||||
public int valasztokerulet;
|
||||
public int szavazatok;
|
||||
public string part;
|
||||
|
||||
public Kepviselo(string nev, int valasztokerulet, int szavazatok, string part)
|
||||
{
|
||||
this.nev = nev;
|
||||
this.valasztokerulet = valasztokerulet;
|
||||
this.szavazatok = szavazatok;
|
||||
this.part = part;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user