Exemplo n.º 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));
            }
        }
Exemplo n.º 2
0
        protected void Button1_Click(object sender, EventArgs e)
        {
            using (LiBoClothesShopEntities context = new LiBoClothesShopEntities())
            {

                //对于表格中的每一行
                foreach (GridViewRow row in GridView1.Rows)
                {
                    int id = Convert.ToInt32(row.Cells[0].Text);
                    ColthColor color = (from p in context.ColthColors
                                 where p.Id == id
                                 select p).FirstOrDefault();
                    FileUpload upload = (FileUpload)row.FindControl("imgupload");

                    if (upload.HasFile)
                    {
                        color.PicFileName = upload.FileName;
                        //将文件上传到Upload目录下
                        upload.SaveAs(Server.MapPath(".\\Upload\\" + color.PicFileName));
                    }

                }
                context.SaveChanges();
                Response.Redirect("~/ViewCloth.aspx?id=" + ProductId);
            }
        }
Exemplo n.º 3
0
 protected void Button1_Click(object sender, EventArgs e)
 {
     String name = TextBox1.Text.Trim();
     decimal price = Convert.ToDecimal(TextBox2.Text.Trim());
     decimal marketprice = Convert.ToDecimal(TextBox3.Text.Trim());
     int qty = Convert.ToInt32(TextBox4.Text.Trim());
     int brandId = Convert.ToInt32(DropDownList1.SelectedValue);
     int genderId = Convert.ToInt32(DropDownList2.SelectedValue);
     int id;
     using (LiBoClothesShopEntities context = new LiBoClothesShopEntities())
     {
         Cloth cloth = new Cloth();
         cloth.Name = name;
         cloth.Price = price;
         cloth.OriginalPrice = marketprice;
         cloth.Qty = qty;
         cloth.BrandId = brandId;
         cloth.GenderId = genderId;
         context.AddToClothes(cloth);
         context.SaveChanges();
         id = cloth.Id;
         foreach (ListItem item in CheckBoxList1.Items)
         {
             if (item.Selected)
             {
                 ClothSzie size = new ClothSzie();
                 size.Cloth = cloth;
                 size.SizeId = Convert.ToInt32(item.Value);
                 context.AddToClothSzies(size);
             }
         }
         context.SaveChanges();
         foreach (ListItem item in CheckBoxList2.Items)
         {
             if (item.Selected)
             {
                 ColthColor color = new ColthColor();
                 color.Cloth = cloth;
                 color.ColorId = Convert.ToInt32(item.Value);
                 context.AddToColthColors(color);
             }
         }
         context.SaveChanges();
     }
     Response.Redirect(String.Format("~/AddClothStep2.aspx?id={0}", id));
 }
Exemplo n.º 4
0
 protected void AddToCartButton_Click(object sender, EventArgs e)
 {
     using (LiBoClothesShopEntities context = new LiBoClothesShopEntities())
     {
         String CurrentUserName = ((Site1)Page.Master).CurrentUserName;
         int colorId = Convert.ToInt32(DropDownListColor.SelectedItem.Value);
         int sizeId = Convert.ToInt32(DropDownListSize.SelectedValue);
         //查找用户是否有购物车
         var query = from cart in context.CartInfoes
                     where cart.UserName == CurrentUserName
                     select cart;
         CartInfo myCart;
         if (query.Count() == 0)
         {
             myCart = new CartInfo()
             {
                 UserName = CurrentUserName,
                 TotalPrice = 0
             };
             context.AddToCartInfoes(myCart);
             context.SaveChanges();
         }
         else
         {
             myCart = query.FirstOrDefault();
         }
         //查找是否已有该购物车明细
         var query1 = from p in context.CartDetails
                      where p.CartInfo.UserName == CurrentUserName
                      && p.ColorId == colorId
                      && p.SizeId == sizeId
                      && p.ClothId == CurrentProduct.Id
                      select p;
         CartDetail myCartDetail;
         if (query1.Count() == 0)
         {
             //如果没有,新增
             myCartDetail = new CartDetail();
             myCartDetail.CartId = myCart.ID;
             myCartDetail.SizeId = sizeId;
             myCartDetail.ColorId = colorId;
             myCartDetail.ClothId = CurrentProduct.Id;
             myCartDetail.QTY = 1;
             context.AddToCartDetails(myCartDetail);
         }
         else
         {
             //如果有,修改数量
             myCartDetail = query1.First();
             myCartDetail.QTY += 1;
         }
         //修改总价
         myCart.TotalPrice += CurrentProduct.Price;
         context.SaveChanges();
     }
 }
Exemplo n.º 5
0
 protected void Button2_Click(object sender, EventArgs e)
 {
     using (LiBoClothesShopEntities context = new LiBoClothesShopEntities())
     {
         //查询出该订单
         var order = (from orderInfo in context.OrderInfoes
                      where orderInfo.ID == CurrentOrder.ID
                      select orderInfo).FirstOrDefault();
         order.ReceiptTime = DateTime.Now;
         context.SaveChanges();
         Response.Redirect("~/Default.aspx");
     }
 }
Exemplo n.º 6
0
 protected void Button1_Click(object sender, EventArgs e)
 {
     String name = TextBox1.Text.Trim();
     using (LiBoClothesShopEntities context = new LiBoClothesShopEntities())
     {
         GenderInfo newObj = new GenderInfo()
         {
             Name = name
         };
         context.AddToGenderInfoes(newObj);
         context.SaveChanges();
         Response.Redirect("~/Default.aspx");
     }
 }
Exemplo n.º 7
0
        protected void Button1_Click(object sender, EventArgs e)
        {
            if (TextBox1.Text.Length == 0
                || TextBox2.Text.Length == 0
                || TextBox3.Text.Length == 0
                || TextBox4.Text.Length == 0
                || TextBox2.Text != TextBox3.Text)
            {
                Response.Write("<script> alert( '注册失败') </script> ");
                return;
            }
            else
            {
                //检查用户名是否存在
                using (LiBoClothesShopEntities context = new LiBoClothesShopEntities())
                {
                    var query = from userInfo in context.UserInfoes
                                where userInfo.UserName == TextBox1.Text
                                select userInfo;
                    if (query.Count() != 0)
                    {
                        Response.Write("<script> alert( '注册失败') </script> ");
                        return;
                    }
                    else
                    {
                        UserInfo newUser = new UserInfo();
                        newUser.UserName = TextBox1.Text;
                        newUser.Password = TextBox2.Text;
                        newUser.Phone = TextBox3.Text;
                        if (Convert.ToInt32(Request.QueryString["Type"]) == 2)
                        {
                            newUser.IsAdmin = true;
                        }
                        else
                        {
                            newUser.IsAdmin = false;
                        }

                        context.AddToUserInfoes(newUser);
                        context.SaveChanges();
                        Response.Write("<script> alert( '注册成功');window.location.href = 'Default.aspx';</script>");
                    }
                }
            }
        }
Exemplo n.º 8
0
 protected void DeleteButton_Click(object sender, EventArgs e)
 {
     using (LiBoClothesShopEntities context = new LiBoClothesShopEntities())
     {
         var query = from p in context.Clothes
                     where p.Id == CurrentProduct.Id
                     select p;
         context.Clothes.DeleteObject(query.FirstOrDefault());
         context.SaveChanges();
     }
     Response.Redirect("~");
 }
Exemplo n.º 9
0
        protected void ResetQuantity()
        {
            String userName = ((Site1)Page.Master).CurrentUserName;
            if (userName.Equals(""))
                return;
            using (LiBoClothesShopEntities context = new LiBoClothesShopEntities())
            {
                decimal totalPrice = 0;
                //对于表格中的每一行
                foreach (GridViewRow row in GridView1.Rows)
                {
                    //获取表格中填的数量
                    int quantity = Convert.ToInt32(((TextBox)row.FindControl("QuantityTextbox")).Text);
                    //获取软件名称
                    string productName = row.Cells[0].Text;
                    string size = row.Cells[1].Text;
                    string color = row.Cells[2].Text;
                    //找到该购物车明细
                    var query = from cartDetail in context.CartDetails
                                where cartDetail.Cloth.Name == productName
                                && cartDetail.ColorInfo.Name == color
                                && cartDetail.SizeInfo.Name == size
                                select cartDetail;

                    if (quantity <= 0)
                    {
                        //如果数量小于0,删除该购物车明细
                        context.CartDetails.DeleteObject(query.FirstOrDefault());
                    }
                    else
                    {
                        //修改数量
                        query.FirstOrDefault().QTY = quantity;
                    }
                    totalPrice += query.FirstOrDefault().QTY * query.FirstOrDefault().Cloth.Price;
                }
                //修改购物车的总价
                (from p in context.CartInfoes
                 where p.UserName == userName
                 select p).FirstOrDefault().TotalPrice = totalPrice;

                //保存数据库
                context.SaveChanges();
            }
        }