Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
SSW_8_11.doc
Скачиваний:
2
Добавлен:
01.05.2025
Размер:
5 Мб
Скачать
☆

Creating the Database Display

The next step in creating the Employee database application is to modify the form that displays data in the application's window. Because this form is just a special type of dialog box, it's easy to modify with Developer Studio's resource editor, as you'll discover while you complete the following steps.

1. Choose the ResourceView tab to display the application's resources

2. Open the resource tree by double-clicking the Employee Resources folder. Then open the Dialog resource folder the same way. Double-click the IDD_EMPLOYEE_FORM dialog box ID to open the dialog box into the resource editor.

3. Click the static string in the center of the dialog box to select it, and then press Delete on your keyboard to remove the string from the dialog box.

4. Use the dialog box editor's tools to create the dialog box. When you create the edit boxes, use the following IDs: IDC_EMPLOYEE_ID, IDC_EMPLOYEE_NAME, IDC_EMPLOYEE_RATE, IDC_EMPLOYEE_DEPT. Also, set the Read-Only style (found on the Styles page of the Edit Properties property sheet) of the IDC_EMPLOYEE_ID edit box.

Each of these edit boxes will represent a field of data in the database. The first edit box is read-only because it will hold the database's primary key, which should never be modified.

5. Choose View, ClassWizard from the menu bar, or press Ctrl+W on your keyboard. The MFC ClassWizard property sheet appears. (Choose the Member Variables tab if necessary.)

6. With the IDC_EMPLOYEE_DEPT resource ID selected, click the Add Variable button. The Add Member Variable dialog box appears.

7. Click on the arrow next to the Member Variable Name drop-down list, and then choose m_pSet->m_DeptID.

8. Associate other member variables (m_pSet->m_EmployeeID, m_pSet->m_EmployeeName, and m_pSet->m_EmployeeRate) with the edit controls in the same way. By selecting member variables of the application's CEmployeeSet class (derived from MFC's CRecordset class) as member variables for the controls in the database view, you're establishing a connection through which data can flow between the controls and the data source.

9. Click the OK button in the MFC ClassWizard property sheet to finalize your changes.

You've now created a data display form for the Employee application. At this point, you can compile the application by clicking the Build button on Developer Studio's toolbar; by choosing the Build, Build command from the menu bar; or by pressing F7 on your keyboard. After the program has compiled, choose the Build, Execute command from the menu bar or press Ctrl+F5 to run the program. As you can see, the application now displays the contents of records in the Employees database table. Use the database controls in the application's toolbar to navigate from one record in the Employees table to another.

After you've examined the database, try updating a record. To do this, simply change one of the record's fields (except the employee ID, which is the table's primary key and can't be edited). When you move to another record, the application automatically updates the modified record. The commands in the application's Record menu also enable you to navigate through the records in the same manner as the toolbar buttons.

The Employee application is limited. For example, it can't add or delete records. As you might have guessed, that's the next piece of the database puzzle that you'll add.

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]