0% found this document useful (0 votes)
461 views37 pages

Projects PDF

This document provides details for projects to accompany the textbook Murach's C# 2015. It includes over 15 projects of varying difficulty that require students to apply the programming skills learned in the book. The projects are divided into sections corresponding to parts of the book. The first project summarized translates English text to Pig Latin, requiring students to use string handling to parse words and identify consonants and vowels to determine how to transform each word based on specified rules. Subsequent projects involve tasks like maintaining student scores, building basic calculators, and interacting with a SQL database to manage an incident tracking system. Instructions are provided for each project along with optional hints and notes about modifying difficulty levels.

Uploaded by

Bipal Goyal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
461 views37 pages

Projects PDF

This document provides details for projects to accompany the textbook Murach's C# 2015. It includes over 15 projects of varying difficulty that require students to apply the programming skills learned in the book. The projects are divided into sections corresponding to parts of the book. The first project summarized translates English text to Pig Latin, requiring students to use string handling to parse words and identify consonants and vowels to determine how to transform each word based on specified rules. Subsequent projects involve tasks like maintaining student scores, building basic calculators, and interacting with a SQL database to manage an incident tracking system. Instructions are provided for each project along with optional hints and notes about modifying difficulty levels.

Uploaded by

Bipal Goyal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 37

1 Projects for Murach’s C# 2015

Projects for
Murach’s C# 2015
The projects in this document let your students apply the programming skills that they
learn as they progress through Murach’s C# 2015. Unlike the exercises in the book and
the extra exercises in the instructor’s materials, which lead your students step by step, the
projects describe the operation of an application and present the specifications for the
application. Then, your students must decide how to approach the development of the
application.
If you review these projects, you’ll see that they represent different degrees of
difficulty, but you can easily modify them to make them easier or more challenging.
Since most of these projects can be done from scratch in an hour or two, you can also use
these projects as tests.
An introduction to the projects.................................................2
When to assign the projects.............................................................................................2
Which projects to assign...................................................................................................2
About the instructor notes.................................................................................................2
Labels vs. read-only text boxes........................................................................................2
About the TechSupport database.....................................................................................2
Section 2 projects.....................................................................3
Project 2-1 Translate English to Pig Latin.....................................................................3
Project 2-2 Maintain student scores..............................................................................5
Section 3 projects.....................................................................8
Project 3-1 Create a basic calculator............................................................................8
Project 3-2 Assign tickets with time slots....................................................................11
Project 3-3 Direct a simple robot.................................................................................14
Project 3-4 Create a memory calculator......................................................................16
Project 3-5 Maintain student scores (Student class)..................................................17
Project 3-6 Translate English to Pig Latin or Pig Greek..............................................18
How to use the TechSupport database...................................20
The design of the TechSupport database......................................................................20
How to prepare for using the TechSupport database.....................................................21
Section 4 projects...................................................................22
Project 4-1 Maintain products......................................................................................22
Project 4-2 Maintain technicians.................................................................................23
Project 4-3 Display customer incidents.......................................................................24
Project 4-4 Add customer incidents.............................................................................26
Project 4-5 Register products......................................................................................28
Section 5 projects...................................................................30
Project 5-1 Maintain student scores (text file).............................................................30
Project 5-2 Display incidents by technician.................................................................31
Project 5-3 Maintain incidents.....................................................................................33
Section 6 project.....................................................................35
Project 6-1 Calculate conversions...............................................................................35
2 Projects for Murach’s C# 2015

An introduction to the projects


The following topics give you some ideas about how you can use the projects
presented in this document.
When to assign the projects
To give you an idea of when each project can be assigned, the projects are numbered
by section. In addition, the description for each project indicates what chapters your
students must complete before they can do that project. For example, your students will
have the skills they need to complete project 2-1 after they’ve read chapters 1 through 9.
Keep in mind, however, that not all of the chapters have to be read in sequence. After
reading chapters 1 through 12, for example, you may choose to go on to the chapters in
section 4, 5, or 6. Because of that, the projects for sections 4, 5, and 6 require only the
skills presented in chapters 1 through 12.
Which projects to assign
This document includes one or more projects for each of sections 2 through 6 of the
book. Because we feel that doing the exercises is the best way for your students to learn
the skills in each chapter, you’ll probably want to assign only one or two projects for
each section. Then, if your students can do these projects successfully, you can be sure
that they have mastered the skills they need to develop C# applications.
About the instructor notes
After the specifications for most of the projects, you’ll find one or more instructor
notes. Some of these notes describe the skills that are needed for the projects. Others give
you ideas of how you might modify the projects to make them easier or more difficult.
And still others indicate how you might have your students modify a project after reading
a later chapter. Before you distribute the project descriptions to your students, you will
probably want to delete or modify these notes.
Labels vs. read-only text boxes
Unlike the applications presented in the book, which use read-only text boxes to
display the results of calculations, most of the projects use labels. If you want the projects
to adhere more closely to the applications in the book, however, you can instruct your
students to use read-only text boxes instead of labels. Otherwise, information about how
to get the labels to look and work like the ones in the projects is given in project 2-2.
About the TechSupport database
The projects for section 4 require the use of a SQL Server database named
TechSupport. If you will be installing this database on your lab system, you just need to
give your students the information they need for connecting to the database. However, if
your students are going to use SQL Server Express LocalDB on their own systems, you
need to distribute the TechSupport.mdf and TechSupport_log.ldf files that are on the
Instructor’s CD to your students.
3 Projects for Murach’s C# 2015

Section 2 projects
Project 2-1 Translate English to Pig Latin
For this project, you’ll create a form that accepts a text entry from the user and converts
the text to Pig Latin. Prerequisites: chapters 1-9.
The design of the Pig Latin Translator form

Operation
 The user enters text in the first multi-line text box and clicks the Translate button or
presses the Enter key.
 The application translates the text to Pig Latin and displays it in the second multi-line
text box.
 To clear both text boxes, the user clicks the Clear button.
Specifications
 If a word starts with a vowel, just add way to the end of the word.
 If a word starts with a consonant, move the consonants before the first vowel to the end
of the word and add ay.
 If a word starts with the letter Y, the Y should be treated as a consonant. If the Y
appears anywhere else in the word, it should be treated as a vowel.
 Keep the case of the original word whether it’s uppercase (TEST), title case (Test), or
lowercase (test).
 Keep all punctuation at the end of the translated word.
 Translate words with contractions. For example, can’t should be an’tcay.
 Don’t translate words that contain numbers or symbols. For example, 123 should be
left as 123, and [email protected] should be left as [email protected].
 Check that the user has entered text before performing the translation.
4 Projects for Murach’s C# 2015

Hints
 To create a multi-line text box, just set the Multiline property of the text box to True
and size the text box accordingly.
 To add vertical scroll bars to the text box, set the ScrollBars property to Vertical.
 The integer values for all uppercase letters are 65 to 90, and the integer values for all
lowercase letters are 97 to 122.
Instructor notes
 This is not a trivial assignment. Students will have to use string handling to parse the
input string into separate words. Then, string handling will have to be used again to
analyze letters at the beginning of each word, to identify consonants, vowels, numerals,
and punctuation marks, and to add Pig Latin word endings.
 There are no official rules for Pig Latin. Most people agree on how words that begin
with consonants are translated, but there are many different ways to handle words that
begin with vowels. To enhance this application, you can have your students add radio
buttons that provide for selecting one of several translations. To find out more about
different Pig Latin translations, you can use an Internet search service such as Google.
 Project 3-6 builds on this project by adding the ability to translate to another dialect
that’s similar to Pig Latin. This project uses classes and an interface.
5 Projects for Murach’s C# 2015

Project 2-2 Maintain student scores


For this project, you’ll develop an application that lets the user add students to a list,
change the scores for a student in the list, and delete a student from the list. Prerequisites:
chapters 1-10.
The design of the Student Scores form

Operation
 To display the total, count, and average for a student, the user selects the student from
the list box. If the list box is empty, the total, count, and average labels should be
cleared.
 To add a new student, the user clicks the Add New button to display the Add New
Student dialog box.
 To update an existing student’s scores, the user selects the student in the list box and
clicks the Update button to display the Update Student Scores dialog box.
 To delete a student, the user selects the student in the list box and clicks the Delete
button.
The design of the Add New Student form

Operation
 To add a new student, the user enters a student name and, optionally, one or more
scores and clicks the OK button.
6 Projects for Murach’s C# 2015

 To add a score, the user enters a score and clicks the Add Score button. The score is
added to the list of scores in the Scores label.
 To remove all scores from the Scores label, the user clicks the Clear Scores button.
 To cancel the add operation, the user clicks the Cancel button.
The design of the Update Student Scores
and Add/Update Score forms

Operation
 To add a score, the user clicks the Add button and enters the score in the Add Score
dialog box that’s displayed.
 To update a score, the user selects the score, clicks the Update button, and changes the
score in the Update Score dialog box that’s displayed.
 To remove a score from the Scores list box, the user selects the score and clicks the
Remove button.
 To remove all scores from the Scores list box, the user clicks the Clear Scores button.
 To accept all changes, the user clicks the OK button.
 To cancel the update operation, the user clicks the Cancel button.
Specifications
 This application should make sure that the user enters a name for a new student.
However, a new student can be added without any scores.
 This application should check all scores entered by the user to make sure that each
score is a valid integer from 0 to 100.
 When the application starts, it should load the list box with three sample students.
Hint
 To get the labels that display the score total, score count, and average on the Student
Scores form, the scores on the Add New Student form, and the name on the Update
Student Scores form to look like the ones shown above, you’ll need to set the AutoSize
property of the labels to False and the BorderStyle property to Fixed3D.
Instructor notes
 This project requires the use of lists, list boxes, and some string handling. Although it
uses four forms, it is still a manageable project.
7 Projects for Murach’s C# 2015

 After your students complete chapter 15, you can have them enhance this application
by adding a Student class. See the description for project 3-5 for details.
 After your students complete chapter 21, you can have them enhance this application
by maintaining the student data in a text file. See the description for project 5-1 for
details.
8 Projects for Murach’s C# 2015

Section 3 projects
Project 3-1 Create a basic calculator
For this project, you’ll create a form that lets the user perform the operations provided by
a basic calculator. You’ll also create a class that performs the required operations.
Prerequisites: chapters 1-12.
The design of the Calculator form

Operation
 To perform an addition, subtraction, multiplication, or division operation, the user
clicks the first number, followed by the appropriate operator key (+, -, *, /), followed
by the second number and the equals key (=).
 To perform an addition, subtraction, multiplication, or division operation on the result
of a previous operation, the user clicks another operator key, followed by another
number and the equals key. The user can also repeat the previous operation on the
result by clicking the equals keys without first clicking another operator and number.
 To calculate the square root or the reciprocal of a number or to change the sign of a
number, the user clicks the number followed by the appropriate operator key (sqrt, 1/X,
+/-).
 To calculate the square root or the reciprocal of the result of a previous operation, the
user clicks the appropriate operator key.
 Each time the user clicks a number key, the number is displayed in the text box at the
top of the form. This text box also displays the result of an operation when the user
clicks the sqrt, 1/X, +/-, or = key.
 To erase the last digit entered, the user clicks the Back key.
 To clear all the values entered, the user clicks the Clear key.
Specifications
 Create a class named Calculator that implements the functions of the calculator. Design
whatever methods and properties you need for this class.
9 Projects for Murach’s C# 2015

 The Calculator class should accept decimal parameters and provide a decimal result for
its calculated values.
 If the user tries to divide a number by zero, the calculator should display an error
message in the text box. The form class should use a try-catch statement to catch a
divide-by-zero exception.
Instructor notes
 The calculator that’s created in this project is similar to the calculator that comes with
Windows. If you want to, you can have your students study the behavior of the
Windows calculator so they have a better idea of how it works.
 One of the differences between the calculator created in this project and the Windows
calculator is that you can perform a calculation by clicking an operator key other than
the = key with the Windows calculator. In other words, you can add a list of numbers
like this using the Windows calculator: 3 + 12 + 14 + 8 =. With the calculator for this
project, you have to perform each calculation separately by clicking the = key like this:
3 + 12 = + 14 = + 8 =. If you want to, you can have your students enhance this
calculator so it works like the Windows calculator. Because it is difficult to maintain
the state of the calculator, however, this will be a complicated task.
 You can also have your students enhance this project by adding a button that clears the
last entry, but not the previously calculated value. Again, because of the difficulty
maintaining the state of the calculator, this will be complicated.
 Another enhancement would be for the application to provide for entries from the
keyboard. For example, if the user presses the 1 key, the number 1 should be displayed
in the calculator. Similarly, if the user presses the = key, the current calculation should
be performed. Note, however, that not all of the calculator buttons map to keyboard
keys.
 To simplify this project, you can eliminate the square root and reciprocal functions.
 If you want to be more specific about the Calculator class, you can provide this class
design:
Private field Description
currentValue A decimal that stores the result currently displayed by the
calculator.
operand1 A decimal that stores the value of the first operand.
operand2 A decimal that stores the value of the second operand.
op An Operator type that stores a member of the Operator
enumeration.
Operator An enumeration with these constants: Add, Subtract,
Multiply, Divide, and None.
Constructor Description
() Creates a Calculator object with default values. The default
value for the op field is Operator.None.
Property Description
CurrentValue Gets the value of the currentValue field.
Method Description
Add(displayValue) Sets the operand1 and currentValue fields to the value that’s
passed to it, and sets the op field to Operation.Add.

10 Projects for Murach’s C# 2015

Method Description
Subtract(displayValue) Sets the operand1 and currentValue fields to the value that’s
passed to it, and sets the op field to Operation.Subtract.
Multiply(displayValue) Sets the operand1 and currentValue fields to the value that’s
passed to it, and sets the op field to Operation.Multiply.
Divide(displayValue) Sets the operand1 and currentValue fields to the value that’s
passed to it, and sets the op field to Operation.Divide.
Equals() Performs the operation specified by the op field on the
operand1 and operand2 fields, and stores the result in the
operand1 field.
Equals(displayValue) Sets the operand2 field to the value that’s passed to it. Then,
performs the operation specified by the op field on the
operand1 and operand2 fields, and stores the result in the
operand1 field.
Clear() Sets the private fields to their default values.

 After your students complete chapter 14, you can have them enhance this project by
adding a memory function. To implement this function, your students can create a new
class named MemoryCalculator that inherits the Calculator class. See project 3-4 for
details.
11 Projects for Murach’s C# 2015

Project 3-2 Assign tickets with time slots


For this project, you’ll develop an application that assigns tickets that include a time slot
when a guest can return to visit an attraction without waiting in line, similar to the way
the Fast Pass system works at Disneyland. Prerequisites: chapters 1-12.
The design of the Tickets form

Operation
 To issue a ticket, the user clicks the Issue Ticket button. A ticket with the next ticket
number in the next available time slot is issued.
 Each time a ticket is issued, it is added to the list box.
 The title bar for this form displays the current time and an indication of whether the
current time slot is open or closed. This information is updated once per second.
 The labels in the Ticket Availability section of the form indicate how many tickets are
outstanding and the time slot that will be assigned to the next ticket that’s issued. These
labels are updated as tickets are issued and the time changes.
 When a time slot begins, any outstanding tickets for that time slot are removed from
the list box and the beginning and ending ticket numbers assigned to that slot are
displayed in the label inside the group box at the top of the form.
 To change the options for issuing tickets, the user clicks the Options button. Before the
Options dialog box is displayed, a dialog box is displayed that warns the user that all
outstanding tickets will be deleted and confirms that the user wants to continue.
12 Projects for Murach’s C# 2015

The design of the Options form

Operation
 The user can enter values into the Options dialog box to specify the number of minutes
for each time slot, the number of guests allowed into the attraction during each time
slot, the time the attraction opens, the time the attraction closes, and the number for the
first ticket. The defaults are five minutes per time slot, five guests per time slot, a start
time of the current time, an end time of four hours after the current time, and an initial
ticket number of 1.
 When the user clicks the OK button, the Tickets form is displayed.
Specifications
 Use a Timer control to display the current time in the title bar of the main form and to
determine the current time slot.
 When the application starts, it should display the Options dialog box from the Load
event handler for the Tickets form. For this to work without an exception being thrown,
you’ll need to disable the Timer control until the Options dialog box is completed.
 The data the user enters in the Options dialog box should be validated to be sure that
the minutes per time slot, guests per time slot, and first ticket number are integers; that
the start and end times are DateTime values; and that the difference between the start
time and the end time provides for at least two time slots.
 Create a class that represents a time slot for assigning tickets. This class should have
public fields that indicate the time the time slot begins, the length of the time slot, and
the number of tickets that have been issued for the time slot. This class should also
have a property that gets the time the time slot ends. Use this class to create a time slot
object for each time slot between the start and end times entered on the Options dialog
box, and store these objects in a collection.
 Create a class that represents a ticket. This class should have public fields that store the
ticket number and the time slot that’s assigned to the ticket and a method that sets the
next ticket number. As each ticket is issued, the application should create a ticket object
with the next ticket number and add it to a queue. Then, when the time slot for the
ticket begins, the ticket should be removed from the queue.
 Once a time slot begins and the tickets in that time slot are removed from the
outstanding list of tickets, the user should not be able to issue any more tickets in that
time slot even if the maximum number of tickets for that time slot haven’t been issued.
13 Projects for Murach’s C# 2015

Instructor notes
This project requires only minimal object-oriented programming skills but has extensive
collection and date/time requirements. It also requires that the student research and use
the Timer control, which isn’t presented in the book.
The complexity of the project can be varied as follows:
 Implement just the ticket assignment portion of the application, with no real-time
monitoring of the time.
 Issue a ticket for the current time slot if tickets are still available.
 Instead of issuing a ticket for the next available time slot, let the user choose the time
slot for the ticket. Then, the tickets in the current time slot will have to be listed
individually at the top of the form. Depending on how the student designs the data
store, this may result in a major redesign of the application.
 Use NumericUpDown controls to select the minutes per window and guests per
window from the Options dialog box, and use the DateTimePicker control to select the
start and end times. This will require some additional research by the student.
14 Projects for Murach’s C# 2015

Project 3-3 Direct a simple robot


For this project, you’ll create a form that lets the user move a simple robot a given
direction and distance. You’ll also create a class that performs the robot movements.
Prerequisites: chapters 1-13.
The design of the Robot form

Operation
 To determine the direction the robot will move, the user clicks the N (North), S
(South), E (East), or W (West) button.
 The robot is displayed as an arrow that points in the currently selected direction.
 The user can move the robot 1 or 10 units in the selected direction by clicking the Go 1
or Go 10 button.
 The robot’s current X, Y position is displayed in a label at the top of the form.
Specifications
 Create a class named Robot that has a method that causes the robot to move, a public
field that contains the current direction, and a property that returns the robot’s current
position as a Point structure. When the robot is instantiated, the position should be set
to 0, 0 (the center) and the direction should be set to North.
 Limit the range of the robot to 100 units in any direction. If the user attempts to move
the robot beyond this range, the Robot class should raise an event. The application
should respond to this event by displaying an appropriate message.
Hints
 The easiest way to create the moving arrow is to use a label control. Then, the program
can adjust the control’s Position property to move the arrow within a panel control. If
you need to, you can use online help to research this control.
15 Projects for Murach’s C# 2015

 To create the arrow, set the label’s Font property to the Wingdings font. Then, you can
use the integer values 231 through 234 to set the label to the appropriate arrow.
Instructor notes
 This project requires a class that performs linear robot movements. The class includes
an event that is fired when the robot reaches a boundary. It also uses an enumeration
and the Point structure.
 To simplify this project, you can eliminate the graphic display of the robot’s position
and just display the robot’s X, Y coordinates in a label.
 If your students have a math background, you can enhance this project so it provides
for nonlinear directions of travel. To do that, your students will need to use trig
functions to calculate the robot’s position.
 You might also enhance this project to use inheritance. For example, a subclass could
inherit the basic Robot class and add some functionality, such as recording the
movement of the robot and calculating the distance traveled.
16 Projects for Murach’s C# 2015

Project 3-4 Create a memory calculator


For this project, you’ll create a form that lets the user perform the functions provided by a
memory calculator. This project builds on the calculator described in project 3-1. If you
have already done project 3-1, you can modify it so it works as described here.
Prerequisites: chapters 1-12, 14.
The design of the Calculator form

Operation
 To clear the contents of memory, the user clicks the MC button. To save the value
that’s currently displayed in memory, the user clicks the MS button. To recall the value
that’s currently in memory and display it in the calculator, the user clicks the MR
button. And to add the value that’s currently displayed to the value in memory, the user
clicks the M+ button.
 An M is displayed in the box above the MC button whenever the memory contains a
value.
 See project 3-1 for additional details.
Specifications
 Create a class named MemoryCalculator that inherits the Calculator class described in
project 3-1. The MemoryCalculator class should add properties and methods as needed
to implement the memory function.
Instructor note
 If you want to be more specific about the MemoryCalculator class, you can provide this
class design:
Private field Description
memoryValue A decimal that stores the current memory value.
Method Description
MemoryStore(displayValue) Stores the calculator’s current value in memory.
MemoryRecall() Sets the calculator’s current value to the value stored in
memory.
MemoryAdd(displayValue) Adds the calculator’s current value to the value currently
stored in memory.
MemoryClear() Clears the current memory value.
17 Projects for Murach’s C# 2015

Project 3-5 Maintain student scores


(Student class)
For this project, you’ll develop an application like the one described in project 2-2 that
maintains a list of student scores, but that uses a Student class. If you have already done
project 2-2, you can use it as a starting point for this project. Prerequisites: chapters 1-12,
15.
The design of the Student Scores form

Operation
 See project 2-2.
Specifications
 This application should use a class named Student to store information about each
student.
 The Student class should override the ToString method of the Object class to provide a
string representation of each Student object that includes the student name and scores
as shown above.
 The Update Student Scores form should create a clone of the current student object and
then apply changes to the clone. That way, the changes will be saved to the current
student only if the user clicks the OK button. To create a clone, the Student class will
need to implement the ICloneable interface, and the Clone method will need to
implement a deep copy.
18 Projects for Murach’s C# 2015

Project 3-6 Translate English to Pig Latin


or Pig Greek
For this project, you’ll create a form that accepts a text entry from the user and converts it
to either Pig Latin or Pig Greek. This project builds on the Pig Latin translator described
in project 2-1. If you have already done project 2-1, you can use it as a starting point for
this project. Prerequisites: chapters 1-12, 15.
The design of the Pig Latin & Greek Translator form

Operation
 The user enters text in the first multi-line text box, selects whether to translate the text
into Pig Latin or Pig Greek, and clicks the Translate button or presses the Enter key.
 The application translates the text to Pig Latin or Pig Greek and displays it in the
second multi-line text box.
 When the user selects the Pig Latin or Pig Greek option, the label above the second text
box changes accordingly, and the text box is cleared.
Specifications
 Create an interface named ITranslator that defines a method named Translate. This
method should accept a string parameter and return a string result.
 Create two classes named PigLatinTranslator and PigGreekTranslator that provide the
appropriate translation by implementing the ITranslator interface.
 Translate the text to Pig Greek using the specifications given in project 2-1 for
translating text to Pig Latin except:
If a word starts with a vowel, just add oi to the end of the word.
If a word starts with a consonant, move the consonants before the first vowel to the
end of the word and add omatos.
19 Projects for Murach’s C# 2015

Instructor note
 As an alternative to using an interface to implement this application, you may want to
have your students use inheritance. Then, they can design the PigLatinTranslator and
PigGreekTranslator classes so that those parts of the translation task that are common
to both dialects, such as parsing the string into separate words, are handled by methods
of a base class.
20 Projects for Murach’s C# 2015

How to use the TechSupport database


The projects for section 4 as well as project 5-3 have you develop applications that
work with a database named TechSupport. These applications are used by a hypothetical
software company that develops software for sports leagues. The main purpose of the
database is to track technical support service calls, referred to as incidents. Before you
use this database, you need to be familiar with its design and prepare it for use.
The design of the TechSupport database
The TechSupport database consists of the six tables shown below. The main table is
the Incidents table, which contains one row for each technical support incident. Each row
in the Incidents table is related to one row in the Customers table, which contains
information about the company’s customers; one row in the Products table, which
contains information about the company’s products; and one row in the Technicians
table, which contains information about the company’s technical support staff members.
In addition, a table called Registrations keeps track of the products that are registered to
each customer, and the States table contains state and zip code information.

In addition to the column properties shown above, you should know that the
CustomerID, IncidentID, and TechID columns in the Customers, Incidents, and
Technicians tables are identity columns. So the values of these columns are set
automatically when new rows are added to these tables.
21 Projects for Murach’s C# 2015

How to prepare for using the TechSupport database


Unless your instructor tells you otherwise, you should use SQL Server 2014 Express
LocalDB to work with the TechSupport database. In that case, you can just copy the
TechSupport.mdf and TechSupport_log.ldf files your instructor gives you to your system
Then, you can add the mdf file to each project, and the ldf file will be added
automatically. In contrast, if you’re doing the projects in a computer lab and the database
is installed on the local computer or on a server, you will need to get the information for
establishing a connection to that database before you do the projects.
22 Projects for Murach’s C# 2015

Section 4 projects
Project 4-1 Maintain products
For this project, you’ll create a form that lets the user maintain products using a
DataGridView control. Prerequisites: chapters 1-11, 17, 18.
The design of the Product Maintenance form

Operation
 When this application starts, all the rows in the Products table of the TechSupport
database are displayed in the DataGridView control.
 The user can use the toolbar and the DataGridView control to add new rows, delete
rows, modify the data in existing rows, and save changes to the database.
Specifications
 This application should handle SQL Server exceptions, ADO.NET exceptions, and data
errors that occur when working with the DataGridView control.
Instructor notes
 This project requires the use of a data source with a single table, a data-bound
DataGridView control, and error handling.
 If you assign this project after chapter 19, you can have your students edit the columns
of the DataGridView control to improve their appearance.
23 Projects for Murach’s C# 2015

Project 4-2 Maintain technicians


For this project, you’ll create a form that lets the user maintain technicians. Prerequisites:
chapters 1-11, 17, 18.
The design of the Technician Maintenance form

Operation
 When this application first starts, the data in the first row of the Technicians table is
displayed. Then, the user can display the data for other rows using the navigation
buttons in the toolbar.
 To modify an existing row, the user enters the modifications and then clicks the Save
Data button in the toolbar.
 To delete an existing row, the user clicks the Delete button in the toolbar, followed by
the Save Data button.
 To add a new row, the user clicks the Add New button in the toolbar, enters the data for
the new row, and then clicks the Save Data button.
Specifications
 This application should handle SQL Server and ADO.NET exceptions.
 Because the TechID column is an identity column, don’t allow the user to change the
value in this column.
 Limit the number of characters that can be entered into the Name, Email, and Phone
text boxes so the entries don’t exceed the sizes allowed by the Name, Email, and Phone
columns.
Instructor notes
 This project requires the use of a data source with a single table, data-bound text boxes,
and error handling.
 If you assign this project after chapter 19, you can have your students enhance the
toolbar so it provides a button for canceling an edit operation. You can also have your
students add a parameterized query that retrieves a technician by technician ID.
24 Projects for Murach’s C# 2015

Project 4-3 Display customer incidents


For this project, you’ll create a form that lets the user display the incidents for a selected
customer. Prerequisites: chapters 1-11, 17-19.
The design of the Customer Incidents form

Operation
 When this application starts, a blank Customer Incidents form is displayed.
 To retrieve a customer, the user enters a customer ID and clicks the Get Customer
button. Then, the customer data for the customer with that ID is displayed in the text
boxes and the incidents for that customer are displayed in the DataGridView control. If
a customer with the specified ID isn’t found, an error message is displayed.
Specifications
 Create a data source with two tables: Customers and Incidents. Include all the columns
in the Customers table and all the columns except for TechID and Description in the
Incidents table.
 Add a query to the Customers table adapter that retrieves the data for a customer with a
specified ID. This query should be used to display the customer data in the text boxes
on the form.
 Add a query to the Incidents table adapter that retrieves the incidents for a specified
customer. This query should be used to display the incidents in the DataGridView
control.
 Use error handling as necessary throughout this application.
25 Projects for Murach’s C# 2015

Instructor note
 This project requires the use of a data source with two related tables, parameterized
queries, a custom toolbar, and data validation.
26 Projects for Murach’s C# 2015

Project 4-4 Add customer incidents


For this project, you’ll create a form that lets the user add incidents for a selected
customer. Prerequisites: chapters 1-11, 17-19.
The design of the Add Incident form

Operation
 When this application starts, a blank Add Incident form is displayed.
 To retrieve a customer, the user enters a customer ID and clicks the Get Customer
button. Then, the customer ID and name for that customer are displayed in the first two
text boxes. If a customer with the specified ID isn’t found, an error message is
displayed.
 To add an incident, the user selects a product from the combo box, enters a title and
description, and clicks the Add button to add a row to the Incidents table and update the
database. If the update is successful, a dialog box like the one that follows is displayed
and the form is cleared:

 To cancel the addition of an incident, the user clicks the Cancel button and the form is
cleared.
Specifications
 Create a data source with three tables: Customers, Incidents, and Products. Include the
CustomerID and Name columns in the Customers table, all the columns in the
27 Projects for Murach’s C# 2015

Incidents table except for TechID and DateClosed, and the ProductCode and Name
columns in the Products table.
 Add a query to the Customers table adapter that retrieves the data for a customer with a
specified ID. This query should be used to display the customer name on the form.
(The Customer ID text box will supply the value that’s saved in the CustomerID
column of a new incident, so it should be bound to the Incidents table.)
 Add a query to the Products table adapter that retrieves the products that are registered
to a customer. To do that, you can join the Products table with the Registrations table
and return only the rows for the products in the Registrations table for the selected
customer. These products should be displayed in the combo box on the Add Incident
form. (Be sure to create this query before you bind the combo box or you’ll have
trouble creating the query.)
 Use the Incidents binding source to add a new, blank row to the Incidents table when a
valid customer ID is entered. Then, set the value of the Customer ID text box to that
customer ID, and set the value of the Date Opened text box to the current date.
 Enable and disable the controls for adding an incident and for canceling an addition as
necessary so these controls are enabled only when a customer has been selected. (These
controls should be disabled by default.) In addition, set the ReadOnly property of the
Date Opened text box to True so it can’t be modified.
 Validate the data on the Add Incident form to be sure that a product is selected and that
a title and description are entered.
 Use error handling as necessary throughout this application.
Hints
 If you create the Product combo box from the ProductCode field in the Incidents table,
the data source for the query will be set to the Incidents table by default. To add the
query to the Products table, you’ll need to select that table from the combo box at the
top of the Search Criteria Builder dialog box.
 To clear the data from the form after an incident is added, use the RemoveCurrent
method of the Customers and Incidents binding sources.
 If you retrieve a customer and then retrieve another customer without adding an
incident for the first customer, an error will occur unless you cancel the addition of the
incident for the first customer. To test for this situation, you can check the number of
rows in the Incidents binding source when the user clicks the Get Customer button and
then cancel the addition of the incidents row if the binding source already contains a
row.
Instructor notes
 Although this application performs a relatively simple operation, it uses three tables
and two parameterized queries, and one query includes a join to a fourth table. In
addition, this application requires somewhat complex logic. To make it easier to
complete, the specifications include information about the data source and queries, and
the hints include information about the program logic. If you want to make this project
more difficult, you can omit some or all of this information.
 If you assign this project after chapter 20, you can have your students implement it
using ADO.NET code.
28 Projects for Murach’s C# 2015

Project 4-5 Register products


For this project, you’ll develop an application that lets the user register products to
customers. Prerequisites: chapters 1-12, 17, 20.
The design of the Add Registration form

Operation
 The user selects a customer and product from the two combo boxes, enters a date in the
text box, and clicks the Register Product button to add a new row to the Registrations
table.
 After the user registers a product or clicks the Cancel button to cancel the add
operation, the Add Registration form is cleared.
Specifications
 Add the following classes to the project:

The GetCustomers method in the CustomerDB class should return a List<Customer>


object that can be bound to the Customer combo box, the GetProducts method in the
ProductDB class should return a List<Product> object that can be bound to the
Product combo box, and the AddRegistration method in the RegistrationDB class
should accept a Registration object and return a Boolean value that indicates if the
operation was successful. Use the value that’s returned by the AddRegistration
method to display a message indicating the result of the operation.
 Validate the data on the Add Registration form to be sure that a customer and product
are selected and a registration date with a valid format is entered. The default
registration date for a new registration should be the current date.
29 Projects for Murach’s C# 2015

Instructor notes
 The class diagram for this project indicates that the properties for the Customer,
Product, and Registration classes be coded as auto-implemented properties. If you’d
prefer, you can have your students code them as standard properties instead.
 To enhance this project, you can have your students add another method to the
RegistrationDB class that checks if a product is already registered to a customer. Then,
this method can be used in the validation routine.
 If your students have read chapter 16, you can have them store the business and
database classes in a class library.
30 Projects for Murach’s C# 2015

Section 5 projects
Project 5-1 Maintain student scores (text file)
For this project, you’ll develop an application like the ones described in projects 2-2 and
3-5 that let the user maintain a list of student scores. For this project, though, you’ll use a
text file to store the student data. If you have already done project 2-2 or 3-5, you can use
it as a starting point for this project. Prerequisites: chapters 1-12, 15, 21.
The design of the Student Scores form

Operation
 See project 2-2.
Specifications
 When this application starts, it should read student data from a text file named
StudentScores.txt in the C:\C# 2015\Files directory and display this data in the Students
list box. If this directory or file doesn’t exist, it should be created.
 When students are added, updated, or deleted, this application should write the student
data to the StudentScores.txt file, overwriting any existing data.
 This application should use a class named StudentDB to read data from and write data
to the StudentScores.txt file.
Instructor notes
 Instead of storing the student data in a text file, you can modify this project so the data
is stored in a binary file.
 After your students have completed chapter 22, you can have them modify this project
so the student data is stored in an XML file.
31 Projects for Murach’s C# 2015

Project 5-2 Display incidents by technician


For this project, you’ll develop an application that displays closed incidents by
technician. Prerequisites: chapters 1-12, 23.
The design of the Incidents by Technician form

Operation
 When this application starts, all the closed incidents are listed by technician in a
ListView control.
Specifications
 Add the following classes to the project:

The GetTechnicians method in the TechnicianDB class should return a


List<Technician> object, and the GetIncidents method in the IncidentDB class
should return a List<Incident> object. These objects should be loaded from text files
named Technicians.txt and Incidents.txt that your instructor gives you.
 Use LINQ to define a query expression that will return the fields required by this
application from the List<> objects. Only the closed incidents should be returned, and
those incidents should be sorted by the date opened within the technician name.
 Include the technician name only for the first incident for each technician.
Hint
 Because the fields in the Incidents text file that store the technician ID and date closed
can contain empty strings, you will need to define the TechID and DateClosed fields in
the Incident class as nullable. Then, when you retrieve the values for an incident from
32 Projects for Murach’s C# 2015

the text file, you can check these fields to see if they contain empty strings. If they do,
you can assign null to the fields in the Incident object.
Instructor notes
 If your students haven’t read chapter 21, you will want to provide them with the
TechnicianDB and IncidentDB classes. You may also want to provide your students
with these classes to simplify this project.
 You can also simplify this project by not requiring that the technician names be printed
only for the first incident for each technician.
 To enhance this project, you can have your students add a column to the ListView
control for the customer name. This will involve adding a business class that defines a
Customer object and a database class with a method that loads a file of customers into a
List<Customer> object. (The customer file is provided for you.) Then, the
List<Customer> object can be included in the query expression.
 You can also enhance this project by having your students use extension methods and
lambda expressions instead of using C# clauses.
33 Projects for Murach’s C# 2015

Project 5-3 Maintain incidents


For this project, you’ll develop an application that lets the user assign a date closed and
change the description for open incidents in the TechSupport database. Prerequisites:
Chapters 1-12, 17, 18, 23, 24.
The design of the Incident Maintenance form

Operation
 When the user selects a customer from the combo box, the open incidents for that
customer that have been assigned to a technician are displayed in the DataGridView
control.
 When the user changes the date closed or description for one or more incidents and
clicks the Save button, the changes are saved to the database.
Specifications
 Add an Entity Data Model that includes the Incidents and Customers tables from the
TechSupport database to the project.
 Use LINQ to Entities to define a query expression that returns all the customers that
have incidents that have been assigned to a technician and that haven’t been closed.
Only one object should be returned for each customer. To accomplish that, you can
execute the Distinct method on the query.
 Set the data source for the combo box to a second query expression that sorts the
results of the first query by customer name. This second query expression is required
because the Distinct method works only with unsorted elements.
 Complete the binding for the combo box so the customer names will be displayed in
the control and so the customer ids will be stored in the control.
 Create an object data source from the Incident entity type. (You may need to rebuild
the project for the entity types to be listed in the Data Source Configuration Wizard.)
Then, create a DataGridView control from the object data source.
 Change the properties for the DataGridView control so rows can’t be added or deleted.
In addition, change the properties of the columns so they look like the ones shown
above. Only the Date Closed and Description columns should be modifiable. You can
delete the columns for the Customer and CustomerID properties, but don’t delete the
column for the IncidentID property since it’s needed to perform the update operation.
Instead, change its Visible property to false.
34 Projects for Murach’s C# 2015

 Use LINQ to Entities to define a query expression that returns all the incidents for the
selected customer that have been assigned to a technician and that haven’t been closed.
To get the customer id for the selected customer, cast the SelectedItem property of the
combo box to a Customer object and then get the CustomerID property from that
object.
 Bind the collection of incidents to the binding source for the DataGridView control.
Hints
 Be sure not to set the CancelButton property of the form to the Exit button. If you do,
the user won’t be able to press the Esc key to cancel a change in the DataGridView
control.
 To get the customer id for the customer that’s selected in the combo box, the query
expressions that return the customer data must return the entire customer row instead of
an anonymous type. That way, you can cast the SelectedItem property of the combo
box to a Customer object.
Instructor notes
 This is not a trivial project. Besides creating and working with an Entity Data Model,
your students will need to know how to bind a combo box and a DataGridView control
to the results of a query, how to create and work with an object data source, and how to
format the columns of a DataGridView control.
 If you want to enhance this project, you can have your students use extension methods
and lambda expressions in the required queries instead of C# clauses.
35 Projects for Murach’s C# 2015

Section 6 project
Project 6-1 Calculate conversions
For this project, you’ll develop an application that lets the user perform conversion
calculations. This application requires a parent form that includes both a menu and a
toolbar, a child form that lets the user calculate conversions, and two additional forms. It
also uses two text files, an XML file, two business classes, and two database classes.
Prerequisites: chapters 1-12, 21, 22, 24.
The design of the parent and child forms

Operation
 To display an instance of the Conversion form, the user selects the New Conversion
command from the File menu or clicks the New button in the toolbar.
 To switch to an open Conversion form, the user clicks the form or selects the form
from the Window menu.
 To close the active Conversion form, the user clicks the Close button or selects the
Close command from the File menu.
 To change the conversion options, the user clicks the Options button in the toolbar or
selects the Options command from the Tools menu to display the Options dialog box.
 To arrange the open Conversion forms within the parent form, the user selects the
Cascade, Tile Vertical, or Tile Horizontal command from the Window menu.
 To perform a conversion, the user selects the conversion to be performed from the
combo box list and the application modifies the labels that indicate the “from” and “to”
lengths accordingly. Then, the user enters the “from” length and clicks the Calculate
button.
36 Projects for Murach’s C# 2015

The design of the Options form

Operation
 To change the conversion that’s displayed by default when a Conversion form is
opened, the user selects the conversion from the Default Conversion combo box.
 To determine whether or not the toolbar is displayed, the user checks or unchecks the
Show Toolbar option.
 To remove a conversion so it’s not included in any new Conversion forms that are
opened, the user selects the conversion in the list and then clicks the Remove button.
 To add a conversion to any new Conversion forms that are opened, the user clicks the
Add button to display the Add Conversion dialog box.
 To restore the default options, the user clicks the Restore Defaults button.
 To save all the changes made to the options, the user clicks the OK button. To cancel
the changes, the user clicks the Cancel button.
The design of the Add Conversion form

Operation
 To add a conversion, the user enters unit descriptions in the From and To text boxes
and a multiplier that indicates the number of To units in a From unit in the Multiplier
text box, and then clicks the OK button.
37 Projects for Murach’s C# 2015

Specifications
 All user entries should be checked to be sure they’re valid.
 When the application starts, the parent form should do the following:
(1) Read the conversion data from a text file named Conversions.txt that’s stored in
the same directory as the other project files and store it in an array;
(2) Read the current options from an XML file named Options.xml that’s stored in
the same directory as the other project files and store them in an instance of a
class named Options; and
(3) Display one Conversion form.
 When a child form is displayed, the application should append a number to the text in
its title bar.
 If any changes are made to the options, the Options.xml file should be updated.
 If conversions are added, removed, or restored, the Conversions.txt file should be
updated.
 The default conversions are stored in a text file named ConversionsDefault.txt in the
same directory as the other project files. These conversions are as follows:
From To Conversion
Miles Kilometers 1 mile = 1.6093 kilometers
Kilometers Miles 1 kilometer = 0.6214 miles
Feet Meters 1 foot = 0.3048 meters
Meters Feet 1 meter = 3.2808 feet
Inches Centimeters 1 inch = 2.54 centimeters
Centimeters Inches 1 centimeter = 0.3937 inches

 The code for working with the Conversions and ConversionsDefault files should be
stored in a class named ConversionsDB. The code for working with the Options file
should be stored in a class named OptionsDB. And the code for validating the user
entries should be stored in a class named Validator.
Hints
 To refer to the text and XML files in the project directory, you can use this path:
..\..\
This means that the files are two directories above the directory that contains the
executable file for the program, which is usually the bin\Debug directory that’s
subordinate to the project directory.
 To display a list of all the open Conversion windows in the Window menu, you can set
the MdiWindowListItem property of the menu to True.
 To display a dialog box in the center of the parent window, you can set the
StartPosition property of the dialog box to CenterParent.
Instructor notes
 This project is good for testing many of the basic skills presented in sections 2, 3, 5,
and 6 of this book.
 You might also have your students add ToolTips and context-sensitive help to one or
more forms of this application.

You might also like