📄 mycars.aspx
字号:
String sProcName = "ConvertToOrder";
String sMessage;
SqlConnection sqlConn = new SqlConnection(sConnect);
SqlCommand sqlComm = new SqlCommand(sProcName, sqlConn);
sqlComm.CommandType = CommandType.StoredProcedure;
sqlComm.Parameters.Add("@QuoteOrderID", iOrderID);
try {
sqlConn.Open();
if (sqlComm.ExecuteNonQuery() == 1) {
// update to an order from a quote succeeded
// get DataSet with updated values and display them
dsDetails = GetUserDetailsDS();
DisplayUserVehicles(dsDetails);
// send email confirmation of order
SendEmailConfirmation(sOrderID);
sMessage = "<p>Thank you for placing your order. An email confirmation<br />"
+ "has been sent to you with delivery and payment details.</p>";
}
else {
sMessage = "* Sorry, this quotation could not be located.";
}
}
catch (Exception e) {
sMessage = "* Sorry, the database could not be accessed.";
}
finally {
sqlConn.Close();
}
// display message in Label on page
lblMessage.Text = sMessage;
}
// --------------------------------------------------
// routine to send email confirmation of placing an order
void SendEmailConfirmation(String sOrderID) {
try {
// build parts of message as strings
// get user details from single row of UserDetail table in DataSet
DataRow drDetails = dsDetails.Tables["UserDetail"].Rows[0];
String sUser = "Name: " + drDetails["UserName"] + (char)13 + (char)10
+ "Address: " + drDetails["Address"] + (char)13 + (char)10
+ "City: " + drDetails["City"] + (char)13 + (char)10
+ "State: " + drDetails["State"] + (char)13 + (char)10
+ "Country: " + drDetails["Country"] + (char)13 + (char)10
+ "Phone: " + drDetails["Phone"] + (char)13 + (char)10
+ "Email: " + drDetails["Email"] + (char)13 + (char)10;
// create a criteria and select the matching row in the Orders table
// in the DataSet, then extract order details
String sFind = "QuoteOrderID = " + sOrderID;
DataRow[] arrOrders = dsDetails.Tables["Orders"].Select(sFind);
DataRow drOrder = arrOrders[0];
DateTime dDate = (DateTime)drOrder["OrderDate"];
String sOrder = "Order #" + drOrder["QuoteOrderID"] + " placed on "
+ dDate.ToString("dd MMM yyyy") + (char)13 + (char)10;
String sModel = "Model: The Xrox " + drOrder["CarName"] + (char)13 + (char)10
+ "Engine: " + drOrder["EngineName"] + (char)13 + (char)10
+ "Color: " + drOrder["ColorName"] + (char)13 + (char)10;
// select the matching rows in the OrderLines table
// in the DataSet, then extract "extras" details
Decimal fPrice, fInterest, fPayment;
arrOrders = dsDetails.Tables["OrderLines"].Select(sFind);
if (arrOrders.Length > 0) {
sModel += "Optional extras included in your order:" + (char)13 + (char)10;
foreach (DataRow drOrderLine in arrOrders) {
fPrice = (Decimal)drOrderLine["ExtraPrice"];
sModel += "* " + drOrderLine["ExtraName"] + " ($"
+ fPrice.ToString("F2") + ")" + (char)13 + (char)10;
}
}
fPrice = (Decimal)drOrder["TotalPrice"];
String sPrice = "Total Price including extras and finance charges: $"
+ fPrice.ToString("#,##0.00") + (char)13 + (char)10;
if ((int)drOrder["PaymentMonths"] > 0) {
fPrice = (Decimal)drOrder["BasePrice"];
fInterest = (Decimal)drOrder["Interest"];
fPayment = (Decimal)drOrder["PaymentAmount"];
sPrice += "Basic price: $" + fPrice.ToString("#,##0.00")
+ " plus $" + fInterest.ToString("#,##0.00")
+ " interest." + (char)13 + (char)10 + "Terms: "
+ drOrder["PaymentMonths"].ToString() + " monthly payments of $"
+ fPayment.ToString("#,##0.00") + (char)13 + (char)10;
}
String sMessage = "Thank you for placing your order with the "
+ "Xrox Car Company." + (char)13 + (char)10 + (char)13 + (char)10
+ "Your order details are:" + (char)13 + (char)10 + (char)13 + (char)10
+ sOrder + (char)13 + (char)10 + sUser + (char)13 + (char)10
+ sModel + (char)13 + (char)10 + sPrice + (char)13 + (char)10
+ "We will contact you as soon as your vehicle "
+ "is ready for delivery and arrange payment "
+ "and shipping details." + (char)13 + (char)10 + (char)13 + (char)10
+ "NOTE: Xrox Cars are a fictitious organization "
+ "designed only to promote the Dave And Al book "
+ "Al's ASP.NET WebForms Cookbook. "
+ "For more details see http://www.daveandal.com/books/7868/";
// use ASCX control in root folder of application to send the message
// the .NET MailMessage object is not always reliable when called from
// a page in a folder that is not configured as a virtual application
ctlMail.FromAddress = ConfigurationSettings.AppSettings["XroxCarsWebmasterEmail"];
ctlMail.ToAddress = drDetails["Email"].ToString();
ctlMail.MessageSubject = "Xrox Car Company Order Confirmation";
ctlMail.MessageBody = sMessage;
ctlMail.SendEmail();
}
catch (Exception e) {
}
}
// --------------------------------------------------
</script>
<!doctype html public "-//IETF//DTD HTML 3.2 Final//EN">
<html>
<head>
<basefont size="2" face="Tahoma,Arial,Helvetica,sans-serif">
<link rel="stylesheet" type="text/css" href="../stylesheets/wcc<% = sStyleSize %>.css" />
<title>Xrox Car Company - My Cars</title>
</head>
<body bgcolor="#ffffff" class="body-text"><div style="position:absolute;height:0px;"><font size="1" color=#ffffff">
<!-- skip link for aural page readers -->
<layer visibility="hidden">
<a href="#content" style="color:#ffffff;font-size:1px;text-decoration:none"><img width="1" height="1" hspace="0" vspace="0" src="../images/_blnk.gif" border="0" alt="Skip to Content" /></a>
</layer>
</font></div>
<form runat="server">
<table width="100%" border="0" cellspacing="0" cellpadding="10">
<tbody>
<tr>
<td valign="top" width="110px">
<a Title="Back to List of Models" href="../home.aspx">
<img src="../images/btn_home.gif" width="100" height="49" hspace="3" vspace="2" alt="Home Page" border="0" /></a>
</td>
<td align="left">
<!-- user's name/address details and Log Off button -->
<table border="0" width="95%">
<tr><td align="left"><a name="content" />
<font face="Arial,Helvetica,sans-serif" size="4" color="#b50055"><b>
<asp:Label id="lblHeading" CssClass="large-red-text" runat="server" /></b></font><p />
<font face="Tahoma,Arial,Helvetica,sans-serif" size="2">
<asp:Label id="lblDetail" CssClass="body-text" runat="server" />
</font></td><td align="right" valign="bottom">
<font face="Tahoma,Arial,Helvetica,sans-serif" size="2">
<input type="submit" Value="Log Off" runat="server" OnServerClick="DoSignOut"
title="Log off and cancel automatic logon for this site" />
</font></td></tr>
</table>
<!-- message for feedback when placing an order -->
<font face="Arial,Helvetica,sans-serif" size="4" color="#b50055"><b>
<asp:Label id="lblMessage" CssClass="large-red-text"
EnableViewState="False" runat="server" /></b></font>
<!-- caption for list of quotes -->
<asp:Label id="lblQuotesHeading" CssClass="large-red-text"
Visible="False" EnableViewState="False"
runat="server"><hr size="1" />
<font face="Arial,Helvetica,sans-serif" size="4" color="#b50055">
<b>Your Quotations for New Vehicles:</b>
</asp:Label></font><p />
<!-- list of quotes -->
<asp:Repeater id="repQuotes" runat="server"
OnItemDataBound="QuotesListDatabound" OnItemCommand="PlaceOrder">
<HeaderTemplate>
<table border="0" cellpadding="7" cellspacing="7">
</HeaderTemplate>
<ItemTemplate>
<tr>
<td valign="top">
<asp:Image runat="server" hspace="10"
ImageUrl='<%# DataBinder.Eval(Container.DataItem, "CarName", "../images/{0}150.gif") %>'
ToolTip='<%# DataBinder.Eval(Container.DataItem, "CarName", "The Xrox {0}") %>' /></td>
<td valign="top"><font face="Arial,Helvetica,sans-serif" size="3">
<b>The Xrox <%# DataBinder.Eval(Container.DataItem, "CarName") %>
<%# DataBinder.Eval(Container.DataItem, "EngineName") %> in
<%# DataBinder.Eval(Container.DataItem, "ColorName") %></b></font><br />
<font face="Tahoma,Arial,Helvetica,sans-serif" size="2">
Quotation #<b><asp:Label id="lblOrderID"><%# DataBinder.Eval(Container.DataItem, "QuoteOrderID") %></asp:Label></b>
on <b><%# DataBinder.Eval(Container.DataItem, "OrderDate", "{0:dd MMM yyyy}") %></b><br />
<!-- list of extras for each vehicle -->
<asp:Repeater id="repQuoteLines" runat="server">
<ItemTemplate>
* <%# DataBinder.Eval(Container.DataItem, "ExtraName") %>
($<%# DataBinder.Eval(Container.DataItem, "ExtraPrice", "{0:#,##0.00}") %>)<br />
</ItemTemplate>
</asp:Repeater>
<b>Total price</b> (including extras and finance charges):
<b>$<%# DataBinder.Eval(Container.DataItem, "TotalPrice", "{0:#,##0.00}") %></b><br />
<asp:Label id="lblFinance" Visible="False" runat="server">
Basic price $<%# DataBinder.Eval(Container.DataItem, "BasePrice", "{0:#,##0.00}") %> plus
$<%# DataBinder.Eval(Container.DataItem, "Interest", "{0:#,##0.00}") %> interest.<br />
Terms: <%# DataBinder.Eval(Container.DataItem, "PaymentMonths") %> monthly payments of
$<%# DataBinder.Eval(Container.DataItem, "PaymentAmount", "{0:#,##0.00}") %></asp:Label>
<p><asp:Button id="cmdOrder" Text="Order now!" runat="server"
ToolTip="Place an order for this vehicle now"
CommandName='<%# DataBinder.Eval(Container.DataItem, "QuoteOrderID") %>' /></p></font></td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
<!-- caption for list of orders -->
<asp:Label id="lblOrdersHeading" CssClass="large-red-text"
Visible="False" EnableViewState="False"
runat="server"><hr size="1" />
<font face="Arial,Helvetica,sans-serif" size="4" color="#b50055">
<b>Vehicles You Already Own:</b>
</asp:Label></font><p />
<!-- list of orders -->
<asp:Repeater id="repOrders" runat="server"
OnItemDataBound="OrdersListDatabound">
<HeaderTemplate>
<table border="0" cellpadding="7" cellspacing="7">
</HeaderTemplate>
<ItemTemplate>
<tr>
<td valign="top">
<asp:Image runat="server" hspace="10"
ImageUrl='<%# DataBinder.Eval(Container.DataItem, "CarName", "../images/{0}150.gif") %>'
ToolTip='<%# DataBinder.Eval(Container.DataItem, "CarName", "The Xrox {0}") %>' /></td>
<td valign="top"><font face="Arial,Helvetica,sans-serif" size="3">
<b>The Xrox <%# DataBinder.Eval(Container.DataItem, "CarName") %>
<%# DataBinder.Eval(Container.DataItem, "EngineName") %> in
<%# DataBinder.Eval(Container.DataItem, "ColorName") %></b></font><br />
<font face="Tahoma,Arial,Helvetica,sans-serif" size="2">Order #<b><%# DataBinder.Eval(Container.DataItem, "QuoteOrderID") %></b>
Ordered on <b><%# DataBinder.Eval(Container.DataItem, "OrderDate", "{0:dd MMM yyyy}") %></b><br />
<!-- list of extras for each vehicle -->
<asp:Repeater id="repOrderLines" runat="server">
<ItemTemplate>
* <%# DataBinder.Eval(Container.DataItem, "ExtraName") %>
($<%# DataBinder.Eval(Container.DataItem, "ExtraPrice", "{0:#,##0.00}") %>)<br />
</ItemTemplate>
</asp:Repeater>
<b>Total price</b> (including extras and finance charges):
<b>$<%# DataBinder.Eval(Container.DataItem, "TotalPrice", "{0:#,##0.00}") %></b><br />
</font></td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
</font>
<hr size="1" />
<font size="1" face="Arial,Helvetica,sans-serif">
<a href="../home.aspx" title="Home Page">Home</a>
<font size="1" face="Arial,Helvetica,sans-serif">©2002 <a href="http://www.daveandal.net/" title="Dave And Al">Dave And Al</a>
UK and USA. Contact:
<asp:Hyperlink id="lnkWebmaster" runat="server" title="Support Email Address" /></font>
</td>
</tr>
</tbody>
</table>
</form>
<!-- control containing the routine to send email messages -->
<wcc:sendmail id="ctlMail" runat="server" />
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -