<%@ 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_CCONNECTION"%>

<%@ page import = "zr.zrpower.common.web.SelectBox" %>
<%@ 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("FID");
ANALYSE_STATISTICS_CCONNECTION[] cconnection = StatisticsCfg.GetAnalyseCConnectionList(strID);
ANALYSE_STATISTICS_MAIN[] STATISTICS = StatisticsCfg.getANALYSE_STATISTICS_MAIN(strID);

String  tablename = "",fieldname = "",tablechinese="",tableid="",fieldchinese="";
String  tablename1 = "",fieldname1 = "",tablechinese1="",tableid1="",fieldchinese1="";

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

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

     if (cconnection!=null && cconnection.length>0){
       row1 = cconnection.length;
       String tmpStr = "";
       String tmpStr1 ="";
       for(int i=0;i<cconnection.length;i++){
         strshow_data = strshow_data + "[";

         tmpStr = cconnection[i].getCFIELD();
         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);
         }

         tmpStr1 = cconnection[i].getMFIELD();
         try
         {
         tablename1  = tmpStr1.split("\\.")[0];
         fieldname1  = tmpStr1.split("\\.")[1];
         tablechinese1 =StatisticsCfg.GetAllTableFieldName("CHINESENAME","BPIP_TABLE","TABLENAME",tablename1);
         tableid1 =StatisticsCfg.GetAllTableFieldName("TABLEID","BPIP_TABLE","TABLENAME",tablename1);
         fieldchinese1 = StatisticsCfg.GetAllFieldName(tableid1,fieldname1);
         }catch(Exception ex)
         {
           out.print(tmpStr);
         }

         strshow_data = strshow_data + "\""+cconnection[i].getID()+"\",";
         strshow_data = strshow_data + "\""+tablechinese+"."+fieldchinese+"\",";
         strshow_data = strshow_data + "\""+tablechinese1+"."+fieldchinese1+"\",";
         gl = cconnection[i].getJOINTYPE();
         if (gl.equals("1")){gl="一般";}
         if (gl.equals("2")){gl="左外关联";}
         if (gl.equals("3")){gl="右外关联";}
         strshow_data = strshow_data + "\""+gl+"\",";
         strshow_data = strshow_data + "\""+cconnection[i].getCFIELD()+"\",";
         strshow_data = strshow_data + "\""+cconnection[i].getMFIELD()+"\",";
         if (i<19 )
         {
            strshow_data = strshow_data + "\""+cconnection[i].getJOINTYPE()+"\"],\r\n";
         }else
         {
            strshow_data = strshow_data + "\""+cconnection[i].getJOINTYPE()+"\"]";
         }


       }
     }


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><%=SysPreperty.getProperty().SystemName%><%=SysPreperty.getProperty().Versoin%></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>
<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>


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

	recordType : 'array',
	data : show_data
}


var colsOption = [
           {id: 'f1' , header: "<center>编号</center>" , width :10 , align : 'center' ,hidden:true },
           {id: 'f2' , header: "<center>左关联表字段</center>" , width :230,  align : 'center'  },
	   {id: 'f3' , header: "<center>右关联表字段</center>" , width :230 ,align : 'center'  },
           {id: 'f4' , header: "<center>关联类型</center>" , width :220 ,align : 'center'  },
           {id: 'f5' , header: "add1" , width :10 ,align : 'center',hidden:true   },
           {id: 'f6' , header: "add2" , width :10 ,align : 'center',hidden:true   },
	   {id: 'f7' , header: "add3" , width :10 , align : 'center',hidden:true  }
];


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

  <table border='0' height="100%" width="580px" cellspacing="0" cellpadding="0" align=center>
               <tr>
          <td height="25" align="right"> </td>
          <td align="left"></td><td height="25" align="right">
          <td height="25" align="right"> </td>
           <td align="left"></td>
      </tr>
              <TR>
               <TD width="20%" align="right">左关联表：</TD>
               <TD>
               <table cellspacing="0" cellpadding="0" border='0'>
                       <tr>
                          <td>
                               <input class="text" type="text"  name="CTABLEchinesename" id="CTABLEchinesename" size="20" readonly="readonly"><input class="text" type="hidden"  id="CTABLE" name="CTABLE" size="20"><%=userUI.ClickButton("选择","JavaScript:ShowModalTableTree();","buttonSelect.gif",user.getUserImage())%>
                          </td>
                       </tr>
              </table>
               </TD>

          <td width="20%" height="25" align="right">
            左关联字段：</td>
            <td align="left">
             <table cellspacing="0" cellpadding="0" border='0'>
                       <tr>
                          <td>
                               <input class="text" type="text"  name="CFIELDchinesename" id="CFIELDchinesename" size="15" readonly="readonly"><input class="text" type="hidden"  id="CFIELD" name="CFIELD" size="15"><%=userUI.ClickButton("选择","JavaScript:ShowModalFieldList();","buttonSelect.gif",user.getUserImage())%>
                          </td>
                       </tr>
              </table>
         </td>
         </tr>
         <TR>
               <TD width="20%" align="right">右关联表：</TD>
               <TD> <table cellspacing="0" cellpadding="0" border='0'>
                       <tr>
                          <td>
                               <input class="text" type="text" name="MTABLEchinesename" id="MTABLEchinesename" size="20" readonly="readonly"><input class="text" type="hidden"  id="MTABLE" name="MTABLE" size="20"><%=userUI.ClickButton("选择","JavaScript:ShowModalTableTree1();","buttonSelect.gif",user.getUserImage())%>
                          </td>
                       </tr>
              </table></TD>

          <td width="20%" height="25" align="right">右关联字段：</td>
             <td  align="left">
            <table cellspacing="0" cellpadding="0" border='0'>
                       <tr>
                          <td>
                               <input class="text" type="text"  name="MFIELDchinesename" id="MFIELDchinesename" size="15" readonly="readonly"><input class="text" type="hidden"  id="MFIELD" name="MFIELD" size="15"><%=userUI.ClickButton("选择","JavaScript:ShowModalFieldList1();","buttonSelect.gif",user.getUserImage())%>
                          </td>
                       </tr>
              </table>
         </td>
         </tr>

         <tr>
          <td height="25" align="right">
          关联类型：</td><td align="left" colspan="3">
          <select name="JOINTYPE"  id="JOINTYP"  style="width=120">
                  <option value="1">一般</option>
                  <option value="2">左外关联</option>
                  <option value="3">右外关联</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())%>
                   </tr>
                </table>
      </td></tr>
       <tr><td height="2"  colspan="4"></td></tr>
      <tr><td height="60%"  colspan="4">

   <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="4">
      <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();}","buttonSave.gif",user.getUserImage())%>
            <%=userUI.ClickButton("关 闭","JavaScript:parent.layer.closeAll();","buttonClose.gif",user.getUserImage())%>

                <%}else{ %>
                    <%=userUI.ClickButton("保 存","JavaScript:if(Check(document.RegForm)){document.RegForm.submit();}","buttonSave.gif",user.getUserImage())%>
            <%=userUI.ClickButton("关 闭","JavaScript:window.close();","buttonClose.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 ShowModalTableTree()
{
  var url='TableTree1.jsp?strResult='+RegForm.CTABLE.value;
  var status='dialogHeight:450px;dialogWidth:250px;status:0;help:no;center:yes';
  <%if("6".equals(user.getUserWINDOWTYPE())){ %>
   layer.open({
     type: 2,
     title:'选择表',
     area: ['300px', '380px'],
     fix: false, //不固定
     maxmin: false,
     content: url+'&zdid=CTABLE/CTABLEchinesename'
   });
  <%}else{%>
  var rtnResult=window.showModalDialog(url,window,status);
   if (rtnResult!=null)
   {
     var   sarray=new   Array();
     sarray=rtnResult.split(',');
     RegForm.CTABLE.value=sarray[0];
     RegForm.CTABLEchinesename.value=sarray[1];
   }
    <%}%>
}
function ShowModalTableTree1()
{
  var url='TableTree1.jsp?strResult='+RegForm.MTABLE.value;
  var status='dialogHeight:450px;dialogWidth:250px;status:0;help:no;center:yes';
  <%if("6".equals(user.getUserWINDOWTYPE())){ %>
   layer.open({
     type: 2,
     title:'选择表',
     area: ['300px', '380px'],
     fix: false, //不固定
     maxmin: false,
     content: url+'&zdid=MTABLE/MTABLEchinesename'
   });
  <%}else{%>
  var rtnResult=window.showModalDialog(url,window,status);
 if (rtnResult!=null)
   {
     var  sarray=new   Array();
     sarray=rtnResult.split(',');
     RegForm.MTABLE.value=sarray[0];
     RegForm.MTABLEchinesename.value=sarray[1];
   }
    <%}%>
}
function ShowModalFieldList()
{
  var url='SelectField1.jsp?TableName='+RegForm.CTABLE.value+'&strResult='+RegForm.CFIELD.value;
  var status='dialogHeight:150px;dialogWidth:380px;status:0;help:no;center:yes';
  <%if("6".equals(user.getUserWINDOWTYPE())){ %>
   layer.open({
     type: 2,
     title:'选择字段',
     area: ['300px', '150px'],
     fix: false, //不固定
     maxmin: false,
     content: url+'&zdid=CFIELD/CFIELDchinesename'
   });
  <%}else{%>
  var rtnResult=window.showModalDialog(url,window,status);
 if (rtnResult!=null)
   {
    var  sarray=new   Array();
     sarray=rtnResult.split(',');
     RegForm.CFIELD.value=sarray[0];
     RegForm.CFIELDchinesename.value=sarray[1];
   }
    <%}%>
}
function ShowModalFieldList1()
{
  var url='SelectField1.jsp?TableName='+RegForm.MTABLE.value+'&strResult='+RegForm.MFIELD.value;
  var status='dialogHeight:150px;dialogWidth:380px;status:0;help:no;center:yes';
  <%if("6".equals(user.getUserWINDOWTYPE())){ %>
   layer.open({
     type: 2,
     title:'选择字段',
     area: ['300px', '150px'],
     fix: false, //不固定
     maxmin: false,
     content: url+'&zdid=MFIELD/MFIELDchinesename'
   });
  <%}else{%>
  var rtnResult=window.showModalDialog(url,window,status);
 if (rtnResult!=null)
   {
     var  sarray=new   Array();
     sarray=rtnResult.split(',');
     RegForm.MFIELD.value=sarray[0];
     RegForm.MFIELDchinesename.value=sarray[1];
   }
   <%}%>
}
function gridAddRow()
{

  mygrid.setCellValue("f1",row1,"1");
  mygrid.setCellValue("f2",row1,RegForm.CTABLEchinesename.value+"."+RegForm.CFIELDchinesename.value);
  mygrid.setCellValue("f3",row1,RegForm.MTABLEchinesename.value+"."+RegForm.MFIELDchinesename.value);
  mygrid.setCellValue("f4",row1,RegForm.JOINTYPE.options[RegForm.JOINTYPE.selectedIndex].text);
  mygrid.setCellValue("f5",row1,RegForm.CTABLE.value+"."+RegForm.CFIELD.value);
  mygrid.setCellValue("f6",row1,RegForm.MTABLE.value+"."+RegForm.MFIELD.value);
  mygrid.setCellValue("f7",row1,RegForm.JOINTYPE.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.refresh();
  }
}

function gridUpdateRow()
{
   if(confirm("确定要更新选中的行吗?"))
   {
     if (mygrid.getCellValue("f1",crow1)=="")
     {
        alert("提示:只能选择保存过的记录更新!");
        return;
     }
     mygrid.setCellValue("f2",crow1,RegForm.CTABLEchinesename.value+"."+RegForm.CFIELDchinesename.value);
     mygrid.setCellValue("f3",crow1,RegForm.MTABLEchinesename.value+"."+RegForm.MFIELDchinesename.value);
     mygrid.setCellValue("f4",crow1,RegForm.JOINTYPE.options[RegForm.JOINTYPE.selectedIndex].text);
     mygrid.setCellValue("f5",crow1,RegForm.CTABLE.value+"."+RegForm.CFIELD.value);
     mygrid.setCellValue("f6",crow1,RegForm.MTABLE.value+"."+RegForm.MFIELD.value);
     mygrid.setCellValue("f7",crow1,RegForm.JOINTYPE.value);
     mygrid.refresh();
   }
}

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

    strResult+=mygrid.getCellValue("f5",row)+"#"+
               mygrid.getCellValue("f6",row)+"#"+
               mygrid.getCellValue("f7",row)+"#"+
               mygrid.getCellValue("f1",row)+"&";
     }
  }
  RegForm.AnalyseCConnectionStr.value=strResult;
}

function gridClick() //点击响应
{
   if (mygrid.getCellValue("f1",crow1)!="")
   {
     var Cfieldvaulename = mygrid.getCellValue("f2",crow1);
     var Mfieldvaulename = mygrid.getCellValue("f3",crow1);
     RegForm.CTABLEchinesename.value=Cfieldvaulename.split(".")[0];
     RegForm.CFIELDchinesename.value=Cfieldvaulename.split(".")[1];
     RegForm.MTABLEchinesename.value=Mfieldvaulename.split(".")[0];
     RegForm.MFIELDchinesename.value=Mfieldvaulename.split(".")[1];
     var Cfieldvaule = mygrid.getCellValue("f5",crow1);
     var Mfieldvaule = mygrid.getCellValue("f6",crow1);
     RegForm.CTABLE.value=Cfieldvaule.split(".")[0];
     RegForm.CFIELD.value=Cfieldvaule.split(".")[1];
     RegForm.MTABLE.value=Mfieldvaule.split(".")[0];
     RegForm.MFIELD.value=Mfieldvaule.split(".")[1];
     RegForm.JOINTYPE.value=mygrid.getCellValue("f7",crow1);

   }

}


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

%>
