//Hiển thị sản phẩm public ActionResult ChiTiet(int id) { if (CheckAdmin() == false) { return(RedirectToAction("Login", "QuanLySanPham")); } SANPHAM sanpham = data.SANPHAMs.SingleOrDefault(n => n.MASP == id); ViewBag.MASP = sanpham.MASP; if (sanpham == null) { Response.StatusCode = 404; return(null); } try { HINHANH hinh = (HINHANH)data.HINHANHs.First(n => n.MASP == id); ViewBag.URLHinh = hinh.URLHINH; } catch (Exception e) { return(RedirectToAction("HinhAnh", new { id = id })); } return(View(sanpham)); }
public List<HINHANH> SelectHINHANHsAll() { List<HINHANH> list = new List<HINHANH>(); using (LinQDataContext db = new LinQDataContext(global::DAOAuction.Properties.Settings.Default.webdoantruongConnectionString)) { ISingleResult<HINHANH_getallResult> lp = db.HINHANH_getall(); foreach (HINHANH_getallResult HINHANH in lp) { HINHANH var1 = new HINHANH(); var1.MaHinhAnh = HINHANH.MaHinhAnh ; var1.DuongDan = HINHANH.DuongDan ; var1.MaAlbum = HINHANH.MaAlbum ; list.Add(var1); } try { // Save the changes. db.SubmitChanges(); } // Detect concurrency conflicts. catch (ChangeConflictException) { // Resolve conflicts. db.ChangeConflicts.ResolveAll(RefreshMode.KeepChanges); } } return list; }
// POST: Admin/HinhAnh/Sua public ActionResult Sua(HINHANH ha) { using (Web_KTCKEntities db = new Web_KTCKEntities()) { HINHANH hinhanh = db.HINHANHs.SingleOrDefault(n => n.IdHinhAnh == ha.IdHinhAnh); if (hinhanh != null) { hinhanh.TenHinhAnh = ha.TenHinhAnh; if (ha.NgayDang == null) { hinhanh.NgayDang = hinhanh.NgayDang; } else { hinhanh.NgayDang = ha.NgayDang; } hinhanh.HinhAnh1 = ha.HinhAnh1; hinhanh.IdAlbum = ha.IdAlbum; ViewBag.IdAlbum = new SelectList(db.ALBUMs.ToList(), "IdAlbum", "TenAlbum"); ViewBag.IdTaiKhoan = new SelectList(db.TAIKHOANs.ToList(), "IdTK", "HoTen"); hinhanh.IdTaiKhoan = ha.IdTaiKhoan; db.SaveChanges(); } } return(RedirectToAction("Index")); }
public ActionResult Sua(int id, HttpPostedFileBase file, FormCollection coll) { SANPHAM sanpham = data.SANPHAMs.SingleOrDefault(n => n.MASP == id); HINHANH hinhanh = (HINHANH)data.HINHANHs.First(n => n.MASP == id); sanpham.NGAYCAPNHAT = DateTime.Now; ViewBag.MATH = new SelectList(data.THUONGHIEUs.ToList().OrderBy(n => n.TENTH), "MATH", "TENTH"); ViewBag.MAPC = new SelectList(data.PHONGCACHes.ToList().OrderBy(n => n.TENPC), "MAPC", "TENPC"); if (file != null) { var fileName = Path.GetFileName(file.FileName); var path = Path.Combine(Server.MapPath("~/images"), fileName); if (System.IO.File.Exists(path)) { ViewBag.Thongbao = "Hình ảnh đã tồn tại"; } else { file.SaveAs(path); } hinhanh.URLHINH = fileName; } //Them vao CSDL if (ModelState.IsValid) { UpdateModel(sanpham); UpdateModel(hinhanh); data.SubmitChanges(); } return(RedirectToAction("Index")); }
public ActionResult ThemHinh(int id, IEnumerable <HttpPostedFileBase> files, FormCollection coll) { foreach (var file in files) { if (file != null && file.ContentLength > 0) { HINHANH hinh = new HINHANH(); var fileName = Path.GetFileName(file.FileName); var path = Path.Combine(Server.MapPath("~/images"), fileName); if (System.IO.File.Exists(path)) { ViewBag.Thongbao = "Hình ảnh đã tồn tại"; } else { //Luu hinh anh vao duong dan file.SaveAs(path); } hinh.MASP = id; hinh.URLHINH = fileName; data.HINHANHs.InsertOnSubmit(hinh); } } data.SubmitChanges(); return(RedirectToAction("HinhAnh", new { id = id })); }
public ActionResult Sua(int id) { if (CheckAdmin() == false) { return(RedirectToAction("Login", "QuanLySanPham")); } SANPHAM sanpham = data.SANPHAMs.SingleOrDefault(n => n.MASP == id); ViewBag.MASP = sanpham.MASP; if (sanpham == null) { Response.StatusCode = 404; return(null); } ViewBag.MATH = new SelectList(data.THUONGHIEUs.ToList().OrderBy(n => n.TENTH), "MATH", "TENTH", sanpham.MATH); ViewBag.MAPC = new SelectList(data.PHONGCACHes.ToList().OrderBy(n => n.TENPC), "MAPC", "TENPC", sanpham.MAPC); try { HINHANH hinh = (HINHANH)data.HINHANHs.First(n => n.MASP == id); ViewBag.URLHinh = hinh.URLHINH; } catch (Exception e) { return(RedirectToAction("HinhAnh", new { id = id })); } return(View(sanpham)); }
public ActionResult UploadFileImage(string id, HttpPostedFileBase[] fileImages) { var message = 0; string path = Server.MapPath("~/UploadFile/"); string path2 = "C:\\xampp\\htdocs\\apiFahasa\\image\\"; var delete = new BookDao().DeleteImage(id); if (fileImages != null) { foreach (var file in fileImages) { if (file != null) { var images = new HINHANH(); var imageDao = new UploadHinhAnhSanPhamDao(); string extensionName = System.IO.Path.GetExtension(file.FileName); var fileInfo = new FileInfo(file.FileName); string finalFileName = DateTime.Now.Ticks.ToString() + extensionName; file.SaveAs(path + finalFileName); file.SaveAs(path2 + finalFileName); //Insert database images.LINKHINHANH = finalFileName; images.MASANPHAM = id; images.TENHINHANH = file.FileName; message = imageDao.Insert(images); } } } return(Json(message, JsonRequestBehavior.AllowGet)); }
public ActionResult SuaHinh(int id, HttpPostedFileBase file, FormCollection coll) { HINHANH hinhanh = data.HINHANHs.SingleOrDefault(n => n.MAHINH == id); if (file != null) { var fileName = Path.GetFileName(file.FileName); var path = Path.Combine(Server.MapPath("~/images"), fileName); if (System.IO.File.Exists(path)) { ViewBag.Thongbao = "Hình ảnh đã tồn tại"; } else { file.SaveAs(path); } hinhanh.URLHINH = fileName; } //Them vao CSDL UpdateModel(hinhanh); data.SubmitChanges(); return(RedirectToAction("HinhAnh", new { id = hinhanh.MASP })); }
protected void btnThem_Click(object sender, EventArgs e) { try { //lay thong tin tu textbox HINHANH lpDTO = new HINHANH(); lpDTO.MaHinhAnh = int.Parse(txtmahinhanh.Text); lpDTO.DuongDan = txthinhanh.Text; lpDTO.MaAlbum = int.Parse(txtmaalbum.Text); //Goi ham cap nhat BUSHinhAnh BUSHinhAnh = new BUSHinhAnh(); if (BUSHinhAnh.Them(lpDTO) == 0) { //Thong bao lbThongBao.Text = "Thêm Thành Công"; lbThongBao.Visible = true; //Response.Redirect("LoaiMatHang.aspx"); } else { lbThongBao.Text = "Thêm Không Thành Công"; lbThongBao.Visible = true; } } catch { lbThongBao.Text = "Thêm Không Thành Công"; lbThongBao.Visible = true; } }
public ActionResult DeleteConfirmed(int id) { HINHANH hINHANH = db.HINHANHs.Find(id); db.HINHANHs.Remove(hINHANH); db.SaveChanges(); return(RedirectToAction("Index")); }
public bool SuaHinhAnh(HINHANH p) { HINHANH hinh = linq.HINHANHs.Where(t => t.MAHINHANH == p.MAHINHANH).FirstOrDefault(); hinh.TENHINHANH = p.TENHINHANH; hinh.URL = p.URL; linq.SubmitChanges(); return(true); }
private void insertHinhAnh() { if (pictureEdit1.Image != null) { try { HINHANH ha = new HINHANH(); ha.MAHINHANH = bLL_NhanVien.BLL_FindHinhAnhByMANV(txt_MaNV.Text); ha.TENHINHANH = pictureEdit1.Text; ha.URL = st.imageToByteArray(pictureEdit1.Image); bLL_NhanVien.BLL_UpdateHinhAnh(ha); } catch { try { HINHANH ha = new HINHANH(); ha.MAHINHANH = bLL_NhanVien.BLL_FindHinhAnhByMANV(txt_MaNV.Text); ha.TENHINHANH = pictureEdit1.Text; ha.URL = st.imageToByteArray(pictureEdit1.Image); ha.MAUNGVIEN = bLL_load.BLL_FindUngVienByMaNV(txt_MaNV.Text); bLL_NhanVien.BLL_InsertHinhAnh(ha); } catch { } } } else { try { HINHANH ha = new HINHANH(); ha.MAHINHANH = bLL_NhanVien.BLL_FindHinhAnhByMANV(txt_MaNV.Text); ha.TENHINHANH = pictureEdit1.Text; ha.URL = null; bLL_NhanVien.BLL_UpdateHinhAnh(ha); } catch { try { HINHANH ha = new HINHANH(); ha.MAHINHANH = bLL_NhanVien.BLL_FindHinhAnhByMANV(txt_MaNV.Text); ha.TENHINHANH = pictureEdit1.Text; ha.URL = null; ha.MAUNGVIEN = bLL_load.BLL_FindUngVienByMaNV(txt_MaNV.Text); bLL_NhanVien.BLL_InsertHinhAnh(ha); } catch { } } } }
public ActionResult XoaHinh(int id, FormCollection coll) { HINHANH hinhanh = data.HINHANHs.SingleOrDefault(n => n.MAHINH == id); //Them vao CSDL data.HINHANHs.DeleteOnSubmit(hinhanh); data.SubmitChanges(); return(RedirectToAction("HinhAnh", new { id = hinhanh.MASP })); }
public ActionResult Edit([Bind(Include = "IDHA,IDTD,TENHA,LINK")] HINHANH hINHANH) { if (ModelState.IsValid) { db.Entry(hINHANH).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.IDTD = new SelectList(db.TRANDAUs, "IDTD", "IDTD", hINHANH.IDTD); return(View(hINHANH)); }
public ActionResult XoaHinh(int id) { if (CheckAdmin() == false) { return(RedirectToAction("Login", "QuanLySanPham")); } HINHANH hinh = data.HINHANHs.SingleOrDefault(n => n.MAHINH == id); ViewBag.MaSP = hinh.MASP; return(View(hinh)); }
public ActionResult Create([Bind(Include = "IDHA,IDTD,TENHA,LINK")] HINHANH hINHANH) { if (ModelState.IsValid) { db.HINHANHs.Add(hINHANH); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.IDTD = new SelectList(db.TRANDAUs, "IDTD", "IDTD", hINHANH.IDTD); return(View(hINHANH)); }
public GioHang(int maSP) { iMaSP = maSP; SANPHAM sp = data.SANPHAMs.Single(n => n.MASP == iMaSP); sTenSP = sp.TENSP; dDonGia = double.Parse(sp.GIABAN.ToString()); iSoLuong = 1; HINHANH img = data.HINHANHs.First(n => n.MASP == iMaSP); sAnhDaiDien = img.URLHINH; }
// POST: Admin/HinhAnh/Xoa public ActionResult Xoa(int id) { using (Web_KTCKEntities db = new Web_KTCKEntities()) { HINHANH ha = db.HINHANHs.SingleOrDefault(n => n.IdHinhAnh == id); if (ha != null) { db.HINHANHs.Remove(ha); db.SaveChanges(); } } return(RedirectToAction("Index")); }
public int Insert(HINHANH entity) { try { db.HINHANHs.Add(entity); db.SaveChanges(); return(1); } catch { return(-2); } }
// GET: Admin/HINHANHs/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } HINHANH hINHANH = db.HINHANHs.Find(id); if (hINHANH == null) { return(HttpNotFound()); } return(View(hINHANH)); }
// GET: Admin/HINHANHs/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } HINHANH hINHANH = db.HINHANHs.Find(id); if (hINHANH == null) { return(HttpNotFound()); } ViewBag.IDTD = new SelectList(db.TRANDAUs, "IDTD", "IDTD", hINHANH.IDTD); return(View(hINHANH)); }
public int CapNhat(HINHANH lpDTO) { try { LinQDataContext db = new LinQDataContext(global::DAOAuction.Properties.Settings.Default.webdoantruongConnectionString); return db.HINHANH_update( lpDTO.MaHinhAnh, lpDTO.DuongDan, lpDTO.MaAlbum ); } catch (Exception ex) { throw (ex); } }
public int Them(HINHANH lpDTO) { try { LinQDataContext db = new LinQDataContext(global::DAOAuction.Properties.Settings.Default.webdoantruongConnectionString); db.HINHANH_add( lpDTO.DuongDan , lpDTO.MaAlbum ); return 1; } catch { return 0; } }
public void UploadHinhAnh(string file, string name, int maxe) { HINHANH h = new HINHANH(); h.Link = file; h.Name = name; db.HINHANHs.InsertOnSubmit(h); db.SubmitChanges(); int idanh = h.Id; XE_ANH x = new XE_ANH(); x.IdAnh = idanh; x.MaXe = maxe; db.XE_ANHs.InsertOnSubmit(x); db.SubmitChanges(); }
public ActionResult ThemMoi(SANPHAM sanpham, HINHANH hinhanh, IEnumerable <HttpPostedFileBase> files, FormCollection coll) { ViewBag.MaTH = new SelectList(data.THUONGHIEUs.ToList().OrderBy(n => n.TENTH), "MATH", "TENTH"); ViewBag.MaPC = new SelectList(data.PHONGCACHes.ToList().OrderBy(n => n.TENPC), "MAPC", "TENPC"); // Kiem tra duong dan file if (files == null) { ViewBag.Thongbao = "Vui lòng chọn ảnh bìa"; return(View()); } //Them vao CSDL else { if (ModelState.IsValid) { //Luu vao CSDL sanpham.NGAYCAPNHAT = DateTime.Now; data.SANPHAMs.InsertOnSubmit(sanpham); data.SubmitChanges(); foreach (var file in files) { if (file != null && file.ContentLength > 0) { var fileName = Path.GetFileName(file.FileName); var path = Path.Combine(Server.MapPath("~/images"), fileName); if (System.IO.File.Exists(path)) { ViewBag.Thongbao = "Hình ảnh đã tồn tại"; } else { //Luu hinh anh vao duong dan file.SaveAs(path); } hinhanh.URLHINH = fileName; hinhanh.MASP = sanpham.MASP; data.HINHANHs.InsertOnSubmit(hinhanh); } } data.SubmitChanges(); } return(RedirectToAction("Index")); } }
// POST: Admin/HinhAnh/Them public ActionResult Them(HINHANH ha) { using (Web_KTCKEntities db = new Web_KTCKEntities()) { if (ha.NgayDang == null) { ha.NgayDang = DateTime.Parse(DateTime.Now.ToString()); } else { ha.NgayDang = ha.NgayDang; } ViewBag.IdAlbum = new SelectList(db.ALBUMs.ToList(), "IdAlbum", "TenAlbum"); ViewBag.IdTaiKhoan = new SelectList(db.TAIKHOANs.ToList(), "IdTK", "HoTen"); db.HINHANHs.Add(ha); db.SaveChanges(); return(RedirectToAction("Index")); } }
// GET: Admin/HINHANHs/Delete/5 public ActionResult Delete(int?id) { HINHANH hINHANH = db.HINHANHs.Find(id); return(View(hINHANH)); }
public ActionResult CreateVPP(ProductModel inputData, HttpPostedFileBase[] fileImages) { string path = Server.MapPath("~/UploadFile/"); string path2 = "C:\\xampp\\htdocs\\apiFahasa\\image\\"; var session = (UserLogin)Session[QLNhaSachFahasa.Common.CommonConstants.USER_SEESION]; int res; var product = new SANPHAM() { MASANPHAM = new SanPhamDao().CreateIDVPPAuto("VPP"), TENSANPHAM = inputData.TenSanPham, PHANLOAI = inputData.PhanLoai, SOLUONG = inputData.SoLuong, CHATLIEU = inputData.ChatLieu, MAUSAC = inputData.MauSac, TRONGLUONG = inputData.TrongLuong, KICHTHUOC = inputData.KichThuoc, NHASANXUAT = inputData.NhaSanXuat, NHACUNGCAP = inputData.NhaCungCap, QUOCGIA = inputData.QuocGia, DONGIA = inputData.DonGia, GHICHU = inputData.GhiChu, LUOTXEM = 0, NGAYTAO = DateTime.Now, NGAYCAPNHAT = DateTime.Now, NGUOITAO = session.UserID, TRANGTHAI = 1 }; res = new SanPhamDao().InsertProduct(product); decimal gia = inputData.DonGia; if (!string.IsNullOrEmpty(inputData.GiaBan.ToString()) && inputData.GiaBan != 0) { gia = inputData.GiaBan; } var updateGiaBan = new SanPhamDao().UpdateGiaBan(product.MASANPHAM, gia, product.NGUOITAO); if (fileImages != null) { foreach (var file in fileImages) { if (file != null) { var images = new HINHANH(); var imageDao = new UploadHinhAnhSanPhamDao(); string extensionName = System.IO.Path.GetExtension(file.FileName); var fileInfo = new FileInfo(file.FileName); string finalFileName = DateTime.Now.Ticks.ToString() + extensionName; file.SaveAs(path + finalFileName); file.SaveAs(path2 + finalFileName); //Insert database images.LINKHINHANH = finalFileName; images.MASANPHAM = product.MASANPHAM; images.TENHINHANH = file.FileName; res = imageDao.Insert(images); } } } return(Json(res, JsonRequestBehavior.AllowGet)); }
public ActionResult GetCreateBook(BookModel inputData, HttpPostedFileBase[] fileImages) { string path = Server.MapPath("~/UploadFile/"); string path2 = "C:\\xampp\\htdocs\\apiFahasa\\image\\"; int result; var dao = new BookDao(); var phanloaidao = new GroupPhanLoaiDao(); if (dao.CheckBookExist(inputData.TENSACH, inputData.NHAXUATBAN)) { result = -1; } else { var book = new SANPHAM(); var session = (UserLogin)Session[QLNhaSachFahasa.Common.CommonConstants.USER_SEESION]; book.MASANPHAM = dao.CreateIDAuto("SH"); book.TENSANPHAM = inputData.TENSACH; book.PHANLOAI = inputData.MAPHANLOAISACH.Trim(); book.TRANGTHAI = 1; book.NGONNGU = inputData.MANGONNGU; book.HINHTHUC = inputData.MAHINHTHUC; book.TACGIA = inputData.TACGIA; book.DONGIA = inputData.GIASACH; book.TRONGLUONG = inputData.TRONGLUONG; book.SOTRANG = inputData.SOTRANG; book.KICHTHUOC = inputData.KICHTHUOC; book.GHICHU = inputData.TOMTAC; book.NHAXUATBAN = inputData.NHAXUATBAN; book.NGAYTAO = DateTime.Now; book.NGAYCAPNHAT = DateTime.Now; book.NGUOITAO = session.UserID; book.SOLUONG = 0; book.LUOTXEM = 0; book.SOLUONG = inputData.SoLuong; book.NHACUNGCAP = inputData.NHACUNGCAP; result = dao.InserBook(book); decimal gia = inputData.GIASACH; if (!string.IsNullOrEmpty(inputData.GIABAN.ToString()) && inputData.GIABAN != 0) { gia = inputData.GIABAN; } var updateGiaBan = new SanPhamDao().UpdateGiaBan(book.MASANPHAM, gia, book.NGUOITAO); // Upload file lên server if (fileImages != null) { foreach (var file in fileImages) { if (file != null) { var images = new HINHANH(); var imageDao = new UploadHinhAnhSanPhamDao(); string extensionName = System.IO.Path.GetExtension(file.FileName); var fileInfo = new FileInfo(file.FileName); string finalFileName = DateTime.Now.Ticks.ToString() + extensionName; file.SaveAs(path + finalFileName); file.SaveAs(path2 + finalFileName); //Insert database images.LINKHINHANH = finalFileName; images.MASANPHAM = book.MASANPHAM; images.TENHINHANH = file.FileName; result = imageDao.Insert(images); } } } } return(Json(result, JsonRequestBehavior.AllowGet)); }
public bool BLL_UpdateHinhAnh(HINHANH p) { return(dAL_NhanVien.SuaHinhAnh(p)); }
public bool BLL_InsertHinhAnh(HINHANH p) { return(dAL_NhanVien.ThemHinhAnh(p)); }
public bool ThemHinhAnh(HINHANH p) { linq.HINHANHs.InsertOnSubmit(p); linq.SubmitChanges(); return(true); }