brand.setName(name);
brand.setDescription(description);
brand.setImageUrl(imageUrl);
ApplicationContext ac = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
IGatewayService gatewayService = (IGatewayService) ac.getBean("gatewayService");
long lsupplierid = -1;
try {
lsupplierid = Long.parseLong(supplierid);
} catch (Exception e) {
lsupplierid = -1;
}
Supplier supplier = gatewayService.findSupplier(lsupplierid);
if(supplier==null) {
out.print("({'result':'0','msg':'添加失败,未找到对应的供应商!'})");
out.flush();
return;
}
if(gatewayService.chechBrandNameExsits(name)) {
out.print("({'result':'0','msg':'添加失败,品牌名称已存在!'})");
out.flush();
return;
}
brand.setSupplier(supplier);
gatewayService.createBrand(brand);
out.print("({'result':'1','msg':'成功添加品牌!'})");
out.flush();
return;
} else if("2".equals(operation)) {
String id = request.getParameter("id");
long lid = -1;
try {
lid = Long.parseLong(id);
} catch (Exception e) {
lid = -1;
}
ApplicationContext ac = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
IGatewayService gatewayService = (IGatewayService) ac.getBean("gatewayService");
Brand brand = gatewayService.findBrandById(lid);
if(brand==null) {
out.print("({'result':'0','msg':'修改的品牌信息不存在!'})");
out.flush();
return;
}
String name = request.getParameter("name");
/*if(gatewayService.chechBrandNameExsits(name)) {
out.print("({'result':'0','msg':'修改失败,品牌名称已存在!'})");
out.flush();
return;
}*/
String description = request.getParameter("description");
String imageUrl = request.getParameter("imageUrl");
String supplierid = request.getParameter("supplierid");
brand.setName(name);
brand.setDescription(description);
brand.setImageUrl(imageUrl);
long lsupplierid = -1;
try {
lsupplierid = Long.parseLong(supplierid);
} catch (Exception e) {
lsupplierid = -1;
}
Supplier supplier = gatewayService.findSupplier(lsupplierid);
if(supplier==null) {
out.print("({'result':'0','msg':'修改失败,未找到对应的供应商!'})");
out.flush();
return;
}
brand.setSupplier(supplier);
gatewayService.updateBrand(brand);
out.print("({'result':'1','msg':'修改品牌信息成功!'})");
out.flush();
return;
} else if("3".equals(operation)) {
String id = request.getParameter("id");
long lid = -1;
try {
lid = Long.parseLong(id);
} catch (Exception e) {
lid = -1;
}
ApplicationContext ac = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
IGatewayService gatewayService = (IGatewayService) ac.getBean("gatewayService");
gatewayService.deleteBrand(lid);
request.getRequestDispatcher("page/gateway/admin/brand/BrandList.jsp").forward(request, response);
}
}