1 00:00:00,510 --> 00:00:01,500 ‫Welcome back. 2 00:00:01,530 --> 00:00:08,340 ‫In this video, we are going to add another list which will show us our associated animals list. 3 00:00:08,370 --> 00:00:12,150 ‫As you know, we have a list of zoos and then we have a list of animals. 4 00:00:12,150 --> 00:00:17,690 ‫And we need a list where we see the animals that are at a specific zoo. 5 00:00:17,700 --> 00:00:23,310 ‫And for example, if I click on New York, then I want to see in this additional list view, which we 6 00:00:23,310 --> 00:00:27,870 ‫have to set up the additional animals that are in New York. 7 00:00:28,110 --> 00:00:35,640 ‫So let's go ahead and just add that we need to go to our Zemo file first because we need to add another 8 00:00:35,640 --> 00:00:35,880 ‫list. 9 00:00:35,880 --> 00:00:41,520 ‫So I'm just going to enter those two or access those two elements, and I'm going to copy and paste 10 00:00:41,520 --> 00:00:43,880 ‫them so I can drag them to the side. 11 00:00:43,890 --> 00:00:54,690 ‫So now this one will not state list of the zoos, but it will be the associated animals list. 12 00:00:56,040 --> 00:00:57,870 ‫And so see. 13 00:00:58,700 --> 00:01:02,910 ‫A So not a c k associated animals list. 14 00:01:03,000 --> 00:01:13,410 ‫And now we have this one here which had the name list, zoo copies, and we want this to be list associated 15 00:01:13,410 --> 00:01:14,400 ‫animals. 16 00:01:14,610 --> 00:01:19,650 ‫So it just has a different name and then everything else is the same. 17 00:01:19,770 --> 00:01:20,460 ‫All right. 18 00:01:20,460 --> 00:01:26,790 ‫So now if we want to add functionality when something in here is clicked, we can of course do that 19 00:01:26,790 --> 00:01:27,270 ‫manually. 20 00:01:27,270 --> 00:01:30,390 ‫We can type it out or we can simply double click on it. 21 00:01:30,390 --> 00:01:34,950 ‫And you see it will create a selection change event for us. 22 00:01:34,950 --> 00:01:39,960 ‫So here a selection change event args are handled over and this is for list zoos. 23 00:01:39,960 --> 00:01:43,740 ‫So whenever we press on list zoos, this will be triggered. 24 00:01:43,740 --> 00:01:50,190 ‫And in order to check that, we can simply show that onto our console and list. 25 00:01:50,190 --> 00:01:52,950 ‫Zoos was clicked. 26 00:01:54,330 --> 00:01:55,980 ‫It's just going to be simple for now. 27 00:01:55,980 --> 00:02:02,310 ‫What we want to do is actually, well, update our other list once that is clicked. 28 00:02:02,310 --> 00:02:11,100 ‫Now let's check it out and I'm going to press on New York and you see lists, zoos was clicked, same 29 00:02:11,100 --> 00:02:14,790 ‫for Tokyo, list was clicked and so forth. 30 00:02:14,940 --> 00:02:15,450 ‫All right. 31 00:02:15,450 --> 00:02:18,660 ‫So of course, I don't want to show a message box here. 32 00:02:18,660 --> 00:02:23,670 ‫This was just for testing purposes so that you see what this selection changed does. 33 00:02:23,940 --> 00:02:30,660 ‫Now, what we need is another method which is very similar to the one that shows the zoos we need to 34 00:02:30,660 --> 00:02:33,240 ‫show the associated animals. 35 00:02:33,240 --> 00:02:42,270 ‫And well, actually what we can do is we can even copy that code here and just adjust it accordingly. 36 00:02:42,330 --> 00:02:46,230 ‫So we know we want to show animals. 37 00:02:46,230 --> 00:02:50,970 ‫So I'm going to show associated animals. 38 00:02:50,970 --> 00:02:52,920 ‫This is a new name of the method. 39 00:02:52,920 --> 00:02:55,860 ‫So I just copied and pasted the whole show Zoo's method. 40 00:02:57,030 --> 00:03:03,930 ‫And now I have this try and catch block again, which is trying to execute some query code and if it 41 00:03:03,930 --> 00:03:07,440 ‫didn't work, it's going to catch it and a message box will show up. 42 00:03:07,980 --> 00:03:08,670 ‫All right. 43 00:03:08,670 --> 00:03:14,760 ‫Now in here, I have a query, and that query is rather simple, simple right now. 44 00:03:14,760 --> 00:03:18,240 ‫And we need to make it a little more in-depth. 45 00:03:18,930 --> 00:03:33,600 ‫So instead of select star from Zoo, we need to go ahead and use select from animal a inner join zoo 46 00:03:33,600 --> 00:03:49,800 ‫animal that a on a dot ID is equal to z a dot animal ID animal ID. 47 00:03:50,190 --> 00:03:56,430 ‫So what we're pretty much saying is create those two or take those two tables, join them together, 48 00:03:56,430 --> 00:04:08,460 ‫and then check where the ID and of the animal and the zoo animal are the same and then go ahead and 49 00:04:08,460 --> 00:04:10,110 ‫display that to us. 50 00:04:10,380 --> 00:04:21,720 ‫So where the zoo ID is equal to at zoo ID and zoo ID is something that we will set up in a second. 51 00:04:21,720 --> 00:04:25,200 ‫So this adds where ID is like a variable. 52 00:04:25,200 --> 00:04:31,920 ‫You could say, okay, we are adding a variable in our query and now we can go ahead and set that variable 53 00:04:31,920 --> 00:04:32,700 ‫in code. 54 00:04:32,700 --> 00:04:35,610 ‫So I'm going to put that in a second line. 55 00:04:36,120 --> 00:04:36,450 ‫All right. 56 00:04:36,450 --> 00:04:42,870 ‫So now that we have that, what we next need to do is instead of setting up the SQL adapter, as we 57 00:04:42,870 --> 00:04:50,550 ‫did, we need an SQL Command because I use this at Zoo ID and in order to use it as a variable kind 58 00:04:50,550 --> 00:04:53,910 ‫of thing, I need to use an SQL Command. 59 00:04:54,180 --> 00:05:02,580 ‫And this is going to be called SQL Command, and that one is a new SQL Command, which will allow us 60 00:05:02,580 --> 00:05:07,380 ‫to use the query with the SQL Connection. 61 00:05:08,610 --> 00:05:14,670 ‫So from now it looks like it's an adapter, but we are going to add things to the command. 62 00:05:14,670 --> 00:05:22,020 ‫So we cannot simply add something like what zoo ID is to an SQL adapter, but we can add it to an SQL 63 00:05:22,020 --> 00:05:26,520 ‫command, which we then hand over to the SQL adapter. 64 00:05:26,520 --> 00:05:33,960 ‫So what we need to do is instead of running the query and the SQL connection here, we hand over the 65 00:05:33,960 --> 00:05:35,640 ‫SQL Command. 66 00:05:37,030 --> 00:05:37,570 ‫All right. 67 00:05:37,870 --> 00:05:44,650 ‫So we create a new SQL Command, which takes the query with the SQL Connection, and we hand that over 68 00:05:44,650 --> 00:05:45,790 ‫to SQL adapter. 69 00:05:45,790 --> 00:05:49,770 ‫And now we can go ahead and apply things to this SQL Command. 70 00:05:49,780 --> 00:05:53,230 ‫So this means that we can add a parameter to that. 71 00:05:53,530 --> 00:05:58,720 ‫So I'm going to do that with SQL Command DOT parameters. 72 00:05:59,300 --> 00:06:04,690 ‫There's a property called Parameters and it has a method called Add with value. 73 00:06:04,960 --> 00:06:08,860 ‫And then here I'm just going to say add zu id. 74 00:06:10,890 --> 00:06:13,170 ‫It's going to be my list. 75 00:06:13,170 --> 00:06:17,490 ‫Zoos that selected value. 76 00:06:19,920 --> 00:06:20,550 ‫All right. 77 00:06:21,090 --> 00:06:22,860 ‫And what what does that mean? 78 00:06:23,670 --> 00:06:30,510 ‫Well, zoo ID, as we know, is within our zoo animal. 79 00:06:32,230 --> 00:06:32,920 ‫Table. 80 00:06:32,920 --> 00:06:36,670 ‫So I'm going to show you that we have this zoo ID here, this one. 81 00:06:36,670 --> 00:06:38,200 ‫That's the ID of the zoo. 82 00:06:38,200 --> 00:06:41,350 ‫And that's the idea of the animal that is at that zoo. 83 00:06:42,000 --> 00:06:44,640 ‫And we want to have that. 84 00:06:44,640 --> 00:06:50,640 ‫So we are using it in our case class and we use that for this query here. 85 00:06:50,760 --> 00:06:59,280 ‫And now we want to hand over a specific ID, which is based on what we have selected in our list box. 86 00:06:59,280 --> 00:07:03,750 ‫So we have this list box here, the list where we have the different views. 87 00:07:03,750 --> 00:07:08,490 ‫And now when I click on one of them, I want the table to be updated. 88 00:07:08,490 --> 00:07:10,410 ‫And of course, it's not a zoo table. 89 00:07:10,530 --> 00:07:12,450 ‫It's an animal table here. 90 00:07:12,750 --> 00:07:14,190 ‫Animal table. 91 00:07:14,790 --> 00:07:19,620 ‫I'm going to copy that and I'm going to hand over this here now instead of the location. 92 00:07:19,620 --> 00:07:21,960 ‫I don't want to have the location of the animal. 93 00:07:21,990 --> 00:07:24,990 ‫I want to have the name of the animal. 94 00:07:25,350 --> 00:07:32,220 ‫And now, instead of applying it to the list zoos, which we applied earlier on when we showed all zoos, 95 00:07:32,220 --> 00:07:34,140 ‫we want to show the animals. 96 00:07:34,140 --> 00:07:39,210 ‫So we need to get the list, associated animals list. 97 00:07:39,630 --> 00:07:44,130 ‫And I'm just going to use it for all of the three lines. 98 00:07:45,960 --> 00:07:46,620 ‫All right. 99 00:07:46,710 --> 00:07:48,400 ‫And that is pretty much it. 100 00:07:48,420 --> 00:07:53,460 ‫So for you to understand what this ID is, I'm simply going to do the following. 101 00:07:53,550 --> 00:07:55,120 ‫I will show you lists. 102 00:07:55,140 --> 00:07:58,820 ‫Use dot selected value. 103 00:07:58,830 --> 00:08:03,180 ‫So this is a value and I will make a string out of it. 104 00:08:03,390 --> 00:08:06,840 ‫And now I want to show this in the message box. 105 00:08:06,840 --> 00:08:16,740 ‫So I'm going to create a new message box, dot show, and that will show me the value that was selected. 106 00:08:16,740 --> 00:08:19,020 ‫So you will see in a second what that means. 107 00:08:19,950 --> 00:08:20,190 ‫All right. 108 00:08:20,190 --> 00:08:21,020 ‫So there we are. 109 00:08:21,030 --> 00:08:27,720 ‫I click on, let's say, Tokyo, and you see the ID two comes up, I click on New York, the ID one 110 00:08:27,720 --> 00:08:28,410 ‫comes up. 111 00:08:28,620 --> 00:08:29,450 ‫Berlin. 112 00:08:29,460 --> 00:08:31,970 ‫Well, actually, Cairo ID was four. 113 00:08:31,980 --> 00:08:37,200 ‫So once I click on those, I want this method to be executed. 114 00:08:37,200 --> 00:08:40,020 ‫So show all associated animals. 115 00:08:40,290 --> 00:08:47,460 ‫And by the way, this is the ID that we hand over the zoo ID and by doing that we add this to this line 116 00:08:47,460 --> 00:08:53,700 ‫here to this query that we have here, and then it can execute that query and give us all the required 117 00:08:53,700 --> 00:08:55,410 ‫info on our list. 118 00:08:55,410 --> 00:08:56,880 ‫Associated Animals. 119 00:08:56,910 --> 00:09:03,210 ‫Now of course, as I said, instead of this message box, I would like to show this method here or execute 120 00:09:03,210 --> 00:09:05,880 ‫this method where we show associated animals. 121 00:09:05,970 --> 00:09:08,550 ‫So associated animals. 122 00:09:08,940 --> 00:09:16,500 ‫And now if we run that, let's run the code, let's click on New York and we see there are sharks and 123 00:09:16,500 --> 00:09:17,490 ‫clownfish. 124 00:09:17,490 --> 00:09:24,540 ‫Then in Tokyo are monkeys and wolves, Berlin Gecko, crocodile, Cairo Island Parrot and my milano 125 00:09:24,540 --> 00:09:27,720 ‫has all of them, so it has all the aid animals. 126 00:09:28,200 --> 00:09:32,220 ‫All right, so that's pretty much our associated animals list. 127 00:09:32,790 --> 00:09:33,420 ‫Great. 128 00:09:33,790 --> 00:09:39,560 ‫And now you know how to create your own associated lists. 129 00:09:39,570 --> 00:09:42,600 ‫We've done that before, but now you have seen the query. 130 00:09:42,600 --> 00:09:44,040 ‫Once again, we have set it up. 131 00:09:44,040 --> 00:09:50,970 ‫And you also have seen how we can use that in C-sharp by creating adapters, by using commands in order 132 00:09:50,970 --> 00:09:56,220 ‫to well adjust the queries based on execution or by based on code. 133 00:09:56,220 --> 00:10:03,540 ‫Because we couldn't add a fixed value here, we couldn't just say four because we want it to be a specific 134 00:10:03,540 --> 00:10:07,320 ‫value and that value is going to be our list. 135 00:10:07,350 --> 00:10:08,820 ‫Use selected value. 136 00:10:09,940 --> 00:10:11,350 ‫All right, great. 137 00:10:11,350 --> 00:10:13,450 ‫So I'd say that's good for this video. 138 00:10:13,450 --> 00:10:19,840 ‫And in the next video, we are going to add the list with all animals and some additional elements. 139 00:10:19,840 --> 00:10:20,890 ‫So see you there.