|
Introduction to Database Visual Support |
|
A Data Source
Introduction
Practical
Learning: Introducing Visual Database Support
- Start Microsoft Visual Studio
- To create a new application, on the main menu, click FILE -> New
-> Project...
- Make sure Windows Forms Application. Set the Name to
AltairRealtors2 and click OK
- To create a new database, in the Server Explorer, right-click Data
Connections and click Create New SQL Server Database...
- In the Server Name combo box, select your server or type (local)
- Set the database name as AltairRealtors2 and
click OK
- In the Server Explorer, right-click the AltairRealtors2 connection
and click New Query
- Open the
AltairRealtors2 file and select everything in the document
- Copy and paste it in the Query window
- Right-click inside the document and click Execute
- In the Solution Explorer, right-click Form1.cs and click Rename
- Type AltairRealtors.cs and press Enter twice
Adding a Data Source
Practical
Learning: Creating a Binding Source
- If necessary, display the form.
In the Toolbox, click Data and
click BindingSource
- Click the form
- In the Properties window, change its (Name) to
bsProperties
- Click DataSource and click the arrow of its combo box
- Click the + button of the Other Data Sources node to expand it
- Click the + button of the Project Data Sources node
- Click dsAltairRealtors
The Table Adapter
Introduction
After creating a data set and a data source, the next
step is to indicate to each control where its data would come from.
The Binding Navigator
Introduction
If you drag a table from the Data Source window and drop it on a form, Microsoft Visual Studio adds the necessary Windows controls to
the form and binds them to the columns of the table. To move from one record to another, you would need a way to navigate among the records. You can
manually take care of this if you want. Alternatively, the .NET Framework provides a class named BindingNavigator that contains all
the necessary functionality for this task.
There are various ways you can create a binding
navigator:
Practical
Learning: Generating Visual Objects
- Open the
LambdaSquareApartments1 file and select everything in it the
document
- Copy to the clipboard
- Display the Query window (if it not available, right-click any
connection in the Server Explorer and click New Query)
- To create a new database, paste in the Query window
- Right-click inside the Query window and click Execute
- To create a new application, on the main menu, click FILE -> New ->
Project...
- Make sure Windows Forms Application. Set the Name to
LambdaSquareApartments1
- Click OK.
If you are asked whether you want to save
SQLQuery1.sql, click No
- On the main menu, click PROJECT -> Add New Data Source...
- On the first page of the wizard, make sure Database is selected and
click Next
- On the second page of the wizard, make sure Dataset is selected and
click Next
- In the third page of the wizard, click New Connection...
If the
Choose Data Source dialog box comes up, click Microsoft SQL Server and
click Continue
- In the Server Name combo box, select the server or type
(local)
- In the Select or Enter a Database Name combo box, select
LambdaSquareApartments1
- Click OK
- On the Data Source Configuration Wizard, make sure the new
connection is selected
Click the + button of Connection String
- Click Next
- Change the connection string to csLambdaSquareApartments
and click Next
- Click the check boxes of Tables and Stored Procedures
- Change the name of the data set to dsLambdaSquareApartments
- Click Finish
- To create a new form, on the main menu, click PROJECT -> Add Windows
Form...
- Set the Name to Apartments and click Add
- From the Data Source, drag Apartments and drop it on the new form
- Design the form as follows:
- To create a new form, on the main menu, click PROJECT -> Add Windows
Form...
- Set the Name to Employees and click Add
- From the Data Source, drag Employees and drop it on the new form
- Design the form as follows:
- To create a new form, on the main menu, click PROJECT -> Add Windows
Form...
- Set the Name to Registrations and click Add
- From the Data Source, drag Registrations and drop it on the new form
- Design the form as follows:
- To create a new form, on the main menu, click PROJECT -> Add Windows
Form...
- Set the Name to Payments and click Add
- From the DataSource, drag Payments and drop it on the form
- Design the form as follows:
- In the Solution Explorer, right-click Form1.cs and click Rename
- Type LambdaSquareApartments.cs and press Enter twice
- Design the form as follows:
|
Control |
(Name) |
Name |
Button |
|
btnRegistrations |
Tenants Registrations... |
Button |
|
btnRentPayments |
Rent Payments... |
Button |
|
btnApartments |
Apartments... |
Button |
|
btnEmployees |
Employees... |
Button |
|
Close |
btnClose |
|
- Double-click the Tenants Registrations button
- Return to the form and double-click the Rent Payments button
- Return to the form and double-click the Apartments button
- Return to the form and double-click the Employees button
- Return to the form and double-click the Close button
- Implement the events as follows:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace LambdaSquareApartments1
{
public partial class LambdaSquareApartments : Form
{
public LambdaSquareApartments()
{
InitializeComponent();
}
private void btnRegistrations_Click(object sender, EventArgs e)
{
Registrations regs = new Registrations();
regs.Show();
}
private void btnRentPayments_Click(object sender, EventArgs e)
{
Payments pmts = new Payments();
pmts.Show();
}
private void btnApartments_Click(object sender, EventArgs e)
{
Apartments aparts = new Apartments();
aparts.Show();
}
private void btnEmployees_Click(object sender, EventArgs e)
{
Employees empls = new Employees();
empls.Show();
}
private void btnClose_Click(object sender, EventArgs e)
{
Close();
}
}
}
- Execute the application
- Click the Employees button, click the Add New button, add the values,
and click the Save button. The records to create are:
Employee # |
First Name |
Last Name |
Title |
40685 |
Justine |
Sandt |
Rent Manager |
73048 |
Raymond |
Wilkinson |
|
60949 |
Mark |
Reason |
Maintenance Technician |
38408 |
Marc |
Knights |
Rent Associate |
93947 |
Leonard |
Goulet |
Owner - General Manager |
20448 |
Nancy |
Longhorn |
Rent Associate |
- Click the Tenants Registrations button, click the Add New button, add
the values, and click the Save button. The records to create are:
Regist Date |
Employeee # |
Tenant Code |
First Name |
Last Name |
Marital Status |
Tenancy |
Children |
Phone # |
Email Address |
Unit |
Start Date |
2014-06-12 |
38408 |
29-485-05 |
Ann |
Sanders |
Married |
Active |
1 |
(240) 524 -2831 |
annsanders@emailcity.com |
139749 |
2014-07-01 |
2014-06-15 |
20448 |
83-400-85 |
Mahty |
Shaoul |
Married |
Active |
2 |
202-729-1574 |
mshaoulman@gmail.com |
928364 |
2014-09-01 |
2014-06-22 |
40685 |
48-602-73 |
Frank |
Ulm |
Single |
Active |
0 |
(301) 882-0704 |
fulm112244@yaho.com |
729397 |
2014-07-01 |
2014-06-22 |
93947 |
24-385-30 |
Elizabeth |
Provoski |
Separated |
Active |
1 |
(443) 974-9631 |
eprevalence@yahoo.com |
844850 |
2014-08-01 |
2014-07-23 |
93947 |
92-048-11 |
Grace |
Curryan |
Married |
Active |
1 |
(240) 927-0993 |
gcarrier@gmail.com |
297297 |
2014-09-01 |
2014-07-25 |
38408 |
51-304-58 |
Tracy |
Warrens |
Divorced |
Active |
2 |
202-793-6924 |
twarrior12@hotmail.coom |
492739 |
2014-08-01 |
2014-08-01 |
38408 |
72-384-04 |
Paul |
Yamo |
Married |
Active |
3 |
(410-792-7045 |
pyamo@hr.umd.edu |
384068 |
2014-10-01 |
2014-08-10 |
40685 |
62-405-29 |
Nancy |
Shermann |
Single |
Active |
1 |
(703) 338-2973 |
nsherre@emailcity.com |
829475 |
2014-09-01 |
2014-09-12 |
20448 |
72-484-04 |
Michael |
Tiernan |
Single |
Active |
0 |
301-274-9285 |
resdev.globelan.net |
829479 |
2014-11-01 |
2014-10-05 |
38408 |
60-285-83 |
Phillippe |
Anderson |
Single |
Active |
0 |
202-729-1574 |
philanders@gmail.com |
496055 |
2014-11-01 |
- Click the Rent Payments button, click the Add New button, add the
values, and click the Save button. The records to create are:
Pmt Date |
Employee # |
Regist Date |
Amt Paid |
Notes |
2014-06-12 |
38408 |
1001 |
650.0000 |
This is the payment for the security deposit. |
2014-06-20 |
40685 |
1003 |
500.0000 |
Security Deposit |
2014-07-27 |
38408 |
1003 |
925.0000 |
|
2014-07-28 |
38408 |
1001 |
1150.0000 |
|
2014-08-01 |
40685 |
1006 |
850.0000 |
Security Deposit |
2014-08-08 |
40685 |
1007 |
850.0000 |
Security Deposit |
2014-08-08 |
40685 |
1008 |
500.0000 |
Security Deposit |
2014-08-13 |
40685 |
1004 |
600.0000 |
Security Deposit |
2014-08-14 |
20448 |
1002 |
850.0000 |
Payment for security deposit |
2014-08-25 |
38408 |
1001 |
1150.0000 |
|
2014-08-25 |
38408 |
1002 |
1350.0000 |
|
2014-08-26 |
20448 |
1003 |
925.0000 |
|
2014-08-27 |
40685 |
1004 |
1100.0000 |
|
2014-08-30 |
38408 |
1006 |
1350.0000 |
|
2014-09-17 |
40685 |
1009 |
650.0000 |
Security Deposit |
2014-09-18 |
20448 |
1005 |
550.0000 |
Security Deposit |
2014-09-25 |
20448 |
1004 |
1100.0000 |
|
2014-09-25 |
20448 |
1006 |
1350.0000 |
|
2014-09-25 |
20448 |
1008 |
885.0000 |
|
2014-09-28 |
20448 |
1001 |
1150.0000 |
|
2014-09-28 |
40685 |
1002 |
1350.0000 |
|
2014-09-28 |
40685 |
1005 |
1150.0000 |
|
2014-10-05 |
38408 |
1003 |
925.0000 |
|
2014-10-08 |
40685 |
1010 |
500.0000 |
Security Deposit |
2014-10-24 |
38408 |
1004 |
1100.0000 |
|
2014-10-24 |
38408 |
1005 |
1150.0000 |
|
2014-10-25 |
40685 |
1006 |
1350.0000 |
|
2014-10-25 |
40685 |
1007 |
1250.0000 |
|
2014-10-27 |
93947 |
1001 |
1150.0000 |
|
2014-10-29 |
93947 |
1008 |
885.0000 |
|
2014-10-30 |
38408 |
1002 |
1350.0000 |
|
2014-10-31 |
40685 |
1003 |
925.0000 |
|
2014-11-26 |
38408 |
1002 |
1350.0000 |
|
2014-11-26 |
38408 |
1008 |
885.0000 |
|
2014-11-27 |
38408 |
1006 |
1350.0000 |
|
2014-11-28 |
20448 |
1004 |
1100.0000 |
|
2014-11-28 |
38408 |
1005 |
1150.0000 |
|
2014-11-28 |
38408 |
1007 |
1250.0000 |
|
2014-11-29 |
93947 |
1001 |
1150.0000 |
|
2014-11-30 |
38408 |
1003 |
925.0000 |
|
2014-11-30 |
20448 |
1009 |
1150.0000 |
|
2014-11-30 |
20448 |
1010 |
895.0000 |
|
2014-12-25 |
38408 |
1006 |
1350.0000 |
|
2014-12-25 |
38408 |
1007 |
1250.0000 |
|
2014-12-27 |
20448 |
1009 |
1150.0000 |
|
2014-12-28 |
20448 |
1001 |
1150.0000 |
|
2014-12-28 |
38408 |
1004 |
1100.0000 |
|
2014-12-28 |
38408 |
1005 |
1150.0000 |
|
2014-12-28 |
38408 |
1010 |
895.0000 |
|
2014-12-30 |
20448 |
1003 |
925.0000 |
|
2014-12-31 |
38408 |
1002 |
1350.0000 |
|
2014-12-31 |
20448 |
1008 |
885.0000 |
|
2015-01-23 |
20448 |
1005 |
1150.0000 |
|
2015-01-26 |
38408 |
1001 |
1150.0000 |
|
2015-01-28 |
93947 |
1003 |
925.0000 |
|
2015-01-29 |
93947 |
1002 |
1350.0000 |
|
2015-02-10 |
20448 |
1004 |
100.0000 |
This is a fee for late payment. |
2015-02-10 |
20448 |
1004 |
1100.0000 |
|
2015-02-20 |
20448 |
1001 |
1150.0000 |
|
2015-02-25 |
20448 |
1005 |
1150.0000 |
|
2015-02-26 |
38408 |
1002 |
1350.0000 |
|
2015-03-01 |
38408 |
1004 |
1100.0000 |
|
2015-03-03 |
40685 |
1003 |
925.0000 |
|
- Close the forms and return to your programming environment
|