📄 commitorderform.aspx.cs
字号:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Linq;
using System.Data.Linq;
using System.Collections.Generic;
public partial class DesktopModules_OrderForm_CommitOrderForm : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
///获取购物车的信息
ShowShoppingCartInfo();
}
}
private void ShowShoppingCartInfo()
{
///判定购物车中是否存在数据
if (Session[Session.SessionID + ASPNET35System.ShoppingCart] == null)
{
Message.Visible = true;
return;
}
///绑定购物车的数据,显示购物车信息
OrderFormInformation order = (OrderFormInformation)Session[Session.SessionID + ASPNET35System.ShoppingCart];
gvOrderForm.DataSource = order.OrderItemList;
gvOrderForm.DataBind();
///不显示提示信息
Message.Visible = false;
}
protected void CheckShopCart_Click(object sender, EventArgs e)
{
///保存订单信息到数据库中
if (Session[Session.SessionID + ASPNET35System.ShoppingCart] == null)
{
return;
}
///获取购物车的信息
OrderFormInformation order = (OrderFormInformation)Session[Session.SessionID + ASPNET35System.ShoppingCart];
OrderFormM orderform = new OrderFormM();
///添加订单信息到数据库中
int nOrderFormID = orderform.AddOrderForm(Int32.Parse(Session["UserID"].ToString()),
order.TotalNumber,
order.TotalMoney);
if (nOrderFormID > -1)
{
///添加订单中的每一个子项
OrderItemM orderItem = new OrderItemM();
foreach (OrderItemInformation item in order.OrderItemList)
{
orderItem.AddOrderItem(item.BookID, item.Number,nOrderFormID);
}
}
///显示提示信息
Response.Write("<script>alert(\"结帐成功!!!\")</script>");
CheckOut.Text = "你这次购物总共" + order.TotalNumber.ToString() + "件,总消费金额为:" + order.TotalMoney.ToString() + "元。";
}
protected void AddBookBtn_Click(object sender, EventArgs e)
{
Response.Redirect("~/DesktopModules/Book/BrowserBook.aspx");
}
protected void gvOrderForm_RowCommand(object sender,GridViewCommandEventArgs e)
{
///保存订单信息到数据库中
if(Session[Session.SessionID + ASPNET35System.ShoppingCart] == null)
{
return;
}
///删除购物车中的书籍
if(e.CommandName.ToLower() == "delete")
{
///获取购物车的信息
OrderFormInformation order = (OrderFormInformation)Session[Session.SessionID + ASPNET35System.ShoppingCart];
order.OrderItemList.RemoveAt(Int32.Parse(e.CommandArgument.ToString()));
///重新绑定购物车的数据
ShowShoppingCartInfo();
}
}
protected void gvOrderForm_RowDataBound(object sender,GridViewRowEventArgs e)
{
///为删除按钮添加确认对话框
ImageButton deleteBtn = (ImageButton)e.Row.FindControl("DeleteBook");
if(deleteBtn != null)
{
deleteBtn.Attributes.Add("onclick","return confirm('" + ASPNET35System.OPERATIONDELETEMESSAGE + "');");
}
}
protected void gvOrderForm_RowCreated(object sender,GridViewRowEventArgs e)
{
if(e.Row.RowType == DataControlRowType.DataRow)
{
ImageButton deleteBtn = (ImageButton)e.Row.FindControl("DeleteBook");
if(deleteBtn != null)
{
deleteBtn.CommandArgument = e.Row.RowIndex.ToString();
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -