예제 #1
0
        private void Button_import(object sender, RoutedEventArgs e)
        {
            // gets all the seperatly parts of the CSV
            String[][] results = readCSV(getFile());

            Klasse     k = null;
            Teilnehmer t = null;

            // if i can read the CSV
            if (results != null)
            {
                // connect to the db
                using (var con = new DBKlassenliste())
                {
                    // get all the Klassen
                    List <Klasse> list = con.Klasse.ToList();

                    // for each line, save the entries
                    for (int i = 0; i < results.GetLength(0); i++)
                    {
                        // make a new Klasse
                        k             = new Klasse();
                        k.Bezeichnung = results[i][4];
                        k.Kuerzel     = results[i][5];
                        k.Jahr        = Int32.Parse(results[i][6]);

                        // check if its already in the db
                        if (!list.Contains(k))
                        {
                            // if its not in the db, insert it
                            con.Klasse.Add(k);
                        }

                        // make a new Teilnehmer
                        t              = new Teilnehmer();
                        t.Name         = results[i][0];
                        t.Vorname      = results[i][1];
                        t.Email        = results[i][2];
                        t.Geburtsdatum = DateTime.ParseExact(results[i][3], "dd/MM/yyyy", CultureInfo.CurrentCulture);
                        t.Klasse       = k;

                        // save the Teilnehmer
                        con.Teilnehmer.Add(t);

                        // insert everything needed in the db
                        con.SaveChanges();
                    }
                }
            }

            fillTreeView();
        }
예제 #2
0
        private void ok_Click(object sender, RoutedEventArgs e)
        {
            using (var con = new KlassenlisteEntities1())
            {
                Teilnehmer t = new Teilnehmer();
                t.Name         = name.Text;
                t.Vorname      = vorname.Text;
                t.Email        = email.Text;
                t.Geburtsdatum = geburtstag.SelectedDate;
                t.Klasse       = klasse.SelectedItem as Klasse;

                con.Teilnehmer.Add(t);
                con.SaveChanges();
            }

            this.Close();
        }
예제 #3
0
        private void Button_delete(object sender, RoutedEventArgs e)
        {
            // connect to the db
            using (var con = new DBKlassenliste())
            {
                // if something is selected in the TreeView
                if (treeView.SelectedItem != null)
                {
                    // if the selected item isn't null
                    Teilnehmer t = treeView.SelectedItem as Teilnehmer;
                    if (t != null)
                    {
                        // delete the Teilnehmer
                        con.Teilnehmer.Remove(t);
                        con.SaveChanges();

                        fillTreeView();
                    }
                }
            }
        }