public void AddButtonActions(params Button[] buttons) { buttons[0].Click += (sender, args) => { NalogSluzbenikaDialog nalogSluzbenikaDialog = new NalogSluzbenikaDialog(null); nalogSluzbenikaDialog.ShowDialog(); Load_Data(); }; buttons[1].Click += (sender, args) => { var dataGridSelectedItems = DataGrid.SelectedItems; using (var ersteModel = new ErsteModel()) { foreach (var dataGridSelectedItem in dataGridSelectedItems) { var sluzbenikRemove = ersteModel.sluzbenici.Find(((sluzbenik)dataGridSelectedItem).Id); if (sluzbenikRemove?.osoba != null) { ersteModel.osobe.Remove(sluzbenikRemove.osoba); ersteModel.SaveChanges(); } } } Load_Data(); }; }
public void AddButtonActions(params Button[] buttons) { buttons[0].Click += (sender, args) => { EvidencijaProfesoraDialog evidencijaProfesoraDialog = new EvidencijaProfesoraDialog(null); evidencijaProfesoraDialog.ShowDialog(); Load_Data(); }; buttons[1].Click += (sender, args) => { var dataGridSelectedItems = DataGrid.SelectedItems; using (var ersteModel = new ErsteModel()) { foreach (var dataGridSelectedItem in dataGridSelectedItems) { var profesorRemove = ersteModel.profesori.Find(((profesor)dataGridSelectedItem).Id); if (profesorRemove?.osoba != null) { ersteModel.osobe.Remove(profesorRemove.osoba); ersteModel.SaveChanges(); } } } Load_Data(); }; }
private void DodavanjePolaznika_OnSelectionChanged(object sender, SelectionChangedEventArgs e) { Func <string, string[]> parser = s => { string[] result = new string[3]; var splittedString = s.Split(' '); if (splittedString.Length >= 3) { result[2] = splittedString[splittedString.Length - 1].Substring(1, splittedString[splittedString.Length - 1].Length - 2); result[1] = splittedString[splittedString.Length - 2]; result[0] = splittedString.Take(splittedString.Length - 2).Aggregate("", (acc, x) => acc + x);; } return(result); }; if (flag) { using (ErsteModel ersteModel = new ErsteModel()) { if (e.AddedItems.Count > 0) { string text = e.AddedItems[0].ToString(); var p = parser(text); string ime = p[0]; string prezime = p[1]; string email = p[2]; polaznik polaznik = ersteModel.polaznici.First(g => g.osoba.Ime == ime && g.osoba.Prezime == prezime && g.osoba.Email == email); grupa grupica = ersteModel.grupe.Where(gr => gr.Id == grupa.Id).ToList().First(); grupica.polaznici.Add(polaznik); polaznik.grupe.Add(grupica); string odabraniNivo = NivoKursa.Text; string odabraniJezik = jezikKursa.Text; polaznik_na_cekanju p_na_c = polaznik.polaznik_na_cekanju; kurs kurs_za_p_na_c = p_na_c.kursevi.First(k => k.Nivo.Equals(odabraniNivo) && k.jezik.Naziv.Equals(odabraniJezik)); kurs_za_p_na_c.polaznici_na_cekanju.Remove(p_na_c); p_na_c.kursevi.Remove(kurs_za_p_na_c); p_na_c.polaznik.polaznik_na_cekanju = null; ersteModel.SaveChanges(); Init(); NazivGrupeCombo.Text = text; } } } }
private void ObrisiKurs() { try { using (var ersteModel = new ErsteModel()) { kurs kurs_remove = ersteModel.kursevi.Find(kurs.Id); ersteModel.kursevi.Remove(kurs_remove); ersteModel.SaveChanges(); } MessageBox.Show("Kurs je uspješno obrisan."); Close(); } catch (Exception ex) { MessageBox.Show("MySQL Exception: " + ex.ToString()); } }
private void ObrisiKandidata() { try { using (var ersteModel = new ErsteModel()) { polaznik polaznikRemove = ersteModel.polaznici.Find(polaznik.Id); if (polaznikRemove?.osoba != null) { ersteModel.osobe.Remove(polaznikRemove.osoba); ersteModel.SaveChanges(); } } Close(); } catch (Exception ex) { MessageBox.Show("MySQL Exception: " + ex.ToString()); } }
private void ObrisiSluzbenika() { try { using (var ersteModel = new ErsteModel()) { sluzbenik sluzbenik_remove = ersteModel.sluzbenici.Find(sluzbenik.Id); if (sluzbenik_remove.osoba != null) { ersteModel.osobe.Remove(sluzbenik_remove.osoba); ersteModel.SaveChanges(); } } MessageBox.Show("Korisnik je uspješno obrisan."); Close(); } catch (Exception ex) { MessageBox.Show("MySQL Exception: " + ex.ToString()); } }
private void ObrisiProfesora() { try { using (var ersteModel = new ErsteModel()) { profesor profesor_remove = ersteModel.profesori.Find(profesor.Id); if (profesor_remove.osoba != null) { ersteModel.osobe.Remove(profesor_remove.osoba); ersteModel.SaveChanges(); } } MessageBox.Show("Korisnik je uspješno obrisan."); Close(); } catch (Exception ex) { MessageBox.Show("MySQL Exception: " + ex.ToString()); } }
private void DodavanjeTermina_OnSelectionChanged(object sender, SelectionChangedEventArgs e) { Func <string, (string, int, int, int, int)> parser = s => { var splittedString = s.Split(' '); string date = splittedString[1]; var niz = date.Substring(1, date.Length - 2).Split('-'); string[] ar1 = niz[0].Split(':'); string[] ar2 = niz[1].Split(':'); return(splittedString[0], int.Parse(ar1[0]), int.Parse(ar1[1]), int.Parse(ar2[0]), int.Parse(ar2[1])); }; if (flag) { using (ErsteModel ersteModel = new ErsteModel()) { if (e.AddedItems.Count > 0) { string text = e.AddedItems[0].ToString(); var p = parser(text); string dan = p.Item1; int sat1 = p.Item2; int min1 = p.Item3; int sat2 = p.Item4; int min2 = p.Item5; termin termin = ersteModel.termini.First(t => t.Dan == dan && t.Od.Hours == sat1 && t.Od.Minutes == min1 && t.Do.Hours == sat2 && t.Do.Minutes == min2); grupa grupica = ersteModel.grupe.Where(gr => gr.Id == grupa.Id).ToList().First(); grupica.termini.Add(termin); termin.grupa = grupica; ersteModel.SaveChanges(); Init(); NazivGrupeCombo.Text = text; } } } }
private void DodavanjeProfesora_OnSelectionChanged(object sender, SelectionChangedEventArgs e) { Func <string, string[]> parser = s => { string[] result = new string[3]; var splittedString = s.Split(' '); if (splittedString.Length >= 3) { result[2] = splittedString[splittedString.Length - 1].Substring(1, splittedString[splittedString.Length - 1].Length - 2); result[1] = splittedString[splittedString.Length - 2]; result[0] = splittedString.Take(splittedString.Length - 2).Aggregate("", (acc, x) => acc + x);; } return(result); }; if (flag) { using (ErsteModel ersteModel = new ErsteModel()) { if (e.AddedItems.Count > 0) { string text = e.AddedItems[0].ToString(); var p = parser(text); string ime = p[0]; string prezime = p[1]; string email = p[2]; profesor profesor = ersteModel.profesori.First(g => g.osoba.Ime == ime && g.osoba.Prezime == prezime && g.osoba.Email == email); grupa grupica = ersteModel.grupe.Where(gr => gr.Id == grupa.Id).ToList().First(); grupica.profesori.Add(profesor); profesor.grupe.Add(grupica); ersteModel.SaveChanges(); Init(); NazivGrupeCombo.Text = text; } } } }
public void AddButtonActions(params Button[] buttons) { buttons[0].Click += (sender, args) => { EvidencijaKursaDialog evidencijaKursaDialog = new EvidencijaKursaDialog(null); evidencijaKursaDialog.ShowDialog(); Load_Data(); }; buttons[1].Click += (sender, args) => { var dataGridSelectedItems = DataGrid.SelectedItems; using (var ersteModel = new ErsteModel()) { foreach (var dataGridSelectedItem in dataGridSelectedItems) { var kursRemove = ersteModel.kursevi.Find(((kurs)dataGridSelectedItem).Id); ersteModel.kursevi.Remove(kursRemove); ersteModel.SaveChanges(); } } Load_Data(); }; }
private void Apply_Btn_Click(object sender, RoutedEventArgs e) { ResetBorderColors(); string odabraniJezik = (string)chb_Jezik.SelectedItem; string odabraniNivo = (string)chb_Nivo.SelectedItem; if (string.IsNullOrEmpty(textBox_Ime.Text) || string.IsNullOrEmpty(textBox_Prezime.Text) || string.IsNullOrEmpty(textBox_Email.Text) || string.IsNullOrEmpty(textBox_BrojTelefona.Text) || string.IsNullOrEmpty(odabraniJezik) || string.IsNullOrWhiteSpace(odabraniNivo)) { MessageBox.Show("Sva polja za unos moraju biti popunjena."); var textBoxes = grid.Children.OfType <TextBox>(); foreach (var t in textBoxes) { if (String.IsNullOrEmpty(t.Text)) { t.BorderBrush = Brushes.Red; } } if (string.IsNullOrEmpty(odabraniJezik)) { chb_Jezik.BorderBrush = Brushes.Red; } else if (string.IsNullOrWhiteSpace(odabraniNivo)) { chb_Nivo.BorderBrush = Brushes.Red; } return; } if (!GrupeDataGrid.Items.IsEmpty && (GrupeDataGrid.SelectedItems == null || GrupeDataGrid.SelectedItems.Count == 0)) { MessageBox.Show("Izaberite grupu iz tabele."); return; } var ersteModel = new ErsteModel(); osoba o = new osoba(); o.Ime = textBox_Ime.Text; o.Prezime = textBox_Prezime.Text; o.BrojTelefona = textBox_BrojTelefona.Text; o.Email = textBox_Email.Text; polaznik p = new polaznik(); p.osoba = o; if (!GrupeDataGrid.Items.IsEmpty) { GrupaKursZapis zapis = (GrupaKursZapis)GrupeDataGrid.SelectedItem; grupa zapisGrupa = (from g in ersteModel.grupe where g.Id == zapis.Grupa.Id select g).First(); p.grupe.Add(zapisGrupa); zapisGrupa.polaznici.Add(p); MessageBox.Show("Uspjesno dodan polaznik."); ersteModel.SaveChanges(); ersteModel.Dispose(); } else { polaznik_na_cekanju pnc = new polaznik_na_cekanju(); pnc.polaznik = p; pnc.Id = p.Id; // RAZMISLI O OVOME, KAKO MAPIRATI POLAZNIKE PO KURSEVIMA RAZLICITIH DATUMA var kursLista = (from k in ersteModel.kursevi join j in ersteModel.jezici on k.JezikId equals j.Id where k.Nivo.Equals(odabraniNivo) && j.Naziv.Equals(odabraniJezik) && k.DatumDo.CompareTo(DateTime.Now) > 0 orderby k.DatumDo descending select k).ToList(); kurs kurs = kursLista.First(); IEnumerable <polaznik_na_cekanju> polazniciNaCekanjuZaTrazeniKurs = kursLista.SelectMany(k => k.polaznici_na_cekanju).ToList(); //List<polaznik_na_cekanju> polazniciNaCekanjuZaTrazeniKurs = new List<polaznik_na_cekanju>(); //foreach (kurs k in kursLista) //{ // polazniciNaCekanjuZaTrazeniKurs.AddRange(k.polaznici_na_cekanju); //} if (polazniciNaCekanjuZaTrazeniKurs.Count() >= 2) { //nova grupa grupa g = new grupa { KursId = kurs.Id, BrojClanova = 0, }; ersteModel.SaveChanges(); //unos podataka o novoj grupi UpisTerminaGrupe upisTermina = new UpisTerminaGrupe(g, ersteModel); upisTermina.ShowDialog(); if (g.Naziv == null) { Task.Run(() => MessageBox.Show("Unesite naziv grupe.")); upisTermina = new UpisTerminaGrupe(g, ersteModel); upisTermina.ShowDialog(); } g = (from gr in ersteModel.grupe where gr.Id == g.Id select gr).First(); //dobijanje ref na polaznike i polaznika na cekanju List <polaznik> polazniciNoveGrupe = new List <polaznik>(); polazniciNoveGrupe.Add(p); foreach (polaznik_na_cekanju p_na_c in polazniciNaCekanjuZaTrazeniKurs) { polazniciNoveGrupe.Add(p_na_c.polaznik); } //brisanje korisnika na cekanju i veza s kursevima foreach (polaznik_na_cekanju p_na_c in polazniciNaCekanjuZaTrazeniKurs) { kurs kurs_za_p_na_c = p_na_c.kursevi.First(k => k.Nivo.Equals(odabraniNivo) && k.jezik.Naziv.Equals(odabraniJezik)); kurs_za_p_na_c.polaznici_na_cekanju.Remove(p_na_c); p_na_c.kursevi.Remove(kurs_za_p_na_c); p_na_c.polaznik.polaznik_na_cekanju = null; } //dodavanje polaznika u grupu foreach (polaznik p_u_g in polazniciNoveGrupe) { p_u_g.grupe.Add(g); g.polaznici.Add(p_u_g); } //dodavanje grupe u tabelu //ersteModel.grupe.Add(g); MessageBox.Show("Polaznik uspjesno ubacen u grupu.Polaznici na cekanju za odabrani kurs i nivo su takodje uspjesno ubaceni u grupu."); ersteModel.SaveChanges(); ersteModel.Dispose(); } else { kurs.polaznici_na_cekanju.Add(pnc); pnc.kursevi.Add(kurs); MessageBox.Show("Polaznik dodat na listu cekanja za odabrani kurs i jezik."); ersteModel.SaveChanges(); ersteModel.Dispose(); } } }
private void Button1_Click(object sender, RoutedEventArgs e) { ResetBorderColors(); if (sluzbenik != null) { if (!izmjena) { textBox_Ime.IsEnabled = true; textBox_Prezime.IsEnabled = true; textBox_Email.IsEnabled = true; textBox_BrojTelefona.IsEnabled = true; textBox_KorisnickoIme.IsEnabled = true; textBox_Lozinka.IsEnabled = true; textBox_LozinkaProvjera.IsEnabled = true; Button1.Content = uredu; Button2.Content = otkazi; izmjena = true; } else { if (!String.IsNullOrEmpty(textBox_Ime.Text) && !String.IsNullOrEmpty(textBox_Prezime.Text) && !String.IsNullOrEmpty(textBox_Email.Text) && !String.IsNullOrEmpty(textBox_BrojTelefona.Text) && !String.IsNullOrEmpty(textBox_KorisnickoIme.Text) && textBox_Lozinka.Password.Equals(textBox_LozinkaProvjera.Password)) { try { using (var ersteModel = new ErsteModel()) { sluzbenik = ersteModel.sluzbenici.Find(sluzbenik.Id); sluzbenik.osoba.Ime = textBox_Ime.Text; sluzbenik.osoba.Prezime = textBox_Prezime.Text; sluzbenik.osoba.Email = textBox_Email.Text; sluzbenik.osoba.BrojTelefona = textBox_BrojTelefona.Text; sluzbenik.KorisnickoIme = textBox_KorisnickoIme.Text; if (!String.IsNullOrEmpty(textBox_Lozinka.Password)) { HashGenerator hashGenerator = new HashGenerator(); sluzbenik.LozinkaHash = hashGenerator.ComputeHash(textBox_Lozinka.Password); } ersteModel.SaveChanges(); MessageBox.Show("Korisnik je uspješno izmijenjen."); Close(); } } catch (Exception ex) { MessageBox.Show("MySQL Exception: " + ex.ToString()); } } else { if (!textBox_Lozinka.Password.Equals(textBox_LozinkaProvjera.Password)) { MessageBox.Show("Lozinke moraju biti iste."); } else { MessageBox.Show("Sva polja moraju biti popunjena."); var textBoxes = grid.Children.OfType <TextBox>(); foreach (var t in textBoxes) { if (String.IsNullOrEmpty(t.Text)) { t.BorderBrush = Brushes.Red; } } } } } } else { if (!String.IsNullOrEmpty(textBox_Ime.Text) && !String.IsNullOrEmpty(textBox_Prezime.Text) && !String.IsNullOrEmpty(textBox_Email.Text) && !String.IsNullOrEmpty(textBox_BrojTelefona.Text) && !String.IsNullOrEmpty(textBox_KorisnickoIme.Text) && textBox_Lozinka.Password.Equals(textBox_LozinkaProvjera.Password)) { sluzbenik sluzbenik = new sluzbenik(); sluzbenik.osoba = new osoba(); sluzbenik.osoba.Ime = textBox_Ime.Text; sluzbenik.osoba.Prezime = textBox_Prezime.Text; sluzbenik.osoba.Email = textBox_Email.Text; sluzbenik.osoba.BrojTelefona = textBox_BrojTelefona.Text; sluzbenik.KorisnickoIme = textBox_KorisnickoIme.Text; HashGenerator hashGenerator = new HashGenerator(); sluzbenik.LozinkaHash = hashGenerator.ComputeHash(textBox_Lozinka.Password); try { using (var ersteModel = new ErsteModel()) { ersteModel.sluzbenici.Add(sluzbenik); ersteModel.SaveChanges(); Close(); } } catch (Exception ex) { MessageBox.Show("MySQL Exception: " + ex.ToString()); } } else { if (!textBox_Lozinka.Password.Equals(textBox_LozinkaProvjera.Password)) { MessageBox.Show("Lozinke moraju biti iste."); } else { MessageBox.Show("Sva polja moraju biti popunjena."); var textBoxes = grid.Children.OfType <TextBox>(); foreach (var t in textBoxes) { if (String.IsNullOrEmpty(t.Text)) { t.BorderBrush = Brushes.Red; } } } } } }
private void Button_Uredu_Click(object sender, RoutedEventArgs e) { ResetBorderColors(); if (!izmjena) { textBox_Ime.IsEnabled = true; textBox_Prezime.IsEnabled = true; textBox_Email.IsEnabled = true; textBox_BrojTelefona.IsEnabled = true; Button_Uredu.Content = uredu; Button_Otkazi.Content = otkazi; izmjena = true; } else { if (!string.IsNullOrEmpty(textBox_Ime.Text) && !string.IsNullOrEmpty(textBox_Prezime.Text) && !string.IsNullOrEmpty(textBox_Email.Text) && !string.IsNullOrEmpty(textBox_BrojTelefona.Text)) { if (polaznik != null) { try { using (var ersteModel = new ErsteModel()) { polaznik = ersteModel.polaznici.Find(polaznik.Id) ?? new polaznik(); polaznik.osoba.Ime = textBox_Ime.Text; polaznik.osoba.Prezime = textBox_Prezime.Text; polaznik.osoba.Email = textBox_Email.Text; polaznik.osoba.BrojTelefona = textBox_BrojTelefona.Text; // dodati još šta ima polaznik ersteModel.SaveChanges(); } } catch (Exception ex) { MessageBox.Show("MySQL Exception: " + ex.ToString()); } } else { polaznik polaznik = new polaznik(); polaznik.osoba = new osoba(); polaznik.osoba.Ime = textBox_Ime.Text; polaznik.osoba.Prezime = textBox_Prezime.Text; polaznik.osoba.Email = textBox_Email.Text; polaznik.osoba.BrojTelefona = textBox_BrojTelefona.Text; try { using (var ersteModel = new ErsteModel()) { ersteModel.polaznici.Add(polaznik); ersteModel.SaveChanges(); } } catch (Exception ex) { MessageBox.Show("MySQL Exception: " + ex.ToString()); } } Close(); } else { if (string.IsNullOrEmpty(textBox_Ime.Text) || string.IsNullOrEmpty(textBox_Prezime.Text) || string.IsNullOrEmpty(textBox_Email.Text) || string.IsNullOrEmpty(textBox_BrojTelefona.Text)) { MessageBox.Show("Sva polja moraju biti popunjena."); var textBoxes = grid.Children.OfType <TextBox>(); foreach (var t in textBoxes) { if (String.IsNullOrEmpty(t.Text)) { t.BorderBrush = Brushes.Red; } } } } } }
private void Button1Click(object sender, RoutedEventArgs e) { ResetBorderColors(); if (profesor != null) { if (!izmjena) { textBox_Ime.IsEnabled = true; textBox_Prezime.IsEnabled = true; textBox_Email.IsEnabled = true; textBox_BrojTelefona.IsEnabled = true; Button1.Content = uredu; Button2.Content = otkazi; izmjena = true; } else { if (!String.IsNullOrEmpty(textBox_Ime.Text) && !String.IsNullOrEmpty(textBox_Prezime.Text) && !String.IsNullOrEmpty(textBox_Email.Text) && !String.IsNullOrEmpty(textBox_BrojTelefona.Text)) { try { using (var ersteModel = new ErsteModel()) { profesor = ersteModel.profesori.Find(profesor.Id); profesor.osoba.Ime = textBox_Ime.Text; profesor.osoba.Prezime = textBox_Prezime.Text; profesor.osoba.Email = textBox_Email.Text; profesor.osoba.BrojTelefona = textBox_BrojTelefona.Text; ersteModel.SaveChanges(); MessageBox.Show("Korisnik je uspješno izmijenjen."); Close(); } } catch (Exception ex) { MessageBox.Show("MySQL Exception: " + ex.ToString()); } } else { MessageBox.Show("Sva polja moraju biti popunjena."); var textBoxes = grid.Children.OfType <TextBox>(); foreach (var t in textBoxes) { if (String.IsNullOrEmpty(t.Text)) { t.BorderBrush = Brushes.Red; } } } } } else { if (!String.IsNullOrEmpty(textBox_Ime.Text) && !String.IsNullOrEmpty(textBox_Prezime.Text) && !String.IsNullOrEmpty(textBox_Email.Text) && !String.IsNullOrEmpty(textBox_BrojTelefona.Text)) { profesor profesor = new profesor(); profesor.osoba = new osoba(); profesor.osoba.Ime = textBox_Ime.Text; profesor.osoba.Prezime = textBox_Prezime.Text; profesor.osoba.Email = textBox_Email.Text; profesor.osoba.BrojTelefona = textBox_BrojTelefona.Text; try { using (var ersteModel = new ErsteModel()) { ersteModel.profesori.Add(profesor); ersteModel.SaveChanges(); Close(); } } catch (Exception ex) { MessageBox.Show("MySQL Exception: " + ex.ToString()); } } else { MessageBox.Show("Sva polja moraju biti popunjena."); var textBoxes = grid.Children.OfType <TextBox>(); foreach (var t in textBoxes) { if (String.IsNullOrEmpty(t.Text)) { t.BorderBrush = Brushes.Red; } } } } }
private void Button1_Click(object sender, RoutedEventArgs e) { ResetBorderColors(); if (kurs != null) { if (!izmjena) { comboBox_Jezik.IsEnabled = true; textBox_Nivo.IsEnabled = true; TimePickerOd.IsEnabled = true; TimePickerDo.IsEnabled = true; Button1.Content = uredu; Button2.Content = otkazi; izmjena = true; } else { if (!String.IsNullOrEmpty(textBox_Nivo.Text) && comboBox_Jezik.SelectedIndex != -1 && TimePickerOd.SelectedDate != null && TimePickerDo.SelectedDate != null) { try { using (var ersteModel = new ErsteModel()) { kurs = ersteModel.kursevi.Find(kurs.Id); kurs.Nivo = textBox_Nivo.Text; kurs.JezikId = (comboBox_Jezik.SelectedItem as jezik).Id; kurs.DatumOd = TimePickerOd.SelectedDate.Value; kurs.DatumDo = TimePickerDo.SelectedDate.Value; ersteModel.SaveChanges(); MessageBox.Show("Kurs je uspješno izmijenjen."); Close(); } } catch (Exception ex) { MessageBox.Show("Greška. Pokušajte ponovo kasnije."); } } else { MessageBox.Show("Sva polja moraju biti popunjena."); var textBoxes = grid.Children.OfType <TextBox>(); foreach (var t in textBoxes) { if (String.IsNullOrEmpty(t.Text)) { t.BorderBrush = Brushes.Red; } } if (TimePickerOd.SelectedDate == null) { TimePickerOd.BorderBrush = Brushes.Red; } if (TimePickerDo.SelectedDate == null) { TimePickerDo.BorderBrush = Brushes.Red; } if (comboBox_Jezik.SelectedIndex == -1) { comboBox_Jezik.BorderBrush = Brushes.Red; } } } } else { if (!String.IsNullOrEmpty(textBox_Nivo.Text) && comboBox_Jezik.SelectedIndex != -1 && TimePickerOd.SelectedDate != null && TimePickerDo.SelectedDate != null) { kurs kurs = new kurs(); kurs.Nivo = textBox_Nivo.Text; kurs.JezikId = (comboBox_Jezik.SelectedItem as jezik).Id; kurs.DatumOd = TimePickerOd.SelectedDate.Value; kurs.DatumDo = TimePickerDo.SelectedDate.Value; try { using (var ersteModel = new ErsteModel()) { ersteModel.kursevi.Add(kurs); ersteModel.SaveChanges(); Close(); } } catch (Exception ex) { MessageBox.Show("Greška. Pokušajte ponovo kasnije."); } } else { MessageBox.Show("Sva polja moraju biti popunjena."); var textBoxes = grid.Children.OfType <TextBox>(); foreach (var t in textBoxes) { if (String.IsNullOrEmpty(t.Text)) { t.BorderBrush = Brushes.Red; } } if (TimePickerOd.SelectedDate == null) { TimePickerOd.BorderBrush = Brushes.Red; } if (TimePickerDo.SelectedDate == null) { TimePickerDo.BorderBrush = Brushes.Red; } if (comboBox_Jezik.SelectedIndex == -1) { comboBox_Jezik.BorderBrush = Brushes.Red; } } } }