Please see There are three data tables (Users, Roles and Controls) and two tables that create many-to-many relationships: Users To Roles and Controls To Roles. The Controls table represents a control on a form, and Controls To Roles is the heart of the control-based security approach; it represents the permissions of a given role for a given control on a given form, as is explained in detail below.The application may consist of any number of forms.
That’s it, otherwise all application forms and their controls (including user controls and custom controls) remain unchanged.
Begin by creating a new Windows Forms application in Visual Studio 2005 (or your favorite alternative tool).
Potential Client asks for basic demographic information as shown in figure 2: I’ve intentionally made these application forms crude and simple to allow us to focus on the control-based security rather than on the form design.
In any case, none of the data retrieved in these forms will be persisted, and I encourage you to create your own forms that more closely represent your own business needs.
In this article, I will review the approach I took, focusing on the nitty-gritty code used to make this work, and the challenges faced in creating such an application quickly (their budget for this was 4 days). There are many security schemes that have evolved over time, but the one which has proven most successful, at least in the Windows world, is that of Access Control Lists (ACLs) now most commonly referred to as Users and Roles.
This article takes you as far as saving the users, roles and the permissions those roles have for the various controls. The full source code for this article is available for download. We see this most cleanly and starkly implemented in ASP.
When the user clicks on Add New you’ll get the name from the text box and create the new record for the database and for the list box: When you add a user to a role (by clicking on the arrow key), you’ll make an entry in the Users To Roles table (adding the User ID and Role ID and then updating the Tree View (far right)).
To update the Tree View, you’ll retrieve the entries fro the database and iterate through the rows of the table crating a new parent node each time you come across a new user name (if the “Name” radio button is selected) or a new Role Name (if the Role radio button is pressed): Since our focus is on the controls-based security, I won’t go into more detail here, though as mentioned earlier, the complete source is available for you to download and try out.
Thus, we need only create a Windows form for adding users, adding roles and adding users to roles, and saving all of that to the database.
This is easily accomplished by creating the form shown in Figure 4: You will want to bind the list boxes to data sources tied to your data tables.
I have a data Grid View when I click on any row a form is opened to update the row data, but after ending updates the updating form is closed but the data Grid View data is not updated How can i do that ?