![]() | |
|
|
|
To access the contents, click the chapter and section titles.
Advanced Visual Basic Techniques
Customizing the Interface for UsersBecause the Employee table contains sensitive data, only a few people can look at all the data fields without violating employee privacy. For example, the program cannot allow every employee to read the Social Security number and salary of other employees. An application is more widely usable if it can identify the kinds of access different groups of users require and then customize itself for each group of users. For example, depending on the companys policies, secretaries might be allowed to read personal information, such as home phone number and address, but be unable to access financial information. Managers might be allowed to view both personal and financial information. PeopleWatcher divides employee data into four categories: Basic, Home, HR, and Salary. The first section in this chapter, Using PeopleWatcher, describes these categories in detail. Dividing information into categories such as these makes it easy to determine how groups of users interact with the data. Usually the data items in a particular category also share a common theme that is reflected by the name of the category. For example, information in the Home category involves the employees home life. It includes home address, phone number, and birth date. It could also include similar information, such as the names of other members of the employees family, the work location and phone number of the employees spouse, and so forth. Because these data fields share a common theme, they belong together in the user interface. The program can place the items for each data category inside some sort of container control to provide visual grouping. For example, it could place all of the home data items inside a frame control with the caption Home. If the program should not separate the data so clearly from the other fields, the items can be placed inside a picture box control. The picture boxs border can be removed if the grouping should be even less obvious to the user. PeopleWatcher uses a separate tab in an SSTab control for each data category. This not only groups the data, but it also saves space on the screen. Figure 8.7 shows the running PeopleWatcher application. In this picture the tab containing the basic information is selected. Placing related fields in container controls does more than create a visual separation for the data. It also allows the program to easily customize its user interface for users with different privileges. For example, if the user should not be able to see the salary data, the application can set the Visible property for the container of the salary data fields to false.
Unfortunately for PeopleWatcher, a program cannot easily hide and display the tabs on an SSTab control. A tab controls Visible property applies to the entire control, not to the individual tabs it contains. To work around this problem, PeopleWatcher does not place the data controls within the tab itself. Instead, it places them in picture boxes with no borders. It then positions these picture boxes on top of the tab control so it looks as if the picture boxes are within the tabs. When the user clicks on one of the tabs, the program sets the Visible property of the previously displayed picture box to false. It then sets Visible to true for the newly selected picture box and uses the ZOrder method to ensure that the picture box is displayed on top of any other controls. This makes it appear as if the appropriate controls are contained within the selected tab.
Public Sub InfoTab_Click(PreviousTab As Integer)
TabPicture(PreviousTab).Visible = False
TabPicture(InfoTab.Tab).Visible = True
TabPicture(InfoTab.Tab).ZOrder
End Sub
Setting Field Editability Making fields visible or invisible solves half of the user configuration problem. Users can also have read-only or update privilege for each set of data fields. For instance, members of the Secretary group should be able to view Basic, Home, and HR information but update only the Basic information. The application must prevent a Secretary user from modifying Home and HR data fields. The application can prevent a user from modifying a text box by setting the controls Locked property to true. Preventing modification of other types of controls is not as simple. Combo boxes do not have a Locked property. To prevent the user from modifying a combo box, the program should set the controls Editable property to false. This, unfortunately, makes the control appear grayed, but it does protect the fields value. When a program makes a field noneditable, it should also change the fields background color so that it matches the background color of labels and other noneditable controls. This gives the user a visual indication that the field is not editable. To make these operations easier, PeopleWatcher initializes two arrays of collections containing the text boxes and combo boxes used by each data group. For instance, TextBoxes(0) is a collection that lists the text boxes contained in the first picture boxthose that display Basic information. The SaveEditableControls subroutine initializes these collections for later use. It examines every control on the form and checks to see if it is contained in one of the four picture boxes. If it is, the control is saved in the appropriate collection. Subroutine SetEditable uses these collections to properly set the editability and background color of the text boxes and combo boxes for a data group.
Sub SaveEditableControls()
Dim ctl As Control
Dim i As Integer
For Each ctl In Controls
If TypeOf ctl Is TextBox Then
For i = 0 To 3
If ctl.Container Is TabPicture(i) Then
TextBoxes(i).Add ctl
Exit For
End If
Next i
End If
If TypeOf ctl Is ComboBox Then
For i = 0 To 3
If ctl.Container Is TabPicture(i) Then
ComboBoxes(i).Add ctl
Exit For
End If
Next i
End If
Next ctl
End Sub
Sub SetEditable(Index As Integer, editable As Boolean)
Dim ctl As Control
Dim color As Long
If editable Then
color = EmployeeData.BackColor
Else
color = Label1(0).BackColor
End If
For Each ctl In TextBoxes(Index)
ctl.Locked = Not editable
ctl.BackColor = color
Next ctl
For Each ctl In ComboBoxes(Index)
ctl.Enabled = editable
ctl.BackColor = color
Next ctl
End Sub
Privilege Tables Using the methods described in the previous sections, an application can tailor its user interface for a user with a given set of privileges. The program still needs a way to determine the privileges that belong to each group and the groups to which each user belongs. Most types of databases include security features that can help an application control user access to data. The Jet database engine, for example, supports security features that can allow or deny access to specific tables for each user. Some databases even allow control of user access to specific fields within a table. Unfortunately, these features are difficult to use in Visual Basic for several reasons. First, different databases handle security differently. Without committing to a particular database engine, a program cannot take full advantage of its security features. Second, Visual Basic cannot create a secure Access database. If a secure database is created using Microsoft Access, a Visual Basic program can access it and use its security features. The fact that Visual Basic cannot originally create the database makes securing Visual Basics native database format a bit more difficult.
|
|
Products | Contact Us | About Us | Privacy | Ad Info | Home
Use of this site is subject to certain Terms & Conditions, Copyright © 1996-1999 EarthWeb Inc. All rights reserved. Reproduction whole or in part in any form or medium without express written permision of EarthWeb is prohibited.
|