<%@page contentType="text/html; charset=GBK" %>

<%@page import="zr.zrpower.common.util.SysPreperty"%>
<%@page import="zr.zrpower.ejb.sys.UIService"%>
<%@ page import = "zr.zrpower.analyseengine.mode.Variable"%>
<%@ page import = "zr.zrpower.analyseengine.service.StatisticsConfig"%>
<%@ page import = "zr.zrpower.analyseengine.mode.ANALYSE_STATISTICS_MAIN"%>

<%@ page import = "java.lang.Object"%>
<%@ page import="java.util.*"%>
<%@page import="zr.zrpower.entity.sys.SessionUser"%>


<html>
<%SessionUser user = (SessionUser) session.getAttribute("userinfo");

StatisticsConfig StatisticsCfg =  new StatisticsConfig();
String strID=request.getParameter("ID");
ANALYSE_STATISTICS_MAIN[] STATISTICS = StatisticsCfg.getANALYSE_STATISTICS_MAIN(strID);
String StrWhere = " TableName ='"+STATISTICS[0].getTABLEID()+"'";
int iLength1 = 0;
List list1=new ArrayList();

Variable[] Variables = null;
Variables = StatisticsCfg.GetVariableList();
  request.setCharacterEncoding("GBK");
String strResult=request.getParameter("strResult");

//html5用到
  String userClass="windowimg";
  String zdid=request.getParameter("zdid");
  if(!"6".equals(user.getUserImage())){
     userClass=user.getUserImage();
  }
%>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GBK">
<META HTTP-EQUIV="pragma" CONTENT="no-cache">
<META HTTP-EQUIV="Cache-Control" CONTENT="no-cache, must-revalidate">
<META HTTP-EQUIV="expires" CONTENT="0">
<title><%=SysPreperty.getProperty().SystemName%><%=SysPreperty.getProperty().Versoin%></title>

<link REL="stylesheet" type="text/css" href="../../zrsysmanage/css/<%=user.getUserCSS()%>">
<SCRIPT LANGUAGE="JavaScript" src="../../zrsysmanage/script/Public.js"></SCRIPT>
<SCRIPT LANGUAGE="JavaScript" src="../../zrsysmanage/script/DealList.js"></SCRIPT>

<script type='text/javascript' src='../../dwr/engine.js'></script>
<script type='text/javascript' src='../../dwr/util.js'></script>
<script type='text/javascript' src='../../dwr/interface/AnalyseConfigBean.js'></script>

<script Language="javascript">
function btnSpecialValue(strValue)
{
  if(CheckInputWhereExpression(RegForm.txtResult.value,strValue))
     RegForm.txtResult.value=RegForm.txtResult.value+strValue;
}

function ShowHelpModal()
{

  var url='formulaHelp.jsp';
  var status='dialogHeight:600px;dialogWidth:500px;status:0;help:no;center:yes';
  window.showModalDialog(url,window,status);
}


    function fillFieldName(obj)
   {
     var table=RegForm.TableList;
     fieldName="["+table.options[table.selectedIndex].value+"."+obj.options[obj.selectedIndex].value+"]";
     RegForm.txtResult.value= RegForm.txtResult.value+fieldName;
   }

  function   fillVariable(obj)
  {
   RegForm.txtResult.value=RegForm.txtResult.value+obj.options[obj.selectedIndex].value;
  }

  function  OKClick()
  {


    <%if("6".equals(user.getUserImage())){%>
    var index = parent.layer.getFrameIndex(window.name); //获取窗口索引

      parent.$('#<%=zdid%>').val(RegForm.txtResult.value);
      parent.layer.close(index);
    <%}else{%>
      window.returnValue=RegForm.txtResult.value;
   window.close();
    <%}%>
  }
</script>

</head>
<%
  UIService userUI = new UIService();
%>
<body class="BodyMain">
<form action="" method="post" name="RegForm">
<!--HTML Head表单头显示[显示内容，用户肤色的图片文件夹]-->
<%=userUI.ShowHeadHtml("设置管理",user.getUserImage())%>
<!--HTML Body Start显示表单开始部分-->
<%=userUI.ShowBodyStartHtml()%>


  <fieldset style="width:95%">
    <legend>默认值</legend>
      <table border='0' width="99%" cellspacing="0" cellpadding="0" align=center>
                <tr>
                  <td colspan="2">
                    <table border='0' width="100%" cellspacing="0" cellpadding="0" align=center>
                      <tr>
                        <td width="35%" align="center" height=23>
                          待选表
                        </td>
                        <td width="10%" align="center">
                          待选字段
                        </td>
                        <td width="10%" align="center">
                          待选变量值
                        </td>
                        <td width="45%" align="center"></td>
                      </tr>
                      <tr>
                        <td align="center">
                          <select id="TableList" name="TableList" style=" WIDTH: 200px;height:150px;" size=15 onchange='loadFieldList(this.value)' >
                          </select>
                        </td>
                        <td align=center>
                          <select id="FieldList" name="FieldList" style=" WIDTH: 130px;height:150px;" size=15 onclick="fillFieldName(this)">
                          </select>
                        </td>
                        <td  align="center" >
                          <select name="VaribleList" style=" WIDTH: 130px;height:150px;" size=15 onchange="fillVariable(this)" >
                          <%
                          if(Variables!=null)
                          {
                            for(int i=0;i< Variables.length;i++)
                            {
                              out.print("<option value=\""+Variables[i].getCODE()+"\">"+Variables[i].getNAME()+"</option>");
                            }
                          }
                          %>
                           <Option value="^UserIdea^">用户意见(流程内置变量)</Option>
                          </select>
                        </td>
                        <td align="center" valign="top">

                          <input  type="button" value="+" class="Button1" onclick="btnSpecialValue('+')"/>
                          <input  type="button" value="-" class="Button1" onclick="btnSpecialValue('-')"/>
                          <input  type="button" value="*" class="Button1" onclick="btnSpecialValue('*')"/>
                          <input  type="button" value="/" class="Button1" onclick="btnSpecialValue('/')"/>
                           <input  type="button" value=">" class="Button1" onclick="btnSpecialValue('>')"/>
                          <input  type="button" value=">=" class="Button1" onclick="btnSpecialValue('>=')"/><br /><br />
                          <input  type="button" value="<"  class="Button1" onclick="btnSpecialValue('<')"/>
                          <input  type="button" value="<=" class="Button1" onclick="btnSpecialValue('<=')"/>
                          <input  type="button" value="!=" class="Button1" onclick="btnSpecialValue('!=')"/>
                          <input  type="button" value="=" class="Button1" onclick="btnSpecialValue('=')"/>
                          <input  type="button" value="(" class="Button1" onclick="btnSpecialValue('(')"/>
                          <input  type="button" value=")" class="Button1" onclick="btnSpecialValue(')')"/><br /><br />
                          <input  type="button" value="AND" class="Button1" onclick="btnSpecialValue(' AND ')"/>
                          <input  type="button" value="OR" class="Button1" onclick="btnSpecialValue(' OR ')"/>
                          <input  type="button" value="0" class="Button1" onclick="btnSpecialValue('0')"/>
                          <input  type="button" value="1" class="Button1" onclick="btnSpecialValue('1')"/>
                          <input  type="button" value="2" class="Button1" onclick="btnSpecialValue('2')"/>
                          <input  type="button" value="3" class="Button1" onclick="btnSpecialValue('3')"/><br /><br />
                          <input  type="button" value="4" class="Button1" onclick="btnSpecialValue('4')"/>
                          <input  type="button" value="5" class="Button1" onclick="btnSpecialValue('5')"/>
                          <input  type="button" value="6" class="Button1" onclick="btnSpecialValue('6')"/>
                          <input  type="button" value="7" class="Button1" onclick="btnSpecialValue('7')"/>
                          <input  type="button" value="8" class="Button1" onclick="btnSpecialValue('8')"/>
                          <input  type="button" value="9" class="Button1" onclick="btnSpecialValue('9')"/><br /><br />
                          <input  type="button" value="SUM" class="Button1" onclick="btnSpecialValue('SUM')"/>
                          <input  type="button" value="COUNT" class="Button1" onclick="btnSpecialValue('COUNT')"/>
                          <input  type="button" value="AVG" class="Button1" onclick="btnSpecialValue('AVG')"/>
                          <input  type="button" value="MAX" class="Button1" onclick="btnSpecialValue('MAX')"/>
                          <input  type="button" value="MIN" class="Button1" onclick="btnSpecialValue('MIN')"/>
                        </td>
                      </tr>
                   <tr>
                   <td colspan=4 style="border-bottom:1px inset #999999;">　</td>
                   </tr>
                   <tr>
                   <td colspan=4 height=5>&nbsp;</td>
                   </tr>
                   <tr>
                    <td align=center colspan=4>设置结果：<input class="text" type="text" name="txtResult" size="95" value="<%=strResult%>"   maxlength="1000" ></td>

                   </tr>
                    </table>
                  </td>
                </tr>
              </table>
              <br>
  </fieldset>
  <center>
    <br>
     <table cellspacing="0" cellpadding="0" border='0'><tr>
                 <%=userUI.ClickButton1("确 定","OKClick();","buttonSure.gif",user.getUserImage())%>
                 <%if("6".equals(user.getUserWINDOWTYPE())){%>
                    <%=userUI.ClickButton("取 消","JavaScript:parent.layer.closeAll();","buttonClose.gif",user.getUserImage())%>

                <%}else{ %>
                    <%=userUI.ClickButton1("取 消","window.close();","buttonClose.gif",user.getUserImage())%>
                <%} %>
          </tr></table>
    <br/>
  </center>

  <!--HTML Foot显示表单尾-->
<%=userUI.ShowFootHtml()%></form>
</body>
</html>
<SCRIPT LANGUAGE="javascript">

   // 加载数据表下拉列表。
    function loadTableList(){

        AnalyseConfigBean.GetTableList1("<%=StrWhere%>",
        function(items){
              dwr.util.addOptions("TableList",items,0,1);

              if(RegForm.TableList.length>0)
              {
                RegForm.TableList.selectedIndex=0;
                loadFieldList(RegForm.TableList.value);
              }

        }
        );

    }

    loadTableList();


     // 加载字段下拉列表。
    function loadFieldList(TableName){
        if(TableName==null||TableName==''){
        ClearList("FieldList");
        return;
        }
        AnalyseConfigBean.getFieldList(TableName,
        function(items){
               ClearList("FieldList");
               dwr.util.addOptions("FieldList",items,0,1);
               if(RegForm.FieldList.length>0)
               {
                 RegForm.FieldList.selectedIndex=0;
               }

        }
        );

    }



    function ClearList(ObjId){
        dwr.util.removeAllOptions(ObjId);
    }

window.onload  = function()
{
  var obj = window.dialogArguments;
  RegForm.txtResult.value=obj.document.forms[0].EXPRESSIONSWHERE.value;
}


</SCRIPT>
<%
//清空相关对象
user = null;
userUI = null;
STATISTICS = null;
list1 = null;
Variables = null;
%>
