Professional Documents
Culture Documents
A computer network can also consist of, and is usually made for, more than two computers:
:: Note
:: Note
one of these but using data from a computer that doesnt have a CD writer or a backup system y You may have a computer that doesnt 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
y y
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
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.
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.
o o o
When the computer starts, you can access its BIOS by pressing F2 or F8 depending on the computer, the model or the manufacturer From the computer's desktop, if it's running Windows 95 and later, you can right-click My Computer and click Properties 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 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.com http://www.bestbuy.com http://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 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 y 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
o o o
check
the
amount
of
RAM
your
computer
has:
When the computer starts, you can access its BIOS by pressing F2 or F8 depending on the computer, the model or the manufacturer From the desktop of a Windows 95 and later computer, you can right-click My Computer and click Properties 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 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
y Hard Drive: Before installing Microsoft Windows XP Pr ofessional 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:
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
y 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, ri ght-click the desktop and click Properties. You can also open Control Panel and double -click Display. In the Display Properties, click Settings:
To check the video adapter of your computer, click Advanced and click the Adapter tab. Here is an example:
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
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
requirements: y 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 h ard 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
y y y y y y
Because building a barebone depends on your goals, we will not review here the parts to acquire or the steps performed.
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. 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:
Network Cables
Cable is used to connect computers. Although we are planning to use as much wireless as possible, you have one or more cables around. In our network, we will use Category 5 cable RJ-45. The ends of the ca follows:
You can purchase this cable from a web store on the Internet. Probably the fastest way to get this cable computer store. When purchasing it, get something with at least 6ft.
In our introduction to networks, We mentioned that you could connect one computer to another. This using their serial ports:
This is possible because almost every computer has a serial port. If you have to connect many computers network, this serial connection would not be practical. The solution is to use a central object that the c other resources can connect to, and then this object becomes responsible to distribute or manage network
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 conne this possible, a hub is equipped with small holes called ports. Here is an example of a hub:
Although this appears with 4 ports, depen ding on its type, a hub can be equipped with 4, 5, 12, or more po 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 hu In most cases for a home-based or a small business network, you may not need a hub.
Like a hub, a router is another type of device that acts as the central point among computers and other de 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
Like a hub, the computers and other devices are connected to a router using network cables. To make t router is equipped with holes, called ports, in the back. Here is an example:
Based on advances in the previous years from IEEE and other organizations or research companies, ther routers. With this type, the computers and devices connect to the router using microwaves (no physical cab
In our (small) network, we wish to use a wireless router. Therefore, this is the kind we suggest you purc purchase a wireless router from a computer store or on th (http://www.tigerdirect.com, http://www.3com.com, http://www.provantage.com, etc). You c wireless router from a computer store.
In order to connect to a network, a computer must be equipped with a device called a network card. A netw network adapter, also called a network interface card, or NIC, allows a computer to connect to the exterio computer from one of those popular stores or big companies on the Internet, most of their computers ha card tested and already. You can reliably use it. If you go to a store that sells or manufactures computers them to install or make sure that the computer has a network card.
If you have a computer that doesnt have a network card, you can install one. If you have a computer that network card, you can still replace it.
When it comes to their installation, there are roughly two categories of network cards: internal and extern network card looks like a printed circuit board with some objects "attached" or "glued" to it and it appears a
What this card looks like may not be particularly important and it may depend on the manufacturer b
aspects particularly are. To start, there are two types of cards and you should know which one is suited you want to use) for your computer. One type of NICs uses a peripheral component interconnect (PC 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 com has and install a new one. In some other cases, you will only add a new card but you cannot replace th because it is part of the motherboard (I have found that out lately when opening a few computers for my 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 three main alternatives. You can open the computer and examine the available slots of your computer. Th located inside of what would be considered as the back (wall) of the computer (if you know where yo monitor, you should be able to locate the area that has the slots. Unfortunately, unless you have experie 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 havent thrown 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 the computer. They usually know, provided you can get a human being on the phone, as long as you 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 appropriate network card. One of the most important characteristics of a network card is the speed it ca information. The speeds are either 10 or 100Mbps (megabits per second). When buying a network card, y attention to this. Here are some suggested links where you can buy computer products: http://www.provantage.com http://www.tigerdirect.com http://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 sho a manual and all (easy to follow) instructions. You can also install the network card after setting up the co 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. can go to a computer store or find a web site that sells them. The device you buy may look like this:
If you buy one of these objects, its documentation will guide you.
Overall, the physical installation of a wireless network card follows the same rules as that of a wired NIC. come with easy to follow instructions but it may be a good idea to install the wireless network adapters a the wireless router. Also, it may be a good idea to purchase the network cards and the wireless router f manufacturer.
Most desktop computers (workstations) come without a wireless network card. If you purchase a compute the big companies on the Internet, you can choose to have it shipped with a wireless NIC. Some companie to install it before shipping the computer. If you buy a computer from a store and if you want to use wireles you can buy a wireless network card separately. As stated already, a wireless network card is not particul install.
Besides the wireless network cards that can be installed inside the computer, you can use external car installed using a USB port. Here is an example of a USB adapter:
These adapters, like most USB objects, are easy to connect and use. Like the other hardware parts, whe 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 today ship with both a wired and a wireless adapters). This means that, after purchasing or acquiring should simply check whether it has a wireless adapter. The way you check this depends on the laptop. Th its documentation. If your laptop happens not to a have a wireless adapter and you want to use one, you h 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 o 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 al purchase a network printer. That is, a printer that will directly connect to the network and people can print There are two types of printers in this case: y y
Some printers come equipped with a network card. In this case, as we will learn in Lesson 5, you can u 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 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 al of printer, with or without a network card, to the network. You can purchase a wireless print server fro store or from a web store. It is usually easy to install as it comes with easy-to-follow instructions.
An Internet Service Provider (ISP) is a company that serves as the intermediary between your network (or Internet. If you plan to give access to the Internet to the members of your network, you may need this typ 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 im 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. Man Alternatively, you can use or configure one of the computers of your network as
Network Software
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 Window s 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.
http://www.microsoft.com http://www.tigerdirect.com http://www.provantage.com http://www.cdw.com http://www.amazon.com etc. We will cover the installation later.
Support Software
Office Suite
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.
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: y 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
y y y y y y
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.com http://www.cdw.com http://www.hp.com http://www.dell.com http://www.gateway.com http://www.ibm.com etc 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 wri ter (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: y y 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
o o o
If you have only one partition and it looks small, such as less than 5 GB, simply select it If you have only one partition and that, regardless of its size, you want to use it wholly to install the OS, select it 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 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 minutes A 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 yo u click Customize, the Regional and Language Setup Options dialog box will come up:
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 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 Finish The 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 y our 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 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 reb oot (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 t ake 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 Finish You 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.
Physical Connections
Wired Networking
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.
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 computer to set it up.
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:
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:
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,
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
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
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:
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
Click Next 17. After clicking Next, the wizard will start creating the files used to setup a network, based on your previous selections:
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:
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:
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:
Click Finish 21. After clicking Finish, a message box will ask you whether you want to restart the computer:
Click Yes
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
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:
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
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
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
2. Using Windows Explorer, My Computer or ano ther 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
Server Installation
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: y y 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:
:: Note
A processor with 133-MHz or higher speed; 550-MHz recommended; up to eight processors supported on one server 128 MB of RAM minimum required; 256 MB or more recommended; 32 GB maximum 1.25 to 2 GB of available hard disk space CD-ROM or DVD-ROM drive VGA or hardware that supports console redirection required; Super VGA supporting 800 x 600 or higher resolution monitor recommended
o o o o
A processor with 133-MHz or higher speed; 550-MHz recommended; up to eight processors supported on one server 128 MB of RAM minimum required; 256 MB or more recommended; 32 GB maximum 1.25 to 2 GB of available hard disk space
o o
o o
CD-ROM or DVD-ROM drive 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, bu t 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.
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.c om, 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 :: Note If you are plann the machine, make sure it meets the following requirements:
o o o o o
133-MHz processor required; 550-MHz recommended; up to eight processors supported on one server 128 MB of RAM minimum required; 256 MB or more recommended; 32 GB maximum 1.25 to 2 GB of available hard disk space CD-ROM or DVD-ROM drive 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 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). y 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.com http://www.cdw.com http://www.amazon.com etc y 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...
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.
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 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 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
2. The first page of the wizard presents a summary of the actions you must have taken before continuing
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)
4. Click Next
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
8. In the third page of the wizard, you must specify whether this is the first or an additional domain contr 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
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 d 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":
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:
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:
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:
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 200 3 CD in the drive, you may be be pro to supply it:
Do so After a few seconds, you may receive a message box informing you that your computer has a static IP address. Click OK When the dialog box comes up, simply click OK Another 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
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 wh the installation of Active Directory was successful:
Click Finish
After creating a domain, you can can add client computers to it. In our examples, we will add workstations Microsoft Windows XP Professional. There are two actions to adding a client to a Microsoft Windows Serv domain but only one is required.
Before physically or electronically adding a client to a domain, you can first create a computer account f create a computer account, you have various alternatives: y y y
If using the Manage Your Server window, you can click Manage Users And Computers In Active Directo 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 Compu
Any of these actions would open the Active Directory Users and Computers w indow. In the left frame, exp name of the domain. Then you can right-click the name of the domain -> New -> Computer. This would o New Object - Computer dialog box. In the Computer Name text box, enter the name of the comput operating systems before Windows 2000 don't use very long names. Therefore, when naming a comput this in mind and give a name made of fewer than 15 characters. After naming the computer, click Next tw click Finish.
Instead of right-clicking the name of the domain, in the Active Directory Users And Computers, you can exp name of the domain, right-click the Computers node -> New -> Computer. As mentioned already, in the fi of the New Object - Computer wizard, you can type a name for the computer. Here is an example:
Joining a Domain
After creating an account for a computer, you can add it to the domain. This is referred to as joining a Normally, primarily creating an account for a computer is not required although it's a good idea. When j 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 o
You can right-click My Computer and click Properties... You can display Control Panel and double -click System
4. In the Computer Name text box, enter the desired name of the computer. If you had already created a 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 perm to join let a computer join a domain
9. After entering a user and a password, click OK. If you have the right to add computers to the domain, 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 S 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 o 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
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.
As you install more software or libraries to your computer, the tools may increase in sophistication and number. Here is an example:
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:
To use a tool, you can double-click it. Another technique you can access the tools consists of cl icking Start -> Administrative Tools:
Another technique consists of click Start -> All Programs -> Administrative Tools
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.
being performed. You can perform all routines operations without formally being aware that you are using the MMC.
If you are using Microsoft Windows XP Professional, click open Control Panel, double-click Administrative Tools, and double-click Computer Management
If you are using Microsoft Windows Server 2003, click Start -> Administrative tools -> Active Directory Users and Computers
If you are using Microsoft Windows XP Professional, in the Administrative Tools window, double-click Services
If you are using Microsoft Windows Server 2003, click Start -> All Programs -> Administrative tools -> Event Viewer
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.
4. Click Add... 5. Under the Snap-In header, click Computer Management and click Add 6. In the Computer Management wizard, accept the Local Computer radio button. Click the Allow the Selected Computer to be Changed ... check box
7. Click Finish 8. Once again, in the Add Standalone Snap-in dialog box, click Performance Logs and Alerts) and click Add 9. Click Close
10. Click OK
11. To save and click the MMC, on the main menu, click File -> Save As... 12. Set the file name to Computer Performance and click Save 13. To close the MMC, on the main menu, click File -> Exit 14. To reopen the MMC, on the taskbar, click Start -> Run... 15. Type mmc and press Enter 16. To open a previously saved MMC, on the main menu, click File -> Open 17. Click Computer Management.msc and click Open 18. To review the current tools available, on the main menu, click File -> Add/Remove Snapin... 19. In the Add/Remove Snapp-in dialog box, click the Extensions tab and, if necessary, in the combo box, select Computer Management
20. Click OK
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:
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, cli ck 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:
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
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 OK. Click Next. The next screen asks you check for updates:
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:
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:
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
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 Window s SBS Console:
The next step is probably to connect the server to the Internet. It will be used to connect other computers to the Internet. Y should first make sure that: y y y y y 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:
Click Next. In the second page, the wizard will make an attempt to detect the router:
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, typ 192.168.002.003). Click Next:
If you receive an error, click Finish and start again (it should work the second time; in reality, what may happen is that the wiza will have to detect the router, get the right IP address from it, and use it). Once you have succeeded, click Finish:
browser
and
change
the
address
to
somethin
Next, you should connect the other computers (named clients, or workstations, of client workstations) to the domain. To do th on the Taskbar, click Start, right-click Computer, and click Properties. You should see the computer name and the name of t domain:
Click Change Settings. Click Continue. Notice the (full) name of the computer (and the addre ss we mentioned that your users w use as the address in a browser): Also notice the name of the domain (this name will be used to access some files in the oth computers of the same network):
Notice that the Change button is disabled, which means tha t you can change neither the name of the computer, nor the name the domain). After viewing, click OK.
Just to make sure you can connect to the domain, you should reboot. When the computer comes up, press Ctrl + Alt + Delet Make sure the right
Next, you must join the other computers to the domain. You have two options. You can first create an account for each comput on the domain (on the server), but this is not important. Another option, kind of faster, is to directly join the domain; the serv will automatically create the account. To join the domain, make sure the other computer you want to use has a cable connected the router and it has the right operating system (Microsoft Windows XP Professional, Windows 7 Professional, Windows 7 Ultima (some versions of Linux also can join)).
Start the other computer. Click Start, right-click Computer, and click Properties. Click Change Settings:
Click Change... Click the Domain radio button. In the corresponding text box, enter the name of the domain with the doma extension:
Click OK. You will be asked to provide a user name and a password. These credentials must be those of an account that can joi n
domain. You can use the account that was created during the installation of the server (an alternat ive is to go to the server, crea a separate account with admin rights, and use it) (you can also use the Administrator account but this is not a good solutio normally, the Administrator is disabled):
After entering the username and the password, click OK. If you receive an error, consider the following section. If you don't receiv an error, skip this section.
Possible Errors: y If you use the Administrator account and receive an error when you click OK, go back to the server, click Start -> Administrative Tools -> Active Directory Users and Computers; click Continue; in the left frame, expand the name name of the domain, click Users; in the right frame, right-click Administrator and click Properties; in the Account Options section, remove the check mark of Account Is Disabled; click OK In some cases, you may receive an error message that "An attempt to resolve the DNS Name ..." failed:
This could happen if you were using computer on its own or it was a member of a workgroup and not an act ual domain. Before resolving this, first get the IP address of the server. There are various ways you can go it. Go to the server compute r o Click Start -> Administrative Tools -> DNS. In the left frame, right-click the name of the server and click Properties. Get the IP address that has 4 sections:
Click Cancel o Click Start and click Command Prompt (you can also click Start, then type cmd in the text box and press Enter). Type ipconfig and press Enter. Get the IP address on the right side of IPv4 Addres s)
Click Start -> Control Panel. Click Network and Sharing Center. Click View Status. Click Details. Get the IP address on the right side of IPv4 DNS Server
On the computer that needs to join the domain, click Start -> Control Panel. Click View Network Status and Tasks. Click Loc Area Connection. Click Properties, Click Internet Protocol Version 4 (TCP/IPv4). Click Properties. Click Advanced. Click DNS. Click Add... Type the IP address of the server. Click OK. Click OK. Click OK. Click Close. Click Cl ose. Try joining the domain again
The computer will then try to connect to the server and join the domain. If it is successful, you will receive a message welcomi you to the domain:
Click OK. You will receive a message telling that you will have to reboot:
Click OK. In the System Properties dialog box, click Close. When asked to reboot, click Restart Now.
In Microsoft Windows 7, there is another technique you can use to join the domain.
To start, login to your server (this step is optional). Click Start -> Administrative Tools -> Active Directory Users and Computer In the left frame, right-click Computers -> New Computer. Enter the name of the computer that will join the domain:
Click OK.
In the computer that needs to join the domain, as done in the previous example, display the System Properties dialog box (yo can click Start, right-click Computer, and click Properties, then click Change Settings). In the Computer Name property page, cli Network ID. In the first page of the wizard, make sure the first radio button is selected or click it:
Click Next. In the second page of the wizard, make sure the first radio button is selected or click it:
Click Next. The third page of the wizard will show a message:
After reading it, click Next. In the third page, type a username, a password, and name of the domain:
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 n found in the domain. In this case, enter the domain name again:
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:
Click Next. You will be asked to login. Enter a username and a password that can join a computer to a domain. Also type t domain name.
You will be asked whether you want to enable a domain user account on the computer:
After reading, click Next. The next page of the wizard allows you to specify the type of account you want to create locally. In mo cases, you should accept a Standard Account:
Description
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:
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:
Click Next. In the third page of the wizard, verify the summary of the information you had specified:
If something is wrong, click Back and change it. If everything is alright, click Fin ish.
hi
Click Finish. On the System Properties dialog box, click OK. When asked to restart (first save any files that need to be save d), cli Restart Now.
When the computer comes up, to login, press Ctrl + Alt + Delete. Set the user name as DomainName\username. An examp would be functionx\pkatts, then enter the password. Click the right pointing button.
Solution 1
Click Add... In the bottom text box, you can type just the beginning of the name of a group:
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:
Click OK:
Click OK.
ntroduction
An 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 M icrosoft 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.
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
ttp://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:
ttp://central.functionx.local YThe default intranet site of a computer displays the default page of IIS7:
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:
body>
/body> /html> 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:
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 access to that folders, delete the necessary
already, the web site is in the C:\Inetpub\wwwroot folder. The person who work on the web site should have folder and should have administrative rights on that folder. For example, he or she must be able to create subsub-folders, and perform other necessary file operations. For example, if you are the webmaster, you can create 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. We also use a sub-folder named images:
The images sub-folder contains the pictures of the web site. Once the files have been created or added, the web site is ready:
It is that simple. Of course, there are many other things you can do either to customize the intranet or to create additional web sites, but the ideas here give you a foundation.
Application Authentication
troduction
Application authentication consists of restricting access to an application. You can first create an application and take car e authentication later, but it is better to design the concept before starting. In this series of articles, we are going to create omplete application, step by step, and in different sections that each deals with one particular issue.
magine you want to create an application for a department store. One of the things you can take care of, as far as people w cess the program are concerned, is authentication. For our application, you will first create a database.
1. Log to the server of your network (normally, you can use any computer of your network)
4. Click the arrow of the combo box in the File Sharing window and select Everyone
5. Click Add
6. Click the down-pointing arrow on the right side of Everyone: o If you are sharing from Microsoft Windows Server 2008, select Contributor
7. Click Share
8. Click Close
1. In another computer that can access the shared folder and that has Microsoft Access, start Microsoft Access (we will use Microsoft Access 2010)
2. In the File Name text box, replace the name with FunDS
4. Locate the folder you created and shared from its computer:
5. Click OK
6. Click Create
10. Create the following fields Field Name EmployeeNumber FirstName LastName Title 20 80 Data Type Field Size 20 Format Caption Employee # First Name Last Name Other Properties Primary Key
11. To change the view, right-click the tab of the table and click Datasheet View
13. Click OK
18. Create the following fields Field Name ItemNumber ArrivalDate Manufacturer Category SubCategory ItemName ItemSize UnitPrice DiscountRate SaleStatus Number Number Date/Time 50 50 50 100 50 Double Double 40 Fixed Fixed Sub-Category Item Name Item Size Unit Price Discount Rate Sale Status Data Type Field Size 20 Format Caption Item # Arrival Date Other Properties Primary Key
19. To switch the view, right-click the table's tab and click Datasheet View
21. Click OK
o implement our authentication, we will create a C# application. Normally, you can use Microsoft Visual C# 2010 Express but we w se Microsoft Visual Studio 2010 Professional. To establish a connection to the Microsoft Access database, we will use the .N amework.
s always, you can first create the application and then take care of authentication later.
2. To create a new application, on the main menu, click File -> New Project...
3. If you are using Microsoft Visual Stuio, in the left frame, click Visual C# Projects.
5. Click OK
18. Click OK
19. To create a file for the project, on the main menu, click Project -> Add New Item...
23. In the empty document, type the following: using using using using using using System; System.Data; System.Drawing; System.Data.OleDb; System.Windows.Forms; System.ComponentModel;
24. 25. 26. 27. 28. 29. 30. 31. 32. 33. 34. 35. 36. 37. 38. 39. 40. 41.
public class StoreInventory : Form { private ColumnHeader colIndex; private ColumnHeader colItemNumber; private ColumnHeader colArrivalDate; private ColumnHeader colManufacturer; private ColumnHeader colCategory; private ColumnHeader colSubCategory; private ColumnHeader colItemName; private ColumnHeader colItemSize; private Column Header colUnitPrice;
42. 43. 44. 45. 46. 47. 48. 49. 50. 51. 52. 53. 54. 55. 56. 57. 58. 59. 60. 61. 62. 63. 64. 65. 66. 67. 68. 69. 70. 71. 72. 73. 74. 75. 76. 77. 78. 79. 80. 81. 82. 83. 84. 85. 86. 87. 88. 89. 90. 91. 92. 93. 94. 95. 96. 97. 98. 99. 100. 101. 102.
private ColumnHeader colSaleStatus; private ListView lvwStoreItems; private Button btnClose; public StoreInventory() { InitializeComponent(); } private void InitializeComponent() { colIndex = new ColumnHeader(); colItemNumber = new ColumnHeader(); colArrivalDate = new ColumnHeader(); colManufacturer = new ColumnHeader(); colCategory = new ColumnHeader(); colSubCategory = new ColumnHeade r(); colItemName = new ColumnHeader(); colItemSize = new ColumnHeader(); colUnitPrice = new ColumnHeader(); colSaleStatus = new ColumnHeader(); lvwStoreItems = new ListView(); btnClose = new Button(); SuspendLayout(); colIndex.Text = "Index"; colIndex.Width = 40; colItemNumber.Text = "Item #"; colItemNumber.TextAlign = HorizontalAlignment.Center; colItemNumber.Width = 50; colArrivalDate.Text = "Arrival Date"; colArrivalDate.Width = 70; colManufacturer.Text = "Manufacturer"; colManufacturer.Width = 100; colCategory.Text = "Category"; colSubCategory.Text = "Sub -Category"; colSubCategory.Width = 80; colItemName.Text = "Item Name/Description"; colItemName.Width = 220; colItemSize.Text = "Size"; colItemSize.TextAlign = HorizontalAlignment.Center; colUnitPrice.Text = "Unit Pric e"; colUnitPrice.TextAlign = HorizontalAlignment.Right; colSaleStatus.Text = "Status"; colSaleStatus.Width = 70; btnClose.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; btnClose.Location = new Point(772, 182); btnClose.Size = new Size(75, 23);
103. 104. 105. 106. 107. 108. 109. 110. 111. 112. 113. 114. 115. 116. 117. 118. 119. 120. 121. 122. 123. 124. 125. 126. 127. 128. 129. 130. 131. 132. 133. 134. 135. 136. 137. 138. 139. 140. 141. 142. 143. 144. 145. 146. }
btnClose.TabIndex = 33; btnClose.Text = "Close"; btnClose.UseVisualStyleBackColor = true; btnClose.Click += new System.EventHandler(btnCloseClicked); lvwStoreItems.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; lvwStoreItems.Columns.AddRange(new ColumnHeader[] { colIndex, colItemNumber, colArrivalDate, colManufacturer, colCategory, colSubCategory, colItemName, colItemSize, colUnitPrice, colSaleStatus}); lvwStoreItems.FullRowSelect = true; lvwStoreItems.GridLines = true; lvwStoreItems.Location = new Point(12, 12); lvwStoreItems.Size = new Size(835, 160); lvwStoreItems.TabIndex = 32; lvwStoreItems.UseCompatibleStateImageBehavior = false; lvwStoreItems.View = System.Windows.Forms.View.Details; ClientSize = new Size(859, 213); Controls.Add(btnClose); Controls.Add(lvwStoreItems); ShowInTaskbar = false; StartPosition = FormStartPosition.CenterScreen; Text = "Fun Department Store - Current Store Inventory"; Load += new System.EventHan dler(StoreInventoryLoaded); ResumeLayout(false); } private void ShowInventory() { } private void StoreInventoryLoaded(object sender, EventArgs e) { ShowInventory(); } private void btnCloseClicked(object sender, EventArgs e) { Close(); } In the Solution Explorer, double -click StoreInventory.cs
147.
148.
To create a new file, on the main menu, click Project -> Add New Item... In the middle list, click Code File Set the Name to Switchboard Click Add In the empty document, type the following: using using using using using using System; System.Data; System.Drawing; System.Data.OleDb; System.Windows.Forms; System.ComponentModel;
149.
150.
151.
152.
153. 154. 155. 156. 157. 158. 159. 160. 161. 162. 163. 164. 165. 166. 167. 168. 169. 170. 171. 172. 173. 174. 175. 176. 177. 178. 179. 180. 181. 182. 183. 184. 185. 186. 187. 188. 189.
public class Switchboard : Form { private Button btnStoreInventory; private Button btnClose; public Switchboard() { InitializeComponent(); } private void InitializeComponent() { btnStoreInventory = 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(265, 98); btnStoreInventory.TabIndex = 21; btnStoreInventory.Text = "View Store Inventory"; btnStoreInventory.UseVisualStyleBackColor = true; btnStoreInventory.Click += new System.EventHandler(btnStoreInventoryClicked); btnClose.Font = new Font("Georgia", 18F, FontStyle.Bold, GraphicsUnit.Point, 0); btnClose.Location = new Point(11, 126);
190. btnClose.Size = new Size(26 5, 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) 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 DepartmentStore 223. { 224. public static int Main() 225. { 226. Application.Run(new Switchboard()); 227. return 0; 228. } } In the Solution Explorer, double-click Switchboard.cs
229.
230.
231.
Click the View Store Inventory button Close the Store Inventory form Close the Switchboard form Access the StoreInventory.cs file Implement the ShowInventory() method as follows: private void ShowInventory() { // If there were some items in the list view, remove them before filling it up lvwStoreItems.Items.Clear(); // To connect to the database, after the following Data Source= expression, // type \\, followed by the name of the server (ours is named Expression), // followed by \\, followed by the name of the folder where the database // is installed (ours is named Fun Department Store) (of course, you must // have shared th at folder), followed by \\, and followed by the name of // the database, in this case FunDS using (OleDbConnection conFunDS = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;" + @"Data Source= \\Expression \\Fun Department Store \\FunDS.accdb")) { // Select all store items OleDbCommand cmdFunDS = new OleDbCommand("SELECT * FROM StoreItems;", conFunDS); OleDbDataAdapter odaFunDS = new OleDbDataAdapter(cmdFunDS); DataSet dsStoreItem s = new DataSet("StoreItemsSet"); odaFunDS.Fill(dsStoreItems); conFunDS.Open(); // Using the total number of records, display each in the list view for (int i = 0; i < dsStoreItems.Tables[0].Rows.Count; i++) { DataRow rcdStoreItem = dsStoreItems.Tables[0].Rows[i]; ListViewItem lviStoreItem = new ListViewItem((i + 1).ToString()); lviStoreItem.SubItems.Add(rcdStoreItem["ItemNumber"].ToString()); lviStoreItem.SubItem s.Add( DateTime.Parse(rcdStoreItem["ArrivalDate"].ToString()).ToShortDateString()); lviStoreItem.SubItems.Add(rcdStoreItem["Manufacturer"].ToString()); lviStoreItem.SubItems.Add(rcdStoreItem["Category"].ToString()); lviStoreItem.SubItems.Add(rcdStoreItem["SubCategory"].ToString()); lviStoreItem.SubItems.Add(rcdStoreItem["ItemName"].ToString()); lviStoreItem. SubItems.Add(rcdStoreItem["ItemSize"].ToString()); lviStoreItem.SubItems.Add( double.Parse(rcdStoreItem["UnitPrice"].ToString()).ToString("F")); lviStoreItem.SubItems.Add(rcdStoreItem["SaleStatus"].ToString()); lvwStoreItems.Items.Add(lviStoreItem); } } } private void StoreInventory_Load(object sender, EventArgs e) { ShowInventory(); To execute, press F5 Click the Store Inventory button
232.
233.
234.
235.
236. 237. 238. 239. 240. 241. 242. 243. 244. 245. 246. 247. 248. 249. 250. 251. 252. 253. 254. 255. 256. 257. 258. 259. 260. 261. 262. 263. 264. 265. 266. 267. 268. 269. 270. 271. 272. 273. 274. 275. 276. 277. 278. 279. 280. 281. 282. 283. 284. }
285.
286.
287.
288.
mplementing Authentication
here is always more than one way to solve a problem in logic and in math. When it comes to an application also, you have m ptions: y y
You can create the first form of your application as the log in dialog box. In this case, if the employee successfully logs, then t 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 th e application would show
n 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.
20. 21. 22. 23. 24. 25. 26. 27. 28. 29. 30. 31. 32. 33. 34. 35. 36. 37. 38. 39. 40. 41. 42. 43. 44. 45. 46. 47. 48. 49. 50. 51. 52. 53. 54. 55. 56. 57. 58. 59. 60. 61. 62. 63. 64. 65. 66. 67. 68. 69. 70. 71. 72. 73. 74. 75. 76. 77. 78. 79. 80.
public Authenticator() { 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.S ize = 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; MinimizeBox = false; ShowInTaskbar = false; StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; Text = "Fun Department Store - Log In"; ResumeLayout(false); }
91. Access the Switchboard.cs file 92. Create a method named LogInToTheApplication and change the SwitchboardLoaded event as follows: 93. private void LogInToTheApplication() 94. { 95. bool usernamePasswordMatch = false; 96. Authenticator dlgLogIn = new Authenticator(); 97. string strPasswordFromDialogBox = "", strPasswordFromDatabase = ""; 98. string strUsernameFromDialogBox = "", strUsernameFromDatabase = ""; 99. 100. // Display the Autheticator dialog box. 101. // If the user clicks Cancel, simply close the application 102. if (dlgLogIn.ShowDialog() == System.Windows.Forms.DialogResult.Cancel) 103. Close(); 104. else // If the user clicks OK 105. { 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 application 113. Close(); 114. } 115. 116. // If the employee doesn't enter a password, display a message box... 117. if (dlgLogIn.t xtPassword.Text == "") 118. { 119. MessageBox.Show("You must type a password.", 120. "Fun Department Store", 121. MessageBoxButtons.OK, MessageBoxIcon.Information); 122. // ... and close the ap plication 123. Close(); 124. } 125. 126. // Get the user name of the dialog box 127. strUsernameFromDialogBox = dlgLogIn.txtUsername.Text;
128. 129. 130. 131. 132. 133. 134. 135. 136. 137. 138. 139. 140. 141. 142. 143. 144. 145. 146. 147. 148. 149. 150. 151. 152. 153. 154. 155. 156. 157. 158. 159. 160. 161. 162. 163. 164. 165. 166. 167. 168. 169. 170. 171. 172. 173. 174. 175. 176. 177. 178. 179. 180. 181. 182. 183. 184. 185. 186. 187. 188.
// Get the password of the dialog box strPasswordFromDialogBox = dlgLogIn.txtPassword.Text; // To connect to the database, after the following Data Source= expression, // type \\, followed by the name of the server (ours is named Expression), // followed by \\, followed by the name of the folder where the database // is installed (ours is named Fun Department Store) (of course, you must // have shared that folder), followed by \\, and followed by the name of // the database, in this case FunDS using (OleDbConnection conFunDS = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;" + @"Data Source= \\Expression \\Fun Department Store \\FunDS.accdb")) { // Get the records of all employees OleDbCommand cmdFunDS = new OleDbCommand("SELECT * FROM Employees;", conFunDS); // Create a data adapater to retrieve the employees OleDbDataAdapter odaEmployees = new OleDbDataAdap ter(cmdFunDS); // Create a data set of employees DataSet dsEmployees = new DataSet("EmployeesSet"); // Fill the data set with the Employees records odaEmployees.Fill(dsEmployees); // Open the con nection conFunDS.Open(); // Navigate to each record for (int i = 0; i < dsEmployees.Tables[0].Rows.Count; i++) { // Get a reference to the current record DataRow rcdStoreItem = dsEmployees.Tables[0].Rows[i]; // When you are on a record, get the username of the employee strUsernameFromDatabase = rcdStoreItem["Username"].ToString(); // and the p assword strPasswordFromDatabase = rcdStoreItem["UserPassword"].ToString(); // // // if { usernamePasswordMatch = t rue; // ... display the switchboard break; } // If there is no match, continue to the next record, // up to the end of the table } // If there was a match for username/password, display the Switchboard // If there was no match for username/password, // Let the employee know ... if (usernamePasswordMatch == false) { MessageBox.Show("The username and password combination did " + "not match any of the employees", "Fun Department Store", Compare the current username to the username of the dialog box and the current password to the password of the dialog box. If they match, ... (strUsernameFromDatabase.Equals(strUsernameFromDialogBox) && strPasswordFromDatabase.Equals(strPasswordFromDialogBox))
189. MessageBoxButtons.OK, Messa geBoxIcon.Information); 190. // ... and close the application 191. Close(); 192. } 193. } 194. } 195. } 196. 197. private void SwitchboardLoaded(object sender, EventArgs e) 198. { 199. LogInToTheApplication(); } 200. 201. 202. 203. 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
217. 218. 219. 220. 221. 222. 223. 224. 225. 226. 227. 228. 229. 230. 231. 232. 233. 234. 235. 236. 237. 238. 239. 240. 241. 242. 243. 244. 245. 246. 247. 248. 249. 250. 251. 252. 253. 254. 255. 256. 257. 258. 259. 260. 261. 262. 263. 264. 265. 266. 267. 268. 269. 270. 271. 272. 273.
Click the View Store Inventory button Close the forms To create a new file, on the main menu, click Project -> Add New Item... In the middle list, click Code File Set the Name to CreateStoreItem Click Add In the empty document, type the following: using using using using using using System; System.Data; System.Drawing; System.Data.OleDb; System.Windows.Forms; System.ComponentModel;
public class CreateStoreItem : Form { private Label lblItemNumber; private TextBox txtItemNumber; private Label lblArrivalDate; private MaskedTextBox txtArrivalDate; private Label lblM anufacturer; private TextBox txtManufacturer; private Label lblCategory; private ComboBox cbxCategories; private Label lblSubCategory; private ComboBox cbxSubCategories; private Label lblItemName; private TextBox txtItemName; private Label lblItemSize; private TextBox txtItemSize; private Label lblUnitPrice; private TextBox txtUnitPrice; private Label lblDiscountRate; private TextBox txtDiscountRate; private Label lblPercent; private Label lblSal eStatus; private ComboBox cbxSaleStatus; private Button btnReset; private Button btnCreate; private Button btnClose; public CreateStoreItem() { InitializeComponent(); } private void InitializeComponent() { lblItemNumber = new Label(); txtItemNumber = new TextBox(); lblArrivalDate = new Label(); txtArrivalDate = new MaskedTextBox(); lblManufacturer = new Label(); txtManufacturer = new TextBox(); lblCategory = new Label(); cbxCategories = new ComboBox();
274. 275. 276. 277. 278. 279. 280. 281. 282. 283. 284. 285. 286. 287. 288. 289. 290. 291. 292. 293. 294. 295. 296. 297. 298. 299. 300. 301. 302. 303. 304. 305. 306. 307. 308. 309. 310. 311. 312. 313. 314. 315. 316. 317. 318. 319. 320. 321. 322. 323. 324. 325. 326. 327. 328. 329. 330. 331. 332. 333. 334.
lblSubCategory = new Label(); cbxSubCategories = new ComboBox(); lblItemName = new Label(); txtItemName = new TextBox(); lblItemSize = new La bel(); txtItemSize = new TextBox(); lblUnitPrice = new Label(); txtUnitPrice = new TextBox(); lblDiscountRate = new Label(); txtDiscountRate = new TextBox(); lblPercent = new Label(); lblSaleStatus = new Label(); cbxSaleStatus = new ComboBox(); btnReset = new Button(); btnCreate = new Button(); btnClose = new Button(); SuspendLayout(); lblItemNumber.AutoSize = true; lblItemNumber.Location = new Point(11, 14); lblItemNumber.Size = new Size(40, 13); lblItemNumber.TabIndex = 0; lblItemNumber.Text = "Item #:"; txtItemNumber.Location = new Point(95, 11); txtItemNumber.Size = new Size(96 , 20); txtItemNumber.TabIndex = 1; lblArrivalDate.AutoSize = true; lblArrivalDate.Location = new Point(223, 14); lblArrivalDate.Size = new Size(65, 13); lblArrivalDate.TabIndex = 2; lblArrivalDate.Text = "Arrival Date:"; txtArrivalDate.Location = new Point(303, 11); txtArrivalDate.Mask = "00/00/0000"; txtArrivalDate.Size = new Size(121, 20); txtArrivalDate.TabIndex = 3; txtArrivalDate.ValidatingType = typeof(System.DateTime); lblManufacturer.AutoSize = true; lblManufacturer.Location = new Point(11, 43); lblManufacturer.Size = new Size(73, 13); lblManufacturer.TabIndex = 4; lblManufacturer.Text = "Manufacturer:"; txtManufacturer.Location = new Point(95, 40); txtManufacturer.Size = new Size(330, 20); txtManufacturer.TabIndex = 5; lblCategory.AutoSize = true; lblCategory.Location = n ew Point(11, 72); lblCategory.Size = new Size(52, 13); lblCategory.TabIndex = 6; lblCategory.Text = "Category:"; cbxCategories.FormattingEnabled = true; cbxCategories.Items.AddRange(new object[] { "Men", "Girls", "Boys",
335. 336. 337. 338. 339. 340. 341. 342. 343. 344. 345. 346. 347. 348. 349. 350. 351. 352. 353. 354. 355. 356. 357. 358. 359. 360. 361. 362. 363. 364. 365. 366. 367. 368. 369. 370. 371. 372. 373. 374. 375. 376. 377. 378. 379. 380. 381. 382. 383. 384. 385. 386. 387. 388. 389. 390. 391. 392. 393. 394. 395.
"Babies", "Women", "Other"}); cbxCategories.Location = new Point(95, 70); cbxCategories.Size = new Size(116, 21); cbxCategories.TabIndex = 7; lblSubCategory.AutoSize = true; lblSubCateg ory.Location = new Point(223, 73); lblSubCategory.Size = new Size(74, 13); lblSubCategory.TabIndex = 8; lblSubCategory.Text = "Sub -Category:"; cbxSubCategories.FormattingEnabled = true; cbxSubCategories.Items.AddRange(new object[] { "Skirts", "Pants", "Shirts", "Shoes", "Blouse", "Beauty", "Dresses", "Clothing", "Sweater", "Watches", "Handbags", "Miscellaneous"}); cbxSubCategories.Locati on = new Point(303, 70); cbxSubCategories.Size = new Size(121, 21); cbxSubCategories.TabIndex = 9; lblItemName.AutoSize = true; lblItemName.Location = new Point(11, 104); lblItemName.Size = new Size(61, 13); lblItemName.TabIndex = 10; lblItemName.Text = "Item Name:"; txtItemName.Location = new Point(95, 100); txtItemName.Size = new Size(329, 20); txtItemName.TabIndex = 11; lblItemSize.AutoSize = true; lblItemSize.Location = new Point(12, 132); lblItemSize.Size = new Size(30, 13); lblItemSize.TabIndex = 12; lblItemSize.Text = "Size:"; txtItemSize.Location = new Point(95, 129); txtItemSize.Size = new Size(96, 20); txtItemSize.TabIndex = 13; lblUnitPrice.AutoSize = true; lblUnitPrice.Location = new Point(224, 135); lblUnitPrice.Size = new Size(56, 13); lblUnitPrice.TabIndex = 14; lblUnitPrice.Text = "Unit Price:"; txtUnitPrice.Location = new Point(304, 132); txtUnitPrice.Size = new Size(121, 20); txtUnitPrice.TabIndex = 15; txtUnitPrice.Text = "0.00"; txtUnitPrice.TextAlign = HorizontalAlignment.Right; lblDiscountRate .AutoSize = true; lblDiscountRate.Location = new Point(11, 161); lblDiscountRate.Size = new Size(78, 13); lblDiscountRate.TabIndex = 16; lblDiscountRate.Text = "Discount Rate:"; txtDiscountRate.Location = new Point( 95, 158); txtDiscountRate.Size = new Size(96, 20); txtDiscountRate.TabIndex = 17;
396. 397. 398. 399. 400. 401. 402. 403. 404. 405. 406. 407. 408. 409. 410. 411. 412. 413. 414. 415. 416. 417. 418. 419. 420. 421. 422. 423. 424. 425. 426. 427. 428. 429. 430. 431. 432. 433. 434. 435. 436. 437. 438. 439. 440. 441. 442. 443. 444. 445. 446. 447. 448. 449. 450. 451. 452. 453. 454. 455. 456.
txtDiscountRate.Text = "0.00"; txtDiscountRate.TextAlign = HorizontalAlignment.Right; lblPercent.AutoSize = true; lblPercent.Font = new Font("Microsoft Sans Serif", 9.75F, FontStyle.Bold, GraphicsUnit.Point, 0); lblPercent.Location = new Point(191, 161); lblPercent.Size = new Size(21, 16); lblPercent.TabIndex = 18; lblPercent.Text = "%"; lblSaleStatus.AutoSize = true; lblSaleStatus.Location = new Point(224, 164); lblSaleStatus.Name = "lblSaleStatus"; lblSaleStatus.Size = new Size(64, 13); lblSaleStatus.TabIndex = 19; lblSaleStatus.Text = "Sale Status:"; cbxSaleStatus.FormattingEnabled = true; cbxSaleStatus.Items.AddRange(new object[] { "Sold", "In Stock", "On Display", "Processing", "Other"}); cbxSaleStatus.Location = new Point(304, 161); cbxSaleStatus.Size = new Size(121, 21); cbxSaleStatus.TabIndex = 20; btnReset.Location = new Point(125, 193); btnReset.Size = new Size(95, 23); btnReset.TabIndex = 23; btnReset.Text = "Reset"; btnReset.UseVisualStyleBackColor = true; btnReset.Click += new System.EventHandler(btnResetClicked); btnCreate.Location = new Point(226, 193); btnCreate.Size = new Size(108, 23); btnCreate.TabIndex = 21; btnCreate.Text = "Create"; btnCreate.UseVisualStyleBackColor = true; btnCreate.Click += new System.EventHandler(btnCreateClicked); btnClose.Location = new Point(340, 193 ); btnClose.Size = new Size(83, 23); btnClose.TabIndex = 22; btnClose.Text = "Close"; btnClose.UseVisualStyleBackColor = true; btnClose.Click += new System.EventHandler(btnClose_Click); Controls.Add( lblItemNumber); Controls.Add(txtItemNumber); Controls.Add(lblArrivalDate); Controls.Add(txtArrivalDate); Controls.Add(lblManufacturer); Controls.Add(txtManufacturer); Controls.Add(lblCategory); Controls.Add(cbxCategories); Controls.Add(lblSubCategory); Controls.Add(cbxSubCategories); Controls.Add(lblItemName); Controls.Add(txtItemName); Controls.Add(lblItemSize); Controls.Add(txtItemSize);
457. 458. 459. 460. 461. 462. 463. 464. 465. 466. 467. 468. 469. 470. 471. 472. 473. 474. 475. 476. 477. 478. 479. 480. 481. 482. 483. 484. 485. 486. 487. 488. 489. 490. 491. 492. 493. 494. 495. 496. 497. 498. 499. 500. 501. 502. 503. 504. 505. 506. 507. 508. 509. 510. 511. 512. 513. 514. 515. 516. 517.
Controls.Add(lblUnitPrice); Controls.Add(txtUnitPrice); Controls.Add(lblDiscountRate); Controls.Add(txtDiscountRate); Controls.Add(lblPercent); Controls.Add(lblSaleStatus); Controls.Add(cbxSaleStatus); Controls.Add(btnCreate); Controls.Add(btnReset); Controls.Add(btnClose); ClientSize = new Size(437, 230); FormBorderStyle = FormBorderStyle.FixedDialog; MaximizeBox = false; MinimizeBox = false; ShowInTaskbar = false; StartPosition = FormStartPosition.CenterScreen; Text = "Fun Department Store - Create New Store Item"; Load += new System.EventHandler(CreateStoreItemLoaded); ResumeLayout(false); PerformLayout(); } private void btnResetClicked(object sender, EventArgs e) { txtItemNumber.Text = ""; txtArrivalDate.Text = DateTime.Today.ToShortDateString(); txtManufacturer.Text = ""; cbxCategories.Text = " "; cbxSubCategories.Text = ""; txtItemName.Text = ""; txtItemSize.Text = ""; txtUnitPrice.Text = "0.00"; txtDiscountRate.Text = "0.00"; cbxSaleStatus.Text = "In Stock"; } private void CreateStoreItemLoaded(object sender, EventArgs e) { // When the form opens, reset it btnResetClicked(sender, e); } private void btnCreateClicked(object sender, EventArgs e) { double unitPrice = 0.00; double discountRate = 0.00; // Make sure the user entered an item number. // If not, don't do anything if (txtItemNumber.Text.Length == 0) { MessageBox.Show("You must pro vide a (unique) item number.", "Fun Department Store", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } // On a related issue, for the simplicity of this exercise, // We are not writing code to check whether the user provided
518. 519. 520. 521. 522. 523. 524. 525. 526. 527. 528. 529. 530. 531. 532. 533. 534. 535. 536. 537. 538. 539. 540. 541. 542. 543. 544. 545. 546. 547. 548. 549. 550. 551. 552. 553. 554. 555. 556. 557. 558. 559. 560. 561. 562. 563. 564. 565. 566. 567. 568. 569. 570. 571. 572. 573. 574. 575. 576. 577. 578.
// a duplicate item number. If the user does, the application // itself would throw an exception. In a nother article, we may have // to take care of that problem. For now, we will ignore it // Make sure the user entered a name for the new item. // If not, don't do anything if (txtItemName.Text.Length == 0) { MessageBox.Show("You must provide a name for the item.", "Fun Department Store", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } // Make sure the user provided a price for the item if (txtUnitPrice.Text.Length == 0) { MessageBox.Show("You must provide a price for the item.", "Fun Department Store", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } // Check if the user provided a valid price... try { unitPrice = double.Parse(txtUnitPrice.Text); } catch (FormatException) { // ... if not, use 0.00 } // Check if the user provided a valid discount rate... try { discountRate = double.Parse(txtDiscountRate.Text); } catch (FormatException) { // ... if not, use 0.00 } // Connect to the database // To connect to the database, after the following Data Source= expression, // type \\, followed by the name of the server (ours is named Expression), // followed by \\, followed by the name of the folder where the database // is installed (ours is named Fun Department Store) (of course, you must // have shared that folder), followed by \\, and followed by the name of // the database, in this case FunDS using (OleDbConnection conFunDS = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;" + @"Data Source= \\Expression \\Fun Department Store \\FunDS.accdb")) { string strSQLInsert = "INSERT INTO StoreItems(ItemNumber, ArrivalDate, " + "Manufacturer, Category, SubCategory, Ite mName, " + "ItemSize, UnitPrice, DiscountRate, SaleStatus) " + "VALUES(" + txtItemNumber.Text + ", '" + txtArrivalDate.Text + " ', '" + txtManufacturer.Text + "', '" + cbxCategories.Text + "', '" +
579. 580. 581. 582. 583. 584. 585. 586. 587. 588. 589. 590. 591. 592. 593. 594. 595. 596. 597. 598. 599. 600. 601. 602. 603. 604. } 605.
cbxSubCategories.Text + "', '" + txtItemName.Text + "', '" + txtItemSize.Text + "', " + unitPrice + ", " + discountRate + ", '" + cbxSaleStatus.Text + "');"; // Generate a command to create a record OleDbCommand cmdStoreItems = new OleDbCommand(strSQLInsert, conFunDS); conFunDS.Open(); cmdStoreItems.ExecuteNonQuery(); // Once the item has been created, let the user know MessageBox.Show("The item has been created", "Fun Department Store", MessageBoxButtons.OK, MessageBoxIcon.Information); btnResetClicked(sender, e); } } private void btnClose_Click(object sender, EventArgs e) { Close(); } In the Solution Explorer, double -click Authenticator.cs
606.
To create a new file, on the main menu, click Project -> Add New Item
607. In the middle list, make sure Code File is selected. Change the name to Employees 608. 609. 610. 611. 612. 613. 614. 615. 616. Click Add In the empty document, type the following: using using using using using using using System; System.IO; System.Data; System.Drawing; System.Data.OleDb; System.Windows.Forms; System.ComponentModel;
617. 618. public class Employees : Form 619. { 620. private ColumnHeader colEmployeeNumber; 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 tx tEmployeeNumber; 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 c hkManager; 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. 679. 680. 681. 682. 683. 684. 685. 686. 687. 688. 689. 690. 691. 692. 693. 694. 695. 696. 697. 698. 699. 700. 701. 702. 703. 704. 705. 706. 707. 708. 709. 710. 711. 712. 713. 714. 715. 716. 717. 718. 719. 720. 721. 722. 723. 724. 725. 726. 727. 728. 729. 730. 731. 732. 733. 734. 735. 736. 737. 738.
lblHourlySalary = new Label(); txtHourlySal ary = new TextBox(); btnSubmit = new Button(); lblUsername = new Label(); txtUsername = new TextBox(); lblPassword = new Label(); txtPassword = new TextBox(); btnClose = new Button(); grpNewEmployee. SuspendLayout(); SuspendLayout(); colEmployeeNumber.Text = "Employee #"; colEmployeeNumber.Width = 70; colFirstName.Text = "First Name"; colFirstName.Width = 80; colLastName.Text = "Last Name"; colLastName.Width = 80; colTitle.Text = "Title"; colTitle.Width = 120; colManager.Text = "Manager"; colHourlySalary.Text = "Salary"; colHourlySalary.TextAlign = System.Windows.Forms.HorizontalAlignment.Right; colHourlySalary.Width = 50; colUsername.Text = "Username"; colPassword.Text = "Password"; lvwEmployees.Columns.AddRange(new ColumnHeader[] { colEmployeeNumber, colFirstName, colLastName, colTitle, colManager, colHourlySalary, colUsername, colPassword}); lvwEmployees.FullRowSelect = true; lvwEmployees.GridLines = true; lvwEmployees.Location = new Point(12, 12); lvwEmployees.Size = new Size(606, 191); lvwEmployees.TabIndex = 0; lvwEmployees.UseCompatibleStateImageBehavior = false; lvwEmployees.View = System.Win dows.Forms.View.Details; grpNewEmployee.Controls.Add(lblEmployeeNumber); grpNewEmployee.Controls.Add(txtEmployeeNumber); grpNewEmployee.Controls.Add(lblFirstName); grpNewEmployee.Controls.Add(txtFirstName); grpNewEmployee.Controls.Add(lblLastName); grpNewEmployee.Controls.Add(txtLastName); grpNewEmployee.Controls.Add(lblTitle); grpNewEmployee.Controls.Add(txtTitle); grpNewEmployee.Controls.Add(btnReset); grpNewEmployee.Controls .Add(chkManager); grpNewEmployee.Controls.Add(lblHourlySalary); grpNewEmployee.Controls.Add(txtHourlySalary); grpNewEmployee.Controls.Add(btnSubmit); grpNewEmployee.Controls.Add(lblUsername); grpNewEmployee.Controls.Add(txtUsername); grpNewEmployee.Controls.Add(lblPassword);
739. 740. 741. 742. 743. 744. 745. 746. 747. 748. 749. 750. 751. 752. 753. 754. 755. 756. 757. 758. 759. 760. 761. 762. 763. 764. 765. 766. 767. 768. 769. 770. 771. 772. 773. 774. 775. 776. 777. 778. 779. 780. 781. 782. 783. 784. 785. 786. 787. 788. 789. 790. 791. 792. 793. 794. 795. 796. 797. 798. 799.
grpNewEmployee.Controls.Add(txtPassword); grpNewEmployee.Location = new Point(12, 209); grpNewEmployee.Size = new Size(605, 165); grpNewEmployee.TabIndex = 1; grpNewEmployee.TabStop = false; grpNewEmployee.Text = "New Employee"; lblEmployeeNumber.AutoSize = true; lblEmployeeNumber.Location = new Point(42, 29); lblEmployeeNumber.Size = new Size(6 6, 13); lblEmployeeNumber.TabIndex = 0; lblEmployeeNumber.Text = "Employee #:"; txtEmployeeNumber.Location = txtEmployeeNumber.Mask = "00 txtEmployeeNumber.Size = new txtEmployeeNumber.TabIndex = new Point(124, 26); -000"; Size(52, 20); 1;
lblFirstName.AutoSize = true; lblFirstName.Location = new Point(42, 55); lblFirstName.Size = new Size(60, 13); lblFirstName.TabIndex = 2; lblFirstName.Text = "First Name:"; txtFirstName.Location = new Point(124, 52); txtFirstName.Size = new Size(100, 20); txtFirstName.TabIndex = 3; lblLastName.AutoSize = true; lblLastName.Location = new Point(245, 55); lblLastName.Size = new Si ze(61, 13); lblLastName.TabIndex = 4; lblLastName.Text = "Last Name:"; txtLastName.Location = new Point(327, 52); txtLastName.Name = "txtLastName"; txtLastName.Size = new Size(100, 20); txtLastName.TabIndex = 5; lblTitle.AutoSize = true; lblTitle.Location = new Point(42, 81); lblTitle.Size = new Size(30, 13); lblTitle.TabIndex = 6; lblTitle.Text = "Title:"; txtTitle.Location = new Point(124, 78); txtTitle.Name = "txtTitle"; txtTitle.Size = new Size(303, 20); txtTitle.TabIndex = 7; btnReset.Location = new Point(447, 104); btnReset.Size = new Size(97, 23); btnReset.TabIndex = 15; btnReset.Text = "Reset"; btnReset.UseVisualStyleBackColor = true; btnReset.Click += new System.EventHandler(btnResetClicked); chkManager.AutoSize = chkManager.CheckAlign chkManager.Location = chkManager.Size = new true; = ContentAlignment.MiddleRight; new Point(45, 107); Size(91, 17);
800. 801. 802. 803. 804. 805. 806. 807. 808. 809. 810. 811. 812. 813. 814. 815. 816. 817. 818. 819. 820. 821. 822. 823. 824. 825. 826. 827. 828. 829. 830. 831. 832. 833. 834. 835. 836. 837. 838. 839. 840. 841. 842. 843. 844. 845. 846. 847. 848. 849. 850. 851. 852. 853. 854. 855. 856. 857. 858. 859. 860.
chkManager.TabIndex = 8; chkManager.Text = "Is a Manager:"; chkManager.UseVisualStyleBackColor = true; lblHourlySalary.AutoSize = true; lblHourlySalary.Location = new Point(245, 107); lblHourlySalary.Size = new Size(72, 13); lblHourlySalary.TabIndex = 9; lblHourlySalary.Text = "Hourly Salary:"; txtHourlySalary.Location = new Point(327, 104); txtHourlySalary.Size = new Size(100, 20); txtHourlySalary.TabIndex = 10; txtHourlySalary.Text = "0.00"; txtHourlySalary.TextAlign = HorizontalAlignment.Right; btnSubmit.Location = new Point(447, 132); btnSubmit.Size = new Size(97, 23); btnSubmit.TabIndex = 16; btnSubmit.Text = "Submit"; btnSubmit.UseVisualStyleBackColor = true; btnSubmit.Click += new System.EventHandler(btnSubmitClicked); lblUsername.Auto Size = true; lblUsername.Location = new Point(42, 133); lblUsername.Size = new Size(58, 13); lblUsername.TabIndex = 11; lblUsername.Text = "Username:"; txtUsername.Location = new Point(124, 130); txtUsername.Size = new Size(100, 20); txtUsername.TabIndex = 12; lblPassword.AutoSize = true; lblPassword.Location = new Point(245, 132); lblPassword.Size = new Size(56, 13); lblPassword.TabIndex = 13; lblPassword.Text = "Password:"; txtPassword.Location = new Point(327, 130); txtPassword.PasswordChar = '*'; txtPassword.Size = new Size(100, 20); txtPassword.TabIndex = 14; btnClose.Location = new Point(459, 384 ); btnClose.Size = new Size(97, 23); btnClose.TabIndex = 17; btnClose.Text = "Close"; btnClose.UseVisualStyleBackColor = true; btnClose.Click += new System.EventHandler(btnCloseClicked); ClientSize = new Size(629, 414); Controls.Add(grpNewEmployee); Controls.Add(lvwEmployees); Controls.Add(btnClose); FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; MaximizeBox = false; MinimizeBox = false; ShowInTaskbar = false; StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; Text = "Fun Department Store - Employees";
861. 862. 863. 864. 865. 866. 867. 868. 869. 870. 871. 872. 873. 874. 875. 876. 877. 878. 879. 880. 881. 882. 883. 884. 885. 886. 887. 888. 889. 890. 891. 892. 893. 894. 895. 896. 897. 898. 899. 900. 901. 902. 903. 904. 905. 906. 907. 908. 909. 910. 911. 912. 913. 914. 915. 916. 917. 918. 919. 920. 921.
Load += new System.EventHandler(Employees_Load); grpNewEmployee.ResumeLayout(fals e); grpNewEmployee.PerformLayout(); ResumeLayout(false); } private void ShowEmployees() { lvwEmployees.Items.Clear(); // To connect to the database, after the following Data Source= expression, // type \\, followed by the name of the server (ours is named Expression), // followed by \\, followed by the name of the folder where the database // is installed (ours is named Fun Department Store) (of course, you must // have shared that folder), followed by \\, and followed by the name of // the database, in this case FunDS using (OleDbConnection conFunDS = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;" + @"Data Source= \\Expression \\Fun Department Store \\FunDS.accdb")) { // Select all store items OleDbCommand cmdFunDS = new OleDbCommand("SELECT * FROM Employees;", conFunDS); OleDbDataAdapter odaFunDS = new OleDbDataAdapter(cmdFunDS); DataSet dsEmployees = new DataSet("EmployeesSet"); odaFunDS.Fill(dsEmployees); conFunDS.Open(); // Using the total number of records, display each in the list view for (int i = 0; i < dsEmployees.Tables[0].Rows.Count; i++) { DataRow rcdEmployee = dsEmployees.Tables[0].Rows[i]; ListViewItem lviEmployee = new ListViewItem((i + 1).ToString()); lviEmployee.SubItems.Add(rcdEmployee["employeeNumber"].ToString()); lviEmployee.SubItems.Add(rcdEmployee["FirstName"].ToString()); lviEmployee.SubItems.Add(rcdEmployee["LastName"].ToString()); lviEmployee.SubItems.Add(rcdEmployee["Title"].ToString()); lviEmployee.SubItems.Add(rcdEmployee["Manager"].ToString()); lviEmployee.SubItems.Add(rcdEmployee["HourlySalary"].ToString()); lviEmployee.SubItems. Add(rcdEmployee["Username"].ToString()); lviEmployee.SubItems.Add(rcdEmployee["UserPassword"].ToString()); lvwEmployees.Items.Add(lviEmployee); } } } private void Employees_Load(object sender, EventArgs e) { ShowEmployees(); btnResetClicked(sender, e); } private void btnResetClicked(object sender, EventArgs e) { Random rndNumber = new Random(); txtEmployeeNumber.Text = rndNumber.Next(10000, 99999).ToString(); txtFirstName.Text = "";
922. 923. 924. 925. 926. 927. 928. 929. 930. 931. 932. 933. 934. 935. 936. 937. 938. 939. 940. 941. 942. 943. 944. 945. 946. 947. 948. 949. 950. 951. 952. 953. 954. 955. 956. 957. 958. 959. 960. 961. 962. 963. 964. 965. 966. 967. 968. 969. 970. 971. 972. 973. 974. 975. 976. 977. 978. 979. 980. 981. 982.
txtLastName.Text = ""; txtTitle.Text = ""; chkManager.Checked = false; txtHourlySalary.Text = "0.00"; txtUsername.Text = ""; txtPassword.Text = ""; } private void btnSubmitClicked(object sender, EventArgs e) { double hourlySalary = 0.00; try { hourlySalary = double.Parse(txtHourlySalary.Text); } catch (FormatException) { } // Connect to the database // To connect to the database, after the following Data Source= expression, // type \\, followed by the name of the server (ours is named Expression), // followed by \\, followed by the name of the folder where the database // is installed (ours is named Fun Department Store) (of course, you must // have shared that folder), followed by \\, and followed by the name of // the database, in this case FunDS using (OleDbConnection conFunDS = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;" + @"Data Source= \\Expression \\Fun Department Store \\FunDS.accdb")) { string strSQLInsert = "INSERT INTO Employees(EmployeeNumber, FirstName, " + "LastName, Title, Manager, HourlySalary, " + "Username, UserPassword) VALUES('" + txtEmployeeNumber.Text + "', '" + txtFirstName.Text + "', '" + txtLastName.Text + "', '" + txtTitle.Te xt + "', " + chkManager.Checked + ", " + hourlySalary + ", '" + txtUsername.Text + "', '" + txtPassword.Text + "');"; // Generate a command to create a record OleDbCommand cmdEmployees = new OleDbCommand(strSQLInsert, conFunDS); conFunDS.Open(); cmdEmployees.ExecuteNonQuery(); MessageBox.Show("The employee has been created.", "Fun Department Store", MessageBoxButtons.OK, MessageBoxIcon.Information); btnResetClicked(s ender, e); } } private void btnCloseClicked(object sender, EventArgs e) { Close(); }
ontextual 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 peo his may sound complicated but it really is not. Or the real difficulty lies, not in programming, but in logic and organizati on (desig One way to solve the problem would consist of making a list of objects in your appl ication, another list of people in your organizati hen specify who will have access to what and who would be denied access to what. This would work perfectly fine in a sm rganization and a small application that hardly changes, but this may not be practical in larger scenarios. Another solution cons f creating groups of people, adding people to those groups, and then deciding what group has access to what.
n 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 st em.
42. 43. 44. 45. 46. 47. 48. 49. 50. 51. 52. 53. 54. 55. 56. 57. 58. 59. 60. 61. 62. 63. 64. 65. 66. 67. 68. 69. 70. 71. 72. 73. 74. 75. 76. 77. 78. 79. 80. 81. 82. 83. 84. 85. 86. 87. 88. 89. 90. 91. 92. 93. 94. 95. 96. 97. 98. 99. 100. 101. 102.
btnStoreInventory.Click += new System.EventHandler(btnStoreInventoryClicked); btnCreateStoreItem.Font = new Font("Georgia", 18F, FontStyle.Bold, GraphicsUnit.Point, 0); 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(btnLog InUser); 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) { Close(); }
103. 104. 105. 106. 107. 108. 109. 110. 111. 112. 113. 114. 115. 116. 117. 118. 119. 120. 121. 122. 123. 124. 125. 126. 127. 128. 129. 130. 131. 132. 133. 134. 135. 136. 137. 138. 139. 140. 141. 142. 143. 144. 145. 146. 147. 148. 149. 150. 151. 152. 153. 154. 155. 156. 157. 158. 159. 160. 161. 162. 163.
private void LogInToTheApplication() { bool usernamePasswordMatch = false; bool currentEmployeeIsManager = false; Authenticator dlgLogIn = new Authenticator(); string strPasswordFromDialogBox = "", strPasswordFromDatabase = ""; string strUsernameFromDialogBox = "", strUsernameFromDatabase = ""; // Display the Autheticator dialog box. // If the user clicks Cancel, simply close the application if (dlgLogIn.ShowDialog() == System.Windows.Forms.DialogResult.Cancel) Close(); else // If the user clicks OK { // If the employee doesn't ent er a username, display a message box... if (dlgLogIn.txtUsername.Text == "") { MessageBox.Show("You must enter a user name.", "Fun Department Store", MessageBoxButtons.OK, MessageBoxIcon.Information); // ... and close the application Close(); } // If the employee doesn't enter a password, display a message box... if (dlgLogIn.txtPassword.Text == "") { MessageBox.Show("You must type a password.", "Fun Department Store", MessageBoxButtons.OK, MessageBoxIcon.Information); // ... and close the application Close(); } // Get the user name of the dialog box strUsernameFromDialog Box = dlgLogIn.txtUsername.Text; // Get the password of the dialog box strPasswordFromDialogBox = dlgLogIn.txtPassword.Text; // To connect to the database, after the following Data Source= expression, // type \\, followed by the name of the server (ours is named Expression), // followed by \\, followed by the name of the folder where the database // is installed (ours is named Fun Department Store) (of course, you must // have shared that folder), followed by \\, and followed by the name of // the database, in this case FunDS using (OleDbConnection conFunDS = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;" + @"Data Source= \\Expression \\Fun Department Store \\FunDS.accdb")) { // Get the records of all employees OleDbCommand cmdFunDS = new OleDbCommand("SELECT * FROM Employees;", conFunDS); // Create a data adapater to retrieve the employees OleDbDataAdapter odaEmployees = new OleDbDataAdapter(cmdFunDS); // Create a data set of employees DataSet dsEmployees = new DataSet("Employe esSet"); // Fill the data set with the Employees records odaEmployees.Fill(dsEmployees); // Open the connection conFunDS.Open();
164. 165. 166. 167. 168. 169. 170. 171. 172. 173. 174. 175. 176. 177. 178. 179. 180. 181. 182. 183. 184. 185. 186. 187. 188. 189. 190. 191. 192. 193. 194. 195. 196. 197. 198. 199. 200. 201. 202. 203. 204. 205. 206. 207. 208. 209. 210. 211. 212. 213. 214. 215. 216. 217. 218. 219. 220. 221. 222. 223. 224.
// Navigate to each record for (int i = 0; i < dsEmployees.Tables[0].Rows.Count; i++) { // Get a reference to the current record DataRow rcdEmployee = dsEmployees.Tables[0].Rows[i]; // Get the managing status of the employee currentEmployeeIsManager = bool.Parse(rcdEmployee["Manager"].ToString()); // When you are on a record, get the username of the employee strUsernameFromDatabase = rcdEmployee["User name"].ToString(); // and the password strPasswordFromDatabase = rcdEmployee["UserPassword"].ToString(); // // // if { usernamePasswordMatch = true; // Find out whether this employee is a manager. // If so, make a referenc e... if (currentEmployeeIsManager == true) employeeIsAManager = true; else employeeIsAManager = false; // ... and stop searchin g break; } // If there is no match, continue to the next record, // up to the end of the table } // If there was a match for username/password, display the Switchboard // If there was no match for username/password, // Let the employee know ... if (usernamePasswordMatch == false) { MessageBox.Show("The username and password combination did " + "not match any of the employees", "Fun Department Store", MessageBoxButtons.OK, MessageBoxIcon.Information); // ... and close the application Close(); } } } } private void LogInAsADifferentEmployee () { bool currentEmployeeIsManager = false; bool usernamePasswordMatch = false; Authenticator dlgLogIn = new Authenticator(); string strPasswordFromDialogBox = "", strPasswordFromDatabase = ""; string strUsernameFromDialogBox = "", strUsernameFromDatabase = ""; Compare the current username to the username of the dialog box and the current password to the password of the dialog box. If they match, ... (strUsernameFromDatabase.Equals(strUsernameFromDialogBox) && strPasswordFromDatabase.Equals(strPasswordFromDialogBox))
225. 226. 227. 228. 229. 230. 231. 232. 233. 234. 235. 236. 237. 238. 239. 240. 241. 242. 243. 244. 245. 246. 247. 248. 249. 250. 251. 252. 253. 254. 255. 256. 257. 258. 259. 260. 261. 262. 263. 264. 265. 266. 267. 268. 269. 270. 271. 272. 273. 274. 275. 276. 277. 278. 279. 280. 281. 282. 283. 284. 285.
// Display the Autheticator dialog box. // If the user clicks Cancel, simply close the application if (dlgLogIn.ShowDialog() == System.Windows.Forms.Dialog Result.Cancel) return; else // If the user clicks OK { // If the employee doesn't enter a username, display a message box... if (dlgLogIn.txtUsername.Text == "") MessageBox.Show("You must enter a user name.", "Fun Department Store", MessageBoxButtons.OK, MessageBoxIcon.Information); // If the employee doesn't enter a passwo rd, display a message box... if (dlgLogIn.txtPassword.Text == "") MessageBox.Show("You must type a password.", "Fun Department Store", MessageBoxButtons.OK, Message BoxIcon.Information); // Get the user name of the dialog box strUsernameFromDialogBox = dlgLogIn.txtUsername.Text; // Get the password of the dialog box strPasswordFromDialogBox = dlgLogIn.txtPassword.Text; // To connect to the database, after the following Data Source= expression, // type \\, followed by the name of the server (ours is named Expression), // followed by \\, followed by the name of the folder where the data base // is installed (ours is named Fun Department Store) (of course, you must // have shared that folder), followed by \\, and followed by the name of // the database, in this case FunDS using (OleDbConnection conFunDS = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;" + @"Data Source= \\Expression \\Fun Department Store \\FunDS.accdb")) { // Get the records of all emp loyees OleDbCommand cmdFunDS = new OleDbCommand("SELECT * FROM Employees;", conFunDS); // Create a data adapater to retrieve the employees OleDbDataAdapter odaEmployees = new OleDbDataAdapter(cmdFunDS); // Create a data set of employees DataSet dsEmployees = new DataSet("EmployeesSet"); // Fill the data set with the Employees records odaEmployees.Fill(dsEmployees); // Open the connection conFunDS.Open(); // Navigate to each record for (int i = 0; i < dsEmployees.Tables[0].Rows.Count; i++) { // Get a reference to the c urrent record DataRow rcdEmployee = dsEmployees.Tables[0].Rows[i]; // Get the managing status of the employee currentEmployeeIsManager = bool.Parse(rcdEmployee["Manager"].ToString()); // When you are on a record, get the username of the employee strUsernameFromDatabase = rcdEmployee["Username"].ToString(); // and the password strPasswordFromDatabase = rcdEmployee["User Password"].ToString(); // Compare the current username to the username of the dialog box
286. 287. 288. 289. 290. 291. 292. 293. 294. 295. 296. 297. 298. 299. 300. 301. 302. 303. 304. 305. 306. 307. 308. 309. 310. 311. 312. 313. 314. 315. 316. 317. 318. 319. 320. 321. 322. 323. 324. 325. 326. 327. 328. 329. 330. 331. 332. 333. 334. 335. 336. 337. 338. 339. 340. 341. 342. 343. 344. 345. 346.
// and the current password to the password of the dialog box. // If they match, ... if (strUsernameFromDatabase.Equals(strUsernameFromDialogBox) && strPasswordFromDatabase.Equals(strPasswordFromDialogBox)) { usernamePasswordMatch = true; // Find out whether this employee is a manager. // If so, make a reference. if (currentEmployeeIsManager == true) employeeIsAManager = true; else employeeIsAManager = false; // ... display the switchboard break; } // If there is no match, continue to the next record, // up to the end of the table } // If there was a match for username/password, display the Switchboard // If there was no match for username/password, // Let the employee know ... if (usernamePasswordMatch == false) { MessageBox.Show("The username and password combination did " + "not match any of the employees", "Fun Department Store", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } } } } private void SwitchboardLoaded( object sender, EventArgs e) { employeeIsAManager = false; LogInToTheApplication(); } private void btnCreateStoreItemClicked(object sender, EventArgs e) { CreateStoreItem csi = new CreateStoreItem(); Using the global canCreateStoreItem variable, find out whether the current user is a manager. If the user is, then display the Create Store Item form (employeeIsAManager == true) csi.ShowDialog(); else // If the user is not, diaplay a message box MessageBox.Show("You are not authorized to create store items.", "Fun Department Store", MessageBoxButtons.OK, MessageBoxIcon.Info rmation); } private void btnLogInUserClicked(object sender, EventArgs e) // // // if
347. { 348. LogInAsADifferentEmployee(); 349. } 350. 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 them 359. staff.grpNewEmployee.Enabled = false; 360. 361. staff.ShowDialog(); 362. } 363. } 364. 365. public class DepartmentStore 366. { 367. public static int Main() 368. { 369. Application.Run(new Switchboard()); 370. return 0; 371. } } 372. 373. 374. 375. 376. 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
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
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
395.
Click Create
Read the message box and click OK Close the form Click Employees
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
Close the form Cick Create Store Iteam Read the message and click OK
ntroduction
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: y y This article will not teach Microsoft Access. If you need to study databases with Microsoft Access, we ha ve 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 yo have computers that still use Microsoft Access 97, Microsoft Access 2000, Microsoft Access 2002, or Microsoft Access 2003, th
database should have the extension .mdb. If you are creating the database using either Microsoft Access 2007 or Microsoft Acces 2010, you can ask it to save the database in a version that is compatible with previous versions. To do that: y
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
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 wi ll be used automatically)
When it comes to distributing a Microsoft Access database, you may have some issues to deal with, not because it is difficult . On of the concerns has to do with the other computers. If the other computers don't have Microsoft Access, you would nee something called the Access Runtime. This is probably the cheapest solution but it may present some challenges. We will not d e with that here.
Another solution is to install Microsoft Access on each computer. This may be the most expensive solution but it is the easies Most companies use that solution because it is easy either to purchase many copies or get many licenses of Microsoft Offic Professional, which includes Microsoft Access. If you want to follow the instructions in this exercise, you can use our Bethesda Car Rental database. 1. To start, using a USB drive or any other way (CD, DVD, etc), copy your database to that portable drive 2. 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 3. Copy the database file into that folder
4. 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)
5. Click the arrow of the combo box in the File Sharing window and select Everyone:
6. After selecting Everyone, click Add 7. Click the down-pointing arrow on the right side of Everyone: o If you are sharing from Microsoft Windows Server 2008, select Contributor
8. Click Share. If you receive a message box, click Continue. You should receive a message box telling that the sharing was successful
9. Click Close 10. In another computer where you want to access the database, open a file utility such as Windows Explorer 11. Click Network 12. Click the name of the computer to show its shared folders:
13. Open the folder that contains the database 14. Right-click the name of the database, position the mouse on Send To, and click Desktop (Create Shortcut)
As an alternative, you could right-click the database and click Create Shortcut, then copy that shoftcut where you want the database to be accessible 15. To open the database from that computer, double-click the shortcut
ntroduction
A 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, ncluding 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
Click Share:
py the following pictures to any folder somewhere on your computer (this is simply an example of preparing the pictures of cars y lude in your application):
BMW: 335i
Chevrolet Avalanche
Honda Accord
Mazda Miata
Chevrolet Aveo
Ford E150XL
Buick Lacrosse
Honda Civic
Ford F-150
Mazda Mazda5
Volvo S40
art Microsoft Visual Studio create a new application, on the main menu, click File -> New Project...
you are using Microsoft Visual Studio, in the left list, click Visual C#. In the middle list, click Windows Forms Application
ck OK
ontrol
utton
utton
utton
utton
utton
save the project, on the Standard toolbar, click the Save All button
uction
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 sers, you have various options. First you must create a form that holds the controls a user would use to enter the time work is obvious.
he real aspects you should think of is how the users would access the time sheet. You can simply let them open the form, but identified. Once againg you have many options. If you are using an application for which a user must be authenticated before u h 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 k for that employee's record in the company.
aspect you should (must) take care of is to find out if an employee i s creating a new time sheet or updating an existing time shee
he employee is creating a new time sheet, you would get the values and create a new record
he 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 t ues the user entered and replace those in the existing time sheet
on is, who will determine whether the user is creating a new time sheet or updating an existing time sheet? The answer to this you decide to implement the time sheet.
le continues from that of Authentication. This means that you must have created a folder namedFun Department
and created a database named FunDS in that folder. The database contains a table named Employees.
eate the following fields Data Type AutoNumber 20 Date/Time 40 Number Number Number Number Number Number Number Number Number Number Number Number Number Number Memo Double Double Double Double Double Double Double Double Double Double Double Double Double Double Fixed Fixed Fixed Fixed Fixed Fixed Fixed Fixed Fixed Fixed Fixed Fixed Fixed Fixed Field Size Format Caption Time Sheet ID Employee # Start Date Time Sheet Code Monday Tuesday Wednesday Thursday Friday Saturday Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sunday Required: Yes Default Value = 0 Default Value = 0 Default Value = 0 Default Value = 0 Default Value = 0 Default Value = 0 Default Value = 0 Default Value = 0 Default Value = 0 Default Value = 0 Default Value = 0 Default Value = 0 Default Value = 0 Default Value = 0 Other Properties Primary Key
eld Name
meSheetID
mployeeNumber
artDate
meSheetCode
eek1Monday
eek1Tuesday
eek1Wednesday
eek1Thursday
eek1Friday
eek1Saturday
eek1Sunday
eek2Monday
eek2Tuesday
eek2Wednesday
eek2Thursday
eek2Friday
eek2Saturday
eek2Sunday
otes
change the view, right-click the tab of the table and click Datasheet View
se Microsoft Access
create a new application, on the main menu, click File -> New Project...
you are using Microsoft Visual Stuio, in the left frame, click Visual C# Projects. the middle list, click Empty Project
se the Properties window the main menu, click Project -> Add Reference...
ck System
ck System.Drawing
ck System.Windows.Forms
ck System.Xml
ease Ctrl
ck OK
create a file for the project, on the main menu, click Project -> Add New Item...
ck Add
the empty document, type the following: System; System.Data; System.Drawing; System.Data.OleDb; System.Windows.Forms; System.ComponentModel;
ublic class TimeSheet : Form private private private private private private private private private private private private private private private private private private private private private private private private private Label lblIdentification; Panel pnlTopLine; Label lblEmployeeNumber; MaskedTextBox txtEmployeeNumber; TextBox txt EmployeeName; Label lblStartDate; DateTimePicker dtpStartDate; Label lblEndDate; DateTimePicker dtpEndDate; TextBox txtTimeSheetCode; Panel pnlSecondLine; Label lblTimeReco rding; Label lblMonday; Label lblTuesday; Label lblWednesday; Label lblSaturday; Label lblFriday; Label lblThursday; Label lblSunday; Label lblWeek1; TextBox txtWeek1Monday; TextBox txtWeek1Tuesday; TextBox txtWeek1Wednesday; TextBox txtWeek1Thursday; TextBox txtWeek1Friday;
private private private private private private private private private private private private private private private private
TextBox txtWeek1Saturday; TextBox txtWeek1Sund ay; Label lblWeek2; TextBox txtWeek2Monday; TextBox txtWeek2Tuesday; TextBox txtWeek2Wednesday; TextBox txtWeek2Thursday; TextBox txtWeek2Friday; TextBox txtWeek2Saturday; TextBox txtWeek2Sunday; Label lblNotes; TextBox txtNotes; Panel pnlBottomLine; Button btnReset; Button btnSubmit; Button btnClose;
public TimeSheet() { InitializeComponent(); } private void InitializeComponent() { lblIdentification = new Label(); pnlTopLine = new Panel(); lblEmployeeNumber = new Label(); txtEmployeeNumber = new MaskedTextBox(); txtEmployeeName = new TextBox(); lblStartDate = new Label(); dtpStartDate = new DateTimePicker(); lblEndDate = new Label(); dtpEndDate = new DateTimePicker(); txtTimeSheetCode = new TextBox(); pnlSecondLine = new Panel(); lblTimeRecording = new Label(); lblMonday = new Label(); lblTuesday = new Label(); lblWednesday = new Label(); lblSaturday = new Label(); lblFriday = new Label(); lblThursday = new Label(); lblSunday = new Label(); lblWeek1 = new Label(); txtWeek1Monday = new TextBox(); txtWeek1Tuesday = new TextBox(); txtWeek1Wednesday = new TextBox(); txtWeek1Thursday = new T extBox(); txtWeek1Friday = new TextBox(); txtWeek1Saturday = new TextBox(); txtWeek1Sunday = new TextBox(); lblWeek2 = new Label(); txtWeek2Monday = new TextBox(); txtWeek2Tuesday = new TextBox(); txtWeek2Wednesday = new TextBox(); txtWeek2Thursday = new TextBox(); txtWeek2Friday = new TextBox(); txtWeek2Saturday = new TextBox(); txtWeek2Sunday = new TextBox(); lblNotes = new Label(); txtNotes = new TextBox();
pnlBottomLine = new Panel(); btnReset = new Button(); btnSubmit = new Button(); btnClose = new Button(); SuspendLayout(); lblIdentification.BackColor = Color.FromArgb(64, 64, 64); lblIdentification.Font = new Font("Tiffany Lt BT", 12F, FontStyle.Bold, GraphicsUnit.Point,0); lblIdentification.ForeColor = Color.White; lblIdentification.Location = new Point(12, 11); lblIdentification.Size = new Size(141, 19); lblIdentification.TabIndex = 0; lblIdentification.Text = "Identification"; pnlTopLine.BackColor = Color.FromArgb(64, 64, 64); pnlTopLine.Location = new Point(124, 28); pnlTopLine.Size = new Size(444, 2); pnlTopLine.TabIndex = 1; lblEmployeeNumber.AutoSize = true; lblEmployeeNumber.Location = new Point(130, 42); lblEmployeeNumber.Size = new Size(66, 13); lblEmployeeNumber.TabIndex = 2; lblEmployeeNumber.Text = "Employee #:"; txtEmployeeNumber.Location = new Point(211, 39); txtEmployeeNumber.Mask = "00 -000"; txtEmployeeNumber.Size = new Size(52, 20); txtEmployeeNumber.TabIndex = 3; txtEmployeeNumber.Leave += new System.EventHandler(txtEmployeeNumberLeave); txtEmployeeName.Location = new Point(269, 39); txtEmployeeName.Size = new Size(142, 20); txtEmployeeName.TabIndex = 37; dtpEndDate.Location = new Point(211, 101); dtpEndDate.Size = new Size(200, 20); dtpEndDate.TabIndex = 39; lblEndDate.AutoSize = true; lblEndDate.Location = new Point(130, 107); lblEndDate.Size = new Size(55, 13); lblEndDate.TabIndex = 38; lblEndDate.Text = "End Date:"; lblStartDate.AutoSize = true; lblStartDate.Location = new Point(130, 73); lblStartDate.Size = new Size(58, 13); lblStartDate.TabIndex = 4; lblStartDate.Text = "Start Date:"; dtpStartDate.Location = dtpStartDate.Size = new dtpStartDate.TabIndex = dtpStartDate.CloseUp += new Point(211, 70); Size(200, 20); 5; new System.EventHandler(dtpStartDateClosedUp);
txtTimeSheetCode.Enabled = false; txtTimeSheetCode.Location = new Point(420, 100); txtTimeSheetCode.Size = new Size(132, 20); txtTimeSheetCode.TabIndex = 40;
pnlSecondLine.BackColor = Color.FromArgb(64, 64, 64); pnlSecondLine.Location = new Point(150, 154); pnlSecondLine.Size = new Size(415, 2); pnlSecondLine.TabIndex = 7; lblTimeRecording.BackColor = Color.FromArgb(64, 64, 64); lblTimeRecording.Font = new Font("Tiffany Lt BT", 12F, FontStyle.Bold, GraphicsUnit.Point,0); lblTimeRecording.ForeColor = Color.White; lblTimeRecording.Location = new Point(12, 134); lblTimeRecording.Size = new Size(141, 22); lblTimeRecording.TabIndex = 6; lblTimeRecording.Text = "Time Recording"; lblMonday.AutoSize = true; lblMonday.Location = new Point(72, 174); lblMonday.Size = new Size(45, 13); lblMonday.TabIndex = 8; lblMonday.Text = "Monday"; lblTuesday.AutoSize = true; lblTuesday.Location = new Point(141, 174); lblTuesday.Size = new Size(48, 13); lblTuesday.TabIndex = 9; lblTuesday.Text = "Tuesday"; lblWednesday.AutoSize = true; lblWednesday.Location = new Point(212, 174); lblWednesday.Size = new Size(64, 13); lblWednesday.TabIndex = 10; lblWednesday.Text = "Wednesday"; lblThursday.AutoSize = true; lblThursday.Location = new Point(279, 174); lblThursday.Name = "lblThursday"; lblThursday.Size = new Size(51, 13); lblThursday.TabIndex = 11; lblThursday.Text = "Thursday"; lblFriday.AutoSize = true; lblFriday.Location = new Point(348, 174); lblFriday.Size = new Size(35, 13); lblFriday.TabIndex = 12; lblFriday.Text = "Friday"; lblSaturday.AutoSize = true; lblSaturday.Location = new Point(417, 174); lblSaturday.Size = new Size(49, 13); lblSaturday.TabIndex = 13; lblSaturday.Text = "Saturday"; lblSunday.AutoSize = true; lblSunday.Location = new Point(495, 174); lblSunday.Size = new Size(43, 13); lblSunday.TabIndex = 14; lblSunday.Text = "Sunday"; lblWeek1.AutoSize = lblWeek1.Location = lblWeek1.Size = new lblWeek1.TabIndex = true; new Point(12, 197); Size(48, 13); 15;
lblWeek1.Text = "Week 1:"; txtWeek1Monday.Location = new Point(75, 194); txtWeek1Monday.Size = new Size(63, 20); txtWeek1Monday.TabIndex = 16; txtWeek1Monday.Text = "0.00"; txtWeek1Monday.TextAlign = HorizontalAlignment.Right; txtWeek1Tuesday.Location = new Point(144, 194); txtWeek1Tuesday.Size = new Size(63, 20); txtWeek1Tuesday.TabIndex = 17; txtWeek1Tuesday.Text = "0.00"; txtWeek1Tuesday.TextAlign = HorizontalAlignment.Right; txtWeek1Wednesday.Location = new Point(213, 194); txtWeek1Wednesday.Size = new Size(63, 20); txtWeek1Wednesday.TabIndex = 18; txtWeek1Wednesday.Text = "0.00"; txtWeek1Wednesday.TextAlign = HorizontalAlignment.Right; txtWeek1Thursday.Location = new Point(282, 194); txtWeek1Thursday.Size = new Size(63, 20); txtWeek1Thursday.TabIndex = 19; txtWeek1Thursday.Text = "0.00"; txtWeek1Thursday.TextAlign = HorizontalAlignment.Right; txtWeek1Friday.Location = new Point(351, 194); txtWeek1Friday.Size = new Size(63, 20); txtWeek1Friday.TabIndex = 20; txtWeek1Friday.Text = "0.00"; txtWeek1Friday.TextAlign = HorizontalAlignment.Right; txtWeek1Sa turday.Location = new Point(420, 194); txtWeek1Saturday.Size = new Size(63, 20); txtWeek1Saturday.TabIndex = 21; txtWeek1Saturday.Text = "0.00"; txtWeek1Saturday.TextAlign = HorizontalAlignment.Right; txtWeek1Sunday .Location = new Point(489, 194); txtWeek1Sunday.Size = new Size(63, 20); txtWeek1Sunday.TabIndex = 22; txtWeek1Sunday.Text = "0.00"; txtWeek1Sunday.TextAlign = HorizontalAlignment.Right; txtWeek2Monday.Location = new Point(75, 220); txtWeek2Monday.Size = new Size(63, 20); txtWeek2Monday.TabIndex = 24; txtWeek2Monday.Text = "0.00"; txtWeek2Monday.TextAlign = HorizontalAlignment.Right; txtWeek2Tuesday.Location = new Point(144, 220); txtWeek2Tuesday.Size = new Size(63, 20); txtWeek2Tuesday.TabIndex = 25; txtWeek2Tuesday.Text = "0.00"; txtWeek2Tuesday.TextAlign = HorizontalAlignment.Right; txtWeek2Wednesday.Location = new Point(213, 220); txtWeek2Wednesday.Size = new Size(63, 20); txtWeek2Wednesday.TabIndex = 26; txtWeek2Wednesday.Text = "0.00"; txtWeek2Wednesday.TextAlign = HorizontalAlignment.Right;
txtWeek2Thursday.Location = new Point(282, 220); txtWeek2Thursday.Size = new Size(63, 20); txtWeek2Thursday.TabIndex = 27; txtWeek2Thursday.Text = "0.00"; txtWeek2Thursday.TextAlign = HorizontalAlignment.Right; txtWeek2Friday.Location = new Point(351, 220); txtWeek2Friday.Size = new Size(63, 20); txtWeek2Friday.TabIndex = 28; txtWeek2Friday.Text = "0.00"; txtWeek2Friday.TextAlign = HorizontalAlignment.Right; txtWeek2Saturday.Location = new Point(420, 220); txtWeek2Saturday.Size = new Size(63, 20); txtWeek2Saturday.TabIndex = 29; txtWeek2Saturday.Text = "0.00"; txtWeek2Saturday.TextAlign = HorizontalAlignment.Right; txtWeek2S unday.Location = new Point(489, 220); txtWeek2Sunday.Size = new Size(63, 20); txtWeek2Sunday.TabIndex = 30; txtWeek2Sunday.Text = "0.00"; txtWeek2Sunday.TextAlign = HorizontalAlignment.Right; lblWeek2.AutoSize = true; lblWeek2.Location = new Point(12, 223); lblWeek2.Size = new Size(48, 13); lblWeek2.TabIndex = 23; lblWeek2.Text = "Week 2:"; lblNotes.AutoSize = true; lblNotes.Location = ne w Point(12, 258); lblNotes.Name = "lblNotes"; lblNotes.Size = new Size(35, 13); lblNotes.TabIndex = 31; lblNotes.Text = "Notes"; txtNotes.Location = new Point(75, 255); txtNotes.Multiline = true; txtNotes.ScrollBars = ScrollBars.Vertical; txtNotes.Size = new Size(477, 64); txtNotes.TabIndex = 32; pnlBottomLine.BackColor = Color.FromArgb(64, 64, 64); pnlBottomLine.Location = new Point(16, 326); pnlBottomLine.Size = new Size(552, 2); pnlBottomLine.TabIndex = 33; btnReset.Location = new Point(255, 337); btnReset.Size = new Size(75, 23); btnReset.TabIndex = 36; btnReset.Text = "Reset"; btnReset.UseVisualStyleBackColor = true; btnReset.Click += new System.EventHandler(btnResetClicked); btnSubmit.Location = new Point(338, 337); btnSubmit.Size = new Size(130, 23); btnSubmit.TabIndex = 34; btnSubmit.Text = "Submit Time Sheet"; btnSubmit.UseVisualStyleBackColor = true;
btnSubmit.Click += new System.EventHandler(btnSubmitClicked); btnClose.Location = new Point(476, 337); btnClose.Name = "btnClose"; btnClose.Size = new Size(75, 23); btnClose.TabIndex = 35; btnClose.Text = "Close"; btnClose.UseVisualStyleBackColor = true; btnClose.Click += new System.EventHandler(btnCloseClicked); ClientSize = new Size(580, 368); Controls.Add(txtTimeSheetCode); Controls.Add(btnClose); Controls.Add(btnSubmit); Controls.Add(btnReset); Controls.Add(pnlBottomLine); Controls.Add(txtNotes); Controls.Add(lblNotes); Controls.A dd(txtWeek2Sunday); Controls.Add(txtWeek2Saturday); Controls.Add(txtWeek2Friday); Controls.Add(txtWeek2Thursday); Controls.Add(txtWeek2Wednesday); Controls.Add(txtWeek2Tuesday); Controls.Add(txtWeek2Monday); Controls.Add(lblWeek2); Controls.Add(txtWeek1Sunday); Controls.Add(txtWeek1Saturday); Controls.Add(txtWeek1Friday); Controls.Add(txtWeek1Thursday); Controls.Add(txtWeek1Wednesday); Controls.Add(txtWee k1Tuesday); Controls.Add(txtWeek1Monday); Controls.Add(lblWeek1); Controls.Add(lblSunday); Controls.Add(lblSaturday); Controls.Add(lblFriday); Controls.Add(lblThursday); Controls.Add(lblWednesday); Controls.Add(lblTuesday); Controls.Add(lblMonday); Controls.Add(pnlSecondLine); Controls.Add(lblTimeRecording); Controls.Add(dtpEndDate); Controls.Add(lblEndDate); Controls.Add(dtpStartDate); Controls.Add(lblStartDate); Controls.Add(txtEmployeeNumber); Controls.Add(txtEmployeeName); Controls.Add(lblEmployeeNumber); Controls.Add(pnlTopLine); Controls.Add(lblIdentification); FormBorderStyle = System .Windows.Forms.FormBorderStyle.FixedDialog; MaximizeBox = false; MinimizeBox = false; StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; Text = "Fun Department Store - Employees Time Sheet"; ResumeLayout(false); PerformLayout(); }
private void txtEmployeeNumberLeave(object sender, EventArgs e) { // This variable will be used to look for an employee bool employeeFound = false; // Connect to the database // To connect to the database, after the following Data Source= expression, // type \\, followed by the name of the server (ours is named Expression), // followed by \\, followed by the name of the folder where the database // is installed (ours is named Fun Department Store) (of course, you must // have shared that folder), followed by \\, and followed by the name of // the database, in this case FunDS using (OleDbC onnection conFunDS = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;" + @"Data Source= \\Expression \\Fun Department Store \\FunDS.accdb")) { // Get the records of employees OleDbCommand cmdFunDS = new OleDbCommand("SELECT * FROM Employees;", conFunDS); OleDbDataAdapter odaFunDS = new OleDbDataAdapter(cmdFunDS); DataSet dsEmployees = new DataSet("EmployeeSet"); odaFunDS.Fill(dsE mployees); conFunDS.Open(); // Visit the record of each employee for (int i = 0; i < dsEmployees.Tables[0].Rows.Count; i++) { // Get a reference to the current record DataRow rcdEmployee = dsEmployees.Tables[0].Rows[i];
// If you find a record whose employee number is the same as // the employee number entered in the form, we have found a match if (rcdEmployee["EmployeeNumber"] .ToString().Equals(txtEmployeeNumber.Text)) { // Display that employee's name txtEmployeeName.Text = rcdEmployee["LastName"].ToString() + ", " + dEmployee["FirstName"].ToString(); // Update the flag that we have found a match employeeFound = true; // Look no further break; } } // If there was no match, let the user know if (employeeFound == false) { MessageBox.Show("There is no employee with that employee number", "Fun Department Store", MessageBoxButtons.OK, MessageBoxIcon.Information); btnResetClicked(sender, e); } } } private void btnResetClicked(object sender, EventArgs e) { txtEmployeeNumber.Text = ""; txtEmployeeName.Text = ""; dtpStartDate.Value = DateTime.Today;
dtpEndDate.Value = dtpStartDate.Value; txtWeek1Monday.Text = "0.00"; txtWeek1Tuesday.Text = "0.00"; txtWeek1Wednesday.Text = "0.00"; txtWeek1Thursday.Text = "0.00"; txtWeek1Friday.Text = "0.00"; txtWeek1Saturday.Text = "0.00"; txtWeek1Sunday.Text = "0.00"; txtWeek2Monday.Text = "0.00"; txtWeek2Tuesday.Text = "0.00"; txtWeek2Wednes day.Text = "0.00"; txtWeek2Thursday.Text = "0.00"; txtWeek2Friday.Text = "0.00"; txtWeek2Saturday.Text = "0.00"; txtWeek2Sunday.Text = "0.00"; txtNotes.Text = ""; } /// This function is used to create a numb er we will name TimeSheetCode /// This number is used to uniquely identify each timesheet record /// This number holds the employee number (00 -000 ) /// and the start date (yyyymmdd) of the time sheet /// It is useful as it allows us to fin d out whether the employee /// had previously filled out a time sheet or not private string CreateTimeSheetCode(string emplNbr, DateTime DateStart) { string strMonth, strDay; int iMonth, iDay; iMonth = DateStart.Month; iDay = DateStart.Day; if (iMonth < 10) strMonth = "0" + iMonth.ToString(); else strMonth = iMonth.ToString(); if (iDay < 10) strDay = strMonth + "0" + iDay.ToString() + DateStart.Year; else strDay = strMonth + iDay.ToString() + DateStart.Year; return emplNbr + strDay; } private void dtpStartDateClosedUp(object sender, EventArgs e) { DateTime dtStartDate, dtEndDate; // If the employee name is empty, probably the // employee number is not recognixed if (txtEmployeeName.Text == "") return; dtStartDate = dtpStartDate.Value; TimeSpan tsStart = new TimeSpan(13, 0, 0, 0) ; dtEndDate = dtStartDate + tsStart; dtpEndDate.Value = dtEndDate; txtTimeSheetCode.Text = CreateTimeSheetCode(txtEmployeeNumber.Text, dtpStartDate.Value);
// To connect to the database, after the following Data Source= ex pression, // type \\, followed by the name of the server (ours is named Expression), // followed by \\, followed by the name of the folder where the database // is installed (ours is named Fun Department Store) (of course, you must // have shared that folder), followed by \\, and followed by the name of // the database, in this case FunDS using (OleDbConnection conFunDS = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;" + @"Data Source= \\Expression \\Fun Department Store \\FunDS.accdb")) { OleDbCommand cmdFunDS = new OleDbCommand("SELECT * FROM TimeSheets;", conFunDS); OleDbDataAdapter odaFunDS = new OleDbDataAdapter(cmdFunDS); DataSet dsTimeSheets = new DataSet("TimeSheetSet"); odaFunDS.Fill(dsTimeSheets); conFunDS.Open(); // Visit each record for (int i = 0; i < dsTimeSheets.Tables[0].Rows.Count; i++) { // Get a reference to the current record DataRow rcdTimeSheet = dsTimeSheets.Tables[0].Rows[i];
if (txtTimeSheetCode.Text == rcdTimeSheet["TimeSheetCode"].ToString()) { // ... it means the employee had previously created this time sheet. // Get the values and display them in the text boxes on the form txtWeek1Monday.Text = double.Parse(rcdTimeSheet["Week1Monday"].ToString()).ToString("F"); txtWeek1Tuesday.Text = double.Parse(rcdTimeSheet["Week1Tuesday"].ToString()).ToString("F"); txtWeek1Wednesday.Text = double. Parse(rcdTimeSheet["Week1Wednesday"].ToString()).ToString(" txtWeek1Thursday.Text = double.Parse(rcdTimeSheet["Week1Thursday"].ToString()).ToString("F") txtWeek1Friday.Text = double.Parse(rcdTimeSheet["Week1Frid ay"].ToString()).ToString("F"); txtWeek1Saturday.Text = double.Parse(rcdTimeSheet["Week1Saturday"].ToString()).ToString("F") txtWeek1Sunday.Text = double.Parse(rcdTimeSheet["Week1Sunday"].ToString()).ToString("F");
txtWeek2Monday.Text = double.Parse(rcdTimeSheet["Week2Monday"].ToString()).ToString("F"); txtWeek2Tuesday.Text = double.Parse(rcdTimeSheet["Week2Tuesday"].ToString()).ToString("F"); txtWeek2Wedne sday.Text = double.Parse(rcdTimeSheet["Week2Wednesday"].ToString()).ToString("F txtWeek2Thursday.Text = double.Parse(rcdTimeSheet["Week2Thursday"].ToString()).ToString("F") txtWeek2Friday.Text = double.Parse(rcdT imeSheet["Week2Friday"].ToString()).ToString("F"); txtWeek2Saturday.Text = double.Parse(rcdTimeSheet["Week2Saturday"].ToString()).ToString("F") txtWeek2Sunday.Text = double.Parse(rcdTimeSheet["Week2Sunday"].ToString ()).ToString("F"); // Since the record was found, look no further break; } else { // If no such record was found, reset the days text boxes txtWeek1Monday.Text = "0.00"; txtWeek1Tuesday.Text = "0.00"; txtWeek1Wednesday.Text = "0.00"; txtWeek1Thursday.Text = "0.00"; txtWeek1Friday.Text = "0.00"; txtWeek1Saturday.Text = "0.00"; txtWeek1Sunday.Text = "0.00"; txtWeek2Monday.Text = "0.00"; txtWeek2Tuesday.Text = "0.00";
txtWeek2Wednesday.Text = "0.00"; txtWeek2Thursday.Text = "0.00"; txtWeek2Friday.Text = "0.00"; txtWeek2Saturday.Text = "0.00"; txtWeek2Sunday.Text = "0.00"; txtNotes.Text = ""; } } } } private void btnSubmitClicked(object sender, EventArgs e) { bool timeSheetExistsAlready = false; // If the employee name is empty, probably the // employee number is not reco gnixed if (txtEmployeeName.Text == "") return; // To connect to the database, after the following Data Source= expression, // type \\, followed by the name of the server (ours is named Expression), // followed by \\, followed by the name of the folder where the database // is installed (ours is named Fun Department Store) (of course, you must // have shared that folder), followed by \\, and followed by the name of // the database, in this case FunDS using (OleDbConnection conFunDS = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;" + @"Data Source= \\Expression \\Fun Department Store \\FunDS.accdb")) { OleDbCommand cmdFunDS = new OleDbCommand("SELECT * FROM TimeSheets;", conFunDS); OleDbDataAdapter odaFunDS = new OleDbDataAdapter(cmdFunDS); DataSet dsTimeSheets = new DataSet("TimeSheetSet"); odaFunDS.Fill( dsTimeSheets); conFunDS.Open(); // Visit each record (time sheet) for (int i = 0; i < dsTimeSheets.Tables[0].Rows.Count; i++) { // Get a reference to the current record DataRow rcdTimeSheet = dsTimeSheets.Tables[0].Rows[i];
// If an employee number in the time sheet is the same as the the employee number on the form, // and if the corresponding start date in the time sheet is the same as the start date on the fo if ((rcdTimeSheet["EmployeeNumber"].ToString().Equals(txtEmployeeNumber.Text)) &&
ateTime.Parse(rcdT imeSheet["StartDate"].ToString()).ToShortDateString().Equals(dtpStartDate.Value.ToShortDateStr ) { // that means the record exists already. Get ready to update it timeSheetExistsAlready = true; break; } else timeSheetExistsAlready = false; } } if (timeSheetExistsAlready == true)
{ using (OleDbConnection conFunDS = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;" + @"Data Source= \\Expression \\Fun Department Store \\FunDS.accdb")) { string strSQLUpdate = "UPDATE TimeSheets " + "SET Week1Monday = " + txtWeek1Monday.Text + ", Week1Tuesday = " + txtWeek1Tuesday.Text + ", Week1Wednesday = " + txtWeek1Wednesday.Text + ", Week1Thursday = " + txtWeek1Thursd ay.Text + ", Week1Friday = " + txtWeek1Friday.Text + ", Week1Saturday = " + txtWeek1Saturday.Text + ", Week1Sunday = " + txtWeek1Sunday.Text + ", Week2Monday = " + txtWeek2Mond ay.Text + ", Week2Tuesday = " + txtWeek2Tuesday.Text + ", Week2Wednesday = " + txtWeek2Wednesday.Text + ", Week2Thursday = " + txtWeek2Thursday.Text + ", Week2Friday = " + txtW eek2Friday.Text + ", Week2Saturday = " + txtWeek2Saturday.Text + ", Week2Sunday = " + txtWeek2Sunday.Text + ", Notes = '" + txtNotes.Text + "' " + "WHERE TimeSheetCode = '" + t xtTimeSheetCode.Text + "';"; OleDbCommand cmdTimeSheet = new OleDbCommand(strSQLUpdate, conFunDS); conFunDS.Open(); cmdTimeSheet.ExecuteNonQuery(); MessageBox.Show("The time sheet has been up dated.", "Fun Department Store", MessageBoxButtons.OK, MessageBoxIcon.Information); } } else {
using (OleDbConnection conFunDS = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;" + @"Data Source= \\Expression \\Fun Department Store \\FunDS.accdb")) { string strSQLInsert = "INSERT INTO TimeSheets(EmployeeN umber, StartDate, TimeSheetCode, Week1Mo
"Week1Tuesday, Week1Wednesday, Week1Thursday, Week1Friday, " + "Week1Saturday, Week1Sunday, Week2Monday, Week2Tuesday, " + "Week2Wednesday, Week2Thursday, Week2Friday, Week2Saturday, " + "Week2Sunday, Notes) VALUES('" + txtEmployeeNumber.Text + "', '" + dtpStartDate.Valu e.ToShortDateString() + txtTimeSheetCode.Text + "', " + double.Parse(txtWeek1Monday.Text) + ", " + double.Parse(txtWeek1Tuesday.Te xt) + ", " + double.Parse(txtWeek1Wednesday.Text) + ", " + double.Parse(txtWeek1Thursday.Text) + ", " + double.Parse(txtWeek1Friday.Text) + ", " + double.Parse(txtWeek1Saturday.Text) + ", " + double.Parse(txtWeek1Sunday.Text) + ", " + double.Parse(txtWeek2Monday.Text) + ", " + double.Parse(txtWeek2Tuesday.Text) + ", " + double.Parse(txtWeek2Wednesday.Text) + ", " + double.Parse(txtWeek2Thursday.Text) + ", " + double.Parse(txtWeek2Friday.Text) + ", " + double.Parse(txtWeek2Saturday.Text) + ", " + double.Parse(txtWeek2Sunday.Text) + ", '" + txtNotes.Text + "');";
// Generate a command to create a record OleDbCommand cmdEmployees = new OleDbCommand(strSQLInsert, conFunDS); conFunDS.Open(); cmdEmployee s.ExecuteNonQuery(); MessageBox.Show("The time sheet has been created.", "Fun Department Store", MessageBoxButtons.OK, MessageBoxIcon.Information); btnResetCl icked(sender, e); } } } private void btnCloseClicked(object sender, EventArgs e) { Close(); }
ublic class Exercise public static int Main() { Application.Run(new TimeSheet()); return 0; }
1. To execute the application, press F5 2. Enter the values as follows: Employee # Week 1 Week 2 3.
Start Date January 2, 2011 Web 8.00 6.50 Thu 9.50 6.00 Fri 8.50 6.00 Sat 0 0 Sun 0 0
4. Click Submit Time Sheet 5. Create other time sheets as follows and click Submit Time Sheet after each: Employee # Week 1 Week 2 6. Employee # Week 1
Start Date January 2, 2011 Web 7 6 Thu 7.5 7.5 Fri 6 6 Sat 0 0 Sun 0 0
Start Date January 2, 2011 Web 6 8.5 Thu 8 7 Fri 8 8.5 Sat 0 0 Sun 0 0
Start Date January 2, 2011 Web 8.5 8.5 Thu 9.5 7.5 Fri 8 8 Sat 0 0 Sun 0 0
9. 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 # Week 1 Week 2 19. Employee # Week 1 Week 2 20. Employee 75-937 Start Date January 16, 2011
Start Date January 16, 2011 Web 8 6 Thu 8.5 7.5 Fri 8.5 0 Sat 0 0 Sun 0 0
Start Date January 16, 2011 Web 6.5 6 Thu 9.5 6.5 Fri 8 8.5 Sat Sun 0 0 0 0
# Mon Week 1 Week 2 21. Employee # Week 1 Week 2 22. Employee # Week 1 Week 2 23. Employee # Week 1 Week 2 24. Employee # Week 1 Week 2 25. Employee # Week 1 Week 2 26. Employee 75-937 Start Date January 30, 2011 Start Date Tue 8.0 8.5 Web 8.5 9.5 44-666 Mon 8.5 9.5 Tue 7.5 6.5 Start Date January 16, 2011 Web 6.5 7.5 Thu 10.5 8.5 Fri 8 8.5 Sat Sun 0 0 0 0 84-715 Mon 0 0 Tue 0 0 Start Date January 16, 2011 Web 0 0 Thu 8 7.50 Fri 8 8.5 Sat 8 8 Sun 0 0 0 0 Tue 0 0 Web 0 0 Thu 0 0 Fri 8.5 9.5 Sat 6 8 Sun 0 0
Start Date January 16, 2011 Web 0 0 Thu 0 0 Fri 9.5 10.5 Sat Sun 10 8 0 0
Start Date January 30, 2011 Web 8 8 Thu 8 8.5 Fri Sat 8 8 0 0 Sun 0 0
# Mon Week 1 Week 2 8.5 8 Tue 9.5 9 Web 8.5 9 Thu 9 10 Fri 8 Sat 0 Sun 0 0
8.5 0
27. Close the form 28. Press F5 to execute again 29. Press F5 to execute again 30. In the employee number, type 40-715 31. Set the Start Date to January 16, 2011 32. In the Week 1 row, change the Thursday value to 10.5 33. In the Week 2 row, change the Thursday value to 8.00 34. Click Submit Time Sheet 35. Close the application