Thursday, October 18, 2007

Final Project Presentation

Presentation for the final project will be on October 19, Friday at Rm 308, DR2 and will start at 8:30AM.

Each group will be given 20 minutes starting with the first group from IT3A. The order of the presentation is arranged alphabetically based on the first member of the group as follows:

IT3A:
1. Alcoberes, et. al.
2. Arinto, et. al.
3. Barriga, et. al.
4. Basas, et. al.
5. Claro, et. al.
6. Gaanan, et. al.
7. Gio, et. al.

IT3B:
8. Abello, et. al.
9. Alay, et. al.
10. Albores, et. al.
11. Carado, et. al.
12. Co, et. al.
13. Deocampo, et. al.
14. Donayre, et. al.
15. Frigillano, et. al.
16. Masudo, et. al.
17. Polancos, et. al.

Wednesday, October 17, 2007

Using Crystal Reports

For those who are having problems with integrating Crystal Report in their applications, check this out:

http://www.crystalreportsbook.com/CrystalReportsXI.asp

Friday, October 12, 2007

Sample Codes: Data Access (2)

This sample improves the previous one by delegating all data access functions to a separate class named DBHelper. This also implements row filtering using the DefaultView property of a DataTable.

Download Code

This sample uses an MS Access database for persistent storage and adds reporting capabilities. This uses a different approach to retrieving and updating data by extending the DataSet class.

Download Code

To run both applications, set the ConnectionString value of the App.config file to the correct path of the databases. For the second example, Crystal Studio should be installed.

Thursday, September 20, 2007

Sample Code and Slide: Data Access

This sample uses the SQL provider to retrieve and manipulate data in an attached database (SQLExpress). This also demonstrates binding data to DataGridView and ComboBox controls.

To run the application, edit the AttachDbFilename value in the App.config file to point to the correct path of the database file. You can also copy the mdf/ldf files to a fixed location, e.g. "C:\", and set your AttachDbFilename value to "C:\Purchasing.mdf"

Download Code
Download Powerpoint Presentation

Wednesday, September 12, 2007

Final Program: Forms

Instruction: Submit this exercise on September 19, Wednesday. Compress the whole project located at "My Documents Path\Visual Studio 2005\Projects\Project Name" (default) or at the location you specified. Upload this file to ELMS. Also include the database design for your final project.

Continuing from exercise #8, create additional forms (a minimum of 3) for the transactions that your application will support. Each form should contain all fields necessary to process its corresponding transaction and should provide validation of its fields.

As an example, consider a Loans Management System which allows a group or a company to monitor all member loans. Possible transactions identified can include the following:
  • Loan Application - form to process member loan applications. Fields can include the transaction date, loan status, member information, loan type, loan cycle, loan amount, interest, mode of payment (monthly, weekly, etc) and terms of payment. Validation can be applied to numeric types like loan cycle, loan amount, and interest.
  • Loan Release - form to process loan disbursements. Fields can include the release date, loan status, and authorizing officer.
  • Loan Payment - form to process payments made by member. Fields can include the payment date, principal amount paid, interest amount paid, and cashier. Validation can be applied to numeric types.

Tuesday, August 28, 2007

Programming Exercise 8: Windows Forms 4

Instruction: Submit this exercise on September 10, Monday. Compress the whole project located at "My Documents Path\Visual Studio 2005\Projects\Project Name" (default) or at the location you specified. Upload this file to ELMS.

In preparation for your finals, you will be creating an application that will serve as the prototype for your final project. Although not fully functional, your application should implement these minimum requirements:
  • The application starts with a login form that will perform user validation. If the entered username and password are valid, load the main application form. If not, display an error. If the user clicks the Cancel button, the application should terminate. Since the application is not yet capable of storing data to a persistent storage, validate using "guest" as username and password for the meantime.
  • The application should also integrate your existing User Manager application. The User Manager form can be loaded when clicking the System -> Maintenance -> System Users menu item in the main application form.
  • The main application form should contain menu items similar to the sample given, i.e. it should have the following menus:
    • System - contains all menu items related to performing system functions
      • Maintenance - contains menu items related to configuring system-wide settings like system users and role assignments.
      • Masterfile - contains menu items related to configuring system-wide settings like lookup values used in transactions. An example of a menu item is "Loan Type" for a Loans Management System. Replace this with masterfiles related to your proposed system.
      • Exit - prompts a message confirming if the user wishes to close the application.
    • Transaction - contains all menu items related to performing system transactions. An example of a menu item is "Loan Application" for a Loans Management System. Replace this with transactions related to your proposed system.
    • Report - contains all menu items related to creating reports. An example of a menu item is "Loan Summary Report" for a Loans Management System. Replace this with reports related to your proposed system.
  • Create a System Configuration form similar to the sample given. This form does not need to implement any functionality yet and is reserved for future exercises.

The application should also integrate your existing User Manager application. The User Manager form can be loaded when clicking the System -> Maintenance -> System Users menu item in the main application form.
Hints: In addition to the existing controls you've used, this application also uses the following controls:
  • MenuStrip
  • StatusStrip
  • ListBox
  • TabControl
  • ComboBox
For the main application form, research on creating MDI forms.

You can download a sample output here.

Sample Code and Slide: Regular Expressions

This sample demonstrates using regular expressions for matching patterns in a string, which can be used to perform form data validation. This also uses a listbox form control for displaying results.

Download Code
Download Powerpoint Presentation

Wednesday, August 15, 2007

Programming Exercise 7: Windows Forms 3

This exercise is due on August 22, Wednesday. Compress the whole project located at "My Documents Path\Visual Studio 2005\Projects\Project Name" and upload it to ELMS.

Continuing from exercise #6, update your User Management application to support the following operations:

  • Edit a User record
  • Delete a User record
The application should have these additional buttons:
  • Edit - enables all textboxes (except the current index) for editing
  • Delete - deletes the current User record from the list
The functionality of these existing buttons should also be updated:
  • Save - if in edit mode, updates the current User record using values from the textboxes
  • Cancel - if in edit mode, disables all textboxes without updating the current User record
You can download the updated sample output here.

Hint: Use the ArrayList class for storing values as this array can be dynamically resized.

Wednesday, August 8, 2007

Programming Exercise 6: Windows Forms 2

Continuing from exercise #5, create a User Management application that maintains a list of User records. The application should support the following operations:
  • Add a new User record
  • Navigate through the list
The application should contain the following buttons:
  • Prev - moves to the previous User record
  • Next - moves to the next User record
  • New - clears and enables all textboxes for record entry
  • Save - adds a new User record to the list
  • Cancel - clears and disables all textboxes without adding a User record to the list
Upon application startup, all form controls (textboxes and buttons) except the New button are disabled. When the New button is clicked, the Save and Cancel buttons, as well as textboxes except the current index, are enabled. Clicking on the Save button will create a User record with values based on the values entered in the textboxes. This new record will be added to the list.

If there are already records in the list, the application should allow navigation through the Prev and Next buttons. The current index textbox should also be updated based on the record's index in the list. If the current index is 0, the Prev button is disabled. If the current index is equal to the number of records in the list, the Next button is disabled.

You can download the sample output here.

Sample Code: Forms (Properties)

This sample demonstrates using some of the properties of the Form controls to control the application's behavior. This also demonstrates the use of classes to pass data between forms, accessible through a property.

Download Code

Wednesday, August 1, 2007

Programming Exercise 5: Windows Forms

Create a windows application that allows a user to input the following in a Windows form titled 'Add User':
  • User ID
  • Password
  • First Name
  • Last Name
  • E-mail Address
The application should also contain two buttons: "Add" and "Clear". Clicking on the "Add" button will display all the entered fields on a separate Windows form. The displayed text should follow this format:
  • User ID : UserID
  • Password: Password
  • First Name: First Name
  • Last Name: Last Name
  • E-mail Address: E-mail Address
Hint: You can use the MessageBox class for this purpose.

Clicking on the "Clear" button clears all fields.

Here's a screenshot on how the application will look like:

Sample Code: Forms (Label, TextBox and Button)

This sample demonstrates the use of Label, Text and Button controls in a Windows Application. It also uses the MessageBox class for displaying messages in a separate Windows Form.

Download Code

Saturday, July 28, 2007

Sample Codes: Arrays and Collections

Here are the sample codes demonstrating the concepts discussed for arrays and collections

Wednesday, July 25, 2007

Programming Exercise (Ungraded): Inheritance

Implement the following class hierarchy:


Description of each class and its members:
  • Phone - an abstract class
    • Type - an abstract readonly property that identifies the type of phone. Implemented by subclasses
    • Number - an abstract property that sets and gets the phone number. Implemented by subclasses
    • Ring - an abstract method that will output the message "Ringing phone-type" when invoked. Implemented by subclasses
  • Telephone - an implementation of the Phone abstract class that represents all landline-based phones
    • Telephone - constructor that accepts a phone number as parameter
    • Type - returns "Telephone"
    • Number - gets or sets the phone number. This property should also validate the assigned phone number using this format: nnn-nnnn
    • Ring - displays the message "Ringing Telephone" when invoked
  • CellularPhone - an implementation of the Phone abstract class that represents all mobile-based phones
    • CellularPhone - constructor that accepts a phone number parameter
    • Type - returns "CellularPhone"
    • Number - gets or sets the phone number. This property should also validate the assigned phone number using this format: nnnn-nnnnnnn
    • Ring - displays the message "Ringing CellularPhone" when invoked
After implementing, you should be able to use your classes as follows:

class Program
{
static void Main(string[] args)
{
Telephone telephone = new Telephone("233-1234");
CellularPhone cellphone = new CellularPhone("0920-1234567");

Console.WriteLine(telephone.Type); // displays "Telephone"
Console.WriteLine(cellphone.Type); // displays "CellularPhone"

telephone.Number = "233-123"; // displays error
Console.WriteLine(telephone.Number); // displays "233-1234"
cellphone.Number = "0920-123x567"; // displays error
Console.WriteLine(cellphone.Number); // displays
"0920-1234567"
Phone phone = cellphone;
Console.WriteLine(phone.Number); // displays
// "0920-1234567"

phone = telephone;
phone.Ring(); // displays "Ringing Telephone"

Console.ReadLine();
}
}

Monday, July 23, 2007

Exam 1: Solution

This solution contains all implementation for the exam problems. Download it here.

Tuesday, July 17, 2007

Exam 1: C# Basics and Classes

Instruction: Zip all your project files for this exam and send them to my e-mail address. Name your zip file as section_name.zip. Project folders inside the zip file should be organized as follows:
/Prob1
/Prob2
/Prob3
/Prob4 (if present)

Ganbatte ne.

Problem #1 (10pts): Create a console application that accepts 3 float values and displays these numbers in ascending order.

Expected program output:
Enter float 1: 3.6
Enter float 2: 1.15
Enter float 3: 3.45

Order:
1.15
3.45
3.6

Problem #2 (15pts):
Create a console application that computes the Fahrenheit equivalent of a Celsius value and vice versa. The application should provide a menu that allows the user to choose the conversion to perform. In addition, the menu should also have an option to exit the application. In other words, the application will only terminate if the user chooses this option.

You can use these conversion formulas:

F = (9/5) C + 32
C = (F - 32)(5/9)

Expected program output:
Menu:
[C] Convert from Fahrenheit to Celsius
[F] Convert from Celsius to Fahrenheit
[X] Exit application
Choice: C

Enter temperature in Fahrenheit: 86
Temperature in Celsius: 30

Menu:
[C] Convert from Fahrenheit to Celsius
[F] Convert from Celsius to Fahrenheit
[X] Exit application
Choice: F

Enter temperature in Celsius:
Temperature in Fahrenheit:

Menu:
[C] Convert from Fahrenheit to Celsius
[F] Convert from Celsius to Fahrenheit
[X] Exit application
Choice: X

Problem #3 (25pts): Download this project and complete the Book class:

Define constructors that can accept the following parameters:
  • All parameters: book type, title, author, pages
  • Book type, title and author only
  • Title and author only
  • No parameters
Note: The book status should be initialized to Available upon creation.

Define the following properties:
  • Title - sets and gets the the book title
  • Author - sets and gets the author of the book.
    • The set implementation should not accept values with digits and should only update the field if the given value is valid
    • The get implementation return "Unknown" if it the author field has no value
  • Pages - sets and gets the number of pages in the book.
  • Type - sets and gets the book type
  • IsBorrowed (readonly) - returns a bool value indicating whether the book is borrowed or not
Define the following methods:
  • Borrow - sets the book status to borrowed. This method will return an error if the book's status is already borrowed
  • Return - sets the book status to available. This method should return an error if the book's status is already available.
  • ToString - returns a string representation of the object, formatted as follows:
    • "Type: booktype, Title: title, Author: author, Pages: pages"
After implementing these requirements, you should be able to compile and execute the project. You can use the defined Main method for testing your implementation.

Bonus (Extra 10pts):
Create a ConsoleUtil class that defines the following static methods:
  • ReadString - takes a string parameter that is used as a message prompt and returns a string entered by the user
  • WriteString - takes a string parameter and displays it
Sample usage:

class Program
{
static void Main(string[] args)
{
string name = ConsoleUtil.ReadString("Enter name:" ); // Prompts user to enter a name
ConsoleUtil.WriteString("Hello " + name);

Console.ReadLine();
}
}

Monday, July 16, 2007

Review Exercises

Problem #1: Data Types and Variables
Create a console application that accepts 4 int values from the user, and compute and output the following
  • The sum of the 4 integers
  • The product of the 4 integers
  • The difference between integers 1 and 2
  • The quotient between integers 3 and 4 expressed as a float type
Hint: Recall the Convert.Totype-name() or type-name.Parse() methods for converting a string to a numeric type. Also recall how to cast one data type to another to get the desired value.

Sample program output:

Enter integer 1: 10
Enter integer 2: 5
Enter integer 3: 8
Enter integer 4: 14

Sum: 37
Product: 5600
Difference (1 and 2): 5
Quotient (3 and 4): 0.5714286

Problem #2: Control Structures (Conditionals, Loops)
Create a console application that accepts a number of student grades to process. The application should loop through this number to get the grade for each student.

For each grade input, the application should check if the grade is within 60 to 100. If the grade is invalid, the application should display an error and ask for input again.

If the grade is valid, the application should check if the student passed or failed (failing grade is between 60 to 74) and should increment the appropriate count for passed or failed students (declared as variables). The application should also be able to compute the percentage of passed and failed students.

Sample program output:

Enter number of students to process: 10

Enter grade for student 1 (60-100): 80
Enter grade for student 2 (60-100): 10
Error: Grade must be within 60 to 100
Enter grade for student 2 (60-100): 74
...
Enter grade for student 10 (60-100): 90

Total no. of students: 10
No. of students who passed: 6
No. of students who failed: 4

Percentage of students who passed: 60%
Percentage of students who failed: 40%


Problem #3: Classes - Constructors, Fields, Properties and Methods
Create a class called MathUtil which implements the basic arithmetic functions defined in Problem #1. The choice on how to define the constructors, fields, properties or methods is totally up to you.

Slides: C# Basics and Classes

I updated the PowerPoint presentations used in our discussions. You can download them here:
Review these concepts for the prelim exam

Wednesday, July 11, 2007

Programming Exercise 4: Classes - Methods

Define a Deactivate() method in your existing User class. Calling this method will set its status field to Inactive.

This is the expected output when using your class:


class Program
{
static void Main(string[] args)
{
User user = new User("jtamad", "jtamad");
Console.WriteLine(user.IsActive); // Outputs "True" (default value)
user.Deactivate();
Console.WriteLine(user.IsActive); // Outputs "False"
Console.ReadLine();
}
}


Define another method, GetCopy(), that allows the class to return a copy of itself. Hint: Use the MemberwiseClone() method inherited from System.Object. You also need to perform a cast to the appropriate User object as this method returns a System.Object type.

After implementing this, you should be able to use your class as follows:


class Program
{
static void Main(string[] args)
{
User user1 = new User("jtamad", "jtamad");
Console.WriteLine(user1.UserID); // Outputs "jtamad"

User user2 = user1; // user2 references the
// same object as user1
user2.UserID = "juantamad"; // Modifies user1 also
// since user2 references
// the same object as user1
Console.WriteLine(user1.UserID); // Outputs "juantamad

user2 = user1.GetCopy(); // user2 has its own copy
// of a User object copied
// from user1
user2.UserID = "jtamad"; // Does not affect user1
// since this is a new object
Console.WriteLine(user1.UserID); // Outputs "juantamad"
Console.WriteLine(user2.UserID); // Outputs "jtamad"

Console.ReadLine();
}
}

Tuesday, July 10, 2007

Sample Code: Class Inheritance

This sample implements the inheritance hierarchy shown below

Download Code
Note: If clicking on this link doesn't work, copy the link location to a new browser window

Monday, July 9, 2007

Programming Exercise 3: Classes - Static Fields and Static Constructors

Define additional fields in your existing User class.
  • _dateCreated (static readonly) - Date of object creation
  • ClassesCreated (static) - Number of objects instantiated
Define a static constructor that initializes the ClassesCreated field to 0.

Modify your existing constructor to set values for the additional fields:
  • The _dateCreated field is set to the current date
  • The ClassesCreated field is incremented
Define a read-only property for the _dateCreated field

After implementing these, you should be able to use your class as follows:


class Program
{
static void Main(string[] args)
{
User user1 = new User("user1", "password1");
Console.WriteLine(user1.DateCreated); // Outputs the creation date for user1
Console.WriteLine(User.ClassesCreated); // Outputs "1" since this is the first object

User user2 = new User("user2", "password2");
Console.WriteLine(user2.DateCreated); // Outputs the creation date for user2
Console.WriteLine(User.ClassesCreated); // Outputs "2" since this is the second object
Console.ReadLine();
}
}

Thursday, July 5, 2007

Sample Codes: Classes

Here are a couple of sample codes available for download:
Note: If clicking on these links don't work, copy the link location to a new browser window

Wednesday, July 4, 2007

Programming Exercise 2: Classes - Fields, Properties and Constructors

Create a User class. This class should at least contain the following fields:
  • User ID - this is equivalent to a login name
  • Password
  • First Name
  • Last Name
  • E-mail Address
  • Status - valid values are 'Inactive', 'Active', 'Deleted'
Define constructors that accept the following parameter lists:
  • All parameters: User ID, Password, First Name, Last Name, E-mail Address
  • User ID, Password and E-mail Address
  • User ID and Password Only
** The status field should be initialized to 'Active' upon creation
** Constructors 2 and 3 should use a constructor initializer

Define read-only properties that return the following:
  • IsActive – whether or not the account's status is active
  • FullName – a concatenation of the account's first and last names
Define additional properties that behave as follows:
  • UserID
    • Set operation should ensure the user id does not start with a digit and should only update the user id field if the given value is valid
    • Get operation just returns the user id
  • Password
    • Set operation should validate the password length is within 8 to 20 characters and should only update the password field if the given value is valid
    • Get operation just returns the password
** You can reuse elements from your first programming exercise.
** Refer to the string class in the MSDN for methods in processing strings

After implementing these, you should be able to use your class as follows:


class Program
{
static void Main(string[] args)
{
User user = new User("jtamad", "jtamad",
"Juan", "Tamad", "jtamad@tapulan.com");

Console.WriteLine(user.IsActive); // Outputs "True"
Console.WriteLine(user.FullName); // Outputs "Juan Tamad"

user.UserID = "1jtamad"; // Outputs an error
user.Password = "1jta"; // Outputs an error
Console.WriteLine(user.UserID); // Outputs "jtamad", no changes
Console.WriteLine(user.Password); // Outputs "jtamad", no changes

user.UserID = "juantamad";
user.Password = "juantamad";
Console.WriteLine(user.UserID); // Outputs "juantamad"
Console.WriteLine(user.Password); // Outputs "juantamad"
}
}