‫Welcome back.
‫In this video, we are going to add the update zoo and update animal button.
‫So first of all, I want this text to be updated with whatever zoo, for example, I have chosen or
‫with whatever animal I have chosen.
‫So let's create that functionality and go into our code behind.
‫So I will create a new method and well, I'm just going to do it in here.
‫Private void.
‫Show selected zoo in text box.
‫Pretty long name, but that's exactly what it does.
‫So it's going to show us the select zoo in the text box.
‫And in order to well run the correct code, I'm actually going to use something very similar to show
‫associated animals or show zoos.
‫Actually, let's copy the show Associated Animals entries that we have here and I'm going to plug it
‫in.
‫So the query is, of course, a lot shorter.
‫Instead of showing everything, I want to see the location.
‫So select location from zoo where the ID is equal to at zoo ID.
‫And now of course this one is here at the value is zoo ID and now this one is the list zoo selected
‫value.
‫So all of that code is pretty much the same.
‫Now, there is one difference, though.
‫We don't want to update our list associated values and stuff like that, but what we want to do is to
‫update our text box.
‫So I need to access my text box, dot text and update it with zoo data table.
‫And now that's interesting.
‫Actually, this is not an animal data table.
‫I'm going to call that zoo data table.
‫And now I can access that zoo data table.
‫And this data table is pretty much a c sharp object.
‫Right.
‫And it contains something well, it contains multiple rows.
‫So there's a property called rows.
‫And I want to have the first row that there is, which is at the data column called Location and its
‫Capital L location.
‫And now that should be converted to a string.
‫So zoo data table, as I said, is pretty much just the table that we are looking at.
‫And I want to have the very first entry at the location because we have this selected value, which
‫is one particular value, and it creates a new data table based on our command.
‫Right?
‫So what it does is it searches for this particular entry, which we say here.
‫Third, where ID is zoo ID and this is unique, right?
‫The ID is unique as we know.
‫So this is going to get one entry only.
‫That's why I can use zero here.
‫So I can say, give me the very first entry, the very first row in your table and there, give me the
‫location, please.
‫And I want that to be translated into a string or convert it into a string.
‫So that's why I can simply use this approach here and I can run that.
‫And what that will allow me to do is, well, update my text box based on clicks.
‫And actually show selected Zune text box.
‫Well, of course, we're not calling the method yet, so it's not going to be called.
‫So when I click here, as you can see, nothing happens.
‫And that has to do with us not having implemented our zoo or adjusted our zoo change method.
‫What is it?
‫List zoo selection changed exactly that one.
‫So in here I now want to call this method that I've just created.
‫Right.
‫And it's called show or or what's the name exactly.
‫So select zoo and TextBox.
‫So that's the method that I want to call in.
‫My selection changed method from list zoos.
‫So in here I'm going to call this method show selected zoo in text box.
‫Now let's run that.
‫There we are.
‫So I'm going to click on Cairo and Berlin and you can see our text is updated all the time.
‫That's perfect.
‫That's exactly what I wanted, because now that I have that, I can go ahead and implement the update
‫zoo functionality.
‫But before we do that, a little challenge for you.
‫Please implement the same functionality for our list here at the right.
‫So for the animals list, because when somebody presses on Monkey, I want this text to be updated as
‫well.
‫So please go ahead and try that.
‫All right.
‫I hope you did.
‫So I'm going to make it simple.
‫I'm going to just copy this method that I've just created.
‫So show selected zoo in text box, and I'm going to stop the application and I'm going to call that
‫show selected animal in text box and now select.
‫And now it's not the location, it's the name from zoo and it's not Zoo, it's from animal where the
‫ID is animal ID.
‫And of course, I need to adjust that entry here.
‫And it's not the list zoos, but it's the list animals all list all animals.
‫And now instead of the location, I want to have the name of the animal.
‫And everything else should be the same.
‫All right.
‫So that's pretty much it.
‫So now we can execute that code.
‫Actually we cannot because we have not implemented the functionality to be run.
‫But as you can see, this one is not implemented.
‫So now let's implement this functionality to our list here.
‫So I'm going to double click on the list.
‫And as you can see, it adds this list.
‫All animals selection changed.
‫And in here, I'm just going to call show selected animal in text box.
‫All right, now let's try it again.
‫And there we are.
‫As you can see, our tiger comes up, our clownfish comes up, all of that and works great.
‫Now, there's one thing missing and that's to update our owl, our zoo, our parrot.
‫So let's say we have made a typo and we would like to change the name or well, the city name has changed
‫for some reason because the mayor decided now it's not going to be New York, it's going to be New York
‫or something like that.
‫So yeah, let's do that.
‫Let's implement that functionality.
‫And in order to do so, we need to run a query again.
‫So let's create a new method for that.
‫So let's start with the update zoo click method.
‫So actually I'm going to.
‫Copy this ad animal to zoo method.
‫Because it's very similar copy and it's going to be not add animal but update zoo click.
‫So once this update zoo click method is called I want to run a different query than we have here I want
‫to update zoo and set its location to is equal to add location where the ID is.
‫So where ID is at zoo ID.
‫All right.
‫So that's pretty much what I want to do.
‫I just want to change the location.
‫And the location is the name of the zoo, right?
‫So that's that one here.
‫Zoo.
‫So update the zoo table and set the location to the location that we have where the ID is the zoo ID
‫and now we have zoo ID already, which is the last zoos and now the location.
‫Location should be our and now it's interesting here our text box which is my text box actually my text
‫box dot text.
‫All right.
‫And, well, that should be it.
‫Instead of showing associated animals, I want to update the zoos.
‫So show zoos should be called and everything else should be the same.
‫Let's test that before we update the animal kind of button as well.
‫Or the animal button.
‫Update animal button.
‫So let's press on Cairo.
‫Let's change that to Cairo.
‫Just add an O and it's update.
‫Nothing happens because the update button is not implemented.
‫So let's go to Main Window example update button.
‫And here let's add this click event which is going to be update zoo click and now we can run it again.
‫And our update button should do what it was supposed to do.
‫All right, so now let's call this one.
‫Well, actually, let's select Cairo and let's change it to Cairo and update.
‫And as you can see, our list here has updated Cairo or Berlin is now called Berlin.
‫We changed the name to a female name, Berlin.
‫And we are or New York, as I said, let's call it new org.
‫It's a new org.
‫A City of Works update.
‫There we are.
‫New York has sharks and clownfish and tigers.
‫That's pretty awesome.
‫A little bit like World of Warcraft here.
‫So now for you, a little challenge.
‫Please implement this update animal button, which updates the animal on the list on the right hand
‫side based on what is entered into the text box here.
‫All right.
‫I hope you have tried it.
‫I hope you passed the video and tried it by yourself.
‫So I'm just going to copy this update zu click and I'm going to call it Update Animal Click.
‫Now, instead of updating the zoo table, I want to update the animal table.
‫And there I don't want to change the location.
‫I want to change the name.
‫To name where animal ID?
‫So where the ID is the animal ID that we have?
‫Well.
‫At the bottom here.
‫So the animal ID is going to be the animal list or what is it called list?
‫All animals.
‫That's the one.
‫And text box should have the name.
‫So this one will be the name.
‫And everything else is the same.
‫So now let's run it again.
‫Well, actually, before we run it, let's go to the XAML file and implement that method because or
‫add that method to the button click.
‫So Update Animal is going to have a new click here.
‫Click is equal to update animal click.
‫Okay.
‫Now we can test it and we should be done.
‫By the way, I hope you manage to do that yourself.
‫So there we are.
‫Let's select a monkey and let's call it monkey or monkey update animal.
‫And most likely it is updated, but we don't see it.
‫And you might know why that is.
‫That's because we show the zoo's here and we don't show all animals.
‫Now, if we do that and we start again, we should see monkeys there already because internally it has
‫changed.
‫So the database has been updated, but we haven't seen it so that we are monkey.
‫Monkey.
‫And now let's change monkey back to monkey with well, just one.
‫Why update animal bam monkey is updated.
‫So let's change the clownfish to a simple clown bird.
‫Let's update the animal.
‫We have a cloud bird.
‫And now, by the way, you see new org has a clown bird.
‫Now, isn't that awesome?
‫Because New York has clown birds.
‫That's a place where I want to be.
‫All right.
‫So, yeah, I'd say we're pretty much done.
‫Of course, there are some cases which could still be added and the functionality could be extended
‫and so forth.
‫But it's about understanding what those queries do, about understanding how to run a command, how
‫to adjust that, how to implement that into our WPF.
‫And as you can see, we have taken stuff that we know from our WPF tutorial.
‫We have implemented additional functionality that we have not learned so far, which is to use databases.
‫So you have seen how to use tables, how to well adjust your entries via code, with buttons and with
‫text fields and so forth.
‫And well, in general you have built a whole application here.
‫So now you could apply that knowledge to build a whole database application for your employees or for
‫whatever you might come up with, or if you have a job to do.
‫And somebody says, Yeah, I need this database where I can enter A, B, C, D, and then, you know,
‫All right, yeah, I can do that.
‫And you simply go back to this tutorial and you can check out.
‫This was the method for updating.
‫This was the method for well deleting and so forth.
‫All right.
‫So if you manage to do the exercises in this chapter, great job.
‫If you didn't, no worries.
‫You can simply go back and try to do it yourself once you have finished this chapter, which is already
‫now.
‫So you can go ahead and try to build that on your own.
‫Now, of course you can always go a little bit, but it's best if you try to build it yourself.
‫And by the way, if you don't come up with this SQL Command stuff and so forth, you can always Google
‫it.
‫It's always good to yeah.
‫Research a little bit to read about it and to understand a little better what's going on.
‫Okey dokey.
‫So I hope you enjoyed this chapter.
‫We have created a pretty cool little application and in the next chapter we are going to check out link
‫which well will improve our life a lot because all of this stuff is well, it's old school, it's a
‫little old school link increases the efficiency by a bit so we can actually work with real sharp queries
‫instead of using these MySQL queries which can always go wrong.
‫So if I have data here instead of updates or updates, then I get errors and well, it's not so easy
‫to figure it out sometimes.
‫Great.
‫So I see you in the next chapter, so see you there.