For a car rental company, the customers are the people or
entities who rent cars. In a small application, you can enter the customer's when
processing a rental order. A better way is to create a list of customers so that a
repeating customer would have his or her records already in the database.
Practical Learning: Introducing the Application
|
|
- In the Microsoft SQL Server Management Studio, if necessary, expand the
Databases, the bcr, and the Tables node.
To create a new table, right the Tables node under bcr and click New
Table...
- Set the first column name to CustomerID
- Set its Data Type to int
- In the lower section, expand Identity Specification and set the (Is
Identify) field to Yes
- Right-click CustomerID and click Set Primary Key
- Complete the table with the following columns
Column Name |
Data Type |
Allow Nulls |
CustomerID |
int |
|
DrvLicNbr |
varchar(50) |
Uncheck
|
FullName |
varchar(50) |
Uncheck |
Address |
varchar(50) |
|
City |
varchar(50) |
|
State |
varchar(50)
|
|
ZIPCode |
varchar(20)
|
|
Country |
varchar(50)
|
|
- Save the table as Customers and close it
- In the Object Explorer, right-click dbo.Customers and click Open Table
- Create a few
records
- In Microsoft Visual Studio, if necessary, open the bcr1 application
created in the previous section
- In the Data Source window, right-click dsBCR and click Configure DataSet
With Wizard...
- Expand the Tables node and click the check box of Customers
- Click Finish
- To create a new form, on the main menu, click Project -> Add New
Item...
- In the Templates list, click Windows Form and set the name to Customers
- Click Add
- Drag the Customers
node and drop it on the form
- While the DataGridView control is still selected on the form, in the
Properties window, click the ellipsis of the Columns field and make the
following changes:
Selected Columns |
HeaderText |
Width |
CustomerID |
Customer ID |
75 |
DrvLicNbr |
Drv. Lic. # |
|
FullName |
Full Name |
|
Address |
|
130 |
City |
|
80 |
State |
|
50 |
ZIPCode |
ZIP Code |
50 |
Country |
|
50 |
- Click OK
- Set DataGridView's Anchor property to Top, Bottom, Left, Right
- Under the DataGridView control, add a button and set its properties as
follows:
Text: Close
(Name): btnClose
Anchor: Bottom, Right
- Double-click the Close button and implement its even as follows:
private void btnClose_Click(object sender, EventArgs e)
{
Close();
}
|
- Access the first form
- Add a button to it and set its properties as follows:
Text: Customers
(Name): btnCustomers
- Double-click the Customers button
- In the top section of the file, under the #pragma once line, type #include
"Customers.h"
- Scroll to the bottom of the file and implement the even as follows:
System::Void btnCustomers_Click(System::Object^ sender,
System::EventArgs^ e)
{
Customers ^ frmCustomers = gcnew Customers;
frmCustomers->ShowDialog();
}
|
- Execute the application to test it
- Display the Customers form
- Close the form(s)
|
|