Repository navigation
C Programming Intermediate Lecture 6 Database Design Identity and Foreign Keys Salted Hashing
Full tutorial link > https://www.youtube.com/watch?v=sfVi14PI0f8
C# Programming (Advanced/Intermediate) Lectures (6/14) will teach you #CSharp #programming from beginner to intermediate/expert level. This course is an excellent source to learn advanced concepts in C# #coding. If you are a beginner to C#, watch our previous course lectures. The playlist link of the previous course is below.
Full playlist of the previous course: C# For Beginners
https://www.youtube.com/playlist?list=PL_pbwdIyffskoSXySh0MdiayPJsBZ7m2o
Discord ➡️ https://bit.ly/SECoursesDiscord
Patreon ➡️ https://www.patreon.com/SECourses
Technology Playlist (30+ Tutorial / Guide / News / Review Videos)
https://www.youtube.com/playlist?list=PL_pbwdIyffsnkay6X91BWb9rrfLATUMr3
Stable Diffusion Playlist (30+ Tutorial / Guide Videos)
https://www.youtube.com/playlist?list=PL_pbwdIyffsmclLl0O144nQRnezKlNdx3
Please join discord, mention me and ask me any questions. Thank you for like, subscribe, share and Patreon support. I am open to private consulting with Patreon subscription.
Full playlist of this course
https://www.youtube.com/playlist?list=PL_pbwdIyffslHaBdS3RUW26RKzSjkl8m4
You can watch for free our C# Programming, ASP .NET Core MVC programming, Machine Learning and Software Engineering related courses on our playlists page
https://www.youtube.com/@SECourses/playlists
GitHub code repository of this course (source codes of the lectures)
https://github.com/FurkanGozukara/Introduction-to-Programming-2-2021
In lecture 6:
-
How to compose a database in MS-SQL server
-
How to design a database in MS-SQL server properly
-
What is identity column
-
How to reseed identity column
-
What is a foreign key
-
What is foreign key update delete cascade
-
How design a full database with proper primary keys, identity keys and foreign keys
-
How to design a database for Patient Management System which includes Users, User types, treatments, drugs, prescriptions, and diseases tables
-
How to not write code in main window but compose proper classes to reduce complexity of your MainWindow written code
-
What is the purpose of salted password hashing?
-
How to do salted SHA256 password hashing?
-
How to bind list of custom class elements to a ComboBox and read the value of selected item of that custom class
-
How to generate entity framework classes in .NET Core application of existing database with using OnConfiguring builder.UseSqlServer
-
How to properly insert a record to the database with Entity framework and handle errors properly
-
How to program a register screen for patient management system
Introduction
MS-SQL Server is a relational database management system (RDBMS) developed by Microsoft Corporation. It is one of the most popular RDBMS systems in the world and is widely used for various applications. In this article, we will discuss the various aspects of designing and composing a database in MS-SQL Server, including the design process, the various types of database elements, and best practices for creating a comprehensive database.
Composing a Database in MS-SQL Server
To compose a database in MS-SQL Server, you need to follow a few steps. Firstly, you need to decide on the schema of the database, which includes the structure and relationships between the various elements of the database. Secondly, you need to create the database and tables using Transact-SQL (T-SQL) commands. Finally, you need to populate the tables with data.
Designing a Database in MS-SQL Server Properly
To design a database in MS-SQL Server properly, you need to follow some best practices. These include using appropriate data types, defining primary keys, and using foreign keys to establish relationships between tables. It is also important to normalize the database to reduce redundancy and improve data consistency.
What is Identity Column?
An identity column is a column in a database table that automatically generates a unique value for each row. It is typically used as a primary key or as a surrogate key when there is no natural primary key available.
How to Reseed Identity Column
To reseed an identity column in MS-SQL Server, you need to use the DBCC CHECKIDENT command. This command allows you to reset the identity value of a table to a specified value. It is useful when you want to reuse previously deleted identity values.
What is a Foreign Key?
A foreign key is a column or a set of columns in a database table that references the primary key of another table. It is used to establish a relationship between the two tables.
What is Foreign Key Update Delete Cascade?
Foreign key update delete cascade is a feature in MS-SQL Server that automatically updates or deletes related records in a child table when a record in the parent table is updated or deleted. This feature ensures data consistency and helps to maintain referential integrity.
Designing a Full Database with Proper Primary Keys, Identity Keys, and Foreign Keys
-
00:00:02 Hello dear students, welcome to the introduction to programming to lecture 6 as known as also
-
00:00:09 advanced programming.
-
00:00:11 So today we are going to compose a new project which will be about patient management system
-
00:00:20 and we will use all of the skills that we have gained each gain it during this year's
-
00:00:27 in this project.
-
00:00:29 Okay, I'm going to start composing or database first.
-
00:00:38 So in this project, it will be a simple one.
-
00:00:42 We will have patients doctors.
-
00:00:48 Prescriptions and diseases, okay.
-
00:00:52 So, how can we compose a database for search such data?
-
00:01:01 Okay, let's open and see we will have.
-
00:01:08 patients Doctors medical doctors actually
-
00:01:12 Okay, and we will have prescriptions.
-
00:01:22 and diseases
-
00:01:23 Okay.
-
00:01:26 So for this simplistic design, what kind of database you would have?
-
00:01:36 Okay, let's start composing our database.
-
00:01:43 I click new database.
-
00:01:44 I'm using SQL Server management studio.
-
00:01:48 So the database name will be patient management system PMS, okay.
-
00:01:58 And in RPMs database we are going to have how many tables how many tables for each case
-
00:02:05 we would have one table or not.
-
00:02:08 Okay, okay for this system, we are going to design a relational database.
-
00:02:16 Okay, relational database means that there will be relations between
-
00:02:22 tables and Records
-
00:02:24 Okay, so let's start with the new table.
-
00:02:30 Okay, first I will use a user ID.
-
00:02:39 And I am going to Define it as integers you are if you are going to have more than 2 billion
-
00:02:45 records, you can set it bit big integer as well.
-
00:02:49 So this will be a primary key, but not only primary key.
-
00:02:53 I am going to make it also.
-
00:03:02 Identity so it is going to be an identity.
-
00:03:06 It is see it.
-
00:03:08 It's it will be one and it's increment will be 1 so for each record, I add to this table
-
00:03:16 will start from user ID 1 and each time.
-
00:03:22 It will get increased by 1 so I will show you that in a moment.
-
00:03:29 And what does that will be in this?
-
00:03:31 well, so we are going to have to type of
-
00:03:36 let's say users one will be patience and one will be doctors.
-
00:03:42 Right so we can have users type and it is under at 126.
-
00:03:51 Therefore.
-
00:03:52 I will use small tiny in to Define that and the I want a love note for this one as well.
-
00:04:00 So let's save our table with control s or
-
00:04:05 You can also click here.
-
00:04:07 So this table will be T. Real users.
-
00:04:10 Okay.
-
00:04:11 So first of all, I want to show you about this primary key and identity means when I
-
00:04:19 refresh here it says here now.
-
00:04:22 I'm clicking edit top mm droves.
-
00:04:26 Okay, so you cannot enter any value to use right / because it is identity key.
-
00:04:34 Okay.
-
00:04:35 Therefore it is automatic so I can only enter user type.
-
00:04:39 I am answering 3:103.
-
00:04:42 If I answer something bigger than 250, it will throw me an error because tiny inch allows
-
00:04:51 you to have numbers between 2 0 and 255 because it is eight bits, okay?
-
00:05:03 And with eight bits you can have 0 between 0 to 255 integers.
-
00:05:11 Therefore.
-
00:05:12 I can make it like this here like this.
-
00:05:18 You see ID user IDs coming automatically and each time.
-
00:05:22 It is incremented by 1 and when I do select
-
00:05:30 okay, they are all here.
-
00:05:33 So what happens if I delete them or can I update user ID such as update tibial users
-
00:05:42 set user ID equal to like this values ride equal to 1 will it work?
-
00:05:49 No, because you cannot update identity column.
-
00:05:54 Okay.
-
00:05:55 Can I delete them?
-
00:05:56 Of course?
-
00:05:57 It is from TBL users and they are gone.
-
00:06:01 As you can see, so what happens when I add name something new here.
-
00:06:06 It says values are changed.
-
00:06:09 Therefore I have to
-
00:06:10 reopen
-
00:06:16 like this and then I add something like this it will start from by the way.
-
00:06:23 Five because it continued from its last teeth.
-
00:06:28 So if you want to reset the seat as well, what can you do?
-
00:06:32 So let's delete all the chords.
-
00:06:35 You can also use truncate command truncate command is much faster than delete command
-
00:06:45 because it is low place and it cannot be taken back truncate table TBL users like this.
-
00:06:53 It will immediately deleted and when I click properties.
-
00:06:59 Okay, let's see if the seal is right here.
-
00:07:09 Maybe just here that's design open design again and let's see the user ID label designer
-
00:07:23 identity.
-
00:07:24 Okay, so the seed is not displayed here therefore.
-
00:07:30 We are going to reset the seat.
-
00:07:32 However, you can reset the seed after you have deleted all the records.
-
00:07:37 Okay?
-
00:07:38 And what was the comment?
-
00:07:41 I don't remember.
-
00:07:45 Let me find it.
-
00:07:50 Okay.
-
00:07:51 Yeah.
-
00:07:52 Yeah he is.
-
00:07:56 Okay, so the table name is if you are users besides its.
-
00:08:07 zero
-
00:08:08 Okay, I'm done when we add something.
-
00:08:19 Yeah, now it is starting from zero.
-
00:08:23 So if you want to start it from one, then you should reset to see it as one.
-
00:08:30 Okay?
-
00:08:31 Okay.
-
00:08:32 Now let's continue our design so we are going to have user time.
-
00:08:40 And for this user type, we are going to compose another table near the table and it will have
-
00:08:48 user type ID which will be small integers.
-
00:08:52 Let's say and users type name or description whatever you want and more characters and
-
00:09:02 let's make it 156 doesn't matter.
-
00:09:07 So this will be a primary key and it will be TBL user types.
-
00:09:16 Okay?
-
00:09:18 Okay, so let's refresh it and what user types were going to have user type 1 will be Medical.
-
00:09:31 doctors and user type 2 will be
-
00:09:33 patience
-
00:09:35 Okay, and now it is ready.
-
00:09:46 Okay.
-
00:09:47 So this here this user type will be depended on the user types table so I can link this
-
00:10:03 to ID here.
-
00:10:06 However, these ideas are not likely to change.
-
00:10:11 So it is more related to data base design.
-
00:10:13 So I want to answer that so we can set I mean a foreign key to this one to here.
-
00:10:24 What does that mean?
-
00:10:26 Okay, let's see that as well.
-
00:10:28 So let's open this again.
-
00:10:30 So this will be small in and actual tie means.
-
00:10:36 Yeah, and this is going to have
-
00:10:39 a foreign key
-
00:10:47 So I am clicking new Frankie and there are some settings as you can see check existing
-
00:10:54 data on creation or re-enabling and there are also some others.
-
00:11:00 Specifications and first for replication and first foreign key constraint insert update
-
00:11:12 delete specification and that can be rules as well.
-
00:11:17 Okay, so let's look from here.
-
00:11:28 And let's see.
-
00:11:29 What does that as?
-
00:11:30 Well simply so the prank is cost with is used from the actions that would destroy links
-
00:11:36 between tables and apparently is appeared or collection of fields in one table that
-
00:11:42 we first primary key in another table the table with Ferengi is called the child table
-
00:11:47 and the table with chemical equilibria for a suit or positive.
-
00:11:50 So the chart table will be TBR users and the parent table will be TBR user types.
-
00:11:57 So let's
-
00:11:58 Some because the tibia users to see what happens.
-
00:12:01 So 1 1 1 2 2 2 1 1 1 2 1.
-
00:12:10 Okay, whatever they are all done.
-
00:12:12 Okay, so you see some values are not updated here in the edit window.
-
00:12:18 Why?
-
00:12:19 You have to this Diner simply now when we select you see their old incremented.
-
00:12:30 And the table, okay, so here so how do we compose a foreign key?
-
00:12:40 Okay, so I just need to add okay here.
-
00:12:48 So this is the way of adding a foreign key in Microsoft SQL Server.
-
00:12:54 Okay alter table TBL users add constraints foreign key.
-
00:13:03 Let's say a person type and the 4-H a will be on
-
00:13:14 Let's see user type.
-
00:13:16 reference sister versus the TV a user types
-
00:13:24 TBL okay, here's
-
00:13:32 and which column it will be referencing to user type ID.
-
00:13:40 Okay.
-
00:13:41 However, there are also some other options such as update on update or on delete, okay?
-
00:13:49 caskets
-
00:13:50 I want to show you that actually and on delete also.
-
00:14:09 Okay, there is delete Cascade and update Cascade.
-
00:14:17 I also want to add them.
-
00:14:25 So how do we do it?
-
00:14:33 with query
-
00:14:35 chainsaw it is
-
00:14:37 Okay, there is Rule.
-
00:14:39 Yeah, we can also add from design and I think it would be it even easier.
-
00:14:44 So let's add a new Korean key.
-
00:14:48 and
-
00:14:49 Freak a base table.
-
00:14:56 No, not this one.
-
00:15:04 Let's delete.
-
00:15:08 Can I say the designers?
-
00:15:13 Okay, so we navigate to the keys for during the child table right?
-
00:15:18 Click Keys folder and select new foreign key.
-
00:15:20 Okay, so we do it on the child table here and you put in key.
-
00:15:31 Okay, and here's on insert update.
-
00:15:36 Delete we need to select casket about
-
00:15:40 It's okay.
-
00:15:42 Let's see.
-
00:15:44 Okay, that is tables and its Creations from here primary key table user type idea for
-
00:15:53 a kitty bit table in Bellevue.
-
00:15:57 Another table you are not here.
-
00:16:05 Okay, not this one.
-
00:16:16 For a creative I have to be able to select another table.
-
00:16:20 Here's okay.
-
00:16:22 So T we are all but I am not able to change it.
-
00:16:27 So let's try from here.
-
00:16:36 Okay, primary key table will be fighting.
-
00:16:41 Yes, I now I can change it.
-
00:16:45 So let's restart so you can understand so I am coming to my files table, which is Trivial
-
00:16:54 users.
-
00:16:55 I click new pouring K and from tables and column specifications.
-
00:17:00 I select primary creatively as user types and Palenque table will be tibia users and
-
00:17:07 User type ID will be key of user type here.
-
00:17:12 Okay, and then we will set delete Rule and update rule.
-
00:17:19 Okay, and as it now
-
00:17:22 Okay, no and how it is save it.
-
00:17:31 I wanted to save it.
-
00:17:35 Okay, we select them.
-
00:17:38 select them
-
00:17:39 it says yes, but I don't see it.
-
00:17:48 Where is the same button?
-
00:17:54 Is it here, you know?
-
00:18:20 All we have to save it here.
-
00:18:21 I see so when we safety behind users it will it is coming this year now?
-
00:18:30 Okay now it is here.
-
00:18:33 And so when we click modify we can see it it is cascaded.
-
00:18:37 Okay.
-
00:18:38 So what does this means?
-
00:18:40 This means that let me show you now.
-
00:18:45 This user type records are linked to the primary key of user type ID here.
-
00:18:55 Okay.
-
00:18:56 However, this is not identity this user type ID so I can change them.
-
00:19:00 So when I update you see these are underlined and therefore I have to go intelligence and
-
00:19:06 refresh local cage typical user types.
-
00:19:11 And set user type ID equal to let's say 12, when user type ID equal to 2.
-
00:19:19 So this will automatically update delete course in other table as well because of the casket.
-
00:19:26 Okay, one row affected here.
-
00:19:29 And now let's see.
-
00:19:31 Okay, you see these are updated to 12.
-
00:19:34 This is what it is about having foreign Keys.
-
00:19:37 Okay, so if I delete type one
-
00:19:41 What happens it is also cascaded to delete as well.
-
00:19:47 It is prom TV and user types that user type ID equal to one.
-
00:19:53 So, let's see so it has directed one row here.
-
00:19:57 However, the records here will be also deleted.
-
00:20:00 Okay.
-
00:20:01 So this is really dangerous feature.
-
00:20:04 You have to use it extremely carefully.
-
00:20:07 However, it can be also extremely useful as well.
-
00:20:10 So imagine
-
00:20:11 imagine that you have a relational tables, for example, you want to delete a user and
-
00:20:18 now then you would be have to delete all the cords related to that user as well.
-
00:20:24 So if you used for in Keys when you delete the user all other records that depends on
-
00:20:33 user would get automatically deleted if you use these foreign Keys cascading system.
-
00:20:39 Okay, so I think
-
00:20:41 Those are extremely useful to explain you in details.
-
00:20:47 So I will take a note of lectures context.
-
00:21:00 Okay in a church.
-
00:21:19 Mr. 6 also
-
00:21:34 I have to take a pulse.
-
00:21:38 Okay how to reset identity column and
-
00:21:41 What is a foreign key?
-
00:21:46 What is 14K update lead car Scott?
-
00:21:54 Okay, and okay, let's continue.
-
00:22:00 So now we have learned how to do foreign Keys cascading and such and I'm going to
-
00:22:12 And it's my table again.
-
00:22:15 Okay, I will make his bond and two will be Medical.
-
00:22:23 Doctors so this is what is it about being what is it about programming a relational
-
00:22:31 database?
-
00:22:32 Okay, and simply we will just
-
00:22:36 keep at a tiny intvalue as the type of users not we are not going to write the name of
-
00:22:51 the user type here.
-
00:22:53 So it will be much more efficient easy to update.
-
00:22:58 It will take less of space.
-
00:23:01 All right, so let's delete.
-
00:23:04 the courts
-
00:23:12 and then
-
00:23:13 let's release it it when it's our research.
-
00:23:25 You can also achieve that for NK with created like this but using design is I think Butters
-
00:23:33 Okay, I'm going to close this this.
-
00:23:42 okay this
-
00:23:45 It looks like we have the latitude truncate or month or is here.
-
00:23:56 Okay.
-
00:23:58 You see it's the same that current identity the value of was 12 now.
-
00:24:02 It is VC 2 1.
-
00:24:05 Okay, let's design the table.
-
00:24:08 So we are going to have used or type and from our design what we what else we need we can
-
00:24:17 have users email for logging.
-
00:24:22 User email, it will be unbar characters.
-
00:24:25 Actually, it can be bad character because he emails cannot have non English letters
-
00:24:35 and but we also don't want to users to register with the same email.
-
00:24:45 Okay.
-
00:24:46 So, how can we ensure that in the database?
-
00:24:51 We can ensure it with a very like this.
-
00:24:54 Let me show you.
-
00:24:55 Okay.
-
00:24:56 And first I will add some records for example one and a @k Gmail comb.
-
00:25:08 Okay to a Jimmy.
-
00:25:12 I wonder if this character is even saved in watercolor brush.
-
00:25:17 okay, so it is a valid character perhaps and a at
-
00:25:31 home
-
00:25:32 Okay, 1A.
-
00:25:33 Aah email comb.
-
00:25:36 Okay.
-
00:25:37 So right now we have multiple users with the same email such as we're email or user email.
-
00:25:48 Equal to this U Z3 email is same they are case insensitive to do a two-hour Collision.
-
00:25:59 So let's check our collation as well.
-
00:26:04 And what is the correlation options?
-
00:26:08 Yeah, so alkylation is set as case insensitive but accent sensitive.
-
00:26:17 Okay.
-
00:26:18 So what does that mean?
-
00:26:19 That means that for example, let's set another one she remain calm.
-
00:26:29 But since this is one character.
-
00:26:35 Yeah, they are saved as same because it is not and more character is already more character
-
00:26:43 anyway, so our aim is not a loving same email to be recorded the database.
-
00:26:50 So, how can I do that?
-
00:26:51 I can do it with are simply.
-
00:26:59 index
-
00:27:01 so
-
00:27:06 what kind of index we can have I'm going to have a name index.
-
00:27:10 But as you see it is not allowing me to change in this from this server management studio
-
00:27:19 right now.
-
00:27:20 I think it's the back in server SQL Server management studio.
-
00:27:24 So when this happens, I just restart or open another instance of SQL Server management
-
00:27:32 Studio.
-
00:27:34 I don't know how why that happens but
-
00:27:36 It happens sometimes.
-
00:27:38 Okay.
-
00:27:39 So what we are going to do is we are going to Define an index.
-
00:27:44 Okay, so it will be a non-clustered index.
-
00:27:50 Okay, and in this non-clustered index we are going to have used email.
-
00:27:57 Okay, and it will be unique like this.
-
00:28:00 So when you set in in this like this, it will only allow unique values to be included in
-
00:28:10 that column.
-
00:28:12 Also, it would also speed up your Valkyries.
-
00:28:25 We can also add a constraint and the constraint would be.
-
00:28:39 It requires an expression.
-
00:28:42 Okay, let's see a concert.
-
00:28:46 I have never dated a constraint.
-
00:28:47 I have only used indexes.
-
00:28:58 Let's see if that is possible.
-
00:29:29 Cadiz
-
00:29:34 Okay.
-
00:29:39 I wonder if the only way is index or constraint as well.
-
00:29:44 Yeah, it is about indexes So currently I'm just delete this our index is failing to compose.
-
00:29:58 Do you know why because we already have duplicate key in our database.
-
00:30:05 So therefore first we have to delete our recourse, okay?
-
00:30:14 like this
-
00:30:17 then we can compose our in days.
-
00:30:22 We can give a name for it such as index users email, by the way here.
-
00:30:30 I am picking unique non-clustered means that it won't be the primary key of the table.
-
00:30:40 You can look for it for more details later.
-
00:30:44 And so when I check unique
-
00:30:48 It's means that this column will be none of unique.
-
00:30:53 Okay, and then I by the way if you are a loving null probably you can set it as unique.
-
00:30:59 I don't know why I haven't tried it.
-
00:31:01 Okay.
-
00:31:02 So now I won't be able to add same email twice for example one a
-
00:31:16 at gmail.com.
-
00:31:17 Then a HTML Chrome and it will throw me an error.
-
00:31:21 Okay, you see cannot insert duplicate key role in object with unique index as like this.
-
00:31:30 So this is the way to ensure uniqueness on a column.
-
00:31:35 This may be the more most.
-
00:31:39 Yeah, this is probably the only most efficient very because if you don't keep an index each
-
00:31:46 time, when you end up at a record, it would be have to risk on the entire table there
-
00:31:54 for an index is the only proper way.
-
00:31:57 Yes, so we have also verified our Theory as well.
-
00:32:01 Okay.
-
00:32:02 So let's continue our design then what else we need.
-
00:32:06 We need password.
-
00:32:09 user password
-
00:32:10 We will keep password wheat.
-
00:32:17 Sha 256 encryption and we will also salted I will also show you what is salted passport.
-
00:32:26 What does that mean?
-
00:32:27 Okay.
-
00:32:28 So, uh put sighs I think it is 64 characters.
-
00:32:40 always
-
00:32:44 yeah, it is 60-45 remember correctly.
-
00:32:49 So I'm going to set it as character 64th always and what other info would we need by the way,
-
00:32:58 it is each time showing this.
-
00:33:00 Do you know why because we did set a foreign key here.
-
00:33:05 Therefore it is always oh, by the way, it says that index was edit and it will be deleted
-
00:33:14 because it was added.
-
00:33:17 Here and not on this window on this instance.
-
00:33:21 And therefore I will just copy this.
-
00:33:24 Then open another design is gone.
-
00:33:29 Yeah, okay.
-
00:33:30 Let's say use a pair of PV characters 64.
-
00:33:42 Okay, database design is something that you need to develop your skills over time.
-
00:33:51 It is not an easy task designing a designing and efficient database.
-
00:34:00 Okay, what other information we can keep we can keep register IP.
-
00:34:07 For example, and we can keep IPS IP version 4 which are also called this one, two, three.
-
00:34:15 One, two, three, one, two, three, one two three, so it is 12 plus 1 2 3 4 16 character.
-
00:34:28 but it it would be better to keep it as an characters as
-
00:34:38 I mean one characters.
-
00:34:41 16 okay.
-
00:34:44 So this will be registration IP and we can also make this unique.
-
00:34:50 So from one IP a person can only register one but it is up to us.
-
00:34:57 And we can keep the register date.
-
00:35:01 such as daytime and we can set a new default value for this such as
-
00:35:06 If this is a method of SQL servers, for example, if you type like this, you will get get UTC
-
00:35:18 time when you are working on a server the time synchronization is really important.
-
00:35:27 So I prefer to use UTC time for my programs, but you can also keep the local time as
-
00:35:36 System data in that case.
-
00:35:40 It will be dependent on the your system time.
-
00:35:43 So UTC time is better Universal.
-
00:35:47 Okay.
-
00:35:49 Users can shoot also record his her first name and last name.
-
00:36:00 So first name.
-
00:36:04 such as animal characters
-
00:36:07 40 below the enough and last name
-
00:36:11 or certainly one bolt is fine.
-
00:36:17 Okay, and this can't we also know and what the other information we will take from patient
-
00:36:24 or doctors?
-
00:36:25 Okay, since we will keep both doctors and patients we can also keep the specific specifically
-
00:36:36 area of doctors.
-
00:36:37 Therefore we can design them in our user types.
-
00:36:44 For example that can be other doctor types as value can expand the table, but for Simplicity
-
00:36:54 just let's just keep it as this way.
-
00:36:58 Okay, so this will be our users table.
-
00:37:03 Okay, it says that IV cannot insert null value because there are some records in our table.
-
00:37:15 Avi videos pick the a la Luz
-
00:37:27 Oh, we have to delete this existing record.
-
00:37:32 Why because we are not allowing Knowles.
-
00:37:36 Therefore if there is an existing record.
-
00:37:39 I cannot modify table like this.
-
00:37:41 I have to pick checkbox alone knows our I have to delete record.
-
00:37:46 Let's delete them.
-
00:37:49 Okay.
-
00:37:52 Now it's not let me save.
-
00:37:55 Okay, so users table is save it and user types is ready.
-
00:38:03 Then what others table we need we need prescriptions table.
-
00:38:09 Okay.
-
00:38:10 So let's compose a Neve table.
-
00:38:16 It will be simply prescription.
-
00:38:19 Heidi it will have which I make this integers primary key, but it doesn't have to be identity.
-
00:38:28 We can also make it identity.
-
00:38:29 It is up to us.
-
00:38:31 So let's make it identity for easier.
-
00:38:39 easy processing and the prescription what else that can be for prescriptions that can
-
00:38:44 be malignant milligram size and name expiration date, whatever so
-
00:38:53 I will say I will keep the milligram.
-
00:38:58 No, we can keep the milligram in the name as well.
-
00:39:04 Or let's add a column for that.
-
00:39:07 So it will be prescription medical.
-
00:39:16 Ah, yeah.
-
00:39:18 Okay medication.
-
00:39:20 How it is.
-
00:39:22 Okay, drug dogs.
-
00:39:25 Yeah, let's call it as doors.
-
00:39:30 milligram
-
00:39:31 and since it will be a milligram.
-
00:39:35 Let's make it how much milligram yeah small in should be sufficient.
-
00:39:46 And then prescription name.
-
00:39:50 Or all this is about drugs not prescriptions.
-
00:39:55 So this is with rock ID.
-
00:39:59 And those milligram and rock name.
-
00:40:03 It will be unwell corrector 200.
-
00:40:06 Okay, so this will be drugs table.
-
00:40:11 Okay and done.
-
00:40:16 We will have Z this.
-
00:40:21 Okay.
-
00:40:23 Do we need diseases for this task?
-
00:40:34 You have for searching we would need Okay, so let's a disease ID.
-
00:40:41 You see the database design is totally up to you how you design it how efficiently you
-
00:40:47 design it is about your experience your experimentation.
-
00:40:56 Okay disease named okay can be like this and that can be disease description.
-
00:41:06 We could expand this database for disease symptoms and such other things but it would
-
00:41:16 make it even more.
-
00:41:19 Let's say complex.
-
00:41:21 We don't need that right now.
-
00:41:26 Okay.
-
00:41:27 Okay, so there will be disease.
-
00:41:29 I did this is named.
-
00:41:31 This is description TBR diseases.
-
00:41:34 Okay, one more table.
-
00:41:36 We need what?
-
00:41:38 Can this be just think about that?
-
00:41:42 Okay, we will have a table that will that will have the prescriptions?
-
00:41:54 What does that mean that medical doctors will write drugs to the patients with disease assignment.
-
00:42:07 Okay.
-
00:42:09 So now it is about this is what what it means.
-
00:42:14 We'll have relational database.
-
00:42:16 So here we will have a prescription idea.
-
00:42:28 How else can we call it?
-
00:42:32 It can be also treatment as well.
-
00:42:34 Let's make it treatment idea.
-
00:42:36 Yeah, and it will be primary and
-
00:42:43 and behind that specification
-
00:42:48 yes, and this treatment ID will include
-
00:42:57 doctors so the treating doctor it'll be issued on let's say
-
00:43:09 prescribing doctors
-
00:43:14 So this will be the doctor user ID doctor user ID.
-
00:43:20 Okay, and then describing doctor Easy Rider patient user ID.
-
00:43:31 Okay.
-
00:43:34 And what does that can be prescribing doctor user ID patient user patient user ID and prescribed
-
00:43:44 Rock.
-
00:43:45 Okay, so if you make prescribed drug, then we cannot have multiple drugs assigning to
-
00:43:55 a treatment.
-
00:43:58 Okay.
-
00:43:59 Therefore I will not make it that way.
-
00:44:01 I will put you here also in addition disease it disease ID.
-
00:44:14 Okay.
-
00:44:18 Let's save it as TV treatments.
-
00:44:23 And I will also set pouring keys for these treatments here.
-
00:44:31 Okay, so let's check.
-
00:44:35 So the primary cake will be
-
00:44:39 Okay, this is ID.
-
00:44:42 Oh boring cable with sorry about that.
-
00:44:49 Frankie will be the diseases here.
-
00:44:52 So let's test it.
-
00:44:55 Okay, so the primary K table will be treatments and from treatments that will disease idea.
-
00:45:04 It will be equal to disease ID of diseases so they will be cascaded.
-
00:45:11 Okay.
-
00:45:13 Mmm, okay.
-
00:45:17 It says that it is not unique or not.
-
00:45:25 Okay, so we are not able to set a relation like this.
-
00:45:34 Okay, one moment.
-
00:45:46 Okay, so the primary key will be diseased idea and praying key with the disease ID in
-
00:45:55 our treatments table.
-
00:45:57 Okay.
-
00:45:58 Now it is done and I am going to set it as cost card and casket by the way when you set
-
00:46:06 it like this and assume that you are trying to add a non-existing disease idea to your
-
00:46:17 treatment table then you
-
00:46:19 Get an error.
-
00:46:20 Okay, so this is useful for that as well.
-
00:46:24 So let's continue our other foreign keys.
-
00:46:27 I will delete this delete this
-
00:46:30 Okay, there it is as well.
-
00:46:34 So let's restart.
-
00:46:38 Okay, here's 4 NK table will be disease idea diseases.
-
00:46:47 Is it ID disease ID done and another one.
-
00:46:52 Why the first make this cascading?
-
00:46:57 I can use it on pause for application for foreign key constraint by with that way.
-
00:47:06 You won't be able to add a non-existing disease idea to your treatment table.
-
00:47:13 Okay, so here's drugs.
-
00:47:17 No, no drugs.
-
00:47:22 We need user CS from users table user ID will be the patient user ID.
-
00:47:33 Oh, we can Define multiple know.
-
00:47:46 I wonder if this would work.
-
00:47:53 Let's try let's make
-
00:47:57 another one
-
00:47:59 This time try my cable be user ID again and it's feel very talk to use right?
-
00:48:13 Yes.
-
00:48:14 Okay, and when we save the table
-
00:48:17 Okay, okay, it's saved.
-
00:48:20 So we still need one more table.
-
00:48:26 But before going test let's try something.
-
00:48:29 Okay, so let's add some users.
-
00:48:32 so our database
-
00:48:36 To see our foreign keys.
-
00:48:44 So user ID we can set it to user type one email something.
-
00:48:51 Where's the passport has to be 64 character exhibit problem?
-
00:48:56 Let's play.
-
00:49:01 Let's use some basics for encoders.
-
00:49:09 No, not this one.
-
00:49:15 Jay there is an online tool.
-
00:49:20 Yeah, something like this, okay.
-
00:49:23 It's register IPA something like this.
-
00:49:27 Register that we can leave it.
-
00:49:30 No because it will be UTC daytime.
-
00:49:36 Okay.
-
00:49:39 Okay.
-
00:49:41 Now we have the first users and let's add a disease.
-
00:49:47 For example, this is ID.
-
00:49:50 This is name.
-
00:49:52 Let's play.
-
00:49:55 Coronavirus is covid-19.
-
00:50:02 very dangerous
-
00:50:08 Be careful.
-
00:50:09 Okay.
-
00:50:10 Okay.
-
00:50:11 Now I have ID and
-
00:50:12 I need also another users because I have one currently patient that Anna then I need also
-
00:50:20 a medical doctors.
-
00:50:22 So let's add another user.
-
00:50:26 I can use those type to something to Let's copy same okay and
-
00:50:42 Let's say talk.
-
00:50:44 After X.
-
00:50:45 Whatever but this is the doctor now we can add a treatment.
-
00:50:53 Okay.
-
00:50:54 So the treatment ID will be okay automatic.
-
00:50:56 So the doctor I'd available to patients to drive everyone this is item in Devon and
-
00:51:06 Okay.
-
00:51:08 Okay, let's see don't we have two users or you see all user IDs are different because
-
00:51:21 each time when you try to commit a change from editing window of SQL Server management
-
00:51:30 studio and it fails your user your primary K will be increased by one what I mean is
-
00:51:38 each time.
-
00:51:40 You try to commit
-
00:51:43 name three chords
-
00:51:47 ROM SQL Server management edit window interface.
-
00:51:55 It fails your primary key will increase by one.
-
00:52:01 Okay.
-
00:52:02 So this is why we have four and six therefore.
-
00:52:06 We will make them as 6 and 4.
-
00:52:11 Okay now it is working and when I try something like this, this user does not exist and this
-
00:52:17 your exist.
-
00:52:18 This one exists.
-
00:52:19 You see now it is throbbing pain error.
-
00:52:22 This is what is it about foreign keys.
-
00:52:25 So foreign keys and sure that you have valid values in your tables.
-
00:52:33 Okay.
-
00:52:34 It is extremely useful if you use it properly.
-
00:52:39 All right, and there is one more thing we need we need drugs prescribed drugs.
-
00:52:46 So prescribed drugs will have this time we are not going to have a primary key.
-
00:52:54 Why because the primary key will be a composition of treatments and Drug IDs in this case in
-
00:53:03 this case, so there will be treatment idea.
-
00:53:09 Okay, something like this and that will be drunk ID.
-
00:53:17 And that's all this is what we need for prescribed drugs and the composition of these two values
-
00:53:27 will be the primary key.
-
00:53:31 Let's say however we can also add any additional think it can be as the prescription date why
-
00:53:43 because a patient may get
-
00:53:48 Multiple prescriptions of the same treatment but it is related to your design.
-
00:53:54 So let's let's go keep it this way for now and
-
00:54:00 Yeah, let's keep it simple TBI prescriptions.
-
00:54:05 Okay, and now we also need to set key foreign keys for this.
-
00:54:16 So this time it will be primary key will be drugs from drugs.
-
00:54:25 It will be Rock ID and from here.
-
00:54:28 It will be Rock idea.
-
00:54:31 So this will be none and this will be
-
00:54:32 Rock ID okay
-
00:54:48 Okay, looks like we are not able to set.
-
00:54:52 This kind of rain key.
-
00:55:06 Oh, I think we can set yes none.
-
00:55:11 Okay, and I will make it insert update delete cascaded.
-
00:55:16 Okay when you cast cut it may delete your record.
-
00:55:22 So it is extremely dangerous as well.
-
00:55:27 So we have set the drag and now we are going to set the treatment so there will be treatment
-
00:55:34 ID here and this will be none.
-
00:55:39 Okay, so we have fully set primary keys and foreign keys and everything.
-
00:55:46 Okay.
-
00:55:47 Now it is save it.
-
00:55:50 Okay.
-
00:55:51 Now everything is ready to court.
-
00:55:55 We have designed our database perfectly fine and let's start with our coding.
-
00:56:07 Database design is extremely important part of programming and it requires knowledge skill
-
00:56:16 experience research experimentation everything and there are also indexes for performance
-
00:56:23 tuning and I haven't get into them yet.
-
00:56:27 So we are opening EPF dotnet framework uses.
-
00:56:30 This was named as dotnet core previously as you already know.
-
00:56:36 Let's peak hours.
-
00:56:42 all this
-
00:56:44 Okay, here's lecture 600.
-
00:56:51 This is not not that net cost ya.
-
00:56:56 So I was good I was confused.
-
00:57:01 If f is now dotnet not that that framework, this is regular dotnet framework.
-
00:57:08 We need to pick this one.
-
00:57:12 Yes.
-
00:57:13 Okay, you see there is no dream of selection.
-
00:57:17 So let's pick this Source folders.
-
00:57:22 Here's here's
-
00:57:25 Okay, next your six.
-
00:57:29 Okay, okay.
-
00:57:31 Oh there is dotnet 3.1.
-
00:57:37 You see now it shows this is one out of support.
-
00:57:39 This is long-term support and dotnet five core 5 is current we are going to use always
-
00:57:53 the newest technology.
-
00:58:14 Okay.
-
00:58:22 Okay, so our code is being generated.
-
00:58:42 Okay, so our project is composed.
-
00:59:27 Okay, if he remembers to be able to use Entity framework in.net core we were using reverse
-
00:59:34 engineer.
-
00:59:35 And therefore I will use it as well.
-
00:59:39 So we will get an eve database Source located receiving list of servers.
-
00:59:50 We can also get faster server with.
-
00:59:55 server name
-
00:59:57 like here's okay and database name will be RPMs.
-
01:00:03 Okay, and let rest will be by default correctly.
-
01:00:11 You see here.
-
01:00:12 It says loading database objects now we will teach our tables.
-
01:00:17 And you see it is displaying the primary Keys.
-
01:00:21 The other things are the following keys are related to database itself.
-
01:00:26 I don't think so.
-
01:00:27 It is getting into and fame of this design.
-
01:00:34 Okay, we'll leave the rest as default.
-
01:00:41 Okay, so our classes are generated.
-
01:00:46 He's he's installing EP core provider package, and it is also installed and references will
-
01:00:57 get loaded.
-
01:01:01 You see it is saying that responding problem.
-
01:01:05 So loading packages and references are taking time.
-
01:01:09 Oh, I see it all for even have the foreign key constraints as well.
-
01:01:16 So you see even they are loaded.
-
01:01:19 It it when shows the unique code or fixed length.
-
01:01:27 Everything is loaded into classes.
-
01:01:28 Okay, this is pretty convenient.
-
01:01:33 All classes are here tibial diseases drugs prescriptions treatments users user types.
-
01:01:41 Okay, and I will be ready right now.
-
01:01:45 Okay, and I am going to add my existing class from my another project.
-
01:01:57 Okay, I think it is.
-
01:02:01 How do we do it?
-
01:02:04 Add existing item here and it is located in lecture 5 here's csdb connection.
-
01:02:12 Okay, you see this has namespace lecture 3 therefore if I don't include this namespace
-
01:02:22 into my project.
-
01:02:24 I cannot use it.
-
01:02:25 So if I want to use it either I can change its name space or I can delete namespace and
-
01:02:31 when you delete the name space it will be it will become available to your entire project
-
01:02:38 and
-
01:02:42 That is says that SQL connection is not available.
-
01:02:46 Let's see.
-
01:02:48 It says that.
-
01:02:51 Okay, we have data here.
-
01:03:03 Okay, it says that the type name SQL connection could not be found if system data SQL client?
-
01:03:20 Okay to have it.
-
01:03:25 Okay, let's close and reopen.
-
01:03:43 Okay, it looks like you have to add.
-
01:03:51 SQL clients
-
01:03:54 Maybe you should I don't remember we have installed it.
-
01:04:07 JDate
-
01:04:10 let's install it.
-
01:04:21 Okay, after we installed the package it is available.
-
01:04:35 So this is our default SQL connection class now, let's add.
-
01:04:44 existing item and
-
01:04:46 okay, so we didn't cut anything for Entity framework as a global function.
-
01:04:58 Okay, so we can continue from what we have.
-
01:05:05 So I will change the database name here to PMS.
-
01:05:11 All right.
-
01:05:14 Okay.
-
01:05:16 Now let's start with a register window for users.
-
01:05:25 okay for registering users, we are going to have several Xboxes and we can also use
-
01:05:46 we can also use
-
01:05:50 top control as well if we want.
-
01:06:00 So let's start the top item and first one will be named as register.
-
01:06:07 Okay?
-
01:06:09 and here let's
-
01:06:11 Make art but it's like this, okay.
-
01:06:18 Okay, now that we have J this video, so let's take it back.
-
01:06:29 Okay, let's put some things so it will automatically get updated.
-
01:06:37 Okay to properly.
-
01:06:40 position them you can use
-
01:06:46 grid layouts I think once was this coded
-
01:06:53 Yeah, grid layout but I won't be wasting time with that right now as it is not our topic
-
01:07:02 in this at the moment.
-
01:07:05 Okay, so this will be a username.
-
01:07:12 Or let's say first name.
-
01:07:15 Okay.
-
01:07:17 So let's put here.
-
01:07:22 So the design T is totally up to you.
-
01:07:25 You can design your application as you want as you wish.
-
01:07:31 Let's make them same hate.
-
01:07:33 Let's eat make each.
-
01:07:37 One of them is 40 and it's over also.
-
01:07:45 forty
-
01:07:46 and I will position the same like this.
-
01:07:51 Okay, so I think can be
-
01:07:56 That's can I lying that.
-
01:08:03 Let's look for it.
-
01:08:12 Let's try this picture is working.
-
01:08:26 Ruskin and I'm Tia tennis vertical alignment centers
-
01:08:33 I have to delete this.
-
01:08:38 Okay, it is not about text.
-
01:08:41 So we need something related to taste vertical alignment content and alignment.
-
01:08:49 Oh, I see we have to do something like this.
-
01:09:05 And I won't be spending time together.
-
01:09:07 So that will be first name and lets you need to text and give it a name.
-
01:09:14 Let's take the first name.
-
01:09:20 Let's copy and paste this to.
-
01:09:27 Okay, so this will be last me.
-
01:09:34 Okay Tac last name?
-
01:09:39 Okay, and what other information we are going to have we're going to have email right for
-
01:09:47 for email?
-
01:09:49 Okay, let's type it here.
-
01:09:56 Amanda Bynes, I will make to email text box bigger.
-
01:10:10 Such as this txt email.
-
01:10:17 Okay, and then
-
01:10:21 you're going to have
-
01:10:27 okay.
-
01:10:28 What the other information we do collect?
-
01:10:34 Yeah, we are going to need password.
-
01:10:42 Let's say password.
-
01:10:47 Okay, and we can also have passwords verification.
-
01:10:50 So passwords will be about a password box like this.
-
01:11:00 So it can't have text.
-
01:11:04 Okay, and it will be th CP asphalt one more text wrapping as well.
-
01:11:14 okay, so password and
-
01:11:29 okay.
-
01:11:33 password verify
-
01:11:40 like this
-
01:11:42 a chain that's
-
01:11:49 Okay, so we need text wrapping for this job.
-
01:12:12 Watching so many texts look for that perhaps.
-
01:12:20 Yeah, he needs.
-
01:12:28 Can you can you look like this as well?
-
01:12:51 Bye.
-
01:12:54 Why not Islam?
-
01:13:02 Can you really fine?
-
01:13:04 You see now that the text is put inside another Arden box something like that.
-
01:13:10 So that's how it is rapid.
-
01:13:11 And okay.
-
01:13:12 Let's make it like this.
-
01:13:13 the team to make this maximum
-
01:13:17 size
-
01:13:18 okay, so there is hate and wait, so let's make it same as the
-
01:13:35 content
-
01:13:39 they are not matching interesting.
-
01:13:58 I can't wait is working.
-
01:14:17 And not important anyway, so this will be T XT pv2.
-
01:14:28 And finally we are going to have a combo box for picking up Authority level.
-
01:14:36 So I will make the selection inside this one.
-
01:14:41 I will show you what I mean.
-
01:14:44 So this will be named GM box.
-
01:14:50 Users Rank, and then we will have a button for registers.
-
01:14:58 Okay.
-
01:14:59 Let's put a modern here and let's name it as registered name BTW, I register.
-
01:15:13 Okay.
-
01:15:14 Okay, let's compose.
-
01:15:15 It's click event.
-
01:15:20 All right.
-
01:15:23 So there are several things I want to do right.
-
01:15:28 Now.
-
01:15:29 First one is I don't want to write my code inside my vein window class.
-
01:15:37 How can I do it?
-
01:15:38 I can do it simply like this first I generate an instance of main window or less a reference
-
01:15:46 of men we do and I sign it so main window will be something like this public.
-
01:15:53 Ma'am, and love and Main.
-
01:15:58 Okay, and this man will have reference of this.
-
01:16:04 Okay, so why I am doing that I will explain to you.
-
01:16:12 And register will call another class.
-
01:16:16 So let's add a class.
-
01:16:19 as register operations
-
01:16:24 Okay, yeah.
-
01:16:27 Okay, so register will call a register here for public Voyage from plates.
-
01:16:39 registers
-
01:16:40 and this method will be called.
-
01:16:47 So let's make it close static class.
-
01:16:52 And is in the public static?
-
01:17:06 Okay.
-
01:17:08 Okay, so this button will simply call this method inside register operations.
-
01:17:20 Okay, then I also need another think I have to initialize the combo box.
-
01:17:37 So let's write a method for that.
-
01:17:47 First write the method inside here, then we will move it.
-
01:17:50 So what is this going to do this?
-
01:17:54 We'll initialize items into our combo box.
-
01:17:59 Okay, but I want to use a class what I mean is a collection of observable collection to
-
01:18:11 be source of
-
01:18:15 My phone box.
-
01:18:18 So basically we are going to
-
01:18:25 design a collection of observable collection of user types.
-
01:18:34 Okay.
-
01:18:35 So observable collection go to be able to use it.
-
01:18:40 I don't need yes.
-
01:18:45 Let's do it like this observable.
-
01:18:53 connection
-
01:18:54 probably is not available.
-
01:19:00 Yeah, it has added a reference perhaps now jobs or whole collection and it will be type
-
01:19:11 of tibial user types here and users frogs, whatever equal to the user types.
-
01:19:25 I was only one connection.
-
01:19:28 Okay, just giving which is okay.
-
01:19:32 Now it is working then we will use our Entity framework.
-
01:19:39 Okay.
-
01:19:40 So for do it we will do using and I don't remember the exact same text because it's
-
01:19:46 I am still not used to it yet.
-
01:19:53 So let's open our previous.
-
01:20:02 Hold my hand.
-
01:20:09 Okay, so
-
01:20:14 yes.
-
01:20:17 Yeah he is so it will be a context.
-
01:20:26 Okay using so our context will be.
-
01:20:32 PMS
-
01:20:34 PMS context my or less a context equal to NIV PMX context here.
-
01:20:44 Then we are going to get user types.
-
01:20:50 Okay, so tibia user types.
-
01:20:56 and
-
01:20:57 let's say a word.
-
01:21:01 equals or we are user types equal to context dots TBI user types dots
-
01:21:17 Wind or select so Point returns?
-
01:21:23 Finds an entity.
-
01:21:24 If found attached to context and its own if not divide node is returned.
-
01:21:39 So that can be fined or water sigh.
-
01:21:46 Can we select so what does selector?
-
01:21:52 Okay, so I think we need to.
-
01:21:55 find
-
01:21:57 like this.
-
01:22:01 Okay.
-
01:22:02 So let's see what will these return to us for now and proceed from there, but this context
-
01:22:12 will be available only inside this using statement.
-
01:22:17 That's an important factor to consider.
-
01:22:24 Devon moment.
-
01:22:31 Okay, one second.
-
01:22:42 Okay, so our software is running.
-
01:22:58 Okay.
-
01:22:59 So let's click register or we didn't call this yet.
-
01:23:07 So I will call it here first.
-
01:23:20 By the way, this means instance of the main class here.
-
01:23:25 Okay, so let's execute a step.
-
01:23:29 Okay.
-
01:23:30 So no database provider has been complicated dbcontext.
-
01:23:34 Yeah, we have to set the agree on configuring we had done that here and where was it goes
-
01:23:45 inside here perhaps
-
01:23:47 Yeah, he's on configuring inside context.
-
01:23:51 So PMS context in which we are going to use it here.
-
01:23:57 Yes now it should work.
-
01:24:07 You see you don't have to memorize you just need to know where to look.
-
01:24:14 Okay, so it says
-
01:24:19 Okay, so the find didn't being everything.
-
01:24:37 Okay, it was just like this me don't need find find is used for I think doing where's
-
01:24:52 queries.
-
01:24:53 So it is about filtering change the number of rows returns.
-
01:25:01 Okay.
-
01:25:04 My Moment
-
01:25:08 Yes, so, let's see what has written.
-
01:25:14 So we have Aunt its type and local so inside local we have zero and type.
-
01:25:27 Okay, let's count.
-
01:25:30 and there are two cons and
-
01:25:35 non public members
-
01:25:36 Okay, so
-
01:25:40 let's do a four th inside.
-
01:25:46 So this is the type of pink.
-
01:25:49 TV set TV user types
-
01:25:51 And from here, what do we have?
-
01:25:56 And item dots.
-
01:26:06 Okay.
-
01:26:11 So then we check item VCT.
-
01:26:14 We are users user type ID and username.
-
01:26:17 Okay.
-
01:26:18 So this is what we need actually, however, I don't understand why this is huge.
-
01:26:26 So this is all.
-
01:26:35 I collection.
-
01:26:41 Okay, so let's try it like this.
-
01:26:47 Let's add inside this something.
-
01:26:51 Okay, new table user types and here I think.
-
01:27:00 So interior user types, we have public string user type name.
-
01:27:15 And we have type usual ID.
-
01:27:19 They are inside TV and user types.
-
01:27:22 Okay.
-
01:27:23 So when we say this is why I cannot set the values here's
-
01:27:30 Oh, I can set it.
-
01:27:34 So here I will set widely.
-
01:27:37 There is one extra thing.
-
01:27:40 Okay, so here I will set the user type ID as 0 and type name as please pick user type,
-
01:27:51 okay.
-
01:27:52 So it is the best range.
-
01:27:58 So this will be the first item of our observable collection.
-
01:28:07 Then I will add item okay item.
-
01:28:17 Honda I will bond it has itemssource equal to use the rungs and the also need to set
-
01:28:33 the display item.
-
01:28:35 So the display path display member Pat will be equal to user type name.
-
01:28:42 Okay.
-
01:28:43 So let's try I'm hoping that it won't work.
-
01:28:49 Okay.
-
01:28:53 Let's see.
-
01:29:00 Object it is working as expected and one final thing.
-
01:29:07 Okay, we will set the selected index at zero.
-
01:29:13 Okay, so this will be our initialization.
-
01:29:16 However, I am going to write another class.
-
01:29:20 So we will reduce the code.
-
01:29:23 We are re riding in our main window.
-
01:29:25 You should write as minimal as possible code inside your main window class main interface
-
01:29:35 class, okay?
-
01:29:36 So let's add another class here and let's call it as in it.
-
01:29:45 Or let's say up in it.
-
01:29:48 Okay, and it will be a public static class public static void in it up or methods and
-
01:30:02 here we will do the same.
-
01:30:04 So it will be something like this.
-
01:30:07 Okay.
-
01:30:09 Now you will see we are getting an error of
-
01:30:13 observable collection because we need to add reference we have added then we are not able
-
01:30:19 to access this so hard we are going to access it is simply we are going to access it by
-
01:30:24 our main window dots
-
01:30:29 I'm not at so how can I access it?
-
01:30:33 We can access okay public static mainly domain.
-
01:30:39 And from here we can access it.
-
01:30:44 I think.
-
01:30:46 Yes, yeah and like this.
-
01:30:56 I could also get reference of this combo box inside here.
-
01:31:02 However, I think yeah, I think I will do a better job better approach.
-
01:31:08 Okay, let's say Main and Forum will be simply.
-
01:31:16 I've been I called this method I will call it like this up in it that's in it up and
-
01:31:29 it will take this, okay?
-
01:31:31 So you can use either method you can aiders reference it or you can provide reference
-
01:31:36 like this.
-
01:31:37 It is up to you.
-
01:31:38 I think we can reference it like this, but we can keep other way as well.
-
01:31:43 So let's keep both of them.
-
01:31:45 Okay, and now when we run the application we should see as expected.
-
01:31:52 You see how clean our code is looking this is the proper way of
-
01:31:58 coding
-
01:31:59 Okay, so it says please pick a user type patients or medical doctors.
-
01:32:10 And you can pick any type and then that will be other things.
-
01:32:16 So now we need to take also main window as well.
-
01:32:25 Maybe as reference.
-
01:32:28 So this is just simply passing the reference of main means of instance.
-
01:32:34 Okay, and here we are going to use using content EMS context.
-
01:32:46 Okay, simply we are going to set value is and then add record.
-
01:32:55 Okay.
-
01:32:56 So how we gonna do it is one text Dot TV and users that at okay.
-
01:33:04 So two before doing that we will compose a tibia.
-
01:33:09 Users my users.
-
01:33:10 Stevia users my users Dot and the first name will be equal to
-
01:33:20 I mean, that's tasty first name, by the way, if you need checks, then you need to do it
-
01:33:29 also will be equal to main dot txt.
-
01:33:32 Last name the text.
-
01:33:35 Of course.
-
01:33:40 And then I also need to have my SSA 206.
-
01:33:51 And we are going to also make it salted.
-
01:33:54 Okay, it is important.
-
01:33:56 To make it salted and how can we make it salted by the way, so I bet you wonder what is salted?
-
01:34:06 Only see how Chic so you see when you save your passwords as I say 206 it is not enough
-
01:34:21 because there are rainbow tables and with that way hacker still can solve a lot of passwords.
-
01:34:30 However, when you salt your hash then you can never fail, okay.
-
01:34:39 So it is best to salt.
-
01:34:43 I use a password for each user.
-
01:34:52 And so how can we do it simply let's say
-
01:34:58 Yeah, let's if you're not going to let users to change their name done.
-
01:35:07 We can use their first name as a salt.
-
01:35:11 It makes sense.
-
01:35:14 So first, we need to check of course if the that or passwords pv1.
-
01:35:23 I mean for example moment.
-
01:35:34 This is simple check I'm doing.
-
01:35:42 Okay, so then I have to display a message box show.
-
01:35:48 Okay, you say I am not able to access message box inside here?
-
01:36:01 And you can see but with reference.
-
01:36:02 I wonder if he can yeah, I think we can show okay and let passwords not matching, please
-
01:36:16 type.
-
01:36:18 passwords
-
01:36:20 Okay, then we will simply return from the method not continue.
-
01:36:35 Okay, then we are going to compose our salted password.
-
01:36:44 So
-
01:36:45 this is our sha-256 function.
-
01:36:49 So let's
-
01:36:57 Add another class as Global methods.
-
01:37:03 Okay.
-
01:37:06 Probably static unless something like this.
-
01:37:18 Why do I will make this as an extension?
-
01:37:25 So it will be an extension to call it is ready.
-
01:37:28 And so basically I will use.
-
01:37:38 Another thing.
-
01:37:39 So let's say let's add another method.
-
01:37:45 Yeah, so this will take sink as I'll use PV and string users.
-
01:37:53 First name by they be don't need this to be public and private and this will return compute
-
01:38:08 a solution of 6, okay.
-
01:38:13 so let's up and it as something like this and add some character here and
-
01:38:24 So you see we will not simply get the password of users get the hash it out put of the user
-
01:38:36 password.
-
01:38:37 So we are going to make it unique and
-
01:38:44 With this way.
-
01:38:48 No remove tables will be useful.
-
01:39:05 This is the proper way of.
-
01:39:10 Password keeping therefore you should use it all so you can look for what is salted
-
01:39:16 password.
-
01:39:17 There are all you see lots of information.
-
01:39:19 I won't get into them right now however bottle but there is one key issue with these when
-
01:39:28 you check user password, then you have to apply same rule.
-
01:39:32 So first you need to get first name of the user from database then you need
-
01:39:39 So add that to user entered password and compared it whether it's matching or not.
-
01:39:45 So it is an extra time consuming thing.
-
01:39:49 However, this greatly increases your password security.
-
01:39:54 Even your database gets Hackett hackers cannot ever obtain your passwords.
-
01:40:01 Okay, it's practically it practically makes it impossible to decode passwords.
-
01:40:09 Okay, so when is our?
-
01:40:18 They just got here.
-
01:40:21 Okay, then we will get the user password as this one.
-
01:40:29 Okay PV equal to Global methods that return user PV and it will take my users start first
-
01:40:42 name.
-
01:40:44 and password Here
-
01:40:47 We Came in txt pv1 text or not password.
-
01:41:01 citizens
-
01:41:03 Okay, okay.
-
01:41:06 And then what else we are going to take we are going to get user rank.
-
01:41:11 Okay.
-
01:41:12 So we also need to check that if combo box.
-
01:41:18 So it is from Maine and combo box selected index is equal to zero or less say lesser
-
01:41:27 than 1
-
01:41:29 Then we will show an error.
-
01:41:32 Okay, please let's say errors.
-
01:41:38 Please select your user drunk roll first.
-
01:41:47 And return then we will set the user type is equal to so you see this is the tricky
-
01:42:00 part or the beautiful part CMB box with drunk selected item dot or essay.
-
01:42:09 Yes selected item.
-
01:42:14 However, I am going to make an explicit conversation as user types.
-
01:42:23 like this and then it will be
-
01:42:27 just not on this is not the way so.
-
01:42:32 Let's make it as as.
-
01:42:36 user types and then
-
01:42:43 thoughts
-
01:42:47 the type of yes, so you see when you bind a class or a list of items to a combo box
-
01:42:59 or another thing then you can keep all of the features of that class.
-
01:43:04 So now with this approach I can get the user type value of selected user type.
-
01:43:14 And what other bodies do we have?
-
01:43:15 Okay, we have type navigation.
-
01:43:18 Okay, we won't use this.
-
01:43:20 I don't know why it has generated that we have email and it will be
-
01:43:27 okay main dot txt email text and what other volume we need first.
-
01:43:38 We must have registered a tit register date is automatic IP.
-
01:43:43 We need to provide some IP.
-
01:43:46 So I will just provide some fake IP right now.
-
01:43:49 okay, something like this and
-
01:43:55 Okay, TBL tradesman's patient users.
-
01:44:00 Okay, we don't need oh, oh, I see why these are existing.
-
01:44:07 These are existing because they are foreign Keys.
-
01:44:11 Therefore I will just pass them and I don't know if they should be visible here.
-
01:44:19 There is also a user type.
-
01:44:23 So this is user type.
-
01:44:26 Yeah.
-
01:44:27 Okay.
-
01:44:28 Okay, everything is set.
-
01:44:29 Then we are going to add this into our context.
-
01:44:34 TV users add my users
-
01:44:40 then I need to save changes.
-
01:44:46 Okay.
-
01:44:47 So when you do this you need to you should try catch block because if an error happens,
-
01:44:54 then you can catch and display it.
-
01:44:58 Okay, and every word I say.
-
01:45:06 Let's put a new line.
-
01:45:14 So let's put errors.
-
01:45:20 Okay, I will make ever has.
-
01:45:31 last let's put some new lines and
-
01:45:34 If you need an exception available.
-
01:45:38 Stack trace or message?
-
01:45:43 Yeah, that's broad message.
-
01:45:48 Okay, otherwise, let's say
-
01:45:50 users has been success fully registered then you can you should reset the values as
-
01:46:04 A man that for example takes email something like this and Main dot takes a first name
-
01:46:14 I taste and such.
-
01:46:17 Okay.
-
01:46:18 So this is what you should do when someone registers you can visit or whatever you want
-
01:46:26 to the after which is search operations, okay?
-
01:46:32 So after this, you have to of course return for other message to not seen.
-
01:46:38 All right.
-
01:46:39 Let's see if all our software code is working or not.
-
01:46:43 Oh, did we call this?
-
01:46:45 Yes, we have colored it inside here and wonder friends and let's go there and we have to
-
01:46:52 provide our main window of reference here.
-
01:47:01 Okay, and let's see.
-
01:47:12 Okay, let's register.
-
01:47:15 Okay test 1 third name on as enters my Village name and she mail call passwords one passwords
-
01:47:29 one registers.
-
01:47:31 Yes.
-
01:47:32 It says please select your user drunk.
-
01:47:34 I will put another password Here.
-
01:47:38 And you say it is not matching 1 1 so a patient registers.
-
01:47:42 Yes.
-
01:47:43 It is working and these values are deleted and let's see.
-
01:47:49 Yes, it is here exactly working as we want.
-
01:47:54 Let's register another one.
-
01:47:55 So I will use the same name same image.
-
01:47:58 So let's see if error happens.
-
01:48:00 They just okay.
-
01:48:02 It says error an error has occurred while registering error is an error occurs while
-
01:48:06 obtaining the
-
01:48:07 Today's see the inner exception for details.
-
01:48:09 You see providing energy exception provides more details.
-
01:48:14 Therefore I have also posted on message cannot insert duplicate K. Robbin objective your
-
01:48:22 t-value users.
-
01:48:23 Okay, however, you wouldn't like to
-
01:48:27 Display and tie-in message to the client because you see it is the exposing our table name,
-
01:48:33 which is something that we wouldn't like.
-
01:48:36 Okay.
-
01:48:37 So if you should catch the error and say the user that user that this email is being used.
-
01:48:45 Okay not show the entire message.
-
01:48:49 Let's say
-
01:48:53 Never show the role of error message to the user because it can cause your system exposure
-
01:49:06 to the let's say.
-
01:49:14 Threats threats hackers, okay.
-
01:49:19 Okay, so it didn't work.
-
01:49:21 So let's add another one and let's change this.
-
01:49:25 Yes.
-
01:49:26 It is working when we do something like this.
-
01:49:30 You see please select your username.
-
01:49:32 Okay, everything is working.
-
01:49:33 Let's get one is yes, they are all here.
-
01:49:38 You see our unsuccessful registration.
-
01:49:40 Try also increases our user ID by one.
-
01:49:43 I don't know if that behavior can be prevented, but I haven't checked it by the way.
-
01:49:54 These are salted hashes.
-
01:49:56 So let's see.
-
01:49:57 Normally we have written only one as a password.
-
01:50:02 So where was that?
-
01:50:08 Sha 206 online.
-
01:50:13 So, let's see.
-
01:50:18 Okay, so these are not matching.
-
01:50:21 However, if I if we follow our practice it will be this test one then we are adding this
-
01:50:33 string.
-
01:50:35 like this
-
01:50:39 Let's see if they are matching.
-
01:50:43 Yes, they are matching as you can see exactly as much in as you can see so this is what
-
01:50:49 it's about salting if you just simply use one.
-
01:50:52 This is probably already in rainbow tables.
-
01:50:57 Therefore they can easily solve that this hash matches the one however, if you use salting
-
01:51:04 then there is no possible way for them to automatically solve even easy password such
-
01:51:12 as one, okay?
-
01:51:13 This is the way it is.
-
01:51:16 All right, I think this lesson was awesome.
-
01:51:20 So let's record all of them as nodes.
-
01:51:27 Okay how to not write code in a window but compose proper classes to reduce complexity
-
01:51:41 of your main window of reading coat, okay.
-
01:51:48 Okay how to do this was a regular insert.
-
01:51:55 So the let's say.
-
01:52:00 salted password hashing
-
01:52:05 Okay how to do salted situation under six plus five, I think.
-
01:52:18 Okay, what else what else check how to bind custom let's say how to bind list of custom
-
01:52:31 class elements to Mambo.
-
01:52:34 Box and read the body of selected item of this custom glass.
-
01:52:49 Okay.
-
01:52:50 What else did he do?
-
01:52:56 Jake how to generate
-
01:53:01 in.net core application of existing database, okay.
-
01:53:25 No, Jaso.
-
01:53:32 I'm going to the range.
-
01:53:37 So let's close this Global methods.
-
01:53:45 Okay and register operations.
-
01:53:52 Okay.
-
01:53:55 Let's say how to insert.
-
01:54:10 Okay, you see how it is easy to save a record with this approach.
-
01:54:19 We could also achieve this with regulars of course regular our DB connection as well.
-
01:54:27 However, you can also use this.
-
01:54:31 It's perfectly fine.
-
01:54:32 You see I am using this using Clause.
-
01:54:34 It is really important because after this using class ended all of the
-
01:54:39 Objects here will be properly disposed of when you are working with database operations.
-
01:54:46 You should always use using Clause using scope.
-
01:54:53 It is really important.
-
01:54:55 Okay?
-
01:54:56 I think it is enough for this.
-
01:55:02 Today, okay how to program and register screen for and should management system.
-
01:55:15 Okay.
-
01:55:16 Okay.
-
01:55:17 This was a great lecture.
-
01:55:18 I will also put this database backup into our folder.
-
01:55:24 However, I suggest you to compose the database yourself from zero from scratch big to learn
-
01:55:35 it better.
-
01:55:36 To learn.
-
01:55:37 How do we do it?
-
01:55:39 Other way, otherwise you probably would have a lot of problems.
-
01:55:44 So I will put it inside CD B&P me as backup.
-
01:55:55 You can restore it.
-
01:55:56 Of course, if you have the latest version as I have so the versions have to be latest
-
01:56:03 or a perversion.
-
01:56:05 Okay, I will put this inside our
-
01:56:10 introduction problem lecture 6
-
01:56:18 here's okay.
-
01:56:19 Okay.
-
01:56:21 Let's upload our source code.
-
01:56:42 Bosch
-
01:56:47 Okay, everything uploaded to restore a database you come here and pick restore and then just
-
01:57:10 select device and pick from the folder.
-
01:57:13 That's it.
-
01:57:14 Okay, hopefully see you next week and of lecture 6
