package jp.co.ulsystems.xmldb.input

import javax.servlet.http.HttpServletRequest;

public class SelectListInput {
   private String customer;
   private String title;
   private String location;
   private String charge;

   public void evaluateParams(HttpServletRequest request) throws Exception {
      customer = (String)request.getParameter("customer");
      title = (String)request.getParameter("title");
      location = (String)request.getParameter("location");
      charge = (String)request.getParameter("charge");
   }

   public String createWhere() {
      String where = "";
      //入力された条件からwhrere句の文字列取得
      // 検索条件:お客様名
      if(!customer.equals("")){
         where = " where " + "contains($customer/text(),'" + customer + "')";
      }
      // 検索条件:提案タイトル
      if(!title.equals("")){
         if(where.equals("")){
            where += " where " + "contains($title/text(),'" + title + "')";
         }else{
            where += " and " + "contains($title/text(),'" + title + "')";
         }
      }
      // 検索条件:営業拠点
      if(!location.equals("")){
         if(where.equals("")){
            where += " where " + "contains($location/text(),'" + location + "')";
         }else{
            where += " and " + "contains($location/text(),'" + location + "')";
         }
      }
      // 検索条件:担当営業者
      if(!charge.equals("")){
         if(where.equals("")){
            where += " where " + "contains($charge/text(),'" + charge + "')";
         }else{
            where += " and " + "contains($charge/text(),'" + charge + "')";
         }
      }
      return where;
   }
}