Start-to-Finish Visual C# 2015 by Tim Patrick
Author:Tim Patrick
Language: eng
Format: epub
Publisher: Owani Press
Published: 2016-09-01T07:00:00+00:00
Figure 11-2. The official Library Project administrative login form
I’ve already added the ChangeUser.cs form to the project. If you’re using the Before version of this chapter’s code, select ChangeUser.cs in the Solution Explorer. Then change its Build Action property (in the Properties panel) from None to Compile, just as you did with the UserName.cs form. Confirm that its subordinate ChangeUser.Designer.cs file also had its Build Action changed to Compile.
All of the hard work occurs in the form’s ActOK_Click event handler. If the user selects the Return to Patron Mode option, all security values are cleared, and the main form hides most features (through code added later).
LoggedInUserID = -1L; LoggedInUserName = ""; LoggedInGroupID = -1L; ReprocessSecuritySet();
This form gets connected into the application through the main form’s ActLogin_Click event. Open up the MainForm.cs file, double-click on the Login button in the upper-right corner, and add the following code to the Click event template that appears.
Insert Snippet
Insert Chapter 11, Snippet Item 12.
// ----- Prompt the user for patron or administrative mode. ShowLoginForm();
That wasn’t much code. Add the ShowLoginForm method’s code to the form as well.
Insert Snippet
Insert Chapter 11, Snippet Item 13.
private void ShowLoginForm() { // ----- Prompt the user for patron or // administrative mode. DialogResult userChoice; // ----- Prompt the user. userChoice = (new ChangeUser()).ShowDialog(); if (userChoice == DialogResult.OK) UpdateDisplayForUser(); }
Let’s also enable the F12 key to act as a login trigger. Add the following code to the switch statement in the MainForm_KeyDown event handler.
Insert Snippet
Insert Chapter 11, Snippet Item 14.
case Keys.F12: // ----- Prompt the user for patron or administrative mode. ShowLoginForm(); e.Handled = true; break;
The ShowLoginForm routine calls another method, UpdateDisplayForUser, which hides and shows various display elements on the main form based on the security profile of the current user. Add it to the MainForm class code. I won’t show the code here, but basically it looks at the LoggedInUserID variable, and if it is set to −1, it hides all the controls for advanced features.
Insert Snippet
Insert Chapter 11, Snippet Item 15.
Currently, when you run the application, all the advanced features appear, even though no administrator has supplied an ID or password. Calling UpdateDisplayForUser when the main form first appears solves that problem. Add the following code to the end of the MainForm_Load method.
Insert Snippet
Insert Chapter 11, Snippet Item 16.
// ----- Prepare for a patron user. UpdateDisplayForUser();
The last update (five updates, actually) involves limiting the major sections of the form to just authorized administrators. For instance, only administrators who are authorized to run reports should be able to access the reporting panel on the main form. Locate the TaskReports method in the main form, and find the line that displays the panel.
PanelReports.Visible = true;
Replace this line with the following code.
Insert Snippet
Insert Chapter 11, Snippet Item 17.
if (SecurityProfile[(int)LibrarySecurity.RunReports]) PanelReports.Visible = true;
We need to do the same thing in the TaskCheckOut, TaskCheckIn, TaskAdmin, and TaskProcess methods. In each case, look for the following line.
Panel???.Visible = true;
Replace each line with code that checks the security settings before showing the panel.
Insert Snippet
Insert Chapter 11, Snippet Items 18 through 21.
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
NET | C & C++ Windows Programming |
SQL Server | VBA |
Visual Basic |
Deep Learning with Python by François Chollet(11922)
Hello! Python by Anthony Briggs(9387)
OCA Java SE 8 Programmer I Certification Guide by Mala Gupta(9353)
The Mikado Method by Ola Ellnestam Daniel Brolund(9321)
Dependency Injection in .NET by Mark Seemann(8866)
Algorithms of the Intelligent Web by Haralambos Marmanis;Dmitry Babenko(7860)
Test-Driven iOS Development with Swift 4 by Dominik Hauser(7350)
Grails in Action by Glen Smith Peter Ledbrook(7305)
The Well-Grounded Java Developer by Benjamin J. Evans Martijn Verburg(7126)
Secrets of the JavaScript Ninja by John Resig Bear Bibeault(5969)
Kotlin in Action by Dmitry Jemerov(4653)
Practical Vim (for Kathryn Amaral) by Drew Neil(3733)
Cracking the GRE Premium Edition with 6 Practice Tests, 2015 (Graduate School Test Preparation) by Princeton Review(3601)
Linux Device Driver Development Cookbook by Rodolfo Giometti(3447)
Learn Windows PowerShell in a Month of Lunches by Don Jones(3252)
Learning Java by Patrick Niemeyer & Daniel Leuck(2874)
Learning React: Functional Web Development with React and Redux by Banks Alex & Porcello Eve(2846)
Becoming a Dynamics 365 Finance and Supply Chain Solution Architect by Brent Dawson(2837)
Microservices with Go by Alexander Shuiskov(2628)