Ejemplo n.º 1
0
        public void Add(OHoaDonBan item)
        {
            conn.connect();
            var comm = new SqlCommand("HDB_Add", conn.db);

            comm.CommandType = CommandType.StoredProcedure;
            if (comm == null)
            {
                return;
            }
            comm.Parameters.Add("@MaKhach", SqlDbType.Int).Value = item.MaKhach;

            comm.ExecuteNonQuery();
        }
Ejemplo n.º 2
0
        public void Update(OHoaDonBan item)
        {
            conn.connect();
            var comm = new SqlCommand("HDB_Add", conn.db);

            comm.CommandType = CommandType.StoredProcedure;
            if (comm == null)
            {
                return;
            }

            comm.Parameters.Add("@MaHDB", SqlDbType.Int).Value         = item.MaHDB;
            comm.Parameters.Add("@NgayGiao", SqlDbType.DateTime).Value = item.NgayGiao;

            comm.Parameters.Add("@IsActive", SqlDbType.Int).Value = item.TrangThai;

            comm.ExecuteNonQuery();
        }
Ejemplo n.º 3
0
        public ActionResult Update(OHoaDonBan model)
        {
            if (ModelState.IsValid)
            {
                var pro = hdbService.GetById(model.MaHDB);
                if (pro != null)
                {
                    try
                    {
                        hdbService.Edit(model);
                        return(RedirectToAction("Search", "HoaDonBan"));
                    }
                    catch (Exception e)
                    {
                    }
                }
            }

            ViewBag.IsEdit = true;
            return(View(model));
        }
Ejemplo n.º 4
0
        public OHoaDonBan GetById(int mahdb)
        {
            conn.connect();
            var comm = new SqlCommand("HDB_Get", conn.db);

            comm.CommandType = CommandType.StoredProcedure;
            if (comm == null)
            {
                return(null);
            }
            comm.Parameters.Add("@mahdb", SqlDbType.Int).Value = mahdb;
            DataTable dt = new DataTable();

            dt.Load(comm.ExecuteReader());
            OHoaDonBan item = new OHoaDonBan();

            item = Help.DAL.ConvertDataTable <OHoaDonBan>(dt).FirstOrDefault();

            conn.Close();
            return(item);
        }
Ejemplo n.º 5
0
        public ActionResult DatHang()
        {
            string  strChuoi = "";
            decimal total    = 0;

            ShoppingCartModels model = new ShoppingCartModels();

            model.Cart = (Carts)Session["Cart"];

            if (Session["Account"] == null || Session["Account"].ToString() == "")
            {
                //return RedirectToAction("Login", "Account");
                return(Json(new { Success = false, Url = Url.Action("Login", "Account") }));
            }

            OAccount account = (OAccount)Session["Account"];
            OAccount kh      = accountService.Get(account.TenDN, account.MatKhau);

            if (kh == null)
            {
                return(Redirect("Error"));
            }
            OHoaDonBan ddh = new OHoaDonBan
            {
                MaKhach   = kh.MaKhach,
                TrangThai = 0,
            };

            hdbService.Add(ddh);
            int idHdb = hdbService.GetLastId();

            foreach (var item in model.Cart.ListItem)
            {
                cTHDBService.Add(new OCTHDB
                {
                    MaHDB     = idHdb,
                    MaSanPham = item.ProductId,
                    SoLuong   = item.Quantity,
                    ThanhTien = item.Total,
                });

                strChuoi += "<li> Tên sản phẩm: " + item.ProductName + "</li> ";
                strChuoi += "<li> Giá: " + item.Price.ToString("#,##") + " đ</li> ";
                strChuoi += "<li> Số lượng: " + item.Quantity + "</li> ";
                total    += item.Total;
                var product = sachService.Get(new OSanPham {
                    MaSanPham = item.ProductId
                });
                var newproduct = sachService.Get(new OSanPham {
                    MaSanPham = item.ProductId
                });
                if (product != null)
                {
                    newproduct.SoLuong = product.SoLuong - item.Quantity;
                    sachService.Update(newproduct);
                }
            }
            strChuoi += "<li>Tổng tiền: " + total.ToString("#,##") + " đ </li>";
            SendEmail(kh.Email, strChuoi);
            Session["Cart"] = null;

            return(Json(new { Success = true, Message = "Đặt hàng thành công. Bạn hãy check email nhé !" }));
        }