In this video we're going to start building some functionality behind our buttons to add edit and delete
our cars from our database.
Before I continue though I want to show you some change that I made here to the grid view where we were
filling or grid view with the custom model or a collection or a list of the custom model coming from
our database for the make model Vin year and license plate number.
And the column for license plate number would have displayed this in case which is undesirable to me
in terms of presentation.
So what I did was to go underneath and actually set a custom header text for the fourth or the fifth
column that would have been in our grid view.
So remember that this would be 0 1 2 3 4.
So the fourth one would have gotten the custom header tech start.
So in order to put in some functionality First we need to understand the behavior that we're aiming
for at least that I'm aiming for the behavior I'm expecting is that a user would select a column and
then click edit car or they would just click I do car and you know a new window comes up allowing them
to fill out the form click submit and we're going to make at least the make and the model and the let's
say the license plate number mandatory so you know you can customize your own validations plan when
to put in some amount of validation in that form if they select roll and then click edit then the expectation
is that a window similar to the ad new car window will pop up allowing them to modify the details of
whatever record they selected.
And then when they click submit or to see if changes it will update that's in the database in a similar
fashion when they select a rule and then click delete.
We want to one ask them Are they sure you what they want to delete and if they proceed to click yes
then we proceed to delete the car.
So in this video we're going to be looking at a few things where we're going to be creating a new form
and then we can't constructor overloading as to how we can pass values into our farms so that this form
will load with a set of values.
So in this situation we're actually going to use the same form for the ad new car and it's because it's
the same sets of fields.
We're building one farm and then we look at passing values in as at the time of loading so that we get
different outcomes from the same farm and different functionality.
I don't want to make some modifications to my grid view.
The first thing I'm going to do is include the.
So we did build the custom model we said make model all the things that we want to display to the user
are all here and you notice that they're kind of great.
So if you hover over it the light bulb is really telling you that since the custom name that we're giving
it is the same as the actual column name then we really don't need to see me equals the same column
name.
So if you just get the lightning bolt and use its suggestion then you see that it just replaces it DNC
that you could just reference it does me.
Right.
So you could go through and clean it up if you want but I'm going to leave it as it is.
No.
So that it's clear what exactly is happening the modification I want to make however is to add the I.D.
because when I select our role and then I want to click edit I need to know what I'm selecting and the
best way to know what room selecting or what car I'm selecting is to know the idea of that vehicle.
Right.
So the same way that we needed idea when we were saving it in the car or a courtroom but that we have
to bind the value member of I.T. I need a way to find that value member in my four hour from my grid
so that when I click edit I can do a lookup for that particular car based on its unique identifier which
is the I.D. and then return that data to the form so that it can be up for editing.
So what I'm going to do is just continue underneath the license plate number and then I'm just going
to say cue dot I.D..
So I I could say I.D. equals a cute idea but then the lightning bolt would once again up you're telling
me that this is redundant.
So I don't need to see the I.D. equal to the same column name.
So just to drive my point home or to appease Visual Studio I'm just going to say cue that I.D. just
to show that I didn't have to specify a column name all the time.
Right.
So I'm including to I.D. into the data set that is being returned which means that my grid is going
to definitely generate a column for the I.D. which I don't necessarily want because I don't need to
see the I.D. column.
So what I'm going to do is underneath where I set the header text for the license plate number I'm going
to say GV vehicle list dot columns and then I can specify that I want the fifth column or the will of
the sixth column or a column with a subscript five which would represent my I.D. I want it I want its
visibility to be set to falls right.
So even though it's there it will show up but I know it's there and I am sitting it there because I
know that when I need the value from it I can get that value.
So I'm putting it there but I'm making it hidden.
All right.
So let's go ahead and prepare our ad edit form so I'm just going to regulate my project at a new farm.
I'm going to call this one I'd edit vehicles or ad edit vehicle and then that's my new form someone
to explore some new editing techniques in this one so the first thing I want to do is change the title.
So I want to.
Well I'm actually going to set the title on the fly.
So I'm going to show you guys that a lot of these things can be controlled from the code behind us at
the time as at runtime right.
So I am using it for two purposes.
Adding and editing but when it is going to be time to add something I wanted to see add vehicle when
I want to edit I wanted to see it vehicle what I don't want is for it to say and edit vehicle rights
I'm going to show you how you can set that during runtime.
Another thing that we want to look at in this is the power off label.
So if I go to my tool box and I go to the containers section then I see that I have a few labels.
You have the floor panel which kind of takes things and stacks them side by side automatically of the
group Box which is usually used that went out radio buttons and Chip boxes that you want to associate
with each other.
You have a panel of the split country and area of type controls and you have to believe someone to borrow
the table labeled here drag it over and you know Android's over the section that I wanted.
And you notice that it's just one big box red one big grid box.
So what I intend to do here is put the labels to the left and the controls to the right.
So I can actually resize this and you notice that the grid that the cells actually resize accordingly.
I have a boat.
Let me check my database of 1 2 3 4 5 feels that need to be filled.
So I need at least five rows.
So using the black carrots at the top right hand corner I can add a as I can add columns as I need to
and I can also edit the rows and columns.
So I want to add a few rows.
And like I said I need five.
So that's one two three four five.
So I have one extra I can remove the last of the sorry that was the column.
Let me just undo that quickly.
All right someone to remove the last row actually.
And then you notice that you know sizing is not so key and so you can always just drug and resize as
you see fit.
And this may still not work go to be the best.
So you can actually just go to edit rows and columns and then you can see the type of sizing you want
for your columns and you can use the dropdown at the top and see rows and you can choose the sizing
you want for your rules.
So you can see they have percentage and you have absolute someone to select all and then going to say
I want all of them to be 50 percent that I click Okay you see that everything kind of normalizes and
if I expand they'll kind of expand with that.
Right.
So that's my table layout.
And then I'm going to drop in the Add button.
So I just bring over my button to go key and then I want my button to see save changes.
Right.
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
to have another button that is going to see cancel that one I'm putting to the right.
So you know we're just building this so you may have different design ideas from me and that's fine.
That's actually excellent if you're thinking differently from me.
But if you're not then that's fine too.
We're in this together.
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
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
so add new car right or actually them when to leave this label blank and better yet I'm going to make
it see what I wanted to see based on the more.
So I'm going to just change its name so that I know the control from the code bans on what to call it
LBO title All right so even your labels.
Yes we weren't really naming labels because we didn't necessarily need to call them from the code behind.
But I want to call this one and I want to feel the content relative to the mode that this form is in
print.
So once again I'm creating a form I'm calling it ad edit vehicle.
This form has been dubbed the dual purpose of providing fields for adding a car versus editing car.
Right.
And adding and editing are pretty much the same operations.
Well at least the same fields are involved in both operations.
So in the tool box I'm just going to take over a few labels drag them drop them inside of these rules.
So they may have may get online trying to put them in some just pasting pasting so that all of them
go into the left hand side.
And then I just delete the extra ones from the right hand side because I don't really want them there.
And then I'll drag over the text boxes so everything here is really a text box anyway.
All right.
So text box inside of that one and I'm just pasting so I'm filling out all of these with ticks boxes
then I modify my labels.
So the first label would be for the make of the car the second label would be for the just right click
properties and then a pin properties.
I can move a bit faster.
So the other one would be for the model and then I mean in a real world situation you probably want
to give them dropdown lists for make and model because you don't want them to be typing in Honda without
an H or Toyota and spelling it with an extra E.
Stuff like that so you probably want to give them drop.
But for the simplicity of the sake of these examples and these lessons I'm not going to go into all
of that.
I just want us to have some key concepts under our grasp.
So the next one would be the VIN the next label would be our license or our year rather and then the
final one would be the license plate.
No all right.
Saw that it was click each label change the property for the text.
If you want you can meet them bigger and more pronounce.
That's fine.
I'm just going to leave those that way for no.
All right.
And then we have the respective takes boxes to get the values for each.
Now let's go over to the code file and start adding some code that will make or or form a bit more dynamic
so as is typical we have our class.
We have the name of the form inheriting from our beast school form and then we have our base constructor
which is initializing the component in stride knowing this be a SQL instructor I can actually start
setting other things.
So I want to maybe set the title so if this constructor or the form is loaded using this constructor
then I want the title text to see add new vehicle
all right.
And then maybe I want the well I could change the button to text also so as I said before we want to
make sure that we put name store controls.
So I actually skip that step.
So let's go back and put names to our controls properly so that we don't have any problems moving forwards
or take Suboxone is really t the MC Right.
So is it takes blocks for the make of the vehicle.
We have the second one being t the model we have the third one being TB V and TB even.
We have the fourth one being TB here and then this one is TV license plate number.
So TV license I know this certainly sensitive license and not right.
And then for our buttons and went to have Beatty and save.
All right.
And then for cancel and went off Beatty and cancel.
And then while I'm here I'm just going to set up those quick events.
So be GNC.
Click event and Beatty in Kansas.
Click event once again to create those you just double click a control then it will generate the Click
event.
No back in our code file I'm going to create a second controller.
So this is what we'll call overwriting right or overloading.
So we have this concept in programming called function overloading and in Opal or pea you can actually
overload constructors.
Right.
So we have a constructor that's taking zero parameters on when to overload display constructor and I'm
going to want it to take a Parmenter of type of car and then I'm want to call it car right.
Or you know what I'm going to be very specific and I want to see car to edit.
So that we know exactly the purpose of this property.
Right.
So cart at it.
All right.
So when we load the form with this constructor we're expected to pass in an object of type types of
car and then we will then use it to fill out the data points in the text boxes as they are there already.
Right.
So of course if I'm if I'm loading the form then I need initialized component.
So that has to be there.
I'm also going to take the part where I'm sitting the title.
So if it's loaded with this one which is for the edit mode then I'm going to see edit vehicle.
All right.
So if we load the form using this constructor it's to add a new vehicle if I load the form using the
second constructor which is the Overlord then it is to edit said vehicle further to setting the title
for the editing.
What I'm want to do is create a function called populate fields.
All right.
So the cool thing about visual studio is that I can write the function call I don't until a function
called populate fields I just wrote it and then you see the lightning bolt is coming up with a red X
and it's asking me Do you want to generate the method for that.
So if I click that then it automatically just generates that method for me.
Right.
So it makes coding much more efficient than it could be otherwise.
Right.
So instead of populate fields I'm going to be setting the field values to whatever the matching field
value is coming over from this object.
So actually I'm going to pass this object into populated fields so I'm passing type of types of car
into that and I'm going to make sure that this function also knows of the incoming data.
All right.
So I could just call this car just to show you that once again I'm getting a property or I'm getting
an object of type types of car.
Right.
So this represents the data from the database and this is the object that has the data that we're going
to be editing in the farm right.
And then I'm getting it in this constructor ammunition as in my components I'm setting the title off
the whole form to be edit vehicle and then I'm seeing I want to start populating the fields in the form.
Here is the data.
So instead of the actual function populate fields I'm getting that object.
So I'm just calling it Kyra this to show you that it doesn't necessarily have to have the same name.
It must however have the same data type because if I said integer then that would cause an arrow in
the function called cause then it seeing well passing some invalid data type.
So the data types the much the name doesn't necessarily have to match.
And then what I'm going to be doing inside populate fields is calling each text box.
So if I say TV Let's start from the top make dot text.
All right is going to be equal to the object coming in dot and then the corresponding data that that
text box should have.
So I can do that for every one of them TV model dot text is equal to car dot model.
All right.
So um when you can pause here and try and do them all on your own.
I'm just going to finish them up.
All right.
So if you pause then try it it's on your own then you would have something looking at this if you have
an arrow trying to put the year into the text box then a you need to make it a string in order for it
to go into the text of the text box.
Right.
So once again we're seeing that we can load this form normally right or we can decide to call the constructor
with some data put some data to this construct a version of the farm and then that construct to proceed
to populate the fields with some data.
I'm also going to introduce a private property and I'm going to call this one is edit mode so I'm just
using this flag which is a boolean is it it mode.
Right.
And I'm not even going to initialize it just yet.
I'm just declaring it.
And then if it is the constructor with its initial data then I know that I'm not in edit mode some would
just say is it its mode is equal to falls.
Right.
So it gets initialized right there.
And if it's the constructor with data then and or is it its mode is equal to true.
So pretty much I'm going to be using this flag inside of my Beatty and see if so I can determine the
behavior because it's a different kind of query.
If I'm inserting data versus if I'm updating data so I'm just going to track the value off is edit mode
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
do an edit query if it's not edit more than I do an adequate.
That's pretty much all that I need to do now in my BATNA and save button click event what we're going
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
C sharp we can write this in the short end and this really translates that if is edit mode is equivalent
to true.
That's really what that is asking.
All right.
So if is edit more than we want to do something else we want to do something else.
So if it is it it more than we want to write edit code here.
And if it is not edit mode then we read add code here.
All right so I'm just going to leave those comments for No.
And then the cancel click is pretty much worse than to close the window so if I click cancel the expectation
is that this window will close so I can actually just see it in the beach and cancel click.
I can just see this dot close.
All right.
So remember that this keyword is special and specific to the actual class.
It's just an object of the class that it is being used in.
So this represents the ad to vehicle window and then the dot close is the opposite of the dot show.
So not sure shows the window closed closes the window so if I could cancel then just close the window.
That's pretty much all we're seeing.
And then you notice a visual studio is actually agreeing all this.
So it's not every time that you actually need to use the word this so you could actually just see close
and it will know that's so close itself.
Now we're making good progress.
I'm not already too quiet.
I'm not quite ready to code the edit and add functionality yet instead of going to go back over to my
manage vehicle listing window and we can just take a quick look at that design once again and we have
the add new car button and we have a car button.
Expectation is that when they click add new car we're going to show a new form.
So I'm just going to do that.
So when they click that I'm going to see this.
Sorry.
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
from a visual studio sorry and then I'm going to say is equal to a new instance of it vehicle.
Once again we could always simplify this by saying var if anything and then I'm just going to say had
it.
Vehicle not sure.
So just going to show that new window and of course you want the MDI appearance because you don't want
to just show this room but when we just show the window it's a free window to do anything.
So I wanted to know that its appearance is the mean window.
So I'm went off to read this quote a bit differently.
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
see this dot MDI period.
So they may explain exactly what is happening here.
Remember that we're launching manage vehicle listing from inside of our main window mean windows are
MDI appearance.
So when when the manage vehicle listing window would launch it would have launched inside of me a window.
You would know that mean window is its MDI appearance right.
No I want to launch another window on the command off the manage vehicle listing which is a child off
me and window.
So I needed to know that it is also a child of mine window in the previous ones.
We would have said that when you launch.
Let me just get back to my main window code so you can be reacquainted with it when we were launching
money vehicle listing we said that this is the MDI period.
This being mean window.
In this situation mean window is not the one being doing the launch.
So I can't see this is the mean window because then that would make manage vehicle listing them the
parent for my ad.
Edit window which would be wrong.
So instead I'm seeing this which represents them manage vehicle listing not MDI period which represents
me in the window.
I'm seeing that whatever the MDA parent is off this form that is the parent for the ad edits vehicle.
All right so that's all I'm doing in that line.
So you know a situation you just have to know how to maneuver it in some situations.
This because the MDA appearances make under a call sometimes a child of the MDA appearance is making
that direct call.
So you just need to see.
However my appearance is.
That's also your appearance so that's all we're doing in this line.
I'm saying that my parent is your parent and then we're showing that window.
All right.
So this is loading our ad edit vehicle using the normal constructor in order button click events especially
like in the edit no we'll need to 1 retrieve the data off the car to be edited and then pass that data
over to the farm.
Right.
So once again the expected behaviors that the person is going to click the grid click the row in the
grid and then click edit.
Right.
So firstly we need to know what rule was clicked or at least the value or that I value off the rule
that is clicked and selected.
So here I just outlined some of the steps that we'd need to take when we click the edit button.
So one we need to get the idea of the selected roll right.
So when the person clicks the rule and then clicks edit we need to know what is the idea of that rule
right.
After getting the idea of the rule then we need to query our database which means that we need to initiate.
OK.
We have DB already so we have a connection to the database already active because well that's all we
feel to the grid.
So I already have that object.
So we need to query the database for the Red Card associated with that idea and then we need to launch
our window similar to what we did here.
Except we're going to be launching it with the data.
So remember once again that we have two constructors we have a normal constructor that doesn't expect
too much it just knows it's supposed to add.
And then we have one that is expecting some data to be passed in and that is the one that we're going
to be using when we're going to be launching for editing purposes.
So let's start by getting the idea of the selected rule someone to see a var idea lowercase is equal
to and then I'm going to call my grid which I call GV vehicle list and then I have a property that's
is selected rules.
But then notice it's selected rules because that's actually a collection.
See there it's a selected row collection because maybe the person can select more than one rules.
Right.
But we're expecting that it's only one rule that they're going to select on it's even if they select
more than one where only one the first one.
Right.
So this is a wild assumption.
We can call defensively in the future but right now I'm just keeping it simple.
So of the selected rows I want the first one.
So it's a collection I can use my square brackets specify that I want the first one then I see a dot
then I want off that rule.
We have cells cells represent the columns right.
So I want the cells but then of the cells which is also a collection I'm really only interested in the
one called ide.
Let me hide the properties so we have more room to write a quarter it so I can use a named index.
So in some situations you want the number situations you just want to specify the name of the column
because if I add more columns here I can go by numbers write it off to change my code every time.
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
so I want the value in that cell.
So all it's going to do is say give me the selected the first selected rule and then give me the so-called
80 and whatever the value is even though it's not visible because we keep it.
But whatever that value is I want to store it inside of this variable called I.D. I know that we know
the I.D. off the rule that was selected.
I can see of var car because I not only want one is equal to underscore D.B. dot the table that I intend
to get the car from which is the types of cars dot.
And then we're going to look at another function in length called First or default right.
For a start default we have first entered our first default.
So the difference is that first will fail if it doesn't bring back anything.
Defaults will fail gracefully and give you a nice sense of the error message or just return note.
So on the first floor defaults and then I'm going to do what we have come to love no a lambda expression.
So I want to say to then my arrow then all I'm seeing is give me the first or default.
Pretty much this is like a where clause where to dot.
And then you see that the Q is giving me access to all of the columns I'm interested in the idea column
where the value in the column is equivalent to the idea that we just retrieved from our selected grid.
All right.
So all this is going to do is run it and it's giving me an error here because Ida is actually an object.
All right.
So what I would want to do here is probably just do an implicit passing to an INT.
All right.
So no this is returning an intent Heidi.
And then I'm comparing the integer column to the integer value coming back from this operation.
Know that we've gotten the car.
So as you know we get the car or we get it.
That's what first our default means.
Right.
And the assumption is that if they're clicking the grid then that I.D. is in the database and then we
go on to launch or form with the data.
So I'm going to also see var.
And then once you use the same object name and because they're in different functions they won't interfere
with each other.
And but then this one is going to be equal to a new instance of ad edit vehicle.
But then I'm passing in the data that is coming back from the database in the form of car.
All right.
So I'm went to launch a new instance of this window or this form passing in the data coming from the
database and then I can just copy these two lines where I'm sitting the MDA appearance and I'm setting
it to show so you can see that they're doing similar things except that it is a bit more work because
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
it on into the new window.
All right.
So when it passes into the new window just schoolbook over there it's going to launch with this constructor
which is sorry this constructor which is initializing a component setting a different text setting the
edit mode to be true and then populating the field so that when the form loads you will load with all
of those values already in the text boxes.
Now back in our managed vehicle listing I'm just going to top it all off and do the delete click event
which is going to do a similar thing.
They select the grid.
So we need the idea of the selected value from the grid and when to reuse this code.
And then I need to do a lookup for that vehicle right.
So I do the same thing there but then this time I'm going to delete vehicle from table.
Right.
So after I get the vehicle that is being referenced by that selected rule then I'm going to say underscore
BD dot types of cars dot remove this time.
So when we're inserting data we do add when we're moving we see dots remove.
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
up for.
And then after all of that I'm just going to say D.B. dot save changes.
All right so when we select something from the grid and then we click delete car or the delete button
it will then remove and then I'm going to do one more thing where I see that the grid view should refresh
right.
So I'm just going to refresh the grid view after this has occurred.
No Buck in our ad edit form or the first thing I want is my connection to the database so I'm just going
to copy the existing code because once again I want to keep it consistent.
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
initialization.
So this might be like a double step at this point and you're saying well I don't really want to do it
this way and that's fine.
If he can find a more efficient way you feel free to let me know.
I mean there are more efficient ways.
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
way.
Right.
You could actually just do it in one line just like this and cut out the double or.
Right.
So you could do it that way and have it Initialize all in one line.
That's fine.
But I'm just going to leave it like this since that's the pattern that we've been using up until now.
So after initializing it what I'm going to do is go ahead and write in the code for the editing.
Right.
So after we click save what we need to do is to build a module that represents what was edited and an
important thing to note is that when we're editing we need to keep track of the ideas of the record
that's being edited.
So we have skipped that step because here I set all of the text boxes to have the values what I did
not set was a value for the object being edited.
So you know sometimes you do something you make a decision and then you realize later on that you missed
a step.
So that's part of the development process.
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
to call this label I'm going to blank call it the text I'm also going to make it not visible.
So I'm going to change a proper to visible forms.
I'm also going to change its name to be.
Heidi.
Right.
So that's I know exactly what to call it.
It's in the code behind.
So one of the first things I'm going to set is actually the text for that would be a I.D..
So I would be Bill I.D. that takes is equal to car dog's I.D..
All right.
So we're getting the car object and I.D. is coming overall.
So it's saying I can't.
That's a string stuff to do a two string because I'm storing it instead of a text variable right instead
of a string variable.
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
what I.D. belong to the record that was being updated.
Now I have all the data that I need what I'm going to do first is look up the record that was being
edited.
So like I said you always have to do these lookup.
So that is why it was important for us to track the I.D. because at the time of we us clicking save
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
text which we know is a string.
So that's a string I want of I want to integer variable or an integer value or other someone's out to
do an int dot pass I can do the implicit conversion because that doesn't work when it's a string and
being converts right second in that pass what is in my I.D. label and store it inside of that and then
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
or typing into it before I do where I say D.B. the types of cars not first or default.
So anytime you want one record you can use for a start he folds get our lambda expression open or running
and then say Q Dot I.D. is equivalent to the I.D. We just got back from our form.
No we have our car object and we are not entirely sure what was edited because we have five fields five
text boxes we don't know if they were populated if the votes are deleted we don't know as yet.
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
to the text that is inside of TV model dot the TV model takes box.
Right.
And pretty much that's all I'm want to do for all of them.
So car make is equal to whatever values in TV make that text right.
And I'm going to continue doing that for all of them so you can pass here and finish them.
You'll find that as you go along you may have to do quite a few data conversions to and from so on top
we have to convert from integer to string to get it into the text box and then below we have to convert
from string into integer to get it back into the database after filling all out all of the properties
are probable values so the only one I'm not sitting is idea I don't need to set the idea because the
whole operation is based on the fact that it is the seam.
And the idea would not have changed right after doing all of that.
I would just say D.B. dot save changes and then this would submit all of the potentially new values
even if they're old values.
So even if there was no real change made it would submit all of those to the database for our new car.
No.
A similar operation would be done for adding so I'm just going to do adding quickly where I'm went to
build a car model so I would say something like var new car is equal to a new instance of type of or
types type all types of car.
So remember that this represents our new table.
Right.
So it did something similar to this with our car entire record where we built the car into truck or
no we're just building a new type of car or our types of cars record.
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
allows us to just use our current embraces and fill all of the column names in one could sweep in one
full seat.
Right.
So initializing my object to a new instance of my table to be populated and then I can fill out each
column so I can see the license plate number is equal to whatever value is coming back from the license
plate text box I'm just going to copy and paste so I can move more quickly and then make is equal to
what are values coming from the text box for the Make I notice that there are comma separated model
sorry model is equal to the text box TV model but text right.
And I would just go along and feel each one out.
And I'm just sharp cutting edge here so I can move a bit more quickly.
TB Vin text
and the year well the year would no have in the past right.
So I can just copy that because the code already exists so no that we've filled out a new record for
types of car in order to add it to the database.
You know that we need to see underscored D.B. dot find our table dot ad and then I'm going to pass in
my new model which is new car.
All right.
And then at the end of any operation like this we always need to see changes and that's it.
So if they click and save and we're in edit mode then we will change the see if the changes made to
an existing record.
So we do a lookup based on the idea and then we've made you know submit the changes to that record that
we looked up and then we see the changes.
And then if we're adding a new car meaning we're not in edit mode then we create a new model off the
table type or the cross type to be added to the tables.
Right.
We fill it with the data and then we add it to the collection of records and then save changes.
Now we can test our changes to test all of the code that we've written and click Start.
So I go over to my manage vehicle listing agency that I already took the liberty of editing one of them
before so let's just look at this experience.
Let's start with adding a new car.
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.
Tom the VIN is one two three four five six.
It is twin to 18 and then the license plate number would be H G.
5 6 4 7 right.
That we could say of changes.
So I mean I click save changes the window is still open and but then if you notice that the label is
seeing add new vehicle because we clicked add.
So it's setting the title well.
We didn't see that.
Anything else should happen after see changes so those are some refinements that we need to make as
we go along.
Right.
So the window is still up.
That's 1 and 2.
The grid is not showing any changes.
So if I close this window and then I close the grid and then reopen it however you see that it runs
a fresh query bringing back our newly added vehicle.
So that's something that we have to look into because we wouldn't want to use it off to go through all
of that.
See that they've added a new vehicle.
We also didn't give them any visual prompt to say hey you've added a new vehicle successfully.
So things like that.
So that's with adding a vehicle let's look at anything.
So I'm going to choose one of these existing ones so buggy we did see we're going to modify a buggy
a bit and I'm went to a car.
So the mic is really evokes while gone and it's a beetle.
The VIN and then the year is toy is let's say 1995 and then the plate number would be H Y.
Some random numbers save changes same net effect except that we're in Edit more this time so you see
that one.
It says I did vehicle and in the expectation is that when I refresh the grid buggy will no show different
values.
So once again we didn't necessarily do a good job of handling the experience of moving between the windows
that can be fixed but for no.
Just so that we can validate our changes we can see that buggy is no showing or different values.
So things that we need to do one handling the experience having done an edit or an ad we need to close
the window once the operation is done show them are prompt to let them know it was successful and also
find a way to refresh the grid that is being displayed in the background.
That's what I think that's three objectives right there.
Another thing that we want to do is add some validation and some error handling.
So one you notice that if I click Lada and click a car and then let's say Okay I made one change here
and I click save changes it's going to more time.
Give us one of those nasty arrows which we'll call exceptions which we've been through before.
It's important to handle exceptions.
So that's another thing you can go ahead and add to your form to make sure that it handles these kind
of kinds of arrows gracefully.
All right.
So there are a few places so in every single click event I would suggest that you put the error handling
I try to get statement to try and catch those arrows and display appropriate error messages without
ending the runtime of the program someone to leave you guys to do that.
This was a very long video we did quite a bit.
So I'm going to leave you guys to try and experiment with those validations and those exception handling
and when to stop recording right here and I will do them all screen and in the next video we can review
them together.