|
Practical
Learning: Assisting With Data Entry
|
|
- Start Microsoft Visual C# and create a Windows Application named WattsALoan4
- To create a new form, in the Solution Explorer, right-click WattsALoan4
-> Add -> Windows Forms...
- Set the Name to LoanAllocations and click Add
- From the Data section of the Toolbox, click DataSet and click the form
- Select the Untyped Dataset radio button and click OK
- In the Properties window, change the following characteristics:
DataSetName: dsLoanAllocations
(Name): LoanAllocations
- Click Tables and click its ellipsis button
- To create a new table, click Add and change the properties as follows:
TableName: Loan
(Name): tblLoan
- Click Columns and click its ellipsis button
- Click Add 10 times and change the properties as follows:
| ColumnName |
(Name) |
| DateAllocated |
colDateAllocated |
| LoanNumber |
colLoanNumber |
| PreparedBy |
colPreparedBy |
| PreparedFor |
colPreparedFor |
| Principal |
colPrincipal |
| InterestRate |
colInterestRate |
| Periods |
colPeriods |
| InterestEarned |
colInterestEarned |
| FutureValue |
colFutureValue |
| MonthlyPayment |
colMonthlyPayment |
- In the Members list, click LoanNumber
- In the Properties list, double-click Unique to change its value to True
- In the Members list, click Principal
- In the Properties list, click DataType, click the arrow of its combo box
and select System.Double
- In the same way, change the data types of the following columns:
| Member |
DataType |
| DateAllocated |
System.DateTime |
| LoanNumber |
System.String |
| PreparedBy |
System.String |
| PreparedFor |
System.String |
| Principal |
System.Double |
| InterestRate |
System.Double |
| Periods |
System.Double |
| InterestEarned |
System.Double |
| FutureValue |
System.Double |
| MonthlyPayment |
System.Double |
- In the Members list, click Principal
- In the Properties list, click DefaultValue and delete <DBNull>
- Type 0.00
- In the same way, change the default values of the following columns:
| Member |
DefaultValue |
| Principal |
0.00 |
| InterestRate |
8.75 |
| Periods |
36 |
- In the Members list, click FutureValue
- In the Properties list, click Expression and type Principal + InterestEarned
- In the same way, change the data types of the following columns:
| Member |
Expression |
| InterestEarned |
Principal * (InterestRate / 100) * (Periods / 12) |
| FutureValue |
Principal + InterestEarned |
| MonthlyPayment |
FutureValue / Periods |
- In the Members list, click DateAllocated
- In the Properties list, double-click the value of the AllowDBNull field to
set it to False
- In the Members list, click LoanNumber
- In the Properties list, double-click the value of the AllowDBNull field to
set it to False
- Click Close and click Close
- To create a new form, in the Solution Explorer, right-click WattsALoan4
-> Add -> Windows Forms...
- Set the Name to Employees and click Add
- From the Data section of the Toolbox, click DataSet and click the form
- Select the Untyped Dataset radio button and click OK
- In the Properties window, change the following characteristics:
DataSetName: dsEmployees
(Name): Employees
- Click Tables and click its ellipsis button
- To create a new table, click Add and change the properties as follows:
TableName: Employee
(Name): tblEmployee
- Click Columns and click its ellipsis button
- Click Add 5 times and change the properties as follows:
| AllowDBNull |
ColumnName |
DefaultValue |
DataType |
Expression |
Unique |
(Name) |
| False |
EmployeeNumber |
|
|
|
True |
colEmployeeNumber |
| |
FirstName |
|
|
|
|
colFirstName |
| False |
LastName |
|
|
|
|
colLastName |
| |
FullName |
|
|
LastName + ', ' + FirstName |
|
colFullName |
| |
Title |
|
|
|
|
colTitle |
| |
HourlySalary |
8.75 |
System.Double |
|
|
colHourlySalary |
- Click Close and click Close
- Design the form as follows:
 |
| Control |
Text |
Name |
Other Properties |
| DataGridView |
|
dgvEmployees |
DataSource: dsEmployees
DataMember: Employee |
| Button |
Close |
btnClose |
|
|
| Data Grid Columns |
| DataPropertyName |
HeaderText |
Width |
| EmployeeNumber |
Empl # |
65 |
| FirstName |
First Name |
65 |
| LastName |
Last Name |
65 |
| FullName |
Full Name |
120 |
| Title |
|
110 |
| HourlySalary |
Salary/hr |
60 |
|
- Double-click an unoccupied area of the form and implement the event as
follows:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace WattsALoan4
{
public partial class Employees : Form
{
public Employees()
{
InitializeComponent();
}
private void Employees_Load(object sender, EventArgs e)
{
string strFilename = "employees.xml";
if (File.Exists(strFilename))
dsEmployees.ReadXml(strFilename);
}
}
}
|
- Return to the form and click an unoccupied area of its body
- In the Properties window, click the Events button and double-click
FormClosing
- Implement the event as follows:
private void Employees_FormClosing(object sender, FormClosingEventArgs e)
{
dsEmployees.WriteXml("employees.xml");
}
|
- Return to the form and double-click the Close button
- Implement the event as follows:
private void btnClose_Click(object sender, EventArgs e)
{
Close();
}
|
- Return to the form
- Under the form, right-click dsEmployees and click Copy
- Display the LoanAllocations form
- Right-click it and click Paste
- To create a new form, in the Solution Explorer, right-click WattsALoan4
-> Add -> Windows Forms...
- Set the Name to Customers and click Add
- From the Data section of the Toolbox, click DataSet and click the form
- Select the Untyped Dataset radio button and click OK
- In the Properties window, change the following characteristics:
DataSetName: dsCustomers
(Name): Customers
- Click Tables and click its ellipsis button
- To create a new table, click Add and change the properties as follows:
TableName: Customer
(Name): tblCustomer
- Click Columns and click its ellipsis button
- Click Add 5 times and change the properties as follows:
| AllowDBNull |
ColumnName |
Unique |
(Name) |
| False |
AccountNumber |
True |
colAccountNumber |
| False |
FullName |
|
colFullName |
| |
EmailAddress |
|
colEmailAddress |
| |
PhoneNumber |
|
colPhoneNumber |
- Click Close and click Close
- Design the form as follows:
 |
| Control |
Text |
Name |
Other Properties |
| DataGridView |
|
dgvCustomers |
DataSource: dsCustomers
DataMember: Customer |
| Button |
Close |
btnClose |
|
|
| Data Grid Columns |
| DataPropertyName |
HeaderText |
Width |
| AccountNumber |
Account # |
65 |
| FullName |
Full Name |
120 |
| EmailAddress |
Email Address |
120 |
| PhoneNumber |
Phone # |
90 |
|
- Double-click an unoccupied area of the form and implement the event as
follows:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace WattsALoan4
{
public partial class Customers : Form
{
public Customers()
{
InitializeComponent();
}
private void Customers_Load(object sender, EventArgs e)
{
string strFilename = "customers.xml";
if (File.Exists(strFilename))
dsCustomers.ReadXml(strFilename);
}
}
}
|
- Return to the form and click an unoccupied area of its body
- In the Properties window, click the Events button and double-click
FormClosing
- Implement the event as follows:
private void Customers_FormClosing(object sender, FormClosingEventArgs e)
{
dsCustomers.WriteXml("customers.xml");
}
|
- Return to the form and double-click the Close button
- Implement the event as follows:
private void btnClose_Click(object sender, EventArgs e)
{
Close();
}
|
- Return to the form
- Under the form, right-click dsCustomers and click Copy
- Display the LoanAllocations form
- Right-click it and click Paste
- Design the form as follows:
|
|