Ejemplo n.º 1
0
        private void ListView_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            switch (tableName)
            {
            case "Indoors":
                climbIndoor = (ClimbIndoor)ListViewIndoors.SelectedItem;
                if (climbIndoor != null)
                {
                    TextBoxClimbID.Text         = climbIndoor.ClimbID.ToString();
                    TextBoxClimbName.Text       = climbIndoor.ClimbName.ToString();
                    TextBoxClimbGrade.Text      = climbIndoor.ClimbGrade.ToString();
                    CheckboxClimbDone.IsChecked = climbIndoor.ClimbDone;
                    TextBoxClimbLocation.Text   = climbIndoor.ClimbLocation.ToString();
                }
                break;

            case "Outdoors":
                climbOutdoor = (ClimbOutdoor)ListViewOutdoors.SelectedItem;
                if (climbOutdoor != null)
                {
                    TextBoxClimbID.Text         = climbOutdoor.ClimbID.ToString();
                    TextBoxClimbName.Text       = climbOutdoor.ClimbName.ToString();
                    TextBoxClimbGrade.Text      = climbOutdoor.ClimbGrade.ToString();
                    CheckboxClimbDone.IsChecked = climbOutdoor.ClimbDone;
                    TextBoxClimbLocation.Text   = climbOutdoor.ClimbLocation.ToString();
                }
                break;

            default:
                break;
            }
            ButtonEdit.IsEnabled = true;
        }
Ejemplo n.º 2
0
        private void ButtonAdd_Click(object sender, RoutedEventArgs e)
        {
            if ((string)ButtonAdd.Content == "Add")
            {
                TextBoxClimbName.IsReadOnly     = false;
                TextBoxClimbGrade.IsReadOnly    = false;
                CheckboxClimbDone.IsEnabled     = true;
                TextBoxClimbLocation.IsReadOnly = false;
                TextBoxClimbName.Background     = Brushes.White;
                TextBoxClimbGrade.Background    = Brushes.White;
                TextBoxClimbLocation.Background = Brushes.White;
                ButtonAdd.Content = "Confirm";
            }
            else
            {
                BrushConverter brush = new BrushConverter();
                using (var db = new ClimbingDBEntities())
                {
                    switch (tableName)
                    {
                    case "Indoors":
                        ClimbIndoor climbIndoor = new ClimbIndoor
                        {
                            ClimbName     = TextBoxClimbName.Text,
                            ClimbGrade    = TextBoxClimbGrade.Text,
                            ClimbDone     = (bool)CheckboxClimbDone.IsChecked,
                            ClimbLocation = TextBoxClimbLocation.Text
                        };
                        db.ClimbIndoors.Add(climbIndoor);
                        db.SaveChanges();
                        ListViewIndoors.ItemsSource = null;
                        indoors = db.ClimbIndoors.ToList();
                        ListViewIndoors.ItemsSource = indoors;
                        break;

                    case "Outdoors":
                        ClimbOutdoor climbOutdoor = new ClimbOutdoor
                        {
                            ClimbName     = TextBoxClimbName.Text,
                            ClimbGrade    = TextBoxClimbGrade.Text,
                            ClimbDone     = (bool)CheckboxClimbDone.IsChecked,
                            ClimbLocation = TextBoxClimbLocation.Text
                        };
                        db.ClimbOutdoors.Add(climbOutdoor);
                        db.SaveChanges();
                        ListViewOutdoors.ItemsSource = null;
                        outdoors = db.ClimbOutdoors.ToList();
                        ListViewOutdoors.ItemsSource = outdoors;
                        break;

                    default:
                        break;
                    }
                }
                TextBoxClimbName.IsReadOnly     = true;
                TextBoxClimbGrade.IsReadOnly    = true;
                CheckboxClimbDone.IsEnabled     = false;
                TextBoxClimbLocation.IsReadOnly = true;
                TextBoxClimbName.Background     = (Brush)brush.ConvertFrom("#BECCE8");
                TextBoxClimbGrade.Background    = (Brush)brush.ConvertFrom("#BECCE8");
                TextBoxClimbLocation.Background = (Brush)brush.ConvertFrom("#BECCE8");
                ButtonAdd.Content = "Add";
            }
        }