Ejemplo n.º 1
0
        private void AddGroupButton_Click(object sender, RoutedEventArgs e)
        {
            var db = (Application.Current as App).db;
            var groupViewSource = ((CollectionViewSource)(this.FindResource("groupViewSource")));

            groupViewSource.Source = db.Groups.Local;
            var dialog = new NewGroup();

            if (dialog.ShowDialog() == true)
            {
                var newGroup = new Model.Group();
                var rand     = new Random();
                newGroup    = dialog.FindResource("NewGroup") as Model.Group;
                newGroup.Id = rand.Next(1000000);
                db.Groups.Add(newGroup);
            }
        }
Ejemplo n.º 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;
            }
        }