@@ -22,24 +22,24 @@ public FillOrCancel()
22
22
/// </summary>
23
23
private bool IsOrderIDValid ( )
24
24
{
25
- // Check for input in the Order ID text box.
25
+ // Check for input in the Order ID text box.
26
26
if ( txtOrderID . Text == "" )
27
27
{
28
28
MessageBox . Show ( "Please specify the Order ID." ) ;
29
29
return false ;
30
30
}
31
31
32
- // Check for characters other than integers.
32
+ // Check for characters other than integers.
33
33
else if ( Regex . IsMatch ( txtOrderID . Text , @"^\D*$" ) )
34
34
{
35
- // Show message and clear input.
35
+ // Show message and clear input.
36
36
MessageBox . Show ( "Customer ID must contain only numbers." ) ;
37
37
txtOrderID . Clear ( ) ;
38
38
return false ;
39
39
}
40
40
else
41
41
{
42
- // Convert the text in the text box to an integer to send to the database.
42
+ // Convert the text in the text box to an integer to send to the database.
43
43
parsedOrderID = Int32 . Parse ( txtOrderID . Text ) ;
44
44
return true ;
45
45
}
@@ -48,43 +48,42 @@ private bool IsOrderIDValid()
48
48
49
49
//<Snippet2>
50
50
/// <summary>
51
- /// Executes a t-SQL SELECT statement to obtain
52
- /// order data for a specified order ID, then
53
- /// displays it in the DataGridView on the form.
51
+ /// Executes a t-SQL SELECT statement to obtain order data for a specified
52
+ /// order ID, then displays it in the DataGridView on the form.
54
53
/// </summary>
55
54
private void btnFindByOrderID_Click ( object sender , EventArgs e )
56
55
{
57
56
if ( IsOrderIDValid ( ) )
58
57
{
59
- using ( SqlConnection connection = new SqlConnection ( Properties . Settings . Default . connStr ) )
58
+ using ( SqlConnection connection = new SqlConnection ( Properties . Settings . Default . connString ) )
60
59
{
61
- // Define a t-SQL query string that has a parameter for orderID.
60
+ // Define a t-SQL query string that has a parameter for orderID.
62
61
const string sql = "SELECT * FROM Sales.Orders WHERE orderID = @orderID" ;
63
62
64
- // Create a SqlCommand object.
63
+ // Create a SqlCommand object.
65
64
using ( SqlCommand sqlCommand = new SqlCommand ( sql , connection ) )
66
65
{
67
- // Define the @orderID parameter and set its value.
66
+ // Define the @orderID parameter and set its value.
68
67
sqlCommand . Parameters . Add ( new SqlParameter ( "@orderID" , SqlDbType . Int ) ) ;
69
68
sqlCommand . Parameters [ "@orderID" ] . Value = parsedOrderID ;
70
69
71
70
try
72
71
{
73
72
connection . Open ( ) ;
74
73
75
- // Run the query by calling ExecuteReader().
74
+ // Run the query by calling ExecuteReader().
76
75
using ( SqlDataReader dataReader = sqlCommand . ExecuteReader ( ) )
77
76
{
78
- // Create a data table to hold the retrieved data.
77
+ // Create a data table to hold the retrieved data.
79
78
DataTable dataTable = new DataTable ( ) ;
80
79
81
- // Load the data from SqlDataReader into the data table.
80
+ // Load the data from SqlDataReader into the data table.
82
81
dataTable . Load ( dataReader ) ;
83
82
84
- // Display the data from the data table in the data grid view.
83
+ // Display the data from the data table in the data grid view.
85
84
this . dgvCustomerOrders . DataSource = dataTable ;
86
85
87
- // Close the SqlDataReader.
86
+ // Close the SqlDataReader.
88
87
dataReader . Close ( ) ;
89
88
}
90
89
}
@@ -94,7 +93,7 @@ private void btnFindByOrderID_Click(object sender, EventArgs e)
94
93
}
95
94
finally
96
95
{
97
- // Close the connection.
96
+ // Close the connection.
98
97
connection . Close ( ) ;
99
98
}
100
99
}
@@ -110,10 +109,10 @@ private void btnCancelOrder_Click(object sender, EventArgs e)
110
109
{
111
110
if ( IsOrderIDValid ( ) )
112
111
{
113
- // Create the connection.
114
- using ( SqlConnection connection = new SqlConnection ( Properties . Settings . Default . connStr ) )
112
+ // Create the connection.
113
+ using ( SqlConnection connection = new SqlConnection ( Properties . Settings . Default . connString ) )
115
114
{
116
- // Create the SqlCommand object and identify it as a stored procedure.
115
+ // Create the SqlCommand object and identify it as a stored procedure.
117
116
using ( SqlCommand sqlCommand = new SqlCommand ( "Sales.uspCancelOrder" , connection ) )
118
117
{
119
118
sqlCommand . CommandType = CommandType . StoredProcedure ;
@@ -124,10 +123,10 @@ private void btnCancelOrder_Click(object sender, EventArgs e)
124
123
125
124
try
126
125
{
127
- // Open the connection.
126
+ // Open the connection.
128
127
connection . Open ( ) ;
129
128
130
- // Run the command to execute the stored procedure.
129
+ // Run the command to execute the stored procedure.
131
130
sqlCommand . ExecuteNonQuery ( ) ;
132
131
}
133
132
catch
@@ -136,7 +135,7 @@ private void btnCancelOrder_Click(object sender, EventArgs e)
136
135
}
137
136
finally
138
137
{
139
- // Close connection.
138
+ // Close connection.
140
139
connection . Close ( ) ;
141
140
}
142
141
}
@@ -152,19 +151,19 @@ private void btnFillOrder_Click(object sender, EventArgs e)
152
151
{
153
152
if ( IsOrderIDValid ( ) )
154
153
{
155
- // Create the connection.
156
- using ( SqlConnection connection = new SqlConnection ( Properties . Settings . Default . connStr ) )
154
+ // Create the connection.
155
+ using ( SqlConnection connection = new SqlConnection ( Properties . Settings . Default . connString ) )
157
156
{
158
- // Create command and identify it as a stored procedure.
157
+ // Create command and identify it as a stored procedure.
159
158
using ( SqlCommand sqlCommand = new SqlCommand ( "Sales.uspFillOrder" , connection ) )
160
159
{
161
160
sqlCommand . CommandType = CommandType . StoredProcedure ;
162
161
163
- // Add the order ID input parameter for the stored procedure.
162
+ // Add the order ID input parameter for the stored procedure.
164
163
sqlCommand . Parameters . Add ( new SqlParameter ( "@orderID" , SqlDbType . Int ) ) ;
165
164
sqlCommand . Parameters [ "@orderID" ] . Value = parsedOrderID ;
166
165
167
- // Add the filled date input parameter for the stored procedure.
166
+ // Add the filled date input parameter for the stored procedure.
168
167
sqlCommand . Parameters . Add ( new SqlParameter ( "@FilledDate" , SqlDbType . DateTime , 8 ) ) ;
169
168
sqlCommand . Parameters [ "@FilledDate" ] . Value = dtpFillDate . Value ;
170
169
@@ -181,7 +180,7 @@ private void btnFillOrder_Click(object sender, EventArgs e)
181
180
}
182
181
finally
183
182
{
184
- // Close the connection.
183
+ // Close the connection.
185
184
connection . Close ( ) ;
186
185
}
187
186
}
0 commit comments