Пример #1
0
        protected void ButtonConfirm_Click(object sender, EventArgs e)
        {
            //删除所有购物车明细,创建订单,创建订单明细。
            //一个字符串对象,保存用户名
            String userName = ((Site1)Page.Master).CurrentUserName;
            if (userName.Equals(""))
                return;
            if (TextBox1.Text.Trim().Length == 0
                || TextBox2.Text.Trim().Length == 0
                || TextBox3.Text.Trim().Length == 0
                || TextBox4.Text.Trim().Length == 0)
            {
                Response.Write("<script>alert('请输入所有资料');</script>");
            }
            String ReciverName = TextBox1.Text.Trim();
            String Address = TextBox2.Text.Trim();
            String Phone = TextBox3.Text.Trim();
            String PostCode = TextBox4.Text.Trim();
            using (LiBoClothesShopEntities context = new LiBoClothesShopEntities())
            {
                OrderInfo myOrder = new OrderInfo();
                myOrder.Consignee = ReciverName;
                myOrder.Address = Address;
                myOrder.Phone = Phone;
                myOrder.Zip = PostCode;
                myOrder.CreateTime = DateTime.Now;
                myOrder.PaymentTime = DateTime.Now;
                myOrder.SendTime = null;
                myOrder.ReceiptTime = null;
                myOrder.UserName = ((Site1)Page.Master).CurrentUserName;
                context.AddToOrderInfoes(myOrder);
                context.SaveChanges();
                var cartDetails = from p in context.CartDetails
                                  where p.CartInfo.UserName == ((Site1)Page.Master).CurrentUserName
                                  select p;
                foreach (CartDetail cartDetail in cartDetails)
                {
                    OrderDetail orderDetail = new OrderDetail()
                    {
                        OrderId = myOrder.ID,
                        ClothesId = cartDetail.ClothId.Value,
                        QTY = cartDetail.QTY,
                        UnitPrice = cartDetail.Cloth.Price,
                        SizeId = cartDetail.SizeId.Value,
                        ColorId = cartDetail.ColorId.Value
                    };
                    myOrder.OrderDetails.Add(orderDetail);
                    context.CartDetails.DeleteObject(cartDetail);
                }

                context.SaveChanges();
                //新建一个OrderInfo类,即创建一个订单
                Response.Redirect(String.Format("~/ViewOrderDetail.aspx?ID={0}", myOrder.ID));
            }
        }
Пример #2
0
 /// <summary>
 /// Deprecated Method for adding a new object to the OrderInfoes EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToOrderInfoes(OrderInfo orderInfo)
 {
     base.AddObject("OrderInfoes", orderInfo);
 }
Пример #3
0
 /// <summary>
 /// Create a new OrderInfo object.
 /// </summary>
 /// <param name="id">Initial value of the ID property.</param>
 /// <param name="userName">Initial value of the UserName property.</param>
 /// <param name="consignee">Initial value of the Consignee property.</param>
 /// <param name="address">Initial value of the Address property.</param>
 /// <param name="phone">Initial value of the Phone property.</param>
 /// <param name="zip">Initial value of the Zip property.</param>
 /// <param name="createTime">Initial value of the CreateTime property.</param>
 /// <param name="paymentTime">Initial value of the PaymentTime property.</param>
 public static OrderInfo CreateOrderInfo(global::System.Int32 id, global::System.String userName, global::System.String consignee, global::System.String address, global::System.String phone, global::System.String zip, global::System.DateTime createTime, global::System.DateTime paymentTime)
 {
     OrderInfo orderInfo = new OrderInfo();
     orderInfo.ID = id;
     orderInfo.UserName = userName;
     orderInfo.Consignee = consignee;
     orderInfo.Address = address;
     orderInfo.Phone = phone;
     orderInfo.Zip = zip;
     orderInfo.CreateTime = createTime;
     orderInfo.PaymentTime = paymentTime;
     return orderInfo;
 }
Пример #4
0
        protected void Page_Load(object sender, EventArgs e)
        {
            //加载页面时
            int userType = ((Site1)Page.Master).CurrentUserType;
            if (userType == UserType.Admin)
            {
                Button1.Visible = true;
                Button2.Visible = false;
            }
            else if (userType == UserType.RegUser)
            {
                Button1.Visible = false;
                Button2.Visible = true;
            }
            else
            {
                Button1.Visible = false;
                Button2.Visible = false;
            }
            if (!IsPostBack)
            {
                //如果是第一次加载
                String userName = ((Site1)Page.Master).CurrentUserName;
                if (userName.Equals(""))
                    return;
                //从url中读取订单号
                int id = Convert.ToInt32(Request.QueryString["id"]);
                using (LiBoClothesShopEntities context = new LiBoClothesShopEntities())
                {
                    //查询出该订单
                    var order = (from orderInfo in context.OrderInfoes
                                 where orderInfo.ID == id
                                 select orderInfo).FirstOrDefault();
                    //查询出该订单的订单明细
                    var query2 = from orderDetail in order.OrderDetails
                                 select new
                                 {
                                     Id = orderDetail.ClothesId,
                                     ProductName = orderDetail.Cloth.Name,
                                     Quantity = orderDetail.QTY,
                                     Size = orderDetail.SizeInfo.Name,
                                     Color = orderDetail.ColorInfo.Name,
                                     UnitPrice = orderDetail.UnitPrice,
                                     SubTotal = orderDetail.QTY * orderDetail.UnitPrice
                                 };
                    //GridView1的数据源为查询结果
                    GridView1.DataSource = query2;
                    //绑定数据源
                    GridView1.DataBind();
                    CurrentOrder = order;
                    //计算总价
                    order.TotalPrice = (from p in query2 select p.SubTotal).Sum();

                    Label1.Text = order.Consignee;
                    Label2.Text = order.Address;
                    Label3.Text = order.Phone;
                    Label4.Text = order.Zip;
                    Label5.Text = order.CreateTime.ToString();
                    if (order.PaymentTime != null)
                        Label6.Text = order.PaymentTime.ToString();
                    else
                        Label6.Text = "未付款";
                    if (order.SendTime != null)
                        Label7.Text = order.SendTime.Value.ToString();
                    else
                        Label7.Text = "未发货";
                    if (order.ReceiptTime != null)
                        Label8.Text = order.ReceiptTime.Value.ToString();
                    else
                        Label8.Text = "未收货";
                    Label9.Text = ((Site1)Page.Master).PriceFormater(order.TotalPrice.Value);

                }
            }
        }