Main

C# Programming (Intermediate) - Lecture 9: Unique Constraints in Databases, Entity Framework Sorting

Join Discord For Help : https://bit.ly/CodeInNetDiscord. Lecture 9/14 of Advanced/Intermediate C# Programming. If I have been of assistance to you and you would like to show your support for my work, please consider becoming a patron on 🥰 https://www.patreon.com/SECourses Source code repository of this Course: https://github.com/FurkanGozukara/Introduction-to-Programming-2-2021 Playlist of C# #PROGRAMMING (Advanced/Intermediate) Full Course 👨‍💻 (FREE) - 2023: https://www.youtube.com/playlist?list=PLdCdTIJgqkdGHoXqOVInDRQ5WwYFmx27e In Lecture 9: * How to hide and display a tab according to the authority of the logged-in user * How to load a ready CSV dataset into the database with Entity Framework * How to utilize task.factory to prevent user interface freeze * How to update label from sub-threads, sub-tasks with dispatcher * How to add uniqueness constraint to a database table with defining a unique index * How to achieve unique adding to the database when using entity framework * How to add sorting feature to your datagrid display when using entity framework for automatic display, insert, update, delete * How to bind all elements of an enumeration to a combobox * How to display description of enum items in the combobox * How to get selected enumeration of itemssource bound combobox User Authorization-Based Tab Visibility One key aspect of an effective user interface design involves dynamically tailoring content according to the authority level of a logged-in user. This concept can be implemented using many different technologies. One approach could be hiding or displaying tabs according to the user's assigned roles or privileges. By doing so, we ensure that users only interact with the content and resources within their access rights. Implementing this approach would typically involve a blend of front-end and back-end development strategies, including user authentication, role-based authorization, and dynamic UI updates. Importing CSV Datasets into a Database with Entity Framework Entity Framework (EF) is a powerful Object-Relational Mapping (ORM) tool for .NET applications that abstracts the underlying database system, providing a simpler and more intuitive way to handle data. It can even be used to load CSV datasets into a database. The general process involves reading the CSV file, parsing the data, creating corresponding entities, and then using EF's DbContext and DbSet classes to save these entities into the database. UI Responsiveness: Task.Factory to the Rescue In modern application development, user experience plays a crucial role. A responsive UI, one that doesn't freeze or become unresponsive, is paramount. This is where Task.Factory comes in handy. By utilizing Task.Factory in .NET, long-running operations can be offloaded to a background thread, keeping the main UI thread free and responsive. Task.Factory creates and starts a task in one method call, returning a Task that can be monitored and interacted with. Thread-Safe UI Updates using Dispatcher Updating UI elements from non-UI threads can be a challenging task due to thread-safety issues. One common situation is when we have to update a label from a sub-thread or task. A technique commonly used in this scenario is a Dispatcher, which marshals the execution of a block of code to the UI thread, ensuring that UI elements are updated in a thread-safe manner. Enforcing Uniqueness: Adding Constraints and Unique Indexes In the world of databases, ensuring data integrity and avoiding duplication are often high on the priority list. One way to ensure that a field remains unique across all entries in a table is to define a unique index. A unique index acts as a constraint, preventing the insertion of duplicate values within the column(s) it covers. Unique Additions to the Database with Entity Framework Entity Framework (EF) makes data operations easier, but ensuring uniqueness during data insertion requires some additional steps. To maintain uniqueness while using EF, you'd generally check if an entity with the same unique attribute(s) exists before trying to insert a new one. This can be done using LINQ queries, which can seamlessly integrate with EF's DbContext to provide a smooth workflow. Adding Sorting Features to DataGrids with Entity Framework Data presentation is as crucial as data storage and retrieval. A feature often desired when displaying data in a DataGrid is sorting. With Entity Framework, you can easily implement automatic data display, insertion, update, and deletion. Adding a sorting feature can be achieved by handling the appropriate events and using LINQ to Entities to order the data according to the user's preferences. Binding Enumeration Elements to a ComboBox Enumerations, or Enums, are a powerful tool to represent a collection of related constants in a programming language. In many instances, you might need to display all elements of an enumeration in a ComboBox for user selection.

Code In NET

8 months ago

Hello dear students, welcome to the lecture 9 of introduction to programming 2 aka advanced programming today we will continue from our previous lecture. I will start with cloning our lecture 8 code as usual and meanwhile let's also open our sql server management studio. So if you are remembering we were building a patient management system at the previous lecture, we had built an interface to update, delete, or insert drugs with using fully autonomous entity framework. Okay, so let's rename thi
s to lecture 9. If you have any questions regarding to our course lectures, please ask them through me Discord channel so that I can answer them in the lecture video or in the Discord channel. You can ask me as you want. You can ask them through our Discord channel. Also, your feedback could help me to improve our lecture videos. Okay, so pms system in the pms system, what do we have? we have diseases, drugs, login. Try prescriptions, treatments, users, and user types. So so far I think we have
only coded drugs and login and user and user types. So let's run our application to verify that. Okay, so we have register form, we have user types, we have login and we have drugs. Okay first we are going to enable drugs screen for only. Let's say medical doctors and I want it fully hidden not only be visible but not clickable. So let's change its status. How am I going to do that? let's check our methods. Okay here we have top login, top register, and btn login. I'm going to write a method her
e as set drugs panel and this panel will do this. Let me show you. So where do we keep our logged in status? Okay, let's look from our method so we have login. Try login. Click okay here. So this is inside login operations and login operations is here. I think I will move this to here global methods in the login operations we keep logged in user here. So what am I going to do is I am going to set drugs panel status with if login operations, dot tbl or login user is not equal null. Okay actually
I can do this with a null check like this dot here. I should have user type okay in user types. What do we have? We have user type id and user type name right. So not equal to medical doctor. Okay two because this is id matching. If I remember correctly, user type is here. Yes, you see as you see it is id matching. So if it is not equal to we will set main dot top drugs visibility equal hidden hidden else. We are going to set it as wisdom. I also need to call this in two separate cases actually
three separate cases. Where do I need to set it change? I need to set it change in the init up here. Okay so this is up init cs. Actually this is also a custom class. Therefore I will put it here. Okay this will be as global methods dot set drugs panel actually let's rename this to a better name like set drugs panel visibility: yeah, now it will ask me to rename wherever it is linked and it's only linked in here so far. Okay, it's automatically renamed as you see and we are going to set it in. L
ogin operations login try actually change login status? yes, we can put it here. Yeah, now it should work. Let's retry to see whether it is working or not. So we will call that method when the application first run to hide that window. Yes, it is hidden. We will change it after login. So let's try patient one. Okay, page one, uh, email will be at patient one at gmail dot com. Whatever password will be one and user type will be patients registered and then okay, we are not automatically logged in
. We should automatically log in user after registration. Okay, so we are going to call our login operations login try login operations. It is inside custom classes. So let's add that using lecture six custom classes, you see lecture six is not changed. I mean the namespace. I could change it that you just need to control f namespace, lecture six, or actually lecture six because we don't have anything else as that name to lecture eight. If I do that with entire solution, everything will become l
ecture eight simply. However, it may break our application I am not sure we will see. I hope that it won't break because I didn't take any backup. Actually, this is lecture nine. Why did we change it to lecture six? Let's change it to lecture nine and see what happens. Let's check parties. Okay, it is lecture nine to nine. Yeah, everything's lecture nine. Maybe check the properties here. Okay, lecture nine okay, default namespace. I have to change that as well. And then let's see what happens. O
kay, so we have one error and okay, other errors. Okay, so we can't see lines here. So let's first enable that. It is in the text editor in here general or all languages. Okay here. Word drop and line numbers and in the lined. Okay, it is not here. So it is related to somewhere here. Probably okay. In here, we have cg. Proj. Let's open it. Yeah, here here, I have to change that to this. You see root namespace and then now it should progress. Run okay, so you see renaming the entire namespace is
a bit problematic. Therefore, it may cause you some trouble. Okay, we were doing registration and then automatic login. Let's continue to that here. We have added lecture nine custom classes. Now we will call our login operations dot login. Try you see login? try takes main window main and therefore I need something else here. Normally this is reading the values that is coming from txt, login, email text, and the password of the text box. So before I do that, I need to set main window values as
main dot txt login email equal to okay before I reset them, main dot txt email text and then I need to set password as well. So the password here. Okay, main dot txt login password equal to this. Okay, I can't set it like that, but maybe this can work. Yeah, then I will just pass the main here. Okay, now let's retry to register and see if it is automatically logged in or not. By the way, this operation will be done after displaying user user has been successfully registered. Okay and here. Patie
nt two two two at gmail.com one one and patients register. Okay, you see until I click. Okay, the application is not continuing. So this is the application blocking event and when I click, okay, it will continue. Okay, now we are. You have successfully logged in, but we don't have any other screen. Therefore, even though we are logged in, we don't see our drugs panel right now as we are supposed to. Also, we didn't clear the text or other things of the register. Let's also clear them: main dot p
assword txt okay, pv1 equal to nothing. Okay, let's change this to and txt last name. Actually, you should also set an identifier to make them displaying as a registration. What I mean is let me show you so in here. I will rename them and I am hoping that it will automatically rename everywhere. Txt first name or let's say register first name. It is renamed here, but I don't know if the references are renamed as well. No, no, it didn't rename so this didn't work. So if I rename here, will it tel
l me to rename anyway? That would be a more appropriate name. You can do that. It wouldn't take too much time by the way. Okay, so we are now able to register and when we register as a patient we don't see the drugs tab. So let's register with a doctor authority doctor one doctor, one doctor one at email.com one one and doctor register. Okay, register it. Okay, all fields are reset and now I can click drugs tab. When I click refresh it brings me drugs and let's add a drug 25 9. So you see when I
click somewhere else it will tell me there is new one but they are not saved yet. Let's save. Oh I see I shouldn't set drug id because it is set as an identity if I see it correctly. Therefore, I need to disable editing of drug id in the window so that user cannot enter or change the drug id. So let's see if it is the case. Yes, it is identity. Therefore, I have to disable edit of drug id and how am I going to do that? I am going to do that simply with here. So the header of the drug id will be
equal to simply drug id okay, and I will set it as edit change. Okay, let's see how do we do that. Cell style perhaps no. Can user view the resize clipboard content binding feather style. Okay, there is is read only and i'm going to set it as true so it will be only readable but not editable. Let's try again. Okay, I will login as doctor two. Let's see users. Doctor one: yeah, doctor one one okay, you have successfully logged in. Okay login parameters. We didn't reset them yet. So they are here
. Drugs refresh okay, so you see I am not able to click or change or enter anything there. I have to write it here. Okay, zero default. Whatever. I think it will be ignored. Eight and then save. Okay now it is saved and when I refresh you see they are here as expected and it is working great. Okay, after I log out, let's see if this drug window disappears. Yes, it is disappeared. But we are still on that window so we need to change back to login window. Okay, let's go to our logout button. It is
here after that. Actually, I will just okay set it here. Global methods: dot main dot login selected true. Once the user is logged out, we also need to check some other things. I mean in our application currently user can change values even if they are logged out because we are not doing a server side or background check in our logged in operations. Okay which is here. Let's move it to custom pluses as well. So in here I need to make a check. I need to check first is user logged in as a doctor.
So what I need to do is simply this okay public static boom is doctor logo in okay what this is going to do it. It will just check this if it is user type not to return false. Okay actually I need to check equal to two if it is equal to two. Because there can be other user types as well. We just need to allow for two. It will return true else it will return false. I need to check that if is a doctor logged in equal to false it will be hidden, else it will be true. You see, I am doing a method u
sing approach. Never a duplicate code. You also need to follow this practice in our logged in operation. First I need to check that if a doctor is logged in or not. So in global methods is a doctor logged in if it's equal false return. So I won't allow none other than doctor user to be able to view refresh or save changes so I will not allow them to either refresh or save the new data. Okay or the delete data. Okay, so for each of these methods I am checking is a doctor logged in so let's re-try
and see. Okay, let's log in. Okay, now I can click. I can refresh. I can change anything, say refresh or it's not says I need to click change refresh. Okay, so milligram. Okay, you see it is showing an error displaying why? Because we did set this as a small integer if I remember correctly and small integer can be maximum 32k. So if I make it like this, yes. Now working great. And when I log out now that screen is gone. And if I log in as a different user who is not a doctor who is a patient, I
won't have that drugs panel to see it and I can now log out. Okay, okay everything is working as we want. However, assume that there were hundreds of or thousands of drugs. What can we do in that case? Okay, so in your project, I also want you to fill your database with synthetic data so that you can show all of your features first, let's insert some synthetic data into our database to do that. Actually, i'm going to find the drug list. Typical drug list txt, some real database. Okay, there are
some data here. Submissions products? maybe here. See it. Okay, there is ml product. No, but there is no marketing name. Okay, there is pharma downloadable data. I could also generate some random names and milligrams. But let's have some real data because it is easy to find. I believe some pharmacological names. Okay, there is a csv data. I think I can open this as notepad plus plus, it's faster. So let's extract it here. That is causing time. So let's edit it with notepad plus plus. Okay, so t
here is some values. Milligram okay, okay, so maybe this is the name. Yes, so you see they are ending with their milligrams, not all of them. Okay, so there is. The milligrams are written in here. Okay, so I need to parse this data and add them to my database. So let's add some data to our database from this file. Okay, how am I going to do that? If you wonder in my drugs panel, there are some columns automatically generated which I don't want you see. When you are working like this, you can acc
identally generate. Let's add a button here and I will call it as load data into database. Okay, let's compose the event. Okay, it is ready right? not ready data here. It will tell me to compose a new method and I will do it here. Gets internal? yeah, fine. Where is our data located? Let's add this. Oh, it is 70 megabytes so it is pretty big. But if I add it to my project, it should be able to load into GitHub repository. So it's fine. Let's add that data into another folder as static data here.
Add an existing item, document or files here. Okay, I need to copy this data to debug folders otherwise it wouldn't work. So i'm going to set it as copy if newer. Let's run the application to see if copy it as expected or not. Now I see static data here. It's copied. Oh, we also have some problem in our okay yeah I i need to change this. Did we make the column with previously? I don't remember. I need to take copy of this button first. Then it was z. Yeah now it is working so that wasn't an unn
ecessary. That wasn't unnecessary. And then in the drag stop we are going to add our button button, pull it this so we can now code. What we are going to do is we are going to simply read values in this csv file so it will be understand data for each. I need to add using io put output operations here. We will read file, dot read lines. We don't need to read all of them at once. Therefore, and we are line. Okay, so what is the format? One two, three, four, five, seven, eight, nine, ten. Okay, the
tenth item is the drag name and that's all I need. So name equal to we are line dot, split the tenth item, then I am going to get its milligram. How am I gonna do that? I am going to split it into parts and I think I think I just need to extract the double values inside it. Yeah, so yeah I think we can do it like this. So equal to we are line dot split not we are line. We are for deadlines that count or length if contains or equal to yeah let's say equal to equal to milligram. Then I have the m
illigram as a previous value. So in here I am going to generate an instance of tbr drug here my drugs on this leave tbr drug and the tbr drug that does milligram. So our dose is set as small integer. Therefore if it is not an integers I would have a problem. Therefore I think I will make it like this equal to convert to int 32 walls I minus one. Okay it's expecting short therefore to int 16. Yeah and then break and the drug name will be set here. Okay okay so for faster insert I will insert data
for each 100 items. So for to be able to do that I will add a counter like this. It will start from one and it will get increased by one. I am going to also add a using pms context context equal to new context. Okay what we are going to do is we are going to add it to our context. But how if my drug dot dose milligram not equal to zero okay then my context dot tv l drugs dot add so it will say it says begins tracking the given entity and any others reachable entities that are not already being
tracked. So I will just simply add my drug. Okay and for 100 each item. Okay so if our country is equal or less person this I will just call save changes. However, currently this would freeze my application interface. Because we are not using any multi-threading we are blocking the main thread. Therefore until this operation is completed our screen will be frozen and let's see what happens. So let's log in as a doctor. Okay here let's start loading. Okay we have a problem. Yeah we have forgotten
to add static data folder name. It should be like yeah oh one moment I made mistake. Okay, I think the opposite would work as well. Okay okay so there are some inputs that doesn't match but it looks correct. Why? Okay, it was not able to convert this into an integer. So I think what i'm going to do is simply like this: we need to change our database. So we need to change this from small integer to document but with precision too. Yeah I think this is would be better. We can save them as double
as well but they come in precision too. Should be better. They come in precision too. Yeah I think I will make this as let's make this as 12. I don't think so that would be such milligram and maybe we can make it even. Let's save it and after we make same. Okay we need to change our references as well. So let's reverse engineer and okay so it will cause us some other type changes as well so that we could have. Okay, not this is not correct. Database is from my other leg. Okay, um I need to add a
new database. So let's first one moment get the server name. Okay, then it will be pms. Okay, okay everything's here. Okay, okay, this will be refreshed. Yes. So now drug milligram will be a type of let's see where it is. Let's go to the class. It will be type of decimum. Yes, you see decimum. Okay, so we are going to change our try parts into decimum and let's make it as the try and it will be decimum. Try parts and this is try. Yes, now it should work. Let's delete the older data. Okay, let's
try what happens now we should be able to hold milligrams correctly supposed to be okay and refresh. There is nothing. Let's load and let's see. Okay, they are getting loaded. As you can see, i'm pretty fast. You see there are also duplicate values. As you can see, I think we can prevent that. How could we prevent it? if I add a unique index? I wonder if that would cause an error. Yeah, probably that would. I don't know if entity framework would handle that or not. You see so many duplicate dru
gs, they are duplicate. Okay, it is working, but we are adding duplicate values. We want to prevent duplicate addition. To be able to do that, we can add a unique index. Okay, let's open an instance of secret server management. If you are not able to add a new index, just open a new instance. I don't know. Sometimes it is getting bugged or something. Unclustered index: okay, what we are going to do is we are going to add drug name and drug dose. So let's change the order. The order is important.
Why? Because the more identifying column should come first. So the milligram is not the most identifying one in here. The most identifying thing is the name. Then the milligram and this will be unique. Okay, so when I set it unique, it will throw me an error right now because there are duplicate values. Just you see, let me show you see, index failed because there are duplicate values to prevent it. I need to delete the existing values. Okay, and now it will be successful. However, now when I t
ry to add with the usual method, I think I will get errors. I am not sure if entity framework will handle that or not. So let's see. Oh, let's refresh our table. Maybe it will also take into consideration that index. I am not sure. Okay, let's make this comment out and let's go to tbl drugs. Okay, there is index and it is unique. Yeah, maybe it will consider this as well. I am not sure. Let's see you see it has index name of drug, name, name of those milligram. If it handles this I can say it is
awesome. It will make our job much easier. It will just sort out the duplicate values and let's load. I hope no error. Okay, we got an error. So you see we got inner exception. I wonder if there is an easier way. Okay, let's see if there is any easier way. Okay, there is add or update and it says add or update here. Maybe that would work at or I think it may be requiring another reference. Let's see it is requiring this and the migrations and then I edit okay, Microsoft and framework. Or we are
using this. So there is update and there is add or update. Let's see if update works or not. Yeah, there is update. Okay. Begins tracking the given entity and entries reachable from the given entity using the state modified set by default. But see below for cases. And of course let's see. I'm not sure if this would work or not so I will just delete the existing drugs and retry. Okay, and let's just run. So update didn't work. Yeah, probably our mass insert will not work if we follow this. But w
hat we can do is alternatively for each item instead of the counter, we can save changes at each row. That should remove our problem because after each row save it will just check the database. I believe. I'm not sure. Let's try it. So if it exists it will update. If it's not, it will insert but this will be probably slower. I am sure there can be a way to make it faster. Like we can keep the local cage of all drugs and then load them later. Oh I see update is not working because it is also chec
king primary id. Yeah, because their primary id is different, it didn't work. So what else we need to do? Okay, looks like there is no easier way so we need to check that whether it exists or not. Okay find users primary k therefore I need to look for select. Yeah here that equal to this will return something. Okay now this will become bull. Why? okay, so if this is empty no we will add and then okay with this approach. I think this should work. I'm not sure it's right. So this should also use t
he local cage as well. However, each time it will make a database query too. If it is not in the local cage I don't know how much performance it have. Why we are doing interesting. This is interesting why I think we need to use where not select. Yes I know the reason where. Now it will return a drug and if it is not new yeah now it should work fine. Where and select makes difference in the entity framework. Thank you. Why? Why do we still get errors? ah, I know because this is not checking the l
ocal cage. Probably. I think I also need to check local and and then if okay i'm going to make another check here. This time I will check local. I'm not sure it will work or not. Try first. We will check database, then we will check the local. Actually I can handle local myself too. Yeah, be even faster. If this doesn't work, I will do that. Okay, looks like working. Let's see how many drugs we have added so far. Okay, you see now we are adding much slower but each one is unique. As you see, we
are even able to add lower milligrams like this. Okay, we are adding so much drugs. But you see our interface is completely frozen and I am going to show you how we can fix it. You see, this is frozen. This is frozen. Everywhere is frozen because currently this thread is running under the main thread, under the main window thread. Therefore, it is blocking the entire thread until it is completed. Therefore, my user interface is completely frozen. Okay, so now I will show you that. Okay, we are g
oing to use task factory to start as a new task. Update our interface. We have done that before, but it will be good to remember again. Open that tab here. Let's add a oh, we already have a label so we can use that here. Yeah, I think I can encapsulate within a task like task that factory start new. Okay, it will be okay. So here our parentheses begin. Here it ends. Oh, we already. We need to move this to here. Okay, so this is self encapsulating task. Now to be able to update our label, we also
need to change how this work. As with like this. Okay, here I need is okay. What do I need we need dispatchers begin invoke your action and inside here what do we have? we have delegates. Maybe it was like this. Okay one moment oh so action is self encapsulated like this and then actually it is telling that this is an action. It is like this. So this is simply same as dispatcher. But here we are putting this to exclusively tell the compiler that this is an action and we will just put this insid
e here. Okay so now this will support multi-trading as well threads as well in our task factory. What we are going to do is we are going to update the label as I think we can update the label as with 100 changes so far. Inserted drugs count? perhaps. Yeah, I will make it like this so we won't get increase of the counter if you are not adding it. Continue will continue this loop. Yes, okay and let's add. Okay now let's see. Let's delete all existing drugs although we increase the counter somewher
e, I have to increase it actually here. Not that let's stop and let's make it like this. Okay, let's log in with our users. Let's go to drugs refresh. It's nothing. Let's load. You see interface didn't freeze and usually how fast we are inserting into database. Then we select count star room pbl drugs okay let's see. Oh this counter and this is not matching as you can see. So we have an error somewhere. Where do we have error? simply okay, we have counter we only count. Oh I know. So if this is
not null we also need to continue. I see I think I can fix this so this is too much increasing. How to fix is simply. Let's define a bool here. False and we will set it through here and then okay. If okay we are added then continue. Now it should work better. Okay and let's restart the application. Okay okay let's log in and let's start loading. Okay so you see it is now much slower and probably totally correct. Okay, as you can see yes you see there is a one difference because we have started t
he counter from one instead of zero. This is how we are adding the database. This can be speed up with tuning such as we also keep all drugs in the memory and we do a faster check rather than sequel checking. But it should work really fast as well right now. Okay so I am going to stop the application now. We have so many drugs when we load. We were limiting it to 100 as here because if we take 100 000 drugs into the screen, that would make our application unusable. So when I load refresh, you se
e there are so many drugs like this. Yeah, we can make it like this. We see their ids, we see their milligram doses. Yeah, however, let's say I want to see drugs that have over 10 milligram dose. How can I do that? I need to add sorting and filtering. So how am I gonna do it? meanwhile I am doing it. I will load more data into the database. So how am I going to do that? I will just delete this copy and paste this so I can work you see in your project I am expecting same from you. You should have
a lot of data in your database to display your application, not just few data. You can generate synthetic data or find a data from internet. Close this. Okay currently of course it is causing a slowness in my computer, but it is fine. So we need to add filtering options. Let's start adding them first. We should add some sorting such as sort by milligram or sort by name. We can do each of them. So let's add two sorting options so we will support both of them to do that. We are going to add combo
box and I will do it with let's say values and naming. I mean I will bind it to a class list. I will show you. So let's make this like this and make it like this so I will add it into the init. I think we can define a class here. Public class sorting options. Okay, what it is going to have. It will have elimination. Which sorting? I will name it like that. So it will have sort by drug name scanning, sort by drug name standing, third by milligram or dose drug dose ascending, sort by drug dose st
anding. We can also add a sorting with id, sort by id, ascending, sort by drug. Id is changing and then it will have another value. This doesn't have to be inside it, but let's keep it inside it. Here, it will work. It is going to have two property. First one will be which sorting as which option or sort option and then it will have another property. Okay, it's saying constant accessibility property. Yeah, this has to be public as well so that it can be public. Then public strings are a new name
. So here let's see why it is not working. Okay, we add annotations. Okay, since we can set enumeration as well. I think we don't even need this class and display will be sort by. Okay, why do we have a problem with this? Okay, let's see auto generated field auto generated filter description group name name. Yeah, I need name equal to okay. Sort by drug name standing okay, sort by drug name ascending yeah. Now let's set enumeration to other ones standing. And uh, sort by drug those outstanding.
Okay, the rock those standing. These annotations are extremely useful. You can use it for simply anything. And the rock was descending and drug id id scanning and the rock. I did this channel so this will be the display name. We are adding rocks, but they are getting slower due to our unoptimized queries, so we need to optimize our query. So it has become too slow due to our both cage querying and database querying. I believe we may be at the end of our ram memory. Yeah, pretty much okay. Okay,
I could do a lot of optimization prevent it to be like this, but that is not our topic at the moment. Maybe I can do it at the end of the lecture. So I will just let it be like this. We could have also an error thrown so it's not working anymore, but i'm not sure. Okay, let's continue. So what we are going to do is we are going to have a list of enumeration and bind it to our combo box. So how we're gonna do that? okay, so this first combo box will be. I will just sort it with a single option. Y
ou could also do it with multiple options as well, but it is not necessary to show right now. Combo box okay cmb sorting drugs okay so this will have okay something like this in our occasion in it means cmb sorting drugs item source will be equal to neve list I think. Okay, I have these numerations so in here we will have them like this. Or yeah, let me check something. Let's see if this is possible. Okay so it is possible like this. Okay and enum get values, type of which sorting. Let's see how
will it be displayed. Okay and let's close it. We have enough number of items. Fine so probably an error happened and since it was running in the threat mode we didn't see it. Okay so here let's refresh and let's see. Okay so currently it is displaying their value. However I need to display their display name. Let's see what will this generate. But okay this will be value member. There is no value member okay type convert and then let's ask it in another way. Let's add a public class. I will go
with the easier solution and sorting options. I will name it as here it will have sorting option by the way it will have an enumeration this which sort we can name it as then it will have a public string description and I will make it automated. Let me show you so here we are going to have a list of sorting options as options, private void, init sorting options and inside. Here we are going to get enumeration. Okay for this we need reflection and model. Yeah so here we will use description inst
ead of name. Still not that easy but easier to understand. And here we are going to have a for each. First this will be published or vibes and not initialize this. Then we will cause and here what we are going to do is we will add new elements to our list. New sorting option item. Okay here we will have description. So the description will be string value of sort. Which sort will be equal to I think just sort support like this. Okay and we need to call this on our init application. Here we will
set item source equal to our list here and the display member path will be equal to our description. Okay, like I think other solutions were harder to understand. So we just added a one helper method like this method like this to initialize our list automatically from our enumeration. Okay oh still not working. Why? We just set the display member path as our description. Maybe they are not working. Let's restart to see. Yeah yeah our method has a problem. So here we have a problem. It is looking
for description attributes. We already have description. So what is not working? Oh I see not display but description. So it has to be like this. Yeah, let's make it like that description: equal or no. No, you can see i'm working. We will place this all right. Let's start. I would expect it would be easy to just bind it to description but it appears that there is no easier way. So we had to have some coding and now working. Okay so now time to code our sortings. How we're gonna do it. We are go
ing to do it it in our login operations and in here. So you see we are going to call this method but this time we will take into our sorting. Okay so we are going to have a switch and this switch will take global dot, global methods dot main dot, combo box, user sorting, drugs. Okay maybe it will auto generate. Let's rest, let's try to generate it switch so complete. No didn't work. Okay so which cases we have here actually I need to use selected item here now it should work automatically. Try s
elected item dot no selected item and I have to convert it to 13. What was our elimination name that's named as again it changed here this okay to be able to use it. I am going to add using static lecture in it here now that I can use it now it should automatically generate I think switch. Okay they are automatically filled as you see now based on the selected option I will use it. So this is the default option. A scanning order. You see. Now let's sort the descending. Okay, descending here. Let
's sort by name so it will simply take name scanning: we are going to sort by standing and then let's sort by those you see. It is being harder when you use entity framework. Could make this much easier with traditional database functions methods. But it also has downsides. This also has downsides so you have to decide. Okay, so we also need something else for this to work. What do we need when combo box is changed? We need to call our refresh method so it will be automatically getting refresh i
t. So let's go to here and here. We are going to add an event here. Say selection changes. Where is it here? I double click. When is simply generated. It will just simply call this method. You see how it is good to write methods instead of copy pasting code. It just reduces your code, reduces the need of writing more codes. Okay, let's log in. Let's refresh. Do we have a problem? oh okay. So we also need something. If there is nothing selected, it would cause error. Therefore, we are going to de
lete the application with a selected option. So zero, one, two, three, four the four is our default. Therefore, we are going to set selected index equal to four. So this will be default selected index. It will be same as the previous working say it will be by default sort by id ascending you see sort by ascending refresh. Okay, we have selected unable to cast object type sorting option. Why why yeah, there is which sort. Oh, I see, I need to get this. However, I am not able to get interesting se
lected item so this is object. Oh I know the reason I know the reason. First I need to type this into our class here which is sorting option and then I need to get okay. I need to add another parenthesis here and then I need to get which sort. Now it will work. So we will cast it first the type of the class that this list is holding, which list the list we bound as an item source to our combo box because that list contains a type of sorting option objects: okay, let's log in refresh: okay, they
are working and sorted by id. Let's change sorting to drug name. Okay, you see drug name descending order and it is starting from letter z. Let's sort by those you see there are up to 8400 milligrams those it is milk tassel as a drug I think this is supplementary thing if I remember correctly. And there is kava ginger garlic. Yeah, garlic is also the garlic we know. Okay, maybe you can. Oh, this also sorts, but this is locally sorting. This is not sorting the entire database, this is sorting wit
hin the results. For example, if I make it ascending here, you see it is going as low as 0.02 milligram. It is ethanol estradiol. Yes, it is working great as expected. We can sort them automatically within their displayed results. I will also show searching filtering in the next week. Let's take our notes. Okay, let's open. Okay here here. Did we take in a next? Okay, yeah, we did that. Nice. Let's open. Lecture nine: context: so in lecture nine: what have we done? Okay, how to hide and display
a tab according to the authority of the logged in user. How to how to bind all elements of an enumeration to a combo box box display description: get selected: enumeration of first bond combo box: okay, so we had to write this method to get the value or description of the enumeration. We also had to write this to add all values of enumeration dynamically. So whatever I add here, I don't need to change any other code. It will be fully automatic. Of course I would need to change the sorting option
s and to be used is no, we don't use this. Let's remove this because it may get you confused. Okay, let's test it again. Okay, I will also get a new backup of the database so you can use it. That's did we do logged in operations. Okay, let's log in. So inserting the database was really slow, right? so I am going to make an optimization. What kind of optimization I am going to make you wonder? let me show you. Of course this would require some extra ram memory, but should work because our values
are not that much big. Not that big. So let me show you the optimization. First, I will load to cage. How am I going to do that? So this will load everything into the cage? I think yeah. Then first I will check cage. Then I will check the database. Actually, I don't need even to check database. Okay, let's remove this because we are full local caging. Let's see. So it should load everything into database right here. Let's see how much ram it will increase. I mean it should load everything in the
database to the ram here. Then we don't even need to check the database anymore. They will be in the local or not, so it will be pretty fast. Of course it will require more ram memory. If you had millions of items, you can do that. Okay, let's see. We are at the okay 700 megabyte. Okay, we can see we have got 120 megabyte. Okay, it didn't even increase anything. I don't know if it worked. Okay, let's go to this part. Jump and oh, it was zero. So let's go here. For example. So there is 200 milli
gram. It is probably existing the database already. Okay, it wasn't null because it did get it from the local cage. So let's see the speed of our algorithm. Okay, it is still very slow. Oh, I know the reason because it is now first parsing the first records above 3000, then it will start adding them. Currently, it is parsing so we can actually display two indexes. Let's do that. Okay, so let's add edit counters, rename it, and then add process it counters. Okay, so for processing it will get inc
reased each time and process like this. Let's display it here as well. Okay, drag this so we need to change it to here. But if it is not, edit, we do continue. Oh, I see. So I also need to change this and change this as well. Here and remove this. Let's see how fast we will process records. Login see okay, so we are processing with this speed. This file has so many. Okay, so this shouldn't have happened because when we edit it should get into local. Okay, how many did three? interesting. So prob
ably this is not getting into local cage. I also need to add this to local cage. Perhaps see if this will work. Can we add to local? Okay and set this at zero as well. Let's see what happened. I am not sure if this will work, but it should work because first we are loading everything into the memory, then we are adding them to local and meanwhile I will look something else too. Chrome. Okay, entity frame versus okay. So yeah, it is not working. I wonder why? okay, there are 3498 member test some
thing. Let's put a break point here. Okay I think I will leave this to solve next week. So meanwhile you can work on that until next week and maybe you can figure out figure it out before me so it will be also a nice working for you. So we have in the local. Okay 3498. Okay let's see the local. Oh I think I may know the reason. So in here so this is its name. Maybe there is case sensitivity problem. Oh no this doesn't exist yet. Okay let's continue but it throws an error why there is no such rec
ord like this says that there is kids key. Yeah this is related to database itself so I will do a like query. See okay I see it already exists like this. So where is this difference coming from? So when I look for it like this see if it will come I copy pasted it. It doesn't come. Do you think? Why? Why do you think? But when I search like this I see it is here here as you see. Ah because these drug names are encapsulated with yeah I know the reason because we didn't remove this so I need to sea
rch them like this when I search it like this. Yeah it is here. Let's see the features of this one. Okay let's restart what may be causing this error? let's see 0.125 do we have that? yes we have it. But this one has different. So drug name and dos. Okay, and when we go here, we only have one drug edit. Yeah, and when we save it, it is not working. Why is that happening? When we see the encrypt, it takes drug name and dos milligram so something is not right here. Oh, I know the reason. Okay, I h
ave figured out the reason. I will leave it to you and I want you to find it. Okay, so let's take some notes next week show why is producing an unhandled error at searching feature. Okay, I want you to find out the reason I have found it. So I will take a backup of the database and add it to our source code as well so I will be able to use it exactly as me. Okay, let's go to our temporary folder and no, not this one. Okay, db folder here. Let's remove pms. Okay, ms backup: let's copy and paste t
his into our source code. Lecture nine here. Okay, let's push to this area. Okay, okay, it says it is larger but it is accepted. I think let's check our repository to verify. Okay, let's open our repositories. Okay, it's updated. Lectures here, lecture nine and inside our stick data. Okay, everything is working and thank you very much for watching. Hope we'll see you next week! end of lecture nine.

Comments

@efesametaltinbas9170

Efe Samet Altınbaş 225060045 00:02 Introduction. 00:19 Discussing Previous Video. 3:14 Implementing setDrugsPanel Method. 7:48 Executing Application. 10:03 Addressing Error Issues. 13:36 Accessing Drugs as a Doctor. 21:42 Running the Program. 21:54 Resolving Error Problems. 25:34 Encounter Error Situations. 26:37 Seeking Solutions on Stack Overflow. 29:16 Modifying Local Cage. 37:16 Implementing Data Annotations. 38:51 Binding ComboBox. 44:22 Populating Sort Case. 47:12 Testing the Code. 49:37 Inserting into Database. 53:22 Error Resolution.

@gorkemgucluefe1408

Hayri Görkem Güçlüefe 215060016 0:00 Start 0:27 remembering the previous Lecture. 3:22 Setting setDrugsPanel 7:54 Testing the program. 10:05 fixing the bugs 13:35 only doctors see the drugs 16:54 Adding a button for load to data 21:46 testing the app 22:16 fixing errors 37:23 adding data annotations 47:15 testing the application 53:27 fixing errors 56:20 end of the lesson.

@volkanaykut5494

Volkan Aykut 215060021 00:00 Intro 00:18 Talking about previous video 3:15 Setting setDrugsPanel method 7:49 Running application 10:05 Fixing the errors 13:39 You can see drugs if u are a doctor 21:45 Running the program 21:57 Fixing errors 25:37 Getting some errors 26:39 Searching on the stackoverflow 29:19 Changing local cage 37:18 Adding dataannotations 38:54 Binding ComboBox 44:25 Filling Sort Case 47:15 Running the Code 49:40 Inserting Database 53:25 Fixing some errors

@v1nce99

Mehmet Deniz Can 225060053 0:00 Intro (Lecture 9) 0:20 Remembering what we did last lesson and what we are planning to do 3:40 Setting drugs in Init 7:50 Running application and try to see if it can automatically logins 10:05 Fixing errors 13:35 Making drugs for doctors to see only 16:50 Adding a button to load the data into database 21:45 Testing the application 22:15 Fixing input errors 26:40 Trying to find solutions online 37:20 Adding Data Annotations 44:25 Sorting the code and filling Sorting Cases 47:15 Testing the application 48:30 Topics of the video 56:20 Outro

@ayael-mir6085

Aya El Mir 225060046 00:20 Reminding us about what the project is about 3:47 Setting the drugs innn the AppInit folder 7:51 Testing the running of the application. 10:03 Addressing and fixin Error Issues. 13:36 Drugs be accessible only for doctors. 21:42 Running and testing the Program again. 21:54 Resolving Error Problems. 25:34 Solving Error Situations online. 26:37 Seeking Solutions from Stack Overflow. 29:16 Modifying Local Cage. 37:16 Adding Data Annotations. 38:51 Binding ComboBox. 44:26 Sorting coding part and filling the sort cases. 47:12 Testing the Code. 49:37 Inserting into Database. 53:22 Error Resolution.

@efsan9480

215060006 Nurefşan Biçici 0:00 Intro 0:18 Previous Lecture. 3:40 Setting SetDrugsPanel Methods. 7:48 Testing the Application if it can automatically login. 10:05 Fixing errors 13:35 Letting the drugs only visible 15:10 Implement synthetic data into our database. 16:49 Adding a button for load data into database. 21:44 Testing the Application. 22:12 Fixing errors. 24:40 Adding a unique index to prevent duplicate addition. 26:40 Finding solutions online. 37:20 Adding Data Annotations. 44:26 Sorting coding part 47:16 Testing the Application. 56:20 Outro.

@emirturkoglu6752

abdulbaki emir türkoğlu 225060028 0:19 What we did in past address 2:32 What we are planning to do 3:41 Setting drugs in init as well 7:46 Running application to see on the off chance that application naturally logs in 10:07 Settling blunders 13:36 Making drugs as it were obvious to specialists 15:11 Actualizing manufactured information into our database 21:45 Testing the application 22:13 Settling inputs that doesnt coordinate 26:42 Finding arrangements online 37:21 Including DataAnnotations 44:25 Consequently filling sorting cases 47:14 Testing the app 53:32 Looking why including local cage isn't working 55:09 We are going learn was the reason following week

@josephtraboulsy4805

Joseph Traboulsi 225060004 0:00 Intro to the Lecture 9. 0:18 Recap of the previous Lecture. 3:40 Setting SetDrugsPanel Methods. 7:50 Testing the Application if it can automatically login. 10:05 Disable editing of drugs in the window. 13:35 Letting the drugs only visible to doctors. 15:10 Implementing synthetic data into our database. 16:49 Adding a button for load data into database. 21:44 Testing the Application. 22:12 Fixing ERRORS (inputs). 24:40 Adding a unique index to prevent duplicate addition. 26:40 Searching for solutions online. 37:20 Adding Data Annotations. 44:26 Sorting coding part and filling the sort cases. 47:16 Testing the Application. 48:30 Topics of the video. 56:20 Outro.

@fratmugdatoglu9223

Fırat Muğdatoğlu 225060058 0:00 - Intro 1:35 - Medical doctors and I want it fully hidden not only be visible but not clickable.How can we do this? 4:43 - We should automatically log in user after registration. 5:12 - If I do that with entire solution,everything will become lecture eight simply. 7:34 - Now let's try to register and see if it is automatically logged in or not. 8:05 - You have successfully logged in, but we don't have any other screen. Therefore, even though we are logged in, we don't see our drugs panel right now as we are supposed to. Also, we didn't clear the text or other things of the register. 9:42 - All fields are reset and now I can click drugs tab. 10:05 - I need to disable editing of drugs in the window so that user cannot enter or change the drug id. 11:44 - After I log out, let's see if this drug window disappears. 12:15 - In our application currently user can change values even if they are logged out because we are not doing a server side or background check in our logged in operations. 12:34 - I need to check first is user logged in as a doctor. 14:19 - Do you see that it shows an error indicating why? Because we set this as a small integer, and the small integer can be a maximum of 32k. 14:50 - Assume that there were hundreds of or thousands of drugs. What can we do in that case? 16:49 - Add a button here and I will call it as load data into database. 17:34 - I need to copy this data to debug folders otherwise it wouldn't work. 18:53 - So name equal to we are line dot, split the tenth item, then I am going to get its milligram. How am I gonna do that? 21:29 - Currently this would freeze my application interface. Because we are not using any multi-threading we are blocking the main thread. 24:40 - We want to prevent duplicate addition. To be able to do that, we can add a unique index. 25:28 - Index failed because there are duplicate values to prevent it. I need to delete the existing values. 29:17 - Why do we still get errors? Because this is not checking the local cage. 30:14 - Everywhere is frozen because currently this thread is running under the main thread, under the main window thread. Therefore,it is blocking the entire thread until it is completed. 31:11 - Now to be able to update our label, we also need to change how this work. 33:00 - This counter and this is not matching as you can see. 34:43 - I want to see drugs that have over 10 milligram dose. How can I do that? 38:12 - We are adding rocks, but they are getting slower due to our unoptimized queries, so we need to optimize our query. 38:54 - What we are going to do is we are going to have a list of enumeration and bind it to your combobox. So how we're gonna do that? 43:12 - Now time to code our sortings. How we're gonna do it. 46:41 - First I need to type this into our class here which is sorting option and then I need to get okay. 47:59 - We can sort them automatically within their displayed results. I will also show searching filtering in the next week. 48:32 - Topics we covered in the video. 49:40 - Inserting the database was really slow.So I am going to make an optimization 56:20 - Outro.

@fv4202x

Berke Uğur Öner 225060025 0:18 What we did in previous lecture 2:30 What we are going to do 3:40 Setting drugs in init too 7:48 Running application to see if application automatically logs in 10:06 Fixing errors 13:35 Making drugs only visible to doctors 15:10 Implementing synthetic data into our database 21:46 Testing our application 22:12 Fixing inputs that doesnt match 26:40 Finding solutions online 37:20 Adding DataAnnotations 44:26 Automatically filling sorting cases 47:16 Testing our application 53:30 Searching why adding local cage is not working 55:08 We will learn was the reason next week

@user-qb9jr9hj1t

Joseph Traboulsi 225060004 0:00 Intro to the Lecture 9. 0:18 Recap of the previous Lecture. 3:40 Setting SetDrugsPanel Methods. 7:50 Testing the Application if it can automatically login. 10:05 Disable editing of drugs in the window. 13:35 Letting the drugs only visible to doctors. 15:10 Implementing synthetic data into our database. 16:49 Adding a button for load data into database. 21:44 Testing the Application. 22:12 Fixing ERRORS (inputs). 24:40 Adding a unique index to prevent duplicate addition. 26:40 Searching for solutions online. 37:20 Adding Data Annotations. 44:26 Sorting coding part and filling the sort cases. 47:16 Testing the Application. 48:30 Topics of the video. 56:20 Outro.