Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

ASP.NET 2.0 Instant Results

.pdf
Скачиваний:
67
Добавлен:
17.08.2013
Размер:
11.03 Mб
Скачать

Wiley Publishing, Inc.

End-User License Agreement

READ THIS. You should carefully read these terms and conditions before opening the software packet(s) included with this book “Book”. This is a license agreement “Agreement” between you and Wiley Publishing, Inc. “WPI”. By opening the accompanying software packet(s), you acknowledge that you have read and accept the following terms and conditions. If you do not agree and do not want to be bound by such terms and conditions, promptly return the Book and the unopened software packet(s) to the place you obtained them for a full refund.

1.License Grant. WPI grants to you (either an individual or entity) a nonexclusive license to use one copy of the enclosed software program(s) (collectively, the “Software”) solely for your own personal or business purposes on a single computer (whether a standard computer or a workstation component of a multi-user network). The Software is in use on a computer when it is loaded into temporary memory (RAM) or installed into permanent memory (hard disk, CD-ROM, or other storage device). WPI reserves all rights not expressly granted herein.

2.Ownership. WPI is the owner of all right, title, and interest, including copyright, in and to the compilation of the Software recorded on the disk(s) or CD-ROM “Software Media”. Copyright to the individual programs recorded on the Software Media is owned by the author or other authorized copyright owner of each program. Ownership of the Software and all proprietary rights relating thereto remain with WPI and its licensers.

3.Restrictions on Use and Transfer.

(a)You may only (i) make one copy of the Software for backup or archival purposes, or (ii) transfer the Software to a single hard disk, provided that you keep the original for backup or archival purposes. You may not (i) rent or lease the Software, (ii) copy or reproduce the Software through a LAN or other network system or through any computer subscriber system or bulletin-board system, or (iii) modify, adapt, or create derivative works based on the Software.

(b)You may not reverse engineer, decompile, or disassemble the Software. You may transfer the Software and user documentation on a permanent basis, provided that the transferee agrees to accept the terms and conditions of this Agreement and you retain no copies. If the Software is an update or has been updated, any transfer must include the most recent update and all prior versions.

4.Restrictions on Use of Individual Programs. You must follow the individual requirements and restrictions detailed for each individual program in the About the CD-ROM appendix of this Book. These limitations are also contained in the individual license agreements recorded on the Software Media. These limitations may include a requirement that after using the program for a specified period of time, the user must pay a registration fee or discontinue use. By opening the Software packet(s), you will be agreeing to abide by the licenses and restrictions for these individual programs that are detailed in the About the CD-ROM appendix and on the Software Media. None of the material on this Software Media or listed in this Book may ever be redistributed, in original or modified form, for commercial purposes.

5.Limited Warranty.

(a)WPI warrants that the Software and Software Media are free from defects in materials and workmanship under normal use for a period of sixty (60) days from the date of purchase of this Book. If WPI receives notification within the warranty period of defects in materials or workmanship, WPI will replace the defective Software Media.

(b)WPI AND THE AUTHOR(S) OF THE BOOK DISCLAIM ALL OTHER WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, WITH RESPECT TO THE SOFTWARE, THE PROGRAMS, THE SOURCE CODE CONTAINED THEREIN, AND/OR THE TECHNIQUES DESCRIBED IN THIS BOOK. WPI DOES NOT WARRANT THAT THE FUNCTIONS CONTAINED IN THE SOFTWARE WILL MEET YOUR REQUIREMENTS OR THAT THE OPERATION OF THE SOFTWARE WILL BE ERROR FREE.

(c)This limited warranty gives you specific legal rights, and you may have other rights that vary from jurisdiction to jurisdiction.

6.Remedies.

(a)WPI’s entire liability and your exclusive remedy for defects in materials and workmanship shall be limited to replacement of the Software Media, which may be returned to WPI with a copy of your receipt at the following address: Software Media Fulfillment Department, Attn.: ASP.NET 2.0 Instant Results, Wiley Publishing, Inc., 10475 Crosspoint Blvd., Indianapolis, IN 46256, or call 1-800-762-2974. Please allow four to six weeks for delivery. This Limited Warranty is void if failure of the Software Media has resulted from accident, abuse, or misapplication. Any replacement Software Media will be warranted for the remainder of the original warranty period or thirty (30) days, whichever is longer.

(b)In no event shall WPI or the author be liable for any damages whatsoever (including without limitation damages for loss of business profits, business interruption, loss of business information, or any other pecuniary loss) arising from the use of or inability to use the Book or the Software, even if WPI has been advised of the possibility of such damages.

(c)Because some jurisdictions do not allow the exclusion or limitation of liability for consequential or incidental damages, the above limitation or exclusion may not apply to you.

7.U.S. Government Restricted Rights. Use, duplication, or disclosure of the Software for or on behalf of the United States of America, its agencies and/or instrumentalities “U.S. Government” is subject to restrictions as stated in paragraph (c)(1)(ii) of the Rights in Technical Data and Computer Software clause of DFARS 252.227-7013, or subparagraphs

(c)(1) and (2) of the Commercial Computer Software - Restricted Rights clause at FAR 52.227-19, and in similar clauses in the NASA FAR supplement, as applicable.

8.General. This Agreement constitutes the entire understanding of the parties and revokes and supersedes all prior agreements, oral or written, between them and may not be modified or amended except in a writing signed by both parties hereto that specifically refers to this Agreement. This Agreement shall take precedence over any other documents that may be in conflict herewith. If any one or more provisions contained in this Agreement are held by any court or tribunal to be invalid, illegal, or otherwise unenforceable, each and every other provision shall remain in full force and effect.

1

Modifying the Online Diar y

The project as it stands provides a good springboard for a fully developed diary and contacts management system. You could, for example, improve contact display and management. While the system is fine for a dozen or two contacts it’ll become unwieldy much beyond that. Organizing display of contacts by the first letter of their surname would be one way of dealing with this. The Contact class already has a method that enables that and which you could use. Another alternative is a search facility based on one or more parameters such as e-mail, name, and so on.

Either way you’ll need to edit the YourContacts.aspx page. Currently when it displays contacts in the GridView control it just shows all. The Contact class already has a function that takes the first letter of the surname as a parameter. However, at the moment it’s optional and the current code doesn’t make use of it. By adding a drop-down list with A to Z, you could then use that to pass the surname’s first letter as a parameter.

You’ll then need to let the ObjectDataSource control know about the new parameter. If you’ve called your list box DropDownBox1 then to your ObjectDataSource mark up you’d need to add:

<asp:ControlParameter ControlID=”DropDownList1” Name=”FirstLetterOfSurname” PropertyName=”SelectedValue” Type=”Char” />

Now only the contacts with surname specified in the drop down list will be displayed.

A few more improvements could be:

Capability to upload and store photos of contacts.

Capability to specify which of your contacts will be attending an event.

Storing details like contacts’ birthdays and having automatic reminders.

Having automatic reminders for events e-mailed to you.

Adding cell phone text messaging support allowing you to send e-mails or text messages to contacts.

2

Modifying the Wrox

File Share

Although the Wrox File Share is a great starter application for learning ASP.NET 2.0, it likely does not contain all of the features you might want to see. Some possible enhancements to the Wrox File Share could include:

Management Capabilities: It would be nice to be able to see which files are on the server, how many times they have been accessed, and so forth. Maybe even the ability to delete the file if it is not being accessed or is getting old.

Reporting: It would be great to have some prepared reports about resources, their responses, and percentages for each.

Additional E-mail: The sender of the file may wish to receive an e-mail indicating that the user has downloaded the file that was sent.

Site Counters: The ability to track the number of hits to the site, including the number of times the file is downloaded.

If you want to take on one of these features, the sending of an additional e-mail, the following steps would be required:

1.In Visual Web Developer or Visual Studio 2005, open the website from its extracted location at C:\inetpub\wwwroot. Open the Database Explorer by selecting the View DataBase Explorer from the menu. Find your database under the Database Connections node of the TreeView. If your database is not listed, right-click the Data Connections node, select the Add Connection option, select the Microsoft SQL Server File option, and browse to the FileShareDB.mdf file in the App_Data folder of the site. This should bring up your connection within the Database Explorer window. Now that you have a valid database tree, expand it to see the Stored Procedures folder. Right-click the folder and select the Add New Stored Procedure option.

Chapter 2

2.Add the following new stored procedure:

CREATE

PROCEDURE dbo.sprocResourceSelectEmailInfo

/*

‘===============================================================

NAME:

sprocResourceSelectEmailInfo

DATE CREATED:

October 27, 2005

CREATED BY:

Shawn Livermore (shawnlivermore.blogspot.com)

CREATED FOR:

ASP.NET 2.0 - Instant Results

FUNCTION:

Gets a specific resource’s sender email information from

the DB

 

 

‘===============================================================

*/

 

 

(@id int)

 

as

 

 

SELECT dbo.Contact.email

 

FROM

dbo.Contact INNER JOIN

 

dbo.Resource ON dbo.Contact.id = dbo.Resource.fromContactID

WHERE (dbo.Resource.id = @id)

This new stored procedure, sprocResourceSelectEmailInfo, will provide the e-mail address of the sender for a specific resource file.

3.Expand the App_Code folder, and then expand the Dal folder to view the EmaiContentDB.vb class file. In this class, you must add a new function, GetEmailSenderForResource, which will execute the stored procedure you just created. This function will also have the integer parameter of resourceID, and return a string value for the sender’s e-mail address.

The text of this function is as follows:

‘’’ <summary>

‘’’ Gets the email address for the sender of a file from the database ‘’’ </summary>

Public Shared Function GetEmailSenderForResource(ByVal resourceID As Integer) As String

Dim mSender As String = “”

Try

Using mConnection As New SqlConnection(Config.ConnectionString) Dim mCommand As SqlCommand = New SqlCommand( _

“sprocResourceSelectEmailInfo”, mConnection) mCommand.CommandType = CommandType.StoredProcedure mCommand.Parameters.AddWithValue(“@id”, resourceID) mConnection.Open()

Using mDataReader As SqlDataReader = _ mCommand.ExecuteReader(CommandBehavior.CloseConnection) If mDataReader.Read() Then

mSender = mDataReader.GetString( _ mDataReader.GetOrdinal(“email”))

End If mDataReader.Close()

End Using End Using

Catch ex As Exception

4

Modifying the Wrox File Share

‘By calling the “Throw” statement, you are raising the error to the ‘global.asax file, which will use the default error handling page to ‘process/display the custom error to the user

Throw

End Try

Return mSender

End Function

4.In the App_Code folder within the Bll subfolder, open the EmailContent.vb class file. Add a new function to this class, named GetEmailSenderForResource. This function will also have the integer parameter of resourceID, and return a string value for the sender’s e-mail address.

The following is the contents of GetEmailSenderForResource:

‘’’ <summary>

‘’’ Gets the email address for the sender of a file from the database ‘’’ </summary>

Public Shared Function GetEmailSenderForResource(ByVal resourceID As Integer) As String

Return EmailContentDB.GetEmailSenderForResource(resourceID) End Function

5.Open the Download.aspx page and press F7 to open the code-behind file, Download.aspx.cs. You can also right click the Download.aspx page and select the View Code option from the menu. Within this page, add some logic, displayed below, to send the e-mail to the original sender. This logic must occur within the Try-Catch block of the DisplayDownloadDialog function. This functionality will capture the resourceID querystring variable, and use it to query the database and extract the sender’s e-mail address.

Dim resourceID As Integer = Request.QueryString(“resourceID”)

Dim senderEmail As String = EmailContent.GetEmailSenderForResource( _ resourceID)

Dim emailBody As String = “Your file was downloaded at “ & _ System.DateTime.Today.ToLongDateString

Utilities.SendEmail(senderEmail, Config.EmailFrom, _ “Your file was downloaded”, emailBody)

Now that you have implemented a simple enhancement, your understanding of the application’s architecture is probably much stronger. You have seen and developed within the layered approach to the design. This will allow you to move quickly to add more functionality to the application, or write one of your own.

5