Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Microsoft C# Professional Projects - Premier Press.pdf
Скачиваний:
177
Добавлен:
24.05.2014
Размер:
14.65 Mб
Скачать

298 Project 2 CREATING THE EMPLOYEE RECORDS SYSTEM PROJECT

This project describes the procedure to access XML data from a Windows application. It also illustrates the use of important Windows controls, such as

the TreeView and ListView controls.

Case Study

 

Y

 

 

You need to develop an application that enables you to pick up the details of

 

L

employees from an XML file and display the employee codes in the TreeView

 

F

control. On clicking an employee code, the details of the employee must be dis-

played in the ListView control.

 

 

M

 

 

A

 

 

E

 

This chapter will startTdeveloping the ERS project.This project will introduce you to various controls, such as reeView, ListView, StatusBar, and ListLabel, and their properties and methods. The project will also discuss how to read records from a XML data store. This chapter covers the design of the project.

Project Life Cycle

You looked at the phases of a DLC (development life cycle) of a project in Chapter 7, “Project Case Study,” in the section “Case Study.” Because we have already discussed the entire life cycle of the project, here I will discuss the design of the application created by the development team for the ERS project. You, as a part of the development team, will analyze the requirements and create a design for the application.

Analyzing Requirements

To find a solution to a problem faced by a customer, you first need to analyze the customer’s requirements in detail. This is done in the analyzing requirements phase of the project life cycle. After analyzing the customer’s problems in detail, you create a plan for developing the application. This analysis of the customer’s

Team-Fly®

PROJECT CASE STUDY AND DESIGN

Chapter 13

299

 

 

 

 

problem is based on the problem statement stated by senior management and the information gathered by the development team.

In this case, the problem statement, as stated by the HR Manager, is, “The details of each employee must be accessible in an easy and simple manner.”

Upon analyzing the problem statement, the development team defined the following list of tasks that they need to do:

The HR department needs to maintain the records of its employee in a data store.

The HR department needs an application that will enable it to obtain its employee records in a quick and efficient manner.

This application can be extended to add new employee records, modify existing records, and delete records.

High-Level Design

Based on the plan of the Windows application, the development team created a design of the Windows application in the high-level design phase. The design of the ERS application includes creating the user interface for the Windows form used in the application.

The ERS application consists of a Windows form, as shown in Figure 13-1.

FIGURE 13-1 Layout of the ERS form

300 Project 2 CREATING THE EMPLOYEE RECORDS SYSTEM PROJECT

To create the layout of the ERS application, as shown in Figure 13-1, you need to include TreeView, ListView, and StatusBar controls. The following section discusses the different controls in detail. The ERS application consists of a main Windows form, called EmployeeRecordsForm.

Press F4 to view the properties of the EmployeeRecordsForm form. Change the following property values in the Properties window:

Name: EmployeeRecordsForm

Auto Scroll: True

MinimizeBox: False

MaximizeBox: False

Size: 728, 408

Text: Employee Records Monitoring System

The properties of the EmployeeRecordsForm form are as shown in Figure 13-2.

FIGURE 13-2 Properties of the EmployeeRecordsForm form

Changing the Name property changes the name of the form. By setting the MinimizeBox and the MaximizeBox properties to False, you can ensure that the form cannot be maximized or minimized.

PROJECT CASE STUDY AND DESIGN

Chapter 13

301

 

 

 

 

TreeView Control

A TreeView control is a Windows Forms control that you can use to display a hierarchy of nodes. These nodes are called root or parent nodes. Each root node in the hierarchy can contain one or more nodes, called child nodes.The root and parent nodes can be collapsed or expanded.

To add a TreeView control in Visual Studio .NET, you can drag the TreeView control from the Windows Forms toolbox to the EmployeeRecordsForm form. Figure 13-3 shows the TreeView control in the Windows Forms toolbox.

FIGURE 13-3 A TreeView control in the Windows Forms toolbox

You can create a TreeView control by dragging a TreeView control from the Windows Forms toolbox to the form.The appearance of the TreeView control can be changed from the properties window. Table 13-1 lists and explains some of the important TreeView control properties.

302

Project 2

CREATING THE EMPLOYEE RECORDS SYSTEM PROJECT

 

 

 

 

 

 

Table 13-1 TreeView Control Properties

 

 

 

 

 

 

 

Property

Description

 

 

 

 

 

 

 

 

Name

 

Sets the name of the control.

 

 

AllowDrop

Indicates whether the control can accept data that user drags onto it.

 

 

BorderStyle

Sets the border st yle of the control.The default style is Fixed3D,

 

 

 

 

 

wherein the control has a sunken three-dimensional appearance.

 

 

CheckBoxes

Displays check boxes next to the tree nodes in the control when set to

 

 

 

 

 

true.

 

 

FullRowSelect

Highlights the entire width of the control when a node is selected.

 

 

HideSelection

When set to true, the selected tree node remains highlighted even

 

 

 

 

 

after the control has lost the focus.

 

 

HotTracking

When set to true, the tree node labels appear as a hyperlink when the

 

 

 

 

 

mouse pointer moves over it.

 

 

ImageIndex

Sets the image-list index value of the default image that is displayed

 

 

 

 

 

by the tree nodes.

 

 

ImageList

Specifies the ImageList that contains the images.

 

 

LabelEdit

The tree node labels can be edited when this property is set to true.

 

 

Nodes

 

Gets the collection of nodes that are assigned to the TreeView control.

 

 

Scrollable

The TreeView control displa ys scroll bars when it is set to true.

 

 

SelectedImageIndex

Gets or sets the image list index value of the image that is displayed

 

 

 

 

 

when a tree node is selected.

 

 

ShowLines

Displays lines connecting the nodes in the control,when set to true.

 

 

ShowPlusMinus

Displays plus sign (+) and minus sign (-) when a node contains child

 

 

 

 

 

nodes.

 

 

ShowRootLines

Displays lines connecting root nodes in the control when set to true.

 

 

Size

 

Sets the height and width of the control.

 

 

Sorted

 

When set to true, the nodes in the control are displayed in a sorted

 

 

 

 

 

order.

 

 

Visible

When set to true, the control is not displayed.

 

 

 

 

 

 

PROJECT CASE STUDY AND DESIGN

Chapter 13

303

 

 

 

 

You will now create a TreeView control for the application. To create a TreeView control, perform the following steps:

1.Drag a TreeView control from the Windows Forms toolbox to the form. A blank TreeView control is added to the form.

2.Press the F4 key to display the properties of the TreeView control.

3.In the Properties window, change the following properties:

Name: treeView1

ShowLines: True

ShowPlusMinus: True

ShowRootLines: True

Size: 240, 352

The control does not contain any nodes. You can add both parent and child nodes to the TreeView control by using the Nodes property. You can also add nodes programmatically, which will be discussed in the next chapter.

ListView Control

A ListView control is a Windows Form control that displays a collection of items by using one of the four different possible views. A ListView control enables you to display a list of items with text and images to identify the type of item. You can display the items in a ListView control as large icons, small icons, or a vertical list. The items can also be displayed with column headers identifying the information being displayed in a subitem.

You can create a ListView control by dragging a ListView control from the Windows Forms toolbox to the form.The appearance of the ListView control can be changed from the Properties window. Table 13-2 lists and explains some of the important ListView control properties.

304

Project 2

CREATING THE EMPLOYEE RECORDS SYSTEM PROJECT

 

 

 

 

 

 

Table 13-2 ListView Control Properties

 

 

 

 

 

 

 

Property

Description

 

 

 

 

 

 

 

 

Name

 

Sets the name of the control.

 

 

Activation

Specifies the type of action the user must take to activate an item.

 

 

Alignment

Sets the alignment of items in the control.

 

 

AllowDrop

Indicates whether the control will accept data the user drags onto it or

 

 

 

 

 

not.

 

 

AllowColumnReorder

Indicates whether the user can drag column headers to reorder

 

 

 

 

 

columns in the control.

 

 

AutoArrange

Indicates whether items are automatically arranged.

 

 

BorderStyle

Sets the border st yle of the control.

 

 

Columns

Gets the collection of all column headers that appear in the control.

 

 

Dock

 

Sets the edge of the parent container to which a control is docked.

 

 

FullRowSelect

Indicates whether clicking an item selects all its subitems.

 

 

HeaderStyle

Sets whether the column header is clickable or not.

 

 

Items

 

Specifies the collection of items in the control.

 

 

LabelWrap

Indicates whether the item label wraps or not.

 

 

LargeImageList

Specifies the ImageList to use when displaying the items as large

 

 

 

 

 

icons.

 

 

MultiSelect

Indicates whether multiple items can be selected.

 

 

Scrollable

Indicates whether scroll bars will be displayed.

 

 

SmallImageList

Specifies the ImageList to use when displaying the items.

 

 

Sorting

Sets the sort order for items in the control.

 

 

View

 

Specifies the manner in which items are displayed in the control.The

 

 

 

 

 

items can be displayed either as large icons, small icons,in a list man-

 

 

 

 

 

ner, or in a details manner.

 

 

Visible

When set to true, the control is not displayed.

 

 

 

 

 

 

PROJECT CASE STUDY AND DESIGN

Chapter 13

 

305

 

 

 

 

 

 

You will now create a ListView control for the application. To create a ListView control, perform the following steps:

1.Drag a ListView control from the Windows Forms toolbox to the form.

A blank ListView control is added to the form. Similar to the TreeView control, the appearance of the ListView control can be modified by changing its properties.

2.Press the F4 key to display the properties of the ListView control.

3.In the Properties window, change the following properties:

Name: listView1

Activation: TwoClick

MultiSelect: False

View: Details

StatusBar Control

A StatusBar control is a Windows Forms control that typically appears at the bottom of the form and is used to display different types of status information. A StatusBar control can have status bar panels on them that display text or icons to indicate the state. The StatusBar panels can be used to display information about page numbers, spelling and grammar status, and editing modes on the status bar.

Perform the following steps to create a status bar for the application:

1.Drag a StatusBar control from the Windows Forms toolbox to the form.

2.Press F4 and change the following properties:

Name: statusBar1

ShowPanels: True

Panels can be added to a StatusBar control either at design time through

StatusBarPanel Collection Editor or at run time through the Status-

BarPanelCollection class.

3.In the Properties window, click on the Panels property, and then click on the ellipsis (…) button to open StatusBarPanel Collection Editor.

4.Add a panel by clicking the Add button.

306 Project 2 CREATING THE EMPLOYEE RECORDS SYSTEM PROJECT

5. Change the following values:

Name: statusBarPanel1

Text: Click the employee code to view details

Width: 240

The StatusBarPanel Collection Editor is shown in Figure 13-4.

FIGURE 13-4 The StatusBarPanel Collection Editor

The XML File Schema

The development team decides to store the records of the employees in an XML file.This would facilitate accessing the data store from any system.The schema of this XML file is as follows:

<?xml version=”1.0”?>

<EmpRecordsData>

<Ecode Id=”E0001” EmployeeName=”Michael Perry”>

<EmpDetails DateofJoin=”02-02-1999” Grade=”A” salary=”1750”/>

</Ecode>

PROJECT CASE STUDY AND DESIGN

Chapter 13

307

 

 

 

 

<Ecode Id=”E0002” EmployeeName=”Jenifer Carell”>

<EmpDetails DateofJoin=”03-22-1999” Grade=”B” salary=”2500”/> </Ecode>

<Ecode Id=”E0003” EmployeeName=”George Rice”>

<EmpDetails DateofJoin=”04-18-1999” Grade=”A” salary=”1800”/> </Ecode>

<Ecode Id=”E0004” EmployeeName=”Pamela Griffin”>

<EmpDetails DateofJoin=”04-27-1999” Grade=”E” salary=”7000”/> </Ecode>

<Ecode Id=”E0005” EmployeeName=”Simon Watson”>

<EmpDetails DateofJoin=”05-03-1999” Grade=”A” salary=”1650”/> </Ecode>

<Ecode Id=”E0006” EmployeeName=”Daniel Allison”>

<EmpDetails DateofJoin=”05-13-1999” Grade=”D” salary=”5700”/> </Ecode>

<Ecode Id=”E0007” EmployeeName=”Laura Hansen”>

<EmpDetails DateofJoin=”06-02-1999” Grade=”C” salary=”4150”/> </Ecode>

<Ecode Id=”E0008” EmployeeName=”Sarah Judd”>

<EmpDetails DateofJoin=”09-11-1999” Grade=”B” salary=”2600”/> </Ecode>

<Ecode Id=”E0009” EmployeeName=”Joshua Johnson”>

<EmpDetails DateofJoin=”09-23-1999” Grade=”E” salary=”7725”/> </Ecode>

<Ecode Id=”E0010” EmployeeName=”Larry Gates”>

<EmpDetails DateofJoin=”10-20-1999” Grade=”C” salary=”4350”/> </Ecode>

<Ecode Id=”E0011” EmployeeName=”Nicholas Harvey”>

<EmpDetails DateofJoin=”10-20-1999” Grade=”B” salary=”2720”/> </Ecode>

<Ecode Id=”E0012” EmployeeName=”Michael Brown”>

<EmpDetails DateofJoin=”11-11-1999” Grade=”A” salary=”1665”/> </Ecode>

<Ecode Id=”E0013” EmployeeName=”George Lewis”>

<EmpDetails DateofJoin=”12-07-1999” Grade=”B” salary=”3150”/> </Ecode>