Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
1.6 kB
2
Indexable
Never
@RequestMapping(value="add", method = RequestMethod.POST) public String
	  themSanPham(ModelMap model,
				HttpSession session,
			  @RequestParam("photo") MultipartFile photo,
			  	HttpServletRequest request
	 ) {
		String maLoai = request.getParameter("maLoai");
		if (getMaLoai(maLoai)) {
			model.addAttribute("message", "Mã loại bị trùng");
			return "sp/themsp";
		}
		NhanVien nv = (NhanVien) session.getAttribute("user1");
		if(nv==null) {
			return "redirect:/dangnhap.htm";
		}
		String tenSP = request.getParameter("ten");
		String gia = request.getParameter("gia");
		String giaNhap = request.getParameter("giaNhap");
		String cpu = request.getParameter("cpu");
		String ram = request.getParameter("ram");
		String hardware = request.getParameter("hardware");
		String card = request.getParameter("card");
		String screen = request.getParameter("screen");
		String os = request.getParameter("os");
		String moTa = request.getParameter("moTa");
		String theLoai = request.getParameter("theLoai");
		String hang = request.getParameter("hangSanXuat");
		BigDecimal gia1 = new BigDecimal(gia);
		BigDecimal gia2 = new BigDecimal(giaNhap);
		String fileName = saveImage(photo);
		if(fileName == null) {
			fileName = "sp.png";
		}
		LoaiSanPham x = new LoaiSanPham(maLoai, tenSP, gia1, fileName, moTa, cpu, 
				ram, hardware, card, screen, os,gia2, null, null);
		String s = saveLoaiSanPham(x, theLoai, hang, nv);
		if (s.equals("TC")) {
			return "redirect:/home/danh-muc-san-pham.htm";
		}
		model.addAttribute("message", s);
	  return "sp/themsp";
	}