1. Trang chủ
  2. » Luận Văn - Báo Cáo

Xây dựng Website giới thiệu sản phẩm và bán hàng Nông sản

32 16 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Xây dựng Website giới thiệu sản phẩm và bán hàng Nông sản. Cài đặt Website trong đó: ‐ Trang người dùng: 1. Xây dựng giao diện website như trang mẫu. 2. Đăng ký, đăng nhập, có kiểm tra hợp lệ của dữ liệu trước khi gửi đi. 3. Hiển thị sản phẩm nông sản theo chủng loại. 4. Tìm kiếm sản phẩm theo tên loại, khoảng giá và nhiều tiêu chí khác. 5. Xem chi tiết ảnh, thông tin từng sản phẩm nông sản . 6. Đặt mua được sản phẩm nông sản. 7. Quản lý được sản phẩm vừa đặt nhưng chưa gửi (xem lại, sửa, xóa). 8. Các trang hiển thị có phân trang. 9. Xem được các tin tức liên quan tới các sản phẩm nông sản. ‐ Phía người quản trị 1. Giao diện website có bố cục hợp lý, đồng nhất về màu sắc, font chữ. 2. Có đăng nhập, tạo user, phân cấp user 3. Cập nhật tất cả các bảng trong cơ sở dữ liệu 4. Quản lý được hóa đơn đặt hàng nông sản (xem, sửa, xóa, in) 5. Hiển thị 3 sản phẩm nông sản được khách hàng mua. 6. Các trang hiển thị có phân trang.

TRƯỜNG ĐẠI HỌC CÔNG NGHIỆP HÀ NỘI KHOA CÔNG NGHỆ THÔNG TIN ======***====== BÁO CÁO BÀI TẬP LỚN MÔN: LẬP TRÌNH ỨNG DỤNG CƠ SỞ DỮ LIỆU TRÊN WEB ĐỀ TÀI: Xây dựng Website giới thiệu sản phẩm bán hàng Nơng sản GVHD: Nhóm: Sinh viên: Ths Đỗ Ngọc Sơn 12 Nguyễn Viết Trí Đặng Ngọc Đăng Huy Dương Thị Nhung Nguyễn Phương Thảo Lớp: 202110503134011 Khóa: 13 Hà Nội - Năm 2022 LỜI MỞ ĐẦU Nền tin học phát triển người có nhiều phương pháp mới, cơng cụ để xử lý thông tin nắm bắt nhiều thông tin hơn, Tin học ứng dụng ngành nghề, lĩnh vực đời sống xã hội, việc áp dụng tin học vào quản lý, sản xuất, kinh doanh du lịch xu hướng tất yếu Đối với việc kinh doanh, việc áp dụng tin học quản lý bán hàng giải pháp đắn hiệu trước nhu cầu mua sắm thị trường tăng Xuất phát từ thực tế đó, đề tài “ Xây dựng website cho cửa hàng sản phẩm nông sản” mà chúng em xây dựng mong muốn góp phần đưa cách bán hàng tới người tiêu dùng Tuy nhiên việc nghiên cứu gặp nhiều khó khăn nên đề tài chưa khai thác tuyệt đối, đề tài cịn có nhiều thiếu sót Rất mong thầy bạn đóng góp ý kiến để chương trình ngày hồn thiện đưa vào sử dụng Chúng em xin chân thành cảm ơn ! Lập trình ứng dụng CSDL Web MỤC LỤC Lập trình ứng dụng CSDL Web Bảng phân công công việc Mã SV Họ tên Cơng việc phân 2018604596 Nguyễn Viết Trí + Layout client + Slider + Tìm kiếm sản phẩm + Oder , giỏ hàng , toán + Thiết kế cở sở liệu + Quản lý đơn đặt hàng 2018604110 Đặng Ngọc Đăng Huy + Thiết kế cở sở liệu + Layout admin + Quản lý tài khoản + Quản lý Sản phẩm + Liên hệ + Quản lý contact 2018603799 Dương Thị Nhung + Đăng Ký + Tin tức , giới thiệu + Quản lý Danh Mục Sản phẩm + Quản lý , Tìm kiếm đơn đặt hàng + Phân trang + Hiện thị sản phẩm theo chủng loại 2018603850 Nguyễn Phương + Đăng Nhập Thảo + Xem chi tiết sản phẩm + Quản lý danh mục + Đăng Xuất Lập trình ứng dụng CSDL Web + Quản lý Blog + Quản lý Footer, About Phần TÌM HIỂU WEBSITE THỰC TẾ 1.1 Mô tả chức Website thực tế Cài đặt Website đó: ‐ Trang người dùng: Xây dựng giao diện website trang mẫu Đăng ký, đăng nhập, có kiểm tra hợp lệ liệu trước gửi Hiển thị sản phẩm nông sản theo chủng loại Tìm kiếm sản phẩm theo tên loại, khoảng giá nhiều tiêu chí khác Xem chi tiết ảnh, thông tin sản phẩm nông sản Đặt mua sản phẩm nông sản Quản lý sản phẩm vừa đặt chưa gửi (xem lại, sửa, xóa) Các trang hiển thị có phân trang Xem tin tức liên quan tới sản phẩm nơng sản ‐ Phía người quản trị Giao diện website có bố cục hợp lý, đồng màu sắc, font chữ Có đăng nhập, tạo user, phân cấp user Cập nhật tất bảng sở liệu Quản lý hóa đơn đặt hàng nơng sản (xem, sửa, xóa, in) Hiển thị sản phẩm nơng sản khách hàng mua Các trang hiển thị có phân trang Trang Web mẫu: - Tên website mẫu: http://anhloc.vn/ - Địa : Phòng 912 CT1 - X2 Bắc Linh Đàm, phường Hoàng Liệt, quận Hoàng Mai, Tp Hà Nội - Số điện thoại: 0358.241.421 - Một số trang giao diện WebSite thực tế tham khảo Lập trình ứng dụng CSDL Web Hình 1.1 Trang Chủ Hình 1.2 Đăng nhập đăng kí Lập trình ứng dụng CSDL Web Hình 1.3 Chi tiết sản phẩm Hình 1.4 Giỏ hàng đặt hàng Hình 1.5 Danh mục sản phẩm Lập trình ứng dụng CSDL Web Hình 1.6 Blog sản phẩm Hình 1.7 List trang Home Lập trình ứng dụng CSDL Web Hình 1.8 Thơng tin trang Web Lập trình ứng dụng CSDL Web 10 Hình 1.9 Đặc trưng trang WebSite Lập trình ứng dụng CSDL Web 18 - Quản lý tài khoản (thêm, sửa, xóa , tìm kiếm) - Quản lý blog (thêm, sửa, xóa , tìm kiếm) Lập trình ứng dụng CSDL Web 19 - Quản lý đơn đặt hàng (thêm, sửa, xóa , tìm kiếm) - Quản lý giao diện (thêm, sửa, xóa , tìm kiếm) Lập trình ứng dụng CSDL Web 20 2.3 Chương trình 2.3.1 Homecontroller using using using using using using using using Model.DAO; Model.EF; ShopFruit.Models; System; System.Collections.Generic; System.Linq; System.Web; System.Web.Mvc; namespace ShopFruit.Controllers { public class HomeController : Controller { public ActionResult Index() { ViewBag.Slides = new SlideDAO().ListAll(); var productDAO = new ProductDAO(); var DanhMucDAO = new DanhMucDAO(); var DanhMucSanPhamDAO = new CategoryProductDAO(); ViewBag.NewProducts = productDAO.ListNewProduct(4); ViewBag.NewProducts1 = productDAO.ListNewProduct1(4); ViewBag.ListFeatureProducts = productDAO.ListFeatureProduct(4); ViewBag.SanPhamBanChay = productDAO.SanPhamBanChay(4); ViewBag.DanhMuc = DanhMucDAO.ListAll(); ViewBag.DanhMucSanPham = DanhMucSanPhamDAO.ListCategoryProduct(); return View(); } public PartialViewResult HeaderCart() { var cart = Session[Common.CommonConstants.CartSession]; var list = new List(); if (cart != null) { list = (List)cart; } return PartialView(list); } public ActionResult Footer() { var model = new FooterDAO().GetFooter(); return PartialView(model); } public ActionResult About() { return View("About"); } Lập trình ứng dụng CSDL Web 21 [HttpGet] public ActionResult Contact() { return View(); } [HttpPost] public ActionResult Contact(MessageContact messageContact) { if (ModelState.IsValid) { var dao = new UserDAO(); long id = dao.InsertMessage(messageContact); if (id > 0) { ModelState.AddModelError("", "Gửi thành công"); return RedirectToAction("Contact", "Home"); } else { ModelState.AddModelError("", "Thêm user không thành công"); } } return View(); } } } 2.3.2 Userscontroller using using using using using using using using using using using using Facebook; Model.DAO; Model.EF; Model.ViewModel; ShopFruit.Common; ShopFruit.Models; System; System.Collections.Generic; System.Configuration; System.Linq; System.Web; System.Web.Mvc; namespace ShopFruit.Controllers { public class UserController : Controller { private string groupID = "MEMBER"; private Uri RedirectUri { get { var uriBuilder = new UriBuilder(Request.Url); Lập trình ứng dụng CSDL Web 22 uriBuilder.Query = null; uriBuilder.Fragment = null; uriBuilder.Path = Url.Action("FacebookCallback"); return uriBuilder.Uri; } } public ActionResult Index() { return View(); } public ActionResult QuanLyDonHang() { return View(); } public PartialViewResult DonHangDangDat() { var session = (UserLogin)Session[CommonConstants.USER_SESSION]; var thongTinDonHangDAO = new ThongTinDonHangDAO(); ViewBag.DonHangDangDat = thongTinDonHangDAO.DonHangChuaGiao(session.UserID); return PartialView(); } public PartialViewResult TatCaDonHang() { var session = (UserLogin)Session[CommonConstants.USER_SESSION]; var thongTinDonHangDAO = new ThongTinDonHangDAO(); ViewBag.TatCaDonHang = thongTinDonHangDAO.ToanBoDonDatHang(session.UserID); return PartialView(); } public PartialViewResult DonHangDaGiao() { var session = (UserLogin)Session[CommonConstants.USER_SESSION]; var thongTinDonHangDAO = new ThongTinDonHangDAO(); ViewBag.DonHangDaGiao = thongTinDonHangDAO.DonHangDaGiao(session.UserID); return PartialView(); } [HttpGet] public ActionResult ChiTietDonHang(string orderID) { var session = (UserLogin)Session[CommonConstants.USER_SESSION]; var thongTinDonHangDAO = new ThongTinDonHangDAO(); var TatCaDonHang = thongTinDonHangDAO.ToanBoDonDatHang(session.UserID); DonHangViewModel dHModel = new DonHangViewModel(); Lập trình ứng dụng CSDL Web 23 foreach (var item in TatCaDonHang) { if (item.OrderID.Trim() == orderID.Trim()) { dHModel.OrderID = item.OrderID; dHModel.SanPhamID = item.SanPhamID; dHModel.DonGia = item.OrderID; dHModel.Quantity = item.Quantity; dHModel.ThanhTien = item.ThanhTien; dHModel.CreateDate = item.CreateDate; dHModel.ShipName = item.ShipName; dHModel.ShipMobile = item.ShipMobile; dHModel.ShipAddress = item.ShipAddress; dHModel.ShipEmail = item.ShipEmail; dHModel.UserID = item.UserID; dHModel.TongTien = item.TongTien; dHModel.TenSanPham = item.TenSanPham; dHModel.Status = item.Status; } } return View(dHModel); } public ActionResult Login(LoginModel model) { if (ModelState.IsValid) { var dao = new UserDAO(); var result = dao.Login(model.Gmail, Encryptor.MD5Hash(model.Password)); if (result == 1) { var user = dao.GetByGmail(model.Gmail); var userSession = new UserLogin(); userSession.UserID = user.UserID; userSession.Gmail = user.Gmail; userSession.Name = user.Name; userSession.Address = user.Address; userSession.Phone = user.Phone; string groupID = "ADMIN"; var Group = dao.GetByGroup(userSession.Gmail, groupID); Session.Add(CommonConstants.USER_SESSION, userSession); if (Group.Count > 0) { return RedirectToAction("Index", "Home_Admin", new { area = "Admin" }); } else { return RedirectToAction("Index", "Home"); } Lập trình ứng dụng CSDL Web 24 } else if (result == 0) { ModelState.AddModelError("", "tài khoản không tồn tại"); } else if (result == -1) { ModelState.AddModelError("", "tài khoản bị khóa"); } else if (result == -2) { ModelState.AddModelError("", "Tài khoản mật không không đúng"); } else { ModelState.AddModelError("", "Tài khoản mật không không đúng"); } } return PartialView("Index"); } public ActionResult LoginFacebook() { var fb = new FacebookClient(); var loginUrl = fb.GetLoginUrl(new { client_id = ConfigurationManager.AppSettings["FbAppID"], client_secret = ConfigurationManager.AppSettings["FbAppSecret"], redirect_uri = RedirectUri.AbsoluteUri, response_type = "code", scope = "email", }); return Redirect(loginUrl.AbsoluteUri); } public ActionResult FacebookCallback(string code) { var fb = new FacebookClient(); dynamic result = fb.Post("oauth/access_token", new { client_id = ConfigurationManager.AppSettings["FbAppID"], client_secret = ConfigurationManager.AppSettings["FbAppSecret"], redirect_uri = RedirectUri.AbsoluteUri, code = code }); var accessToken = result.access_token; if (!string.IsNullOrEmpty(accessToken)) { fb.AccessToken = accessToken; Lập trình ứng dụng CSDL Web 25 dynamic me = fb.Get("me? fields=first_name,middle_name,last_name,id,email"); string email = me.email; string name = me.first_name + " " + me.middle_name + " " + me.last_name; groupID = "MEMBER"; var user = new User(); user.Gmail = email; user.Password = "NULL"; user.Phone = "NULL"; user.Address = "NULL"; user.GroupID = groupID; user.Name = name; user.Status = true; ViewBag.Email = user.Gmail; var resultInsert = new UserDAO().InsertForFacebook(user); if (resultInsert > 0) { var userSession = new UserLogin(); userSession.Gmail = user.Gmail; userSession.UserID = resultInsert; Session.Add(CommonConstants.USER_SESSION, userSession); return View("UpdateLoginFacebook"); } } return RedirectToAction("Index", "Home"); } public ActionResult UpdateLoginFacebook(User user) { var dao = new UserDb(); var userSession = (UserLogin)Session[CommonConstants.USER_SESSION]; user.UserID = userSession.UserID; user.Password = Encryptor.MD5Hash(user.Password); var update = dao.UpdateLoginFacebook(user); ViewBag.Update = "Cập nhật thành công"; return View("Index"); } public ActionResult Logout() { Session[Common.CommonConstants.USER_SESSION] = null; return View("Index"); } public ActionResult Register(RegisterModel model) { if (ModelState.IsValid) Lập trình ứng dụng CSDL Web 26 { var dao = new UserDAO(); if (dao.CheckGmail(model.Gmail)) { ModelState.AddModelError("", "Gmail tồn tại"); } else { var user = new User(); user.Gmail = model.Gmail; user.Password = Encryptor.MD5Hash(model.Password); user.Name = model.Name; user.Phone = model.Phone; user.Status = true; user.Address = model.Address; var result = dao.Insert(user); if (result > 0) { ViewBag.Success = "Đăng ký thành công"; model = new RegisterModel(); } else { ViewBag.Success = "Đăng ký không thành công"; } } } return View("Index"); } } } 2.3.3 Giỏ hàng using using using using using using using using using using using Common; Model.DAO; Model.EF; ShopFruit.Models; System; System.Collections.Generic; System.Configuration; System.Linq; System.Web; System.Web.Mvc; System.Web.Script.Serialization; namespace ShopFruit.Controllers { public class CartController : Controller { Lập trình ứng dụng CSDL Web 27 private const string CartSession = "CartSession"; // GET: Cart public ActionResult Index() { FruitShopDbContext db = new FruitShopDbContext(); ViewBag.Ship = db.Ships.ToList(); var cart = Session[CartSession]; var list = new List(); if (cart != null) { list = (List)cart; } return View(list); } public JsonResult DeleteAll() { Session[CartSession] = null; return Json(new { status = true }); } public JsonResult Delete(long id) { var sessionCart = (List)Session[CartSession]; sessionCart.RemoveAll(x => x.Product.SanPhamID == id); Session[CartSession] = sessionCart; return Json(new { status = true }); } public JsonResult Update(string cartModel) { var jsonCart = new JavaScriptSerializer().Deserialize(cartModel); var sessionCart = (List)Session[CartSession]; foreach (var item in sessionCart) { var jsonItem = jsonCart.SingleOrDefault(x => x.Product.SanPhamID == item.Product.SanPhamID); if (jsonItem != null) { item.Quantity = jsonItem.Quantity; } } Session[CartSession] = sessionCart; return Json(new Lập trình ứng dụng CSDL Web 28 { status = true }); } public ActionResult AddItem(long productID, int quantity) { var product = new ProductDAO().ProductDetail(productID); var cart = Session[CartSession]; if (cart != null) { var list = (List)cart; if (list.Exists(x => x.Product.SanPhamID == productID)) { foreach (var item in list) { if (item.Product.SanPhamID == productID) { item.Quantity += quantity; } } } else { var item = new CartItem(); item.Product = product; item.Quantity = quantity; list.Add(item); } //Gán vào session Session[CartSession] = list; } else { //tạo đối tượng cart item var item = new CartItem(); item.Product = product; item.Quantity = quantity; var list = new List(); list.Add(item); Session[CartSession] = list; } return RedirectToAction("Index"); } [HttpGet] public ActionResult Payment(int Ship) { FruitShopDbContext db = new FruitShopDbContext(); var ship = new Ship(); var gia = db.Ships.Where(y => y.ShipID == Ship).ToList(); foreach(var item in gia) { Lập trình ứng dụng CSDL Web 29 ship.GiaShip = item.GiaShip; } ViewBag.GiaShip = ship.GiaShip; var session = new List(); session = (List)Session[CartSession]; foreach (var item in session) { item.GiaShip = ship.GiaShip; } Session[CartSession] = session; var cart = Session[CartSession]; List list = new List(); if (cart != null) { list = (List)cart; } return View(list); } [HttpPost] public ActionResult Payment(string shipName, string mobile, string address, string email) { var cart = (List)Session[CartSession]; var order = new Order(); order.CreateDate = DateTime.Now; order.ShipAddress = address; order.ShipMobile = mobile; order.ShipName = shipName; order.ShipEmail = email; // lấy id user order.Status = true; var listSession = new List(); listSession = (List)Session[Common.CommonConstants.CartSession]; foreach (var item in listSession) { order.GiaShip = item.GiaShip; break; } order.TongTien = cart.Sum(x => Convert.ToInt64(x.Product.PromotionPrice) * x.Quantity) + order.GiaShip; SanPham sanPham = new SanPham(); SanPhamDAO sanPhamDAO = new SanPhamDAO(); try { var id = new OrderDAO().Insert(order); var detailDao = new Model.DAO.OrderDetailDAO(); Lập trình ứng dụng CSDL Web 30 decimal? total = order.TongTien; foreach (var item in cart) { var orderDetail = new OrderDetail(); orderDetail.SanPhamID = item.Product.SanPhamID; orderDetail.OrderID = id; orderDetail.DonGia = item.Product.PromotionPrice; orderDetail.Quantity = item.Quantity; orderDetail.ThanhTien = (Convert.ToInt64(orderDetail.DonGia) * item.Quantity).ToString(); detailDao.Insert(orderDetail); var soLuong = sanPhamDAO.ListAll().Where(x => x.SanPhamID == orderDetail.SanPhamID).ToList(); foreach (var soluong in soLuong) { sanPham.SanPhamID = soluong.SanPhamID; sanPham.Image = soluong.Image; sanPham.TenSanPham = soluong.TenSanPham; sanPham.DonGia = soluong.DonGia; sanPham.PromotionPrice = soluong.PromotionPrice; sanPham.TomTat = soluong.TomTat; sanPham.Description = soluong.Description; sanPham.MetaKeyword = soluong.MetaKeyword; sanPham.Quantity = soluong.Quantity - item.Quantity; sanPham.DanhMucSanPhamID = soluong.DanhMucSanPhamID; sanPham.Status = soluong.Status; sanPhamDAO.Update(sanPham); } } string content = System.IO.File.ReadAllText(Server.MapPath("~/Content/Client/Template/new order.html")); //content = content.Replace("{{CustomerName}}", shipName); //content = content.Replace("{{Phone}}", mobile); //content = content.Replace("{{Email}}", email); //content = content.Replace("{{Address}}", address); //content = content.Replace("{{Total}}", total.Value.ToString("N0")); //var toEmail = ConfigurationManager.AppSettings["ToEmailAddress"].ToString(); //new MailHelper().SendMail(email, "khách hàng đặt hàng từ FruitShop", content); //new MailHelper().SendMail(toEmail, "Đơn hàng từ FruitShop", content); } catch (Exception ex) { //ghi log return Redirect("/bao-tri"); Lập trình ứng dụng CSDL Web 31 } Session[CartSession] = null; return Redirect("/hoan-thanh"); } public ActionResult Success() { return View(); } public ActionResult Error() { return View(); } } } Lập trình ứng dụng CSDL Web 32 Phần KẾT LUẬN Thành công hạn chế trình xây dựng phát triển dự án Sau thời gian bắt tay vào nghiên cứu với hướng dẫn tận tình thầy giáo ThS Đỗ Ngọc Sơn, nhóm chúng em hồn thành đề tài “Xây dựng Website giới thiệu sản phẩm bán hàng Nông sản” Những thành công Đây website mà chúng em thực nên bước đầu gặt hái nhiều thành công: - Xây dựng hồn chỉnh Website giới thiệu nơng sản đặt mua nông sản tuyến trang http://anhloc.vn/ - Hoàn thành Các yêu cầu chung Website người dùng phía quản trị - Đưa sản phẩm hoàn thiện tới tay người dùng - Đoàn kết làm việc hỗ trợ cho tốt, tăng khả làm việc nhóm - Nắm nhiều phương pháp, kinh nghiệm trình thực dự án - Biết sử dụng phần mềm VisualStudio, SQLServer hỗ trợ thực dự án - Rút nhiều kinh nghiệm từ khâu khởi động việc kiểm soát, thực dự án Khó khăn Các thành viên nhóm cịn chưa có nhiều kinh nghiệm nên cịn gặp nhiều khó khăn khâu chuẩn bị, triển khai hồn thiện ý tưởng, gặp nhiều trở ngại khơng mong muốn trình thực TÀI LIỆU THAM KHẢO Lập trình ứng dụng CSDL Web ... thị sản phẩm nơng sản theo chủng loại Tìm kiếm sản phẩm theo tên loại, khoảng giá nhiều tiêu chí khác Xem chi tiết ảnh, thông tin sản phẩm nông sản Đặt mua sản phẩm nông sản Quản lý sản phẩm vừa... trường tăng Xuất phát từ thực tế đó, đề tài “ Xây dựng website cho cửa hàng sản phẩm nông sản? ?? mà chúng em xây dựng mong muốn góp phần đưa cách bán hàng tới người tiêu dùng Tuy nhiên việc nghiên... trình xây dựng phát triển dự án Sau thời gian bắt tay vào nghiên cứu với hướng dẫn tận tình thầy giáo ThS Đỗ Ngọc Sơn, nhóm chúng em hồn thành đề tài ? ?Xây dựng Website giới thiệu sản phẩm bán hàng

Ngày đăng: 14/02/2022, 17:02

Xem thêm:

TỪ KHÓA LIÊN QUAN

Mục lục

    Phần 1. TÌM HIỂU WEBSITE THỰC TẾ

    1.1 Mô tả các chức năng của Website thực tế

    1.2 Thiết kế cơ sở dữ liệu

    Phần 2. Thiết kế và cài đặt chương trình

    2.1 Giao diện phía khách hàng

    2.1.2 Các trang màn hình tương ứng với các chức năng hỗ trợ khách hàng

    2.1.2.1 Đăng Nhập và Đăng Ký

    2.1.2.2 Chi tiết sản phẩm

    2.1.2.3 Tìm kiếm sản phẩm

    2.1.2.4 Giỏ hàng và thanh toán

TÀI LIỆU CÙNG NGƯỜI DÙNG

TÀI LIỆU LIÊN QUAN

w