Beispiel #1
0
        private void MetroWindow_Loaded(object sender, RoutedEventArgs e)
        {
            StudentsDBEntities SDE = new StudentsDBEntities();
            var data = from d in SDE.StudentsTable select d;

            ListaStudentowDg.ItemsSource = data.ToList();
            ListaStudentowDg.Items.Refresh();
            ListaStudentowDg.SelectedIndex = 0;
        }
Beispiel #2
0
        public void WyszykajTb_KeyUp(object sender, KeyEventArgs e)
        {
            StudentsDBEntities SDE = new StudentsDBEntities();

            if (WyszykajTb.Text.Count() > 0 || OdDp.SelectedDate.HasValue || DoDp.SelectedDate.HasValue)
            {
                IQueryable <StudentsTable> data;
                if (WyszykajTb.Text.Count() > 0)
                {
                    if (DoDp.SelectedDate.HasValue && OdDp.SelectedDate.HasValue)
                    {
                        data = from d in SDE.StudentsTable where d.StudentName.Trim().Contains(WyszykajTb.Text.Trim()) || d.StudentSurname.Trim().Contains(WyszykajTb.Text.Trim()) || d.Id.ToString().Contains(WyszykajTb.Text.Trim()) && d.DateOfBirt >= OdDp.SelectedDate.Value && d.DateOfBirt <= DoDp.SelectedDate.Value select d;
                    }
                    else if (DoDp.SelectedDate.HasValue)
                    {
                        data = from d in SDE.StudentsTable where d.StudentName.Trim().Contains(WyszykajTb.Text.Trim()) || d.StudentSurname.Trim().Contains(WyszykajTb.Text.Trim()) || d.Id.ToString().Contains(WyszykajTb.Text.Trim()) && d.DateOfBirt <= DoDp.SelectedDate.Value select d;
                    }
                    else if (OdDp.SelectedDate.HasValue)
                    {
                        data = from d in SDE.StudentsTable where d.StudentName.Trim().Contains(WyszykajTb.Text.Trim()) || d.StudentSurname.Trim().Contains(WyszykajTb.Text.Trim()) || d.Id.ToString().Contains(WyszykajTb.Text.Trim()) && d.DateOfBirt >= OdDp.SelectedDate.Value select d;
                    }
                    else
                    {
                        data = from d in SDE.StudentsTable where d.StudentName.Trim().Contains(WyszykajTb.Text.Trim()) || d.StudentSurname.Trim().Contains(WyszykajTb.Text.Trim()) || d.Id.ToString().Contains(WyszykajTb.Text.Trim()) select d;
                    }
                }
                else
                {
                    if (DoDp.SelectedDate.HasValue && OdDp.SelectedDate.HasValue)
                    {
                        data = from d in SDE.StudentsTable where d.DateOfBirt >= OdDp.SelectedDate.Value && d.DateOfBirt <= DoDp.SelectedDate.Value select d;
                    }
                    else if (DoDp.SelectedDate.HasValue)
                    {
                        data = from d in SDE.StudentsTable where d.DateOfBirt <= DoDp.SelectedDate.Value select d;
                    }
                    else if (OdDp.SelectedDate.HasValue)
                    {
                        data = from d in SDE.StudentsTable where d.DateOfBirt >= OdDp.SelectedDate.Value select d;
                    }
                    else
                    {
                        data = from d in SDE.StudentsTable select d;
                    }
                }

                ListaStudentowDg.ItemsSource = data.ToList();
                ListaStudentowDg.Items.Refresh();
                ListaStudentowDg.SelectedIndex = 0;
                ListaStudentowDg_SelectionChanged(null, null);
            }
            else
            {
                MetroWindow_Loaded(null, null);
            }
        }
Beispiel #3
0
        private void UsunBtn_Click(object sender, RoutedEventArgs e)
        {
            StudentsDBEntities SDE    = new StudentsDBEntities();
            var rowAssessment         = (AssessmentsTable)OcenyDg.SelectedItem;
            MessageBoxResult question = MessageBox.Show("Czy chcesz usunąć tę ocenę?", "Usuwanie oceny", MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.No);

            if (question == MessageBoxResult.Yes)
            {
                var UsunOceneStudenta = SDE.AssessmentsTable.Where(w => w.Id == rowAssessment.Id).FirstOrDefault();
                SDE.AssessmentsTable.Remove(UsunOceneStudenta);
                SDE.SaveChanges();
                ListaStudentowDg_SelectionChanged(null, null);
            }
        }
Beispiel #4
0
        public void ListaStudentowDg_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            var row = (StudentsTable)ListaStudentowDg.SelectedItem;
            StudentsDBEntities SDE = new StudentsDBEntities();
            var data = from d in SDE.AssessmentsTable select d;

            if (row != null)
            {
                OcenyDg.ItemsSource = data.ToList().Where(IndeksID => IndeksID.IndeksID == row.Id);
            }
            else
            {
                OcenyDg.ItemsSource = new List <AssessmentsTable>();
            }
        }
Beispiel #5
0
        private void UsunStudenta_Click(object sender, RoutedEventArgs e)
        {
            var rowStudent              = (StudentsTable)ListaStudentowDg.SelectedItem;
            StudentsDBEntities SDE      = new StudentsDBEntities();
            MessageBoxResult   question = MessageBox.Show("Czy chcesz usunąć studenta: " + rowStudent.StudentName + " " + rowStudent.StudentSurname + "?", "Usuwanie studenta", MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.No);

            if (question == MessageBoxResult.Yes)
            {
                var UsunStudenta = SDE.StudentsTable.Where(w => w.Id == rowStudent.Id).FirstOrDefault();
                SDE.StudentsTable.Remove(UsunStudenta);
                SDE.AssessmentsTable.RemoveRange(SDE.AssessmentsTable.Where(w => w.IndeksID == rowStudent.Id));
                SDE.SaveChanges();
                WyszykajTb_KeyUp(null, null);
                ListaStudentowDg_SelectionChanged(null, null);
            }
        }