Exemplo n.º 1
0
        private void ButtonEdit_Click(object sender, RoutedEventArgs e)
        {
            if ((string)ButtonEdit.Content == "Edit")
            {
                TextBoxClimbName.IsReadOnly     = false;
                TextBoxClimbGrade.IsReadOnly    = false;
                CheckboxClimbDone.IsEnabled     = true;
                TextBoxClimbLocation.IsReadOnly = false;
                TextBoxClimbName.Background     = Brushes.White;
                TextBoxClimbGrade.Background    = Brushes.White;
                TextBoxClimbLocation.Background = Brushes.White;
                ButtonEdit.Content = "Save";
            }
            else
            {
                BrushConverter brush = new BrushConverter();
                using (var db = new ClimbingDBEntities())
                {
                    switch (tableName)
                    {
                    case "Indoors":
                        var climbToEdit = db.ClimbIndoors.Find(climbIndoor.ClimbID);
                        climbToEdit.ClimbName     = TextBoxClimbName.Text;
                        climbToEdit.ClimbGrade    = TextBoxClimbGrade.Text;
                        climbToEdit.ClimbDone     = (bool)CheckboxClimbDone.IsChecked;
                        climbToEdit.ClimbLocation = TextBoxClimbLocation.Text;
                        db.SaveChanges();
                        ListViewIndoors.ItemsSource = null;
                        indoors = db.ClimbIndoors.ToList();
                        ListViewIndoors.ItemsSource = indoors;
                        break;

                    case "Outdoors":
                        var climbToEdit1 = db.ClimbOutdoors.Find(climbOutdoor.ClimbID);
                        climbToEdit1.ClimbName     = TextBoxClimbName.Text;
                        climbToEdit1.ClimbGrade    = TextBoxClimbGrade.Text;
                        climbToEdit1.ClimbDone     = (bool)CheckboxClimbDone.IsChecked;
                        climbToEdit1.ClimbLocation = TextBoxClimbLocation.Text;
                        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");
                ButtonEdit.Content = "Edit";
            }
        }
Exemplo n.º 2
0
 void Initialise()
 {
     using (var db = new ClimbingDBEntities())
     {
         indoors  = db.ClimbIndoors.ToList();
         outdoors = db.ClimbOutdoors.ToList();
     }
     ListViewIndoors.ItemsSource  = indoors;
     ListViewOutdoors.ItemsSource = outdoors;
 }
Exemplo n.º 3
0
        private void ButtonDelete_Click(object sender, RoutedEventArgs e)
        {
            if ((string)ButtonDelete.Content == "Delete")
            {
                ButtonDelete.Content    = "Are You Sure?";
                ButtonDelete.Background = Brushes.Red;
            }
            else
            {
                using (var db = new ClimbingDBEntities())
                {
                    switch (tableName)
                    {
                    case "Indoors":
                        var climbToDelete = db.ClimbIndoors.Find(climbIndoor.ClimbID);
                        db.ClimbIndoors.Remove(climbToDelete);
                        db.SaveChanges();
                        ListViewIndoors.ItemsSource = null;
                        indoors = db.ClimbIndoors.ToList();
                        ListViewIndoors.ItemsSource = indoors;
                        break;

                    case "Outdoors":
                        var climbToDelete1 = db.ClimbOutdoors.Find(climbOutdoor.ClimbID);
                        db.ClimbOutdoors.Remove(climbToDelete1);
                        db.SaveChanges();
                        ListViewOutdoors.ItemsSource = null;
                        outdoors = db.ClimbOutdoors.ToList();
                        ListViewOutdoors.ItemsSource = outdoors;
                        break;

                    default:
                        break;
                    }
                }
                ButtonDelete.Content = "Delete";
                BrushConverter brush = new BrushConverter();
                ButtonDelete.Background = (Brush)brush.ConvertFrom("#BECCE8");
            }
        }