|
抱歉!造成您的困擾。C# 程式碼如下: protected void DetailsView1_Inserting(Object sender, DetailsViewInsertEventArgs e) { SqlDataSource1.InsertParameters["SubTotal"].DefaultValue = lblSubTotal.Text; SqlDataSource1.InsertParameters["Shipping"].DefaultValue = "100"; SqlDataSource1.InsertParameters["GrandTotal"].DefaultValue = Convert.ToString(Convert.ToInt32(lblSubTotal.Text) + 100); } protected void DetailsView1_Inserted(Object sender, DetailsViewInsertedEventArgs e) { SqlDataSource ads = new System.Web.UI.WebControls.SqlDataSource(); ConnectionStringSettings settings = ConfigurationManager.ConnectionStrings["shopConnectionString"]; String conn = settings.ConnectionString; ads.ConnectionString = conn; ads.SelectCommand = "SELECT * FROM [Orders] ORDER BY [OrderID] DESC"; DataView dv = (DataView)ads.Select(DataSourceSelectArguments.Empty); int Oid = Convert.ToInt32(dv[0]["OrderID"]); String CMail = Convert.ToString(dv[0]["CustomerEmail"]); int i; for(i=0;i<=GridView1.Rows.Count-1;i++) { ads.InsertCommand = "INSERT INTO [OrderDetail] ([OrderID], [ProductID], [ProductName], [UnitPrice], [Quantity]) VALUES (@OrderID, @ProductID, @ProductName, @UnitPrice, @Quantity)"; ads.InsertParameters.Add("OrderID", Convert.ToString(Oid)); ads.InsertParameters.Add("ProductID", Convert.ToString(GridView1.Rows[i].Cells[1].Text)); ads.InsertParameters.Add("ProductName", Convert.ToString(GridView1.Rows[i].Cells[2].Text)); ads.InsertParameters.Add("UnitPrice", Convert.ToString(GridView1.Rows[i].Cells[3].Text)); ads.InsertParameters.Add("Quantity", Convert.ToString(GridView1.Rows[i].Cells[4].Text)); ads.Insert(); ads.InsertParameters.Clear(); } String mailContent = "<p>感謝您的光臨,您已經成功的完成訂購程序。</p><p>我們將儘快把您選購的商品郵寄給您! 再次感謝您支持。</p><p>您的訂單編號為:" + Oid + ",您可以使用這個編號回到網站中查詢訂單的詳細內容。</p><p align='right'><strong>織夢線上購物網</strong></p>"; MailMessage message = new MailMessage("e-happy@e-happy.com.tw", CMail, "織夢線上購物網訂單通知", mailContent); message.IsBodyHtml = true; SmtpClient emailClient = new SmtpClient("msa.hinet.net", 25); emailClient.Send(message); htChoose.Clear(); Session["allChoose"] = htChoose; Response.Redirect("cartFinish.aspx?OrderId=" + Oid + "&CustomerEmail=" + CMail); } |