<%@ page contentType="text/html; charset=GBK" %>
<%@ page import = "zr.zrpower.common.util.SysPreperty" %>
<%@ page import = "zr.zrpower.entity.sys.SessionUser" %>
<%@ page import = "zr.zrpower.ejb.sys.UIService" %>
<%@page import="zr.zrpower.dbmanage.service.*"%>
<%@page import="zr.zrpower.dbmanage.*"%>
<%@ page import = "java.util.Hashtable" %>

<HTML>
<%
SessionUser user = (SessionUser)session.getAttribute("userinfo");
UIService userUI =new UIService();
BPIP_FIELD[] TC = null;

FieldService Field = new FieldService();
TableService Table = new TableService();
String strtableid = request.getParameter("TABLEID");
BPIP_TABLE tablelist = new BPIP_TABLE();
tablelist = Table.getTableID(strtableid);

String name = tablelist.getTABLENAME();                //获取表名
String chinesename = tablelist.getCHINESENAME();       //获取表中文名
String sum = Table.SumTable1(name);                    //获取表中记录数
String sum1 = Field.SumTable(strtableid);              //获取表中字段数

String strTableType =  tablelist.getTABLETYPE();



//得到查询的记录集
    TC = Field.GetBpipFieldList(strtableid);

    Hashtable Hashtable0 = new Hashtable();
    Hashtable Hashtable1 = new Hashtable();
    Hashtable Hashtable2 = new Hashtable();
    Hashtable Hashtable3 = new Hashtable();

    Hashtable0.put("0","否");
    Hashtable0.put("1","是");

    Hashtable1.put("1","VARCHAR2");
    Hashtable1.put("2","FLOAT");
    Hashtable1.put("3","BLOB");
    Hashtable1.put("4","DATE");
    Hashtable1.put("5","DATETIME");
    Hashtable1.put("6","NUMBER");
    Hashtable1.put("7","CLOB");

    Hashtable2.put("1","无特殊标记");
    Hashtable2.put("2","代码表标记");
    Hashtable2.put("3","用户表标记");
    Hashtable2.put("4","单位表标记");
    Hashtable2.put("5","前缀字母");
    Hashtable2.put("6","数字型自动编号(无条件)");
    Hashtable2.put("7","数字型自动编号(一个条件)");
    Hashtable2.put("8","数字型自动编号(两个条件)");
    Hashtable2.put("9","数字型自动编号(三个条件)");
    Hashtable2.put("10","文本型自动编号(无条件)");
    Hashtable2.put("11","文本型自动编号(一个条件)");
    Hashtable2.put("12","文本型自动编号(两个条件)");
    Hashtable2.put("13","文本型自动编号(三个条件)");

    Hashtable3.put("0","");
    Hashtable3.put("1","点选控件");
    Hashtable3.put("2","下拉控件");
    Hashtable3.put("3","字典控件");
    Hashtable3.put("4","多选控件");


    String strshow_data="";
     if (TC!=null && TC.length>0){
        strshow_data = strshow_data + "[";
        for(int i=0;i<TC.length;i++){
            strshow_data = strshow_data + "[";
            strshow_data = strshow_data + "'"+TC[i].getFIELDID()+"',";
            strshow_data = strshow_data + "'"+TC[i].getFIELDNAME()+"',";
            strshow_data = strshow_data + "'"+TC[i].getCHINESENAME()+"',";
            strshow_data = strshow_data + "'"+Hashtable1.get(TC[i].getFIELDTYPE())+"',";
            strshow_data = strshow_data + "'"+TC[i].getFIELDLENGTH()+"',";
            strshow_data = strshow_data + "'"+Hashtable0.get(TC[i].getISNULL())+"',";
            strshow_data = strshow_data + "'"+Hashtable2.get(TC[i].getFIELDTAG())+"',";
            strshow_data = strshow_data + "'"+Hashtable3.get(String.valueOf(TC[i].getTAGEXT()))+"',";

            strshow_data = strshow_data + "'"+TC[i].getDICTTABLE()+"',";
            strshow_data = strshow_data + "'"+Field.GetFieldCHINESENAME(TC[i].getAUTO1())+"',";
            strshow_data = strshow_data + "'"+Field.GetFieldCHINESENAME(TC[i].getAUTO2())+"',";
            strshow_data = strshow_data + "'"+Field.GetFieldCHINESENAME(TC[i].getAUTO3())+"',";


            if (i < TC.length-1 )
            {
               strshow_data = strshow_data + "'"+TC[i].getDESCRIPTION()+"'],\r\n";
            }else
            {
               strshow_data = strshow_data + "'"+TC[i].getDESCRIPTION()+"']";
            }
        }

        strshow_data = strshow_data + "]";
    }else
    {
        strshow_data = "null";
    }

%>
<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/tablespacetree.js"></SCRIPT>
<SCRIPT LANGUAGE="JavaScript" src="../../zrsysmanage/script/Public.js"></SCRIPT>

<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())){ %>
<LINK type="text/css" rel="stylesheet" href="../../zrsysmanage/html5/css/style_tables.css">
<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";}
if (css=="Public.css")
{skincss = "default";}
if (css=="Window.css" || css=="nBlue.css")
{skincss = "mac";}
if (css=="Yellow.css")
{skincss = "pink";}


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

var dsOption= {

	fields :[
                {name : 'FIELDID'  },
		{name : 'FIELDNAME'  },
		{name : 'CHINESENAME'  },
                {name : 'FIELDTYPE'  },
                {name : 'FIELDLENGTH'  },
		{name : 'ISNULL'  },
		{name : 'FIELDTAG'  },
                {name : 'TAGEXT'  },
                {name : 'DICTTABLE'  },
                {name : 'AUTO1'  },
                {name : 'AUTO2'  },
                {name : 'AUTO3'  },
                {name : 'DESCRIPTION'  }
	],

	recordType : 'array',
	data : show_data
}


var colsOption = [

           {id: 'FIELDID' , header: "<center>字段ID</center>" , width :70 , align : 'center'  },
           {id: 'FIELDNAME' , header: "<center>字段名</center>" , width :120 , align : 'center'  },
           {id: 'CHINESENAME' , header: "<center>中文名称</center>" , width :120,  align : 'center'  },
           {id: 'FIELDTYPE' , header: "<center>字段类型</center>" , width :120,  align : 'center'  },
           {id: 'FIELDLENGTH' , header: "<center>字段长度</center>" , width :120,  align : 'center'  },
           {id: 'ISNULL' , header: "<center>是否可空</center>" , width :120,  align : 'center'  },
           {id: 'FIELDTAG' , header: "<center>特殊属性</center>" , width :120,  align : 'center'  },
           {id: 'TAGEXT' , header: "<center>扩展属性</center>" , width :120,  align : 'center'  },
           {id: 'DICTTABLE' , header: "<center>对应字典表</center>" , width :120,  align : 'center'  },
           {id: 'AUTO1' , header: "<center>对应字段1或前缀字母</center>" , width :120,  align : 'center'  },
           {id: 'AUTO2' , header: "<center>对应字段2</center>" , width :120,  align : 'center'  },
           {id: 'AUTO3' , header: "<center>对应字段3</center>" , width :120,  align : 'center'  },
           {id: 'DESCRIPTION' , header: "<center>描述</center>" , width :120,  align : 'center'  }
];



var gridOption={
	id : grid_demo_id,
	width: "800",
	height: "260",
	container : 'gridbox',
	replaceContainer : true,
	dataset : dsOption ,
	columns : colsOption,
	pageSize : 2000,
	toolbarContent : null,
        skin : skincss,

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

       showIndexColumn : true
};


<%if(!"6".equals(user.getUserWINDOWTYPE())){ %>
var mygrid=new Sigma.Grid( gridOption );
Sigma.Util.onLoad( Sigma.Grid.render(mygrid));
<%}%>
</script>

</HEAD>
<BODY class="BodyMain">
<form name="recordfrm" action="FieldList.jsp">
<input type="hidden"  id="tabletype" name="tabletype" value="<%=strTableType%>">

  <%if("6".equals(user.getUserWINDOWTYPE())){ %>
   <div id="mianRole" style="height: 300px;overflow: auto;">
   <%=chinesename%>[<%=name%>]一共有字段：<%=sum1%>个；记录数：<%=sum%>条；<br><Font class="WriteSign">提示：增加或修改字段时请先关闭第三方连接数据库的工具，否则可能执行不成功。</Font>
    <hr />
   <a style="margin-top: -15px" class="btn1 btn-medium btn-blue btn-radius" href="#" onclick="JavaScript:add();">增加字段</a>
   <a style="margin-top: -15px" class="btn1 btn-medium btn-blue btn-radius" href="#" onclick="JavaScript:edit();">编辑字段</a>

  <table class="bordered" id="html5_table">

<thead>
<tr>
<th style="width:60;">序号</th>
<th style="width:70;">字段ID</th>
<th style="width:120;">字段名</th>
<th style="width:200;">中文名称</th>
<th style="width:80;">字段类型</th>
<th style="width:80;">字段长度</th>
<th style="width:80;">是否可空</th>
<th style="width:120;">特殊属性</th>
<th style="width:120;">扩展属性</th>
<th style="width:120;">对应字典表</th>
<th style="width:80;">对应字段1或前缀字母</th>
<th style="width:80;">对应字段2</th>
<th style="width:80;">对应字段3</th>
<th style="width:80;">描述</th>

</tr>
</thead>

<%
if (TC!=null && TC.length>0){
  for(int i=0;i<TC.length;i++){
     %>
     <tr onclick="click_color(this,'<%=TC[i].getFIELDID() %>');">
        <td style="text-align:center;"><%=i+1 %></td>
        <td style="text-align:left;"><%=TC[i].getFIELDID() %></td>
        <td style="text-align:left;"><%=TC[i].getFIELDNAME() %></td>
        <td style="text-align:left;"><%=TC[i].getCHINESENAME() %></td>
        <td style="text-align:left;"><%=Hashtable1.get(TC[i].getFIELDTYPE()) %></td>
        <td style="text-align:left;"><%=TC[i].getFIELDLENGTH() %></td>
        <td style="text-align:left;"><%=Hashtable0.get(TC[i].getISNULL()) %></td>
        <td style="text-align:left;"><%=Hashtable2.get(TC[i].getFIELDTAG()) %></td>
        <td style="text-align:left;"><%=Hashtable3.get(String.valueOf(TC[i].getTAGEXT())) %></td>
        <td style="text-align:left;"><%=TC[i].getDICTTABLE() %></td>
        <td style="text-align:left;"><%=Field.GetFieldCHINESENAME(TC[i].getAUTO1()) %></td>
        <td style="text-align:left;"><%=Field.GetFieldCHINESENAME(TC[i].getAUTO2()) %></td>
        <td style="text-align:left;"><%=Field.GetFieldCHINESENAME(TC[i].getAUTO3()) %></td>
        <td style="text-align:left;"><%=TC[i].getDESCRIPTION() %></td>

     </tr>

     <%
  }
}

 %>
</table></div>

<%}else{ %>
   <table border='0' height="229" width="100%" background="../../zrsysmanage/images/<%=user.getUserImage()%>/databack2.jpg" cellspacing="0" cellpadding="0" align=center>
       <tr>
          <td  width="40%"></td>
          <td width="42%"></td>
          <td width="18%"></td>
        </tr>
       <tr>
          <td  width="40%"></td>
          <td width="42%"></td>
          <td width="18%"></td>
        </tr>

       <tr>
         <td  width="40%"></td>
         <td width="42%" valign="bottom"><%=chinesename%>[<%=name%>]一共有字段：<%=sum1%>个<br />记录数：<%=sum%>条
         <br><br><Font class="WriteSign">提示：增加或修改字段时请先关闭第三方连接数据库的工具，<br>否则可能执行不成功。</Font>

         </td>
         <td width="18%"></td>
       </tr>

        <tr><td width="40%"></td>
           <td width="42%" valign="bottom" align="left">
          <br>
           <table cellspacing="0" cellpadding="0" border='0'>
            <tr><td height='22'><a href="JavaScript:add();" title='增加字段'><img border='0' align='absmiddle' src='../../zrsysmanage/images/<%=user.getUserImage()%>/dataadd.gif'>&nbsp;增加字段</a></td>
               <td height='22'><a href="JavaScript:edit();" title='编辑字段'><img border='0' align='absmiddle' src='../../zrsysmanage/images/<%=user.getUserImage()%>/dataedit.gif'>&nbsp;编辑字段</a></td>
           </tr>
          </table>
      </td>
           <td width="18%"></td>
        </tr>
      </table>

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


  </form>
</BODY>
<script language="JavaScript" type="text/JavaScript">
<%if("6".equals(user.getUserWINDOWTYPE())){ %>
 var h=$(document.body).height();//浏览器当前窗口文档body的高度
 h=h*1-10;
 $('div').css('height',h);
<%}%>

var allvalue="";
function clickValue(value){
    allvalue=value;
}
function add(){
  var type = document.getElementById("tabletype").value;
  if (type=="1")
  {
     <%if("6".equals(user.getUserWINDOWTYPE())){ %>
         layer.alert('字典表不能增加字段!', {icon: 7});
       <%}else{%>
         alert("字典表不能增加字段！");
       <%}%>
     return;
  }
  <%if("6".equals(user.getUserWINDOWTYPE())){%>
  layer.open({
  type: 2,
  area: ['550px', '420px'],
  fix: false, //不固定
  maxmin: false,//是否可以最大化
  content: 'FieldAdd.jsp?TABLEID=<%=strtableid%>'
  });
  <%}else{%>
  var url="FieldAdd.jsp?TABLEID=<%=strtableid%>";
  var name="PopWindow";
  var ShowPopWindow = null;
  var status="toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=yes,scrollbars=yes,width=550,height=490";
  ShowPopWindow = window.open(url,name,status);
  ShowPopWindow.moveTo(200,150);
  ShowPopWindow.focus();
  <%}%>
}
function edit(){
    var type = document.getElementById("tabletype").value;
    if (type=="1")
    {
       <%if("6".equals(user.getUserWINDOWTYPE())){ %>
         layer.alert('字典表不能修改字段!', {icon: 7});
       <%}else{%>
         alert("字典表不能修改字段！");
       <%}%>
       return;
    }

  <%if("6".equals(user.getUserWINDOWTYPE())){ %>
         var strID = allvalue;
         if(strID!=""){
             layer.open({
               type: 2,
               area: ['550px', '420px'],
               fix: false, //不固定
               maxmin: false,//是否可以最大化
               content: 'FieldEdit.jsp?TABLEID=<%=strtableid%>&SelectedItems='+strID
               });
         }else{
             layer.alert('请选择要操作的数据!', {icon: 7});
         }
    <%}else{%>
         var allvalue = mygrid.getSelectedRecords()+",0";
         var strID = allvalue.split(",")[0];
         var url="FieldEdit.jsp?SelectedItems="+strID+"&TABLEID=<%=strtableid%>";
      var name="PopWindow";
      var ShowPopWindow = null;
      var status="toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=yes,scrollbars=yes,width=550,height=490";
      ShowPopWindow = window.open(url,name,status);
      ShowPopWindow.moveTo(200,150);
      ShowPopWindow.focus();
    <%}%>
}

</script>
</HTML>
<%
//清空相关对象
user = null;
userUI = null;
Field = null;
Table = null;
TC = null;
%>
