<%@ page contentType="text/html; charset=GBK" %>
<%@ page import = "zr.zrpower.common.util.SysPreperty" %>
<%@ page import = "zr.zrpower.entity.sys.SessionUser" %>
<%@ page import = "zr.zrpower.collectionengine.*"%>
<%@ page import = "zr.zrpower.ejb.sys.UIService" %>
<%@ page import = "zr.zrpower.analyseengine.service.StatisticsConfig"%>
<%@ page import = "zr.zrpower.analyseengine.mode.ANALYSE_STATISTICS_MAIN"%>
<%@ page import = "zr.zrpower.analyseengine.mode.ANALYSE_STATISTICS_WHERE"%>

<%@ page import = "zr.zrpower.common.util.DateWork" %>
<%@ page import = "java.lang.Object"%>

<HTML>
<%
SessionUser user = (SessionUser)session.getAttribute("userinfo");
UIService userUI =new UIService();
StatisticsConfig StatisticsCfg =  new StatisticsConfig();
String strID=request.getParameter("ID");
ANALYSE_STATISTICS_WHERE[] where = StatisticsCfg.GetAnalyseWhereList(strID);
ANALYSE_STATISTICS_MAIN[] STATISTICS = StatisticsCfg.getANALYSE_STATISTICS_MAIN(strID);
String StrWhere = " TableName ='"+STATISTICS[0].getTABLEID()+"'";
int row1 = 0;

//html5用到
  String userClass="windowimg",webH="100%";
  String zdid=request.getParameter("zdid");
  if(!"6".equals(user.getUserImage())){
     userClass=user.getUserImage();
  }else{
     webH="750px";
  }

String strshow_data = "";
String gl = "",g2 = "",g3 = "";
strshow_data = strshow_data + "[";



     if (where!=null && where.length>0){
       row1 = where.length;

       String  tablename = "",fieldname = "",tablechinese="",tableid="",fieldchinese="";
       String tmpStr = "";
       for(int i=0;i<where.length;i++){

          strshow_data = strshow_data + "[";

          strshow_data = strshow_data + "\""+where[i].getID()+"\",";

          gl = where[i].getSLEFT();
          if (gl.equals("0")){gl="无";}

          strshow_data = strshow_data + "\""+gl+"\",";

          tmpStr = where[i].getFIELD();
         try
         {
         tablename  = tmpStr.split("\\.")[0];
         fieldname  = tmpStr.split("\\.")[1];
         tablechinese =StatisticsCfg.GetAllTableFieldName("CHINESENAME","BPIP_TABLE","TABLENAME",tablename);
         tableid =StatisticsCfg.GetAllTableFieldName("TABLEID","BPIP_TABLE","TABLENAME",tablename);
         fieldchinese = StatisticsCfg.GetAllFieldName(tableid,fieldname);
         }catch(Exception ex)
         {
           out.print(tmpStr);
         }
         strshow_data = strshow_data + "\""+tablechinese+"."+fieldchinese+"\",";
         strshow_data = strshow_data + "\""+where[i].getSYMBOL()+"\",";
         strshow_data = strshow_data + "\""+where[i].getWHEREVALUE()+"\",";

         g2 = where[i].getSRIGHT();
         if (g2.equals("0")){g2="无";}
         strshow_data = strshow_data + "\""+g2+"\",";

         g3 = where[i].getLOGIC();
         if (g3.equals("0")){g3="无";}
         if (g3.equals("1")){g3="与";}
         if (g3.equals("2")){g3="或";}
         strshow_data = strshow_data + "\""+g3+"\",";
         strshow_data = strshow_data + "\""+where[i].getSLEFT()+"\",";
         strshow_data = strshow_data + "\""+where[i].getFIELD()+"\",";
         strshow_data = strshow_data + "\""+where[i].getSYMBOL()+"\",";
         strshow_data = strshow_data + "\""+where[i].getWHEREVALUE()+"\",";
         strshow_data = strshow_data + "\""+where[i].getSRIGHT()+"\",";


          if (i<19 )
         {
            strshow_data = strshow_data + "\""+where[i].getLOGIC()+"\"],\r\n";
         }else
         {
            strshow_data = strshow_data + "\""+where[i].getLOGIC()+"\"]";
         }

       }
     }



 for (int i=0;i<(20-row1);i++)
{
   if (i<(19-row1))
   {
     strshow_data = strshow_data + "['','','','','','','','','','','','',''],";
   }else
   {
     strshow_data = strshow_data + "['','','','','','','','','','','','','']";
   }

}


strshow_data = strshow_data + "]";
 %>
<HTML>
<HEAD>
<TITLE></TITLE>
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<META http-equiv="Content-Type" content="text/html; charset=GBK">
<LINK type="text/css" rel="stylesheet" href="../../zrsysmanage/css/<%=user.getUserCSS()%>">
<SCRIPT LANGUAGE="JavaScript" src="../../zrsysmanage/script/Public.js"></SCRIPT>
<%if("6".equals(user.getUserImage())){ %>
<link rel="stylesheet" type="text/css" media="all" href="../../ZrwebGui/sigma_grid_html/grid/calendar/calendar-blue.css">
<script type="text/javascript" src="../../ZrwebGui/sigma_grid_html/grid/calendar/calendar.js"></script>
<script type="text/javascript" src="../../ZrwebGui/sigma_grid_html/grid/calendar/calendar-setup.js"></script>
<link rel="stylesheet" type="text/css" href="../../ZrwebGui/sigma_grid_html/grid/gt_grid.css">
<link rel="stylesheet" type="text/css" href="../../ZrwebGui/sigma_grid_html/grid/skin/vista/skinstyle.css">
<link rel="stylesheet" type="text/css" href="../../ZrwebGui/sigma_grid_html/grid/skin/pink/skinstyle.css">
<link rel="stylesheet" type="text/css" href="../../ZrwebGui/sigma_grid_html/grid/skin/mac/skinstyle.css">
<script type="text/javascript" src="../../ZrwebGui/sigma_grid_html/grid/gt_msg_en.js"></script>
<script type="text/javascript" src="../../ZrwebGui/sigma_grid_html/grid/gt_const.js"></script>
<script type="text/javascript" src="../../ZrwebGui/sigma_grid_html/grid/gt_grid_all.js"></script>
<%}else{ %>
<link rel="stylesheet" type="text/css" media="all" href="../../ZrwebGui/sigma_grid/grid/calendar/calendar-blue.css">
<script type="text/javascript" src="../../ZrwebGui/sigma_grid/grid/calendar/calendar.js"></script>
<script type="text/javascript" src="../../ZrwebGui/sigma_grid/grid/calendar/calendar-setup.js"></script>
<link rel="stylesheet" type="text/css" href="../../ZrwebGui/sigma_grid/grid/gt_grid.css">
<link rel="stylesheet" type="text/css" href="../../ZrwebGui/sigma_grid/grid/skin/vista/skinstyle.css">
<link rel="stylesheet" type="text/css" href="../../ZrwebGui/sigma_grid/grid/skin/pink/skinstyle.css">
<link rel="stylesheet" type="text/css" href="../../ZrwebGui/sigma_grid/grid/skin/mac/skinstyle.css">
<script type="text/javascript" src="../../ZrwebGui/sigma_grid/grid/gt_msg_en.js"></script>
<script type="text/javascript" src="../../ZrwebGui/sigma_grid/grid/gt_const.js"></script>
<script type="text/javascript" src="../../ZrwebGui/sigma_grid/grid/gt_grid_all.js"></script>

<%} %>

<%if("6".equals(user.getUserWINDOWTYPE())){ %>
<SCRIPT LANGUAGE="JavaScript" src="../../zrsysmanage/html5/script/jquery-2.0.3.min.js"></SCRIPT>
<SCRIPT LANGUAGE="JavaScript" src="../../zrsysmanage/html5/layer/layer.js"></SCRIPT>
<%}%>


<script type="text/javascript" >
var css = "<%=user.getUserCSS()%>";
var skincss = "vista";

if (css=="Blue.css")
{skincss = "vista";}
else if (css=="Public.css")
{skincss = "default";}
else if (css=="Window.css" || css=="nBlue.css")
{skincss = "mac";}
else if (css=="Yellow.css")
{skincss = "pink";}
else{
skincss="mac";
}

var grid_demo_id = "myGrid1" ;
var show_data= <%=strshow_data%>;

var dsOption= {

	fields :[
		{name : 'f1'  },
		{name : 'f2'  },
		{name : 'f3'  },
                {name : 'f4'  },
		{name : 'f5'  },
		{name : 'f6'  },
                {name : 'f7'  },
		{name : 'f8'  },
		{name : 'f9'  },
                {name : 'f10'  },
		{name : 'f11'  },
		{name : 'f12'  },
		{name : 'f13'  }
	],

	recordType : 'array',
	data : show_data
}


var colsOption = [
           {id: 'f1' , header: "<center>编号</center>" , width :10 , align : 'center' ,hidden:true },
           {id: 'f2' , header: "<center>左括号</center>" , width :100,  align : 'center'  },
	   {id: 'f3' , header: "<center>条件列</center>" , width :100 ,align : 'center'  },
           {id: 'f4' , header: "<center>条件符</center>" , width :100 ,align : 'center'  },
           {id: 'f5' , header: "<center>条件值</center>" , width :180 ,align : 'center'  },
           {id: 'f6' , header: "<center>右括号</center>" , width :100 ,align : 'center'  },
           {id: 'f7' , header: "<center>逻辑符</center>" , width :100 ,align : 'center'  },
           {id: 'f8' , header: "add1" , width :10 ,align : 'center',hidden:true   },
           {id: 'f9' , header: "add2" , width :10 ,align : 'center',hidden:true   },
           {id: 'f10' , header: "add3" , width :10 ,align : 'center',hidden:true   },
           {id: 'f11' , header: "add4" , width :10 ,align : 'center',hidden:true   },
           {id: 'f12' , header: "add5" , width :10 ,align : 'center',hidden:true   },
	   {id: 'f13' , header: "add6" , width :10 , align : 'center',hidden:true  }
];


var gridOption={
	id : grid_demo_id,
	<%if("6".equals(user.getUserImage())){%>
	width: "99%",
	height: "300px",
	<%}else{%>
	width: "98%",
	height: "98%",
	<%}%>


	container : 'gridbox',
	replaceContainer : true,
	dataset : dsOption ,
	columns : colsOption,
	pageSize : 500,
	toolbarContent : null,
        skin : skincss,

        onCellClick:function(value, record , cell, row,  colNO, rowNO,columnObj,grid){
           crow1 = rowNO;
        },

        onCellDblClick:function(value, record , cell, row,  colNO, rowNO,columnObj,grid){
           crow1 = rowNO;
           gridClick();
        },

       showIndexColumn : false
};


var mygrid=new Sigma.Grid( gridOption );
Sigma.Util.onLoad( Sigma.Grid.render(mygrid));

</script>



<script language="JavaScript" type="text/JavaScript">
<!--
function Check(theForm)
{
  try
  {
   AnalyseWhereStr();
    return true;
  }
  catch(e)
  {
    alert(e.description);
    return false;
  }
}

//-->
</script>

</HEAD>
<BODY class="BodyMain">
<FORM name="RegForm" method="post" action="../../actionstatisticsother.do" onsubmit="return Check(this);">
<input type="hidden" name="Act"  value="savewhere">
<input type="hidden" name="FID" value="<%=strID%>">
<input type="hidden" name="AnalyseWhereStr" value="">


   <%if("6".equals(user.getUserImage())){ %>
      <table border='0'  width="100%" cellspacing="0" cellpadding="0" align=center>
      <%}else{ %>
     <table border='0' height="100%" width="100%" cellspacing="0" cellpadding="0" align=center>
     <%} %>
     <%if(!"6".equals(user.getUserImage())){%>
       <tr >
          <td height="160"  colspan="4">
        <table  border='0' height="160" width="100%" background="../../zrsysmanage/images/<%=user.getUserImage()%>/databack3.jpg" cellspacing="0" cellpadding="0" align=center>
          <tr>
          <td></td>
        </tr>
      </table>
     </td></tr>
     <%}%>
     <tr>
                    <td align=right width="12%" height="25">左括号：</td>
                    <td  align=left >
                    <select name="SLEFT"  style="width:150px">
                    <option  value="0">无</option>
                    <option value="(" selected="selected">(</option>
                    <option value="((" >((</option>
                    <option value="(((" >(((</option>
                    <option value="((((">((((</option>
                    <option value="(((((">(((((</option>

                    </select>
                    <td width="12%" align="right"> 条件列：</td>
                    <td>
                     <select name="FIELD"  style="width:350px">
                      <%=StatisticsCfg.ShowTableFieldSelect(StrWhere)%>
                    </select>
                    </td>

                   </tr>
                   <tr>
                   <td align="right"> 条件符：</td>
                   <td align="left">
                    <select name="SYMBOL" id="SYMBOL" style="width:150px" >
                      <option value=">">></option>
                      <option value=">=" selected="selected">>=</option>
                      <option value="=">=</option>
                      <option value="<"><</option>
                      <option value="<="><=</option>
                      <option value="Like">Like</option>
                      <option value="Not Like">Not Like</option>
                      <option value="In">In</option>
                      <option value="Not In">Not In</option>
                      <option value="!=">!=</option>
                      <option value="Is">Is</option>
                     </select>
                   </td>
                    <td align=right  height="25">条件值：</td>

                    <td  align="left">
                     <table cellspacing="0" cellpadding="0" border='0'>
                       <tr>
                          <td>
                               <input class="text" type="text" name="WHEREVALUE" id="WHEREVALUE" size="45" > <%=userUI.ClickButton("设置","JavaScript:ShowModal();","buttonSelect.gif",user.getUserImage())%>
                          </td>
                       </tr>
                   </table>
                    </td>
                   </tr>
                    <tr>
                    <td align=right height="25">右括号：</td>
                    <td  align="left" >
                    <select name="SRIGHT"  style="width:150px">
                    <option value="0">无</option>
                    <option value=")" selected="selected">)</option>
                    <option value="))">))</option>
                    <option value=")))">)))</option>
                    <option value="))))">))))</option>
                    <option value=")))))">)))))</option>

                    </select>
                   </td>
                      <td align=right height="25">逻辑符：</td>
                    <td  align="left" >
                    <select name="LOGIC"  style="width:250px">
                     <option value="1" selected="selected">与</option>
                     <option value="2">或</option>
                     <option value="0">无</option>
                    </select>
                   </td>
                </tr>
      <tr>
          <td height="25" align="center" colspan="4">
               <table cellspacing="0" cellpadding="0" border='0'>
                   <tr>
                     <%=userUI.ClickButton1("增加行","gridAddRow();","IcoAdd.gif",user.getUserImage())%>
                     <%=userUI.ClickButton1("删除行","gridDeleteRow();","buttonDelete.gif",user.getUserImage())%>
                     <%=userUI.ClickButton1("更  新","gridUpdateRow();","buttonCancel.gif",user.getUserImage())%>
                     <%=userUI.ClickButton("保 存","JavaScript:if(Check(document.RegForm)){document.RegForm.submit();}","buttonSave.gif",user.getUserImage())%>
                   </tr>
                </table>
      </td></tr>
      <tr>
      <%if("6".equals(user.getUserImage())){ %>
      <td  colspan="4" style="padding-left: 120px;">
      <br/>
      <DIV id="divMessage" style='position:absolute;width:90%;height:90%;overflow:auto'>
      <div id="gridbox" style="border:0px solid #cccccc;background-color:#f3f3f3;padding:5px;height:200px;width:700px;" ></div>

        </div>
     </td>
      <%}else{ %>
      <td height="90%"  colspan="4"  align="left" valign="top">
      <DIV id="divMessage" style='position:absolute;width:100%;height:310;overflow:auto'>
      <div id="gridbox" style="border:0px solid #cccccc;background-color:#f3f3f3;padding:5px;height:200px;width:700px;" ></div>

        </div>
     </td>
      <%} %>
  </tr>

  </table>


  </form>
</BODY>
<script language="JavaScript" type="text/JavaScript">
<!--

var row1 = <%=row1%>;
var crow1 = 0;

//
function ShowModal()
{
  var url='ConValueSetup.jsp?strResult='+RegForm.WHEREVALUE.value;
  var status='dialogHeight:380px;dialogWidth:700px;status:0;help:no;center:yes';
  <%if("6".equals(user.getUserWINDOWTYPE())){ %>
  layer.open({
     type: 2,
     title:'条件设置',
     area: ['700px', '408px'],
     fix: false, //不固定
     maxmin: false,
     content: url+'&zdid=WHEREVALUE'
   });
  <%}else{%>
  var rtnResult=window.showModalDialog(url,window,status);
 if (rtnResult!=null)
   {
     RegForm.WHEREVALUE.value=rtnResult;
   }
   <%}%>
}

//
function gridAddRow()
{

  mygrid.setCellValue("f1",row1,"1");
  mygrid.setCellValue("f2",row1,RegForm.SLEFT.options[RegForm.SLEFT.selectedIndex].text);
  mygrid.setCellValue("f3",row1,RegForm.FIELD.options[RegForm.FIELD.selectedIndex].text);
  mygrid.setCellValue("f4",row1,RegForm.SYMBOL.options[RegForm.SYMBOL.selectedIndex].text);
  mygrid.setCellValue("f5",row1,RegForm.WHEREVALUE.value);
  mygrid.setCellValue("f6",row1,RegForm.SRIGHT.options[RegForm.SRIGHT.selectedIndex].text);
  mygrid.setCellValue("f7",row1,RegForm.LOGIC.options[RegForm.LOGIC.selectedIndex].text);
  mygrid.setCellValue("f8",row1,RegForm.SLEFT.value);
  mygrid.setCellValue("f9",row1,RegForm.FIELD.value);
  mygrid.setCellValue("f10",row1,RegForm.SYMBOL.value);
  mygrid.setCellValue("f11",row1,RegForm.WHEREVALUE.value);
  mygrid.setCellValue("f12",row1,RegForm.SRIGHT.value);
  mygrid.setCellValue("f13",row1,RegForm.LOGIC.value);

  mygrid.refresh();

  row1 = row1+1;



}

function gridDeleteRow()
{

  if(confirm("确定要删除选中的行吗?"))
  {
      mygrid.setCellValue("f1",crow1,"");
      mygrid.setCellValue("f2",crow1,"");
      mygrid.setCellValue("f3",crow1,"");
      mygrid.setCellValue("f4",crow1,"");
      mygrid.setCellValue("f5",crow1,"");
      mygrid.setCellValue("f6",crow1,"");
      mygrid.setCellValue("f7",crow1,"");
      mygrid.setCellValue("f8",crow1,"");
      mygrid.setCellValue("f9",crow1,"");
      mygrid.setCellValue("f10",crow1,"");
      mygrid.setCellValue("f11",crow1,"");
      mygrid.setCellValue("f12",crow1,"");
      mygrid.setCellValue("f13",crow1,"");
      mygrid.refresh();
  }

}

function gridUpdateRow()
{

    if(confirm("确定要更新选中的行吗?"))
   {
     if (mygrid.getCellValue("f1",crow1)=="")
     {
        alert("提示:只能选择保存过的记录更新!");
        return;
     }
     mygrid.setCellValue("f2",crow1,RegForm.SLEFT.options[RegForm.SLEFT.selectedIndex].text);
     mygrid.setCellValue("f3",crow1,RegForm.FIELD.options[RegForm.FIELD.selectedIndex].text);
     mygrid.setCellValue("f4",crow1,RegForm.SYMBOL.options[RegForm.SYMBOL.selectedIndex].text);
     mygrid.setCellValue("f5",crow1,RegForm.WHEREVALUE.value);
     mygrid.setCellValue("f6",crow1,RegForm.SRIGHT.options[RegForm.SRIGHT.selectedIndex].text);
     mygrid.setCellValue("f7",crow1,RegForm.LOGIC.options[RegForm.LOGIC.selectedIndex].text);
     mygrid.setCellValue("f8",crow1,RegForm.SLEFT.value);
     mygrid.setCellValue("f9",crow1,RegForm.FIELD.value);
     mygrid.setCellValue("f10",crow1,RegForm.SYMBOL.value);
     mygrid.setCellValue("f11",crow1,RegForm.WHEREVALUE.value);
     mygrid.setCellValue("f12",crow1,RegForm.SRIGHT.value);
     mygrid.setCellValue("f13",crow1,RegForm.LOGIC.value);

     mygrid.refresh();

  }


}

function AnalyseWhereStr()
{
  var strResult="0#0#0#0#0#0#0&";

  for(row=0;row<=20;row++)
  {
     if (mygrid.getCellValue("f1",row)!="")
     {
           strResult+=mygrid.getCellValue("f8",row)+"#"+
               mygrid.getCellValue("f9",row)+"#"+
               mygrid.getCellValue("f10",row)+"#"+
               mygrid.getCellValue("f11",row)+"#"+
               mygrid.getCellValue("f12",row)+"#"+
               mygrid.getCellValue("f13",row)+"#"+
               mygrid.getCellValue("f1",row)+"&";
     }
  }


 RegForm.AnalyseWhereStr.value=strResult;
}

function gridClick() //点击响应
{
     if (mygrid.getCellValue("f1",crow1)!="")
   {


     RegForm.SLEFT.value=mygrid.getCellValue("f8",crow1);
       RegForm.FIELD.value=mygrid.getCellValue("f9",crow1);
       RegForm.SYMBOL.value=mygrid.getCellValue("f10",crow1);
       RegForm.WHEREVALUE.value=mygrid.getCellValue("f11",crow1);
       RegForm.SRIGHT.value=mygrid.getCellValue("f12",crow1);
       RegForm.LOGIC.value=mygrid.getCellValue("f13",crow1);


    }

}
//--
</script>
</HTML>
<%
//清空相关对象
user = null;
userUI = null;
StatisticsCfg = null;
where = null;
STATISTICS = null;
%>
