namespace _2024._05._27
{
    public partial class Form1 : Form
    {
        private List<string> list = new List<string>();
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            List<string> listABC = new List<string>();
            StreamReader sr = new StreamReader("oscar.csv");
            string line = sr.ReadLine();

            while (line != null)
            {
                list.Add(line);
                listABC.Add(line.Split(";")[1]);

                line = sr.ReadLine();
            }

            sr.Close();

            listABC.Sort();

            foreach (var i in listABC)
            {
                OscarAwardFilmsListBox.Items.Add(i);
            }
        }

        private async void NewFilmButton_Click(object sender, EventArgs e)
        {
            try
            {
                string name = NameTextBox.Text;
                int year = int.Parse(YearTextBox.Text);
                int jeloles = int.Parse(JelolesekTextBox.Text);
                int award = int.Parse(AwardTextBox.Text);

                using (StreamWriter w = File.AppendText("oscar.csv"))
                {
                    w.WriteLine($"{name};{year};{award};{jeloles}");
                }

                OscarAwardFilmsListBox.Items.Add(name);
                list.Add($"{name};{year};{award};{jeloles}");
            }

            catch
            {
                MessageBox.Show("Valamelyik adat hibás!");
            }
        }

        private void MostAwardFilmButton_Click(object sender, EventArgs e)
        {
            Dictionary<string, int> award = new Dictionary<string, int>();

            foreach (var i in list)
            {
                string[] currrentLine = i.Split(";");
                award.Add(currrentLine[1], int.Parse(currrentLine[3]));
            }
        }
    }
}