示例#1
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            var db = (Application.Current as App).db;
            var studentViewSource = ((CollectionViewSource)(this.FindResource("studentViewSource")));

            studentViewSource.Source = db.Students.Local;
            var dialog = new NewStudent();

            if (dialog.ShowDialog() == true)
            {
                db.Students.Add(dialog.FindResource("NewStudent") as Model.Student);
            }
            studentViewSource.Filter -= StudentsFilter;
            studentViewSource.Filter += StudentsFilter;
        }
示例#2
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            var db     = (Application.Current as App).db;
            var button = sender as Button;

            switch (button.Tag)
            {
            case "addStudent":
                var studentDialog = new NewStudent();
                if (studentDialog.ShowDialog() == true)
                {
                    db.Students.Add(studentDialog.FindResource("newStudent") as Model.Student);
                }
                studentViewSource.Filter -= StudentsFilter;
                studentViewSource.Filter += StudentsFilter;
                break;

            case "removeStudent":
                db.Students.Remove(listBox.SelectedItem as Model.Student);
                break;

            case "addGroup":
                var groupDialog = new NewGroup();
                if (groupDialog.ShowDialog() == true)
                {
                    db.Groups.Add(groupDialog.FindResource("newGroup") as Model.Group);
                }
                break;

            case "removeGroup":
                db.Groups.Remove(groupListBox.SelectedItem as Model.Group);
                break;

            default:
                MessageBox.Show(button.Tag?.ToString() ?? "");
                break;
            }
        }