Пример #1
0
    public void LoadDataToCartRepeater(SanacoDataContext ctx, string sSessionId)
    {
        var DSCart = (from s in ctx.SessionCarts
                      where s.SessionId == sSessionId
                      select s);

        List<Product> listProductOrder = new List<Product>();
        decimal dTongTien = 0;
        if (DSCart.Count() > 0)
        {
            foreach (var item in DSCart)
            {
                var SanPham = (from sp in ctx.Products
                               where sp.ID == item.ProductId
                               select sp).First();

                decimal dPrice = (decimal)SanPham.NewPrice;
                dTongTien += dPrice * item.Quantity;

                listProductOrder.Add(SanPham);
            }
            rptGioHang.DataSource = listProductOrder;
        }
        else
        {
            btnUpdate.Visible = false;
            hlOrder.Visible = false;
            lbTotal.Visible = false;
            lbTitle.Text = "Giỏ hàng của bạn trống! ";
            //lbMessage.Text = "<span style=\"color:red; font-size: 17px;\"> Cập nhật giỏ hàng thành công!</span>";
        }
        rptGioHang.DataBind();
        lbTotal.Text = "<span style=\"color:black;\">Tổng tiền:</span> " + showMoney(dTongTien);
    }
Пример #2
0
    public void LoadDataToCartRepeater(SanacoDataContext ctx, string sSessionId)
    {
        var DSCart = (from s in ctx.SessionCarts
                      where s.SessionId == sSessionId
                      select s);

        List<Product> listProductOrder = new List<Product>();
        decimal dTongTien = 0;
        if (DSCart.Count() > 0)
        {
            foreach (var item in DSCart)
            {
                var SanPham = (from sp in ctx.Products
                               where sp.ID == item.ProductId
                               select sp).First();

                decimal dPrice = (decimal)SanPham.NewPrice;
                dTongTien += dPrice * item.Quantity;

                listProductOrder.Add(SanPham);
            }
            rptGioHang.DataSource = listProductOrder;
        }

        rptGioHang.DataBind();
        lbTotal.Text = "<span style=\"color:black;\">Tổng tiền:</span> " + showMoney(dTongTien);
        Session["Total"] = dTongTien;
    }
Пример #3
0
    public string ShowPosition(object input, string colunmName)
    {
        String sSessionId = Session["SID"].ToString();
        Product data = input as Product;
        SanacoDataContext ctx = new SanacoDataContext();
        Double SoLuong = (from sc in ctx.SessionCarts
                          where sc.SessionId == sSessionId && sc.ProductId == data.ID
                          select sc.Quantity).First();
        switch (colunmName)
        {
            case "id":
                return SoLuong.ToString();
            case "thanhtien":
                String sThanhTien = "---";
                String sPrice = (from sp in ctx.Products
                                 where sp.ID == data.ID
                                 select sp.NewPrice).First().ToString();
                Double dPrice = 0f;
                if (Double.TryParse(sPrice, out dPrice))
                {
                    Double dThanhTien = SoLuong * dPrice;
                    sThanhTien = dThanhTien.ToString();
                }

                return StringUltility.createMoneyString(sThanhTien);
            case "giatien":
                if (data.NewPrice != null && data.NewPrice > 0)
                {
                    return showMoney((decimal)data.NewPrice);
                }
                else
                {
                    return "Vui lòng liên hệ";
                }
            default:
                return "";
        }
    }
Пример #4
0
    protected void btnUpdate_Click(object sender, EventArgs e)
    {
        SanacoDataContext ctx = new SanacoDataContext();

        string sSessionId = Session["SID"].ToString();
        string sQuantity = Request.Form["txtQuantity"] ?? "";
        var quantitys = sQuantity.Split(',').Cast<String>().ToList();

        var DSSC = (from sc in ctx.SessionCarts
                    where sc.SessionId == sSessionId
                    select sc);

        int i = 0;
        foreach (var item in DSSC)
        {
            int quantity = 0;
            if (Int32.TryParse(quantitys.ElementAt(i), out quantity))
            {
                if (quantity > 0)
                {
                    item.Quantity = quantity;
                }
                else
                {
                    ctx.SessionCarts.DeleteOnSubmit(item);
                }
                lbMessage.Text = "<span style=\"color:red; font-size: 17px;\"> Cập nhật giỏ hàng thành công!</span>";
            }
            else
            {
                lbMessage.Text = "<span style=\"color:red;\"> Vui lòng nhập số nguyên cho số lượng sản phẩm</span>";
                return;
            }

            i++;
        }

        string stringid = Request.Form["cbDelProd"] ?? "";
        var ids = stringid.Split(',').Cast<String>().ToList();

        var DSSCToDelete = (from sc in ctx.SessionCarts
                            where sc.SessionId == sSessionId && ids.Contains(sc.ProductId.ToString())
                            select sc);

        if (DSSCToDelete.Count() > 0)
        {
            ctx.SessionCarts.DeleteAllOnSubmit(DSSCToDelete);
        }

        ctx.SubmitChanges();

        var DSCart = (from s in ctx.SessionCarts
                      where s.SessionId == sSessionId
                      select s);
        if (DSCart != null && DSCart.Count() > 0)
        {
            Session["Amount"] = DSCart.Count();
        }
        else
        {
            Session["Amount"] = 0;
        }

        LoadDataToCartRepeater(ctx, Session["SID"].ToString());
    }
Пример #5
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            // Tạo linQ context
            SanacoDataContext ctx = new SanacoDataContext();
            string sSessionId = Session["SID"].ToString();

            // Lấy product id và session id
            string sPid = Request.QueryString["pid"] ?? "";
            if (sPid != "")
            {
                int nPid = int.Parse(sPid);

                SessionCart newSC = new SessionCart();
                newSC.ProductId = nPid;
                newSC.SessionId = sSessionId;

                // Kiểm tra giỏ hàng với sản phẩm mới
                var DSHang = (from p in ctx.SessionCarts
                              where p.SessionId == sSessionId && p.ProductId == nPid
                              select p);

                if (DSHang.Count() > 0)
                {
                    // Sản phẩm đã được đặt, cộng số lượng đặt lên 1
                    SessionCart oldCart = (SessionCart)(DSHang.First());
                    oldCart.Quantity = oldCart.Quantity + 1;

                }
                else
                {
                    // Chưa đặt sản phẩm này lần nào, thiết lập số lượng đặt là 1
                    newSC.Quantity = 1;
                    ctx.SessionCarts.InsertOnSubmit(newSC);
                }

                // Cập nhật database
                ctx.SubmitChanges();

                var DSCart = (from s in ctx.SessionCarts
                              where s.SessionId == sSessionId
                              select s);
                if (DSCart != null && DSCart.Count() > 0)
                {
                    Session["Amount"] = DSCart.Count();
                }
                else
                {
                    Session["Amount"] = 0;
                }
            }
            LoadDataToCartRepeater(ctx, sSessionId);
        }
    }
Пример #6
0
    protected void btnMuaHang_Click(object sender, EventArgs e)
    {
        SanacoDataContext ctx = new SanacoDataContext();

        //Theme đơn hàng mới
        Order order = new Order();
        order.SessionID = Session["SID"].ToString();
        Customer cus = (Customer)Session["Customer"];
        order.HoTen = cus.FullName;
        order.DiaChi = cus.Address;
        order.SDT = cus.Phone;
        order.Email = cus.Email;
        order.YeuCauThem = cus.OtherRequire;
        order.TongHoaDon = Convert.ToDecimal(Session["Total"].ToString());
        order.TrangThai = 0;
        order.NgayOrder = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd"));

        ctx.Orders.InsertOnSubmit(order);
        ctx.SubmitChanges();

        //Theme vào chi tiết order
        String sSessionId = Session["SID"].ToString();
        var oldOrder = (from ord in ctx.Orders
                        where ord.SessionID == sSessionId
                        select ord).First();

        List<OrdersDetail> listProductOrder = new List<OrdersDetail>();
        var DSCart = (from s in ctx.SessionCarts
                      where s.SessionId == sSessionId
                      select s);

        if (DSCart.Count() > 0)
        {
            foreach (var item in DSCart)
            {
                var SanPham = (from sp in ctx.Products
                               where sp.ID == item.ProductId
                               select sp).First();

                OrdersDetail orderDetail = new OrdersDetail();
                orderDetail.OrderID = oldOrder.ID;
                orderDetail.ProductID = SanPham.ID;
                orderDetail.Quantity = item.Quantity;
                orderDetail.SellPrice = SanPham.NewPrice;
                orderDetail.Total = item.Quantity * SanPham.NewPrice;
                listProductOrder.Add(orderDetail);

            }

        }
        ctx.OrdersDetails.InsertAllOnSubmit(listProductOrder);
        ctx.SubmitChanges();

        //Xóa Session cart lưu tạm
        var DSSCToDelete = (from sc in ctx.SessionCarts
                            where sc.SessionId == sSessionId
                            select sc);

        if (DSSCToDelete.Count() > 0)
        {
            ctx.SessionCarts.DeleteAllOnSubmit(DSSCToDelete);
        }
        ctx.SubmitChanges();

        Session.Abandon();
        Response.Cookies.Add(new HttpCookie("ASP.NET_SessionId", ""));
        Session["SID"] = Session.SessionID;

        confirm.Visible = false;
        InforConfirmPanel.Visible = false;
        lbMessage.Text = "<span style=\"color:blue; text-align:center; float:left; width: 100%; font-size:15px !important; font-weight: bod; margin-top:20%;\"> Đơn hàng của bạn đã được gửi đi, chúng tôi sẽ xử lý đơn hàng và liên hệ với bạn trong thời gian sớm nhất <br/>Chân thành cảm ơn bạn đã mua sắm tại cửa hàng của chúng tôi</span>";
    }
Пример #7
0
    protected void btnConfirm_Click(object sender, EventArgs e)
    {
        SanacoDataContext ctx = new SanacoDataContext();
        String sSessionId = Session["SID"].ToString();
        LoadDataToCartRepeater(ctx, sSessionId);

        confirm.Visible = false;
        InforConfirmPanel.Visible = true;

        GetData();
        Customer customer = (Customer)Session["Customer"];
        lbFullName.Text = customer.FullName;
        lbAddress.Text = customer.Address;
        lbPhone.Text = customer.Phone.ToString();
        lbEmail.Text = customer.Email;
        lbOtherRequire.Text = customer.OtherRequire;
    }