/**
 * Copyright (c) 2003-2004 System Integrator Corporation.
 *                 All Rights Reserved.
 */
package jp.co.sint.servlet.mallmgr;

import java.io.IOException;
import java.sql.SQLException;

import javax.naming.NamingException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import jp.co.sint.basic.SILogin;
import jp.co.sint.beans.mallmgr.UICmdtyListCond;
import jp.co.sint.beans.mallmgr.UIRegCmdty;
import jp.co.sint.config.SIConfig;
import jp.co.sint.database.SIDatabaseConnection;
import jp.co.sint.servlet.SIServlet;
import jp.co.sint.tools.SIHTMLUtil;
import jp.co.sint.tools.SIUtil;
import jp.co.sint.tools.SIURLParameter;

import org.apache.log4j.Category;
  
/**
 * @version $Id: SISelectCmdtySrv.java,v 1.0 2004/11/2 Exp $
 * @author  Shionoya Yoshiaki
 * <br>Description: 商品検索を行うServlet
 * <p>History</p>
 * <p>Author&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Date&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Reason</p>
 * ============&nbsp;&nbsp;&nbsp;==========&nbsp;&nbsp;===========================<br>
 * Shionoya Yoshiaki   2004/11/4  Original
 */

public class SISearchCmdtySrv extends SIServlet {
  //ログ用のインスタンスの生成
  private static Category log = Category.getInstance(SIConfig.SILOG4J_WEBSHOP_CATEGORY_NAME);
  
  /**
   * <b>doUpdate</b>
   * HTTP リクエストの処理
   * @param  なし
   * @return なし
   * @throws ServletException
   * @throws IOException
   */
  public void doUpdate(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    SILogin manLogin=SIHTMLUtil.getLogin(request);
    if (!manLogin.isLogin()){
      forwardKey(request,response,"webshop.jsp.manager.login");
      return;
    }
    
    HttpSession session = request.getSession(true); //セッションの取得
    SIDatabaseConnection databaseConnection = new SIDatabaseConnection(); //DBへのコネクションの作成
    SIURLParameter urlParam = new SIURLParameter(request);
    
    try {
      String actionName = this.getActionName(urlParam); //画面からのアクション
      String editMode = this.getEditMode(urlParam); //DBへの編集モード
      String lFromName = (String)urlParam.getParam("formName");
      String lInputCmdtyName = (String)urlParam.getParam("inputCmdtyName");
      
      UIRegCmdty regCmdty = new UIRegCmdty();
      UICmdtyListCond cmdtyList = new UICmdtyListCond();
      
      if (this.getServletPath(request).equals("/mallmgr/SearchCmdtySrv2")) { //検索２
        //データの取得とデータのチェック
        cmdtyList = new UICmdtyListCond(request,urlParam);
        if(SIUtil.isNotNull(lFromName)) cmdtyList.setFormName(lFromName);
        if(SIUtil.isNotNull(lInputCmdtyName)) cmdtyList.setInputCmdtyName(lInputCmdtyName);
        cmdtyList.init(request,urlParam);
        cmdtyList.validateList(request);
        session.setAttribute(SIConfig.SISESSION_MAN_CMDTY_LIST_NAME, cmdtyList);
        forwardKey(request, response, "webshop.jsp.manager.search.cmdty2");
        
      // EDBTG003-00 elecs-matsushima add start
      } else if (this.getServletPath(request).equals("/mallmgr/SearchCmdtySetSrv")) { //構成商品検索
        if (SIConfig.SIACTION_LIST.equalsIgnoreCase(actionName)) { //一覧と検索などの画面
          //データの取得とデータのチェック
          cmdtyList = new UICmdtyListCond(request,urlParam);
          if(SIUtil.isNotNull(lFromName)) cmdtyList.setFormName(lFromName);
          if(SIUtil.isNotNull(lInputCmdtyName)) cmdtyList.setInputCmdtyName(lInputCmdtyName);
          cmdtyList.init(request,urlParam);
          cmdtyList.validateList(request);
          session.setAttribute(SIConfig.SISESSION_MAN_CMDTY_LIST_NAME, cmdtyList);
          forwardKey(request, response, "webshop.jsp.manager.search.cmdty.set");
        } else if (SIConfig.SIACTION_MODIFY.equalsIgnoreCase(actionName)){//一覧に戻る
          regCmdty = new UIRegCmdty(request,urlParam);
          regCmdty.reset(databaseConnection.getConnection());
          forwardKey(request, response, "webshop.jsp.manager.order.update.delivery");
        }
      // EDBTG003-00 elecs-matsushima add start
      }else{
        if (SIConfig.SIACTION_LIST.equalsIgnoreCase(actionName)) { //一覧と検索などの画面
          //データの取得とデータのチェック
          cmdtyList = new UICmdtyListCond(request,urlParam);
          if(SIUtil.isNotNull(lFromName)) cmdtyList.setFormName(lFromName);
          if(SIUtil.isNotNull(lInputCmdtyName)) cmdtyList.setInputCmdtyName(lInputCmdtyName);
          cmdtyList.init(request,urlParam);
          cmdtyList.validateList(request);
          session.setAttribute(SIConfig.SISESSION_MAN_CMDTY_LIST_NAME, cmdtyList);
          forwardKey(request, response, "webshop.jsp.manager.search.cmdty");
        } else if (SIConfig.SIACTION_MODIFY.equalsIgnoreCase(actionName)){//一覧に戻る
          regCmdty = new UIRegCmdty(request,urlParam);
          regCmdty.reset(databaseConnection.getConnection());
          forwardKey(request, response, "webshop.jsp.manager.order.update.delivery");
        }
      }
    }catch (SQLException e){
      e.printStackTrace();
      throw new ServletException();
    }catch (NamingException e){
      e.printStackTrace();
      throw new ServletException();
    }finally{
      databaseConnection.close();
    }
  }
  
  public void destroy() {
  }
}