GoodManagerAction.java
资源名称:Jason.rar [点击查看]
上传用户:wok5188
上传日期:2018-02-20
资源大小:1835k
文件大小:8k
源码类别:
MySQL数据库
开发平台:
Java
- /*
- * Generated by MyEclipse Struts
- * Template path: templates/java/JavaClass.vtl
- */
- package com.center.control;
- import java.io.IOException;
- import java.io.PrintWriter;
- import java.sql.Connection;
- import java.sql.SQLException;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.Map;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- import javax.servlet.http.HttpSession;
- import org.apache.struts.action.ActionForm;
- import org.apache.struts.action.ActionForward;
- import org.apache.struts.action.ActionMapping;
- import org.apache.struts.actions.LookupDispatchAction;
- import com.center.commons.DataConnect;
- import com.center.dto.GoodDTO;
- import com.center.model.Goodmodel;
- import com.center.util.DealString;
- /**
- * MyEclipse Struts
- * Creation date: 05-16-2007
- *
- * XDoclet definition:
- * @struts.action path="/goodUpdate" name="goodUpdateForm" input="/show/admin/goodUpdate.jsp" parameter="method" scope="request" validate="true"
- * @struts.action-forward name="ok" path="/ok.jsp"
- * @struts.action-forward name="err" path="/err.jsp"
- */
- public class GoodManagerAction extends LookupDispatchAction {
- /*
- * Generated Methods
- */
- /**
- * Method execute
- * @param mapping
- * @param form
- * @param request
- * @param response
- * @return ActionForward
- */
- private GoodDTO gooddto;
- public HttpSession session;
- private Connection conn;
- public GoodManagerAction() {
- // TODO Auto-generated constructor stub
- this.conn = new DataConnect().getConn();
- }
- public ActionForward publishgood(ActionMapping mapping, ActionForm form,
- HttpServletRequest request, HttpServletResponse response) throws SQLException {
- GoodForm goodForm = (GoodForm) form;// TODO Auto-generated method stub
- gooddto = new GoodDTO();
- gooddto.setGoodname(DealString.toGBK(goodForm.getGoodname()));
- gooddto.setGoodtype(DealString.toGBK(goodForm.getGoodtype()));
- gooddto.setGoodprice(goodForm.getGoodprice());
- gooddto.setGooddesc(DealString.toGBK(goodForm.getGooddesc()));
- gooddto.setPublishtime(DealString.toGBK(DealString.getDateTime()));
- gooddto.setPublisher(DealString.toGBK(goodForm.getGoodpublisher()));
- // System.out.println(gooddto.getGoodprice());
- new GoodManagerAction();
- Goodmodel goodmodel = new Goodmodel(conn);
- int i = goodmodel.goodpublish(gooddto);
- if(i == 1){
- try {
- System.out.println(i);
- response.sendRedirect(request.getContextPath()+"/show/admin/publishgoodok.jsp");
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }else{
- try {
- response.sendRedirect(request.getContextPath()+"/show/admin/publishgooderr.jsp");
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- try {
- conn.close();
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- return null;
- }
- public ActionForward delgood(ActionMapping mapping, ActionForm form,
- HttpServletRequest request, HttpServletResponse response) {
- GoodForm goodForm = (GoodForm) form;// TODO Auto-generated method stub
- new GoodManagerAction();
- String goodid = request.getParameter("goodid");
- if(goodid != null){
- Goodmodel goodmodel = new Goodmodel(conn);
- String[] goodids = goodid.split("|");
- StringBuffer delres = null;
- int k[] = null;
- for(int i = 0;i < goodids.length;i++){
- k[i] = goodmodel.delgood(goodids[i]);
- if(k[i] > 0){
- delres.append("操作成功");
- }
- }
- HttpSession session = request.getSession();
- session.setAttribute("del", delres);
- try {
- response.sendRedirect("/delgoodok.jsp");
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }else{
- try {
- response.sendRedirect("/delgooderr.jsp");
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- try {
- conn.close();
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- return null;
- }
- public ActionForward updatagood(ActionMapping mapping, ActionForm form,
- HttpServletRequest request, HttpServletResponse response) {
- GoodForm goodForm = (GoodForm) form;// TODO Auto-generated method stub
- gooddto = new GoodDTO();
- gooddto.setGoodname(goodForm.getGoodname());
- gooddto.setGoodtype(goodForm.getGoodtype());
- gooddto.setGoodprice(goodForm.getGoodprice());
- gooddto.setGooddesc(goodForm.getGooddesc());
- gooddto.setPublishtime(DealString.getDateTime());
- gooddto.setPublisher(goodForm.getGoodpublisher());
- new GoodManagerAction();
- int i = 0;
- if(gooddto != null){
- Goodmodel goodmodel = new Goodmodel(conn);
- i = goodmodel.updatagood(gooddto);
- }
- if(i == 1){
- try {
- response.sendRedirect("/updatagoodok.jsp");
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }else{
- try {
- response.sendRedirect("/updatagooderr.jsp");
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- try {
- conn.close();
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- return null;
- }
- public ActionForward showgoods(ActionMapping mapping, ActionForm form,
- HttpServletRequest request, HttpServletResponse response) throws SQLException {
- GoodForm goodForm = (GoodForm) form;// TODO Auto-generated method stub
- String strname = request.getParameter("goodname");
- String strtype = request.getParameter("goodtype");
- System.out.println(DealString.toGBK(strname)+DealString.toGBK(strtype));
- if(strtype != null || strtype != ""){
- strtype = DealString.toGBK(strtype);
- }
- if(strname != null || strname != ""){
- strname = DealString.toGBK(strname);
- }
- session = request.getSession();
- conn = new DataConnect().getConn();
- Goodmodel goodmodel = new Goodmodel(conn);
- ArrayList goodlist = goodmodel.showgoods(strname,strtype);
- if(goodlist.size()>0){
- session = request.getSession();
- session.setAttribute("goodinfo", goodlist);
- System.out.println("显示"+goodlist.size());
- try {
- response.sendRedirect(request.getContextPath()+"/show/admin/goodshow.jsp");
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }else{
- try {
- response.sendRedirect(request.getContextPath()+"/show/admin/nogood.jsp");
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- try {
- conn.close();
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- return null;
- }
- public ActionForward setcommend(ActionMapping mapping, ActionForm form,
- HttpServletRequest request, HttpServletResponse response) throws IOException, SQLException {
- GoodForm goodForm = (GoodForm) form;// TODO Auto-generated method stub
- String good_id = request.getParameter("goodid");
- String actiona = request.getParameter("actionc");
- int actionc = Integer.parseInt(actiona);
- int goodid = Integer.parseInt(good_id);
- response.setContentType("text/html;charset=gbk");
- PrintWriter out = response.getWriter();
- int k = 0;
- new GoodManagerAction();
- Goodmodel goodmodel = new Goodmodel(conn);
- k = goodmodel.commendgoods(goodid,actionc);
- if(k == 1){
- out.write("<script language=javascript>window.close();alert('推荐成功');</script>");
- }
- if(k == 2){
- out.write("<script language=javascript>window.close();alert('设为特价');</script>");
- }
- if(k == 3){
- out.write("<script language=javascript>window.close();alert('设为精品');</script>");
- }
- out.flush();
- out.close();
- try {
- conn.close();
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- return null;
- }
- protected Map getKeyMethodMap() {
- // TODO Auto-generated method stub
- Map map = new HashMap();
- map.put("button.save", "publishgood");
- map.put("button.show", "showgoods");
- map.put("show", "showgoods");
- map.put("setcommend", "setcommend");
- // map.put("button.save", "publishgood");
- // map.put("button.save", "publishgood");
- return map;
- }
- }