private void zapiszOcenęKońcową_Click(object sender, RoutedEventArgs e)
 {
     if (wyborUcznia.SelectedItem != null)
     {
         using (var db = new DziennikContext())
         {
             var id = (from u in db.DaneUczniów
                       where u.Imię == wyborUcznia.SelectedItem
                       select u.u_id).First();
             var query = (from s in db.StatystykaKońcowa
                          where s.u_id == id
                          select s);
             if (query == null)
             {
                 db.StatystykaKońcowa.Add(
                     new StatystykaKońcowa {
                     u_id = id, OcenaKońcowa = Int32.Parse(ocenaKońcowa.Text), Średnia = Convert.ToDecimal(średnia.Text), Frekwencja = Int32.Parse(frekwencja.Text)
                 }
                     );
             }
             else
             {
                 query.First().OcenaKońcowa = Int32.Parse(ocenaKońcowa.Text);
                 query.First().Średnia      = Convert.ToDecimal(średnia.Text);
                 query.First().Frekwencja   = Int32.Parse(frekwencja.Text);
             }
             db.SaveChanges();
         }
     }
 }
 public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
 {
     if (value != null)
     {
         using (var db = new DziennikContext())
         {
             string ret = (string)value;
             ret += "\nAdres zamieszkania: ";
             var query = (from u in db.DaneUczniów
                          where u.Imię == (string)value
                          select u.AdresZamieszkania.ToString()).First();
             ret  += query + "\nData urodzenia: ";
             query = (from u in db.DaneUczniów
                      where u.Imię == (string)value
                      select u.DataUrodzenia.ToString()).First();
             ret  += query + "\nData rozpoczecia nauki: ";
             query = (from u in db.DaneUczniów
                      where u.Imię == (string)value
                      select u.DataRozpoczęciaNauki.ToString()).First();
             ret += query;
             return(ret);
         }
     }
     else
     {
         return(null);
     }
 }
        public MainWindow()
        {
            InitializeComponent();
            var          db   = new DziennikContext();
            StreamWriter file = new StreamWriter("log.txt");

            db.Database.Log = (s) => file.WriteLine(s);
            //file.WriteLine(db.Database.Log);
        }
 public Model()
 {
     DataAktualna        = DateTime.Now.ToString();
     SelectedLogin       = null;
     SelectedWybórUcznia = null;
     using (var db = new DziennikContext())
     {
         var query = (from k in db.Klasy
                      select k.Wychowawca.ToString()).ToList();
         Login = query;
     }
 }
 public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
 {
     if (value != null)
     {
         using (var db = new DziennikContext())
         {
             var query = (from u in db.DaneUczniów
                          join k in db.Klasy on u.k_id equals k.k_id
                          where k.Wychowawca == (string)value
                          select u.Imię.ToString()).ToList();
             return((List <string>)query);
         }
     }
     else
     {
         return(null);
     }
 }
 public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
 {
     if (value != null)
     {
         using (var db = new DziennikContext())
         {
             var query = (from u in db.DaneUczniów
                          join o in db.OcenyCząstkowe on u.u_id equals o.u_id
                          where u.Imię == (string)value
                          select o.RodzajOceny.ToString()).ToList();
             return((List <string>)query);
         }
     }
     else
     {
         return(null);
     }
 }
 private void obecny_Click(object sender, RoutedEventArgs e)
 {
     if (wyborUcznia.SelectedItem != null)
     {
         using (var db = new DziennikContext())
         {
             var id = (from u in db.DaneUczniów
                       where u.Imię == wyborUcznia.SelectedItem
                       select u.u_id).First();
             db.Frekwencja.Add(
                 new Frekwencja {
                 u_id = id, DataZajęć = DateTime.Now, Obecność = true
             }
                 );
             db.SaveChanges();
         }
     }
 }
 private void zapiszOceneCzastkowa_Click(object sender, RoutedEventArgs e)
 {
     if (wyborUcznia.SelectedItem != null)
     {
         using (var db = new DziennikContext())
         {
             var id = (from u in db.DaneUczniów
                       where u.Imię == wyborUcznia.SelectedItem
                       select u.u_id).First();
             db.OcenyCząstkowe.Add(
                 new OcenyCząstkowe {
                 DataOceny = DateTime.Now, Ocena = Int32.Parse(ocenaCzastkowa.Text), u_id = id, RodzajOceny = rodzajOceny.Text
             }
                 );
             db.SaveChanges();
         }
     }
 }
 public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
 {
     if (value != null)
     {
         using (var db = new DziennikContext())
         {
             var query = (from u in db.DaneUczniów
                          join f in db.Frekwencja on u.u_id equals f.u_id
                          where u.Imię == (string)value
                          group f by f.u_id into g
                          select g.Count()).First().ToString();
             return("/ " + query);
         }
     }
     else
     {
         return(null);
     }
 }
 public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
 {
     if (value != null)
     {
         using (var db = new DziennikContext())
         {
             var query = (from u in db.DaneUczniów
                          join o in db.OcenyCząstkowe on u.u_id equals o.u_id
                          where u.Imię == (string)value
                          group o by o.u_id into g
                          select g.Average(x => x.Ocena)).First();
             return(Math.Round(System.Convert.ToDouble(query), 2).ToString());
         }
     }
     else
     {
         return(null);
     }
 }
 public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
 {
     if (value != null)
     {
         using (var db = new DziennikContext())
         {
             var query = (from u in db.DaneUczniów
                          where u.Imię == (string)value
                          select u.Zdjęcie).First();
             MemoryStream ms  = new MemoryStream(query);
             BitmapImage  bmp = new BitmapImage();
             bmp.BeginInit();
             ms.Seek(0, SeekOrigin.Begin);
             bmp.StreamSource = ms;
             bmp.EndInit();
             return((BitmapImage)bmp);
         }
     }
     else
     {
         return(null);
     }
 }