Now that you know how to delete entries in our database or in our table, we need to add something to
it because it's pretty empty already and it's time to add something up.
And therefore we need to have this text box and we need to add a zoo button.
So let's go ahead and build those up and we'll add the functionality.
Therefore, we need to add a new method and I'm going to call it private void add zoo, underscore click
and it's going to need an object sender and routed event args just like that.
And there we are.
So once this method is called and well it should be called when somebody clicks onto the button.
So add zoo should have this event here just click event.
Actually I'm going to add it just at the first row so it's easier.
Click is going to be our Add Zoo Click.
Now we can go ahead and implement it in here and therefore we need to run some very similar code to
what we have done with this delete zoo click.
So I'm just going to copy that code here and I'm going to replace delete with insert into now insert
into will add a new entry in a specific table and I'm going to add values to it.
The values that I want to add is going to be the location.
So it works like this values at location.
And actually in our case, the table was called location with a capital L.
So that's the query.
Then we need to run the SQL Command onto that query over with that query onto our SQL connection.
We need to open the connection.
We need to add the parameter.
And in this case it's called location.
And the location is not the list zu selected value, but it's our text box and well we have the problem
that we haven't implemented this step text box yet, or at least we haven't added the name to the text
box.
So I'm going to give a name to this text box.
Text box new or actually name is going to be my text box like that.
Now it can go ahead and actually let's use a uncapped m here like that.
And now I can call this my text box and get its text.
So I need a text that was entered in my text box whenever this method will be called.
So whatever ads you click will be clicked or our zoo button will be clicked, this code will be executed.
We're going to try to add the location to our database and then we are going to catch errors if there
are any, and we'll show the zoos afterwards.
So that's important as well.
We need to show the zoos, otherwise we won't see any changes in our table.
And by the way, before we start that it should be well use and not value and as well it's insert into.
So that's the thing about using queries because they're hardcoded or it's a string that you enter and
it's not testing.
So SQL is not being tested by a Visual Studio ID.
So that's something that link does and which increases our efficiency by a lot because this is just
a basic error that you can do.
So for example, instead of insert, you just write, insert, or instead of values you start right
value and suddenly the whole thing doesn't work anymore.
So let's run it now with the correct line.
So insert into zoo values at location.
Now add a new location and let's go ahead and add Cairo, add zoo and we can see Cairo's there.
And of course, there are no associated animals to our Cairo zoo.
Now, what we can do is add a new one.
Let's add Berlin back to the story.
So Berlin here at zoo and we have a new zoo.
So now you can go ahead and add multiple zoos to your zoo list.
But what we cannot do yet is add animals to that zoo list.
So how about we implement this add animal to zoo as well?
All right.
So let's go ahead and do that at Zoo Click was that one?
And now we need a new one.
And I'm going to call that add animal to zoo click.
So private void, add animal to zoo underscore click.
And it needs an object center and it needs a rooted event argument or multiple ones.
And now what should happen here?
Well, first of all, let's see if the button text works.
So message box dot show add animal to zoo clicked.
It's always good to check that if you run into an error and you wonder why it's not working.
Well, if you do that, you at least know that the button works.
So let's press this button and well, it's not implemented yet.
There you are.
You see already a slight error that could have cost me hours of searching for it.
And it's the button of add animal to zoo.
And this one needs a click event, of course.
And it's going to be this add new or add animal to zoo click and now we can test it.
So that's why it's so super useful to make this a little test before running all the other code or adding
code to your button.
So add animal to zoo was clicked perfect.
Now that works and now we can go ahead and implement all the nice fancy stuff in here.
So we need a query again.
We need all of this stuff.
So as you can see, it's pretty much the same approach here.
Only this changes.
So only our query changes pretty much, and of course the name of the parameter and where we get the
value from.
So I'm going to copy that.
And I'm going to insert into zoo values.
Well, now it's not into research into zoo values, but insert into zoo animal values.
And here we need the animal ID.
And actually, I'm going to use a capital A and this is going to be added here.
The animal ID and the animal ID will be our.
List all animals that selected value.
That one.
So that will be the idea of the animal that we have selected.
And we need another parameter which is our zoo ID because we need to add two things to our zoo animal.
As you see here, we have the zoo ID and the animal ID that are correlated to each other.
So we need to do the same thing not only with the animal ID here, but at zoo ID as well like that.
Now we can copy this row here because we are going to add another parameter value with the name of zoo
ID like that one here.
It has to be exactly the same.
And now instead of list all animals selected value, we need to list zoo's selected value.
And now we can execute that code and we can go ahead and close our connection afterwards.
And now we don't only want to show the zoos, but we also want to show the associated animals like that.
And this show, Associated Animals, is our method that we have created here, which is just showing
all the animals that are associated to the zoo that we have selected.
All right.
And as there could be plenty of things going wrong, as you know.
Well, of course, we need to have this try and catch a block.
All right.
That we are.
So let's go to New York.
Well, New York has animals already, Kyra.
Doesn't have any animals.
So let's add a crocodile to Cairo, add animal to a zoo.
And as you see, Cairo has this animal now.
Let's go to Berlin.
Let's is empty, cold Cairo.
And Cairo has a crocodile.
Let's add a gecko.
Let's add a wolf, a monkey and so forth.
So now Berlin is empty.
Let's add a parrot in all there because there are only flying animals or, well, birds.
All right.
So we have added the delete button.
We have added the zoo button.
We have added this add animal to zoo button.
And now we need to have the functionality for remove animal, add animal to zoo, delete animal entirely,
update animal and update zoo.
And these are things that we're going to do in the next videos.
And actually you can do most of it already.
So what I want you to do is to implement this remove animal button and also add animal to animal zoo,
which should be called add animal.
So I'm going to change that in a second.
So implement this button and that button.
So those two for now and actually that button as well, delete animal, you should be able to do that
based on what you have seen.
We're going to see what this update zoo and haploid animal method will do in the next video.
But first of all, I would like you to add those three buttons to well, the functionality to those
buttons.
So pause the video and try that, please.
All right.
I hope you tried to do that.
And first of all, we need to create the methods themselves.
So let's stop that.
And while we're at it, I'm going to change the name from Add Animal Zoo to add animal there.
Where is it?
It's the content, right?
The content of the button.
And animal like that.
All right.
Now we need to have button functionality, so we need to have clicks here.
As you can see, an animal doesn't have a click update methods don't have a click delete, animal doesn't
have a click.
So let's build all of those in here.
First, let's start with delete animal, which will simply delete the animal from the list list on the
right hand side.
So I'm going to call it private void, delete, animal underscore click, which is going to have an
object center and then rooted event arx e so nothing new here.
And actually let's copy our code from here because we only need to execute something or actually let's
even get it from our delete zoo click because it's very similar to that one.
So I'm going to copy that code.
And delete from not zoo but animal.
Where ID is animal ID?
And I'm going to copy that here and now instead of the list zoos.
It's the list.
All animals selected value.
So once somebody clicks on delete animal click, I want them to well, get rid of the animal in the
list all animals.
So it's going to delete the animal entirely.
Right now instead of showing zoos here, I want to show all animals here.
So show all animals should be called, which is the method that simply updates our list on the right
hand side.
Right.
And I didn't check this method before I implemented this code, but we will see in a second if it works.
And also, of course, we may not forget to add to delete animal, this little click event that we have
just created.
So Click is going to be delete animal click.
Okay, now let's test it.
And let's see if the button works.
There we are.
So let's select the monkey and.
Well, actually, it's on the right hand side.
Right?
So let's get rid of the parrot.
The lead animal, bam parrot is gone.
Now, I know that Berlin had a parrot, but it doesn't have it anymore because parrots are no animals
that we have in our zoos in general.
So I'm the zoo manager and I decided we don't want to have parrots in our zoos anymore.
And many people are very upset about that.
There were news about it and people are not very happy.
So we need to bring them back.
So we need to add this add animal functionality which adds an animal to our zoo list or animal list
here on the right hand side to the complete list.
So let's implement that button because it doesn't work yet.
All right.
So this add animal button here needs some functionality.
So let's stop that.
And we are going to copy the Add Zoo Click functionality.
So I'm going to copy that and I'm just going to add it below it.
And this one will be called Add Animal Click.
And now insert into animal.
And now it's not the location that I want to add, but it's the name of the animal that was entered
and is actually even my text box dot text.
So it's exactly the same thing.
All right.
So other than changing those two values, I didn't have to do much.
The rest is all the same.
Now, you could argue, hey, why do we even copy and paste all that stuff?
We could create a method which does most of the stuff because it's most of the times it's exactly the
same that happens, right?
So we have like ten different methods to do the same thing.
We could create one method and put all of it in there.
Yeah, we can do that.
But I'm going to leave that to you if you would like to do so.
As I said, we will use a link functionality later on where you will see how to use link to some things
up and make it even shorter anyways.
Right.
So instead of show Zeus here I want to show what is it, an animal click.
This one will be show all animals.
So now let's add this event to our add zoo.
Actually add animal button.
So here click is going to be add animal click.
Now let's test it.
And again, as I said, I didn't test the button if it worked.
But you should if it didn't work.
So.
That we are.
Let's add a little animal.
And we said parrot needs to be back and I'm going to say add animal.
And as you can see, our list here has a new animal called parrot.
And now you can come up with your animals that you want to add to your zoo.
So somebody comes in and says, Hey, we have this great new animal and we want to have it in our zoo.
Could you please add it to your complete list so we can add it to our zoo in New York?
So I'm going to say, all right, a tiger.
Great.
So let's add this tiger to our list now.
We can go ahead to New York and add the tiger to New York.
And now everyone in New York is going to say, whoa, we have a new tiger in our zoo.
Let's go.
Even though I don't support zoos.
All right.
So I made this whole app here, but I'm not that much of a zoo fan, so.
Well, if you're a zoo owner.
Sorry, man, then let's go and add the delete animal.
Well, actually, we are done.
Right?
So we have this remove animal, we have this add animal, we have the delete animal, the animal to
zoo.
Now there are two things missing and actually it's three things if you are very careful.
So update zoo is missing, update animal is missing and this tiger here is not updating.
So if I click on Zoo Milan, Cairo and so forth, this text is not updating the same for the animal
that I'm checking here.
So I'm if I let's say I want to add well, update the clownfish and I press an update zoo.
Well, I don't know whether I have updated the clownfish or not.
So when I click on clownfish, this text should show clownfish here, this text box.
So that's something that we're going to look at in the next video.
So see you there.