<%@ 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_CUSTOM"%>
<%@ 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");
String strTABLENAME=request.getParameter("TABLENAME");
ANALYSE_STATISTICS_CUSTOM[] custom = StatisticsCfg.GetAnalyseCustomList(strID);
String StrWhere = " TableName ='"+strTABLENAME+"'";

     int row1 = 0;
     String strshow_data = "";
     strshow_data = strshow_data + "[";

     if (custom!=null && custom.length>0){
       row1 = custom.length;
       String  tablename = "",fieldname = "",tablechinese="",tableid="",fieldchinese="";
       String tmpStr = "";
       for(int i=0;i<custom.length;i++){

         strshow_data = strshow_data + "[";
         strshow_data = strshow_data + "\""+custom[i].getID()+"\",";
         tmpStr = custom[i].getGFIELD();
         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+"\",";
         if (i<19 )
         {
            strshow_data = strshow_data + "\""+custom[i].getGFIELD()+"\"],\r\n";
         }else
         {
            strshow_data = strshow_data + "\""+custom[i].getGFIELD()+"\"]";
         }

       }
     }


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>

<%} %>
<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'  }
	],

	recordType : 'array',
	data : show_data
}


var colsOption = [
           {id: 'f1' , header: "<center>编号</center>" , width :10 , align : 'center' ,hidden:true },
           {id: 'f2' , header: "<center>统计条件字段</center>" , width :380,  align : 'center'  },
	   {id: 'f3' , header: "add1" , width :10 , align : 'center',hidden:true  }
];


var gridOption={
	id : grid_demo_id,
	width: "398px",
	height: "100%",
	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
  {
   AnalyseCustomStr(); //复用关系属性
    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="savecustom">
<input type="hidden" name="FID" value="<%=strID%>">
<input type="hidden" name="AnalyseCustomStr" value="">


  <table border='0' height="280" width="400" cellspacing="0" cellpadding="0" align=center>

      <tr>
          <td width="180" height="25" align="right">
            自定义统计字段：</td>
            <td align="left">
            <select name="GFIELD"  id="GFIELD"  style="width=200">
               <%=StatisticsCfg.ShowTableFieldSelect(StrWhere)%>
            </select>
         </td>
         </tr>
      <tr>
          <td height="25" align="center" colspan="2">
               <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())%>
                   </tr>
                </table>
      </td></tr>
      <tr><td height="60%"  colspan="2">

<div id="gridbox" style="border:0px solid #cccccc;background-color:#f3f3f3;padding:5px;height:200px;width:700px;" ></div>

  </td>
  </tr>
  <tr valign="bottom" >
    <td valign="bottom"  colspan="2">
      <center>
        <br />
        <table cellspacing="0" cellpadding="0" border='0'>
          <tr>
          <%if("6".equals(user.getUserWINDOWTYPE())){%>
                    <%=userUI.ClickButton("保 存","JavaScript:if(Check(document.RegForm)){document.RegForm.submit();parent.layer.closeAll();}","buttonClose.gif",user.getUserImage())%>

                <%}else{ %>
                    <%=userUI.ClickButton("保 存","JavaScript:if(Check(document.RegForm)){document.RegForm.submit();}","buttonSave.gif",user.getUserImage())%>
                <%} %>

           </tr>
        </table>
        <br>
      </center>
    </td>
  </tr>
  </table>

  </form>
</BODY>
<script language="JavaScript" type="text/JavaScript">
<!--
var row1 = <%=row1%>;
var crow1 = 0;

function gridAddRow()
{
  mygrid.setCellValue("f1",row1,"1");
  mygrid.setCellValue("f2",row1,RegForm.GFIELD.options[RegForm.GFIELD.selectedIndex].text);
  mygrid.setCellValue("f3",row1,RegForm.GFIELD.value);

  mygrid.refresh();
  row1 = row1+1;

}

function gridDeleteRow()
{
   if(confirm("确定要删除选中的行吗?"))
  {
      mygrid.setCellValue("f1",crow1,"");
      mygrid.setCellValue("f2",crow1,"");
      mygrid.setCellValue("f3",crow1,"");

      mygrid.refresh();
  }

}

function gridUpdateRow()
{
  if (mygrid.getCellValue("f1",crow1)=="")
     {
        alert("提示:只能选择保存过的记录更新!");
        return;
     }

  mygrid.setCellValue("f2",crow1,RegForm.GFIELD.options[RegForm.GFIELD.selectedIndex].text);
  mygrid.setCellValue("f3",crow1,RegForm.GFIELD.value);
  mygrid.refresh();

}

function AnalyseCustomStr()
{
  var strResult="0#0&";
  for(row=0;row<=20;row++)
  {
    var getid = mygrid.getCellValue("f1",row);
    if (getid!="" )
     {

    strResult+=mygrid.getCellValue("f3",row)+"#"+
               mygrid.getCellValue("f1",row)+"&";

      }
   }

  RegForm.AnalyseCustomStr.value=strResult;
}

function gridClick() //点击响应
{
   if (mygrid.getCellValue("f1",crow1)!="")
   {
       RegForm.GFIELD.value=mygrid.getCellValue("f3",crow1);
   }
}


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