216
Introduction to Computer Networks What can a Network do For You? Introduction A computer network can be two computers connected: A computer network can also consist of, and is usually made for, more than two computers: Characteristics of a Computer Network :: N It may know a MSWin into n :: N Don’t instal softwa comput comput like t

Introduction to Computer Networks

Embed Size (px)

Citation preview

Page 1: Introduction to Computer Networks

 

Introduction to Computer Networks 

What can a Network do For You? 

Introduction

A computer network can be two computers connected:

 

A computer network can also consist of, and is usually made for, more than two computers:

 

Characteristics of a Computer Network

The primary purpose of a computer network is to share resources:

You can play a CD music from one computer while sitting on another computer

You may have a computer with a CD writer or a backup system but the other computer doesn’t have it; In this case, you can burn CDs or make backups on a computer that has one of these but using data from a computer that doesn’t have a CD writer or a backup

  

:: NoteIt may be a good idea to know a little bit about MSWindowsinto networking.

 :: NoteDon’t think that you can install a (commercial) software product in one computer and use it on many computers. doesn’t work like that.

  

Page 2: Introduction to Computer Networks

system

You may have a computer that doesn’t have a DVD player. In this case, you can place a movie DVD on the computer that has a DVD player, and then view the movie on a computer that lacks a DVD player

You can connect a printer (or a scanner, or a fax machine) to one computer and let other computers of the network print (or scan, or fax) to that printer (or scanner, or fax machine)

You can place a CD with pictures on one computer and let other computers access those pictures

You can create files and store them in one computer, then access those files from the other computer(s) connected to it

Peer-to-Peer Networking

Based on their layout (not the physical but the imagined layout, also referred to as topology), there are two types of networks. A network is referred to as peer-to-peer if most computers are similar and run workstation operating systems:

It typically has a mix of Microsoft Windows 9X, Me, Windows XP Home Edition, or Windows XP Professional (you can also connect a Novell SUSE Linux as part of a Microsoft Windows-based network; the current release of the operating system is really easily to install and made part of the network).

In a peer-to-peer network, each computer holds its files and resources. Other computers can access these resources but a computer that has a particular resource must be turned on for other computers to access the resource it has. For example, if a printer is connected to computer A and computer B wants to printer to that printer, computer A must be turned On.

 

Client/Server Networking

Page 3: Introduction to Computer Networks

A computer network is referred to as client/server if (at least) one of the computers is used to "serve" other computers referred to as "clients". Besides the computers, other types of devices can be part of the network:

In a client/server environment, each computer still holds (or can still hold) its (or some) resources and files. Other computers can also access the resources stored in a computer, as in a peer-to-peer scenario. One of the particularities of a client/server network is that the files and resources are centralized. This means that a computer, the server, can hold them and other computers can access them. Since the server is always On, the client machines can access the files and resources without caring whether a certain computer is On.

Another big advantage of a client/server network is that security is created, managed, and can highly get enforced. To access the network, a person, called a user must provide some credentials, including a username and a password. If the credentials are not valid, the user can be prevented from accessing the network.

The client/server type of network also provides many other advantages such as centralized backup, Intranet capability, Internet monitoring, etc.

In these series of lessons, the network we will build is based on Microsoft Windows operating systems (I have been able to fully connect some versions of Linux, such as Novell SUSE Linux, into a Microsoft Windows-based network but at the time of this writing, I will not be able to address that).

In our lessons, we will mention the names of companies or provide links. These are only indications and not advertisements. Any other company or link that provides the mentioned service is suitable.

 

Page 4: Introduction to Computer Networks

Network Hardware 

Workstations 

Introduction

As introduced in the previous lesson, in a network, computers and optional other devices are connected to share resources. When a computer or device A is requesting a resource from another computer or device B, the item A is referred to as a client. Because all or most items that are part of a network live in association or cooperation, almost any one of them can be referred to as a client. Based on this, there can be different types of clients. The most regularly used of them is referred to as a workstation.

As its name implies, a workstation is a computer on which a person performs everyday regular assignments. A workstation is primarily a personal computer (PC). It can also be a laptop. You have probably used PCs so far. Almost any modern PC can be used as a workstation and participate on a network.

Before building a computer network, when planning the workstations, you may be in one of the following scenarios.

Using New Computers

If you haven't bought the computer(s) but are planning to, refer to our section on purchasing or acquiring new computers in the Lesson 4.

Using Existing Computers

If you already have one or more computers that you plan to use as workstations, you can start by checking the hardware parts installed in the computer. The computer must meet the following requirements:

Processor: An Intel Pentium or Celeron family of processors or an AMD K6/Athlon/Duron family of processors. The processor should have a 300 megahertz clock speed. A higher speed is recommended.To check the speed of the processor of a computer, you have many alternatives: 

o When the computer starts, you can access its BIOS by pressing F2 or F8 depending on the computer, the model or the manufacturer

o From the computer's desktop, if it's running Windows 95 and later, you can right-click My Computer and click Properties

o You can open Control Panel and double-click System

With these two previous options, you can see the processor's speed in the Computer section of the General property page.

As another alternative to check the computer's processor, from Control Panel, you can double-click System, click the Hardware tab, and click Device Manager. In the Device Manager window, expand the Processors node and double-click the first

 

Page 5: Introduction to Computer Networks

node under Processors. Here is an example:

In most cases, if your computer is running Microsoft Windows XP Home Edition, it should be ready for Windows XP Professional. If the computer is running another operating system but it appears to be too slow, you can replace its processor with a faster one. Before replacing a processor, you must first find out what type of processor your computer use. You cannot just replace any processor for another. To know the type of processor your computer uses, you have three options:

o You can check the documentation (manual or user guide) that came with your computer. A page in it should describe the type of processor your computer is using. You can write it down and, when you go to a computer store or to a web store and use this description to purchase a new one. You can purchase a new processor from a computer store or from one of the following web sites: 

http://www.tigerdirect.comhttp://www.bestbuy.comhttp://www.compusa.com

o You can open the computer. In this case, remove the processor. Take it to a computer store and tell the sales people that you want a faster processor

Page 6: Introduction to Computer Networks

o You can call the manufacturer of your computer. They will ask the serial number or the make/model. They will tell you the type of processor installed in it. You can also tell them that you want to purchase a faster processor

 If you purchase or acquire a processor, it is usually easy to install and it comes with easy-to-follow instructions. You will need to open the computer. It may be a good idea to take it to a computer store or a computer repair shop and have them replace the processor for you

RAM: The computer must have a memory of at least 64 megabytes (MB). As memory is not particularly expensive nowadays, you should upgrade the computer's memory to at least 512MB

To check the amount of RAM your computer has: 

o When the computer starts, you can access its BIOS by pressing F2 or F8 depending on the computer, the model or the manufacturer

o From the desktop of a Windows 95 and later computer,  you can right-click My Computer and click Properties

o You can open Control Panel and double-click System

Any of these two options would show the computer's memory in the General  property page under the Computer section. Here is an example:

 If your computer doesn't have enough memory, you can increase it. Like a processor, different computers use different types of memory. Before changing or increasing the memory of your computer, you should find out what type it

Page 7: Introduction to Computer Networks

takes. As mentioned for the processor, you can get this information by consulting the manual it came with, by opening the computer, or by calling the manufacturer.Computer memory has not been very expensive lately. You can purchase the one appropriate for your computer from a computer, from the manufacturer of your computer, or from a web store. Once you get the memory, you can open the computer and insert the new memory in the sockets next to the existing memory

Hard Drive: Before installing Microsoft Windows XP Professional on an existing computer, make sure the hard drive has the appropriate capacity to handle the OS. To find out how much space your hard drive has, you can open Windows Explorer or My Computer, right-click the C:\ drive and click Properties. Here is an example: 

The computer may have more than one drive or many partitions. Here is an example:

Page 8: Introduction to Computer Networks

 In this case, you can check the drive or partition you intend to use to install the new operating system.

The hard drive or the partition you intend to use should have at least 1.5 gigabytes (GB) of available hard disk space

Video: The computer should have Super VGA video adapter and be able to handle at least an 800 x 600 or higher-resolution.To check the current video resolution of your computer, right-click the desktop and click Properties. You can also open Control Panel and double-click Display. In the Display Properties, click Settings: 

Page 9: Introduction to Computer Networks

To check the video adapter of your computer, click Advanced and click the Adapter tab. Here is an example:

Page 10: Introduction to Computer Networks

CD-ROM or DVD drive: Unless you got this computer a long time ago, it should already have either a CD or a DVD drive or both. If it doesn't, you use one of its empty bays to install one. If the installation seems difficult or something you don't feel like doing, you can purchase an external drive. To do this, you can shop to a computer store or a web store

 

Using Barebone Computers

A computer is referred to as "barebone" if it's built almost from scratch by assembling its parts. You can build your own computer or you can purchase one. You can purchase or acquire a computer with all parts or only some parts. To get this type of computers:

You can go to one of those small computer stores on major streets, describe to them what you want. They would get the parts together and assemble them for you

You can shop in a web store such as http://www.tigerdirect.com and click the "Barebone" link

You can investigate how to build a computer from scratch, purchase the parts one by one, and assemble them yourself

You may have a computer without an operating system. For example, you might have formatted the hard drive or you might have created two or more partitions on the hard drive and (may be intentionally) loose the operating system. You may plan to use such a computer as a workstation.

Whether you build your own computer or use one without an operating system, before installing Microsoft Windows XP Professional, make sure the computer meets these hardware

Page 11: Introduction to Computer Networks

requirements:

A processor with 300 megahertz or higher processor clock speed recommended; 233 MHz minimum required (single or dual processor system);* Intel Pentium/Celeron family, or AMD K6/Athlon/Duron family, or compatible processor recommended

128 megabytes (MB) of RAM or higher recommended (64 MB minimum supported; may limit performance and some features)

1.5 gigabytes (GB) of available hard disk space

Super VGA (800 x 600) or higher-resolution video adapter

CD-ROM or DVD drive

As many USB ports as possible

Mouse and Keyboard ports

Because building a barebone depends on your goals, we will not review here the parts to acquire or the steps performed.

 Laptop or Notebook Computers

Because of their flexibility and requirements of users commute, laptops are the prime candidates of a network. If you plan to purchase one or more, refer to our section on purchasing or acquiring new computers in the Lesson 4.

Computer Accessories and Peripherals 

Keyboard and Mouse

When using a computer, there are different ways you can control it. The primary accessories used to perform routine operations are the keyboard and the mouse. If you haven't bought the computer(s) but are planning to, refer to our section on purchasing or acquiring new computers in the Lesson 4. If you are using an existing computer for your network and if either the mouse, the keyboard, or both of these items are missing or not functioning, you should get or replace the failing one.

If you are building your own computer or are acquiring a barebone, make sure you purchase a keyboard and a mouse for the computer.

There are two main ways you install a keyboard or a mouse. If the item is supplied to you with a PS/2 port, connect the end of its cable to the appropriate port, usually in the back of the computer. Many items nowadays are meant to connect to a USB port. In this case, you should be able to connect the end cable of the item to any USB port on your computer.

There are also wireless keyboards and mice. If you purchase them, they come with easy-to-follow instructions to install and configure them. Our advice is that you still should always have a PS/2 keyboard and mouse with you.

Monitors

A monitor is a display that a user looks at when performing daily assignments. You can buy a monitor from a computer store or from a web store. When purchasing a monitor, keep in mind that users may stare at it all day long. You should put as much care as possible when acquiring one.

Page 12: Introduction to Computer Networks

If you haven't bought the computer(s) and monitors, you can refer to our section onpurchasing or acquiring new computers in the Lesson 4.

If you are using an existing computer, it may have a monitor attached to it already. You can still replace it if you want.

If you are using a barebone computer, make sure you purchase a monitor and attach it to it. It is usually easy to connect a monitor to a computer. It uses a unique connector usually in the back of the computer.

Printers

If you want your users to be able to print, you can use an existing printer or purchase a new one. The simplest printers will be attached to one computer and "shared" to allow other computers to access it.

 

Network Distribution 

Introduction

Building a network consists partly of connecting the computers as we saw in Lesson 1:

One way to do this is to use cables.

 

Network Cables

Cable is used to connect computers. Although we are planning to use as much wireless as possible, you should always have one or more cables around. In our network, we will use Category 5 cable RJ-45. The ends of the cable appear as

Page 13: Introduction to Computer Networks

follows:

They can be in different colors:

You can purchase this cable from a web store on the Internet. Probably the fastest way to get this cable is to go to a computer store. When purchasing it, get something with at least 6ft.

Introduction to Network Distributors

In our introduction to networks, We mentioned that you could connect one computer to another. This can be done using their serial ports:

This is possible because almost every computer has a serial port. If you have to connect many computers to produce a network, this serial connection would not be practical. The solution is to use a central object that the computers and other resources can connect to, and then this object becomes responsible to “distribute” or manage network traffic:

Page 14: Introduction to Computer Networks

The most regularly used types of network distributors are the hub, the router, and the switch.

Hub

A hub is rectangular box that is used as the central object on which computers and other devices are connected. To make this possible, a hub is equipped with small holes called ports. Here is an example of a hub:

Although this appears with 4 ports, depending on its type, a hub can be equipped with 4, 5, 12, or more ports. example of a hub with 8 ports:

When configuring it, you connect an RJ-45 cable from the network card of a computer to one port of the hub.

In most cases for a home-based or a small business network, you may not need a hub.

Routers: Wired or Wireless

Like a hub, a router is another type of device that acts as the central point among computers and other devices that are part of a network. Here is an example of a wired router:

A router functions a little differently than a hub. In fact, a router can be considered a little "intelligent" than the hub.

Like a hub, the computers and other devices are connected to a router using network cables. To make this possible, a router is equipped with holes, called ports, in the back. Here is an example:

Page 15: Introduction to Computer Networks

Based on advances in the previous years from IEEE and other organizations or research companies, there are wireless routers. With this type, the computers and devices connect to the router using microwaves (no physical cable).

In our (small) network, we wish to use a wireless router. Therefore, this is the kind we suggest you purchase. You can purchase a wireless router from a computer store or on the internet (http://www.tigerdirect.com, http://www.3com.com, http://www.provantage.com, etc). You can also buy a wireless router from a computer store.

Wired Network Cards

In order to connect to a network, a computer must be equipped with a device called a network card. A network card, or a network adapter, also called a network interface card, or NIC, allows a computer to connect to the exterior. If you buy a computer from one of those popular stores or big companies on the Internet, most of their computers have a network card tested and already. You can reliably use it. If you go to a store that sells or manufactures computers, you can ask them to install or make sure that the computer has a network card.

If you have a computer that doesn’t have a network card, you can install one. If you have a computer that already has a network card, you can still replace it.

When it comes to their installation, there are roughly two categories of network cards: internal and external. An internal network card looks like a printed circuit board with some objects "attached" or "glued" to it and it appears as follows:

What this card looks like may not be particularly important and it may depend on the manufacturer but some of its aspects particularly are. To start, there are two types of cards and you should know which one is suited (or which one you want to use) for your computer. One type of NICs uses a peripheral component interconnect (PCI) connection. Another type uses industry standard architecture (ISA).

There are two primary ways you replace a network card. In most cases, you will remove the card your computer already has and install a new one. In some other cases, you will only add a new card but you cannot replace the existing one because it is part of the motherboard (I have found that out lately when opening a few computers for my users (I was not aware of that)). The area where you add a network card is called a slot.

To proceed, you must find out what your computer has to offer when it comes to network cards. To do this, you have three main alternatives.  You can open the computer and examine the available slots of your computer. They are usually located inside of what would be considered as the back (wall) of the computer (if you know where you connect the monitor, you should be able to locate the area that has the slots. Unfortunately, unless you have experience with this, simply looking at the slots will not tell you what type of connection you are dealing with.

The second alternative is to open the manual that came with you computer (provided you haven’t thrown it away). The manual usually lists the (types of) slots that your computer provides and where they are located.

The last alternative to knowing the types of slots that your computer provides is to contact the company that sold you the

Page 16: Introduction to Computer Networks

computer. They usually know, provided you can get a human being on the phone, as long as you give them the model of the computer.

Once you know the type of slot available to you, you can go on the Internet or to a computer store and buy an appropriate network card. One of the most important characteristics of a network card is the speed it can use to carry information. The speeds are either 10 or 100Mbps (megabits per second). When buying a network card, you should pay attention to this.

Here are some suggested links where you can buy computer products:

http://www.provantage.comhttp://www.tigerdirect.comhttp://www.cdw.com

Your computer manufacturer also may sell network cards intended for your computer.

After buying a network card intended for internal installation, you can/must install it. The network card should come with a manual and all (easy to follow) instructions. You can also install the network card after setting up the computer, which we will cover in Lesson 4.

We mentioned that a network card could also be used or installed externally. This can be done using USB. To use it, you can go to a computer store or find a web site that sells them. The device you buy may look like this:

Here is another example:

If you buy one of these objects, its documentation will guide you.

Page 17: Introduction to Computer Networks

Wireless Network Cards

Depending on your network budget or your customer's, instead of using wired network cards, you can use wireless ones. A wireless NIC appears as its wired counterpart. Here are two examples:

Overall, the physical installation of a wireless network card follows the same rules as that of a wired NIC. They normally come with easy to follow instructions but it may be a good idea to install the wireless network adapters after installing the wireless router. Also, it may be a good idea to purchase the network cards and the wireless router from the same manufacturer.

Most desktop computers (workstations) come without a wireless network card. If you purchase a computer from one of the big companies on the Internet, you can choose to have it shipped with a wireless NIC. Some companies may propose to install it before shipping the computer. If you buy a computer from a store and if you want to use wireless networking, you can buy a wireless network card separately. As stated already, a wireless network card is not particularly difficult to install.

Besides the wireless network cards that can be installed inside the computer, you can use external cards. These are installed using a USB port. Here is an example of a USB adapter:

Here is another example:

These adapters, like most USB objects, are easy to connect and use. Like the other hardware parts, when you connect these, the computer detects them and helps you get them ready for use.

Unlike desktop computers, most laptops nowadays come equipped with a wireless network card (in fact most laptops today ship with both a wired and a wireless adapters). This means that, after purchasing or acquiring a laptop, you should

Page 18: Introduction to Computer Networks

simply check whether it has a wireless adapter. The way you check this depends on the laptop. Therefore, check its documentation. If your laptop happens not to a have a wireless adapter and you want to use one, you have two main options. The classic style of adapter appears as the following two examples:

This adapter is inserted on a side of the laptop. Normally, you would easily see its port as there is usually only one that is suited for this type of card on the laptop. As you may guess, this card can be inserted and removed at will.

Network Accessories 

Printers

If you attach a printer to one computer and share it, when that computer is off, nobody can print. An alternative is to purchase a network printer. That is, a printer that will directly connect to the network and people can print to it any time. There are two types of printers in this case:

Some printers come equipped with a network card. In this case, as we will learn in Lesson 5, you can use an RJ-45 cable to connect it to a router or a hub

Some printers are equipped for a parallel port. To connect them to a network, you can purchase what is referred to as a print server (or a Jet-Direct card). The manufacturer of the printer can sell it to you

If you are using a wireless network, you can purchase a wireless print server. This allows you to connect almost any type of printer, with or without a network card, to the network. You can purchase a wireless print server from a computer store or from a web store. It is usually easy to install as it comes with easy-to-follow instructions.

Internet Service Provider (ISP)

An Internet Service Provider (ISP) is a company that serves as the intermediary between your network (or you) and the Internet. If you plan to give access to the Internet to the members of your network, you may need this type of company. You can start by checking with your local telephone company or your local TV cable company.

Firewall

Firewall is a security measure that consists of protecting your network from intruders. This is primarily important if you plan to connect your network to the Internet. There are two types of firewalls: hardware and software.

For a small network, when buying a router, you can inquire as to whether it has a built-in firewall. Many of them do. Alternatively, you can use or configure one of the computers of your network as a firewall.

 

Network Software 

Page 19: Introduction to Computer Networks

Operating Systems 

Introduction

A workstation is a computer that is a member of a network. At homes and small businesses, the most regular operating system, at the time of this writing, is probably Microsoft Windows XP Home Edition. Other regularly used operating systems from Microsoft are Microsoft Windows XP Professional, Microsoft Windows 9X, and Microsoft Windows 2000 Professional. On this site, we will mostly cover Microsoft Windows XP Professional.

When preparing to get or acquire your workstations, you may be in one of the following scenarios.

Using New Computers

If you get a contract to build a network for a small business or you are going to create a new network for a home, you may decide to purchase brand new computers. If you haven't bought the computer(s) but are planning to, refer to our section on purchasing or acquiring new computers in the Lesson 4.

Using Existing Computers

If you already have one or more computers that you plan to use as workstations, in the previous lesson, we reviewed how you can get it ready for Microsoft Windows XP Professional. Once the computer is ready with the appropriate hardware, you can prepare the operating system. Because Microsoft Windows 9X, Windows Me, and Windows XP Home Edition have only limited security, on this site, we will mostly consider only Microsoft Windows XP Professional. Based on this, if you have a computer with Microsoft Window 9X, Windows Me, or Windows XP Home Edition but plans to apply a good level of security in your network, you should upgrade it to either Microsoft Windows 2000 Professional or Windows XP Professional.

You can purchase the Microsoft Windows Windows XP Professional operating system in most computer stores or from a web store on the Internet. Here are a few links:

http://www.microsoft.comhttp://www.tigerdirect.comhttp://www.provantage.comhttp://www.cdw.comhttp://www.amazon.cometc.

We will cover the installation later.

Using Barebone Computers

If you have built your own computer or you acquired a "barebone" computer, once it's ready with the necessary hardware parts, you must acquire the operating system. In our lessons, we will use Microsoft Windows Windows XP Professional, which you should acquire or purchase.

You can purchase the operating system from a computer store or one of the above links.

 

Support Software 

Office Suite

Page 20: Introduction to Computer Networks

An office suite is a series of software applications packaged as one that assists the users with their daily regular assignments. . The suite typically includes a word processor, a spreadsheet application, a personal information manager (PIM), and a presentation software. These include the most regularly performed operations at work. In most cases, you should provide an office suite to the users.

The most popular office suite is, obviously, Microsoft Office. The other popular office suites are Corel WordPerfect and OpenOffice. The first two are commercial suites. You can purchase OpenOffice from Sun at a very low price or you can download it free fromhttp://www.openoffice.org.

 

 

Software Installations 

Workstation Operating Systems 

Introduction

When you are planning to use a computer as a workstation is a network, you should make sure that computer meets the necessary requirements. In some cases, it may only meet the hardware requirements without any software. In some cases, something could be missing. In previous lessons, we cover the issues related to making sure that the computer was ready. In some other cases, you may plan to purchase brand new computers that you would use to build your network.

Acquiring Brand New Computers

If you decide to purchase or are in the position of purchasing brand new computers, as a reminder of what we reviewed in Lesson 2, here are the hardware requirements the computer must meet:

A processor with 300 megahertz or higher processor clock speed recommended; 233 MHz minimum required (single or dual processor system);* Intel Pentium/Celeron family, or AMD K6/Athlon/Duron family, or compatible processor recommended

128 megabytes (MB) of RAM or higher recommended (64 MB minimum supported; may limit performance and some features)

1.5 gigabytes (GB) of available hard disk space

Super VGA (800 x 600) or higher-resolution video adapter and monitor

CD-ROM or DVD drive

Keyboard

Microsoft Mouse or compatible pointing device

One way you can shop for computers is to visit the web site of one of the big companies on the Internet. The companies and their web sites where you can do your shopping include, but are not limited to:

http://www.tigerdirect.comhttp://www.cdw.com

Page 21: Introduction to Computer Networks

http://www.hp.comhttp://www.dell.comhttp://www.gateway.comhttp://www.ibm.cometc

If you are shopping on a web site, select a computer with Microsoft Windows XP Professional. The computer will certainly not sell a computer that doesn't meet the hardware requirements. The web site may also propose some upgrade or extra parts. If you can afford them, then add them. The items that can be useful and helpful are a CD writer or a DVD writer (or both) and a backup system.

Instead of the Internet stores, you can also go to a computer store to buy the computers.

A Manufacturer's Installation

If you bought a computer in a computer store or from a web site and had Microsoft Windows XP Professional installed, either it was already installed or you requested that it be installed, there is nothing more to do at this time.

New Installation

A new installation is suitable if:

You have a new computer with no operating system at all

You have a computer with an operating system but you want to overwrite, that is, you want to install a new operating system on top of the old one and you don't mind loosing (since you will loose, with a new installation) whatever files already exist in the computer

You have a computer with an operating system but Microsoft Windows XP Professional doesn't support an upgrade from that existing operating system

 

 Practical Learning: Performing  a New Installation of WinXP

To perform a new installation:

1. Turn the computer on.*If you receive a message stating, "Diskette drive 0 seek failure", open the computer and make sure the power cable that connects the floppy drive is connected*If you are using a computer without an operating system, if you receive a message stating "Missing Operating System", or "Strike F1 to retry boot, F2 for setup utility", don't worry about it at this time

2. Put the Microsoft Windows XP Professional CD in the CD drive and restart the computer (you can press Ctrl + Alt + Delete to restart)

3. After a while, as soon as the computer starts, a message will notify you that the computer will boot from the CD and install the operating system (the message may display "Press any key to boot from CD").*If a message of installing the operating system doesn't come up, you should restart the computer. Then, as soon as the black screen of the computer restarting appears, press a key such as F2 or F8 (but this may depend on your computer or the manufacturer) to access the BIOS. Access the Boot Sequence and check the list. If the CD (or DVD) drive is not on top and if the instructions allow it, move the CD (or DVD) drive to the top of the sequence. If you cannot move the CD (or DVD) drive to the top, then disable the drives, such as floppy or hard drive, that come above it. In some cases, you can select the drive and press the Space bar to remove the check mark from the selected item. In this case, make sure that only the CD (or DVD) drive has a check mark next to it. After making changes in the BIOS to make the computer boot from the CD drive, save and exit the BIOS.

Page 22: Introduction to Computer Networks

Then restart the computer and follow the instructions on the screen to install the operating system.*If a message of installation still doesn't come up, make sure the CD drive is installed appropriately. You could try to find out from somebody to get the Microsoft Windows 98 boot disk (it is a floppy disk that would first install the (driver for the) CD drive). (If you have access to the Internet, you can also check the following site:http://www.bootdisk.com/ for a boot disk). Put that disk in the floppy drive and restart the computer. After a while, a list of options will come up and ask you whether you want to start the computer with or without the CD drive. Select the option that states "without" the CD. After the CD drive has been installed, make sure you remember the drive letter assigned to it. Switch to that drive by typing it followed by : and press Enter. Then, at the prompt, type setup.exe and press Enter. For example, if the CD drive is D, after typing D: and pressing Enter, type D:\setup.exe and press Enter*If the computer still doesn't boot from the CD and if you have access to the Internet, check the following article from Microsoft: http://support.microsoft.com/?kbid=310994As stated above, when the installation starts, you may see a "Boot From CD" message. In this case, press Enter.After a while, you should see a blue screen titled Windows XP Professional Setup and Welcome to Setup, To Set Up Windows XP Now, Press Enter. To continue, press Enter

4. The next screen will present to you the License Agreement. Read it. If you don't agree with it, press Esc and stop the installation.If you agree with the license agreement, press F8 (or the appropriate key)

5. The next screen asks you to select the partition you want to use to install the operating system: 

o If you have only one partition and it looks small, such as less than 5 GB, simply select it

o If you have only one partition and that, regardless of its size, you want to use it wholly to install the OS, select it

o If you have only one partition but it is large and you want to create various partitions, first make sure it is selected. Then, press C to partition it. The next screen would ask how much space you want to use for the new partition. By default, it will propose the total space for it. To reduce it, first press Backspace a few times to delete the numbers, then type the desired number of megabytes, and press Enter. Press the down arrow key to select the Unpartitioned Space option and press C. Continue the same way until you have created the desired partitions.A small partition of 8MB will be created by Windows. Don't touch and don't delete it

o If you have many partitions already, to specify which one will be used to hold the operating system, use the up and down arrow keys to select it

6. After selecting the partition you will use, press Enter to install the OS in it

7. The next screen will ask you to format the selected partition and specify the type of file system you want to use. Select the Format The Partition Using The NTFS File Systemoption and press Enter

8. In the next screen, the installation will start formatting the partition. This may take a few minutes.Once the formatting is over, the installation will starting loading files. This may take a few minutesA wizard, titled Windows XP Professional Setup, will come up. Its first page presents you with two options.The first choice consists of changing the Regional and Language Options. If you click Customize, the Regional and Language Setup Options dialog box will come up: 

Page 23: Introduction to Computer Networks

9. The default options will be selected depending on your version of the CD. For example, if you bought the OS intended for a US use, the US English would be selected. If you want to change the language, click the Customize button. Another dialog box, titled Regional and Language Options, would come up with English (United States) selected. You can then click the arrow of its combo box to change the language. After making your selection, you can click OK. If you don't intend to change anything, you can click Cancel.The bottom option consists of making changes to the way the keyboard will interpret text. Once again, if you are installing the OS intended for a US audience, the US English is selected by default. If you want to change it, click Details. This would open the Text Services and Input Languages dialog box. You can change the language by clicking the arrow of the combo box. After making the change, you can click OK. To ignore any change, you can click Cancel or press Esc.After dealing with the Windows Setup dialog box, click Next

10. The next screen request that you enter your name or the name of the primary person who will be using the computer. You must type a name other than Administrator or Guest

11. The other text box, Organization, expects the name of the company. Make sure that you provide this information

12. After entering the name and the organization, click Next or press Enter

13. The next page of the wizard requests the Product Key, which you must enter

14. After typing the product key, click Next

15. The next page of the wizard, expects you to type the computer name. It also suggests a default based on the organization you entered. You can accept the suggested name, which you can still change later on, or you can type a new name

Page 24: Introduction to Computer Networks

16. The dialog box also requests a password for the administrator. This password will be stored locally, on the computer. Type a semi-difficult password in the Administrator Password text box, such as P@s$w0rd8

17. Type the exact same password in the Confirm Password text box

18. Press Enter

19. The next page of the wizard allows you accept or change the current time, the date, and the time zone of the computer. After making your selection, click Next

20. The installation will start/continue copying files.After a while, a dialog box titled Windows XP Professional Setup will prompt you for Network Settings. Accept Typical Settings and click Next

21. The next page of the wizard will prompt you to specify the name of the network or to join a domain. Accept the default of WORKGROUP and press Enter.The installation will continue copying the files

22. When the installation finishes copying the files, the computer will reboot. When it comes up a Welcome to Microsoft Windows message will display. Click Next

23. In the next screen, accept the "Yes, this computer will connect through a local area network or home network" radio button and click Next

24. In the next screen, click the "No, not at this time" radio button

25. Click Next

26. The next screen prompts you to enter at least one name. Enter a name that is neither Administrator, nor Guest, nor the name of the computer

27. Click Next

28. The next screen displays Thank You and Congratulations...Click FinishThe computer will display Welcome for a few seconds and change to the desktop

Upgrade

If your computer already has an operating system installed, instead of performing a new installation, you can upgrade the existing one. This would preserve the existing files and other items, such as the computer name, the password, the name of the network, etc, and would only install the new features and other improvements.

To perform an upgrade:

1. Start the computer as you usually do

2. Open the CD drive. Put the CD (or DVD) that contains Microsoft Windows XP Professional in the drive and close its door. A window will display and present you some options.

3. Click Install Windows XP.Another window will come up with a dialog box on top of it. The dialog box will present you the option of performing a new installation or upgrading. To choose, click the arrow of the Installation Type combo box and select your desired option.Keep in mind that if you perform a new installation, all existing files will be lost. When in doubt, accept to upgrade

4. After making your selection in the dialog box, click Next

5. You will be presented with the License Agreement. Read it. If you agree with it, click theI Accept This Agreement radio button and click Next. If you don't agree with it, click the second radio button and and click Next to stop the installation

6. If you agreed with the License Agreement and clicked the first radio button, click Next

7. The next screen will request the Product Key. Enter it

Page 25: Introduction to Computer Networks

8. Click Next

9. In the next screen, if you (already) have an Internet connection, accept the first radio button so the installation would check updates on the Microsoft web site. If you don't have an Internet connection or you don't want to check the updates (since you can do this later on anyway), click the second radio button

10. Click Next

11. Continue the installation. At one time, the computer will reboot (itself). Some time to time, the computer will go blank for one second or half a second. Don't worry about that. It will only be a good sign. Let it flow until it prompts you for something. Don't expect this quiet (and perhaps boring) installation to take less than 30 minutes (in fact more than that). Meanwhile, if you have nothing else to do, the installation will present (somewhat advertising) messages that you can read or admire to keep yourself busy

12. When the installation is over and the computer has rebooted, a Welcome to Microsoft Windows will display with Thank You For Purchasing Microsoft Windows XP. Let's Spend A Few Minutes Setting Up Your Computer.Click Next

13. The next screen will ask you whether you want to register online. Click the No, Not At This Time radio button (unless you want to register at this time, in which case you would click the first radio button)

14. Click Next

15. The next window, titled Let's get On The Internet, would prompt you to setup the Internet at this time.Click the Do Not Set Up An Internet Connection At This Time radio button

16. Click Next

17. A Thank You message will show Congratulations, You're Ready To Go!Click FinishYou may be presented with a (blank) window with only one or two icons including Recycle Bin. This would simply indicate that the installation was fine. Congratulations

Routine Operations 

The Computer Name

After performing an installation of the operating system, you can perform some routine operations to check or change things.

To check the name of a computer, open Control Panel and double-click System. Alternatively, you can right-click My Computer and click Properties. In the System Properties dialog box, click the Computer Name tab.

 

Network Setup (Peer-To-Peer) 

Physical Connections 

Wired Networking

Page 26: Introduction to Computer Networks

After installing the operating systems on the computers that will primarily participate in the network, you can "physically" connect the computers and the router. You can start connecting the pieces whether the computers are on or off.

Practical Learning: Wiring the Network

1. Shut down all computers and the router (if necessary)

2. Turn on one computer you will use to setup the router

3. You router should have come equipped with a piece of paper or a brochure of just a few pages that lists the instructions to follow to setup the router. One of the early instructions may ask you to insert the CD that came with the router, in the CD drive and wait for the instructions. Follow these instructions faithfully

4. After setting up and configuring the router, turn it off and turn off the computer you used to set it up (this step is optional)

5. Connect each of the other computers to the router using an RJ-45 cable for each connection:

If you had turned off (some of) the machines, first turn on the router. Then, after a few seconds, turn on the computers. If you receive some messages indicating that a network was detected, fine. If not, don't worry, we will check the network later.

Wireless Networking

If you plan to setup a wireless network using a wireless router, you will need to use one

Page 27: Introduction to Computer Networks

computer to set it up.

 Practical Learning: Wirelessly Connecting a Network 

1. Start the computer you will use to setup the router (you should turn the others off): 

2. Most, if not all, wireless routers come with very easy to follow instructions. Most of them usually ask you to first insert the CD that accompanies the router, that is, before physically installing the router. Consult the documentation (usually just one or a few pieces of paper or a small brochure) and faithfully follow its CD's instructions. At one time, the instructions would indicate to you when to connect the computer and the wireless router. To do this, you will use a cable (usually supplied to you) to connect one end to the computer and another end to the router: 

3. Because the steps to perform depend on the router (or the manufacturer), we will let you perform as described by their documentation

4. After installing and setting up the wireless router, turn it off and turn the computer off

5. If you didn't yet, install the wireless network card(s) on the other computer(s).For any computer that doesn't have a wireless network card but has a wired network card, connect it to a port of the wireless router using an RJ-45 cable. The computers that have a network card will not need a physical connection to the wireless router: 

Page 28: Introduction to Computer Networks

6. Turn on the router. After a few seconds, turn on the computers one by one.You may not need to check whether they work at this time or not. We will check this later

 

Network Connections 

Network Setup on First Computer

After establishing the physical or wireless connections of the computers, you can electronically connect them, test or check that they can "see" each other. Microsoft Windows XP makes networking ridiculously easy. In fact, when writing these lessons, after physically connecting the computers to the router and turning everything on, the whole network had been built and there was no particularly necessary configuration to perform: everything was ready. Still, in the next few sections, we will pretend that the network is not (yet) working.

To "virtually" connect the network, Microsoft Windows XP provides the Network Setup Wizard, which is a series of dialog boxes that can guide you in this process. To start this wizard:

 Practical Learning: Wirelessly Connecting a Network 

1. On one of the computers that runs either Microsoft Windows XP (HE or Pro), click Start -> (All) Programs -> Accessories -> Communications -> Network Setup Wizard

2. The first page of the wizard will present a message and a bulleted list but nothing to choose: 

Page 29: Introduction to Computer Networks

Read the text and click Next

3. The second page of the wizard also displays a message:

 Read the lines of text and click Next

4. In the third page of the wizard, if you have already created a connection to the Internet,

Page 30: Introduction to Computer Networks

you can accept the first radio button. If you haven't gotten or configured a connection to the Internet, as is the case for the computers in our series of lessons so far, click the second radio button: 

5. Click Next

6. In the fourth page of the wizard, as we are not dealing with the Internet at this time, click the Other radio button 

Page 31: Introduction to Computer Networks

7. Click Next

8. In the fifth page of the wizard, read the options of the three radio buttons. Because we are not setting up, or concerned with, the Internet right now, click the This Computer Belongs To A Network That That Does Not Have An Internet Connection radio button 

Page 32: Introduction to Computer Networks

9. Click Next

10. In the sixth page of the wizard, in the Computer Description text box, type a short description such as the role or the position of the computer. There are no real rules to follow for this text, only suggestions. For example, because this description will show in Windows Explorer or other windows, don't make it too long. You can also include any characters you want

11. In the Computer Name text box, type a name for the computer. For this name, there are rules you must follow: 

12. After entering the description and the name of the computer, click Next

13. In its seventh page, the wizard prompts you to enter the name of your network. It suggestsMSHOME. You can accept this name or change it: 

Page 33: Introduction to Computer Networks

14. After typing a name for the network (you can still change the name later), click Next

15. In the eighth page of the wizard, read the text: 

 For our project, accept the Turn On File And Printer Sharing radio button and  click Next

Page 34: Introduction to Computer Networks

16. In the ninth page of the wizard, read the text: 

 Click Next

17. After clicking Next, the wizard will start creating the files used to setup a network, based on your previous selections: 

Page 35: Introduction to Computer Networks

When it has created the files, it would present a new page of the wizard.In the tenth page of the wizard, read the text. Normally, you should create a setup disk: 

To create a setup disk, you will need either a floppy drive or a flash drive (also called a jump drive) (or any portable drive that the computer allows).For our lessons and if your computer has a 3.5 floppy drive, accept the Create A Network Setup Disk radio button. Click Next 

18. In the eleventh page of the wizard, you may be presented with the only portable medium available. If your computer found more than one medium, such as a floppy drive and a flash drive, you would be presented with the option to choose which one you would use. Here is an example: 

Page 36: Introduction to Computer Networks

 If necessary, select the drive you would use and click Next. If you select the floppy drive, make sure you insert a floppy disk in the drive. The following page would ask you whether you want to format it, which you should do: 

Page 37: Introduction to Computer Networks

and click Next

19. After clicking Next, the wizard would copy the necessary files in the medium (flash drive or floppy). After copying the files, it would give you instructions on what to do next: 

 After reading the instructions, remove the disk and click Next

20. In the last page, read the text: 

Page 38: Introduction to Computer Networks

 Click Finish

21. After clicking Finish, a message box will ask you whether you want to restart the computer: 

Click Yes

 

Network Setup on Additional Computers

After setting up the network on one computer, you can continue with the next computer. You two alternatives: you can use the same network wizard or you can use the setup disk you would have created.

To setup the network on the other computer(s) that will be part of your network:

 Practical Learning: Connecting Additional Computers

1. On the next computer, click Start -> Network Places

2. Under Network Tasks, click Set Up A Home Or Office Network

3. In the first page of the wizard, read the text and click Next 

Page 39: Introduction to Computer Networks

4. In the second page of the wizard, read the text and click Next 

5. In the third page of the wizard, accept the first radio button and click Next 

Page 40: Introduction to Computer Networks

6. In the fourth page of the wizard, in the Computer Description text box, type a short description that can define or indicate what this computer is used for

7. In the Computer Name text box, type a name that will distinguish this computer in the network. One of the rules you must observe is that the name must be unique in the network. This means that you cannot use the same name you have already given to another computer in the same network: 

Page 41: Introduction to Computer Networks

8. After entering the description and the name of the computer, click Next

9. In the fifth page of the wizard, it is somewhat important (but it is not a requirement) that you enter the same name you specified for the network of the first computer: 

 If you specify a different name, you will end up with various networks, which can be

Page 42: Introduction to Computer Networks

annoying or confusing but would work fine

10. After entering the name of the network, click Next

11. The wizard will try to check if that name was already specified for another computer of the same network. If it finds that another computer is using that name, then it would allow this computer to "join" the network. If it finds out that no other computer is using that name, then it would create it.After checking the name, the wizard will present you with a summary page: 

 After reading it, click Next

12. The wizard will then create the necessary files to make this computer part of the network. After creating the files, it would present a page giving you to option to create a setup disk. This time, decline by clicking the last radio button

13. Click Next 

Page 43: Introduction to Computer Networks

14. Click Finish 

15. You will be asked whether you want to restart the computer or not. Click Yes

As an alternative, and as instructed when creating the setup disk:

1. On the other computer, put the setup disk in the drive

Page 44: Introduction to Computer Networks

2. Using Windows Explorer, My Computer or another file utility or viewer, access the drive that contains the disk you created and double-click the file it contains

3. Follow the instructions on the screen. They are pretty much self-explanatory

4. When asked to restart the computer, do so

 

Viewing Network Connections 

My Network Places

Once you have built a computer network, from time to time, you will need to check what computers are available and/or what files or folders have been shared. To assist you with this, Microsoft Windows XP provides a window named My Network Places.

To view the available connected computers:

 Practical Learning: Viewing the Connected Computers

1. On one of the computers, click Start -> My Network Places.If you don't see that option in the right column of the Start menu, depending of your configuration, click Start -> Settings -> Network Connections. Then, under Other Places, click My Network Places.As an alternative, you can click Start -> Control Panel or Start -> Settings -> Control Panel. Under Other Places, click My Network Places.

2. Under Network Tasks, click View Workgroup Computers

Page 45: Introduction to Computer Networks

 

 

Server Installation 

Necessary Hardware and Software 

Server Machines

In Lesson 1, we saw that a server was another computer that can participate in a client/server network, as opposed to a peer-to-peer network. A server is used to hold resources and items that other computers would need:

 

  

Page 46: Introduction to Computer Networks

A server is primarily a regular computer. For a small network, identify the computer that you will use as the server. You can use an existing computer or purchase a new one. Before starting to acquire the necessary hardware for your network, when planning a server, you may fit one or the following descriptions:

I will purchase a server from the Internet: If you haven't bought a server but are planning to purchase a computer for it, check our section below on the subject.

I already have the/a computer and it has an operating system: If you plan to use one of your (existing) computers as the server, check its hardware and make sure it meets the following requirements: 

o A processor with 133-MHz or higher speed; 550-MHz recommended; up to eight processors supported on one server

o 128 MB of RAM minimum required; 256 MB or more recommended; 32 GB maximum

o 1.25 to 2 GB of available hard disk space

o CD-ROM or DVD-ROM drive

o VGA or hardware that supports console redirection required; Super VGA supporting 800 x 600 or higher-resolution monitor recommended

If necessary, you can purchase additional items to meet these requirements.

I have a computer with no operating system. Either I got/built it (“barebone†�) without an operating system or I removed the operating system (for example, either I formatted the hard drive or I created two or more partitions on the hard drive): If you have a computer that doesn't have any operating system and you are planning to use it as the server of your network, make sure it meets the following requirements: 

o A processor with 133-MHz or higher speed; 550-MHz recommended; up to eight processors supported on one server

o 128 MB of RAM minimum required; 256 MB or more recommended; 32 GB maximum

o 1.25 to 2 GB of available hard disk space

o CD-ROM or DVD-ROM drive

                

:: NoteYou can use an existing computer as a server

 

Page 47: Introduction to Computer Networks

o VGA or hardware that supports console redirection required; Super VGA supporting 800 x 600 or higher-resolution monitor recommended

For these lessons, the computer will run Microsoft Windows Server 2003 (I will be using Windows Server 2003 Enterprise Edition, but Windows Server 2003 Standard Edition or Microsoft Small Busing Server 2003 will work fine too).

Monitor

You will also need a monitor attached to the server. If you will not work closely with the server, that is, if you will not "watch" the server all day long, the type of monitor you connect to it may not be important.

 Server Operating System

As its name implies, the role of a server is to serve. To perform this job, it must be loaded with a special operating system. On this site, we cover a network that deals with a Microsoft-based network. The company publishes a server operating system named Microsoft Windows Server 2003.

Before acquiring the operating system, you may fit one of the following descriptions:

I will purchase a brand new computer, to use as a server, from a web site: You can purchase a server from a manufacturer on the Internet (HP, Dell, IBM, Gateway,  etc). You can also purchase a computer from an Internet-based store (http://www.tigerdirect.com, http://www.provantage.com, http://www.cdw.com, etc).The web sites of HP, Dell, IBM, Gateway,  etc has a link (or a section) named (or labeled) Servers or Small Business. You can shop from that section, based on your budget. If you are using this approach, look for a machine called server. When choosing the machine, make sure it meets the following requirements: 

o 133-MHz processor required; 550-MHz recommended; up to eight processors supported on one server

o 128 MB of RAM minimum required; 256 MB or more recommended; 32 GB maximum

o 1.25 to 2 GB of available hard disk space

o CD-ROM or DVD-ROM drive

o VGA or hardware that supports console redirection required; Super VGA supporting 800 x 600 or higher-resolution monitor recommended

Besides these requirements, if your budget permits, change or add the following items:Tape Backup and Tape Software: This can help to perform regular backup of files.Floppy Drive: This drive cannot be completely ruled out yet. Get it just in case (you never know).DVD Drive: The web site or company may suggest a CD drive. In most cases this can be enough. Still, try to get a DVD drive instead of a simple CD drive.Second Network Card: This can be valuable if you are building a

 

:: NoteIf you are planning to use a lot of Microsoft products, you should consider getting an MSDN subscription. You can get more information frommsdn.microsoft.comDo a search on MSDN Subscription.

 

Page 48: Introduction to Computer Networks

small network and plan to give access to your computers to the Internet. This second can help you with Internet connection and security.Extended Warranty: No matter what its price and what else, get it (even if you think you will never need it).

I will purchase a brand new computer to use as a server from a web site but I will call them: The above mentioned companies also have a telephone number. You can call the company and describe that you want to purchase a server for a network. They will guide you with the requirements. They may (will) also suggest that you purchase the operating system, which is fine. If you have Microsoft Windows Server 2003 (on CD), you can tell them that you have the operating system already. Most of the time, they will sell you the server without the operating system. This is the standard way and it is just fine. You should be able to install the server operating system yourself.

I will purchase the server operating system: If you buy (bought) a computer, as a server, from one of those big companies (such as Dell, IBM, HP, Gateway, etc) on the Internet, you can ask (may have asked) them to provide you with a server operating system. As mentioned previously, you could ask (have asked) them to install the operating system for you. In some cases, depending on the arrangement you make (or made) with the company, they may send (or might have sent) you the computer without the operating system but with a CD (or DVD) that has the operating system. In this case, you can install the OS yourself, which we will cover later on.

I have a computer I plan to use as a server and it has a non-server operating system already: If you have a computer with another operating system such as Windows 9X, Windows XP Home Edition or else, you would need to get the server operating system separately. To do this, you can access one of the following links to purchase it: 

http://www.microsoft.com http://www.provantage.com http://www.tigerdirect.comhttp://www.cdw.comhttp://www.amazon.cometc

I will buy a computer from a computer store around the corner and use it as the server: You can buy a computer from one of those small computer stores on major streets. When doing this, you can tell them that you want a computer you plan to use as a server. They may offer to install, or not to install, the server operating system. If you don't make arrangements with them to install it, make sure that the computer meets the requirements and that the parts in the computer have been tested. Somehow, you will first take their word for it. Then, you will need to keep contact with them. If the installation doesn't work, even if they claim it is not their fault, you will still need to check that the parts are functional...

 

Installations and Connections

Page 49: Introduction to Computer Networks

 

New Installation

After acquiring a computer, you may have one that is ready but doesn't have an operating. You may have a computer with an operating system but that OS cannot be upgraded into Microsoft Windows Server 2003. In one of these cases, you would need to perform a new installation.

 Practical Learning: Installing the Server Operating System

1. If the computer doesn't have an operating system but it meets all the requirements and it can boot from the CD, start the computer. You may receive a message stating operating system missing or something like that. Open the CD drive, put the CD in the drive, and close it. Restart the computer. You should receive a message stating Press Any Key To Boot From CD (or something like that)

2. Press any key to start the installation.If your computer already has an operating system, start it. Open the CD drive, put the CD in it, and close its door. If the operating system cannot be upgraded, a message box and display and let you know. Accept to perform a new installation and click Next

3. When the installation starts, it will display a blue screen with Windows Setup on top and some messages on the status bar (bottom of screen).After a while, the screen will change and display a new title based on the version of operating system you are installing. For example, if you are installing Microsoft Windows Server 2003 Enterprise Edition, the title would displayWindows Server 2003, Enterprise Edition SetupThe body of the screen will present options to you. To continue the installation, press Enter

4. The next screen will show the Windows Licensing Agreement. Read it. Since it is long, to navigate up and down, you can press Page Up or Page Down. After reading it, if you accept the terms of the license, press F8. If you don't like what it says, press ESC and stop the installation.

5. The next screen asks you to select the partition you want to use to install the operating system:

o If you have only one partition and it looks small, such as less than 8 GB, simply select it

o If you have only one partition and that, regardless of its size, you want to use it wholly to install the OS, select it

o If you have only one partition but it is large and you want to create various partitions, first make sure it is selected it. Then, press C to partition it. The next screen would ask how much space you want to use for the new partition. By default, it will propose the total space for it. To reduce it, first press Backspace a few times to delete the numbers, then type the desired number of megabytes, and press Enter. Press the down arrow key to select the Unpartitioned Space option and press C. Continue in the same way until you have created the desired partitions

o If you have many partitions already, to specify which one will be used to hold the operating system, use the up and down arrow keys to select it

6. After selecting the partition you will use, press Enter to install the OS in it

7. The next screen will ask you to format the selected partition and specify the type of file system you want to use. Select the Format The Partition Using The NTFS File Systemoption and press Enter

8. In the next screen, the partition will get formatted. This may take a few minutes.Once the formatting is over, the installation will continue by copying files.After a while, a wizard, titled Windows Setup, will come up. Its first page presents you with two options.The first choice consists of changing the Regional and Language Options. The default

Page 50: Introduction to Computer Networks

options will be selected depending on your version of the CD. For example, if you bought the OS intended for a US use, the US English would be selected. If you want to change the language, click the Customize button. Another dialog box, titled Regional and Language Options, would come up with English (United States) selected. You can then click the arrow of its combo box to change the language. After making your selection, you can click OK. If you don't intend to change anything, you can click Cancel.The second option consists of making changes to the way the keyboard will interpret text. Once again, if you are installing the OS intended for a US audience, the US English is selected by default. If you want to change it, click Details. This would open the Text Services and Input Languages dialog box. You can change the language by clicking the arrow of the combo box. After making the change, you can click OK. To ignore any change, you can click Cancel or press Esc.After dealing with the Windows Setup dialog box, click Next

9. The next screen request that you enter your name or the name of the primary person who will be using the computer. You must type a name other than Administrator or Guest

10. The other text box, Organization, expects the name of the company. Make sure that you provide this information

11. After entering the name and the organization, click Next or press Enter

12. The next page of the wizard requests the Product Key, which you must enter

13. After typing the product key, click Next

14. The next page of the wizard shows the options available for licensing. You should accept the Per Server option and click Next

15. The next page of the wizard, expects you to type the computer name. It also suggests a default, based on the company name you would have entered previously as the Organization. You can accept the suggested name, which you can still change later on, or you can type a new name

16. We haven't mentioned "user accounts" yet but during installation, a user object is created and it is named Administrator. When setting up the operating system, you must give a password to this account. Obviously the password should not be too easy. Fortunately you can give it temporary password and change it later on as your network, skills, and concerned improve. You must enter the password in the Administrator Password text box and type it again in the Confirm Password text box. Make sure you remember this password because you will need it just after the installation

17. After specifying the password, click Next

18. The next page of the wizard allows you to set the date, the time, and the time zone that the server will use. Most of the time, the computer finds out the right date and the right time and it selects them. On the other hand, you should adjust the time zone if the default is not the right one. This page of the wizard also allows you the let the computer adjust its clock when daylight time is switched during the year. The option to change this is selected by default. If you don't want the computer to take care of that, you can remove the check mark on the check box.After changing the options or making sure that they are right, click Next

19. After clicking next, the wizard is closed and the installation continues copying files.After a few minutes, a new wizard, titled Windows Setup, comes up. This time, it will ask you to accept or change the network settings of the server. The first option allows you to let the installation take care of networking details. The second option allows you to manually set them.Because we will review the details of this wizard in later lessons, accept the Typical Settings option and click Next

20. The next page of the wizard allows you to actually make this computer into a server.Accept the first option not to "join" a domain.The wizard suggests WORKGROUP as the name of the "domain". If you don't like that name, change it. If you can't come up with a domain, you can use the one we will use. For

Page 51: Introduction to Computer Networks

our lessons, our domain will be called Neptune. In this case, in the top text box, type NEPTUNE

21. After entering the name of the domain, click Next

22. After clicking Next, the wizard will start copying the files, again.Once the installation has finished copying the files, the computer will start. When the computer comes back, you will be asked to log in.Press Ctrl + Alt + Delete to log in

23. Accept the User Name as Administrator.In the Password text box, type the password you entered during the installation

24. Click OK.If you see a window titled Manage Your Server, congratulations: you have finished installed Microsoft Windows Server 2003

 

The Role of a Server

After you have installed Microsoft Windows Server 2003 as we did above, it is primarily a regular computer. To use it as a server, you must properly transform. Fortunately, this is an easy process. When the computer comes up and displays the desktop, the first window you see, titled Manage Your Server, allows you define the "role" of the computer. A convenient link is available in the middle of the window.

Page 52: Introduction to Computer Networks

 

 Practical Learning: Configuring Active Directory

1. Read the text in the window and click Add Or Remove A Role

2. The first page of the wizard presents a summary of the actions you must have taken before continuing: 

Page 53: Introduction to Computer Networks

Read it and click Next

3. A dialog box will display briefly and then display a list of the roles you can assign to the server.In the list, click Domain Controller (Active Directory) 

Page 54: Introduction to Computer Networks

4. Click Next 

Page 55: Introduction to Computer Networks

5. Click Next to Run The Active Directory Installation Wizard

6. Another wizard, titled Active Directory Installation Wizard, comes up. Read its text and click Next 

7. In the second page of the wizard, read the text again, and click Next

Page 56: Introduction to Computer Networks

 

8. In the third page of the wizard, you must specify whether this is the first or an additional domain controller. As this is the first, accept the first radio button and click Next 

9. In the fourth page of the wizard, accept the first radio button and click Next 

Page 57: Introduction to Computer Networks

10. In the fifth page, you must enter the name of the domain. The name should be followed by an Internet domain name (.com, .net, .org, .us, etc). If you have a domain in mind, type it. If you don't have a domain in mind, for our lessons, type netconsulting.com 

11. Click Next

12. In the next page of the wizard, a suggested NetBIOS name displays, intended for earlier versions of Windows": 

Page 58: Introduction to Computer Networks

 Accept it and click Next

13. The next page allows you to specify where the Active Directory information would be stored: 

 Accept the default and click Next

14. The next page specifies where the domain's public files would be stored: 

Page 59: Introduction to Computer Networks

Accept the default and click Next

15. After a few seconds, the next page allows you to install DNS.Read the options: 

Accept the suggested second radio button and click Next

16. The next page allows you to set the default permissions:

Page 60: Introduction to Computer Networks

 

Accept the suggested second radio button and click Next

17. The next page prompts you to create a password used to start the server in "Restore Mode". Enter a password in both text boxes: 

18. Click Next

19. The next page displays a summary of your selections:

Page 61: Introduction to Computer Networks

 

Read the text and click Next

20. The wizard will start creating and configuring Active Directory: 

 After a while, if you don't have the Microsoft Windows Server 2003 CD in the drive, you may be be prompted to supply it: 

Page 62: Introduction to Computer Networks

Do soAfter a few seconds, you may receive a message box informing you that your computer has a static IP address. Click OKWhen the dialog box comes up, simply click OKAnother message box will come up. Click it and click OK. The wizard will continue copying files.After a few seconds, the last page of the wizard will display. Read its summary and click Finish 

21. You will be asked to restart the computer:

Page 63: Introduction to Computer Networks

 

If you have a CD in the CD drive, remove it and click Restart New

22. When the computer comes up, click the Options button and make sure that the name of the domain is selected in the Log On To text box.Make sure that Administrator is specified in the User Name text box.Enter your administrator's password

23. Click OK

24. After the computer displays the desktop, a dialog box titled Configure Your Server will let you know whether the installation of Active Directory was successful: 

Click Finish

 

 

Page 64: Introduction to Computer Networks

Joining the Network 

Joining a Domain 

Creating a Computer Account

After creating a domain, you can can add client computers to it. In our examples, we will add workstations that run Microsoft Windows XP Professional. There are two actions to adding a client to a Microsoft Windows Server 2003 domain but only one is required.

Before physically or electronically adding a client to a domain, you can first create a computer account for it. create a computer account, you have various alternatives:

If using the Manage Your Server window, you can click Manage Users And Computers In Active Directory

You can also click Start -> Administrative Tools -> Active Directory Users And Computers

You can also click Start -> Control Panel -> Administrative Tools -> Active Directory Users And Computers

Any of these actions would open the Active Directory Users and Computers window. In the left frame, expand the name of the domain. Then you can right-click the name of the domain -> New -> Computer. This would open the New Object - Computer dialog box. In the Computer Name text box, enter the name of the computer. The operating systems before Windows 2000 don't use very long names. Therefore, when naming a computer, keep this in mind and give a name made of fewer than 15 characters. After naming the computer, click Next twice and click Finish.

Instead of right-clicking the name of the domain, in the Active Directory Users And Computers, you can expand the name of the domain, right-click the Computers node -> New -> Computer. As mentioned already, in the first page of the New Object - Computer wizard, you can type a name for the computer. Here is an example:

Then click Next, Next, and Finish.

 

Page 65: Introduction to Computer Networks

Joining a Domain

After creating an account for a computer, you can add it to the domain. This is referred to as joining a domain. Normally, primarily creating an account for a computer is not required although it's a good idea. When joining a domain, if the computer you are adding doesn't have one already, an account would be created for it.

To join a domain using Microsoft Windows XP Professional:

1. First display the System Properties dialog box. To do this, 

o You can right-click My Computer and click Properties...

o You can display Control Panel and double-click System

2. In the System Properties, click Computer Name

3. Click Change...

4. In the Computer Name text box, enter the desired name of the computer. If you had already created an account in the domain for this computer, type that name

5. In the Member Of section, click the Domain radio button

6. Click the Domain text box and enter the name of the domain 

7. After specifying the name of the computer and the domain to join, click OK

8. You would then be asked to asked to provide a user name and a password for a user who has the permissions to join let a computer join a domain 

Page 66: Introduction to Computer Networks

9. After entering a user and a password, click OK. If you have the right to add computers to the domain, you would receive a Welcome message and click OK: 

10. Once you click OK, you will be asked to restart the computer, which you should do. Therefore, in the System Properties dialog box, click OK

11. When asked whether you want to restart the computer, click Yes

12. After the computer has restarted, when it displays the Log On To Windows dialog box, click the arrow of the Log On To combo box and select the name of the domain

13. If necessary, change the User Name in the top text box.In the Password text box, enter the password associated with the user name

14. Click OK

 

Introduction to Network Management 

Management Overview 

Introduction

Page 67: Introduction to Computer Networks

As a network administrator, you will perform various tasks to keep the network up and running. These include computers, users (the people who use the network), the peripherals (the other machines attached either to the computers or directly to the network. To make this possible, both Microsoft Windows XP Professional and Windows Server 2003 provide the various tools you will need. If you are managing a peer-to-peer network, the former provides local and possibly small network tools to manage workstations. For a client/server network, Microsoft Windows Server 2003 provides all the tools you need to locally or remotely manage the servers or the clients.

Network Management With WinXP

Most of the tools used to locally manage a Microsoft Windows XP Professional or a peer-to-peer network are listed in the Administrative Tools window. To open it, you can open Control Panel and double-click Administrative Tools:

As you install more software or libraries to your computer, the tools may increase in sophistication and number. Here is an example:

Page 68: Introduction to Computer Networks

To use a tool, you can double-click it.

Network Management With Windows Server 2003

Like Microsoft Windows XP Professional, Windows Server 2003 groups its administration routines under an ensemble referred to as Administrative Tools. Unlike the former, the later provides various ways of accessing the tools.

After you have just setup Microsoft Windows Server 2003 and installed Active Directory, the first window that comes up provides some of the most regular tools you will need to administer the network:

Page 69: Introduction to Computer Networks

The middle section of this window provides only a limited list of tools, considered to be the most regularly used. Alternatively, you can display the whole list of tools in a window. To do this, under the Tools and Updates Section, you can click Administrative Tools:

Page 70: Introduction to Computer Networks

To use a tool, you can double-click it.

Another technique you can access the tools consists of clicking Start -> Administrative Tools:

Page 71: Introduction to Computer Networks

Another technique consists of click Start -> All Programs -> Administrative Tools

Page 72: Introduction to Computer Networks

You can also click Start -> Control Panel -> Administrative Tools.

With any of these previous techniques, to use a tool, simply click it from the menu.

 

The Microsoft Management Console 

Introduction

If you have some experience with Windows Explorer of Microsoft Windows 9X and later, you may be aware that, in that same window, you can open your folders, view your files, open Control Panel, or even view a web page. In the same way, to make computer and network management easy, Microsoft Windows XP and Windows Server 2003 provide a common window named Microsoft Management Console or MMC. This makes it possible for all routine operations to be performed in a window that primary looks the same regardless of the task being performed. You can perform all routines operations without formally being aware that you are

Page 73: Introduction to Computer Networks

using the MMC.

 

 Practical Learning: Introducing the MMC

1. To view examples of administrative applications that share an interface: 

o If you are using Microsoft Windows XP Professional, click open Control Panel, double-click Administrative Tools, and double-click Computer Management 

o If you are using Microsoft Windows Server 2003, click Start -> Administrative tools -> Active Directory Users and Computers 

Page 74: Introduction to Computer Networks

2. To one more administrative window: 

o If you are using Microsoft Windows XP Professional, in the Administrative Tools window, double-click Services 

o If you are using Microsoft Windows Server 2003, click Start -> All Programs -> Administrative tools -> Event Viewer 

Page 75: Introduction to Computer Networks

3. Close the windows

 

MMC From Nothing

You might have noticed that the windows of the MMC have the same menu items File, Action, View, and Help. This is because many tools share  them. Inside of the MMC, a tool you use is called a snap-in. This is because it is simply an application that is added in the MMC. Once the tool has been "snapped" in the MMC, it displays as a console.

As you manage your network, you may find out that there are some tools you need constantly more than others. Instead of always opening only one tool at a time, you can create your own customized version of the MMC and include in it the tools you use most regularly. Also, if you are the supervisor of a group of administrators, you can create special versions of the MMC to let them perform their daily routines. If you are the administrator of a small network for a client, since you cannot work in their office all the time, you can create a type of MMC that they can use while you are away or as you guide them over the phone.

Before grouping the desired tools or customizing the way the MMC looks with a particular tool, you can start by opening an "empty" MMC, that is, an MMC without a particular tool. To do this, you can click Start -> Run, type mmc (or mmc.exe), and press Enter.

The MMC appears as a window titled Console1 and a first node labeled Console Root:

Page 76: Introduction to Computer Networks

The first action to take would consist of adding the desired tool(s) to the window. To do this, you can click File -> Add/Remove Snap-in... and follow the wizard.

After creating an MMC console, you can save it as a file. The file would have the extension .msc.

 

 Practical Learning: Customizing the MMC

If necessary, launch Microsoft Windows XP Professional or Windows Server 2003.On the taskbar, click Start -> Run

Type mmc and press Enter

On the main menu of Console1, click File -> Add/Remove Snap-in... 

Page 77: Introduction to Computer Networks

Click Add...

Under the Snap-In header, click Computer Management and click Add

In the Computer Management wizard, accept the Local Computer radio button.Click the Allow the Selected Computer to be Changed... check box 

Page 78: Introduction to Computer Networks

Click Finish

Once again, in the Add Standalone Snap-in dialog box, click Performance Logs and Alerts) and click Add

Click Close 

Click OK 

Page 79: Introduction to Computer Networks

To save and click the MMC, on the main menu, click File -> Save As...

Set the file name to Computer Performance and click Save

To close the MMC, on the main menu, click File -> Exit

To reopen the MMC, on the taskbar, click Start -> Run...

Type mmc and press Enter

To open a previously saved MMC, on the main menu, click File -> Open

Click Computer Management.msc and click Open

To review the current tools available, on the main menu, click File -> Add/Remove Snap-in...

In the Add/Remove Snapp-in dialog box, click the Extensions tab and, if necessary, in the combo box, select Computer Management 

Page 80: Introduction to Computer Networks

Click OK

 

Microsoft Windows Server 2008 Installation

Small Business Server Installation

This installation is for Small Business Server 2008. To start the installation, insert the operation system's DVD in the drive and boot from. While the computer is booting, watch the screen and you should receive a message that asks you to press a key if you want to install from CD. If, press Enter.

A dialog box titled Install Windows should display, asking you to specify the Language To Install, the Time And Currency Format, and the Keyboard Or Input Method. Normally, you should accept the default; if not change them as you see fit:

  

Page 81: Introduction to Computer Networks

Click Next. The second page of the wizard will display a button (or link) titled Install Now:

Click Install Now. You will be prompted for the Product Key:

Page 82: Introduction to Computer Networks

Enter it if you have it. If you don't have it, click Next (a message box will ask you if you want to enter your product key now, click No).

The licensing contract will come up:

Read it. If you agree with it, click the I Accept The License Terms check box. Click Next.

The next page may ask you whether you want to upgrade or perform a new installation:

Page 83: Introduction to Computer Networks

In most cases, you should perform a new installation. Click your selection.

The next screen allows you to select and/or create partitions. If in doubt, accept the defaults. Selection the partition where you want to install the operating system:

After making your selection, click Next. The installation will start copying files.

When the installation has finished copying the files, the computer will reboot. You don't have to do anything. When it has finished rebooting, the installation would continue. At one time, the

Page 84: Introduction to Computer Networks

computer will reboot again.

After a while, a window titled Install Windows Small Business Server 2008 will display. Read its text abd click Next.

The next screen asks you to set your calendar and clock:

To change the calendar and clock, click Open Date and Time ... After making your selection, click

Click Next. The next screen asks you check for updates:

Page 85: Introduction to Computer Networks

If your computer is connected to the Internet, click the first option. The next screen asks you to enter information about your business. After filling the form, click Next.

Accept or enter a name for the server. This name will be the one by which other computers on the network recognize this server. That name will also be used on the intranet. The name shouold be unique among the other computers on your network. Other people can use that in the Address Bar of a browser, inside your network, to access some web pages on that computer (we will see how). For our example, we use the name expression.

Accept or change the name of the internal domain. This name will be used to identify the network inside your intranet, not on the Internet. You can choose a name that identifies your business. You can even use a name of an existing web site because this name will not be accessible on the Internet. When the installation is over, the operating system will create a network that uses the name of the domain + .local. This means that the name you select here will be used as your intranet web site. The extension will be .local (not .com).

For our example, we use the name functionx. This means that the installation will create a web site for us, named functionx.local.

The name of the server will be used to access it as its own intranet web site. For our example, other computers in the same network will be able to access the server by typing http://expression.functionx.local in the Address Bar of the browser. Of course, this means that you will have to communicate this address to your users, in case you need to.

The name of the computer and that of the domain must be distinct:

Page 86: Introduction to Computer Networks

The bad news is that you should carefully choose these names. If you are not sure, leave the installation opened and think of names or plan them as long as you can, until you are ready. As the installation says, once these names have been entered and once you click Next, you will not be able to change them. After specifying the names, click Next.

The next screen asks you to enter the credentials for the administrator account. This will consist of a first name, a last name, a username, and the administrator's password:

Page 87: Introduction to Computer Networks

The next screen will be about security. After making the selections, click Next. The next screen shows a summary of the previous forms. After reading it, click Next

The installation will then start:

When file copying is over, the computer will reboot. When it has rebooted, the installation will

Page 88: Introduction to Computer Networks

resume. This is the longest and probably the most boring phase of the installation.

When the whole installation is over, you will get a window titled Windows SBS Console:

 

Connecting the Server to the Internet

The next step is probably to connect the server to the Internet. It will be used to connect other computers to the Internet. should first make sure that:

The cable (sometimes a telephone cable, sometimes the cable like that of TV cable, etc) from the ISP (or from the wall) is connected to your modem

A cable connects your modem to the router

A cable connects your server to the router

Cables connect your other computers to the router

Both the modem and the router are ON

To start, in the Windows SBS Console, click Connect to the Internet. In the first page of the wizard, read the text:

Page 89: Introduction to Computer Networks
Page 90: Introduction to Computer Networks

Click Next. If you are asked to enter the Router IP Address, type 192.168.002.001 (if you want, in the Server IP Address, type 192.168.002.003). Click Next:

Page 91: Introduction to Computer Networks

If you receive an error, click Finish and start again (it should work the second time; in reality, what may happen is that the wizard will have to detect the router, get the right IP address from it, and use it). Once you have succeeded, click Finish:

Page 92: Introduction to Computer Networks
Page 93: Introduction to Computer Networks

Click Next. If an account was already created on the server for this computer, a message box will let you know:

If an account for the computer was not yet created on the server, you may receive a message that the computer name was not found in the domain. In this case, enter the domain name again:

Page 94: Introduction to Computer Networks

Click Next. You will be asked to enter a user name who has the right to join a domain. Also type the password and domain name:

Page 95: Introduction to Computer Networks

Click Next. You will be asked to login. Enter a username and a password that can join a computer to a domain. Also type the domain name.

You will be asked whether you want to enable a domain user account on the computer:

Page 96: Introduction to Computer Networks

After reading, click Next. The next page of the wizard allows you to specify the type of account you want to create locally. cases, you should accept a Standard Account:

Page 97: Introduction to Computer Networks

Click Next. You will be reminded that you must reboot:

Creating a User Account

In the left frame, right-click Users -> New -> User. Enter the first name and the last name. If you have a middle initial, enter it too. In the User Logon Name, create a usernmae that can be a combination of the first letter of the first name + the last name. Here is an example:

  

Page 98: Introduction to Computer Networks

If you have a middle initial, you can include it as the second character. Here is an example:

Click Next. In the second page of the wizard, type the password as Password1 and press Tab. Type Password1 again. Make sure the User Must Change Password At Next Logon check box is checked:

Page 99: Introduction to Computer Networks

Click Next. In the third page of the wizard, verify the summary of the information you had specified:

Page 100: Introduction to Computer Networks

 

Managing a User Account's Rights: Adding a User to a Group

Solution 1

To access an account, on the Taskbar on the server, click Start -> Administrative Tools -> Active Directory Users and Computers.

In the left frame, expand the domain and click Users.

In the right frame, double-click the user name or right-click it and click Properties. Click Member

 

Page 101: Introduction to Computer Networks

Click Add... In the bottom text box, you can type just the beginning of the name of a group:

Click Check Names:

Page 102: Introduction to Computer Networks

Click OK. Click OK.

Page 103: Introduction to Computer Networks
Page 104: Introduction to Computer Networks

  

Solution 2

In the right frame, double-click Domain Admins or right-click it and click Properties. Click Members:

Click Add...

In the bottom text box, you can type just the username of a user:

Page 105: Introduction to Computer Networks

Click Check Names:

Click OK:

 

Creating an Intranet in Windows Server 2008

Page 106: Introduction to Computer Networks

IntroductionAn intranet is a web site that is used internally in a company. It has all the characteristics and features of a normal web site, except that it is not accessed on the World Wide Web (www), that is, the intranet is not accessible outside the company's network.

If you install Microsoft Windows Server 2008 or Windows Small Business Server 2008, it automatically creates an intranet web site for you. you can even enhance the whole thing if you install Microsoft SharePoint. To be cheap, we will review the intranet of a Windows Small Business Server.

When you have installed Windows Small Business Server 2008, it automatically creates an internal web site for its network. In reality, any company that joins the domain also has its own web site, which makes it possible to make some of its contents available to the other computers of the same network. You can then customize any of the web sites of your intranet.

Accessing an Intranet Site

The first thing you should know is how to access one of the web sites of the intranet. You should first know the name of your domain. When you install Microsoft Windows Server 2008, at one time you are asked to provide a name for the domain. The name you give is appended .local.  For example, if you create a domain named functionx, it complete name becomes functionx.local.

To access the web site hosted on a computer, you must use the name of that computer. To access a site, open a browser. In the address bar, set the address as

http://ComputerName.DomainName.local

For example, if you have a computer named central that belongs to a domain named functionx.local, you can access its intranet site with:

http://central.functionx.local

YThe default intranet site of a computer displays the default page of IIS7:

Page 107: Introduction to Computer Networks

Customizing an Intranet Site

Of course, the default web page of an intranet site is boring. To make it useful, you must customize it. To start, you must locate the folder that holds the primary files of the site. To do this, use a file utility such as Windows Explorer. Normally, the web site is at C:\Inetpub\wwwroot. Probably the first thing to do would consist of creating the home page. To do this, open a text editor such as Notepad and type the necessary HTML code in i. Here is an example:

<html><head><title>Bethesda Car Rental</title></head>

<body>

<h2>Bethesda Car Rental</h2>

<p>Welcome to Bethesda Car Rental</p>

</body></html>

Page 108: Introduction to Computer Networks

Save the file as index.htm (or index.html, or default.htm, or default.html; there are a few other names you can use) in the C:\Inetpub\wwwroot folder. That's it| Once you access the computer using its address in the browser, its home page would display. Here is an example: 

ave the file as index.htm (or index.html, or default.htm, or default.html; there are a few other names you can use) in the C:\Inetpub\wwwroot folder. That's it| Once you access the computer using its address in the browser, its home page would display. Here is an example:

 

Creating an Intranet Web Site

Probably the most important web site of your network will reside on one of your servers. If your network includes many computers, you can distribute the web site on many folders from different web sites. Still, the simplests site for a small business would bee hosted on one server.

As mentioned already, the web site is in the C:\Inetpub\wwwroot folder. The person who work on the web site should have access to that folder and should have administrative rights on that folder. For example, he or she must be able to create sub-folders, delete sub-folders, and perform other necessary file operations. For example, if you are the webmaster, you can create the necessary files in the root folder. You can also create a sub-folder named images in which you would put the necessary pictures.

For example, we are using a file named index.htm and another file named bcr.css added to theC:\Inetpub\wwwroot folder. also use a sub-folder named images:

Page 109: Introduction to Computer Networks

The images sub-folder contains the pictures of the web site. Once the files have been created or added, the web site is ready:

Page 110: Introduction to Computer Networks

 

Page 111: Introduction to Computer Networks

Application Authentication

Introduction

Application authentication consists of restricting access to an application. You can first create an application and take care of authentication later, but it is better to design the concept before starting. In this series of articles, we are going to create a complete application, step by step, and in different sections that each deals with one particular issue.

Imagine you want to create an application for a department store. One of the things you can take care of, as far as people who access the program are concerned, is authentication. For our application, you will first create a database.

Practical Learning: Creating a Folder to Hold the Database

Log to the server of your network (normally, you can use any computer of your network)

Create a folder named Fun Department Store

Right-click that folder and click Share 

Click the arrow of the combo box in the File Sharing window and select Everyone

Click Add

Click the down-pointing arrow on the right side of Everyone:

o If you are sharing from Microsoft Windows Server 2008, select Contributor 

Page 112: Introduction to Computer Networks
Page 113: Introduction to Computer Networks

Click Close

Page 114: Introduction to Computer Networks

Click Create

Close the default table without saving it

On the Ribbon, click Create

In the Tables section, click Table Design

10. Create the following fields 

Field Name Data Type Field Size Format Caption Other Properties

EmployeeNumber   20   Employee # Primary Key

FirstName       First Name  

LastName   20   Last Name  

Title   80      

Manager Yes/No     Manager?  

Page 115: Introduction to Computer Networks

HourlySalary Number Double Fixed Hourly Salary  

Username   20      

UserPassword   20   Password  

11. To change the view, right-click the tab of the table and click Datasheet View

12. When asked to save it, set its name to Employees

13. Click OK

14. Create a few records

15. Close the employees table

16. On the Ribbon, click Create

17. In the Tables section, click Table Design

18. Create the following fields 

Field Name Data Type Field Size Format Caption Other Properties

ItemNumber   20   Item # Primary Key

ArrivalDate Date/Time     Arrival Date  

Manufacturer   50      

Category   50      

SubCategory   50   Sub-Category  

ItemName   100   Item Name  

ItemSize   50   Item Size  

UnitPrice Number Double Fixed Unit Price  

DiscountRate Number Double Fixed Discount Rate  

SaleStatus   40   Sale Status  

19. To switch the view, right-click the table's tab and click Datasheet View

20. When asked to save it, set its name to StoreItems

21. Click OK

22. Create a few records

23. Close Microsoft Access

Introduction to Implementing Authentication

To implement our authentication, we will create a C# application. Normally, you can use Microsoft Visual C# 2010 Express but we will use Microsoft Visual Studio 2010 Professional. To establish a connection to the Microsoft Access database, we will use the .NET Framework.

As always, you can first create the application and then take care of authentication later.

Practical Learning: Creating a Database

Start Microsoft Visual Studio

To create a new application, on the main menu, click File -> New Project...

If you are using Microsoft Visual Stuio, in the left frame, click Visual C# Projects.In the middle list, click Empty Project

Set the Name to FunDepartmentStore1 

Page 116: Introduction to Computer Networks

Click OK

On the main menu, click Project -> FunDepartmentStore1 Properties...

In the Output Type combo box, select Windows Application

Close the Properties window

On the main menu, click Project -> Add Reference...

10. In the Add Reference dialog box, click .NET

11. In the list view, click System.Data

12. Press and hold Ctrl

13. Click System

14. Click System.Drawing

15. Click System.Windows.Forms

16. Click System.Xml

17. Release Ctrl

18. Click OK

Page 117: Introduction to Computer Networks

19. To create a file for the project, on the main menu, click Project -> Add New Item...

20. In the middle list, click Code File

21. Set the Name to StoreInventory

22. Click Add

23. In the empty document, type the following:

24. using System;25. using System.Data;26. using System.Drawing;27. using System.Data.OleDb;28. using System.Windows.Forms;29. using System.ComponentModel;30.31. public class StoreInventory : Form32. {33. private ColumnHeader colIndex;34. private ColumnHeader colItemNumber;35. private ColumnHeader colArrivalDate;36. private ColumnHeader colManufacturer;37. private ColumnHeader colCategory;38. private ColumnHeader colSubCategory;39. private ColumnHeader colItemName;40. private ColumnHeader colItemSize;41. private ColumnHeader colUnitPrice;42. private ColumnHeader colSaleStatus;43.44. private ListView lvwStoreItems;45.

Page 118: Introduction to Computer Networks

46. private Button btnClose;47.48. public StoreInventory()49. {50. InitializeComponent();51. }52.53. private void InitializeComponent()54. {55. colIndex = new ColumnHeader();56. colItemNumber = new ColumnHeader();57. colArrivalDate = new ColumnHeader();58. colManufacturer = new ColumnHeader();59. colCategory = new ColumnHeader();60. colSubCategory = new ColumnHeader();61. colItemName = new ColumnHeader();62. colItemSize = new ColumnHeader();63. colUnitPrice = new ColumnHeader();64. colSaleStatus = new ColumnHeader();65.66. lvwStoreItems = new ListView();67. btnClose = new Button();68.69. SuspendLayout();70.71. colIndex.Text = "Index";72. colIndex.Width = 40;73.74. colItemNumber.Text = "Item #";75. colItemNumber.TextAlign = HorizontalAlignment.Center;76. colItemNumber.Width = 50;77.78. colArrivalDate.Text = "Arrival Date";79. colArrivalDate.Width = 70;80.81. colManufacturer.Text = "Manufacturer";82. colManufacturer.Width = 100;83.84. colCategory.Text = "Category";85. colSubCategory.Text = "Sub-Category";86. colSubCategory.Width = 80;87.88. colItemName.Text = "Item Name/Description";89. colItemName.Width = 220;90.91. colItemSize.Text = "Size";92. colItemSize.TextAlign = HorizontalAlignment.Center;93.94. colUnitPrice.Text = "Unit Price";95. colUnitPrice.TextAlign = HorizontalAlignment.Right;96.97. colSaleStatus.Text = "Status";98. colSaleStatus.Width = 70;99.100. btnClose.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;101. btnClose.Location = new Point(772, 182);102. btnClose.Size = new Size(75, 23);103. btnClose.TabIndex = 33;104. btnClose.Text = "Close";105. btnClose.UseVisualStyleBackColor = true;106. btnClose.Click += new System.EventHandler(btnCloseClicked);

Page 119: Introduction to Computer Networks

107.108. lvwStoreItems.Anchor = AnchorStyles.Top | AnchorStyles.Bottom |109. AnchorStyles.Left | AnchorStyles.Right;110. lvwStoreItems.Columns.AddRange(new ColumnHeader[] {111. colIndex, colItemNumber, colArrivalDate, colManufacturer,112. colCategory, colSubCategory, colItemName,113. colItemSize, colUnitPrice, colSaleStatus});114. lvwStoreItems.FullRowSelect = true;115. lvwStoreItems.GridLines = true;116. lvwStoreItems.Location = new Point(12, 12);117. lvwStoreItems.Size = new Size(835, 160);118. lvwStoreItems.TabIndex = 32;119. lvwStoreItems.UseCompatibleStateImageBehavior = false;120. lvwStoreItems.View = System.Windows.Forms.View.Details;121.122. ClientSize = new Size(859, 213);123. Controls.Add(btnClose);124. Controls.Add(lvwStoreItems);125. ShowInTaskbar = false;126. StartPosition = FormStartPosition.CenterScreen;127. Text = "Fun Department Store - Current Store Inventory";128. Load += new System.EventHandler(StoreInventoryLoaded);129.130. ResumeLayout(false);131. }132.133. private void ShowInventory()134. {135.136. }137.138. private void StoreInventoryLoaded(object sender, EventArgs e)139. {140. ShowInventory();141. }142.143. private void btnCloseClicked(object sender, EventArgs e)144. {145. Close();146. }

}

147. In the Solution Explorer, double-click StoreInventory.cs 

Page 120: Introduction to Computer Networks

148. To create a new file, on the main menu, click Project -> Add New Item...

149. In the middle list, click Code File

150. Set the Name to Switchboard

151. Click Add

152. In the empty document, type the following:

153. using System;154. using System.Data;155. using System.Drawing;156. using System.Data.OleDb;157. using System.Windows.Forms;158. using System.ComponentModel;159.160. public class Switchboard : Form161. {162. private Button btnStoreInventory;163. private Button btnClose;164.165. public Switchboard()166. {167. InitializeComponent();168. }169.170. private void InitializeComponent()171. {172. btnStoreInventory = new Button();173. btnClose = new Button();174.175. SuspendLayout();176.177. btnStoreInventory.Font = new Font("Georgia", 18F, FontStyle.Bold,178. GraphicsUnit.Point, 0);179. btnStoreInventory.Location = new Point(11, 12);180. btnStoreInventory.Size = new Size(265, 98);181. btnStoreInventory.TabIndex = 21;182. btnStoreInventory.Text = "View Store Inventory";183. btnStoreInventory.UseVisualStyleBackColor = true;184. btnStoreInventory.Click +=185. new System.EventHandler(btnStoreInventoryClicked);186.187. btnClose.Font = new Font("Georgia", 18F, FontStyle.Bold,188. GraphicsUnit.Point, 0);189. btnClose.Location = new Point(11, 126);190. btnClose.Size = new Size(265, 66);191. btnClose.TabIndex = 22;192. btnClose.Text = "Close Application";193. btnClose.UseVisualStyleBackColor = true;194. btnClose.Click += new System.EventHandler(btnCloseClicked);195.196. ClientSize = new Size(288, 206);197. Controls.Add(btnStoreInventory);198. Controls.Add(btnClose);199. StartPosition = FormStartPosition.CenterScreen;200. Text = "Fun Department Store - Switchboard";201. Load += new System.EventHandler(SwitchboardLoaded);202. ResumeLayout(false);203. }204.205. private void btnStoreInventoryClicked(object sender, EventArgs e)

Page 121: Introduction to Computer Networks

206. {207. StoreInventory si = new StoreInventory();208. si.ShowDialog();209. }210.211. private void btnCloseClicked(object sender, EventArgs e)212. {213. Close();214. }215.216. private void SwitchboardLoaded(object sender, EventArgs e)217. {218.219. }220. }221.222. public class DepartmentStore223. {224. public static int Main()225. {226. Application.Run(new Switchboard());227. return 0;228. }

}

229. In the Solution Explorer, double-click Switchboard.cs  

230. To execute the application, press F5

231. Click the View Store Inventory button

232. Close the Store Inventory form

233. Close the Switchboard form

234. Access the StoreInventory.cs file

235. Implement the ShowInventory() method as follows:

236. private void ShowInventory()237. {238. // If there were some items in the list view, remove them before filling it up239. lvwStoreItems.Items.Clear();240.241. // To connect to the database, after the following Data Source= expression,242. // type \\, followed by the name of the server (ours is named Expression),243. // followed by \\, followed by the name of the folder where the database

Page 122: Introduction to Computer Networks

244. // is installed (ours is named Fun Department Store) (of course, you must245. // have shared that folder), followed by \\, and followed by the name of246. // the database, in this case FunDS247. using (OleDbConnection conFunDS =248. new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;" +249. @"Data Source=\\Expression\\Fun Department Store\\FunDS.accdb"))250. {251. // Select all store items252. OleDbCommand cmdFunDS = new OleDbCommand("SELECT * FROM StoreItems;", conFunDS);253.254. OleDbDataAdapter odaFunDS = new OleDbDataAdapter(cmdFunDS);255. DataSet dsStoreItems = new DataSet("StoreItemsSet");256. odaFunDS.Fill(dsStoreItems);257.258. conFunDS.Open();259.260. // Using the total number of records, display each in the list view261. for (int i = 0; i < dsStoreItems.Tables[0].Rows.Count; i++)262. {263. DataRow rcdStoreItem = dsStoreItems.Tables[0].Rows[i];264.265. ListViewItem lviStoreItem = new ListViewItem((i + 1).ToString());266. lviStoreItem.SubItems.Add(rcdStoreItem["ItemNumber"].ToString());267. lviStoreItem.SubItems.Add(268. DateTime.Parse(rcdStoreItem["ArrivalDate"].ToString()).ToShortDateString());269. lviStoreItem.SubItems.Add(rcdStoreItem["Manufacturer"].ToString());270. lviStoreItem.SubItems.Add(rcdStoreItem["Category"].ToString());271. lviStoreItem.SubItems.Add(rcdStoreItem["SubCategory"].ToString());272. lviStoreItem.SubItems.Add(rcdStoreItem["ItemName"].ToString());273. lviStoreItem.SubItems.Add(rcdStoreItem["ItemSize"].ToString());274. lviStoreItem.SubItems.Add(275. double.Parse(rcdStoreItem["UnitPrice"].ToString()).ToString("F"));276. lviStoreItem.SubItems.Add(rcdStoreItem["SaleStatus"].ToString());277. lvwStoreItems.Items.Add(lviStoreItem);278. }279. }280. }281.282. private void StoreInventory_Load(object sender, EventArgs e)283. {284. ShowInventory();

}

285. To execute, press F5

286. Click the Store Inventory button

Page 123: Introduction to Computer Networks

 

Implementing Authentication

There is always more than one way to solve a problem in logic and in  math. When it comes to an application also, you have many options:

You can create the first form of your application as the log in dialog box. In this case, if the employee successfully logs, then the actual application would display

You can add the code to call a log in dialog box to the first form. If the employee successfully logs in, then the rest of the application would show

In all cases, you must decide when and how the employee would log in and what to do in case of successful or unsuccessful log in.

Practical Learning: Implementing Authentication

To create a file, on the main menu, click Project -> Add New Item...

In the middle list, click Code File

Set the Name to Authenticator

Click Add

In the empty document, type the following:

using System;using System.Data;using System.Drawing;using System.Windows.Forms;using System.ComponentModel;

public class Authenticator : Form{ private Label lblUsername; public TextBox txtUsername; private Label lblPassword; public TextBox txtPassword; private Button btnOK; private Button btnCancel;

public Authenticator() {

Page 124: Introduction to Computer Networks

InitializeComponent(); }

private void InitializeComponent() { lblUsername = new Label(); txtUsername = new TextBox(); txtPassword = new TextBox(); lblPassword = new Label(); btnOK = new Button(); btnCancel = new Button();

this.SuspendLayout();

lblUsername.AutoSize = true; lblUsername.Location = new Point(12, 19); lblUsername.Size = new Size(58, 13); lblUsername.TabIndex = 0; lblUsername.Text = "Username:";

txtUsername.Location = new Point(87, 16); txtUsername.Size = new Size(100, 20); txtUsername.TabIndex = 1;

lblPassword.AutoSize = true; lblPassword.Location = new Point(12, 45); lblPassword.Size = new Size(56, 13); lblPassword.TabIndex = 2; lblPassword.Text = "Password:";

txtPassword.Location = new Point(87, 42); txtPassword.PasswordChar = '*'; txtPassword.Size = new Size(100, 20); txtPassword.TabIndex = 3;

btnOK.DialogResult = System.Windows.Forms.DialogResult.OK; btnOK.Location = new Point(31, 78); btnOK.Size = new Size(75, 23); btnOK.TabIndex = 4; btnOK.Text = "OK"; btnOK.UseVisualStyleBackColor = true;

btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel; btnCancel.Location = new Point(112, 78); btnCancel.Size = new Size(75, 23); btnCancel.TabIndex = 5; btnCancel.Text = "Cancel"; btnCancel.UseVisualStyleBackColor = true;

Controls.Add(lblUsername); Controls.Add(txtUsername); Controls.Add(lblPassword); Controls.Add(txtPassword); Controls.Add(btnOK); Controls.Add(btnCancel);

AcceptButton = btnOK; CancelButton = btnCancel; ClientSize = new Size(206, 115); FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; MaximizeBox = false;

Page 125: Introduction to Computer Networks

MinimizeBox = false; ShowInTaskbar = false; StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; Text = "Fun Department Store - Log In"; ResumeLayout(false); }

}

In the Solution Explorer, double-click Authenticator.cs

Access the Switchboard.cs file

Create a method named LogInToTheApplication and change the SwitchboardLoaded event as follows:

private void LogInToTheApplication(){ bool usernamePasswordMatch = false; Authenticator dlgLogIn = new Authenticator(); string strPasswordFromDialogBox = "", strPasswordFromDatabase = ""; string strUsernameFromDialogBox = "", strUsernameFromDatabase = "";

100. // Display the Autheticator dialog box.101. // If the user clicks Cancel, simply close the application102. if (dlgLogIn.ShowDialog() == System.Windows.Forms.DialogResult.Cancel)103. Close();104. else // If the user clicks OK105. {106. // If the employee doesn't enter a username, display a message box...107. if (dlgLogIn.txtUsername.Text == "")108. {109. MessageBox.Show("You must enter a user name.",110. "Fun Department Store",111. MessageBoxButtons.OK, MessageBoxIcon.Information);112. // ... and close the application113. Close();114. }115.116. // If the employee doesn't enter a password, display a message box...117. if (dlgLogIn.txtPassword.Text == "")118. {119. MessageBox.Show("You must type a password.",120. "Fun Department Store",121. MessageBoxButtons.OK, MessageBoxIcon.Information);122. // ... and close the application123. Close();124. }125.126. // Get the user name of the dialog box127. strUsernameFromDialogBox = dlgLogIn.txtUsername.Text;128. // Get the password of the dialog box129. strPasswordFromDialogBox = dlgLogIn.txtPassword.Text;130.131. // To connect to the database, after the following Data Source= expression,

Page 126: Introduction to Computer Networks

132. // type \\, followed by the name of the server (ours is named Expression),133. // followed by \\, followed by the name of the folder where the database 134. // is installed (ours is named Fun Department Store) (of course, you must135. // have shared that folder), followed by \\, and followed by the name of136. // the database, in this case FunDS137. using (OleDbConnection conFunDS =138. new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;" +139. @"Data Source=\\Expression\\Fun Department Store\\FunDS.accdb"))140. {141. // Get the records of all employees142. OleDbCommand cmdFunDS = new OleDbCommand("SELECT * FROM Employees;", conFunDS);143.144. // Create a data adapater to retrieve the employees145. OleDbDataAdapter odaEmployees = new OleDbDataAdapter(cmdFunDS);146. // Create a data set of employees147. DataSet dsEmployees = new DataSet("EmployeesSet");148. // Fill the data set with the Employees records149. odaEmployees.Fill(dsEmployees);150.151. // Open the connection152. conFunDS.Open();153.154. // Navigate to each record155. for (int i = 0; i < dsEmployees.Tables[0].Rows.Count; i++)156. {157. // Get a reference to the current record158. DataRow rcdStoreItem = dsEmployees.Tables[0].Rows[i];159.160. // When you are on a record, get the username of the employee161. strUsernameFromDatabase = rcdStoreItem["Username"].ToString();162. // and the password163. strPasswordFromDatabase = rcdStoreItem["UserPassword"].ToString();164.165. // Compare the current username to the username of the dialog box166. // and the current password to the password of the dialog box.167. // If they match, ...168. if (strUsernameFromDatabase.Equals(strUsernameFromDialogBox) &&169. strPasswordFromDatabase.Equals(strPasswordFromDialogBox))170. {171. usernamePasswordMatch = true;172. // ... display the switchboard173. break;174. }175.176. // If there is no match, continue to the next record, 177. // up to the end of the table178. }179.180. // If there was a match for username/password, display the Switchboard181.182. // If there was no match for username/password, 183. // Let the employee know ...184. if (usernamePasswordMatch == false)185. {186. MessageBox.Show("The username and password combination did " +187. "not match any of the employees",188. "Fun Department Store",189. MessageBoxButtons.OK, MessageBoxIcon.Information);190. // ... and close the application191. Close();192. }

Page 127: Introduction to Computer Networks

193. }194. }195. }196.197. private void SwitchboardLoaded(object sender, EventArgs e)198. {199. LogInToTheApplication();

}

To test the application, press F5

When the dialog box comes up, click Cancel

Execute the application again

When the dialog box displays, type the user name as Pasquale and press Enter

Read the message box and click OK

Execute the application again

When the dialog box displays, type the user name as opasquale and press Tab

Type the password as L'Italiano and press Enter

Read the message box and press Enter

Execute the application again

Type the username as mtownsend and press Tab

Type the password as Password4 and pass Enter

Read the message box and click OK

Execute the application again

In the username of the dialog box, type mtownsend and press Tab

Type the password as Password5

Click OK

Click the View Store Inventory button

Close the forms

To create a new file, on the main menu, click Project -> Add New Item...

Page 128: Introduction to Computer Networks

In the middle list, click Code File

Set the Name to CreateStoreItem

Click Add

In the empty document, type the following:

224. using System;225. using System.Data;226. using System.Drawing;227. using System.Data.OleDb;228. using System.Windows.Forms;229. using System.ComponentModel;230.231. public class CreateStoreItem : Form232. {233. private Label lblItemNumber;234. private TextBox txtItemNumber;235. private Label lblArrivalDate;236. private MaskedTextBox txtArrivalDate;237. private Label lblManufacturer;238. private TextBox txtManufacturer;239. private Label lblCategory;240. private ComboBox cbxCategories;241. private Label lblSubCategory;242. private ComboBox cbxSubCategories;243. private Label lblItemName;244. private TextBox txtItemName;245. private Label lblItemSize;246. private TextBox txtItemSize;247. private Label lblUnitPrice;248. private TextBox txtUnitPrice;249. private Label lblDiscountRate;250. private TextBox txtDiscountRate;251. private Label lblPercent;252. private Label lblSaleStatus;253. private ComboBox cbxSaleStatus;254.255. private Button btnReset;256. private Button btnCreate;257. private Button btnClose;258.259. public CreateStoreItem()260. {261. InitializeComponent();262. }263.264. private void InitializeComponent()265. {266. lblItemNumber = new Label();267. txtItemNumber = new TextBox();268. lblArrivalDate = new Label();269. txtArrivalDate = new MaskedTextBox();270. lblManufacturer = new Label();271. txtManufacturer = new TextBox();272. lblCategory = new Label();273. cbxCategories = new ComboBox();274. lblSubCategory = new Label();275. cbxSubCategories = new ComboBox();276. lblItemName = new Label();277. txtItemName = new TextBox();

Page 129: Introduction to Computer Networks

278. lblItemSize = new Label();279. txtItemSize = new TextBox();280. lblUnitPrice = new Label();281. txtUnitPrice = new TextBox();282. lblDiscountRate = new Label();283. txtDiscountRate = new TextBox();284. lblPercent = new Label();285. lblSaleStatus = new Label();286. cbxSaleStatus = new ComboBox();287.288. btnReset = new Button();289. btnCreate = new Button();290. btnClose = new Button();291.292. SuspendLayout();293.294. lblItemNumber.AutoSize = true;295. lblItemNumber.Location = new Point(11, 14);296. lblItemNumber.Size = new Size(40, 13);297. lblItemNumber.TabIndex = 0;298. lblItemNumber.Text = "Item #:";299.300. txtItemNumber.Location = new Point(95, 11);301. txtItemNumber.Size = new Size(96, 20);302. txtItemNumber.TabIndex = 1;303.304. lblArrivalDate.AutoSize = true;305. lblArrivalDate.Location = new Point(223, 14);306. lblArrivalDate.Size = new Size(65, 13);307. lblArrivalDate.TabIndex = 2;308. lblArrivalDate.Text = "Arrival Date:";309.310. txtArrivalDate.Location = new Point(303, 11);311. txtArrivalDate.Mask = "00/00/0000";312. txtArrivalDate.Size = new Size(121, 20);313. txtArrivalDate.TabIndex = 3;314. txtArrivalDate.ValidatingType = typeof(System.DateTime);315. 316. lblManufacturer.AutoSize = true;317. lblManufacturer.Location = new Point(11, 43);318. lblManufacturer.Size = new Size(73, 13);319. lblManufacturer.TabIndex = 4;320. lblManufacturer.Text = "Manufacturer:";321.322. txtManufacturer.Location = new Point(95, 40);323. txtManufacturer.Size = new Size(330, 20);324. txtManufacturer.TabIndex = 5;325.326. lblCategory.AutoSize = true;327. lblCategory.Location = new Point(11, 72);328. lblCategory.Size = new Size(52, 13);329. lblCategory.TabIndex = 6;330. lblCategory.Text = "Category:";331.332. cbxCategories.FormattingEnabled = true;333. cbxCategories.Items.AddRange(new object[] {334. "Men", "Girls", "Boys",335. "Babies", "Women", "Other"});336. cbxCategories.Location = new Point(95, 70);337. cbxCategories.Size = new Size(116, 21);338. cbxCategories.TabIndex = 7;

Page 130: Introduction to Computer Networks

339.340. lblSubCategory.AutoSize = true;341. lblSubCategory.Location = new Point(223, 73);342. lblSubCategory.Size = new Size(74, 13);343. lblSubCategory.TabIndex = 8;344. lblSubCategory.Text = "Sub-Category:";345.346. cbxSubCategories.FormattingEnabled = true;347. cbxSubCategories.Items.AddRange(new object[] {348. "Skirts", "Pants", "Shirts", "Shoes",349. "Blouse", "Beauty", "Dresses", "Clothing",350. "Sweater", "Watches", "Handbags", "Miscellaneous"});351. cbxSubCategories.Location = new Point(303, 70);352. cbxSubCategories.Size = new Size(121, 21);353. cbxSubCategories.TabIndex = 9;354.355. lblItemName.AutoSize = true;356. lblItemName.Location = new Point(11, 104);357. lblItemName.Size = new Size(61, 13);358. lblItemName.TabIndex = 10;359. lblItemName.Text = "Item Name:";360. 361. txtItemName.Location = new Point(95, 100);362. txtItemName.Size = new Size(329, 20);363. txtItemName.TabIndex = 11;364.365. lblItemSize.AutoSize = true;366. lblItemSize.Location = new Point(12, 132);367. lblItemSize.Size = new Size(30, 13);368. lblItemSize.TabIndex = 12;369. lblItemSize.Text = "Size:";370. 371. txtItemSize.Location = new Point(95, 129);372. txtItemSize.Size = new Size(96, 20);373. txtItemSize.TabIndex = 13;374.375. lblUnitPrice.AutoSize = true;376. lblUnitPrice.Location = new Point(224, 135);377. lblUnitPrice.Size = new Size(56, 13);378. lblUnitPrice.TabIndex = 14;379. lblUnitPrice.Text = "Unit Price:";380. 381. txtUnitPrice.Location = new Point(304, 132);382. txtUnitPrice.Size = new Size(121, 20);383. txtUnitPrice.TabIndex = 15;384. txtUnitPrice.Text = "0.00";385. txtUnitPrice.TextAlign = HorizontalAlignment.Right;386.387. lblDiscountRate.AutoSize = true;388. lblDiscountRate.Location = new Point(11, 161);389. lblDiscountRate.Size = new Size(78, 13);390. lblDiscountRate.TabIndex = 16;391. lblDiscountRate.Text = "Discount Rate:";392.393. txtDiscountRate.Location = new Point(95, 158);394. txtDiscountRate.Size = new Size(96, 20);395. txtDiscountRate.TabIndex = 17;396. txtDiscountRate.Text = "0.00";397. txtDiscountRate.TextAlign = HorizontalAlignment.Right;398.399. lblPercent.AutoSize = true;

Page 131: Introduction to Computer Networks

400. lblPercent.Font = new Font("Microsoft Sans Serif", 9.75F,401. FontStyle.Bold, GraphicsUnit.Point, 0);402. lblPercent.Location = new Point(191, 161);403. lblPercent.Size = new Size(21, 16);404. lblPercent.TabIndex = 18;405. lblPercent.Text = "%";406.407. lblSaleStatus.AutoSize = true;408. lblSaleStatus.Location = new Point(224, 164);409. lblSaleStatus.Name = "lblSaleStatus";410. lblSaleStatus.Size = new Size(64, 13);411. lblSaleStatus.TabIndex = 19;412. lblSaleStatus.Text = "Sale Status:";413. 414. cbxSaleStatus.FormattingEnabled = true;415. cbxSaleStatus.Items.AddRange(new object[] {416. "Sold", "In Stock", "On Display",417. "Processing", "Other"});418. cbxSaleStatus.Location = new Point(304, 161);419. cbxSaleStatus.Size = new Size(121, 21);420. cbxSaleStatus.TabIndex = 20;421. 422. btnReset.Location = new Point(125, 193);423. btnReset.Size = new Size(95, 23);424. btnReset.TabIndex = 23;425. btnReset.Text = "Reset";426. btnReset.UseVisualStyleBackColor = true;427. btnReset.Click += new System.EventHandler(btnResetClicked);428.429. btnCreate.Location = new Point(226, 193);430. btnCreate.Size = new Size(108, 23);431. btnCreate.TabIndex = 21;432. btnCreate.Text = "Create";433. btnCreate.UseVisualStyleBackColor = true;434. btnCreate.Click += new System.EventHandler(btnCreateClicked);435.436. btnClose.Location = new Point(340, 193);437. btnClose.Size = new Size(83, 23);438. btnClose.TabIndex = 22;439. btnClose.Text = "Close";440. btnClose.UseVisualStyleBackColor = true;441. btnClose.Click += new System.EventHandler(btnClose_Click);442. 443. Controls.Add(lblItemNumber);444. Controls.Add(txtItemNumber);445. Controls.Add(lblArrivalDate);446. Controls.Add(txtArrivalDate);447. Controls.Add(lblManufacturer);448. Controls.Add(txtManufacturer);449. Controls.Add(lblCategory);450. Controls.Add(cbxCategories);451. Controls.Add(lblSubCategory);452. Controls.Add(cbxSubCategories);453. Controls.Add(lblItemName);454. Controls.Add(txtItemName);455. Controls.Add(lblItemSize);456. Controls.Add(txtItemSize);457. Controls.Add(lblUnitPrice);458. Controls.Add(txtUnitPrice);459. Controls.Add(lblDiscountRate);460. Controls.Add(txtDiscountRate);

Page 132: Introduction to Computer Networks

461. Controls.Add(lblPercent);462. Controls.Add(lblSaleStatus);463. Controls.Add(cbxSaleStatus);464.465. Controls.Add(btnCreate);466. Controls.Add(btnReset);467. Controls.Add(btnClose);468.469. ClientSize = new Size(437, 230);470. FormBorderStyle = FormBorderStyle.FixedDialog;471. MaximizeBox = false;472. MinimizeBox = false;473. ShowInTaskbar = false;474. StartPosition = FormStartPosition.CenterScreen;475. Text = "Fun Department Store - Create New Store Item";476. Load += new System.EventHandler(CreateStoreItemLoaded);477. ResumeLayout(false);478. PerformLayout();479.480. }481.482. private void btnResetClicked(object sender, EventArgs e)483. {484. txtItemNumber.Text = "";485. txtArrivalDate.Text = DateTime.Today.ToShortDateString();486. txtManufacturer.Text = "";487. cbxCategories.Text = "";488. cbxSubCategories.Text = "";489. txtItemName.Text = "";490. txtItemSize.Text = "";491. txtUnitPrice.Text = "0.00";492. txtDiscountRate.Text = "0.00";493. cbxSaleStatus.Text = "In Stock";494. }495.496. private void CreateStoreItemLoaded(object sender, EventArgs e)497. {498. // When the form opens, reset it499. btnResetClicked(sender, e);500. }501.502. private void btnCreateClicked(object sender, EventArgs e)503. {504. double unitPrice = 0.00;505. double discountRate = 0.00;506.507. // Make sure the user entered an item number.508. // If not, don't do anything509. if (txtItemNumber.Text.Length == 0)510. {511. MessageBox.Show("You must provide a (unique) item number.",512. "Fun Department Store",513. MessageBoxButtons.OK, MessageBoxIcon.Information);514. return;515. }516. // On a related issue, for the simplicity of this exercise,517. // We are not writing code to check whether the user provided518. // a duplicate item number. If the user does, the application519. // itself would throw an exception. In another article, we may have520. // to take care of that problem. For now, we will ignore it521.

Page 133: Introduction to Computer Networks

522. // Make sure the user entered a name for the new item.523. // If not, don't do anything524. if (txtItemName.Text.Length == 0)525. {526. MessageBox.Show("You must provide a name for the item.",527. "Fun Department Store",528. MessageBoxButtons.OK, MessageBoxIcon.Information);529. return;530. }531.532. // Make sure the user provided a price for the item533. if (txtUnitPrice.Text.Length == 0)534. {535. MessageBox.Show("You must provide a price for the item.",536. "Fun Department Store",537. MessageBoxButtons.OK, MessageBoxIcon.Information);538. return;539. }540.541. // Check if the user provided a valid price...542. try543. {544. unitPrice = double.Parse(txtUnitPrice.Text);545. }546. catch (FormatException)547. {548. // ... if not, use 0.00549. }550.551. // Check if the user provided a valid discount rate...552. try553. {554. discountRate = double.Parse(txtDiscountRate.Text);555. }556. catch (FormatException)557. {558. // ... if not, use 0.00559. }560.561. // Connect to the database562. // To connect to the database, after the following Data Source= expression,563. // type \\, followed by the name of the server (ours is named Expression),564. // followed by \\, followed by the name of the folder where the database 565. // is installed (ours is named Fun Department Store) (of course, you must566. // have shared that folder), followed by \\, and followed by the name of567. // the database, in this case FunDS568. using (OleDbConnection conFunDS =569. new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;" +570. @"Data Source=\\Expression\\Fun Department Store\\FunDS.accdb"))571. {572. string strSQLInsert = "INSERT INTO StoreItems(ItemNumber, ArrivalDate, " +573. "Manufacturer, Category, SubCategory, ItemName, " +574. "ItemSize, UnitPrice, DiscountRate, SaleStatus) " +575. "VALUES(" + txtItemNumber.Text + ", '" +576. txtArrivalDate.Text + "', '" +577. txtManufacturer.Text + "', '" +578. cbxCategories.Text + "', '" +579. cbxSubCategories.Text + "', '" +580. txtItemName.Text + "', '" +581. txtItemSize.Text + "', " +582. unitPrice + ", " +

Page 134: Introduction to Computer Networks

583. discountRate + ", '" +584. cbxSaleStatus.Text + "');";585.586. // Generate a command to create a record587. OleDbCommand cmdStoreItems = new OleDbCommand(strSQLInsert, conFunDS);588.589. conFunDS.Open();590. cmdStoreItems.ExecuteNonQuery();591.592. // Once the item has been created, let the user know593. MessageBox.Show("The item has been created",594. "Fun Department Store",595. MessageBoxButtons.OK, MessageBoxIcon.Information);596.597. btnResetClicked(sender, e);598. }599. }600.601. private void btnClose_Click(object sender, EventArgs e)602. {603. Close();604. }

}

In the Solution Explorer, double-click Authenticator.cs

To create a new file, on the main menu, click Project -> Add New Item

In the middle list, make sure Code File is selected.Change the name to Employees

Click Add

In the empty document, type the following:

610. using System;611. using System.IO;612. using System.Data;613. using System.Drawing;614. using System.Data.OleDb;615. using System.Windows.Forms;616. using System.ComponentModel;617.618. public class Employees : Form619. {620. private ColumnHeader colEmployeeNumber;

Page 135: Introduction to Computer Networks

621. private ColumnHeader colFirstName;622. private ColumnHeader colLastName;623. private ColumnHeader colTitle;624. private ColumnHeader colManager;625. private ColumnHeader colHourlySalary;626. private ColumnHeader colUsername;627. private ColumnHeader colPassword;628. private ListView lvwEmployees;629.630. public GroupBox grpNewEmployee;631. private Label lblEmployeeNumber;632. private MaskedTextBox txtEmployeeNumber;633. private Label lblFirstName;634. private TextBox txtFirstName;635. private Label lblLastName;636. private TextBox txtLastName;637. private Label lblTitle;638. private TextBox txtTitle;639. private Button btnReset;640. private CheckBox chkManager;641. private Label lblHourlySalary;642. private TextBox txtHourlySalary;643. private Button btnSubmit;644. private Label lblUsername;645. private TextBox txtUsername;646. private Label lblPassword;647. private TextBox txtPassword;648. private Button btnClose;649.650. public Employees()651. {652. InitializeComponent();653. }654.655. private void InitializeComponent()656. {657. colEmployeeNumber = new ColumnHeader();658. colFirstName = new ColumnHeader();659. colLastName = new ColumnHeader();660. colTitle = new ColumnHeader();661. colManager = new ColumnHeader();662. colHourlySalary = new ColumnHeader();663. colUsername = new ColumnHeader();664. colPassword = new ColumnHeader();665. lvwEmployees = new ListView();666.667. grpNewEmployee = new GroupBox();668. lblEmployeeNumber = new Label();669. txtEmployeeNumber = new MaskedTextBox();670. lblFirstName = new Label();671. txtFirstName = new TextBox();672. lblLastName = new Label();673. txtLastName = new TextBox();674. lblTitle = new Label();675. txtTitle = new TextBox();676. btnReset = new Button();677. chkManager = new CheckBox();678. lblHourlySalary = new Label();679. txtHourlySalary = new TextBox();680. btnSubmit = new Button();681. lblUsername = new Label();

Page 136: Introduction to Computer Networks

682. txtUsername = new TextBox();683. lblPassword = new Label();684. txtPassword = new TextBox();685. btnClose = new Button();686.687. grpNewEmployee.SuspendLayout();688. SuspendLayout();689.690. colEmployeeNumber.Text = "Employee #";691. colEmployeeNumber.Width = 70;692.693. colFirstName.Text = "First Name";694. colFirstName.Width = 80;695.696. colLastName.Text = "Last Name";697. colLastName.Width = 80;698.699. colTitle.Text = "Title";700. colTitle.Width = 120;701.702. colManager.Text = "Manager";703.704. colHourlySalary.Text = "Salary";705. colHourlySalary.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;706. colHourlySalary.Width = 50;707.708. colUsername.Text = "Username";709.710. colPassword.Text = "Password";711.712. lvwEmployees.Columns.AddRange(new ColumnHeader[] {713. colEmployeeNumber, colFirstName, colLastName, colTitle,714. colManager, colHourlySalary, colUsername, colPassword});715. lvwEmployees.FullRowSelect = true;716. lvwEmployees.GridLines = true;717. lvwEmployees.Location = new Point(12, 12);718. lvwEmployees.Size = new Size(606, 191);719. lvwEmployees.TabIndex = 0;720. lvwEmployees.UseCompatibleStateImageBehavior = false;721. lvwEmployees.View = System.Windows.Forms.View.Details;722.723. grpNewEmployee.Controls.Add(lblEmployeeNumber);724. grpNewEmployee.Controls.Add(txtEmployeeNumber);725. grpNewEmployee.Controls.Add(lblFirstName);726. grpNewEmployee.Controls.Add(txtFirstName);727. grpNewEmployee.Controls.Add(lblLastName);728. grpNewEmployee.Controls.Add(txtLastName);729. grpNewEmployee.Controls.Add(lblTitle);730. grpNewEmployee.Controls.Add(txtTitle);731. grpNewEmployee.Controls.Add(btnReset);732. grpNewEmployee.Controls.Add(chkManager);733. grpNewEmployee.Controls.Add(lblHourlySalary);734. grpNewEmployee.Controls.Add(txtHourlySalary);735. grpNewEmployee.Controls.Add(btnSubmit);736. grpNewEmployee.Controls.Add(lblUsername);737. grpNewEmployee.Controls.Add(txtUsername);738. grpNewEmployee.Controls.Add(lblPassword);739. grpNewEmployee.Controls.Add(txtPassword);740. grpNewEmployee.Location = new Point(12, 209);741. grpNewEmployee.Size = new Size(605, 165);742. grpNewEmployee.TabIndex = 1;

Page 137: Introduction to Computer Networks

743. grpNewEmployee.TabStop = false;744. grpNewEmployee.Text = "New Employee";745.746. lblEmployeeNumber.AutoSize = true;747. lblEmployeeNumber.Location = new Point(42, 29);748. lblEmployeeNumber.Size = new Size(66, 13);749. lblEmployeeNumber.TabIndex = 0;750. lblEmployeeNumber.Text = "Employee #:";751.752. txtEmployeeNumber.Location = new Point(124, 26);753. txtEmployeeNumber.Mask = "00-000";754. txtEmployeeNumber.Size = new Size(52, 20);755. txtEmployeeNumber.TabIndex = 1;756.757. lblFirstName.AutoSize = true;758. lblFirstName.Location = new Point(42, 55);759. lblFirstName.Size = new Size(60, 13);760. lblFirstName.TabIndex = 2;761. lblFirstName.Text = "First Name:";762.763. txtFirstName.Location = new Point(124, 52);764. txtFirstName.Size = new Size(100, 20);765. txtFirstName.TabIndex = 3;766.767. lblLastName.AutoSize = true;768. lblLastName.Location = new Point(245, 55);769. lblLastName.Size = new Size(61, 13);770. lblLastName.TabIndex = 4;771. lblLastName.Text = "Last Name:";772.773. txtLastName.Location = new Point(327, 52);774. txtLastName.Name = "txtLastName";775. txtLastName.Size = new Size(100, 20);776. txtLastName.TabIndex = 5;777.778. lblTitle.AutoSize = true;779. lblTitle.Location = new Point(42, 81);780. lblTitle.Size = new Size(30, 13);781. lblTitle.TabIndex = 6;782. lblTitle.Text = "Title:";783.784. txtTitle.Location = new Point(124, 78);785. txtTitle.Name = "txtTitle";786. txtTitle.Size = new Size(303, 20);787. txtTitle.TabIndex = 7;788.789. btnReset.Location = new Point(447, 104);790. btnReset.Size = new Size(97, 23);791. btnReset.TabIndex = 15;792. btnReset.Text = "Reset";793. btnReset.UseVisualStyleBackColor = true;794. btnReset.Click += new System.EventHandler(btnResetClicked);795.796. chkManager.AutoSize = true;797. chkManager.CheckAlign = ContentAlignment.MiddleRight;798. chkManager.Location = new Point(45, 107);799. chkManager.Size = new Size(91, 17);800. chkManager.TabIndex = 8;801. chkManager.Text = "Is a Manager:";802. chkManager.UseVisualStyleBackColor = true;803.

Page 138: Introduction to Computer Networks

804. lblHourlySalary.AutoSize = true;805. lblHourlySalary.Location = new Point(245, 107);806. lblHourlySalary.Size = new Size(72, 13);807. lblHourlySalary.TabIndex = 9;808. lblHourlySalary.Text = "Hourly Salary:";809.810. txtHourlySalary.Location = new Point(327, 104);811. txtHourlySalary.Size = new Size(100, 20);812. txtHourlySalary.TabIndex = 10;813. txtHourlySalary.Text = "0.00";814. txtHourlySalary.TextAlign = HorizontalAlignment.Right;815.816. btnSubmit.Location = new Point(447, 132);817. btnSubmit.Size = new Size(97, 23);818. btnSubmit.TabIndex = 16;819. btnSubmit.Text = "Submit";820. btnSubmit.UseVisualStyleBackColor = true;821. btnSubmit.Click += new System.EventHandler(btnSubmitClicked);822.823. lblUsername.AutoSize = true;824. lblUsername.Location = new Point(42, 133);825. lblUsername.Size = new Size(58, 13);826. lblUsername.TabIndex = 11;827. lblUsername.Text = "Username:";828.829. txtUsername.Location = new Point(124, 130);830. txtUsername.Size = new Size(100, 20);831. txtUsername.TabIndex = 12;832.833. lblPassword.AutoSize = true;834. lblPassword.Location = new Point(245, 132);835. lblPassword.Size = new Size(56, 13);836. lblPassword.TabIndex = 13;837. lblPassword.Text = "Password:";838.839. txtPassword.Location = new Point(327, 130);840. txtPassword.PasswordChar = '*';841. txtPassword.Size = new Size(100, 20);842. txtPassword.TabIndex = 14;843.844. btnClose.Location = new Point(459, 384);845. btnClose.Size = new Size(97, 23);846. btnClose.TabIndex = 17;847. btnClose.Text = "Close";848. btnClose.UseVisualStyleBackColor = true;849. btnClose.Click += new System.EventHandler(btnCloseClicked);850.851. ClientSize = new Size(629, 414);852. Controls.Add(grpNewEmployee);853. Controls.Add(lvwEmployees);854. Controls.Add(btnClose);855. FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;856. MaximizeBox = false;857. MinimizeBox = false;858. ShowInTaskbar = false;859. StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;860. Text = "Fun Department Store - Employees";861. Load += new System.EventHandler(Employees_Load);862. grpNewEmployee.ResumeLayout(false);863. grpNewEmployee.PerformLayout();864. ResumeLayout(false);

Page 139: Introduction to Computer Networks

865.866. }867.868. private void ShowEmployees()869. {870. lvwEmployees.Items.Clear();871.872. // To connect to the database, after the following Data Source= expression,873. // type \\, followed by the name of the server (ours is named Expression),874. // followed by \\, followed by the name of the folder where the database 875. // is installed (ours is named Fun Department Store) (of course, you must876. // have shared that folder), followed by \\, and followed by the name of877. // the database, in this case FunDS878. using (OleDbConnection conFunDS =879. new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;" +880. @"Data Source=\\Expression\\Fun Department Store\\FunDS.accdb"))881. {882. // Select all store items883. OleDbCommand cmdFunDS = new OleDbCommand("SELECT * FROM Employees;", conFunDS);884.885. OleDbDataAdapter odaFunDS = new OleDbDataAdapter(cmdFunDS);886. DataSet dsEmployees = new DataSet("EmployeesSet");887. odaFunDS.Fill(dsEmployees);888.889. conFunDS.Open();890.891. // Using the total number of records, display each in the list view892. for (int i = 0; i < dsEmployees.Tables[0].Rows.Count; i++)893. {894. DataRow rcdEmployee = dsEmployees.Tables[0].Rows[i];895.896. ListViewItem lviEmployee = new ListViewItem((i + 1).ToString());897. lviEmployee.SubItems.Add(rcdEmployee["employeeNumber"].ToString());898. lviEmployee.SubItems.Add(rcdEmployee["FirstName"].ToString());899. lviEmployee.SubItems.Add(rcdEmployee["LastName"].ToString());900. lviEmployee.SubItems.Add(rcdEmployee["Title"].ToString());901. lviEmployee.SubItems.Add(rcdEmployee["Manager"].ToString());902. lviEmployee.SubItems.Add(rcdEmployee["HourlySalary"].ToString());903. lviEmployee.SubItems.Add(rcdEmployee["Username"].ToString());904. lviEmployee.SubItems.Add(rcdEmployee["UserPassword"].ToString());905. lvwEmployees.Items.Add(lviEmployee);906. }907. }908. }909.910. private void Employees_Load(object sender, EventArgs e)911. {912. ShowEmployees();913. btnResetClicked(sender, e);914. }915.916. private void btnResetClicked(object sender, EventArgs e)917. {918. Random rndNumber = new Random();919.920. txtEmployeeNumber.Text = rndNumber.Next(10000, 99999).ToString();921. txtFirstName.Text = "";922. txtLastName.Text = "";923. txtTitle.Text = "";924. chkManager.Checked = false;925. txtHourlySalary.Text = "0.00";

Page 140: Introduction to Computer Networks

926. txtUsername.Text = "";927. txtPassword.Text = "";928. }929.930. private void btnSubmitClicked(object sender, EventArgs e)931. {932. double hourlySalary = 0.00;933.934. try935. {936. hourlySalary = double.Parse(txtHourlySalary.Text);937. }938. catch (FormatException)939. {940. }941.942. // Connect to the database943. // To connect to the database, after the following Data Source= expression,944. // type \\, followed by the name of the server (ours is named Expression),945. // followed by \\, followed by the name of the folder where the database 946. // is installed (ours is named Fun Department Store) (of course, you must947. // have shared that folder), followed by \\, and followed by the name of948. // the database, in this case FunDS949. using (OleDbConnection conFunDS =950. new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;" +951. @"Data Source=\\Expression\\Fun Department Store\\FunDS.accdb"))952. {953. string strSQLInsert = "INSERT INTO Employees(EmployeeNumber, FirstName, " +954. "LastName, Title, Manager, HourlySalary, " +955. "Username, UserPassword) VALUES('" +956. txtEmployeeNumber.Text + "', '" +957. txtFirstName.Text + "', '" +958. txtLastName.Text + "', '" +959. txtTitle.Text + "', " +960. chkManager.Checked + ", " +961. hourlySalary + ", '" +962. txtUsername.Text + "', '" +963. txtPassword.Text + "');";964.965. // Generate a command to create a record966. OleDbCommand cmdEmployees = new OleDbCommand(strSQLInsert, conFunDS);967.968. conFunDS.Open();969. cmdEmployees.ExecuteNonQuery();970.971. MessageBox.Show("The employee has been created.",972. "Fun Department Store",973. MessageBoxButtons.OK, MessageBoxIcon.Information);974.975. btnResetClicked(sender, e);976. }977. }978.979. private void btnCloseClicked(object sender, EventArgs e)980. {981. Close();982. }

}

Save all

Page 141: Introduction to Computer Networks

Contextual Access

We refer to contextual the ability to grant access or some operations to one or more objects of an application to one or more people. This may sound complicated but it really is not. Or the real difficulty lies, not in programming, but in logic and organization (design). One way to solve the problem would consist of making a list of objects in your application, another list of people in your organization, then specify who will have access to what and who would be denied access to what. This would work perfectly fine in a small organization and a small application that hardly changes, but this may not be practical in larger scenarios. Another solution consists of creating groups of people, adding people to those groups, and then deciding what group has access to what.

In this example, we will use a field of the Employees table to identify who can have access to the form used to create a new store

Practical Learning: Implementing Contextual Access

Display the Switchboard.cs file

Change the file as follows:

using System;using System.Data;using System.Drawing;using System.Data.OleDb;using System.Windows.Forms;using System.ComponentModel;

public class Switchboard : Form{ private Button btnStoreInventory; private Button btnCreateStoreItem; private Button btnEmployees; private Button btnLogInUser; private Button btnClose;

private bool employeeIsAManager;

public Switchboard() { InitializeComponent(); }

private void InitializeComponent() { btnStoreInventory = new Button(); btnCreateStoreItem = new Button(); btnEmployees = new Button(); btnLogInUser = new Button(); btnClose = new Button();

SuspendLayout();

btnStoreInventory.Font = new Font("Georgia", 18F, FontStyle.Bold, GraphicsUnit.Point, 0); btnStoreInventory.Location = new Point(11, 12); btnStoreInventory.Size = new Size(227, 98); btnStoreInventory.TabIndex = 21; btnStoreInventory.Text = "View Store Inventory"; btnStoreInventory.UseVisualStyleBackColor = true; btnStoreInventory.Click += new System.EventHandler(btnStoreInventoryClicked);

btnCreateStoreItem.Font = new Font("Georgia", 18F, FontStyle.Bold, GraphicsUnit.Point, 0);

Page 142: Introduction to Computer Networks

btnCreateStoreItem.Location = new Point(253, 12); btnCreateStoreItem.Size = new Size(227, 98); btnCreateStoreItem.TabIndex = 23; btnCreateStoreItem.Text = "Create Store Item"; btnCreateStoreItem.UseVisualStyleBackColor = true; btnCreateStoreItem.Click += new System.EventHandler(btnCreateStoreItemClicked);

btnEmployees.Font = new Font("Georgia", 18F, FontStyle.Bold, GraphicsUnit.Point, 0); btnEmployees.Location = new Point(10, 128); btnEmployees.Size = new Size(227, 98); btnEmployees.TabIndex = 25; btnEmployees.Text = "Employees"; btnEmployees.UseVisualStyleBackColor = true; btnEmployees.Click += new System.EventHandler(btnEmployeesClicked);

btnLogInUser.Font = new Font("Georgia", 18F, FontStyle.Bold, GraphicsUnit.Point, 0); btnLogInUser.Location = new Point(254, 128); btnLogInUser.Size = new Size(227, 98); btnLogInUser.TabIndex = 24; btnLogInUser.Text = "Log in as a Different Employee"; btnLogInUser.UseVisualStyleBackColor = true; btnLogInUser.Click += new System.EventHandler(btnLogInUserClicked);

btnClose.Font = new Font("Georgia", 18F, FontStyle.Bold, GraphicsUnit.Point, 0); btnClose.Location = new Point(10, 243); btnClose.Size = new Size(470, 66); btnClose.TabIndex = 22; btnClose.Text = "Close Application"; btnClose.UseVisualStyleBackColor = true; btnClose.Click += new System.EventHandler(btnCloseClicked);

ClientSize = new Size(493, 323); Controls.Add(btnEmployees); Controls.Add(btnLogInUser); Controls.Add(btnCreateStoreItem); Controls.Add(btnClose); Controls.Add(btnStoreInventory);

StartPosition = FormStartPosition.CenterScreen; Text = "Fun Department Store - Switchboard"; Load += new System.EventHandler(SwitchboardLoaded); ResumeLayout(false);

}

private void btnStoreInventoryClicked(object sender, EventArgs e) { StoreInventory si = new StoreInventory(); si.ShowDialog(); }

private void btnCloseClicked(object sender, EventArgs e) {

100. Close();101. }102.103. private void LogInToTheApplication()104. {105. bool usernamePasswordMatch = false;106. bool currentEmployeeIsManager = false;

Page 143: Introduction to Computer Networks

107. Authenticator dlgLogIn = new Authenticator();108. string strPasswordFromDialogBox = "", strPasswordFromDatabase = "";109. string strUsernameFromDialogBox = "", strUsernameFromDatabase = "";110.111. // Display the Autheticator dialog box.112. // If the user clicks Cancel, simply close the application113. if (dlgLogIn.ShowDialog() == System.Windows.Forms.DialogResult.Cancel)114. Close();115. else // If the user clicks OK116. {117. // If the employee doesn't enter a username, display a message box...118. if (dlgLogIn.txtUsername.Text == "")119. {120. MessageBox.Show("You must enter a user name.",121. "Fun Department Store",122. MessageBoxButtons.OK, MessageBoxIcon.Information);123. // ... and close the application124. Close();125. }126.127. // If the employee doesn't enter a password, display a message box...128. if (dlgLogIn.txtPassword.Text == "")129. {130. MessageBox.Show("You must type a password.",131. "Fun Department Store",132. MessageBoxButtons.OK, MessageBoxIcon.Information);133. // ... and close the application134. Close();135. }136.137. // Get the user name of the dialog box138. strUsernameFromDialogBox = dlgLogIn.txtUsername.Text;139. // Get the password of the dialog box140. strPasswordFromDialogBox = dlgLogIn.txtPassword.Text;141.142. // To connect to the database, after the following Data Source= expression,143. // type \\, followed by the name of the server (ours is named Expression),144. // followed by \\, followed by the name of the folder where the database 145. // is installed (ours is named Fun Department Store) (of course, you must146. // have shared that folder), followed by \\, and followed by the name of147. // the database, in this case FunDS148. using (OleDbConnection conFunDS =149. new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;" +150. @"Data Source=\\Expression\\Fun Department Store\\FunDS.accdb"))151. {152. // Get the records of all employees153. OleDbCommand cmdFunDS = new OleDbCommand("SELECT * FROM Employees;", conFunDS);154.155. // Create a data adapater to retrieve the employees156. OleDbDataAdapter odaEmployees = new OleDbDataAdapter(cmdFunDS);157. // Create a data set of employees158. DataSet dsEmployees = new DataSet("EmployeesSet");159. // Fill the data set with the Employees records160. odaEmployees.Fill(dsEmployees);161.162. // Open the connection163. conFunDS.Open();164.165. // Navigate to each record166. for (int i = 0; i < dsEmployees.Tables[0].Rows.Count; i++)167. {

Page 144: Introduction to Computer Networks

168. // Get a reference to the current record169. DataRow rcdEmployee = dsEmployees.Tables[0].Rows[i];170.171. // Get the managing status of the employee172. currentEmployeeIsManager = bool.Parse(rcdEmployee["Manager"].ToString());173. // When you are on a record, get the username of the employee174. strUsernameFromDatabase = rcdEmployee["Username"].ToString();175. // and the password176. strPasswordFromDatabase = rcdEmployee["UserPassword"].ToString();177.178. // Compare the current username to the username of the dialog box179. // and the current password to the password of the dialog box.180. // If they match, ...181. if (strUsernameFromDatabase.Equals(strUsernameFromDialogBox) &&182. strPasswordFromDatabase.Equals(strPasswordFromDialogBox))183. {184. usernamePasswordMatch = true;185.186. // Find out whether this employee is a manager.187. // If so, make a reference...188. if (currentEmployeeIsManager == true)189. employeeIsAManager = true;190. else191. employeeIsAManager = false;192.193. // ... and stop searching194. break;195. }196.197. // If there is no match, continue to the next record, 198. // up to the end of the table199. }200.201. // If there was a match for username/password, display the Switchboard202.203. // If there was no match for username/password, 204. // Let the employee know ...205. if (usernamePasswordMatch == false)206. {207. MessageBox.Show("The username and password combination did " +208. "not match any of the employees",209. "Fun Department Store",210. MessageBoxButtons.OK, MessageBoxIcon.Information);211. // ... and close the application212. Close();213. }214. }215. }216. }217.218. private void LogInAsADifferentEmployee()219. {220. bool currentEmployeeIsManager = false;221. bool usernamePasswordMatch = false;222. Authenticator dlgLogIn = new Authenticator();223. string strPasswordFromDialogBox = "", strPasswordFromDatabase = "";224. string strUsernameFromDialogBox = "", strUsernameFromDatabase = "";225.226. // Display the Autheticator dialog box.227. // If the user clicks Cancel, simply close the application228. if (dlgLogIn.ShowDialog() == System.Windows.Forms.DialogResult.Cancel)

Page 145: Introduction to Computer Networks

229. return;230. else // If the user clicks OK231. {232. // If the employee doesn't enter a username, display a message box...233. if (dlgLogIn.txtUsername.Text == "")234. MessageBox.Show("You must enter a user name.",235. "Fun Department Store",236. MessageBoxButtons.OK, MessageBoxIcon.Information);237.238. // If the employee doesn't enter a password, display a message box...239. if (dlgLogIn.txtPassword.Text == "")240. MessageBox.Show("You must type a password.",241. "Fun Department Store",242. MessageBoxButtons.OK, MessageBoxIcon.Information);243.244. // Get the user name of the dialog box245. strUsernameFromDialogBox = dlgLogIn.txtUsername.Text;246. // Get the password of the dialog box247. strPasswordFromDialogBox = dlgLogIn.txtPassword.Text;248.249. // To connect to the database, after the following Data Source= expression,250. // type \\, followed by the name of the server (ours is named Expression),251. // followed by \\, followed by the name of the folder where the database 252. // is installed (ours is named Fun Department Store) (of course, you must253. // have shared that folder), followed by \\, and followed by the name of254. // the database, in this case FunDS255. using (OleDbConnection conFunDS =256. new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;" +257. @"Data Source=\\Expression\\Fun Department Store\\FunDS.accdb"))258. {259. // Get the records of all employees260. OleDbCommand cmdFunDS = new OleDbCommand("SELECT * FROM Employees;", conFunDS);261.262. // Create a data adapater to retrieve the employees263. OleDbDataAdapter odaEmployees = new OleDbDataAdapter(cmdFunDS);264. // Create a data set of employees265. DataSet dsEmployees = new DataSet("EmployeesSet");266. // Fill the data set with the Employees records267. odaEmployees.Fill(dsEmployees);268.269. // Open the connection270. conFunDS.Open();271.272. // Navigate to each record273. for (int i = 0; i < dsEmployees.Tables[0].Rows.Count; i++)274. {275. // Get a reference to the current record276. DataRow rcdEmployee = dsEmployees.Tables[0].Rows[i];277.278. // Get the managing status of the employee279. currentEmployeeIsManager = bool.Parse(rcdEmployee["Manager"].ToString());280. // When you are on a record, get the username of the employee281. strUsernameFromDatabase = rcdEmployee["Username"].ToString();282. // and the password283. strPasswordFromDatabase = rcdEmployee["UserPassword"].ToString();284.285. // Compare the current username to the username of the dialog box286. // and the current password to the password of the dialog box.287. // If they match, ...288. if (strUsernameFromDatabase.Equals(strUsernameFromDialogBox) &&289. strPasswordFromDatabase.Equals(strPasswordFromDialogBox))

Page 146: Introduction to Computer Networks

290. {291. usernamePasswordMatch = true;292.293. // Find out whether this employee is a manager.294. // If so, make a reference.295. if (currentEmployeeIsManager == true)296. employeeIsAManager = true;297. else298. employeeIsAManager = false;299.300. // ... display the switchboard301. break;302. }303.304. // If there is no match, continue to the next record, 305. // up to the end of the table306. }307.308. // If there was a match for username/password, display the Switchboard309.310. // If there was no match for username/password, 311. // Let the employee know ...312. if (usernamePasswordMatch == false)313. {314. MessageBox.Show("The username and password combination did " +315. "not match any of the employees",316. "Fun Department Store",317. MessageBoxButtons.OK, MessageBoxIcon.Information);318.319. return;320. }321. }322. }323. }324.325. private void SwitchboardLoaded(object sender, EventArgs e)326. {327. employeeIsAManager = false;328. LogInToTheApplication();329. }330.331. private void btnCreateStoreItemClicked(object sender, EventArgs e)332. {333. CreateStoreItem csi = new CreateStoreItem();334.335. // Using the global canCreateStoreItem variable, find out336. // whether the current user is a manager.337. // If the user is, then display the Create Store Item form338. if (employeeIsAManager == true)339. csi.ShowDialog();340. else // If the user is not, diaplay a message box341. MessageBox.Show("You are not authorized to create store items.",342. "Fun Department Store",343. MessageBoxButtons.OK, MessageBoxIcon.Information);344. }345.346. private void btnLogInUserClicked(object sender, EventArgs e)347. {348. LogInAsADifferentEmployee();349. }350.

Page 147: Introduction to Computer Networks

351. private void btnEmployeesClicked(object sender, EventArgs e)352. {353. Employees staff = new Employees();354.355. // If the user is a manager, enable the controls in the group box.356. if (employeeIsAManager == true)357. staff.grpNewEmployee.Enabled = true;358. else // Otherwise, disable them359. staff.grpNewEmployee.Enabled = false;360.361. staff.ShowDialog();362. }363. }364.365. public class DepartmentStore366. {367. public static int Main()368. {369. Application.Run(new Switchboard());370. return 0;371. }

}

To test the application, press F5

When the dialog box comes up, click Cancel. Notice that the application did not continue

Execute the application again

When the dialog box displays, type the user name as stanley and press Enter

Type the password as Password5 and press Enter

Read the message box and press Enter

Execute the application again

Type the username as mtownsend and press Tab

Type the password as Password5 and pass Enter

Click View Store Inventory

Close the form

Click Create Store Item

Page 148: Introduction to Computer Networks

Read the message and click OK

Click Log in as a Different Employees

In the username of the dialog box, type msamson and press Tab

Type the password as password16 and press Enter

Click Employees

Page 149: Introduction to Computer Networks

Close the Employees form

Click Log in as a Different Employees

In the username of the dialog box, type msamson and press Tab

Type the password as Password6 and press Enter

Click Create Store Item

Enter some values for the record

Click Create

Page 150: Introduction to Computer Networks

Read the message box and click OK

Close the form

Click Employees

Page 151: Introduction to Computer Networks

Close the Employees form

Click Log in as a Different Employees

Click Cancel

Click Log in as a Different Employees

In the username of the dialog box, type kdavids and press Tab

Type the password as Password9 and press Enter

Click View Store Inventory

 

Introduction to Microsoft Access

Introduction

One of the types of applications you can use on a network is a database. A database makes it possible in an intranet to have a central location of information so that any computer on the same network can access the database.

Probably the most common type of database used in a Microsoft Windows network is one of a Microsoft Access type. Fortunately, it is not particularly difficult to create and distribute a database on an intranet.

Creating a Database

Of course, to create a Microsoft Access database, you must have Microsoft Access:

This article will not teach Microsoft Access. If you need to study databases with Microsoft Access, we have a different web site for it

You don't need to know anything about Microsoft Access to do this exercise

When you create a Microsoft Access database, you should pay attention to the version you want that database to have. If you have

Page 152: Introduction to Computer Networks

computers that still use Microsoft Access 97, Microsoft Access 2000, Microsoft Access 2002, or Microsoft Access 2003, the database should have the extension .mdb. If you are creating the database using either Microsoft Access 2007 or Microsoft Access 2010, you can ask it to save the database in a version that is compatible with previous versions. To do that:

In Microsoft Access 2007, if you are starting a database, when giving it a name, add the file extension .mdb (if you don't add the extionsion, accdb will be used automatically)

In Microsoft Access 2007, if you have already created the database, to convert it to a previous version, click the Office Button, position the mouse on Save As, and click Access 2000 Database

Page 153: Introduction to Computer Networks

If you are using Microsoft Access 2010, when creating a database, when giving it a name, add the file extension .mdb (if you don't add the extionsion, accdb will be used automatically)

Page 154: Introduction to Computer Networks

Distributing the Database

When it comes to distributing a Microsoft Access database, you may have some issues to deal with, not because it is difficult. One of the concerns has to do with the other computers. If the other computers don't have Microsoft Access, you would need something called the Access Runtime. This is probably the cheapest solution but it may present some challenges. We will not deal with that here.

Another solution is to install Microsoft Access on each computer. This may be the most expensive solution but it is the easiest. Most companies use that solution because it is easy either to purchase many copies or get many licenses of Microsoft Office Professional, which includes Microsoft Access.

If you want to follow the instructions in this exercise, you can use our Bethesda Car Rental database.

To start, using a USB drive or any other way (CD, DVD, etc), copy your database to that portable drive

In the server or the computer of your choice (normally, the database can be located on any computer that is a member of your network) where you want the database to be located, create a folder. For our example, we create a folder named common

Copy the database file into that folder 

Page 155: Introduction to Computer Networks

Access the drive that holds that folder.To share it, right-click it and click Share (this is a screenshot from Microsoft Windows Server 2008) 

Click the arrow of the combo box in the File Sharing window and select Everyone: 

Page 156: Introduction to Computer Networks

After selecting Everyone, click Add

Click the down-pointing arrow on the right side of Everyone:

o If you are sharing from Microsoft Windows Server 2008, select Contributor 

Page 157: Introduction to Computer Networks

o If you are sharing from Microsoft Windows 7, select Read/Write 

Click Share. If you receive a message box, click Continue.You should receive a message box telling that the sharing was successful 

Page 158: Introduction to Computer Networks

Click Close

In another computer where you want to access the database, open a file utility such as Windows Explorer

Click Network

Click the name of the computer to show its shared folders: 

Page 159: Introduction to Computer Networks

Open the folder that contains the database

Right-click the name of the database, position the mouse on Send To, and click Desktop (Create Shortcut) 

Page 160: Introduction to Computer Networks

 

Creating a Client Server Application

IntroductionA client/server application is an application that uses a central place to store its values (or records) but is (or can be) accessed from one or more computers. It allows many people to use the same application. There are various types of client/server applications, including flat-file applications, databases, and web-based applications.

Just like there are various types of applications, there are also different techniques or means of creating them. For this example, we will use Microsoft Visual Studio 2010 to create a file-based applications (you could also use Microsoft Visual C# 2010 Express, which is freely downloadable

  

Page 161: Introduction to Computer Networks

from the Microsoft web site).

Creating the Application

We will create a fictitious application used by a car rental company. It will have a list of customers who rent cars, a list of employees who can perform the transactions, and a list of cars to be rented. The records will be kept in different files. Some time to time, a customer will want to rent a car or a customer will bring back a car. This will be done as order processing.

As mentioned already, the records will be kept in files. All the files used in this application will be in a specific folder. As the network administrator, you should create thi folder before it can eb used. Because this is a networked folder, you should also share it.

For this application, we will use a folder named Bethesda Car Rental in the C: drive of a server named EXPRESSION. If you want to use a different folder, in our code, change that name.

To share the folder used in this application, after creating it, right-click it and click Share... In the combo box, select Everyone and click Add. Click the arrow button of Reader and click Contributor:

Click Share:

Page 162: Introduction to Computer Networks

 

Practical Learning: Starting the Application

Copy the following pictures to any folder somewhere on your computer (this is simply an example of preparing the pictures of cars you would include in your application):

BMW: 335i Chevrolet Avalanche

Honda Accord Mazda Miata

Page 163: Introduction to Computer Networks

Chevrolet Aveo Ford E150XL

Buick Lacrosse Honda Civic

Ford F-150 Mazda Mazda5

Volvo S40 Land Rover LR3

Start Microsoft Visual Studio

To create a new application, on the main menu, click File -> New Project...

If you are using Microsoft Visual Studio, in the left list, click Visual C#. In the middle list, click Windows Forms Application

Change the name to BethesdaCarRental1

Page 164: Introduction to Computer Networks

Click OK

In the Solution Explorer, right-click Form1.cs and click Rename

Central.cs and press Enter twice

Design the form as follows:

Page 165: Introduction to Computer Networks

 

Networking: Time Sheet

Introduction

A time sheet is a list of time values worked by an employee in a time frame, such as a week, two weeks, or a month. To provide a time sheet to your users, you have various options. First you must create a form that holds the controls a user would use to enter the time worked. That aspect is obvious.

One of the real aspects you should think of is how the users would access the time sheet. You can simply let them open the form, but the user must be identified. Once againg you have many options. If you are using an application for which a user must be authenticated before using, you can catch the employee number or the name of the employee. Another way is to ask a user to enter his or her employee number in a text box and look for that employee's record in the company.

Another aspect you should (must) take care of is to find out if an employee is creating a new time sheet or updating an existing time sheet:

If the employee is creating a new time sheet, you would get the values and create a new record

If the employee is updating his or her time sheet, you must first look for that time sheet in the records. If the record is found, grab the values the user entered and replace those in the existing time sheet

A question is, who will determine whether the user is creating a new time sheet or updating an existing time sheet? The answer to this depends on how you decide to implement the time sheet.

Practical Learning: Creating a Time Sheet TableThis article continues from that of Authentication. This means that you must have created a folder namedDepartment Store, shared it, and created a database named FunDS in that folder. The database contains a table named Employees.

Page 166: Introduction to Computer Networks

Start  Microsoft Access

Open the FunDS database

On the Ribbon, click Create

In the Tables section, click Table Design

Create the following fields 

Field Name Data Type Field Size Format Caption Other Properties

TimeSheetID AutoNumber     Time Sheet ID Primary Key

EmployeeNumber   20   Employee #  

StartDate Date/Time     Start Date  

TimeSheetCode   40   Time Sheet Code Required: Yes

Week1Monday Number Double Fixed Monday Default Value = 0

Week1Tuesday Number Double Fixed Tuesday Default Value = 0

Week1Wednesday Number Double Fixed Wednesday Default Value = 0

Week1Thursday Number Double Fixed Thursday Default Value = 0

Week1Friday Number Double Fixed Friday Default Value = 0

Week1Saturday Number Double Fixed Saturday Default Value = 0

Week1Sunday Number Double Fixed Sunday Default Value = 0

Week2Monday Number Double Fixed Monday Default Value = 0

Week2Tuesday Number Double Fixed Tuesday Default Value = 0

Week2Wednesday Number Double Fixed Wednesday Default Value = 0

Week2Thursday Number Double Fixed Thursday Default Value = 0

Week2Friday Number Double Fixed Friday Default Value = 0

Week2Saturday Number Double Fixed Saturday Default Value = 0

Week2Sunday Number Double Fixed Sunday Default Value = 0

Notes Memo        

To change the view, right-click the tab of the table and click Datasheet View

When asked to save it, set its name to TimeSheets

Close the Time Sheets table

Close Microsoft Access

Practical Learning: Implementing a Time Sheet

Start Microsoft Visual Studio

To create a new application, on the main menu, click File -> New Project...

If you are using Microsoft Visual Stuio, in the left frame, click Visual C# Projects.In the middle list, click Empty Project

Set the Name to FunDepartmentStore2

Click OK

On the main menu, click Project -> FunDepartmentStore2 Properties...

In the Output Type combo box, select Windows Application

Close the Properties window

On the main menu, click Project -> Add Reference...

10. In the Add Reference dialog box, click .NET

Page 167: Introduction to Computer Networks

11. In the list view, click System.Data

12. Press and hold Ctrl

13. Click System

14. Click System.Drawing

15. Click System.Windows.Forms

16. Click System.Xml

17. Release Ctrl

18. Click OK

19. To create a file for the project, on the main menu, click Project -> Add New Item...

20. In the middle list, click Code File

21. Set the Name to CreateTimeSheet

22. Click Add

23. In the empty document, type the following:

24. using System;25. using System.Data;26. using System.Drawing;27. using System.Data.OleDb;28. using System.Windows.Forms;29. using System.ComponentModel;30.31. public class TimeSheet : Form32. {33. private Label lblIdentification;34. private Panel pnlTopLine;35. private Label lblEmployeeNumber;36. private MaskedTextBox txtEmployeeNumber;37. private TextBox txtEmployeeName;38. private Label lblStartDate;39. private DateTimePicker dtpStartDate;40. private Label lblEndDate;41. private DateTimePicker dtpEndDate;42. private TextBox txtTimeSheetCode;43. private Panel pnlSecondLine;44. private Label lblTimeRecording;45. private Label lblMonday;46. private Label lblTuesday;47. private Label lblWednesday;48. private Label lblSaturday;49. private Label lblFriday;50. private Label lblThursday;51. private Label lblSunday;52. private Label lblWeek1;53. private TextBox txtWeek1Monday;54. private TextBox txtWeek1Tuesday;55. private TextBox txtWeek1Wednesday;56. private TextBox txtWeek1Thursday;57. private TextBox txtWeek1Friday;58. private TextBox txtWeek1Saturday;59. private TextBox txtWeek1Sunday;60. private Label lblWeek2;61. private TextBox txtWeek2Monday;62. private TextBox txtWeek2Tuesday;63. private TextBox txtWeek2Wednesday;

Page 168: Introduction to Computer Networks

64. private TextBox txtWeek2Thursday;65. private TextBox txtWeek2Friday;66. private TextBox txtWeek2Saturday;67. private TextBox txtWeek2Sunday;68. private Label lblNotes;69. private TextBox txtNotes;70. private Panel pnlBottomLine;71. private Button btnReset;72. private Button btnSubmit;73. private Button btnClose;74.75. public TimeSheet()76. {77. InitializeComponent();78. }79.80. private void InitializeComponent()81. {82. lblIdentification = new Label();83. pnlTopLine = new Panel();84. lblEmployeeNumber = new Label();85. txtEmployeeNumber = new MaskedTextBox();86. txtEmployeeName = new TextBox();87. lblStartDate = new Label();88. dtpStartDate = new DateTimePicker();89. lblEndDate = new Label();90. dtpEndDate = new DateTimePicker();91. txtTimeSheetCode = new TextBox();92. pnlSecondLine = new Panel();93. lblTimeRecording = new Label();94. lblMonday = new Label();95. lblTuesday = new Label();96. lblWednesday = new Label();97. lblSaturday = new Label();98. lblFriday = new Label();99. lblThursday = new Label();100. lblSunday = new Label();101. lblWeek1 = new Label();102. txtWeek1Monday = new TextBox();103. txtWeek1Tuesday = new TextBox();104. txtWeek1Wednesday = new TextBox();105. txtWeek1Thursday = new TextBox();106. txtWeek1Friday = new TextBox();107. txtWeek1Saturday = new TextBox();108. txtWeek1Sunday = new TextBox();109. lblWeek2 = new Label();110. txtWeek2Monday = new TextBox();111. txtWeek2Tuesday = new TextBox();112. txtWeek2Wednesday = new TextBox();113. txtWeek2Thursday = new TextBox();114. txtWeek2Friday = new TextBox();115. txtWeek2Saturday = new TextBox();116. txtWeek2Sunday = new TextBox();117. lblNotes = new Label();118. txtNotes = new TextBox();119. pnlBottomLine = new Panel();120. btnReset = new Button();121. btnSubmit = new Button();122. btnClose = new Button();123. SuspendLayout();124.

Page 169: Introduction to Computer Networks

125. lblIdentification.BackColor = Color.FromArgb(64, 64, 64);126. lblIdentification.Font = new Font("Tiffany Lt BT", 12F, FontStyle.Bold, GraphicsUnit.Point,0);127. lblIdentification.ForeColor = Color.White;128. lblIdentification.Location = new Point(12, 11);129. lblIdentification.Size = new Size(141, 19);130. lblIdentification.TabIndex = 0;131. lblIdentification.Text = "Identification";132.133. pnlTopLine.BackColor = Color.FromArgb(64, 64, 64);134. pnlTopLine.Location = new Point(124, 28);135. pnlTopLine.Size = new Size(444, 2);136. pnlTopLine.TabIndex = 1;137.138. lblEmployeeNumber.AutoSize = true;139. lblEmployeeNumber.Location = new Point(130, 42);140. lblEmployeeNumber.Size = new Size(66, 13);141. lblEmployeeNumber.TabIndex = 2;142. lblEmployeeNumber.Text = "Employee #:";143.144. txtEmployeeNumber.Location = new Point(211, 39);145. txtEmployeeNumber.Mask = "00-000";146. txtEmployeeNumber.Size = new Size(52, 20);147. txtEmployeeNumber.TabIndex = 3;148. txtEmployeeNumber.Leave += new System.EventHandler(txtEmployeeNumberLeave);149. 150. txtEmployeeName.Location = new Point(269, 39);151. txtEmployeeName.Size = new Size(142, 20);152. txtEmployeeName.TabIndex = 37;153.154. dtpEndDate.Location = new Point(211, 101);155. dtpEndDate.Size = new Size(200, 20);156. dtpEndDate.TabIndex = 39;157.158. lblEndDate.AutoSize = true;159. lblEndDate.Location = new Point(130, 107);160. lblEndDate.Size = new Size(55, 13);161. lblEndDate.TabIndex = 38;162. lblEndDate.Text = "End Date:";163.164. lblStartDate.AutoSize = true;165. lblStartDate.Location = new Point(130, 73);166. lblStartDate.Size = new Size(58, 13);167. lblStartDate.TabIndex = 4;168. lblStartDate.Text = "Start Date:";169.170. dtpStartDate.Location = new Point(211, 70);171. dtpStartDate.Size = new Size(200, 20);172. dtpStartDate.TabIndex = 5;173. dtpStartDate.CloseUp += new System.EventHandler(dtpStartDateClosedUp);174.175. txtTimeSheetCode.Enabled = false;176. txtTimeSheetCode.Location = new Point(420, 100);177. txtTimeSheetCode.Size = new Size(132, 20);178. txtTimeSheetCode.TabIndex = 40;179.180.181. pnlSecondLine.BackColor = Color.FromArgb(64, 64, 64);182. pnlSecondLine.Location = new Point(150, 154);183. pnlSecondLine.Size = new Size(415, 2);184. pnlSecondLine.TabIndex = 7;185.

Page 170: Introduction to Computer Networks

186. lblTimeRecording.BackColor = Color.FromArgb(64, 64, 64);187. lblTimeRecording.Font = new Font("Tiffany Lt BT", 12F, FontStyle.Bold, GraphicsUnit.Point,0);188. lblTimeRecording.ForeColor = Color.White;189. lblTimeRecording.Location = new Point(12, 134);190. lblTimeRecording.Size = new Size(141, 22);191. lblTimeRecording.TabIndex = 6;192. lblTimeRecording.Text = "Time Recording";193.194. lblMonday.AutoSize = true;195. lblMonday.Location = new Point(72, 174);196. lblMonday.Size = new Size(45, 13);197. lblMonday.TabIndex = 8;198. lblMonday.Text = "Monday";199.200. lblTuesday.AutoSize = true;201. lblTuesday.Location = new Point(141, 174);202. lblTuesday.Size = new Size(48, 13);203. lblTuesday.TabIndex = 9;204. lblTuesday.Text = "Tuesday";205. 206. lblWednesday.AutoSize = true;207. lblWednesday.Location = new Point(212, 174);208. lblWednesday.Size = new Size(64, 13);209. lblWednesday.TabIndex = 10;210. lblWednesday.Text = "Wednesday";211.212. lblThursday.AutoSize = true;213. lblThursday.Location = new Point(279, 174);214. lblThursday.Name = "lblThursday";215. lblThursday.Size = new Size(51, 13);216. lblThursday.TabIndex = 11;217. lblThursday.Text = "Thursday";218.219. lblFriday.AutoSize = true;220. lblFriday.Location = new Point(348, 174);221. lblFriday.Size = new Size(35, 13);222. lblFriday.TabIndex = 12;223. lblFriday.Text = "Friday";224.225. lblSaturday.AutoSize = true;226. lblSaturday.Location = new Point(417, 174);227. lblSaturday.Size = new Size(49, 13);228. lblSaturday.TabIndex = 13;229. lblSaturday.Text = "Saturday";230. 231. lblSunday.AutoSize = true;232. lblSunday.Location = new Point(495, 174);233. lblSunday.Size = new Size(43, 13);234. lblSunday.TabIndex = 14;235. lblSunday.Text = "Sunday";236. 237. lblWeek1.AutoSize = true;238. lblWeek1.Location = new Point(12, 197);239. lblWeek1.Size = new Size(48, 13);240. lblWeek1.TabIndex = 15;241. lblWeek1.Text = "Week 1:";242.243. txtWeek1Monday.Location = new Point(75, 194);244. txtWeek1Monday.Size = new Size(63, 20);245. txtWeek1Monday.TabIndex = 16;246. txtWeek1Monday.Text = "0.00";

Page 171: Introduction to Computer Networks

247. txtWeek1Monday.TextAlign = HorizontalAlignment.Right;248.249. txtWeek1Tuesday.Location = new Point(144, 194);250. txtWeek1Tuesday.Size = new Size(63, 20);251. txtWeek1Tuesday.TabIndex = 17;252. txtWeek1Tuesday.Text = "0.00";253. txtWeek1Tuesday.TextAlign = HorizontalAlignment.Right;254.255. txtWeek1Wednesday.Location = new Point(213, 194);256. txtWeek1Wednesday.Size = new Size(63, 20);257. txtWeek1Wednesday.TabIndex = 18;258. txtWeek1Wednesday.Text = "0.00";259. txtWeek1Wednesday.TextAlign = HorizontalAlignment.Right;260.261. txtWeek1Thursday.Location = new Point(282, 194);262. txtWeek1Thursday.Size = new Size(63, 20);263. txtWeek1Thursday.TabIndex = 19;264. txtWeek1Thursday.Text = "0.00";265. txtWeek1Thursday.TextAlign = HorizontalAlignment.Right;266.267. txtWeek1Friday.Location = new Point(351, 194);268. txtWeek1Friday.Size = new Size(63, 20);269. txtWeek1Friday.TabIndex = 20;270. txtWeek1Friday.Text = "0.00";271. txtWeek1Friday.TextAlign = HorizontalAlignment.Right;272.273. txtWeek1Saturday.Location = new Point(420, 194);274. txtWeek1Saturday.Size = new Size(63, 20);275. txtWeek1Saturday.TabIndex = 21;276. txtWeek1Saturday.Text = "0.00";277. txtWeek1Saturday.TextAlign = HorizontalAlignment.Right;278.279. txtWeek1Sunday.Location = new Point(489, 194);280. txtWeek1Sunday.Size = new Size(63, 20);281. txtWeek1Sunday.TabIndex = 22;282. txtWeek1Sunday.Text = "0.00";283. txtWeek1Sunday.TextAlign = HorizontalAlignment.Right;284.285. txtWeek2Monday.Location = new Point(75, 220);286. txtWeek2Monday.Size = new Size(63, 20);287. txtWeek2Monday.TabIndex = 24;288. txtWeek2Monday.Text = "0.00";289. txtWeek2Monday.TextAlign = HorizontalAlignment.Right;290.291. txtWeek2Tuesday.Location = new Point(144, 220);292. txtWeek2Tuesday.Size = new Size(63, 20);293. txtWeek2Tuesday.TabIndex = 25;294. txtWeek2Tuesday.Text = "0.00";295. txtWeek2Tuesday.TextAlign = HorizontalAlignment.Right;296.297. txtWeek2Wednesday.Location = new Point(213, 220);298. txtWeek2Wednesday.Size = new Size(63, 20);299. txtWeek2Wednesday.TabIndex = 26;300. txtWeek2Wednesday.Text = "0.00";301. txtWeek2Wednesday.TextAlign = HorizontalAlignment.Right;302.303. txtWeek2Thursday.Location = new Point(282, 220);304. txtWeek2Thursday.Size = new Size(63, 20);305. txtWeek2Thursday.TabIndex = 27;306. txtWeek2Thursday.Text = "0.00";307. txtWeek2Thursday.TextAlign = HorizontalAlignment.Right;

Page 172: Introduction to Computer Networks

308. 309. txtWeek2Friday.Location = new Point(351, 220);310. txtWeek2Friday.Size = new Size(63, 20);311. txtWeek2Friday.TabIndex = 28;312. txtWeek2Friday.Text = "0.00";313. txtWeek2Friday.TextAlign = HorizontalAlignment.Right;314. 315. txtWeek2Saturday.Location = new Point(420, 220);316. txtWeek2Saturday.Size = new Size(63, 20);317. txtWeek2Saturday.TabIndex = 29;318. txtWeek2Saturday.Text = "0.00";319. txtWeek2Saturday.TextAlign = HorizontalAlignment.Right;320.321. txtWeek2Sunday.Location = new Point(489, 220);322. txtWeek2Sunday.Size = new Size(63, 20);323. txtWeek2Sunday.TabIndex = 30;324. txtWeek2Sunday.Text = "0.00";325. txtWeek2Sunday.TextAlign = HorizontalAlignment.Right;326.327. lblWeek2.AutoSize = true;328. lblWeek2.Location = new Point(12, 223);329. lblWeek2.Size = new Size(48, 13);330. lblWeek2.TabIndex = 23;331. lblWeek2.Text = "Week 2:";332.333. lblNotes.AutoSize = true;334. lblNotes.Location = new Point(12, 258);335. lblNotes.Name = "lblNotes";336. lblNotes.Size = new Size(35, 13);337. lblNotes.TabIndex = 31;338. lblNotes.Text = "Notes";339. 340. txtNotes.Location = new Point(75, 255);341. txtNotes.Multiline = true;342. txtNotes.ScrollBars = ScrollBars.Vertical;343. txtNotes.Size = new Size(477, 64);344. txtNotes.TabIndex = 32;345.346. pnlBottomLine.BackColor = Color.FromArgb(64, 64, 64);347. pnlBottomLine.Location = new Point(16, 326);348. pnlBottomLine.Size = new Size(552, 2);349. pnlBottomLine.TabIndex = 33;350.351. btnReset.Location = new Point(255, 337);352. btnReset.Size = new Size(75, 23);353. btnReset.TabIndex = 36;354. btnReset.Text = "Reset";355. btnReset.UseVisualStyleBackColor = true;356. btnReset.Click += new System.EventHandler(btnResetClicked);357.358. btnSubmit.Location = new Point(338, 337);359. btnSubmit.Size = new Size(130, 23);360. btnSubmit.TabIndex = 34;361. btnSubmit.Text = "Submit Time Sheet";362. btnSubmit.UseVisualStyleBackColor = true;363. btnSubmit.Click += new System.EventHandler(btnSubmitClicked);364. 365. btnClose.Location = new Point(476, 337);366. btnClose.Name = "btnClose";367. btnClose.Size = new Size(75, 23);368. btnClose.TabIndex = 35;

Page 173: Introduction to Computer Networks

369. btnClose.Text = "Close";370. btnClose.UseVisualStyleBackColor = true;371. btnClose.Click += new System.EventHandler(btnCloseClicked);372.373. ClientSize = new Size(580, 368);374. Controls.Add(txtTimeSheetCode);375. Controls.Add(btnClose);376. Controls.Add(btnSubmit);377. Controls.Add(btnReset);378. Controls.Add(pnlBottomLine);379. Controls.Add(txtNotes);380. Controls.Add(lblNotes);381. Controls.Add(txtWeek2Sunday);382. Controls.Add(txtWeek2Saturday);383. Controls.Add(txtWeek2Friday);384. Controls.Add(txtWeek2Thursday);385. Controls.Add(txtWeek2Wednesday);386. Controls.Add(txtWeek2Tuesday);387. Controls.Add(txtWeek2Monday);388. Controls.Add(lblWeek2);389. Controls.Add(txtWeek1Sunday);390. Controls.Add(txtWeek1Saturday);391. Controls.Add(txtWeek1Friday);392. Controls.Add(txtWeek1Thursday);393. Controls.Add(txtWeek1Wednesday);394. Controls.Add(txtWeek1Tuesday);395. Controls.Add(txtWeek1Monday);396. Controls.Add(lblWeek1);397. Controls.Add(lblSunday);398. Controls.Add(lblSaturday);399. Controls.Add(lblFriday);400. Controls.Add(lblThursday);401. Controls.Add(lblWednesday);402. Controls.Add(lblTuesday);403. Controls.Add(lblMonday);404. Controls.Add(pnlSecondLine);405. Controls.Add(lblTimeRecording);406. Controls.Add(dtpEndDate);407. Controls.Add(lblEndDate);408. Controls.Add(dtpStartDate);409. Controls.Add(lblStartDate);410. Controls.Add(txtEmployeeNumber);411. Controls.Add(txtEmployeeName);412. Controls.Add(lblEmployeeNumber);413. Controls.Add(pnlTopLine);414. Controls.Add(lblIdentification);415. FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;416. MaximizeBox = false;417. MinimizeBox = false;418. StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;419. Text = "Fun Department Store - Employees Time Sheet";420. ResumeLayout(false);421. PerformLayout();422. }423.424. private void txtEmployeeNumberLeave(object sender, EventArgs e)425. {426. // This variable will be used to look for an employee427. bool employeeFound = false;428.429. // Connect to the database

Page 174: Introduction to Computer Networks

430. // To connect to the database, after the following Data Source= expression,431. // type \\, followed by the name of the server (ours is named Expression),432. // followed by \\, followed by the name of the folder where the database 433. // is installed (ours is named Fun Department Store) (of course, you must434. // have shared that folder), followed by \\, and followed by the name of435. // the database, in this case FunDS436. using (OleDbConnection conFunDS =437. new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;" +438. @"Data Source=\\Expression\\Fun Department Store\\FunDS.accdb"))439. {440. // Get the records of employees441. OleDbCommand cmdFunDS = new OleDbCommand("SELECT * FROM Employees;", conFunDS);442.443. OleDbDataAdapter odaFunDS = new OleDbDataAdapter(cmdFunDS);444. DataSet dsEmployees = new DataSet("EmployeeSet");445. odaFunDS.Fill(dsEmployees);446.447. conFunDS.Open();448.449. // Visit the record of each employee450. for (int i = 0; i < dsEmployees.Tables[0].Rows.Count; i++)451. {452. // Get a reference to the current record453. DataRow rcdEmployee = dsEmployees.Tables[0].Rows[i];454.455. // If you find a record whose employee number is the same as 456. // the employee number entered in the form, we have found a match457. if (rcdEmployee["EmployeeNumber"].ToString().Equals(txtEmployeeNumber.Text))458. {459. // Display that employee's name460. txtEmployeeName.Text = rcdEmployee["LastName"].ToString() + ", " +

rcdEmployee["FirstName"].ToString();461. // Update the flag that we have found a match462. employeeFound = true;463. // Look no further464. break;465. }466. }467.468. // If there was no match, let the user know469. if (employeeFound == false)470. {471. MessageBox.Show("There is no employee with that employee number",472. "Fun Department Store",473. MessageBoxButtons.OK, MessageBoxIcon.Information);474. btnResetClicked(sender, e);475. }476. }477. }478.479. private void btnResetClicked(object sender, EventArgs e)480. {481. txtEmployeeNumber.Text = "";482. txtEmployeeName.Text = "";483. dtpStartDate.Value = DateTime.Today;484. dtpEndDate.Value = dtpStartDate.Value;485.486. txtWeek1Monday.Text = "0.00";487. txtWeek1Tuesday.Text = "0.00";488. txtWeek1Wednesday.Text = "0.00";489. txtWeek1Thursday.Text = "0.00";

Page 175: Introduction to Computer Networks

490. txtWeek1Friday.Text = "0.00";491. txtWeek1Saturday.Text = "0.00";492. txtWeek1Sunday.Text = "0.00";493.494. txtWeek2Monday.Text = "0.00";495. txtWeek2Tuesday.Text = "0.00";496. txtWeek2Wednesday.Text = "0.00";497. txtWeek2Thursday.Text = "0.00";498. txtWeek2Friday.Text = "0.00";499. txtWeek2Saturday.Text = "0.00";500. txtWeek2Sunday.Text = "0.00";501. txtNotes.Text = "";502. }503.504. /// This function is used to create a number we will name TimeSheetCode505. /// This number is used to uniquely identify each timesheet record506. /// This number holds the employee number (00-000 )507. /// and the start date (yyyymmdd) of the time sheet508. /// It is useful as it allows us to find out whether the employee509. /// had previously filled out a time sheet or not510. private string CreateTimeSheetCode(string emplNbr, DateTime DateStart)511. {512. string strMonth, strDay;513. int iMonth, iDay;514.515. iMonth = DateStart.Month;516. iDay = DateStart.Day;517.518. if (iMonth < 10)519. strMonth = "0" + iMonth.ToString();520. else521. strMonth = iMonth.ToString();522.523. if (iDay < 10)524. strDay = strMonth + "0" + iDay.ToString() + DateStart.Year;525. else526. strDay = strMonth + iDay.ToString() + DateStart.Year;527.528. return emplNbr + strDay;529. }530.531. private void dtpStartDateClosedUp(object sender, EventArgs e)532. {533. DateTime dtStartDate, dtEndDate;534. // If the employee name is empty, probably the 535. // employee number is not recognixed536. if (txtEmployeeName.Text == "")537. return;538.539. dtStartDate = dtpStartDate.Value;540. TimeSpan tsStart = new TimeSpan(13, 0, 0, 0);541. dtEndDate = dtStartDate + tsStart;542. dtpEndDate.Value = dtEndDate;543.544. txtTimeSheetCode.Text = CreateTimeSheetCode(txtEmployeeNumber.Text, dtpStartDate.Value);545.546. // To connect to the database, after the following Data Source= expression,547. // type \\, followed by the name of the server (ours is named Expression),548. // followed by \\, followed by the name of the folder where the database 549. // is installed (ours is named Fun Department Store) (of course, you must550. // have shared that folder), followed by \\, and followed by the name of

Page 176: Introduction to Computer Networks

551. // the database, in this case FunDS552. using (OleDbConnection conFunDS =553. new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;" +554. @"Data Source=\\Expression\\Fun Department Store\\FunDS.accdb"))555. {556. OleDbCommand cmdFunDS = new OleDbCommand("SELECT * FROM TimeSheets;", conFunDS);557.558. OleDbDataAdapter odaFunDS = new OleDbDataAdapter(cmdFunDS);559. DataSet dsTimeSheets = new DataSet("TimeSheetSet");560. odaFunDS.Fill(dsTimeSheets);561.562. conFunDS.Open();563.564. // Visit each record565. for (int i = 0; i < dsTimeSheets.Tables[0].Rows.Count; i++)566. {567. // Get a reference to the current record568. DataRow rcdTimeSheet = dsTimeSheets.Tables[0].Rows[i];569.570. if (txtTimeSheetCode.Text == rcdTimeSheet["TimeSheetCode"].ToString())571. {572. // ... it means the employee had previously created this time sheet.573. // Get the values and display them in the text boxes on the form574. txtWeek1Monday.Text =

double.Parse(rcdTimeSheet["Week1Monday"].ToString()).ToString("F");575. txtWeek1Tuesday.Text =

double.Parse(rcdTimeSheet["Week1Tuesday"].ToString()).ToString("F");576. txtWeek1Wednesday.Text =

double.Parse(rcdTimeSheet["Week1Wednesday"].ToString()).ToString("F");577. txtWeek1Thursday.Text =

double.Parse(rcdTimeSheet["Week1Thursday"].ToString()).ToString("F");578. txtWeek1Friday.Text =

double.Parse(rcdTimeSheet["Week1Friday"].ToString()).ToString("F");579. txtWeek1Saturday.Text =

double.Parse(rcdTimeSheet["Week1Saturday"].ToString()).ToString("F");580. txtWeek1Sunday.Text =

double.Parse(rcdTimeSheet["Week1Sunday"].ToString()).ToString("F");581.582. txtWeek2Monday.Text =

double.Parse(rcdTimeSheet["Week2Monday"].ToString()).ToString("F");583. txtWeek2Tuesday.Text =

double.Parse(rcdTimeSheet["Week2Tuesday"].ToString()).ToString("F");584. txtWeek2Wednesday.Text =

double.Parse(rcdTimeSheet["Week2Wednesday"].ToString()).ToString("F");585. txtWeek2Thursday.Text =

double.Parse(rcdTimeSheet["Week2Thursday"].ToString()).ToString("F");586. txtWeek2Friday.Text =

double.Parse(rcdTimeSheet["Week2Friday"].ToString()).ToString("F");587. txtWeek2Saturday.Text =

double.Parse(rcdTimeSheet["Week2Saturday"].ToString()).ToString("F");588. txtWeek2Sunday.Text =

double.Parse(rcdTimeSheet["Week2Sunday"].ToString()).ToString("F");589.590. // Since the record was found, look no further591. break;592. }593. else594. {595. // If no such record was found, reset the days text boxes596. txtWeek1Monday.Text = "0.00";597. txtWeek1Tuesday.Text = "0.00";

Page 177: Introduction to Computer Networks

598. txtWeek1Wednesday.Text = "0.00";599. txtWeek1Thursday.Text = "0.00";600. txtWeek1Friday.Text = "0.00";601. txtWeek1Saturday.Text = "0.00";602. txtWeek1Sunday.Text = "0.00";603.604. txtWeek2Monday.Text = "0.00";605. txtWeek2Tuesday.Text = "0.00";606. txtWeek2Wednesday.Text = "0.00";607. txtWeek2Thursday.Text = "0.00";608. txtWeek2Friday.Text = "0.00";609. txtWeek2Saturday.Text = "0.00";610. txtWeek2Sunday.Text = "0.00";611. txtNotes.Text = "";612. }613. }614. }615. }616.617. private void btnSubmitClicked(object sender, EventArgs e)618. {619. bool timeSheetExistsAlready = false;620. // If the employee name is empty, probably the 621. // employee number is not recognixed622. if (txtEmployeeName.Text == "")623. return;624.625. // To connect to the database, after the following Data Source= expression,626. // type \\, followed by the name of the server (ours is named Expression),627. // followed by \\, followed by the name of the folder where the database 628. // is installed (ours is named Fun Department Store) (of course, you must629. // have shared that folder), followed by \\, and followed by the name of630. // the database, in this case FunDS631. using (OleDbConnection conFunDS =632. new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;" +633. @"Data Source=\\Expression\\Fun Department Store\\FunDS.accdb"))634. {635. OleDbCommand cmdFunDS = new OleDbCommand("SELECT * FROM TimeSheets;", conFunDS);636.637. OleDbDataAdapter odaFunDS = new OleDbDataAdapter(cmdFunDS);638. DataSet dsTimeSheets = new DataSet("TimeSheetSet");639. odaFunDS.Fill(dsTimeSheets);640.641. conFunDS.Open();642.643. // Visit each record (time sheet)644. for (int i = 0; i < dsTimeSheets.Tables[0].Rows.Count; i++)645. {646. // Get a reference to the current record647. DataRow rcdTimeSheet = dsTimeSheets.Tables[0].Rows[i];648.649. // If an employee number in the time sheet is the same as the the employee number on

the form,650. // and if the corresponding start date in the time sheet is the same as the start date

on the form...651. if ((rcdTimeSheet["EmployeeNumber"].ToString().Equals(txtEmployeeNumber.Text)) &&652.

(DateTime.Parse(rcdTimeSheet["StartDate"].ToString()).ToShortDateString().Equals(dtpStartDate.Value.ToShortDateString())))

653. {654. // that means the record exists already. Get ready to update it

Page 178: Introduction to Computer Networks

655. timeSheetExistsAlready = true;656.657. break;658. }659. else660. timeSheetExistsAlready = false;661. }662. }663.664. if (timeSheetExistsAlready == true)665. {666. using (OleDbConnection conFunDS =667. new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;" +668. @"Data Source=\\Expression\\Fun Department Store\\FunDS.accdb"))669. {670. string strSQLUpdate = "UPDATE TimeSheets " +671. "SET Week1Monday = " + txtWeek1Monday.Text +672. ", Week1Tuesday = " + txtWeek1Tuesday.Text +673. ", Week1Wednesday = " + txtWeek1Wednesday.Text +674. ", Week1Thursday = " + txtWeek1Thursday.Text +675. ", Week1Friday = " + txtWeek1Friday.Text +676. ", Week1Saturday = " + txtWeek1Saturday.Text +677. ", Week1Sunday = " + txtWeek1Sunday.Text +678. ", Week2Monday = " + txtWeek2Monday.Text +679. ", Week2Tuesday = " + txtWeek2Tuesday.Text +680. ", Week2Wednesday = " + txtWeek2Wednesday.Text +681. ", Week2Thursday = " + txtWeek2Thursday.Text +682. ", Week2Friday = " + txtWeek2Friday.Text +683. ", Week2Saturday = " + txtWeek2Saturday.Text +684. ", Week2Sunday = " + txtWeek2Sunday.Text +685. ", Notes = '" + txtNotes.Text + "' " +686. "WHERE TimeSheetCode = '" + txtTimeSheetCode.Text + "';";687. OleDbCommand cmdTimeSheet = new OleDbCommand(strSQLUpdate, conFunDS);688. conFunDS.Open();689. cmdTimeSheet.ExecuteNonQuery();690.691. MessageBox.Show("The time sheet has been updated.",692. "Fun Department Store",693. MessageBoxButtons.OK, MessageBoxIcon.Information);694. }695. }696. else697. {698. using (OleDbConnection conFunDS =699. new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;" +700. @"Data Source=\\Expression\\Fun Department Store\\FunDS.accdb"))701. {702. string strSQLInsert = "INSERT INTO TimeSheets(EmployeeNumber, StartDate, TimeSheetCode,

Week1Monday, " +703. "Week1Tuesday, Week1Wednesday, Week1Thursday, Week1Friday, " +704. "Week1Saturday, Week1Sunday, Week2Monday, Week2Tuesday, " +705. "Week2Wednesday, Week2Thursday, Week2Friday, Week2Saturday, " +706. "Week2Sunday, Notes) VALUES('" +707. txtEmployeeNumber.Text + "', '" +

dtpStartDate.Value.ToShortDateString() + "', '" +708. txtTimeSheetCode.Text + "', " +709. double.Parse(txtWeek1Monday.Text) + ", " +710. double.Parse(txtWeek1Tuesday.Text) + ", " +711. double.Parse(txtWeek1Wednesday.Text) + ", " +712. double.Parse(txtWeek1Thursday.Text) + ", " +713. double.Parse(txtWeek1Friday.Text) + ", " +

Page 179: Introduction to Computer Networks

714. double.Parse(txtWeek1Saturday.Text) + ", " +715. double.Parse(txtWeek1Sunday.Text) + ", " +716. double.Parse(txtWeek2Monday.Text) + ", " +717. double.Parse(txtWeek2Tuesday.Text) + ", " +718. double.Parse(txtWeek2Wednesday.Text) + ", " +719. double.Parse(txtWeek2Thursday.Text) + ", " +720. double.Parse(txtWeek2Friday.Text) + ", " +721. double.Parse(txtWeek2Saturday.Text) + ", " +722. double.Parse(txtWeek2Sunday.Text) + ", '" +723. txtNotes.Text + "');";724.725. // Generate a command to create a record726. OleDbCommand cmdEmployees = new OleDbCommand(strSQLInsert, conFunDS);727.728. conFunDS.Open();729. cmdEmployees.ExecuteNonQuery();730.731. MessageBox.Show("The time sheet has been created.",732. "Fun Department Store",733. MessageBoxButtons.OK, MessageBoxIcon.Information);734.735. btnResetClicked(sender, e);736. }737. }738. }739.740. private void btnCloseClicked(object sender, EventArgs e)741. {742. Close();743. }744. }745.746. public class Exercise747. {748. public static int Main()749. {750. Application.Run(new TimeSheet());751. return 0;752. }

}

Page 180: Introduction to Computer Networks

 

Practical Learning: Testing the Time Sheet

To execute the application, press F5

Enter the values as follows: 

Employee #

17-090   Start Date January 2, 2011      

  Mon Tue Web Thu Fri Sat Sun

Week 1 8.00 8.50 8.00 9.50 8.50 0 0

Week 2 8.00 8.00 6.50 6.00 6.00 0 0

 

Page 181: Introduction to Computer Networks

Click Submit Time Sheet

Page 182: Introduction to Computer Networks

Create other time sheets as follows and click Submit Time Sheet after each: 

Employee #

39-581   Start Date January 2, 2011      

  Mon Tue Web Thu Fri Sat Sun

Week 1 8 7.5 7 7.5 6 0 0

Week 2 6 6.5 6 7.5 6 0 0

 

Employee #

40-715   Start Date January 2, 2011      

  Mon Tue Web Thu Fri Sat Sun

Week 1 0 0 0 0 8  8 0

Week 2 0 0 0 0 8 8 0

 

Employee #

44-509   Start Date January 2, 2011      

  Mon Tue Web Thu Fri Sat Sun

Week 1 8 8 6 8 8 0 0

Week 2 8 8 8.5 7 8.5 0 0

 

Page 183: Introduction to Computer Networks

Close the form

10. Press F5 to execute again

11. In the employee number, type 39-581

12. Set the Start Date to January 2, 2011

13. In the Week 1 row, change the Wednesday value to 8.5

14. In the Week 2 row, change the Monday value to 8.00

15. Click Submit Time Sheet

16. Close the form

17. To execute again, press F5

18. Create new time sheets as follows: 

Employee #

17-090   Start Date January 16, 2011      

  Mon Tue Web Thu Fri Sat Sun

Week 1 8 8 8 8.5 8.5 0 0

Week 2 8.5 8 6 7.5 0 0 0

19. 

Employee #

39-581   Start Date January 16, 2011      

  Mon Tue Web Thu Fri Sat Sun

Page 184: Introduction to Computer Networks

Week 1 8.5 8.5 6.5 9.5 8 0 0

Week 2 6.5 8.5 6 6.5 8.5 0 0

20. 

Employee #

75-937   Start Date January 16, 2011      

  Mon Tue Web Thu Fri Sat Sun

Week 1 0 0 0 0 8.5 6 0

Week 2 0 0 0 0 9.5 8 0

21.  

Employee #

84-715   Start Date January 16, 2011      

  Mon Tue Web Thu Fri Sat Sun

Week 1 0 0 0 8 8 8 0

Week 2 0 0 0 7.50 8.5 8 0

22.  

Employee #

44-666   Start Date January 16, 2011      

  Mon Tue Web Thu Fri Sat Sun

Week 1 8.5 7.5 6.5 10.5 8 0 0

Week 2 9.5 6.5 7.5 8.5 8.5 0 0

23.    

Employee #

44-509   Start Date January 16, 2011      

  Mon Tue Web Thu Fri Sat Sun

Week 1 8 8.0 8.5 8.5 8 0 0

Week 2 7.5 8.5 9.5 8 9 0 0

24. 

Employee #

40-715   Start Date January 16, 2011      

  Mon Tue Web Thu Fri Sat Sun

Week 1 0 0 0 0 9.5 10 0

Week 2 0 0 0 0 10.5 8 0

25. 

Employee #

17-090   Start Date January 30, 2011      

  Mon Tue Web Thu Fri Sat Sun

Week 1 8 8.5 8 8 8 0 0

Week 2 8 8 8 8.5 8 0 0

26. 

Page 185: Introduction to Computer Networks

Employee #

75-937   Start Date January 30, 2011      

  Mon Tue Web Thu Fri Sat Sun

Week 1 8.5 9.5 8.5 9 8 0 0

Week 2 8 9 9 10 8.5 0 0

27. Close the form

28. Press F5 to execute again

29. Press F5 to execute again