private void button1_Click(object sender, EventArgs e) { if (comboBox1.SelectedItem == "Studenti") { NewStudent form = new NewStudent(); Studenti student = form.student; form.Text = "Dodaj studenta"; if (form.ShowDialog() == DialogResult.OK) { db.Studentis.Add(student); db.SaveChanges(); updateList(0); } } else if (comboBox1.SelectedItem == "Predmeti") { NewSubject form = new NewSubject(); Predmeti predmet = form.predmet; form.Text = "Dodaj predmet"; if (form.ShowDialog() == DialogResult.OK) { db.Predmetis.Add(predmet); db.SaveChanges(); updateList(1); } } }
private void izbrišiToolStripMenuItem_Click(object sender, EventArgs e) { if (comboBox1.SelectedItem == "Studenti") { Studenti s = (Studenti)listView1.SelectedItems[0].Tag; foreach (var predmet in s.Predmetis.ToList <Predmeti>()) { s.Predmetis.Remove(predmet); } db.Studentis.Remove(s); db.SaveChanges(); updateList(0); } else if (comboBox1.SelectedItem == "Predmeti") { Predmeti p = (Predmeti)listView1.SelectedItems[0].Tag; foreach (var student in p.Studentis.ToList <Studenti>()) { p.Studentis.Remove(student); } db.Predmetis.Remove(p); db.SaveChanges(); updateList(1); } }
public NewSubject(Predmeti p) { InitializeComponent(); this.predmet = p; this.textBox1.Text = p.Id.ToString(); this.textBox2.Text = p.Naziv.Trim(); foreach (var student in Form1.db.Studentis) { checkedListBox1.Items.Add(student.ToString()); } var predmetiResult = from predmet in Form1.db.Predmetis where predmet.Id == p.Id select predmet.Studentis; foreach (var items in predmetiResult) { foreach (var student in items) { for (int i = 0; i < checkedListBox1.Items.Count; i++) { string[] id = checkedListBox1.Items[i].ToString().Split(new char[] { '(', ')' }); if (student.Id.ToString() == id[1]) { checkedListBox1.SetItemChecked(i, true); } } } } }
private void urediToolStripMenuItem_Click(object sender, EventArgs e) { if (comboBox1.SelectedItem == "Studenti") { Studenti s = (Studenti)listView1.SelectedItems[0].Tag; // var student = db.Studentis.First<Studenti>(q => q.Id == s.Id); NewStudent form = new NewStudent(s); if (form.ShowDialog() == DialogResult.OK) { try { db.SaveChanges(); updateList(0); } catch (Exception ex) { } } } else if (comboBox1.SelectedItem == "Predmeti") { Predmeti p = (Predmeti)listView1.SelectedItems[0].Tag; NewSubject form = new NewSubject(p); if (form.ShowDialog() == DialogResult.OK) { try { db.SaveChanges(); updateList(1); } catch (Exception ex) { } } } }
public NewSubject() { predmet = new Predmeti(); InitializeComponent(); }