Esempio n. 1
0
        public void addRabbitToDataBase(string Name, string Age)
        {
            var newRabbit = new Rabbit()
            {
                Age  = int.Parse(Age),
                Name = Name
            };

            using (var db = new RabbitDbEntities())
            {
                db.Rabbits.Add(newRabbit);
                db.SaveChanges();
            }
        }
Esempio n. 2
0
        private void updateRabbitDataBase(int ID, string name, string age)
        {
            //update rabbit
            using (var db = new RabbitDbEntities())
            {
                Rabbit rabbitUpdate = db.Rabbits.Single(a => a.RabbitId == ID);

                if (rabbitUpdate != null)
                {
                    rabbitUpdate.Name = name;
                    rabbitUpdate.Age  = int.Parse(age);
                    db.SaveChanges();
                }
            }
        }
Esempio n. 3
0
        private void BtnUpdateSelectedRabbit_Click(object sender, RoutedEventArgs e)
        {
            ClearDisplay();
            Rabbit selectedRabbit = rabbits[RabbitsListBox.SelectedIndex];

            currentRabbitID = selectedRabbit.RabbitId;
            Label nameLabel = AddNewGridLabel(0, 0, 1, 1, "Name: ");
            Label ageLabel  = AddNewGridLabel(0, 0, 1, 1, "Age: ");

            updateNameText = AddNewGridTextBox(0, 1, 1, 1, selectedRabbit.Name);
            updateAgeText  = AddNewGridTextBox(0, 1, 1, 1, selectedRabbit.Age.ToString());

            updateNameText.Name = "updateName";
            updateAgeText.Name  = "updateAge";

            updateNameText.VerticalAlignment   = VerticalAlignment.Bottom;
            updateAgeText.VerticalAlignment    = VerticalAlignment.Bottom;
            updateNameText.HorizontalAlignment = HorizontalAlignment.Left;
            updateAgeText.HorizontalAlignment  = HorizontalAlignment.Left;

            nameLabel.VerticalAlignment   = VerticalAlignment.Bottom;
            ageLabel.VerticalAlignment    = VerticalAlignment.Bottom;
            nameLabel.HorizontalAlignment = HorizontalAlignment.Right;
            ageLabel.HorizontalAlignment  = HorizontalAlignment.Right;

            Button UpdateRabbit = new Button
            {
                Content             = "UPDATE",
                VerticalAlignment   = VerticalAlignment.Bottom,
                HorizontalAlignment = HorizontalAlignment.Center,
                Height = 25,
                Width  = 200
            };

            Grid.SetRow(UpdateRabbit, 0);
            Grid.SetColumn(UpdateRabbit, 0);
            Grid.SetColumnSpan(UpdateRabbit, 2);

            UpdateRabbit.Click += UpdateRabbit_Click;

            ImageGrid.Children.Add(UpdateRabbit);

            updateNameText.Margin = new Thickness(0, 0, 0, 60);
            nameLabel.Margin      = new Thickness(0, 0, 0, 60);
            updateAgeText.Margin  = new Thickness(0, 0, 0, 30);
            ageLabel.Margin       = new Thickness(0, 0, 0, 30);
        }