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;

namespace _2024._04._28
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }

        private void StatisticFillButton_Click(object sender, EventArgs e)
        {
            listBox1.Items.Clear();

            List<string> lines = new List<string>();
            StreamReader file = new StreamReader("szavazatok.txt");
            string line = file.ReadLine();
            double voted = 0;

            double hep = 0;
            double gyep = 0;
            double tisz = 0;
            double zep = 0;
            double independent = 0;

            while (line != null)
            {
                lines.Add(line);
                line = file.ReadLine();
            }

            foreach (var i in lines)
            {
                string[] currentLine = i.Split(" ");
                voted += Convert.ToInt32(currentLine[1]);

                if (currentLine[4].Equals("HEP"))
                {
                    hep += Convert.ToInt32(currentLine[1]);
                }

                else if (currentLine[4].Equals("GYEP"))
                {
                    gyep += Convert.ToInt32(currentLine[1]);
                }

                else if (currentLine[4].Equals("TISZ"))
                {
                    tisz += Convert.ToInt32(currentLine[1]);
                }

                else if (currentLine[4].Equals("ZEP"))
                {
                    zep += Convert.ToInt32(currentLine[1]);
                }

                else
                {
                    independent += Convert.ToInt32(currentLine[1]);
                }

            }

            AllRepresentativeTextBox.Text = lines.Count.ToString();
            AllVotedPeopleTextBox.Text = voted.ToString();
            RatioTextBox.Text = Math.Round(voted / Convert.ToDouble(AllCitizenTextBox.Text) * 100, 2).ToString();
            listBox1.Items.Add($"Húsevők Pártja                                   {Math.Round(hep / voted * 100, 2)} %");
            listBox1.Items.Add($"Gyümölcsevők Pártja                        {Math.Round(gyep / voted * 100, 2)} %");
            listBox1.Items.Add($"Tejivók Szövetsége                             {Math.Round(tisz / voted * 100, 2)} %");
            listBox1.Items.Add($"Zöldségevők Pártja                            {Math.Round(zep / voted * 100, 2)} %");
            listBox1.Items.Add($"Független jelölt                                  {Math.Round(independent / voted * 100, 2)} %");
        }

        private void CloseButton_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
