示例#1
0
        public NewStudent(Studenti s)
        {
            InitializeComponent();
            foreach (var predmet in Form1.db.Predmetis)
            {
                checkedListBox1.Items.Add(predmet.Naziv);
            }
            this.student       = s;
            this.textBox1.Text = s.Id.ToString();
            this.textBox2.Text = s.Ime.Trim();
            this.textBox3.Text = s.Prezime.Trim();

            var studentiResult = from studenti in Form1.db.Studentis
                                 where s.Id == studenti.Id
                                 select studenti.Predmetis;

            foreach (var items in studentiResult)
            {
                foreach (var predmet in items)
                {
                    for (int i = 0; i < checkedListBox1.Items.Count; i++)
                    {
                        if (checkedListBox1.Items[i].ToString().Trim() == predmet.Naziv.Trim())
                        {
                            checkedListBox1.SetItemChecked(i, true);
                        }
                    }
                }
            }
        }
示例#2
0
 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);
     }
 }
示例#3
0
        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);
                }
            }
        }
示例#4
0
 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) { }
         }
     }
 }
示例#5
0
 public NewStudent()
 {
     InitializeComponent();
     student = new Studenti();
     foreach (var predmet in Form1.db.Predmetis)
     {
         checkedListBox1.Items.Add(predmet.Naziv.Trim());
     }
 }