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.Navigation;
using System.Windows.Shapes;
using System.IO;

namespace SimulazioneVerificaFile
{
    /// <summary>
    /// Logica di interazione per MainWindow.xaml
    /// </summary>
   
    public partial class MainWindow : Window
    {
        WpfListaAlunni liste;
        public MainWindow()
        {
            InitializeComponent();
            try
            {
                liste = new WpfListaAlunni("alunni.csv");
                lstIndirizzi.ItemsSource = liste.ElencoIndirizzi();
            }catch (Exception ex)
            {
                lblMessaggi.Content = ex.Message;
            }
            
        }

      private void lstIndirizzi_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            string indirizzo=lstIndirizzi.SelectedValue.ToString();
            lstClassi.ItemsSource = liste.ElencoClassi(indirizzo);
            lstAlunni.ItemsSource = null;
            lblDatiAlunno.Content = string.Empty;

        }

        private void lstClassi_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (lstClassi.SelectedValue != null)
            {
                string classe = lstClassi.SelectedValue.ToString();
                string indirizzo= lstIndirizzi.SelectedValue.ToString();
                lstAlunni.ItemsSource = liste.ElencoAlunni(classe,indirizzo);
            }
            else
            {
                lstAlunni.ItemsSource = null;
                lblDatiAlunno.Content = string.Empty;
            }
        }

        private void lstAlunni_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (lstAlunni.SelectedValue != null)
            {
                string matricola = lstAlunni.SelectedValue.ToString().Split('-')[0];
                lblDatiAlunno.Content = liste.DatiAlunno(matricola);
            }
            else
            {
                lstAlunni.ItemsSource = null;
                lblDatiAlunno.Content = string.Empty;
            }

        }

     }
}
