1
00:00:01,070 --> 00:00:07,400
In this video we're going to start building some functionality behind our buttons to add edit and delete

2
00:00:07,490 --> 00:00:10,250
our cars from our database.

3
00:00:10,250 --> 00:00:16,370
Before I continue though I want to show you some change that I made here to the grid view where we were

4
00:00:16,400 --> 00:00:24,350
filling or grid view with the custom model or a collection or a list of the custom model coming from

5
00:00:24,350 --> 00:00:28,640
our database for the make model Vin year and license plate number.

6
00:00:28,830 --> 00:00:36,950
And the column for license plate number would have displayed this in case which is undesirable to me

7
00:00:37,700 --> 00:00:39,020
in terms of presentation.

8
00:00:39,020 --> 00:00:45,500
So what I did was to go underneath and actually set a custom header text for the fourth or the fifth

9
00:00:45,500 --> 00:00:48,170
column that would have been in our grid view.

10
00:00:48,180 --> 00:00:52,880
So remember that this would be 0 1 2 3 4.

11
00:00:52,910 --> 00:00:57,920
So the fourth one would have gotten the custom header tech start.

12
00:00:58,340 --> 00:01:04,760
So in order to put in some functionality First we need to understand the behavior that we're aiming

13
00:01:04,760 --> 00:01:13,370
for at least that I'm aiming for the behavior I'm expecting is that a user would select a column and

14
00:01:13,370 --> 00:01:20,090
then click edit car or they would just click I do car and you know a new window comes up allowing them

15
00:01:20,090 --> 00:01:27,830
to fill out the form click submit and we're going to make at least the make and the model and the let's

16
00:01:27,830 --> 00:01:33,370
say the license plate number mandatory so you know you can customize your own validations plan when

17
00:01:33,380 --> 00:01:40,760
to put in some amount of validation in that form if they select roll and then click edit then the expectation

18
00:01:40,760 --> 00:01:48,620
is that a window similar to the ad new car window will pop up allowing them to modify the details of

19
00:01:48,620 --> 00:01:51,830
whatever record they selected.

20
00:01:51,830 --> 00:01:58,580
And then when they click submit or to see if changes it will update that's in the database in a similar

21
00:01:58,580 --> 00:02:02,210
fashion when they select a rule and then click delete.

22
00:02:02,210 --> 00:02:07,760
We want to one ask them Are they sure you what they want to delete and if they proceed to click yes

23
00:02:07,790 --> 00:02:10,970
then we proceed to delete the car.

24
00:02:10,970 --> 00:02:17,060
So in this video we're going to be looking at a few things where we're going to be creating a new form

25
00:02:17,090 --> 00:02:25,040
and then we can't constructor overloading as to how we can pass values into our farms so that this form

26
00:02:25,040 --> 00:02:26,900
will load with a set of values.

27
00:02:26,900 --> 00:02:34,130
So in this situation we're actually going to use the same form for the ad new car and it's because it's

28
00:02:34,130 --> 00:02:35,450
the same sets of fields.

29
00:02:35,510 --> 00:02:42,080
We're building one farm and then we look at passing values in as at the time of loading so that we get

30
00:02:42,170 --> 00:02:46,480
different outcomes from the same farm and different functionality.

31
00:02:46,500 --> 00:02:49,660
I don't want to make some modifications to my grid view.

32
00:02:49,670 --> 00:02:53,220
The first thing I'm going to do is include the.

33
00:02:53,240 --> 00:03:00,050
So we did build the custom model we said make model all the things that we want to display to the user

34
00:03:00,050 --> 00:03:03,010
are all here and you notice that they're kind of great.

35
00:03:03,040 --> 00:03:10,850
So if you hover over it the light bulb is really telling you that since the custom name that we're giving

36
00:03:10,850 --> 00:03:17,840
it is the same as the actual column name then we really don't need to see me equals the same column

37
00:03:17,840 --> 00:03:18,170
name.

38
00:03:18,170 --> 00:03:24,020
So if you just get the lightning bolt and use its suggestion then you see that it just replaces it DNC

39
00:03:24,050 --> 00:03:25,980
that you could just reference it does me.

40
00:03:26,400 --> 00:03:26,630
Right.

41
00:03:26,630 --> 00:03:31,490
So you could go through and clean it up if you want but I'm going to leave it as it is.

42
00:03:31,490 --> 00:03:32,390
No.

43
00:03:32,420 --> 00:03:39,080
So that it's clear what exactly is happening the modification I want to make however is to add the I.D.

44
00:03:39,110 --> 00:03:48,260
because when I select our role and then I want to click edit I need to know what I'm selecting and the

45
00:03:48,260 --> 00:03:55,190
best way to know what room selecting or what car I'm selecting is to know the idea of that vehicle.

46
00:03:55,190 --> 00:03:55,640
Right.

47
00:03:55,670 --> 00:04:00,790
So the same way that we needed idea when we were saving it in the car or a courtroom but that we have

48
00:04:00,790 --> 00:04:08,540
to bind the value member of I.T. I need a way to find that value member in my four hour from my grid

49
00:04:08,750 --> 00:04:15,170
so that when I click edit I can do a lookup for that particular car based on its unique identifier which

50
00:04:15,170 --> 00:04:21,370
is the I.D. and then return that data to the form so that it can be up for editing.

51
00:04:21,380 --> 00:04:27,230
So what I'm going to do is just continue underneath the license plate number and then I'm just going

52
00:04:27,230 --> 00:04:29,070
to say cue dot I.D..

53
00:04:29,300 --> 00:04:35,780
So I I could say I.D. equals a cute idea but then the lightning bolt would once again up you're telling

54
00:04:35,780 --> 00:04:37,450
me that this is redundant.

55
00:04:37,520 --> 00:04:41,090
So I don't need to see the I.D. equal to the same column name.

56
00:04:41,090 --> 00:04:48,980
So just to drive my point home or to appease Visual Studio I'm just going to say cue that I.D. just

57
00:04:48,980 --> 00:04:53,440
to show that I didn't have to specify a column name all the time.

58
00:04:53,450 --> 00:04:54,040
Right.

59
00:04:54,110 --> 00:05:01,550
So I'm including to I.D. into the data set that is being returned which means that my grid is going

60
00:05:01,550 --> 00:05:06,830
to definitely generate a column for the I.D. which I don't necessarily want because I don't need to

61
00:05:06,830 --> 00:05:08,410
see the I.D. column.

62
00:05:08,420 --> 00:05:13,870
So what I'm going to do is underneath where I set the header text for the license plate number I'm going

63
00:05:13,880 --> 00:05:25,110
to say GV vehicle list dot columns and then I can specify that I want the fifth column or the will of

64
00:05:25,110 --> 00:05:32,080
the sixth column or a column with a subscript five which would represent my I.D. I want it I want its

65
00:05:32,090 --> 00:05:35,640
visibility to be set to falls right.

66
00:05:35,690 --> 00:05:40,910
So even though it's there it will show up but I know it's there and I am sitting it there because I

67
00:05:40,910 --> 00:05:44,770
know that when I need the value from it I can get that value.

68
00:05:44,780 --> 00:05:48,310
So I'm putting it there but I'm making it hidden.

69
00:05:48,380 --> 00:05:48,710
All right.

70
00:05:49,340 --> 00:05:58,260
So let's go ahead and prepare our ad edit form so I'm just going to regulate my project at a new farm.

71
00:05:58,850 --> 00:06:08,230
I'm going to call this one I'd edit vehicles or ad edit vehicle and then that's my new form someone

72
00:06:08,270 --> 00:06:16,210
to explore some new editing techniques in this one so the first thing I want to do is change the title.

73
00:06:16,280 --> 00:06:18,440
So I want to.

74
00:06:18,770 --> 00:06:21,500
Well I'm actually going to set the title on the fly.

75
00:06:21,520 --> 00:06:29,060
So I'm going to show you guys that a lot of these things can be controlled from the code behind us at

76
00:06:29,150 --> 00:06:30,980
the time as at runtime right.

77
00:06:30,980 --> 00:06:33,800
So I am using it for two purposes.

78
00:06:33,830 --> 00:06:39,800
Adding and editing but when it is going to be time to add something I wanted to see add vehicle when

79
00:06:39,800 --> 00:06:46,000
I want to edit I wanted to see it vehicle what I don't want is for it to say and edit vehicle rights

80
00:06:46,020 --> 00:06:49,550
I'm going to show you how you can set that during runtime.

81
00:06:49,550 --> 00:06:52,970
Another thing that we want to look at in this is the power off label.

82
00:06:52,990 --> 00:06:59,350
So if I go to my tool box and I go to the containers section then I see that I have a few labels.

83
00:06:59,360 --> 00:07:06,200
You have the floor panel which kind of takes things and stacks them side by side automatically of the

84
00:07:06,200 --> 00:07:11,210
group Box which is usually used that went out radio buttons and Chip boxes that you want to associate

85
00:07:11,210 --> 00:07:12,490
with each other.

86
00:07:12,650 --> 00:07:19,520
You have a panel of the split country and area of type controls and you have to believe someone to borrow

87
00:07:19,520 --> 00:07:25,360
the table labeled here drag it over and you know Android's over the section that I wanted.

88
00:07:25,700 --> 00:07:29,600
And you notice that it's just one big box red one big grid box.

89
00:07:29,600 --> 00:07:34,900
So what I intend to do here is put the labels to the left and the controls to the right.

90
00:07:35,270 --> 00:07:41,810
So I can actually resize this and you notice that the grid that the cells actually resize accordingly.

91
00:07:41,810 --> 00:07:43,500
I have a boat.

92
00:07:43,520 --> 00:07:49,650
Let me check my database of 1 2 3 4 5 feels that need to be filled.

93
00:07:49,650 --> 00:07:52,730
So I need at least five rows.

94
00:07:52,730 --> 00:07:59,510
So using the black carrots at the top right hand corner I can add a as I can add columns as I need to

95
00:07:59,840 --> 00:08:03,370
and I can also edit the rows and columns.

96
00:08:03,370 --> 00:08:05,600
So I want to add a few rows.

97
00:08:05,600 --> 00:08:07,160
And like I said I need five.

98
00:08:07,190 --> 00:08:10,360
So that's one two three four five.

99
00:08:10,370 --> 00:08:16,490
So I have one extra I can remove the last of the sorry that was the column.

100
00:08:16,490 --> 00:08:18,670
Let me just undo that quickly.

101
00:08:18,700 --> 00:08:22,000
All right someone to remove the last row actually.

102
00:08:22,250 --> 00:08:29,390
And then you notice that you know sizing is not so key and so you can always just drug and resize as

103
00:08:29,390 --> 00:08:30,780
you see fit.

104
00:08:30,830 --> 00:08:33,490
And this may still not work go to be the best.

105
00:08:33,560 --> 00:08:40,010
So you can actually just go to edit rows and columns and then you can see the type of sizing you want

106
00:08:40,010 --> 00:08:46,370
for your columns and you can use the dropdown at the top and see rows and you can choose the sizing

107
00:08:46,370 --> 00:08:47,710
you want for your rules.

108
00:08:47,840 --> 00:08:53,330
So you can see they have percentage and you have absolute someone to select all and then going to say

109
00:08:53,330 --> 00:09:00,090
I want all of them to be 50 percent that I click Okay you see that everything kind of normalizes and

110
00:09:00,110 --> 00:09:03,350
if I expand they'll kind of expand with that.

111
00:09:03,390 --> 00:09:04,100
Right.

112
00:09:04,130 --> 00:09:06,890
So that's my table layout.

113
00:09:07,220 --> 00:09:11,090
And then I'm going to drop in the Add button.

114
00:09:11,150 --> 00:09:22,280
So I just bring over my button to go key and then I want my button to see save changes.

115
00:09:22,290 --> 00:09:23,880
Right.

116
00:09:24,050 --> 00:09:30,500
So I have one button that says See if changes and I'm want to put that one to the left and then I'm

117
00:09:30,550 --> 00:09:36,330
to have another button that is going to see cancel that one I'm putting to the right.

118
00:09:36,350 --> 00:09:41,620
So you know we're just building this so you may have different design ideas from me and that's fine.

119
00:09:41,630 --> 00:09:45,580
That's actually excellent if you're thinking differently from me.

120
00:09:45,800 --> 00:09:48,620
But if you're not then that's fine too.

121
00:09:48,650 --> 00:09:49,630
We're in this together.

122
00:09:49,640 --> 00:09:57,050
So I'm just collapsing this a bit and then I'm going to put in a war or label so we know that every

123
00:09:57,050 --> 00:10:03,890
forum we tried to put a label at the top and then I'm going to meet this label see add or edit new car

124
00:10:03,980 --> 00:10:14,410
so add new car right or actually them when to leave this label blank and better yet I'm going to make

125
00:10:14,410 --> 00:10:17,800
it see what I wanted to see based on the more.

126
00:10:17,830 --> 00:10:23,390
So I'm going to just change its name so that I know the control from the code bans on what to call it

127
00:10:23,410 --> 00:10:27,730
LBO title All right so even your labels.

128
00:10:27,740 --> 00:10:33,470
Yes we weren't really naming labels because we didn't necessarily need to call them from the code behind.

129
00:10:33,470 --> 00:10:40,850
But I want to call this one and I want to feel the content relative to the mode that this form is in

130
00:10:40,850 --> 00:10:41,850
print.

131
00:10:41,870 --> 00:10:47,630
So once again I'm creating a form I'm calling it ad edit vehicle.

132
00:10:47,750 --> 00:10:55,060
This form has been dubbed the dual purpose of providing fields for adding a car versus editing car.

133
00:10:55,120 --> 00:10:55,790
Right.

134
00:10:55,820 --> 00:11:00,000
And adding and editing are pretty much the same operations.

135
00:11:00,020 --> 00:11:04,250
Well at least the same fields are involved in both operations.

136
00:11:04,250 --> 00:11:13,680
So in the tool box I'm just going to take over a few labels drag them drop them inside of these rules.

137
00:11:14,400 --> 00:11:20,880
So they may have may get online trying to put them in some just pasting pasting so that all of them

138
00:11:20,910 --> 00:11:23,290
go into the left hand side.

139
00:11:23,490 --> 00:11:28,120
And then I just delete the extra ones from the right hand side because I don't really want them there.

140
00:11:28,290 --> 00:11:36,410
And then I'll drag over the text boxes so everything here is really a text box anyway.

141
00:11:36,410 --> 00:11:36,750
All right.

142
00:11:36,780 --> 00:11:43,760
So text box inside of that one and I'm just pasting so I'm filling out all of these with ticks boxes

143
00:11:43,770 --> 00:11:45,840
then I modify my labels.

144
00:11:45,840 --> 00:11:54,400
So the first label would be for the make of the car the second label would be for the just right click

145
00:11:54,760 --> 00:11:56,660
properties and then a pin properties.

146
00:11:56,660 --> 00:11:58,390
I can move a bit faster.

147
00:11:58,390 --> 00:12:04,360
So the other one would be for the model and then I mean in a real world situation you probably want

148
00:12:04,360 --> 00:12:09,450
to give them dropdown lists for make and model because you don't want them to be typing in Honda without

149
00:12:09,460 --> 00:12:14,270
an H or Toyota and spelling it with an extra E.

150
00:12:14,290 --> 00:12:16,880
Stuff like that so you probably want to give them drop.

151
00:12:16,900 --> 00:12:22,180
But for the simplicity of the sake of these examples and these lessons I'm not going to go into all

152
00:12:22,180 --> 00:12:22,530
of that.

153
00:12:22,530 --> 00:12:26,590
I just want us to have some key concepts under our grasp.

154
00:12:26,650 --> 00:12:38,290
So the next one would be the VIN the next label would be our license or our year rather and then the

155
00:12:38,290 --> 00:12:41,260
final one would be the license plate.

156
00:12:43,050 --> 00:12:45,890
No all right.

157
00:12:46,010 --> 00:12:50,990
Saw that it was click each label change the property for the text.

158
00:12:50,990 --> 00:12:54,210
If you want you can meet them bigger and more pronounce.

159
00:12:54,260 --> 00:12:55,310
That's fine.

160
00:12:55,310 --> 00:12:58,520
I'm just going to leave those that way for no.

161
00:12:58,520 --> 00:12:59,240
All right.

162
00:12:59,240 --> 00:13:05,090
And then we have the respective takes boxes to get the values for each.

163
00:13:05,120 --> 00:13:12,860
Now let's go over to the code file and start adding some code that will make or or form a bit more dynamic

164
00:13:12,890 --> 00:13:16,010
so as is typical we have our class.

165
00:13:16,160 --> 00:13:22,310
We have the name of the form inheriting from our beast school form and then we have our base constructor

166
00:13:22,310 --> 00:13:27,470
which is initializing the component in stride knowing this be a SQL instructor I can actually start

167
00:13:27,470 --> 00:13:28,450
setting other things.

168
00:13:28,450 --> 00:13:36,320
So I want to maybe set the title so if this constructor or the form is loaded using this constructor

169
00:13:36,620 --> 00:13:41,150
then I want the title text to see add new vehicle

170
00:13:44,200 --> 00:13:45,660
all right.

171
00:13:46,130 --> 00:13:55,220
And then maybe I want the well I could change the button to text also so as I said before we want to

172
00:13:55,460 --> 00:13:58,400
make sure that we put name store controls.

173
00:13:58,400 --> 00:13:59,930
So I actually skip that step.

174
00:13:59,930 --> 00:14:06,470
So let's go back and put names to our controls properly so that we don't have any problems moving forwards

175
00:14:06,470 --> 00:14:11,960
or take Suboxone is really t the MC Right.

176
00:14:12,050 --> 00:14:15,000
So is it takes blocks for the make of the vehicle.

177
00:14:15,500 --> 00:14:27,180
We have the second one being t the model we have the third one being TB V and TB even.

178
00:14:27,240 --> 00:14:35,650
We have the fourth one being TB here and then this one is TV license plate number.

179
00:14:35,680 --> 00:14:41,000
So TV license I know this certainly sensitive license and not right.

180
00:14:41,020 --> 00:14:47,760
And then for our buttons and went to have Beatty and save.

181
00:14:47,770 --> 00:14:48,470
All right.

182
00:14:48,580 --> 00:14:53,340
And then for cancel and went off Beatty and cancel.

183
00:14:53,650 --> 00:14:57,100
And then while I'm here I'm just going to set up those quick events.

184
00:14:57,310 --> 00:14:58,440
So be GNC.

185
00:14:58,450 --> 00:15:00,190
Click event and Beatty in Kansas.

186
00:15:00,190 --> 00:15:05,380
Click event once again to create those you just double click a control then it will generate the Click

187
00:15:05,380 --> 00:15:06,240
event.

188
00:15:06,340 --> 00:15:10,380
No back in our code file I'm going to create a second controller.

189
00:15:10,390 --> 00:15:13,900
So this is what we'll call overwriting right or overloading.

190
00:15:13,900 --> 00:15:19,480
So we have this concept in programming called function overloading and in Opal or pea you can actually

191
00:15:19,480 --> 00:15:21,540
overload constructors.

192
00:15:21,550 --> 00:15:21,820
Right.

193
00:15:21,820 --> 00:15:27,940
So we have a constructor that's taking zero parameters on when to overload display constructor and I'm

194
00:15:27,940 --> 00:15:37,050
going to want it to take a Parmenter of type of car and then I'm want to call it car right.

195
00:15:37,510 --> 00:15:42,210
Or you know what I'm going to be very specific and I want to see car to edit.

196
00:15:42,400 --> 00:15:47,650
So that we know exactly the purpose of this property.

197
00:15:47,650 --> 00:15:48,280
Right.

198
00:15:48,280 --> 00:15:50,150
So cart at it.

199
00:15:50,190 --> 00:15:50,470
All right.

200
00:15:50,470 --> 00:15:58,810
So when we load the form with this constructor we're expected to pass in an object of type types of

201
00:15:58,810 --> 00:16:07,290
car and then we will then use it to fill out the data points in the text boxes as they are there already.

202
00:16:07,300 --> 00:16:08,020
Right.

203
00:16:08,050 --> 00:16:14,750
So of course if I'm if I'm loading the form then I need initialized component.

204
00:16:14,750 --> 00:16:16,260
So that has to be there.

205
00:16:16,330 --> 00:16:20,090
I'm also going to take the part where I'm sitting the title.

206
00:16:20,170 --> 00:16:27,050
So if it's loaded with this one which is for the edit mode then I'm going to see edit vehicle.

207
00:16:27,190 --> 00:16:27,860
All right.

208
00:16:27,910 --> 00:16:35,950
So if we load the form using this constructor it's to add a new vehicle if I load the form using the

209
00:16:35,950 --> 00:16:43,030
second constructor which is the Overlord then it is to edit said vehicle further to setting the title

210
00:16:43,030 --> 00:16:44,980
for the editing.

211
00:16:45,100 --> 00:16:50,070
What I'm want to do is create a function called populate fields.

212
00:16:50,070 --> 00:16:50,620
All right.

213
00:16:51,100 --> 00:16:55,900
So the cool thing about visual studio is that I can write the function call I don't until a function

214
00:16:55,900 --> 00:17:01,540
called populate fields I just wrote it and then you see the lightning bolt is coming up with a red X

215
00:17:01,540 --> 00:17:04,990
and it's asking me Do you want to generate the method for that.

216
00:17:05,020 --> 00:17:09,530
So if I click that then it automatically just generates that method for me.

217
00:17:09,530 --> 00:17:09,840
Right.

218
00:17:09,840 --> 00:17:15,250
So it makes coding much more efficient than it could be otherwise.

219
00:17:15,250 --> 00:17:15,940
Right.

220
00:17:15,970 --> 00:17:25,180
So instead of populate fields I'm going to be setting the field values to whatever the matching field

221
00:17:25,180 --> 00:17:26,990
value is coming over from this object.

222
00:17:26,980 --> 00:17:34,630
So actually I'm going to pass this object into populated fields so I'm passing type of types of car

223
00:17:34,630 --> 00:17:41,840
into that and I'm going to make sure that this function also knows of the incoming data.

224
00:17:41,850 --> 00:17:42,580
All right.

225
00:17:42,640 --> 00:17:49,630
So I could just call this car just to show you that once again I'm getting a property or I'm getting

226
00:17:49,900 --> 00:17:53,170
an object of type types of car.

227
00:17:53,390 --> 00:17:53,710
Right.

228
00:17:53,710 --> 00:17:59,680
So this represents the data from the database and this is the object that has the data that we're going

229
00:17:59,680 --> 00:18:01,710
to be editing in the farm right.

230
00:18:01,780 --> 00:18:08,320
And then I'm getting it in this constructor ammunition as in my components I'm setting the title off

231
00:18:08,320 --> 00:18:15,960
the whole form to be edit vehicle and then I'm seeing I want to start populating the fields in the form.

232
00:18:16,090 --> 00:18:17,420
Here is the data.

233
00:18:17,470 --> 00:18:23,710
So instead of the actual function populate fields I'm getting that object.

234
00:18:23,710 --> 00:18:28,200
So I'm just calling it Kyra this to show you that it doesn't necessarily have to have the same name.

235
00:18:28,270 --> 00:18:34,630
It must however have the same data type because if I said integer then that would cause an arrow in

236
00:18:34,630 --> 00:18:39,120
the function called cause then it seeing well passing some invalid data type.

237
00:18:39,130 --> 00:18:43,050
So the data types the much the name doesn't necessarily have to match.

238
00:18:43,130 --> 00:18:48,650
And then what I'm going to be doing inside populate fields is calling each text box.

239
00:18:48,700 --> 00:18:55,310
So if I say TV Let's start from the top make dot text.

240
00:18:55,740 --> 00:19:04,030
All right is going to be equal to the object coming in dot and then the corresponding data that that

241
00:19:04,050 --> 00:19:05,860
text box should have.

242
00:19:05,860 --> 00:19:16,270
So I can do that for every one of them TV model dot text is equal to car dot model.

243
00:19:16,270 --> 00:19:16,530
All right.

244
00:19:16,540 --> 00:19:19,940
So um when you can pause here and try and do them all on your own.

245
00:19:20,050 --> 00:19:21,220
I'm just going to finish them up.

246
00:19:21,940 --> 00:19:22,320
All right.

247
00:19:22,330 --> 00:19:27,010
So if you pause then try it it's on your own then you would have something looking at this if you have

248
00:19:27,010 --> 00:19:34,210
an arrow trying to put the year into the text box then a you need to make it a string in order for it

249
00:19:34,210 --> 00:19:36,670
to go into the text of the text box.

250
00:19:36,670 --> 00:19:37,290
Right.

251
00:19:37,300 --> 00:19:47,020
So once again we're seeing that we can load this form normally right or we can decide to call the constructor

252
00:19:47,260 --> 00:19:54,760
with some data put some data to this construct a version of the farm and then that construct to proceed

253
00:19:55,060 --> 00:19:58,170
to populate the fields with some data.

254
00:19:58,210 --> 00:20:06,880
I'm also going to introduce a private property and I'm going to call this one is edit mode so I'm just

255
00:20:06,880 --> 00:20:12,610
using this flag which is a boolean is it it mode.

256
00:20:12,860 --> 00:20:13,570
Right.

257
00:20:13,660 --> 00:20:16,660
And I'm not even going to initialize it just yet.

258
00:20:16,660 --> 00:20:17,880
I'm just declaring it.

259
00:20:18,250 --> 00:20:25,310
And then if it is the constructor with its initial data then I know that I'm not in edit mode some would

260
00:20:25,310 --> 00:20:29,650
just say is it its mode is equal to falls.

261
00:20:29,680 --> 00:20:29,980
Right.

262
00:20:29,980 --> 00:20:32,110
So it gets initialized right there.

263
00:20:32,110 --> 00:20:39,950
And if it's the constructor with data then and or is it its mode is equal to true.

264
00:20:40,060 --> 00:20:46,330
So pretty much I'm going to be using this flag inside of my Beatty and see if so I can determine the

265
00:20:46,330 --> 00:20:49,020
behavior because it's a different kind of query.

266
00:20:49,030 --> 00:20:57,550
If I'm inserting data versus if I'm updating data so I'm just going to track the value off is edit mode

267
00:20:57,640 --> 00:21:03,280
by the time the button CV is clicked I would know if it's edit mode or not if it's Edit More than I

268
00:21:03,280 --> 00:21:06,880
do an edit query if it's not edit more than I do an adequate.

269
00:21:06,910 --> 00:21:14,100
That's pretty much all that I need to do now in my BATNA and save button click event what we're going

270
00:21:14,100 --> 00:21:20,940
to do is do like a quick if statement so I'm just seeing if is edit mode and a rumor that when we in

271
00:21:20,940 --> 00:21:29,340
C sharp we can write this in the short end and this really translates that if is edit mode is equivalent

272
00:21:29,340 --> 00:21:30,210
to true.

273
00:21:30,360 --> 00:21:31,770
That's really what that is asking.

274
00:21:31,770 --> 00:21:32,370
All right.

275
00:21:32,370 --> 00:21:37,830
So if is edit more than we want to do something else we want to do something else.

276
00:21:37,830 --> 00:21:43,470
So if it is it it more than we want to write edit code here.

277
00:21:43,470 --> 00:21:49,170
And if it is not edit mode then we read add code here.

278
00:21:49,170 --> 00:21:52,930
All right so I'm just going to leave those comments for No.

279
00:21:53,070 --> 00:21:59,700
And then the cancel click is pretty much worse than to close the window so if I click cancel the expectation

280
00:21:59,700 --> 00:22:04,890
is that this window will close so I can actually just see it in the beach and cancel click.

281
00:22:04,890 --> 00:22:08,030
I can just see this dot close.

282
00:22:08,130 --> 00:22:09,000
All right.

283
00:22:09,000 --> 00:22:14,300
So remember that this keyword is special and specific to the actual class.

284
00:22:14,310 --> 00:22:17,780
It's just an object of the class that it is being used in.

285
00:22:17,820 --> 00:22:25,230
So this represents the ad to vehicle window and then the dot close is the opposite of the dot show.

286
00:22:25,230 --> 00:22:30,720
So not sure shows the window closed closes the window so if I could cancel then just close the window.

287
00:22:30,720 --> 00:22:32,490
That's pretty much all we're seeing.

288
00:22:32,490 --> 00:22:36,230
And then you notice a visual studio is actually agreeing all this.

289
00:22:36,240 --> 00:22:41,130
So it's not every time that you actually need to use the word this so you could actually just see close

290
00:22:41,370 --> 00:22:43,940
and it will know that's so close itself.

291
00:22:43,950 --> 00:22:45,420
Now we're making good progress.

292
00:22:45,420 --> 00:22:46,820
I'm not already too quiet.

293
00:22:46,850 --> 00:22:55,190
I'm not quite ready to code the edit and add functionality yet instead of going to go back over to my

294
00:22:55,200 --> 00:23:01,580
manage vehicle listing window and we can just take a quick look at that design once again and we have

295
00:23:01,580 --> 00:23:04,860
the add new car button and we have a car button.

296
00:23:04,940 --> 00:23:09,250
Expectation is that when they click add new car we're going to show a new form.

297
00:23:09,240 --> 00:23:11,130
So I'm just going to do that.

298
00:23:11,130 --> 00:23:16,390
So when they click that I'm going to see this.

299
00:23:16,440 --> 00:23:16,800
Sorry.

300
00:23:16,820 --> 00:23:28,200
I'm going to say ad edit vehicle and I'm just going to call it FA M so arc and just use the the suggestion

301
00:23:28,200 --> 00:23:34,580
from a visual studio sorry and then I'm going to say is equal to a new instance of it vehicle.

302
00:23:34,590 --> 00:23:40,710
Once again we could always simplify this by saying var if anything and then I'm just going to say had

303
00:23:41,320 --> 00:23:42,190
it.

304
00:23:42,380 --> 00:23:44,380
Vehicle not sure.

305
00:23:44,920 --> 00:23:51,120
So just going to show that new window and of course you want the MDI appearance because you don't want

306
00:23:51,120 --> 00:23:55,590
to just show this room but when we just show the window it's a free window to do anything.

307
00:23:55,590 --> 00:23:59,340
So I wanted to know that its appearance is the mean window.

308
00:23:59,580 --> 00:24:02,460
So I'm went off to read this quote a bit differently.

309
00:24:02,460 --> 00:24:15,000
Where I went to see the ad edit object dot in the a parent is equal to and then I'm going to have to

310
00:24:15,000 --> 00:24:21,060
see this dot MDI period.

311
00:24:21,090 --> 00:24:23,860
So they may explain exactly what is happening here.

312
00:24:23,880 --> 00:24:30,060
Remember that we're launching manage vehicle listing from inside of our main window mean windows are

313
00:24:30,060 --> 00:24:30,960
MDI appearance.

314
00:24:30,960 --> 00:24:37,310
So when when the manage vehicle listing window would launch it would have launched inside of me a window.

315
00:24:37,350 --> 00:24:40,360
You would know that mean window is its MDI appearance right.

316
00:24:40,480 --> 00:24:47,340
No I want to launch another window on the command off the manage vehicle listing which is a child off

317
00:24:47,340 --> 00:24:48,370
me and window.

318
00:24:48,450 --> 00:24:54,140
So I needed to know that it is also a child of mine window in the previous ones.

319
00:24:54,150 --> 00:24:56,860
We would have said that when you launch.

320
00:24:56,940 --> 00:25:05,160
Let me just get back to my main window code so you can be reacquainted with it when we were launching

321
00:25:05,160 --> 00:25:08,220
money vehicle listing we said that this is the MDI period.

322
00:25:08,220 --> 00:25:09,730
This being mean window.

323
00:25:09,900 --> 00:25:14,000
In this situation mean window is not the one being doing the launch.

324
00:25:14,040 --> 00:25:20,460
So I can't see this is the mean window because then that would make manage vehicle listing them the

325
00:25:20,460 --> 00:25:22,880
parent for my ad.

326
00:25:22,900 --> 00:25:26,490
Edit window which would be wrong.

327
00:25:26,490 --> 00:25:34,410
So instead I'm seeing this which represents them manage vehicle listing not MDI period which represents

328
00:25:34,410 --> 00:25:35,310
me in the window.

329
00:25:35,310 --> 00:25:44,240
I'm seeing that whatever the MDA parent is off this form that is the parent for the ad edits vehicle.

330
00:25:44,370 --> 00:25:47,030
All right so that's all I'm doing in that line.

331
00:25:47,040 --> 00:25:52,090
So you know a situation you just have to know how to maneuver it in some situations.

332
00:25:52,110 --> 00:25:58,320
This because the MDA appearances make under a call sometimes a child of the MDA appearance is making

333
00:25:58,320 --> 00:25:59,270
that direct call.

334
00:25:59,490 --> 00:26:00,540
So you just need to see.

335
00:26:00,580 --> 00:26:01,830
However my appearance is.

336
00:26:01,830 --> 00:26:05,540
That's also your appearance so that's all we're doing in this line.

337
00:26:05,550 --> 00:26:11,820
I'm saying that my parent is your parent and then we're showing that window.

338
00:26:11,820 --> 00:26:12,090
All right.

339
00:26:12,450 --> 00:26:23,610
So this is loading our ad edit vehicle using the normal constructor in order button click events especially

340
00:26:23,610 --> 00:26:32,130
like in the edit no we'll need to 1 retrieve the data off the car to be edited and then pass that data

341
00:26:32,160 --> 00:26:33,330
over to the farm.

342
00:26:33,330 --> 00:26:33,980
Right.

343
00:26:34,020 --> 00:26:40,080
So once again the expected behaviors that the person is going to click the grid click the row in the

344
00:26:40,080 --> 00:26:42,310
grid and then click edit.

345
00:26:42,330 --> 00:26:42,880
Right.

346
00:26:42,900 --> 00:26:51,150
So firstly we need to know what rule was clicked or at least the value or that I value off the rule

347
00:26:51,270 --> 00:26:54,600
that is clicked and selected.

348
00:26:54,600 --> 00:27:01,630
So here I just outlined some of the steps that we'd need to take when we click the edit button.

349
00:27:01,650 --> 00:27:05,610
So one we need to get the idea of the selected roll right.

350
00:27:05,610 --> 00:27:13,170
So when the person clicks the rule and then clicks edit we need to know what is the idea of that rule

351
00:27:13,390 --> 00:27:14,390
right.

352
00:27:14,460 --> 00:27:20,640
After getting the idea of the rule then we need to query our database which means that we need to initiate.

353
00:27:20,660 --> 00:27:21,020
OK.

354
00:27:21,030 --> 00:27:26,670
We have DB already so we have a connection to the database already active because well that's all we

355
00:27:26,670 --> 00:27:28,130
feel to the grid.

356
00:27:28,140 --> 00:27:29,670
So I already have that object.

357
00:27:29,670 --> 00:27:37,440
So we need to query the database for the Red Card associated with that idea and then we need to launch

358
00:27:37,440 --> 00:27:39,800
our window similar to what we did here.

359
00:27:39,810 --> 00:27:42,450
Except we're going to be launching it with the data.

360
00:27:42,450 --> 00:27:48,570
So remember once again that we have two constructors we have a normal constructor that doesn't expect

361
00:27:48,570 --> 00:27:51,140
too much it just knows it's supposed to add.

362
00:27:51,300 --> 00:27:57,360
And then we have one that is expecting some data to be passed in and that is the one that we're going

363
00:27:57,360 --> 00:28:02,220
to be using when we're going to be launching for editing purposes.

364
00:28:02,580 --> 00:28:09,720
So let's start by getting the idea of the selected rule someone to see a var idea lowercase is equal

365
00:28:09,720 --> 00:28:17,710
to and then I'm going to call my grid which I call GV vehicle list and then I have a property that's

366
00:28:17,710 --> 00:28:19,430
is selected rules.

367
00:28:19,530 --> 00:28:23,990
But then notice it's selected rules because that's actually a collection.

368
00:28:24,000 --> 00:28:29,900
See there it's a selected row collection because maybe the person can select more than one rules.

369
00:28:29,910 --> 00:28:30,450
Right.

370
00:28:30,570 --> 00:28:35,370
But we're expecting that it's only one rule that they're going to select on it's even if they select

371
00:28:35,370 --> 00:28:37,590
more than one where only one the first one.

372
00:28:37,620 --> 00:28:37,890
Right.

373
00:28:37,890 --> 00:28:39,660
So this is a wild assumption.

374
00:28:39,660 --> 00:28:44,460
We can call defensively in the future but right now I'm just keeping it simple.

375
00:28:44,540 --> 00:28:47,640
So of the selected rows I want the first one.

376
00:28:47,640 --> 00:28:54,090
So it's a collection I can use my square brackets specify that I want the first one then I see a dot

377
00:28:54,420 --> 00:28:56,360
then I want off that rule.

378
00:28:56,370 --> 00:28:59,680
We have cells cells represent the columns right.

379
00:28:59,730 --> 00:29:06,750
So I want the cells but then of the cells which is also a collection I'm really only interested in the

380
00:29:06,750 --> 00:29:07,750
one called ide.

381
00:29:07,800 --> 00:29:15,090
Let me hide the properties so we have more room to write a quarter it so I can use a named index.

382
00:29:15,120 --> 00:29:22,500
So in some situations you want the number situations you just want to specify the name of the column

383
00:29:22,510 --> 00:29:28,360
because if I add more columns here I can go by numbers write it off to change my code every time.

384
00:29:28,390 --> 00:29:38,090
So what I'm want to do here is say I want a cell with the name I.D. write and then after getting that

385
00:29:38,090 --> 00:29:41,920
so I want the value in that cell.

386
00:29:42,080 --> 00:29:48,950
So all it's going to do is say give me the selected the first selected rule and then give me the so-called

387
00:29:49,010 --> 00:29:54,080
80 and whatever the value is even though it's not visible because we keep it.

388
00:29:54,170 --> 00:30:01,130
But whatever that value is I want to store it inside of this variable called I.D. I know that we know

389
00:30:01,130 --> 00:30:03,930
the I.D. off the rule that was selected.

390
00:30:04,010 --> 00:30:13,910
I can see of var car because I not only want one is equal to underscore D.B. dot the table that I intend

391
00:30:13,910 --> 00:30:17,710
to get the car from which is the types of cars dot.

392
00:30:17,780 --> 00:30:25,170
And then we're going to look at another function in length called First or default right.

393
00:30:26,380 --> 00:30:29,160
For a start default we have first entered our first default.

394
00:30:29,190 --> 00:30:32,880
So the difference is that first will fail if it doesn't bring back anything.

395
00:30:32,880 --> 00:30:39,110
Defaults will fail gracefully and give you a nice sense of the error message or just return note.

396
00:30:39,390 --> 00:30:46,400
So on the first floor defaults and then I'm going to do what we have come to love no a lambda expression.

397
00:30:46,400 --> 00:30:53,360
So I want to say to then my arrow then all I'm seeing is give me the first or default.

398
00:30:53,440 --> 00:30:57,990
Pretty much this is like a where clause where to dot.

399
00:30:58,170 --> 00:31:03,780
And then you see that the Q is giving me access to all of the columns I'm interested in the idea column

400
00:31:04,320 --> 00:31:12,500
where the value in the column is equivalent to the idea that we just retrieved from our selected grid.

401
00:31:12,540 --> 00:31:13,290
All right.

402
00:31:13,290 --> 00:31:21,780
So all this is going to do is run it and it's giving me an error here because Ida is actually an object.

403
00:31:21,940 --> 00:31:22,770
All right.

404
00:31:22,770 --> 00:31:29,460
So what I would want to do here is probably just do an implicit passing to an INT.

405
00:31:30,090 --> 00:31:30,870
All right.

406
00:31:30,870 --> 00:31:34,440
So no this is returning an intent Heidi.

407
00:31:34,620 --> 00:31:41,440
And then I'm comparing the integer column to the integer value coming back from this operation.

408
00:31:41,820 --> 00:31:43,560
Know that we've gotten the car.

409
00:31:43,560 --> 00:31:45,730
So as you know we get the car or we get it.

410
00:31:45,780 --> 00:31:47,820
That's what first our default means.

411
00:31:47,820 --> 00:31:48,430
Right.

412
00:31:48,450 --> 00:31:54,390
And the assumption is that if they're clicking the grid then that I.D. is in the database and then we

413
00:31:54,390 --> 00:31:58,590
go on to launch or form with the data.

414
00:31:58,620 --> 00:32:02,160
So I'm going to also see var.

415
00:32:02,670 --> 00:32:07,350
And then once you use the same object name and because they're in different functions they won't interfere

416
00:32:07,350 --> 00:32:08,380
with each other.

417
00:32:08,510 --> 00:32:14,620
And but then this one is going to be equal to a new instance of ad edit vehicle.

418
00:32:14,790 --> 00:32:22,200
But then I'm passing in the data that is coming back from the database in the form of car.

419
00:32:22,230 --> 00:32:23,090
All right.

420
00:32:23,220 --> 00:32:31,620
So I'm went to launch a new instance of this window or this form passing in the data coming from the

421
00:32:31,640 --> 00:32:38,010
database and then I can just copy these two lines where I'm sitting the MDA appearance and I'm setting

422
00:32:38,010 --> 00:32:43,410
it to show so you can see that they're doing similar things except that it is a bit more work because

423
00:32:43,620 --> 00:32:52,080
to edit you have to do a look up for the I.D. card for the record to be edited and then you can pass

424
00:32:52,080 --> 00:32:55,420
it on into the new window.

425
00:32:55,420 --> 00:32:56,160
All right.

426
00:32:56,190 --> 00:33:04,200
So when it passes into the new window just schoolbook over there it's going to launch with this constructor

427
00:33:04,500 --> 00:33:10,950
which is sorry this constructor which is initializing a component setting a different text setting the

428
00:33:10,950 --> 00:33:16,080
edit mode to be true and then populating the field so that when the form loads you will load with all

429
00:33:16,080 --> 00:33:18,910
of those values already in the text boxes.

430
00:33:19,090 --> 00:33:26,100
Now back in our managed vehicle listing I'm just going to top it all off and do the delete click event

431
00:33:26,130 --> 00:33:27,640
which is going to do a similar thing.

432
00:33:27,650 --> 00:33:28,980
They select the grid.

433
00:33:29,070 --> 00:33:35,820
So we need the idea of the selected value from the grid and when to reuse this code.

434
00:33:36,060 --> 00:33:41,720
And then I need to do a lookup for that vehicle right.

435
00:33:41,720 --> 00:33:49,870
So I do the same thing there but then this time I'm going to delete vehicle from table.

436
00:33:49,880 --> 00:33:50,540
Right.

437
00:33:50,600 --> 00:33:58,670
So after I get the vehicle that is being referenced by that selected rule then I'm going to say underscore

438
00:33:58,990 --> 00:34:03,440
BD dot types of cars dot remove this time.

439
00:34:03,470 --> 00:34:09,850
So when we're inserting data we do add when we're moving we see dots remove.

440
00:34:10,400 --> 00:34:14,990
And then I'm going to pass in whatever it is I want to remove which is the car that we just did I look

441
00:34:14,990 --> 00:34:16,140
up for.

442
00:34:16,610 --> 00:34:22,440
And then after all of that I'm just going to say D.B. dot save changes.

443
00:34:22,450 --> 00:34:31,140
All right so when we select something from the grid and then we click delete car or the delete button

444
00:34:31,440 --> 00:34:39,340
it will then remove and then I'm going to do one more thing where I see that the grid view should refresh

445
00:34:39,350 --> 00:34:39,610
right.

446
00:34:39,630 --> 00:34:45,650
So I'm just going to refresh the grid view after this has occurred.

447
00:34:45,900 --> 00:34:53,790
No Buck in our ad edit form or the first thing I want is my connection to the database so I'm just going

448
00:34:53,790 --> 00:34:59,330
to copy the existing code because once again I want to keep it consistent.

449
00:34:59,340 --> 00:35:07,800
This time our own so I'm just going to copy this and bring it over and then I'm going to do the respective

450
00:35:07,800 --> 00:35:08,810
initialization.

451
00:35:08,810 --> 00:35:14,130
So this might be like a double step at this point and you're saying well I don't really want to do it

452
00:35:14,130 --> 00:35:15,840
this way and that's fine.

453
00:35:15,840 --> 00:35:20,570
If he can find a more efficient way you feel free to let me know.

454
00:35:20,700 --> 00:35:22,680
I mean there are more efficient ways.

455
00:35:22,680 --> 00:35:29,400
I'm not saying there isn't a more efficient way but if you feel free to let me know if you do it a different

456
00:35:29,400 --> 00:35:29,630
way.

457
00:35:29,640 --> 00:35:30,140
Right.

458
00:35:30,180 --> 00:35:36,540
You could actually just do it in one line just like this and cut out the double or.

459
00:35:36,620 --> 00:35:36,950
Right.

460
00:35:36,980 --> 00:35:40,470
So you could do it that way and have it Initialize all in one line.

461
00:35:40,470 --> 00:35:41,550
That's fine.

462
00:35:41,550 --> 00:35:46,640
But I'm just going to leave it like this since that's the pattern that we've been using up until now.

463
00:35:46,650 --> 00:35:56,570
So after initializing it what I'm going to do is go ahead and write in the code for the editing.

464
00:35:56,580 --> 00:35:57,340
Right.

465
00:35:57,390 --> 00:36:06,660
So after we click save what we need to do is to build a module that represents what was edited and an

466
00:36:06,660 --> 00:36:13,080
important thing to note is that when we're editing we need to keep track of the ideas of the record

467
00:36:13,110 --> 00:36:14,040
that's being edited.

468
00:36:14,070 --> 00:36:21,390
So we have skipped that step because here I set all of the text boxes to have the values what I did

469
00:36:21,390 --> 00:36:27,310
not set was a value for the object being edited.

470
00:36:27,390 --> 00:36:31,770
So you know sometimes you do something you make a decision and then you realize later on that you missed

471
00:36:31,770 --> 00:36:32,190
a step.

472
00:36:32,190 --> 00:36:34,170
So that's part of the development process.

473
00:36:34,200 --> 00:36:41,190
So I'm going back to my design and went to my tool box I'm bringing over a label and I'm just going

474
00:36:41,190 --> 00:36:49,690
to call this label I'm going to blank call it the text I'm also going to make it not visible.

475
00:36:49,710 --> 00:36:54,470
So I'm going to change a proper to visible forms.

476
00:36:54,540 --> 00:36:57,380
I'm also going to change its name to be.

477
00:36:57,630 --> 00:36:58,550
Heidi.

478
00:36:58,680 --> 00:36:59,490
Right.

479
00:36:59,520 --> 00:37:01,300
So that's I know exactly what to call it.

480
00:37:01,310 --> 00:37:02,310
It's in the code behind.

481
00:37:02,320 --> 00:37:09,260
So one of the first things I'm going to set is actually the text for that would be a I.D..

482
00:37:09,930 --> 00:37:15,300
So I would be Bill I.D. that takes is equal to car dog's I.D..

483
00:37:15,380 --> 00:37:15,660
All right.

484
00:37:15,660 --> 00:37:20,490
So we're getting the car object and I.D. is coming overall.

485
00:37:20,490 --> 00:37:21,770
So it's saying I can't.

486
00:37:21,840 --> 00:37:28,470
That's a string stuff to do a two string because I'm storing it instead of a text variable right instead

487
00:37:28,470 --> 00:37:29,310
of a string variable.

488
00:37:29,310 --> 00:37:36,480
So that's all I'm doing I'm just sitting a label to have the I.D. being tracked so that I know exactly

489
00:37:36,480 --> 00:37:41,580
what I.D. belong to the record that was being updated.

490
00:37:41,590 --> 00:37:48,630
Now I have all the data that I need what I'm going to do first is look up the record that was being

491
00:37:48,960 --> 00:37:49,440
edited.

492
00:37:49,470 --> 00:37:52,750
So like I said you always have to do these lookup.

493
00:37:52,750 --> 00:38:00,270
So that is why it was important for us to track the I.D. because at the time of we us clicking save

494
00:38:00,870 --> 00:38:10,670
I can get the I.D. from my form so I can see var I.D. is equal to and then I can get it from the labeled

495
00:38:10,860 --> 00:38:13,740
text which we know is a string.

496
00:38:13,740 --> 00:38:20,460
So that's a string I want of I want to integer variable or an integer value or other someone's out to

497
00:38:20,460 --> 00:38:26,860
do an int dot pass I can do the implicit conversion because that doesn't work when it's a string and

498
00:38:26,860 --> 00:38:34,830
being converts right second in that pass what is in my I.D. label and store it inside of that and then

499
00:38:34,830 --> 00:38:43,080
I can do a look for the car where I say var car is equal to and I'm sure you're just completing my sentence

500
00:38:43,080 --> 00:38:49,950
or typing into it before I do where I say D.B. the types of cars not first or default.

501
00:38:49,950 --> 00:38:57,720
So anytime you want one record you can use for a start he folds get our lambda expression open or running

502
00:38:58,380 --> 00:39:05,270
and then say Q Dot I.D. is equivalent to the I.D. We just got back from our form.

503
00:39:05,490 --> 00:39:13,290
No we have our car object and we are not entirely sure what was edited because we have five fields five

504
00:39:13,290 --> 00:39:18,660
text boxes we don't know if they were populated if the votes are deleted we don't know as yet.

505
00:39:18,690 --> 00:39:27,760
So what I'm going to do is just say car dot and then see for each one of them card don't model is equal

506
00:39:28,060 --> 00:39:36,010
to the text that is inside of TV model dot the TV model takes box.

507
00:39:36,010 --> 00:39:36,610
Right.

508
00:39:36,700 --> 00:39:38,860
And pretty much that's all I'm want to do for all of them.

509
00:39:38,860 --> 00:39:47,290
So car make is equal to whatever values in TV make that text right.

510
00:39:47,320 --> 00:39:51,940
And I'm going to continue doing that for all of them so you can pass here and finish them.

511
00:39:51,940 --> 00:39:57,370
You'll find that as you go along you may have to do quite a few data conversions to and from so on top

512
00:39:57,370 --> 00:40:03,940
we have to convert from integer to string to get it into the text box and then below we have to convert

513
00:40:03,940 --> 00:40:10,780
from string into integer to get it back into the database after filling all out all of the properties

514
00:40:10,780 --> 00:40:16,090
are probable values so the only one I'm not sitting is idea I don't need to set the idea because the

515
00:40:16,090 --> 00:40:19,560
whole operation is based on the fact that it is the seam.

516
00:40:19,570 --> 00:40:23,550
And the idea would not have changed right after doing all of that.

517
00:40:23,560 --> 00:40:32,680
I would just say D.B. dot save changes and then this would submit all of the potentially new values

518
00:40:32,680 --> 00:40:34,360
even if they're old values.

519
00:40:34,450 --> 00:40:42,070
So even if there was no real change made it would submit all of those to the database for our new car.

520
00:40:42,070 --> 00:40:42,580
No.

521
00:40:42,610 --> 00:40:47,860
A similar operation would be done for adding so I'm just going to do adding quickly where I'm went to

522
00:40:47,860 --> 00:40:58,150
build a car model so I would say something like var new car is equal to a new instance of type of or

523
00:40:58,150 --> 00:41:02,370
types type all types of car.

524
00:41:02,470 --> 00:41:05,240
So remember that this represents our new table.

525
00:41:05,260 --> 00:41:05,590
Right.

526
00:41:05,620 --> 00:41:10,380
So it did something similar to this with our car entire record where we built the car into truck or

527
00:41:10,380 --> 00:41:15,220
no we're just building a new type of car or our types of cars record.

528
00:41:15,220 --> 00:41:21,130
So we say new types of car and then I'm going to show you a cool feature that's C sharp does where it

529
00:41:21,280 --> 00:41:28,480
allows us to just use our current embraces and fill all of the column names in one could sweep in one

530
00:41:28,480 --> 00:41:29,110
full seat.

531
00:41:29,110 --> 00:41:29,300
Right.

532
00:41:29,650 --> 00:41:37,090
So initializing my object to a new instance of my table to be populated and then I can fill out each

533
00:41:37,090 --> 00:41:42,910
column so I can see the license plate number is equal to whatever value is coming back from the license

534
00:41:43,090 --> 00:41:50,520
plate text box I'm just going to copy and paste so I can move more quickly and then make is equal to

535
00:41:50,590 --> 00:41:58,630
what are values coming from the text box for the Make I notice that there are comma separated model

536
00:42:01,030 --> 00:42:09,200
sorry model is equal to the text box TV model but text right.

537
00:42:09,300 --> 00:42:12,320
And I would just go along and feel each one out.

538
00:42:13,000 --> 00:42:16,900
And I'm just sharp cutting edge here so I can move a bit more quickly.

539
00:42:16,910 --> 00:42:20,970
TB Vin text

540
00:42:23,450 --> 00:42:28,530
and the year well the year would no have in the past right.

541
00:42:28,700 --> 00:42:36,710
So I can just copy that because the code already exists so no that we've filled out a new record for

542
00:42:36,710 --> 00:42:41,000
types of car in order to add it to the database.

543
00:42:41,030 --> 00:42:50,300
You know that we need to see underscored D.B. dot find our table dot ad and then I'm going to pass in

544
00:42:50,300 --> 00:42:53,580
my new model which is new car.

545
00:42:53,710 --> 00:42:54,670
All right.

546
00:42:54,680 --> 00:43:00,890
And then at the end of any operation like this we always need to see changes and that's it.

547
00:43:00,920 --> 00:43:08,720
So if they click and save and we're in edit mode then we will change the see if the changes made to

548
00:43:08,720 --> 00:43:10,220
an existing record.

549
00:43:10,250 --> 00:43:17,240
So we do a lookup based on the idea and then we've made you know submit the changes to that record that

550
00:43:17,240 --> 00:43:20,120
we looked up and then we see the changes.

551
00:43:20,120 --> 00:43:26,690
And then if we're adding a new car meaning we're not in edit mode then we create a new model off the

552
00:43:26,690 --> 00:43:31,110
table type or the cross type to be added to the tables.

553
00:43:31,130 --> 00:43:31,840
Right.

554
00:43:31,850 --> 00:43:39,500
We fill it with the data and then we add it to the collection of records and then save changes.

555
00:43:39,520 --> 00:43:46,420
Now we can test our changes to test all of the code that we've written and click Start.

556
00:43:46,430 --> 00:43:52,490
So I go over to my manage vehicle listing agency that I already took the liberty of editing one of them

557
00:43:52,490 --> 00:43:54,770
before so let's just look at this experience.

558
00:43:54,770 --> 00:43:57,000
Let's start with adding a new car.

559
00:43:57,020 --> 00:44:08,720
So when I click add new car I can no add a new rules rice and let's say that the make would be fine.

560
00:44:08,720 --> 00:44:13,520
Tom the VIN is one two three four five six.

561
00:44:13,550 --> 00:44:21,050
It is twin to 18 and then the license plate number would be H G.

562
00:44:21,140 --> 00:44:24,030
5 6 4 7 right.

563
00:44:24,080 --> 00:44:25,340
That we could say of changes.

564
00:44:25,370 --> 00:44:31,280
So I mean I click save changes the window is still open and but then if you notice that the label is

565
00:44:31,280 --> 00:44:34,130
seeing add new vehicle because we clicked add.

566
00:44:34,220 --> 00:44:36,730
So it's setting the title well.

567
00:44:37,310 --> 00:44:38,390
We didn't see that.

568
00:44:38,390 --> 00:44:43,160
Anything else should happen after see changes so those are some refinements that we need to make as

569
00:44:43,160 --> 00:44:43,740
we go along.

570
00:44:43,770 --> 00:44:44,250
Right.

571
00:44:44,330 --> 00:44:45,880
So the window is still up.

572
00:44:45,880 --> 00:44:47,370
That's 1 and 2.

573
00:44:47,450 --> 00:44:49,280
The grid is not showing any changes.

574
00:44:49,280 --> 00:44:54,830
So if I close this window and then I close the grid and then reopen it however you see that it runs

575
00:44:54,830 --> 00:44:58,240
a fresh query bringing back our newly added vehicle.

576
00:44:58,240 --> 00:45:01,970
So that's something that we have to look into because we wouldn't want to use it off to go through all

577
00:45:01,970 --> 00:45:02,470
of that.

578
00:45:02,600 --> 00:45:04,840
See that they've added a new vehicle.

579
00:45:04,840 --> 00:45:09,350
We also didn't give them any visual prompt to say hey you've added a new vehicle successfully.

580
00:45:09,500 --> 00:45:11,400
So things like that.

581
00:45:11,480 --> 00:45:15,190
So that's with adding a vehicle let's look at anything.

582
00:45:15,200 --> 00:45:20,360
So I'm going to choose one of these existing ones so buggy we did see we're going to modify a buggy

583
00:45:20,360 --> 00:45:22,930
a bit and I'm went to a car.

584
00:45:22,970 --> 00:45:31,720
So the mic is really evokes while gone and it's a beetle.

585
00:45:32,200 --> 00:45:45,000
The VIN and then the year is toy is let's say 1995 and then the plate number would be H Y.

586
00:45:45,250 --> 00:45:51,160
Some random numbers save changes same net effect except that we're in Edit more this time so you see

587
00:45:51,160 --> 00:45:52,000
that one.

588
00:45:52,000 --> 00:45:58,840
It says I did vehicle and in the expectation is that when I refresh the grid buggy will no show different

589
00:45:58,840 --> 00:45:59,250
values.

590
00:45:59,260 --> 00:46:07,210
So once again we didn't necessarily do a good job of handling the experience of moving between the windows

591
00:46:07,540 --> 00:46:09,770
that can be fixed but for no.

592
00:46:09,940 --> 00:46:16,650
Just so that we can validate our changes we can see that buggy is no showing or different values.

593
00:46:16,720 --> 00:46:22,660
So things that we need to do one handling the experience having done an edit or an ad we need to close

594
00:46:22,660 --> 00:46:28,000
the window once the operation is done show them are prompt to let them know it was successful and also

595
00:46:28,000 --> 00:46:32,910
find a way to refresh the grid that is being displayed in the background.

596
00:46:32,920 --> 00:46:36,250
That's what I think that's three objectives right there.

597
00:46:36,250 --> 00:46:41,710
Another thing that we want to do is add some validation and some error handling.

598
00:46:41,710 --> 00:46:50,530
So one you notice that if I click Lada and click a car and then let's say Okay I made one change here

599
00:46:51,100 --> 00:46:54,410
and I click save changes it's going to more time.

600
00:46:54,450 --> 00:47:00,410
Give us one of those nasty arrows which we'll call exceptions which we've been through before.

601
00:47:00,430 --> 00:47:02,290
It's important to handle exceptions.

602
00:47:02,290 --> 00:47:07,840
So that's another thing you can go ahead and add to your form to make sure that it handles these kind

603
00:47:07,840 --> 00:47:10,350
of kinds of arrows gracefully.

604
00:47:10,360 --> 00:47:10,560
All right.

605
00:47:10,570 --> 00:47:19,060
So there are a few places so in every single click event I would suggest that you put the error handling

606
00:47:19,060 --> 00:47:25,720
I try to get statement to try and catch those arrows and display appropriate error messages without

607
00:47:25,810 --> 00:47:29,890
ending the runtime of the program someone to leave you guys to do that.

608
00:47:29,890 --> 00:47:32,300
This was a very long video we did quite a bit.

609
00:47:32,410 --> 00:47:37,810
So I'm going to leave you guys to try and experiment with those validations and those exception handling

610
00:47:38,020 --> 00:47:43,870
and when to stop recording right here and I will do them all screen and in the next video we can review

611
00:47:43,870 --> 00:47:44,560
them together.
