1 00:00:00,270 --> 00:00:01,080 Welcome back. 2 00:00:01,080 --> 00:00:07,410 In this video we're going to be doing some essential fixes to our application so we've made good progress 3 00:00:07,410 --> 00:00:13,650 so far but there are certain things are boats the application that can be changed I can be you know 4 00:00:13,750 --> 00:00:17,410 refined and just list a few of them. 5 00:00:17,430 --> 00:00:24,060 Well we want to do is make sure that only one window at a time comes up meaning when I in my application 6 00:00:24,060 --> 00:00:25,990 say that I want to add a car. 7 00:00:26,070 --> 00:00:33,540 Let me just log in quickly so we can see exactly what I'm talking about when I say I want to launch 8 00:00:33,560 --> 00:00:38,790 a managed vehicle listing I don't want to be able to click that and have so many instances of the same 9 00:00:38,790 --> 00:00:39,540 window open. 10 00:00:39,540 --> 00:00:45,710 So we're going to be modifying or application so that only one window comes up at a time. 11 00:00:45,750 --> 00:00:46,900 That's one. 12 00:00:46,920 --> 00:00:55,490 And another thing that we will want to do is to do our grid auto refresh so we didn't get to do that 13 00:00:55,770 --> 00:00:59,130 but we want to do that where if I add a new car right. 14 00:00:59,160 --> 00:01:05,670 No I don't have to come back and click refresh but the grid should automatically refresh and show me 15 00:01:05,700 --> 00:01:07,800 the new car outside of that. 16 00:01:07,800 --> 00:01:12,660 Anything else would just be refining the messages and the visual cues that we give to our users with 17 00:01:12,690 --> 00:01:14,590 each operation that they complete. 18 00:01:14,820 --> 00:01:19,350 And then we will upload our application to GitHub. 19 00:01:19,710 --> 00:01:20,910 So let's get started. 20 00:01:20,910 --> 00:01:27,090 I'm going to exit the application and the first thing that we're going to tackle is opening one window 21 00:01:27,150 --> 00:01:28,170 at a time. 22 00:01:28,230 --> 00:01:31,330 No they're for too much two ways to do this one. 23 00:01:31,440 --> 00:01:37,890 While one will help us maintain the MDI child the pattern that we have been using where when a window 24 00:01:37,890 --> 00:01:42,330 comes up as an MDI child they cannot be moved outside of the main window. 25 00:01:42,330 --> 00:01:47,280 And the other one is as short as that dialogue where that window will appear. 26 00:01:47,310 --> 00:01:54,300 Nothing else underneath that new window will be active until that new window is exited but then that's 27 00:01:54,300 --> 00:02:00,000 at the expense of it being an MBA child where it will sit on top and explain exactly what I mean. 28 00:02:00,480 --> 00:02:07,770 So let's start off with the manager equally still rather let us go to the main window and then I will 29 00:02:08,640 --> 00:02:12,400 look in one of these I have this option here. 30 00:02:12,420 --> 00:02:18,360 This button click event where I said I'd rent out the record and add another one for the managed vehicle 31 00:02:18,360 --> 00:02:19,440 listing fired. 32 00:02:20,400 --> 00:02:29,940 So I am going to modify the order into the record button click event to show a dialog instead. 33 00:02:29,940 --> 00:02:36,720 Now the problem with short dialogue is that I can't sit the appear and and then show a dialogue. 34 00:02:36,720 --> 00:02:41,840 You'll get an error part so you can show an MDI child. 35 00:02:41,850 --> 00:02:45,210 So after sitting in that appearance it becomes a dead child. 36 00:02:45,210 --> 00:02:48,240 And then I can show the window as I named my child. 37 00:02:48,270 --> 00:02:53,580 However I would have to omit or at least rearrange this line of code. 38 00:02:53,670 --> 00:03:02,110 So I'd have to put Shaw above the MDI Parent Line and I would have to say sure dialogue. 39 00:03:02,390 --> 00:03:09,360 So wanted shows dialogue pretty much that show MBA that MBA child sitting in their parents sitting gets 40 00:03:09,360 --> 00:03:11,530 nullified it's irrelevant at that point. 41 00:03:11,550 --> 00:03:13,720 But let's see what happens when a short dialogue. 42 00:03:13,720 --> 00:03:16,170 So let me start. 43 00:03:16,170 --> 00:03:16,530 All right. 44 00:03:16,560 --> 00:03:21,360 So we modified the man at her entire record. 45 00:03:21,360 --> 00:03:26,070 And so when I click monitor into records that's a click event. 46 00:03:26,070 --> 00:03:27,220 Right. 47 00:03:27,240 --> 00:03:27,500 And I. 48 00:03:27,600 --> 00:03:28,080 Oh sorry. 49 00:03:28,090 --> 00:03:33,790 It's this event at her entire record when I select that notice that it is not an immediate child. 50 00:03:33,810 --> 00:03:37,110 This window launched well outside of the main window. 51 00:03:37,110 --> 00:03:42,960 However I can't do anything outside of it while it is on the screen and you can see it blinking that 52 00:03:43,020 --> 00:03:47,870 each time it blinks that's me clicking something instead of me in windows I got over me in window I 53 00:03:47,880 --> 00:03:53,970 don't interact with anything and as a result only this window will remain active until I exit it and 54 00:03:53,970 --> 00:03:57,520 then I can proceed with anything else and application. 55 00:03:57,540 --> 00:04:04,380 So that's one very simple way of allowing are ensuring that only one instance of the windows open at 56 00:04:04,440 --> 00:04:05,800 any given time. 57 00:04:05,850 --> 00:04:15,240 Like I said though as you can see the window operates independently off the main window which may not 58 00:04:15,300 --> 00:04:18,160 necessarily be a bad thing depending on your objectives. 59 00:04:18,170 --> 00:04:20,660 So I mean in this situation it's not a bad thing. 60 00:04:20,670 --> 00:04:25,800 I can move it are owned and I can't do anything else until I close it. 61 00:04:25,800 --> 00:04:26,430 Right. 62 00:04:26,430 --> 00:04:28,830 So when I close it then it's business as usual. 63 00:04:28,830 --> 00:04:33,460 So that's not necessarily the worst thing that can happen really. 64 00:04:33,480 --> 00:04:38,490 So that is how you can go both ensuring one instance off the window is up. 65 00:04:38,490 --> 00:04:43,350 So if you want you could change out all of these shows to show dialogue. 66 00:04:43,500 --> 00:04:49,050 Once again though it has to happen before the MDI period line or else you get an error. 67 00:04:49,050 --> 00:04:54,210 So you could actually just remove this line where you set the MDA appearance if you're going to be showing 68 00:04:54,210 --> 00:04:55,920 the dialog. 69 00:04:55,920 --> 00:05:02,750 However I'm going to show you another method using the managed vehicle listing menu click event. 70 00:05:03,080 --> 00:05:10,910 So this one no I'm actually it's going to be far more lines of code and a little more goes into the 71 00:05:10,910 --> 00:05:11,770 thought process. 72 00:05:11,870 --> 00:05:18,270 But the fact is that I will retain the fact that this window has an MDI period. 73 00:05:18,440 --> 00:05:18,770 All right. 74 00:05:18,770 --> 00:05:26,920 So for the other window which is monetary closings or move some code I wrote the code already. 75 00:05:26,930 --> 00:05:29,860 So let me just walk you through it. 76 00:05:29,900 --> 00:05:37,580 So what's going to happen is that we're going to be checking all of the open forms in the application. 77 00:05:37,580 --> 00:05:39,370 So on button click right. 78 00:05:39,390 --> 00:05:44,720 When manage VK listing when that button is clicked and we're able to show we're going to initialize 79 00:05:44,720 --> 00:05:46,620 we're going to set that parent. 80 00:05:46,820 --> 00:05:54,460 But then I'm going to also check to see if there is any open form inside the application as I want of 81 00:05:54,470 --> 00:06:00,710 a fact describe it a bit I do all of that first and then if there is none then I initialize a new object 82 00:06:01,100 --> 00:06:02,330 and then sure the window. 83 00:06:02,330 --> 00:06:03,650 So let's do it that way. 84 00:06:03,640 --> 00:06:04,160 All right. 85 00:06:04,340 --> 00:06:10,070 So the first thing I want to do and then you'll see if you research it you'll see a number of ways of 86 00:06:10,070 --> 00:06:11,810 doing it so be be used for each loop. 87 00:06:11,810 --> 00:06:16,070 Some people use different methods but the concept remains the same. 88 00:06:16,070 --> 00:06:22,280 I'm actually going to use the link because link allows us to iterate through any list or collection 89 00:06:22,970 --> 00:06:26,710 just like if for using a for loop or a for each loop. 90 00:06:26,800 --> 00:06:33,500 So a link is not necessarily unique to only database queries but if you have a list that you want to 91 00:06:33,500 --> 00:06:40,340 interrogate just as if it was a list of requests going from the database side list of objects you can 92 00:06:40,340 --> 00:06:42,970 do the same thing using the link anyway. 93 00:06:43,010 --> 00:06:43,310 Right. 94 00:06:43,730 --> 00:06:49,570 So the first thing I want to do is declare some variables I'm going to say var open forms. 95 00:06:50,100 --> 00:06:50,660 All right. 96 00:06:50,750 --> 00:06:56,810 And then what I want to store in here is the number of or all the open forms in the application so I 97 00:06:56,810 --> 00:07:02,450 say application dot and then I can use open forms. 98 00:07:02,450 --> 00:07:02,900 All right. 99 00:07:02,900 --> 00:07:09,410 So this is giving me a little collection all of the forms owned by the applications that application 100 00:07:09,410 --> 00:07:12,760 is what comes up or what starts to run on we click start. 101 00:07:12,790 --> 00:07:13,540 Right. 102 00:07:13,550 --> 00:07:21,950 And then all of the forms are the open forms would be any window that is open at the time off it's running. 103 00:07:21,980 --> 00:07:22,270 All right. 104 00:07:22,580 --> 00:07:28,530 So I say application that open forms but then I want to do and I kind of list of forms. 105 00:07:28,530 --> 00:07:32,180 So while it's open forms as you can see it's a different data type. 106 00:07:32,180 --> 00:07:39,690 So I want to see a dot and then cast and I'm really casting it to the data type of a form. 107 00:07:39,710 --> 00:07:47,360 So I'm basically saying give me a list of the open forms in the data type form which is what I know. 108 00:07:47,450 --> 00:07:51,110 All right so remember that everything is off the base class farm. 109 00:07:51,170 --> 00:07:54,280 So I want all of them at the base class farm. 110 00:07:54,290 --> 00:08:00,770 So it will handle that type casting for me and then give me a list of the open forms of all of the data 111 00:08:00,770 --> 00:08:02,470 type farm. 112 00:08:02,540 --> 00:08:08,390 Now after I get that list off the open forms I'm going to declare another variable where I want to say 113 00:08:08,390 --> 00:08:12,010 is open so var is open there. 114 00:08:12,020 --> 00:08:15,060 So this is really going to be a boolean rights I'm saying via. 115 00:08:15,080 --> 00:08:20,510 But it's really going to be a boolean and I I'm telling you this because of how I named it is open. 116 00:08:20,510 --> 00:08:28,700 So usually it was a Boolean if you have noticed before you can you know take note of it know that whenever 117 00:08:28,700 --> 00:08:32,630 I declare a boolean I say is this or is that right. 118 00:08:32,720 --> 00:08:35,120 And that's a common pattern in programming. 119 00:08:35,120 --> 00:08:44,180 So I would just say VAR is open and then I'm going to say Give me the list of forms so I say open forms 120 00:08:45,430 --> 00:08:53,210 and then say dot no when I say that if you just look through this list you'll see that all of the options 121 00:08:53,240 --> 00:08:57,530 that we had in the link are here and available at first are defaults. 122 00:08:57,650 --> 00:09:00,440 You have the weird of the selectee of all of them. 123 00:09:00,440 --> 00:09:03,020 The one I'm interested in this time is any. 124 00:09:03,040 --> 00:09:03,350 Right. 125 00:09:03,350 --> 00:09:08,270 So any of those to stipulate a condition. 126 00:09:08,330 --> 00:09:12,920 Is there anything that has this condition and it will give you a true or false. 127 00:09:12,920 --> 00:09:13,240 All right. 128 00:09:13,700 --> 00:09:18,520 So I can see any and then blow up my land. 129 00:09:18,530 --> 00:09:19,310 Expression. 130 00:09:19,320 --> 00:09:22,330 So cue arrow and then cue dot. 131 00:09:22,340 --> 00:09:25,760 So I'm checking if there is any farm. 132 00:09:25,820 --> 00:09:27,430 So if I say kudos to you. 133 00:09:27,430 --> 00:09:33,760 Notice that all of these just the options we see when we are creating a new instance of a farm. 134 00:09:33,760 --> 00:09:34,160 Right. 135 00:09:34,160 --> 00:09:35,420 It's the same thing. 136 00:09:35,420 --> 00:09:42,580 So would you say if there is any farm and then I can do this too is I can say by text or by name so 137 00:09:42,580 --> 00:09:44,240 I'll just stick to a name. 138 00:09:44,330 --> 00:09:48,610 So if there is any form with then name right. 139 00:09:48,640 --> 00:09:55,450 That much is or is equivalent to the name of whatever I'm able to bring up so remember that the name 140 00:09:55,540 --> 00:09:59,770 of the farm is pretty much the class name right. 141 00:09:59,800 --> 00:10:06,970 So I can say is there any form with the name manage vehicle listing because I'm a to launch manage vehicle 142 00:10:06,970 --> 00:10:14,170 listing so I want to know if there is any farm that is open that has the name of the farm I'm about 143 00:10:14,170 --> 00:10:15,400 to launch right. 144 00:10:16,180 --> 00:10:19,910 And then if it is not. 145 00:10:19,960 --> 00:10:22,570 Or if not is open. 146 00:10:22,570 --> 00:10:27,750 I remember that this really translates to if is open is equivalent to falls. 147 00:10:27,820 --> 00:10:33,750 So if it is not open already then I will do all of this. 148 00:10:33,880 --> 00:10:34,350 All right. 149 00:10:34,570 --> 00:10:41,110 So this one has a bit more lines of code but once again the point is that we're just checking to see 150 00:10:41,500 --> 00:10:48,990 if there is any open farm currently with the same name as the one I want to launch. 151 00:10:49,030 --> 00:10:52,850 And if there isn't then I can go ahead and lodge it. 152 00:10:52,870 --> 00:10:59,110 I don't need an ETS because it's either true or false so if it's false then would launch it if it's 153 00:10:59,110 --> 00:10:59,890 true then. 154 00:10:59,890 --> 00:11:02,320 Well we skipped over everything and nothing happens. 155 00:11:02,320 --> 00:11:02,940 Right. 156 00:11:02,980 --> 00:11:05,490 So let's try that one. 157 00:11:05,530 --> 00:11:05,860 All right. 158 00:11:05,860 --> 00:11:11,700 So I'm about to launch manage vehicle listing that's the click event that we just modified. 159 00:11:11,830 --> 00:11:14,980 So when I click manage vehicle listing it will launch the window. 160 00:11:15,010 --> 00:11:18,150 Notice it's the launching as an MBA child. 161 00:11:18,250 --> 00:11:20,970 I didn't change anything about the way it launched. 162 00:11:20,980 --> 00:11:24,160 However if I click the button again and I'm clicking right. 163 00:11:24,160 --> 00:11:29,200 No I see the most is moving and I'm clicking you'll only see one instance coming up. 164 00:11:29,200 --> 00:11:34,660 That's because it's is checking all the open farms and seeing that there is an open forum with that 165 00:11:34,660 --> 00:11:40,390 name already so nothing should happen if I close it and then click it again then it will work and then 166 00:11:40,390 --> 00:11:42,730 ever subsequent click does nothing. 167 00:11:42,760 --> 00:11:51,190 So we see that that is one way that we can retain that MDI child behavior but ensure that only one window 168 00:11:51,370 --> 00:11:52,770 comes up at a time. 169 00:11:54,390 --> 00:11:56,690 So you can use either method. 170 00:11:56,850 --> 00:12:05,400 Like I said the short dialogue doesn't allow for the MDA child but it does give the farm that is launching 171 00:12:05,400 --> 00:12:12,390 kind of the autonomy of not being a child but then based on your application flow under your expectations 172 00:12:12,600 --> 00:12:15,690 then you can use either one that you wish. 173 00:12:16,410 --> 00:12:16,880 No. 174 00:12:16,880 --> 00:12:27,020 Moving on we want to start looking at our grid refresh know what we want to do is ensure that after 175 00:12:27,020 --> 00:12:35,540 we do that that I'd edit operation or add delete operation that our grid refreshes automatically. 176 00:12:35,540 --> 00:12:41,840 So what happens right now is that when you add or edit a record it will you know say the success message 177 00:12:41,870 --> 00:12:48,700 but then you still have to go back to your the manage list and then you just launch applications so 178 00:12:48,700 --> 00:12:49,480 we can see. 179 00:12:49,680 --> 00:12:50,120 All right. 180 00:12:50,120 --> 00:12:54,950 So like I was saying we have to when we launch manage vehicle listing. 181 00:12:54,950 --> 00:13:03,770 If I add a new car right then I would have to come back here and then refresh manually for me to see 182 00:13:03,770 --> 00:13:04,340 the changes. 183 00:13:04,340 --> 00:13:11,060 So I want to modify that after the car and I click submit and it has been saved to the database that 184 00:13:11,060 --> 00:13:18,770 the grid refreshes and I don't I will actually be able to delete and remove or remove the need for this 185 00:13:18,770 --> 00:13:20,080 refresh button. 186 00:13:20,540 --> 00:13:27,710 So no we'll have to actually get creative just like we had to kind of get creative with the log in form 187 00:13:28,010 --> 00:13:35,840 where when we were launching our main window remember that we had to modify it to put in an object off 188 00:13:35,840 --> 00:13:43,700 the log in form into our constructor so that we could manipulate the properties of the log in form when 189 00:13:43,700 --> 00:13:46,340 we wanted or which in this case was to close it. 190 00:13:46,340 --> 00:13:53,390 So what I'm going to have to do is whatever window is launching or manage windows so manage vehicle 191 00:13:53,390 --> 00:14:00,600 listing I'm going to have to pass an object off this into the ad edit window. 192 00:14:00,860 --> 00:14:01,390 All right. 193 00:14:01,400 --> 00:14:08,060 Or even if it's the edit whichever one but once I'm caught in that window I need to pass an object of 194 00:14:08,150 --> 00:14:12,890 this into that phone showing called into that constructor call. 195 00:14:13,010 --> 00:14:13,730 Right. 196 00:14:13,760 --> 00:14:21,820 And then from this window when it launches I'll be able to you know execute with a populate grid function 197 00:14:21,830 --> 00:14:22,290 call. 198 00:14:22,820 --> 00:14:29,170 So I have a function called populate grid which runs of course runs the query sorry. 199 00:14:29,180 --> 00:14:31,710 To actually populate its own grid. 200 00:14:31,850 --> 00:14:33,080 And right now it's private. 201 00:14:33,080 --> 00:14:37,570 So we'll just do the out and then we'll seal all of the changes someone to do it with a manager eco 202 00:14:37,570 --> 00:14:44,500 listing and then I'm going to challenge you to get it done with the current records window also. 203 00:14:44,720 --> 00:14:44,960 All right. 204 00:14:46,010 --> 00:14:47,090 So let's get started. 205 00:14:47,120 --> 00:14:53,400 So the first thing that I want to do is modify my constructors and add edit vehicle so I'd edit vehicle 206 00:14:53,400 --> 00:15:00,920 ahead clean constructor and the constructor that took an object off the car. 207 00:15:01,160 --> 00:15:11,930 Now what I'm going to have to do is modify this so that I have one my private property off type manage 208 00:15:12,650 --> 00:15:17,180 vehicle listing so I'm making this global because I don't know when I'm going to need it. 209 00:15:17,180 --> 00:15:22,880 So after make it global just like I had to do with a log in and everything else that's up here and then 210 00:15:22,880 --> 00:15:29,280 I'm going to call it manage vehicle listing and then I'm going to tell this constructor. 211 00:15:29,300 --> 00:15:38,240 So just copy this quickly that it should take this concept to that had no parameters initially it should 212 00:15:38,240 --> 00:15:44,000 take parameter off type money vehicle listing on this what I want to say it does underscore manage vehicle 213 00:15:44,000 --> 00:15:48,880 listing but then the prob the parameter won't have the underscore. 214 00:15:49,440 --> 00:15:50,110 All right. 215 00:15:50,120 --> 00:15:56,740 So either constructor is supposed to take an object of manage vehicle listing. 216 00:15:57,000 --> 00:16:04,670 Now I can modify this parameter and say something like equals NULL which would then say that you may 217 00:16:04,670 --> 00:16:07,580 or may not need to pass of value in. 218 00:16:07,580 --> 00:16:07,940 All right. 219 00:16:07,940 --> 00:16:12,100 So to make it not a requirement I can see equals. 220 00:16:12,120 --> 00:16:12,430 No. 221 00:16:12,440 --> 00:16:19,220 So if you have to call this constructor but you don't want to pass in that window or this object then 222 00:16:19,520 --> 00:16:25,780 this would kind of help to ease the frustration that would happen at that point right. 223 00:16:26,090 --> 00:16:31,790 So I can do that for both of these parameters and C equals no just in case the person wants to call 224 00:16:31,790 --> 00:16:37,040 the ad or edit constructor without passing in the manage vehicle. 225 00:16:37,040 --> 00:16:42,320 Sorry I said use of what's it's really you the programmer I'm catering to this point. 226 00:16:42,320 --> 00:16:42,590 All right. 227 00:16:42,950 --> 00:16:52,700 So after we've gotten our parameters we want to initialize our local or our private object that we just 228 00:16:52,700 --> 00:16:58,250 declared or to initialize it to whatever value comes in to manage vehicle listing. 229 00:16:58,250 --> 00:17:02,000 So if it's not it's not if it's not no then we get an object. 230 00:17:02,000 --> 00:17:02,680 Right. 231 00:17:03,110 --> 00:17:08,500 So manage vehicle listing easy on the square miles you go this thing is equal to that. 232 00:17:08,660 --> 00:17:12,840 And I'll just take this line and repeat it below. 233 00:17:12,860 --> 00:17:23,800 All right and so whenever our window launches it will have some knowledge of the Managed vehicle listing 234 00:17:24,520 --> 00:17:25,990 window that called it. 235 00:17:26,010 --> 00:17:32,770 So it's easy enough to declare an object off one inside off their own time but then each time we declare 236 00:17:32,770 --> 00:17:34,780 an object it's a brand new object. 237 00:17:34,780 --> 00:17:37,390 It's not the object that exists. 238 00:17:37,400 --> 00:17:37,750 All right. 239 00:17:37,960 --> 00:17:42,850 So we want to make sure that we're tracking the one that exists are the one that called it because we 240 00:17:42,850 --> 00:17:47,380 know that the one that called it is the one that is open in the background currently showing the grid. 241 00:17:47,380 --> 00:17:48,070 All right. 242 00:17:48,070 --> 00:17:51,620 So I going to know go back. 243 00:17:51,640 --> 00:17:52,270 Sorry. 244 00:17:52,330 --> 00:18:00,980 Go back to manage equally listing and then I'm going to make sure that I just hold onto control and 245 00:18:00,980 --> 00:18:03,680 click and then I can just double click. 246 00:18:03,680 --> 00:18:06,640 So if you have more than want instances it will financially double click. 247 00:18:06,650 --> 00:18:08,340 Which one you want to jump to. 248 00:18:08,420 --> 00:18:16,210 So then my function calls to add edits vehicle or mine edit vehicle. 249 00:18:16,250 --> 00:18:22,730 Yes I noticed that there is no arrow because I did set the parameter to be knowledgeable. 250 00:18:22,750 --> 00:18:23,000 Right. 251 00:18:23,000 --> 00:18:27,080 So because I said it to be knowledgeable and let me just change it our own and just show you exactly 252 00:18:27,080 --> 00:18:27,900 what I mean. 253 00:18:27,980 --> 00:18:33,560 If I did not say that he can be equal to null then manage vehicle listing. 254 00:18:33,560 --> 00:18:38,660 This constructor would then give me a red line because then it saying that it doesn't have a constructor 255 00:18:38,660 --> 00:18:43,130 that takes all arguments it needs and it needs to pass in an argument. 256 00:18:43,130 --> 00:18:50,210 Because I said it can be equal to no let me find it back because I said it can be equal to no. 257 00:18:50,360 --> 00:18:56,810 Then I can proceed to meet the regular function call it if I want to are the regular constructor call 258 00:18:56,810 --> 00:18:58,760 without passing a parameter. 259 00:18:58,760 --> 00:18:59,030 All right. 260 00:18:59,030 --> 00:19:04,520 So that is one of those things that I'm just showing you just in case that you wanted to be more versatile. 261 00:19:04,940 --> 00:19:07,110 Either way I'm going to pass in this. 262 00:19:07,130 --> 00:19:15,410 So this surplus in some object of the manage vehicle listing window that is making the call to add edit 263 00:19:15,530 --> 00:19:16,150 vehicle. 264 00:19:16,170 --> 00:19:16,660 Right. 265 00:19:16,760 --> 00:19:23,000 So I'll put this in for the ad click and also do the same for the edit. 266 00:19:23,030 --> 00:19:28,880 So they see the edit click is the same thing it's passing in car which is our required parameter but 267 00:19:28,910 --> 00:19:31,380 it's not crying all the time all the money. 268 00:19:31,380 --> 00:19:32,110 Vehicle listing. 269 00:19:32,120 --> 00:19:36,500 However I will say comma this all right. 270 00:19:36,500 --> 00:19:38,540 No that that is done. 271 00:19:38,540 --> 00:19:45,620 What will happen is that when we add or edit the vehicle once we complete our operation in this function 272 00:19:45,620 --> 00:19:46,510 call. 273 00:19:46,550 --> 00:19:47,270 All right. 274 00:19:47,300 --> 00:19:52,450 The expectation is that our grid is going to refresh. 275 00:19:52,460 --> 00:19:58,700 So what I'm going to do is before show in the message box and seeing everything is completed I'm going 276 00:19:58,700 --> 00:19:59,480 to put in 277 00:20:02,270 --> 00:20:09,950 call to our objects to underscore manage vehicle listing and then I would call populates grid. 278 00:20:10,220 --> 00:20:12,220 No notice that I can't call it. 279 00:20:12,230 --> 00:20:14,810 It's not coming up in the this sense. 280 00:20:14,920 --> 00:20:17,830 And even if I type it all out it's not calling it. 281 00:20:17,870 --> 00:20:18,530 All right. 282 00:20:18,590 --> 00:20:20,960 So what happens is that it is private. 283 00:20:21,050 --> 00:20:25,160 So it's private over inside of our managed vehicle listing. 284 00:20:25,160 --> 00:20:28,410 Let me see if I can find it quickly. 285 00:20:28,610 --> 00:20:29,580 It's private here. 286 00:20:29,580 --> 00:20:32,060 Second call it from outside. 287 00:20:32,060 --> 00:20:37,520 So if I make it public then that problem gets solved. 288 00:20:37,520 --> 00:20:43,350 So I say public void populate grid and then we'll be able to call it. 289 00:20:43,370 --> 00:20:45,550 So let's review the expectation here. 290 00:20:45,560 --> 00:20:55,610 When I click save on whether it's an ad for operation or an edit operation the expectation is that our 291 00:20:55,730 --> 00:21:03,230 you know we do everything that we know we do we check if it's edit mode and we populate or object accordingly. 292 00:21:03,230 --> 00:21:08,350 So you see that we kind of repeated code and we kind of reflected that the last time sort of a BBC if 293 00:21:08,350 --> 00:21:09,390 change is here. 294 00:21:09,440 --> 00:21:16,570 However BBC if change is here and I really wouldn't want to repeat those things all the time right. 295 00:21:16,580 --> 00:21:26,410 So what I'll do is remove these lines of code so I'm just refactoring right now and then I'm going to 296 00:21:26,680 --> 00:21:32,320 take the same lines of code that were repeated and then put them outside of the check if it is a mode 297 00:21:32,320 --> 00:21:33,120 or not. 298 00:21:33,120 --> 00:21:33,390 All right. 299 00:21:34,090 --> 00:21:36,520 So check if it is valid. 300 00:21:36,520 --> 00:21:40,700 Else if it is edit mode then we want to do this. 301 00:21:40,810 --> 00:21:46,390 If it is not it it more than we want to do that either way at the end of the day we want to see if the 302 00:21:46,400 --> 00:21:49,870 changes populate the grid and then. 303 00:21:49,900 --> 00:21:51,820 Sure analogy. 304 00:21:51,910 --> 00:21:59,520 Just make a generic message operation completed refresh to see changes and then we close. 305 00:21:59,590 --> 00:21:59,920 All right. 306 00:22:00,340 --> 00:22:05,210 So then what should happen is that when we click save on it does either operation. 307 00:22:05,350 --> 00:22:13,120 It's actually just going to populate the grid call the populate grid function in the manage in the manage 308 00:22:13,120 --> 00:22:18,880 vehicle listings window and a room without populate grid is what runs the query since the data source 309 00:22:18,880 --> 00:22:25,300 and all of the operations in between and then that should trigger the refresh off the grid. 310 00:22:25,330 --> 00:22:26,470 So let's that that's. 311 00:22:26,970 --> 00:22:27,330 All right. 312 00:22:27,330 --> 00:22:36,250 So we launch our monitors vehicle listing window I click add new car and then I'm going to see the ME 313 00:22:37,210 --> 00:22:45,940 is high on a sorry high on day i 20. 314 00:22:46,050 --> 00:23:00,090 This is twin to 19 model sorry the VIN is it just puts in something random the year is 20 18 and the 315 00:23:00,090 --> 00:23:08,330 license plate is that we click save changes it says operation is completed refresh to see changes Okay 316 00:23:08,340 --> 00:23:10,230 fine but then look at that. 317 00:23:10,290 --> 00:23:13,250 It's already refreshed for me so I can change a message. 318 00:23:13,250 --> 00:23:17,660 No I don't need to tell them to click refresh second of the refresh button there. 319 00:23:17,700 --> 00:23:23,940 But the point is that the operation would refresh the grid automatically. 320 00:23:23,990 --> 00:23:24,540 All right. 321 00:23:24,570 --> 00:23:25,620 The same for edit. 322 00:23:25,890 --> 00:23:31,770 If I say I wanted to edit this and I wanted to clean up this Vin a bit because I put in the wrong video. 323 00:23:33,570 --> 00:23:33,960 All right. 324 00:23:33,960 --> 00:23:36,340 And then save changes operation completed. 325 00:23:36,340 --> 00:23:39,310 Now you see the changed Vin. 326 00:23:39,330 --> 00:23:43,310 Going in and everything is happening real time right. 327 00:23:43,320 --> 00:23:46,560 So that's all you can do that grid refresh operation. 328 00:23:46,560 --> 00:23:48,710 So I did it with a manage vehicle listing. 329 00:23:48,780 --> 00:23:50,390 Well I didn't do it with the lead car. 330 00:23:50,390 --> 00:23:54,310 Let me make sure I did it with the lead car so I no longer have this car in my fleet. 331 00:23:54,310 --> 00:23:55,090 In fact delete. 332 00:23:55,110 --> 00:23:58,060 You see that nothing happened so delete. 333 00:23:58,080 --> 00:23:58,890 Nothing happens. 334 00:23:58,890 --> 00:24:03,500 No visual cue of anything but if I refresh you'll see that it disappears. 335 00:24:03,600 --> 00:24:04,110 All right. 336 00:24:04,800 --> 00:24:07,320 If I tried to delete again I would have gotten an error. 337 00:24:07,650 --> 00:24:15,790 So what we want to do then is make sure that our delete function tells us that the operation was successful. 338 00:24:15,840 --> 00:24:18,480 And it refreshes at the same time. 339 00:24:18,510 --> 00:24:21,420 You mean you want to give them a yes or no. 340 00:24:21,420 --> 00:24:24,210 Are you sure you want to delete kind of prompt. 341 00:24:24,300 --> 00:24:29,560 So I'm back in the mileage vehicle listing so initially I'd try it. 342 00:24:29,580 --> 00:24:36,100 Ah re fresh using this function but that kind of does something different from what we want to do. 343 00:24:36,130 --> 00:24:45,090 Someone to remove this and then what we're going to do is say 1 if the person clicks the delete button 344 00:24:45,360 --> 00:24:53,670 we get the the details you know we get the object and everything and then what I'm going to do is write 345 00:24:53,670 --> 00:24:57,690 some code and I wrote it quickly so I'll just explain it to you. 346 00:24:57,720 --> 00:25:03,870 So what we're doing is doing a message box that allows us to prompt the user. 347 00:25:03,870 --> 00:25:07,370 Are you sure you want to delete so when you click the delete button. 348 00:25:07,470 --> 00:25:12,960 It's going to retrieve the record is going to retrieve the idea and the record associated with the I.T. 349 00:25:12,960 --> 00:25:13,650 sorry. 350 00:25:13,650 --> 00:25:15,950 And then we're launching a dialog box. 351 00:25:15,960 --> 00:25:20,970 Now remember that the dialog box is a box that comes up that prevents you from interacting with any 352 00:25:20,970 --> 00:25:22,350 other open window right. 353 00:25:22,710 --> 00:25:28,390 So this dialog box our dialog result is the data type and object is D.R.. 354 00:25:28,410 --> 00:25:34,440 That's what we're calling it and we're seeing I want a dialog results that has the value off our message 355 00:25:34,440 --> 00:25:35,330 box. 356 00:25:35,400 --> 00:25:39,760 So and then this the message we're showing are you sure you want to delete this record. 357 00:25:39,840 --> 00:25:45,410 You can put in even more details in this if you want because you already retrieved the car object sake 358 00:25:45,410 --> 00:25:51,870 and say Are you sure you want to delete the car name so to speak or the car model car make if you want 359 00:25:52,470 --> 00:25:56,220 and then this is the title of the dialog box which is delete. 360 00:25:56,370 --> 00:25:59,680 Then we see we want to show message box buttons. 361 00:25:59,700 --> 00:26:02,940 Yes no or console so when it comes up it will come up with that. 362 00:26:02,950 --> 00:26:07,490 Yes I know and I cancel button and then we're showing an icon. 363 00:26:07,500 --> 00:26:12,300 That's a warning call we're warning that we're letting them know that they're just entered the danger 364 00:26:12,300 --> 00:26:12,960 zone right. 365 00:26:13,620 --> 00:26:19,080 And then after we've prompted them we're seeing if the result is yes. 366 00:26:19,080 --> 00:26:25,440 Meaning they click the yes button then we want to proceed to remove the car. 367 00:26:25,560 --> 00:26:26,070 All right. 368 00:26:26,070 --> 00:26:33,250 And then having removed the car we can call populate grid all right. 369 00:26:33,440 --> 00:26:35,410 And a spelling error there. 370 00:26:35,540 --> 00:26:41,990 So we can call populates grid and then that should refresh our grid. 371 00:26:42,020 --> 00:26:44,410 So let's try that lead operation. 372 00:26:44,660 --> 00:26:44,960 All right. 373 00:26:44,960 --> 00:26:48,860 So we're back and our goal is to try to delete Toyota. 374 00:26:48,950 --> 00:26:52,460 I don't think Toyota has any rental records associated with it. 375 00:26:52,460 --> 00:26:58,360 I can always check so I can always just go over view the archive and I don't see anything with Toyota. 376 00:26:58,370 --> 00:27:01,480 So I shouldn't have any difficulty deleting Toyota. 377 00:27:01,610 --> 00:27:04,960 I click delete and then it's giving me that dialog box. 378 00:27:04,970 --> 00:27:06,980 Are you sure you want to delete this record. 379 00:27:06,980 --> 00:27:08,950 Yes no maybe so I click. 380 00:27:08,960 --> 00:27:09,390 Yes. 381 00:27:09,440 --> 00:27:15,010 And then boom it removes it and then it refreshes the grid automatically for me. 382 00:27:15,020 --> 00:27:16,150 All right let's try. 383 00:27:16,170 --> 00:27:17,860 Subaru also if I. 384 00:27:17,870 --> 00:27:18,350 No. 385 00:27:18,470 --> 00:27:19,500 Then nothing happens. 386 00:27:19,500 --> 00:27:19,970 Exactly. 387 00:27:19,980 --> 00:27:22,930 Cancel then nothing happens. 388 00:27:22,940 --> 00:27:27,760 But then once I click yes then it is removed. 389 00:27:27,760 --> 00:27:28,070 All right. 390 00:27:28,400 --> 00:27:32,040 So we just cleaned up our application a bit. 391 00:27:32,040 --> 00:27:34,290 We made sure that's only one window opens. 392 00:27:34,430 --> 00:27:39,470 And we also put in some grid refresh capabilities into our windows. 393 00:27:39,470 --> 00:27:41,450 So I did it with managed vehicle listing. 394 00:27:41,450 --> 00:27:47,450 I'm challenging you to try and repeat those steps with the managed rental records either way in the 395 00:27:47,450 --> 00:27:53,090 next video we're going to be checking in our code into source control I would love all the code ready 396 00:27:53,180 --> 00:28:00,350 and available and commented so you can check the repository for the completed code in case you need.