package com.highcom.action; import java.io.IOException; import java.util.ArrayList; import java.util.Map; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.highcom.dao.GoodsDao; import com.highcom.util.Paging; import com.highcom.vo.Goods; @SuppressWarnings("serial") public class GoodsServlet extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { this.doPost(request, response); } public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String method = request.getParameter("method"); if ("query".equals(method)) { String pNo = request.getParameter("pageNo"); int pageNo= 1; if (pNo!=null) { pageNo = Integer.parseInt(pNo); } GoodsDao gdao = new GoodsDao(); int totalCount = (int) gdao.getTotalCount(); ArrayList<Map<String,Object>> list = gdao.queryAll(pageNo); request.setAttribute("list", list); request.setAttribute("pageNo", pageNo); request.setAttribute("fg", 0); request.setAttribute("totalPage", Paging.getTotalPage(totalCount)); request.getRequestDispatcher("gselect.jsp").forward(request, response); } else if ("add".equals(method)){ String gname = request.getParameter("gname"); String gprice = request.getParameter("gprice"); String gpdate= request.getParameter("datetime"); String gqdate= request.getParameter("gqdate"); String suid = request.getParameter("supplier"); Goods goods = new Goods(); goods.setG_name(gname); goods.setG_price(Float.parseFloat(gprice)); goods.setG_pdate(gpdate); goods.setG_qdate(gqdate); goods.setSu_id(Long.parseLong(suid)); GoodsDao gdao = new GoodsDao(); gdao.insert(goods); response.sendRedirect("GoodsServlet?method=query"); } else if("delete".equals(method)) { String id[] = request.getParameterValues("check"); StringBuffer sql = new StringBuffer(); sql.append("UPDATE t_goods SET g_flag = 1 WHERE g_id IN ("); int j =1; for(int i =0;i<id.length;i++){ if(j<id.length){ sql.append(id[i]+","); } else { sql.append(id[i]+")"); } j++; } GoodsDao gdao = new GoodsDao(); gdao.update(sql.toString()); response.sendRedirect("GoodsServlet?method=query"); } else if("queryByid".equals(method)){ String id = request.getParameter("id"); GoodsDao gdao = new GoodsDao(); ArrayList<Map<String,Object>> list = gdao.queryByid(id); ArrayList<Map<String,Object>> lst = gdao.querySupplier(); request.setAttribute("list", list); request.setAttribute("lst", lst); request.getRequestDispatcher("goodsupdate.jsp").forward(request, response); } else if("update".equals(method)){ String id = request.getParameter("id"); String gname = request.getParameter("gname"); String gprice = request.getParameter("gprice"); String gpdate= request.getParameter("gpdate"); String gqdate= request.getParameter("gqdate"); String suid = request.getParameter("supplier"); Goods goods = new Goods(); goods.setG_id(Long.parseLong(id)); goods.setG_name(gname); goods.setG_price(Float.parseFloat(gprice)); goods.setG_pdate(gpdate); goods.setG_qdate(gqdate); goods.setSu_id(Long.parseLong(suid)); GoodsDao gdao = new GoodsDao(); gdao.edit(goods); response.sendRedirect("GoodsServlet?method=query"); }else if ("queryid".equals(method)) { String pNo = request.getParameter("pageNo"); int pageNo= 1; if (pNo!=null) { pageNo = Integer.parseInt(pNo); } String id = request.getParameter("id"); String name = request.getParameter("name"); GoodsDao gdao = new GoodsDao(); ArrayList<Map<String,Object>> list = gdao.queryByid(id,name); request.setAttribute("pageNo", pageNo); request.setAttribute("totalPage", 1); request.setAttribute("list", list); request.setAttribute("fg", 1); request.getRequestDispatcher("gselect.jsp").forward(request,response); } } }
最近下载更多
Boss绝 LV9
6月25日
2036495585 LV9
2023年10月6日
KrisNo10000 LV2
2023年3月1日
TangWeiyu LV3
2021年12月15日
zxyBEIKE LV1
2021年10月10日
wanglinddad LV55
2021年6月21日
ruoyou168 LV12
2021年5月28日
戴佳臻 LV7
2021年4月26日
陈祥图 LV6
2020年12月31日
zuihaofdfdfdfdddd LV10
2020年12月22日