Exemple #1
0
        private void BtnMainWindow_Clicked(object sender, RoutedEventArgs e)
        {          // saves data into csv file
            _csvWriter.Flush();
            Button button = sender as Button;

            rep = Repository.GetInstance();
            Member selectedCd = (Member)lbxCds.SelectedItem;

            // new member
            if (button.Name.Equals("btnNew"))
            {
                AddMemberWindow addMemberWindow = new AddMemberWindow();
                addMemberWindow.ShowDialog();
            }
            else
            {
                // Database---
                using (var db = new ClubMemberContext())
                {
                    if (selectedCd == null)
                    {
                        MessageBox.Show("Wählen Sie einen Mitglied!");
                    }
                    else
                    {                                  // delete member
                        if (button.Name.Equals("btnDel"))
                        {
                            rep.RemoveCd(selectedCd);
                            // Delete--------------------------
                            MessageBox.Show("Lösche Mitglied aus der Datenbank");
                            db.Remove(selectedCd);
                            db.SaveChanges();
                            //---------------------------------
                        }                                   // edit member
                        else if (button.Name.Equals("btnEdit"))
                        {
                            AddMemberWindow addMemberWindow = new AddMemberWindow(selectedCd);
                            addMemberWindow.ShowDialog();
                        }
                    }
                }
            }
            _members           = rep.GetAllMembers();
            lbxCds.ItemsSource = _members;
        }
Exemple #2
0
        private void BtnMainWindow_Clicked(object sender, RoutedEventArgs e)
        {
            Button button = sender as Button;

            Member selectedCd = (Member)lbxCds.SelectedItem;

            // new member
            if (button.Name.Equals("btnNew"))
            {
                AddMemberWindow addMemberWindow = new AddMemberWindow();
                addMemberWindow.ShowDialog();
            }
            else
            {
                // Database---
                if (selectedCd == null)
                {
                    MessageBox.Show("Wählen Sie einen Mitglied!");
                }
                else
                {                              // delete member
                    if (button.Name.Equals("btnDel"))
                    {
                        // Delete--------------------------
                        MessageBox.Show("Lösche Mitglied aus der Datenbank");
                        db.PersonRepository.RemoveCd(selectedCd);
                        db.SaveChanges();
                    }                               // edit member
                    else if (button.Name.Equals("btnEdit"))
                    {
                        AddMemberWindow addMemberWindow = new AddMemberWindow(selectedCd);
                        addMemberWindow.ShowDialog();
                    }
                }
            }
            _members           = db.PersonRepository.GetAllMembers();
            lbxCds.ItemsSource = _members;
            lbxCds.Items.Refresh();
        }