package zr.zrpower.queryengine;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import zr.zrpower.ejb.sys.UIService;
import zr.zrpower.entity.sys.SessionUser;

import zr.zrpower.queryengine.service.QueryControl;
import zr.zrpower.queryengine.Request;
import zr.zrpower.queryengine.mode.QUERY_CONFIG_TABLE;


public class QueryPageSer
    extends HttpServlet {

  public void init() throws ServletException {
  }

  //Process the HTTP Get request
  public void doGet(HttpServletRequest request, HttpServletResponse response) throws
      ServletException, IOException {
    response.setContentType("text/html; charset=GBK");
    request.setCharacterEncoding("GBK");

    QueryControl queryControl = new QueryControl();
    UIService  userUI = new UIService();


    String TITLENAME = request.getParameter("TITLENAME");
    if (TITLENAME == null) {TITLENAME = "";}
    String STB = request.getParameter("STB");
    if (STB == null) {STB = "0";}

    String ISCODE = request.getParameter("ISCODE");
    if (ISCODE == null) {ISCODE = "1";}
    if (ISCODE.length()==0) {ISCODE = "1";}

    if (TITLENAME.length()>0 && ISCODE.equals("1"))
    {
          TITLENAME = new String(TITLENAME.getBytes("iso-8859-1"),"gbk");
    }

    try {

      HttpSession session = request.getSession(true);
      SessionUser user = (SessionUser) session.getAttribute("userinfo");

      Request rq=null;
     try {
       rq = new Request();
       rq.fullItem(request);
     }
     catch (Exception ex) {

     }

     String ID = request.getParameter("ID");
     if (ID == null) {ID = "";}

     //判断访问是否为手机端
     StringBuffer sb=new StringBuffer("");
     sb.append("<script type=\"text/javascript\"> \r\n");

     sb.append("browserRedirect();\r\n");
     sb.append("//jsp判断客户端类型\r\n");
     sb.append("function browserRedirect() { \r\n");
     sb.append("var sUserAgent = navigator.userAgent.toLowerCase();  \r\n");
     sb.append("var bIsIpad = sUserAgent.match(/ipad/i) == \"ipad\"; \r\n");
     sb.append("var bIsIphoneOs = sUserAgent.match(/iphone os/i) == \"iphone os\"; \r\n");
     sb.append("var bIsMidp = sUserAgent.match(/midp/i) == \"midp\";           \r\n");
     sb.append("var bIsUc7 = sUserAgent.match(/rv:1.2.3.4/i) == \"rv:1.2.3.4\";   \r\n");
     sb.append("var bIsUc = sUserAgent.match(/ucweb/i) == \"ucweb\";             \r\n");
     sb.append("var bIsAndroid = sUserAgent.match(/android/i) == \"android\";    \r\n");
     sb.append("var bIsCE = sUserAgent.match(/windows ce/i) == \"windows ce\";     \r\n");
     sb.append("var bIsWM = sUserAgent.match(/windows mobile/i) == \"windows mobile\";    \r\n");
     sb.append("if ((bIsIpad || bIsIphoneOs || bIsMidp || bIsUc7 || bIsUc || bIsAndroid || bIsCE || bIsWM) ){ \r\n");
     sb.append("//访问手机页面            \r\n");
     sb.append("window.location.href=\"QueryPageSerPhone.do?ID="+ID+"\";         \r\n");
     sb.append(" }             \r\n");
     sb.append("}                      \r\n");
     sb.append("</script>\r\n");
     response.getWriter().print(sb);

   String strResult = "";
   strResult = GetTemplateStr(user,request,rq,userUI,queryControl,TITLENAME);
   response.getWriter().print(strResult);

    }
    catch (Exception ex) {
      response.getWriter().print(
          "<p>发生异常！</p><p>详细错误信息:</p><p>" +
          ex.toString() + "</p>");
    }

  }

  //Process the HTTP Post request
  public void doPost(HttpServletRequest request, HttpServletResponse response) throws
      ServletException, IOException {
    doGet(request, response);
  }

  //Clean up resources
  public void destroy() {
  }

  private String GetTemplateStr(SessionUser user,HttpServletRequest _request,Request rq,UIService userUI,QueryControl queryControl,String TITLENAME) {


    StringBuffer sb = new StringBuffer();
    String strRe ="";
    String sumROW = "0";
    String QTABLETYPE = "1";

    String ID = _request.getParameter("ID");
    if (ID == null) {ID = "";}
    String SHOWTITLE = _request.getParameter("SHOWTITLE");
    if (SHOWTITLE == null) {SHOWTITLE = "";}
    String STB = _request.getParameter("STB");
    if (STB == null) {STB = "0";}
    String ALIGN = _request.getParameter("ALIGN");
    if (ALIGN == null) {ALIGN = "center";}
    String XH = _request.getParameter("XH");
    if (XH == null) {XH = "1";}

    String ISCODE = _request.getParameter("ISCODE");
    if (ISCODE == null) {ISCODE = "1";}
    if (ISCODE.length()==0) {ISCODE = "1";}

    String ISNULL = _request.getParameter("ISNULL");
    if (ISNULL == null) {ISNULL = "1";}

    String BUTTONIDS = _request.getParameter("BUTTONIDS");
    if (BUTTONIDS == null) {BUTTONIDS = "";}

    String ifFirstData = _request.getParameter("ifFirstData");
    String strWhere = _request.getParameter("strWhere");
    if(strWhere == null){strWhere = "";}

    String queryFlag =_request.getParameter("queryFlag");
    if(queryFlag == null){queryFlag = "0";}

    String swidth =_request.getParameter("SWIDTH");
    if(swidth == null){swidth = "0";}

    String sheight =_request.getParameter("SHEIGHT");
    if(sheight == null){sheight = "0";}

    String down_height = "278";
    String sum_height = "550";
    int currentPage=1;
    int height;
    try {
      currentPage = Integer.parseInt(_request.getParameter("page"));
    }
    catch (Exception ex) {
      currentPage = 1;
    }


    try {

      QUERY_CONFIG_TABLE queryConfigEntity = queryControl.GetConfigTable(ID);

      if(ifFirstData == null)
      {ifFirstData = queryConfigEntity.getIFFIRSTDATA();}

      String queryHidDis = _request.getParameter("queryDisHid");

      if (queryHidDis != null) {
        if (queryHidDis.trim().length() > 0) {
          queryHidDis = "none";
        }
        else {
          queryHidDis = "";
        }
      }
      else {
        if (queryConfigEntity.getTYPE().equals("2")) {
          queryHidDis = "none";
        }
        else {
          queryHidDis = "";

        }
      }



      sb.append("<HTML>");
      sb.append("<HEAD>");
      sb.append("<TITLE></TITLE>");
      sb.append("<META HTTP-EQUIV=\"Pragma\" CONTENT=\"no-cache\">");
      sb.append(
          "<META http-equiv=\"Content-Type\" content=\"text/html; charset=GBK\">");
      sb.append("<LINK type=\"text/css\" rel=\"stylesheet\" href=\"zrsysmanage/css/").append(
                user.getUserCSS()).append("\">");

      sb.append("<SCRIPT LANGUAGE=\"JavaScript\" src=\"zrsysmanage/script/Public.js\"  type=\"text/jscript\" ></SCRIPT>");
      sb.append("<SCRIPT LANGUAGE=Javascript TYPE=\"text/javascript\" src=\"ZrQueryEngine/Res/coll.js\"></SCRIPT>");


      sb.append("<SCRIPT LANGUAGE=\"JavaScript\" src=\"ZrQueryEngine/Js/QueryEngine.js\"  type=\"text/jscript\" ></SCRIPT>");


      if("html5.css".equals(user.getUserCSS())){
    	  sb.append("<LINK type=\"text/css\" rel=\"stylesheet\" href=\"zrsysmanage/html5/css/style_tables.css\">");
    	  sb.append("<script type=\"text/javascript\" src=\"zrsysmanage/html5/script/jquery-2.0.3.min.js\"></script>");
          sb.append("<script type=\"text/javascript\" src=\"zrsysmanage/html5/layer/layer.js\"></script>");
        //04-25=====================================
          sb.append("<script type=\"text/javascript\" src=\"ZrCollEngine/Datehtml5/laydate.js\"></script>");
          sb.append("<script type=\"text/javascript\" src=\"zrsysmanage/html5/script/systype.js\"></script>");
      }else{
    	  sb.append("<LINK type=\"text/css\" rel=\"stylesheet\" href=\"ZrwebGui/css/").append(
                  user.getUserCSS()).append("\">");
    	  sb.append("<SCRIPT LANGUAGE=\"JavaScript\" src=\"ZrQueryEngine/DatePicker/WdatePicker.js\"  type=\"text/jscript\" ></SCRIPT>");
    	  sb.append("<link rel=\"stylesheet\" type=\"text/css\" media=\"all\" href=\"ZrwebGui/sigma_grid/grid/calendar/calendar-blue.css\" >");
          sb.append("<script type=\"text/javascript\" src=\"ZrwebGui/sigma_grid/grid/calendar/calendar.js\"></script>");
          sb.append("<script type=\"text/javascript\" src=\"ZrwebGui/sigma_grid/grid/calendar/calendar-setup.js\"></script>");
          sb.append("<link rel=\"stylesheet\" type=\"text/css\" href=\"ZrwebGui/sigma_grid/grid/gt_grid.css\">");
          sb.append("<link rel=\"stylesheet\" type=\"text/css\" href=\"ZrwebGui/sigma_grid/grid/skin/vista/skinstyle.css\">");
          sb.append("<link rel=\"stylesheet\" type=\"text/css\" href=\"ZrwebGui/sigma_grid/grid/skin/pink/skinstyle.css\">");
          sb.append("<link rel=\"stylesheet\" type=\"text/css\" href=\"ZrwebGui/sigma_grid/grid/skin/mac/skinstyle.css\">");
          sb.append("<script type=\"text/javascript\" src=\"ZrwebGui/sigma_grid/grid/gt_msg_en.js\"></script>");
          sb.append("<script type=\"text/javascript\" src=\"ZrwebGui/sigma_grid/grid/gt_const.js\"></script>");
          sb.append("<script type=\"text/javascript\" src=\"ZrwebGui/sigma_grid/grid/gt_grid_all.js\"></script>");
      }

      sb.append("</HEAD>");
      sb.append("<BODY class=\"BodyMain\">");
      sb.append(
          "<FORM name=\"recordfrm\" method=\"post\" Action=\"QueryPage.do?ID=").append(
          ID).append("&SHOWTITLE="+SHOWTITLE+"&TITLENAME="+TITLENAME+"&STB="+STB+"&ALIGN="+ALIGN+"&XH="+XH+"&ISCODE="+ISCODE+"&BUTTONIDS="+BUTTONIDS+"&ISNULL="+ISNULL+"\">");
      //页面传递的参数
      String P1, P2, P3, P4, P5;
      P1 = _request.getParameter("P1");
      if (P1 != null) {
        sb.append("<input type=\"hidden\" name=\"P1\" value=\"" ).append(P1).append("\">");
      }

      P2 = _request.getParameter("P2");
      if (P2 != null) {
        sb.append("<input type=\"hidden\" name=\"P2\" value=\"").append(P2).append("\">");
      }

      P3 = _request.getParameter("P3");
      if (P3 != null) {
        sb.append("<input type=\"hidden\" name=\"P3\" value=\"").append(P3).append("\">");
      }

      P4 = _request.getParameter("P4");
      if (P4 != null) {
        sb.append("<input type=\"hidden\" name=\"P4\" value=\"").append(P4).append("\">");
      }

      P5 = _request.getParameter("P5");
      if (P5 != null) {
        sb.append("<input type=\"hidden\" name=\"P5\" value=\"").append(P5).append("\">");
      }


      sb.append("<input type=\"hidden\" name=\"page\" value=\"\">");
      sb.append("<input type=\"hidden\" name=\"setall\" value=\"0\">");
      sb.append("<input type=\"hidden\" name=\"queryDisHid\" value=\"").append(
                queryHidDis).append("\">");
      sb.append("<input type=hidden name=ifFirstData value="+ifFirstData+">");
      sb.append("<input type=hidden name=strWhere value="+strWhere+">");
      sb.append("<input type=hidden name=queryFlag value="+queryFlag+">");
      sb.append("<input type=hidden name=SWIDTH value="+swidth+">");
      sb.append("<input type=hidden name=SHEIGHT value="+sheight+">");

      String getQTABLETYPE = "";
      if (queryConfigEntity.getQTABLETYPE()==null)
      {
        getQTABLETYPE = "1";
      }
      else
      {
        getQTABLETYPE = queryConfigEntity.getQTABLETYPE();
      }
      if (getQTABLETYPE.equals("2"))
      {
        sb.append("<input type=hidden id=selectrow name=selectrow value=0>");
      }else
      {
        sb.append("<input type=hidden id=selectrow  name=selectrow value=x>");
      }

      sb.append("<!--HTML Head表单头显示[显示内容,图标文件,用户肤色的图片文件夹]-->");

      if(!queryConfigEntity.getTYPE().equals("4") && !SHOWTITLE.equals("0"))
      {
        if (TITLENAME.length()==0)
        {
           TITLENAME =  queryConfigEntity.getNAME();
        }
        sb.append(userUI.ShowHeadHtml(TITLENAME, "IcoTitle.gif",user.getUserImage()));
      }



      sb.append("<!--HTML Body Start显示表单开始部分-->");
      sb.append(userUI.ShowBodyStartHtml());
      sb.append(" <TABLE height=\"100%\" width=\"100%\" cellSpacing='0' >");

      //1 一般查询     2 操作查询     3 显示列表    4 嵌入Iframe  5 查询录入项和结果分离
      String queryType = queryConfigEntity.getTYPE();
      String queryItemDis = "";


      if (!queryType.equals("3") && !queryType.equals("4")){

        if(queryType.equals("5") && queryFlag.equals("1"))
        {
          queryItemDis = "none";
        }

        sb.append("<TR height=2><TD></TD></TR>");
        String queryItemStr = queryControl.CreateQueryItem(ID,queryConfigEntity.getQITEMTYPE(),user,rq);


        int ItemRowNum = queryControl.GetQueryItemRowNum(ID,queryConfigEntity.getQITEMTYPE());

        String wh = queryControl.get_query_ts(ID, user.getUserID());
        int U_height =0;
        int D_height =0;
        U_height =Integer.parseInt(wh.split(",")[0]);
        D_height =Integer.parseInt(wh.split(",")[1]);
        down_height = String.valueOf(D_height);

        if (ItemRowNum > 0) {

          height =U_height;
          sum_height  = String.valueOf(height + Integer.parseInt(down_height));



          sb.append("<input type=hidden id=up_height name=up_height value="+String.valueOf(height)+">");
          sb.append("<input type=hidden id=down_height name=down_height value="+down_height+">");


          sb.append("<TR style=\"display:'"+queryItemDis+"'\"><TD  valign=TOP>");
          sb.append("<fieldset style=\"width: 99%;display:'").append(queryHidDis).append(
                    "'\" id=queryItem name=queryItem>");
          sb.append("<legend>查询项目</legend>");
            if(queryType.equals("5") && queryFlag.equals("0"))
            {
              String heightStr="100%";
              if(ItemRowNum>20)
              {
                heightStr = "480px";
              }
              sb.append(" <DIV   style='width:100%;height:"+heightStr+";overflow:auto;'>");

            }else
            {
              sb.append(" <DIV   style='width:100%;height:").append(String.valueOf(height)).append(
                    "px;overflow:auto;'>");
            }



          sb.append("<TABLE border='0' width='99%' cellspacing=\"0\" cellpadding=\"0\" valign=center>");
          sb.append("<TR><TD width=210></TD><TD width=310></TD><TD width=210></TD><TD width=310></TD><TD width=210></TD><TD width=310></TD></TR>");
          sb.append(queryItemStr);
          sb.append("</TABLE>");
          sb.append("</DIV>");

          sb.append("</fieldset>");

          if (STB.equals("1"))
         {
            sb.append("<center><B><font size='5'>"+TITLENAME+"</font></B></center>");
         }


          sb.append("</TD></TR>");
        }else
        {
           ALIGN = "left";
        }

        sb.append("<TR Height=30><TD align="+ALIGN+">");

        sb.append(
            "<table cellspacing=\"0\" cellpadding=\"0\" border='0'><tr align=\"center\">");
        if (ItemRowNum > 0) {

          if(!(queryType.equals("5") && queryFlag.equals("1")))
          {

            sb.append("<td><div id='showquery' name='showquery' style='display:").append(queryHidDis).append("'><table cellspacing=\"0\" cellpadding=\"0\" border='0'><tr align=\"center\"><td>");
            sb.append(userUI.ClickButton("查 询",
                                         "JavaScript:recordfrm.page.value='1';recordfrm.ifFirstData.value='1';recordfrm.queryFlag.value='1';submitquery();",
                                         "IcoBrowse.gif", user.getUserImage()));

            sb.append("</td></tr></table></div></td>");

          }
        }

        if((queryType.equals("5") && queryFlag.equals("1")))
          {
            sb.append(userUI.ClickButton("返 回",
                                        "JavaScript:refh();",
                                        "buttonReturn.gif", user.getUserImage()));
          }

        if(!(queryType.equals("5") && queryFlag.equals("0")))
        {

          if(queryConfigEntity.getIFMULSEL().equals("1"))
          {
            sb.append(userUI.ClickButton("全选/取消",
                                         "JavaScript:SelAllChk('chkRecord');",
                                         "IcoGrade.gif", user.getUserImage()));
          }
          //创建查询按钮
          sb.append(queryControl.CreateButtonNavigate(ID,queryConfigEntity.getQTABLETYPE(),user,BUTTONIDS));

         if( queryConfigEntity.getIFCOMBTN().equals("1"))
         {

           sb.append(userUI.ClickButton1("导出Excel", "expexcel('ZrQueryEngine/ExportExcel.jsp?ID="+ID+"&P1="+P1+"&P2="+P2+"&P3="+P3+"&P4="+P4+"&P5="+P5+"')",
                                        "buttonExcel.gif", user.getUserImage()));

          // sb.append(userUI.ClickButton1("打印",
          //                               "Openprint('ZrQueryEngine/Print/DoPrint.jsp?ID="+ID+"&P1="+P1+"&P2="+P2+"&P3="+P3+"&P4="+P4+"&P5="+P5+"')",
          //                               "70",
          //                               "IcoPrint.gif", user.getUserImage()));

         }
          if (ItemRowNum > 0 && !queryType.equals("5")) {
             sb.append(userUI.ClickButton1("显示/隐藏查询", "JavaScript:showquery();",
                                           "buttonCancel.gif",
                                           user.getUserImage()));
           }

           sb.append("<td width='5'></td><td><a  href=\"JavaScript:query_set('"+ID+"','"+user.getUserWINDOWTYPE()+"');\" ><img border='0' align='absmiddle' src='ZrQueryEngine/Res/query_set.gif'></a></td>");


        }
        sb.append(" </tr></table>");

        sb.append("</TD></TR>");
         sb.append("<TR height=2><TD>");
        sb.append("</TD></TR>");
      }




      sb.append("<TR><TD height=\"99%\" valign=\"top\">");



      if(!(queryType.equals("5") && queryFlag.equals("0")))  //若是5，则在没有查询前是不需要显示的
      {
        QTABLETYPE = queryConfigEntity.getQTABLETYPE();
        if (QTABLETYPE==null){QTABLETYPE="";}
        if (QTABLETYPE.length()==0){QTABLETYPE="1";}
        if (QTABLETYPE.equals("1")&&!"html5.css".equals(user.getUserCSS()))
        {
          sb.append("\r\n<script type=\"text/javascript\">\r\n");
          sb.append("var css = \""+user.getUserCSS()+"\";\r\n");
          sb.append("var skincss = \"vista\";\r\n");
          sb.append("if (css==\"Blue.css\")\r\n");
          sb.append("{skincss = \"vista\";}\r\n");
          sb.append("if (css==\"Public.css\")\r\n");
          sb.append("{skincss = \"default\";}\r\n");
          sb.append("if (css==\"Window.css\" || css==\"nBlue.css\")\r\n");
          sb.append("{skincss = \"mac\";}\r\n");
          sb.append("if (css==\"Yellow.css\")\r\n");
          sb.append("{skincss = \"pink\";}\r\n");
          sb.append("var grid_demo_id = \"myGrid1\";\r\n");


          sb.append(queryControl.GetQueryResultTable(ID,queryConfigEntity.getQTABLETYPE(),queryType,user,rq,P1,P2,P3,P4,P5,ifFirstData,currentPage,swidth,sheight,XH));

          sb.append("\r\n var mygrid=new Sigma.Grid(gridOption);");
          sb.append("Sigma.Util.onLoad( Sigma.Grid.render(mygrid));");
          sb.append("</script>\r\n");

            sb.append("<script type=\"text/javascript\">\r\n");

            if (!swidth.equals("0") && !sheight.equals("0"))
            {
              sb.append("document.write(\"<DIV id='datatable' name='datatable' style='position:absolute;width:"+swidth+";height:"+sheight+";border:inset 1px ;'>\");\r\n");
            }else
            {
              if ((queryType.equals("5") && queryFlag.equals("1")) || queryType.equals("3") || queryType.equals("4"))
              {
                sb.append("document.write(\"<DIV id='datatable' name='datatable' style='position:absolute;width:100%;height:"+sum_height+";border:inset 1px ;'>\");\r\n");
              }else
              {
                 sb.append("document.write(\"<DIV id='datatable' name='datatable' style='position:absolute;width:100%;height:"+down_height+";border:inset 1px ;'>\");\r\n");
              }
            }

            sb.append("</script>\r\n");


          sb.append("<div id='gridtable' name='gridtable' style='position:absolute;border:0px solid #cccccc;background-color:#f3f3f3;padding:5px;height:100%;width:100%;'></div>\r\n");
          sb.append("</DIV>\r\n");

        }else
        {

          if("html5.css".equals(user.getUserCSS())){

              if ((queryType.equals("5") && queryFlag.equals("1")) || queryType.equals("3") || queryType.equals("4"))
              {
                sb.append("<DIV id='datatable' name='datatable' style='position:absolute;width:100%;height:"+sum_height+";overflow:auto;'>");

              }
              else
              {
                sb.append("<DIV id='datatable' name='datatable' style='position:absolute;width:100%;height:"+down_height+";overflow:auto;'>");

              }

        	  sb.append(queryControl.GetQueryResultTable_THREE(ID,user,rq,P1,P2,P3,P4,P5,ifFirstData,currentPage,XH));
          }else{
              if (queryType.equals("5") && queryFlag.equals("1"))
              {
                sb.append("<DIV id='datatable' name='datatable' style='position:absolute;width:100%;height:"+sum_height+";overflow:auto;border:inset 1px ;'>");

              }
              else
              {
                sb.append("<DIV id='datatable' name='datatable' style='position:absolute;width:100%;height:"+down_height+";overflow:auto;border:inset 1px ;'>");

              }

        	  sb.append(queryControl.GetQueryResultTable(ID,queryConfigEntity.getQTABLETYPE(),queryType,user,rq,P1,P2,P3,P4,P5,ifFirstData,currentPage,swidth,sheight,XH));

          }
          sb.append("</DIV>");
        }

      }
      sb.append("</TD></TR>");

      if(!(queryType.equals("5") && queryFlag.equals("0")))  //若是5，则在没有查询前是不需要显示的
      {
        if(ifFirstData.equals("1"))
        {
          sb.append("<TR><TD class='Window_TbE'>");

          sb.append("<TABLE border='0' width='100%' cellspacing='0' cellpadding='0' style=\"background: #dce9f9\">");
          sb.append("<TR>");

          String Navigate1[] = queryControl.CreatePageNavigate(ID,user,P1,P2,P3,P4,P5,currentPage);
          sumROW = Navigate1[1];

          sb.append(Navigate1[0]);


          sb.append("</TD></TR></TABLE>");

          sb.append("</TD></TR>");
        }
      }

      sb.append("</TABLE>");

      sb.append(" <!--HTML Body End显示表单结束部分-->");
      sb.append(userUI.ShowBodyEndHtml()).append(
                " <!--HTML Foot显示表单尾[显示内容，用户肤色的图片文件夹]-->");
      sb.append(userUI.ShowFootHtml("", user.getUserImage()));
      sb.append("</FORM>");
      sb.append("<script language=\"javascript\">");


      //输出必填项js
      String outJS = queryControl.GetIsmustJs(ID,ISNULL);

      sb.append(outJS+"\r\n");
      sb.append("function showquery(){\r\n");
      sb.append("var up_height = document.recordfrm.up_height.value;\r\n");


      if("html5.css".equals(user.getUserCSS())){
        sb.append("var down_height = parseInt(document.body.clientHeight)-parseInt(up_height)-100;\r\n");
        sb.append("var sum_height = parseInt(document.body.clientHeight)-70;\r\n");
      }else
      {
        sb.append("var down_height = parseInt(document.body.clientHeight)-parseInt(up_height)-125;\r\n");
        sb.append("var sum_height = parseInt(document.body.clientHeight)-90;\r\n");
      }



      sb.append("var isshow = document.all.queryItem.style.display;\r\n");


      sb.append("if (isshow=='none'){document.all.queryItem.style.display='';document.all.showquery.style.display='';document.getElementById('datatable').style.height=down_height;}else{document.all.queryItem.style.display='none';document.all.showquery.style.display='none';document.getElementById('datatable').style.height=sum_height;} \r\n");

      sb.append("document.recordfrm.queryDisHid.value=document.all.queryItem.style.display;\r\n");

      sb.append("}\r\n");

     sb.append("function SetSelectValue(SelectId, DictTable){\r\n");


       //网页形式字典选择----------------
            sb.append("var mFileUrl =\"ZrQueryEngine/selectDictPage.jsp?DictTable=\"+DictTable+\"&SelectId=\"+SelectId;\r\n");
            sb.append("var strValue=window.showModalDialog(mFileUrl,window,'status:no;help:no;dialogHeight:312px;dialogWidth:382px');\r\n");
            sb.append("if (strValue!=null){var arrTmp = strValue.split('/');\r\n");
            sb.append("document.getElementById(SelectId).options.length = 0;\r\n");
            sb.append("document.getElementById(SelectId).options[0] = new Option(arrTmp[1],arrTmp[0]);\r\n");
            sb.append("document.getElementById(SelectId).options[0].selected = true;\r\n");
            sb.append("document.getElementById(SelectId).options[0].className = 'selectlist';}\r\n");
        //网页形式-----------------

       sb.append("}\r\n");

      //sb.append("mCodeInput.SkinStyle=" + user.getUserWINDOWTYPE() + ";");

      sb.append("function TableOndblclick()");
      sb.append("{");
      String scriptStr = "";
      try {

        scriptStr = queryControl.CreateButtonScript(queryControl.getButtonByID(
            queryConfigEntity.getBID()),ID);
      }
      catch (Exception ex) {

      }
      if (scriptStr.trim().length() > 0) {
        sb.append("parseButtonJs(\"").append(scriptStr).append("\");");
      }
      sb.append("}\r\n");

      sb.append("function TableOnclick()");
      sb.append("{");
      scriptStr = "";
      try {

        scriptStr = queryControl.CreateButtonScript(queryControl.getButtonByID(
            queryConfigEntity.getCID()),ID);
      }
      catch (Exception ex) {

      }
      if (scriptStr.trim().length() > 0) {
        sb.append("parseButtonJs(\"").append(scriptStr).append("\");");
      }
      sb.append("}\r\n");


      sb.append("function ExeOndblclick(id)");
      sb.append("{");
      scriptStr = "";
      try {

        scriptStr = queryControl.CreateButtonScript(queryControl.getButtonByID(
            queryConfigEntity.getBID()),ID);
      }
      catch (Exception ex) {

      }
      if (scriptStr.trim().length() > 0) {
    	//04-25========================================================================
    	  if("html5.css".equals(user.getUserCSS())){
    		  sb.append("parseButtonJsHtml_value(\"").append(scriptStr).append("\");");
    	  }else{
    		  sb.append("parseButtonJs_B(\"").append(scriptStr).append("\",id);");
    	  }
      }
      sb.append("}\r\n");

      sb.append("function ExeOnclick(id)");
      sb.append("{");
      scriptStr = "";
      try {

        scriptStr = queryControl.CreateButtonScript(queryControl.getButtonByID(
            queryConfigEntity.getCID()),ID);
      }
      catch (Exception ex) {

      }
      if (scriptStr.trim().length() > 0) {
    	//04-25======================================================================================
          if("html5.css".equals(user.getUserCSS())){
        	  sb.append("parseButtonJsHtml_value(\"").append(scriptStr).append("\");");
    	  }else{
    		  sb.append("parseButtonJs_B(\"").append(scriptStr).append("\",id);");
    	  }
      }
      sb.append("}\r\n");


      sb.append("function expexcel(url){\r\n");
      sb.append("url=url+'&crow="+sumROW+"';\r\n");
      sb.append("var name='PopWindow';\r\n");
      sb.append("var ShowPopWindow = null;");
      sb.append("var status='toolbar=no,location=no,directories=no,menubar=no,resizable=yes,scrollbars=yes,width=400,height=250';");
      sb.append("ShowPopWindow = window.open(url,name,status);");
      sb.append("ShowPopWindow.moveTo(280,200);");
      sb.append("ShowPopWindow.focus();");
      sb.append("}\r\n");

      sb.append("function setdataw(){\r\n");

      if (queryType.equals("2"))
      {
         sb.append("document.all.queryItem.style.display='';\r\n");
         sb.append("showquery();\r\n");
      }else
      {
         sb.append("var up_height = document.recordfrm.up_height.value;\r\n");
          if("html5.css".equals(user.getUserCSS())){
            sb.append("var down_height = parseInt(document.body.clientHeight)-parseInt(up_height)-95;\r\n");
          }else
          {
            sb.append("var down_height = parseInt(document.body.clientHeight)-parseInt(up_height)-120;\r\n");
          }

         sb.append("document.getElementById('datatable').style.height=down_height;\r\n");



      }
       if(queryType.equals("5") && queryFlag.equals("1"))
       {
         sb.append("document.all.queryItem.style.display='none';document.all.showquery.style.display='none'; \r\n");

       }



      sb.append("}\r\n");

      //html5 需要-----------------
      if("html5.css".equals(user.getUserCSS())){
    	  sb.append("document.all(\"selectrow\").value='1';\r\n");
    	  sb.append("var allvalue=\"\";\r\n");
    	  sb.append("function clickValue(value){\r\n");
    	  sb.append("allvalue=value;\r\n");
    	  sb.append("}\r\n");
      }
      //html5 结束----------------

      sb.append("function refh(){\r\n");
      sb.append("document.recordfrm.page.value='1';\r\n");
      sb.append("document.recordfrm.queryFlag.value='0';\r\n");
      sb.append("document.recordfrm.submit();\r\n");
      sb.append("}\r\n");


      sb.append("setTimeout(\"setdataw()\",300);\r\n");


      sb.append(" </script>");

      sb.append("</BODY>");
      sb.append("</HTML>");

        strRe = sb.toString();
        //将按钮带有参数的替换成实际的参数值
        if (P1 == null) {P1="";}
        if (P2 == null) {P2="";}
        if (P3 == null) {P3="";}
        if (P4 == null) {P4="";}
        if (P5 == null) {P5="";}
        strRe=strRe.replaceAll("\\{P1\\}",P1);
        strRe=strRe.replaceAll("\\{P2\\}",P2);
        strRe=strRe.replaceAll("\\{P3\\}",P3);
        strRe=strRe.replaceAll("\\{P4\\}",P4);
        strRe=strRe.replaceAll("\\{P5\\}",P5);
        //--------------

      HttpSession session = _request.getSession(true);
      session.setAttribute("queryControl", queryControl);

    }
    catch (Exception ex) {
      return "";
    }

    user = null;
    userUI = null;
    queryControl = null;
    _request = null;

    return strRe;
  }
}
