private void Btn_SubTable_Add(object sender, RoutedEventArgs e) { TableBase table; switch (SelectedMain) { case Firma f: table = new Divizia(); f.SubTable.Add((Divizia)table); break; case Divizia d: table = new Projekt(); d.SubTable.Add((Projekt)table); break; case Projekt p: table = new Oddelenie(); p.SubTable.Add((Oddelenie)table); break; default: throw new ArgumentOutOfRangeException(); } _db.SaveChanges(); _mainWindow.Show(table); }
public override void obnova_dat() { if (select_text != "") { sql_cmd.CommandText = select_text; select_text = ""; } else { sql_cmd.CommandText = "Select * From Divizia"; } listBox.Items.Add(sql_cmd.CommandText); List <Divizia> diviz = new List <Divizia>(); try { using (DbDataReader dataReader = sql_cmd.ExecuteReader()) { while (dataReader.Read()) { Divizia divizia = new Divizia(); divizia.Divizia_id = int.Parse($"{dataReader["divizia_id"]}"); divizia.Firma_id = int.Parse($"{dataReader["firma_id"]}"); divizia.Divizia_nazov = $"{dataReader["divizia_nazov"]}"; divizia.Divizia_veduci = $"{dataReader["divizia_veduci"]}"; diviz.Add(divizia); } } } catch { MessageBox.Show("Zadal si zle udaje"); } dataGrid.DataSource = diviz; }