📄 orderprocess.aspx.cs
字号:
#region 新增付款方式中修改OrderProcess窗体参考答案及评分细则
/* ********************************************************************************************************************
主题:新增付款方式中修改OrderProcess窗体评分细则.
作者:
时间:
分值:20分
细则:
1、修改OrderProcess窗体中信用卡信息显示.....................8分
2、控制OrderProcess页面信用卡信息显示.......................8分
3、修改字符串xml,加上送货方式ID和送货费用信息...............4分
* *********************************************************************************************************************/
#endregion
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Diagnostics;
using PetShop.Components;
namespace PetShop.Web
{
/// <summary>
/// Process the order and display summary.
/// </summary>
public partial class OrderProcess : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label lblShipAdr1;
protected System.Web.UI.WebControls.Label lblShipAdr2;
protected System.Web.UI.WebControls.Label lblShipCity;
protected System.Web.UI.WebControls.Label lblShipState;
protected System.Web.UI.WebControls.Label lblShipPostalCode;
protected System.Web.UI.HtmlControls.HtmlTable tblShowOrderInformation;
public OrderProcess()
{
Page.Init += new System.EventHandler(Page_Init);
}
protected void Page_Load(object sender, System.EventArgs e)
{
// make sure we really have items in the cart
ShoppingCart cart = (ShoppingCart)Session["ShoppingCartSession"];
if (cart.Count == 0)
Response.Redirect("Cart.aspx");
#region 显示送货方式
//show DeliveryMethodName
lblDeliveryMethod.Text=GetDeliveryMethodName();
#endregion
// We have to use a manual datagrid instead of the cart user control
// since the usercontrol displays the content of the shoppingcart
// session object... but its Load event is called after all of the
// Page events are called. By the time the usercontrol's Load event
// is called, the shoppingcart session object is empty.
#region 控制OrderProcess页面dataGrid显示
Hashtable adr = (Hashtable)Session["ShoppingAddressSession"];
if(Convert.ToInt32(adr["AdditionalCharge"])==0)
{
dataGrid.Columns[0].FooterText="Total:";
dataGrid.Columns[1].FooterText="";
dataGrid.Columns[2].FooterText="";
}
else
{
dataGrid.Columns[1].FooterText=Convert.ToDouble(adr["AdditionalCharge"]).ToString("c");
}
dataGrid.Columns[4].FooterText=(cart.Total+Convert.ToDouble(adr["AdditionalCharge"])).ToString("c");
dataGrid.DataSource = cart.GetItems();
dataGrid.DataBind();
#endregion
// determine who is logged in
Debug.Assert(Request.Cookies["CustomerID"] != null);
string userID = (string)Request.Cookies["CustomerID"].Value;
// add order to database
DateTime orderDate = DateTime.Now;
int orderID = AddOrder(userID, orderDate.ToString());
// hook up results
lblDate.Text = orderDate.ToLongDateString();
lblAccount.Text = userID;
lblOrderID.Text = orderID.ToString();
lblStatus.Text = "P";
// credit card
Debug.Assert(adr != null);
lblCardType.Text = (string)adr["CardType"];
lblCardNumber.Text = (string)adr["CardNumber"];
lblCardDate.Text = (string)adr["CardExpireMonth"] + "/" + (string)adr["CardExpireYear"];
#region 控制信用卡信息显示
//hide the Credit Information if payment type is check
if(adr["PaymentType"].ToString()!=PaymentTypes.Credit.ToString())
{
lblCreditCard.Text="Payment Type";
lblCardType.Text=adr["PaymentType"].ToString();
lblCardNumber.Visible=false;
lblCardDate.Visible=false;
}
#endregion
// clear shopping cart
cart.ClearCart();
ControlDeliveryAddress();
}
private void ControlDeliveryAddress()
{
Hashtable adr = (Hashtable)Session["ShoppingAddressSession"];
int id=Convert.ToInt32(adr["DeliveryMethodID"]);
bool showdeliveryaddress=new PetShop.Components.DeliveryMethod().GetDeliveryMethodShowDeliveryAddress(id);
// chkUseBillingAddress.Visible=showdeliveryaddress;
this.Shippingaddress.Visible=showdeliveryaddress;
}
// add order to database
private int AddOrder(string userID, string orderDate)
{
// get shopping cart
ShoppingCart cart = (ShoppingCart)Session["ShoppingCartSession"];
Debug.Assert(cart != null);
// create xml doc to pass down to stored proc, this xml doc contains
// one main <Orders> section and multiple <LineItems> sections
string xml = "<Orders " + GetOrdersXML(userID, orderDate) + ">" +
cart.GetLineItemsXML() + "</Orders>";
// add this order to the database, get the new order id back
Order order = new Order();
int id = order.Add(xml);
return id;
}
// returns the attriubutes for the Orders xml section
private string GetOrdersXML(string userID, string orderDate)
{
// use session objects to create xml string
Hashtable adr = (Hashtable)Session["ShoppingAddressSession"];
Debug.Assert(adr != null);
ShoppingCart cart = (ShoppingCart)Session["ShoppingCartSession"];
Debug.Assert(cart != null);
// total price
string totalPrice = (cart.Total+Convert.ToDouble(adr["AdditionalCharge"])).ToString();
//
string paymenttype=((int)(PaymentTypes)Enum.Parse(typeof(PaymentTypes),adr["PaymentType"].ToString(),true)).ToString();
// create attribute string
string xml = "userid='" + userID +
"' orderdate='" + orderDate +
"' shiptofirstname='" + adr["Ship_FirstName"] +
"' shiptolastname='" +adr["Ship_LastName"] +
"' shipaddr1='" + adr["Ship_Address1"] +
"' shipaddr2='" + adr["Ship_Address2"] +
"' shipcity='" + adr["Ship_City"] +
"' shipstate='" + adr["Ship_State"] +
"' shipzip='" + adr["Ship_PostalCode"] +
"' shipcountry='" + adr["Ship_Country"] +
"' billtofirstname='" + adr["Bill_FirstName"] +
"' billtolastname='" +adr["Bill_LastName"] +
"' billaddr1='" + adr["Bill_Address1"] +
"' billaddr2='" + adr["Bill_Address2"] +
"' billcity='" + adr["Bill_City"] +
"' billstate='" + adr["Bill_State"] +
"' billzip='" + adr["Bill_PostalCode"] +
"' billcountry='" + adr["Bill_Country"] +
"' creditcard='" + adr["CardNumber"] +
"' exprdate='" + adr["CardExpireMonth"] + "/" + adr["CardExpireYear"] +
"' cardtype='" + adr["CardType"] +
"' courier='UPS" +
"' totalprice='" + totalPrice +
"' locale='US_en"+
"' PaymentType='"+paymenttype+ //付款方式
"' DeliveryMethodID='"+adr["DeliveryMethodID"]+ //送货方式ID
"' AdditionalCharge='"+adr["AdditionalCharge"]+ //送货费用
"' CheckNumber='"+adr["CheckNumber"]+"'"; //支票号
return xml;
}
protected void Page_Init(object sender, EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
}
#region 函数GetDeliveryMethodName()
//function of getting DeliverSpeed Name
private string GetDeliveryMethodName()
{
Hashtable adr = (Hashtable)Session["ShoppingAddressSession"];
int id=Convert.ToInt32(adr["DeliveryMethodID"]);
string delivername=new PetShop.Components.DeliveryMethod().GetDeliveryMethodName(id);
return delivername;
}
#endregion
#region Web Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
}
#endregion
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -