<!--#include file ="Conn.asp"-->
<!--#include file ="Check_Manager.asp"-->
<%
If Request.QueryString("action")="addc" Then
Dim lr
Dim le
Dim lb
Dim sql
Dim cname
cname = Trim(Request.QueryString("tname"))
le = Trim(Request.Form("aa0"))
lr = Trim(left(Request.Form("LB0"),2))
lb = Trim(Request.Form("CD0"))
 select case lr
  case "字符"
      le =le & " varchar("&lb&")"
  case "链接"
      le =le & "  varchar(212)"
  case "图片"
      le =le & "  varchar(211)"
  case "整数"
      le=le &  " int"
  case "数字"
      le=le &  " NUMERIC"
  case "日期"
      le=le &  " date"
  case "备注"
      le=le &  " MEMO"
 end select
sql = "ALTER TABLE "&cname&" ADD "&le&""
Conn.ExeCute(Sql)
JaSys("管理员" & session("ManagerUser")&"添加字段<font color=red>["&cname&"]["&le&"]</font>")
Response.write "<script language='javascript'>" & chr(13)
		Response.write "alert('数据字段添加成功!');" & Chr(13)
		Response.write "window.document.location.href='JaAcc_edit.asp?tname="&cname&"';"&Chr(13)
		Response.write "</script>" & Chr(13)
      Response.End
End If
%>
<html>
<head>
<title>管理中心</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312"><LINK href="admin/admin.css" type=text/css rel=stylesheet><script language="JavaScript" src="admin/js.js"></SCRIPT></head>
<SCRIPT language=javascript>
function ConfirmDel()
{
   if(confirm("确定要删除吗？一旦删除将不能恢复！"))
     return true;
   else
     return false;	 
}
</Script>
<Script language="JavaScript">
 
 function reSubmit0(theform) {  
 with (theform) {
 var arr;
 arr =LB0.value.split("&");
 CD0.value = arr[1];
  if (arr[1]=213) {
   document.reSelected.CD0.Enabled="False;"
    }
 } }
 
  
 function chk1()
{

  if (document.reSelected.CD0.value>255)
  {
    alert("字段不能大于255！");
    document.reSelected.CD0.focus();
    return false;
  }
   if (document.reSelected.aa0.value=="")
  {
    alert("字段不能为空！");
    document.reSelected.aa0.focus();
    return false;
  }
}
  
</Script>

<%
Dim tname
tname = Request.QueryString("tname")
function fieldtype(typeid)
select case typeid
	case 130	fieldtype = "文本"
	case 2		fieldtype = "整型"
	case 3		fieldtype = "长整型"
	case 7		fieldtype = "日期/时间"
	case 5		fieldtype = "双精度型"
	case 11		fieldtype = "是/否"
	case 128	fieldtype = "OLE 对象"
	case else	fieldtype = typeid
end select
end function
%>
<script language="JavaScript" type="text/JavaScript">
function chk()
{
  if (document.form1.cmd.value=="")
  {
    alert("语句不能为空！");
    document.form1.cmd.focus();
    return false;
  }
}
</script>
<body text="#000000">

<table width="87%" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr> 
    <td width="48%" height="15">
<div align="center"><a href="JaAcc_Manage.asp">返回数据表选择页面</a></div></td>
    <td width="52%"><strong><font color="#990000">对表操作：</font><a href="JaAcc_editacc.Asp?tname=<%=tname%>">修改表属性</a>   &nbsp;&nbsp;<a href="JaAcc_del.Asp?tname=<%=tname%>" onclick="return ConfirmDel();">删除此表</a></strong></td>
  </tr>
</table>
<br>
<table width="87%" border="0" align="center" cellpadding="4" cellspacing="0" class=tableBorder>
  <tr> 
    <td height="25" background="admin/admin_bg_1.gif"><div align="center"><strong><font color="#FFFFFF">数据库表<font color=#990000>[ <%=tname%> ]</font>管理</font></strong></div></td>
  </tr>
<tr> 
    <td height="25"><table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
         
    <tr bgcolor="#FFFFCC"> 
          <td width="29%" height="8"><b><font color=#990000>字段名</font></b></td>
          <td width="12%" height="8"><b><font color=#990000>数据类型</font></b></td>
          <td width="11%" height="8"><b><font color=#990000>字段大小</font></b></td>
          <td width="9%"  height="8"><b><font color=#990000>精度</font></b></td>
          <td width="17%" height="8"><b><font color=#990000>是否允许为空</font></b></td>
          <td width="12%" height="8"><b><font color=#990000>默认值</font></b></td>
          <td width="10%" height="8"><b><font color=#990000>操作</font></b></td>
        </tr>
   <tr>
    <%
      
     Set objColumnRS = Conn.OpenSchema(4,Array(Empty, Empty, tname))
     do while not objColumnRS.EOF
      iLength = objColumnRS("Character_Maximum_Length")
		iPrecision = objColumnRS("Numeric_Precision")	
	            iScale = objColumnRS("Numeric_Scale")
		iDefaultValue = objColumnRS("Column_Default")
              	If IsNull(iLength) then iLength = "&nbsp;"	
	            If IsNull(iPrecision) then iPrecision = "&nbsp;"
		If IsNull(iScale) then iScale = "&nbsp;"
		If IsNull(iDefaultValue) then iDefaultValue = "&nbsp;"%>
 <td width="29%" height="20"><%=objColumnRS("Column_Name")%></td>
          <td width="12%" height="20"><%=fieldtype(objColumnRS("Data_Type"))%></td>
          <td width="11%" height="20" align="center"><%=iLength%></td>
          <td width="9%" height="20"><%=iPrecision%></td>
          <td width="17%" align="center" height="20"> 
            <%If objColumnRS("Is_Nullable") then
			Response.Write "是"
            else
            Response.write "否"
		End If%>
          </td>
          <td width="12%" height="8"><%=iDefaultValue%></td>
           <td width="10%" height="8"><a href="JaAcc_Del.Asp?action=delc&cname=<%=objColumnRS("Column_Name")%>&tname=<%=tname%>" onclick="return ConfirmDel();">删除</a></td>
        </TR>
        <%
         objColumnRS.MoveNext
         Loop
         Set objColumnRS = Nothing	
        %> 
 </tr>
      </table> </td>
  </tr>
</table>
<br>
<form name="reSelected" method="post" action="JaAcc_edit.Asp?action=addc&tname=<%=tname%>" onSubmit="return chk1(this)">
<table width="87%" border="0" align="center" cellpadding="4" cellspacing="0" class=tableBorder>
  <tr> 
    <td height="25" background="admin/admin_bg_1.gif"><div align="center"><strong><font color=#ffffff>创建新字段</font></strong></div></td>
  </tr>
  <tr>
    <td height="41"> 
 
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
   
        <tr> 
          <td width="31%" height="33"><div align="center"><font color=#990000><b><strong>字段名</strong> 
              <input class=input  type="text" name="aa0" value="">
              </b></font></div></td>
          <td width="29%"> <strong>字段类型 
            <select name=LB0 onChange=reSubmit0(this.form)>
              <option value='字符&50'>字符</option>
              <option value='数字&18'>数字</option>
              <option value='整数&10'>整数</option>
              <option value='链接&212'>链接</option>
              <option value='日期&8'>日期</option>
              <option value='图片&211'>图片</option>
              <option value='备注&0'>备注</option>
            </select>
            </strong></td>
          <td width="40%"><div align="center"><strong>字段宽度</strong> 
              <input name='CD0' type='text' class=input value='50' size="20">
              <input type=submit value="创建" name=Submit>
              <input type=reset value="重置" name=Submit2>
            </div></td>
        </tr>
      </table></tr>
</table>
</form>
 <br>
<table width="87%" border="0" align="center" cellpadding="4" cellspacing="0" class=tableBorder>
  <tr> 
    <td height="25" background="admin/admin_bg_1.gif"><div align="center"><strong><font color="#FFFFFF">数据库表<font color=#990000>[ 
        <%=tname%> ]</font>数据列表<font color="#990000">(列出最新10条记录)</font></font></strong></div></td>
  </tr>
  <tr> 
    <td height="25"> 

     <table width="100%" border="1" cellspacing="0" cellpadding="3" bordercolorlight="#000000" bordercolordark="#FFFFFF">
        <tr bgcolor="#ffffff" align="center" valign="top">
<%dim mysql,objRS,i,j
j=1
mysql="Select Top 10 * From ["&tname&"]"
Set objRS=Conn.Execute(mysql)
'response.write "<td>操作</td>"
For i=0 to objRs.Fields.Count-1
Response.write"<td><b>"&objRS.Fields(i).name&"</b></td>"
Next
Response.write "</tr>"
if objrs.eof then

else
DO While NOT objRS.Eof
Response.write "<tr>"
%>

<%
For i=0 to objRs.Fields.Count-1
Response.write"<td>"
If IsNull(objRs.Fields(i).value) or objRs.Fields(i).value="" or objRs.Fields(i).value=" " then
response.write "&nbsp;"
else
  Response.write Server.HTMLEncode(objRs.Fields(i).value)
 end if
Response.write"</td>"
Next
Response.write"</tr>"
objRS.MoveNext
j=j+1
Loop
end if
set objRs = nothing
set objTableRS = nothing
objConn.Close
set objConn = nothing
%>
     </table></tr>
</table>
<%
If Request.QueryString("action")="do" Then
Dim cmd
cmd = Request.Form("cmd")
Set objRS = Conn.ExeCute(cmd)
%>
<br>
<table width="87%" border="0" align="center" cellpadding="4" cellspacing="0" class=tableBorder>
  <tr> 
    <td height="25" background="admin/admin_bg_1.gif"><div align="center"><strong><font color="#FFFFFF">命令返回结果</font></strong></div></td>
  </tr>
  <tr> 
    <td height="25"> 
  <table width="100%" border="1" cellspacing="0" cellpadding="3" bordercolorlight="#000000" bordercolordark="#FFFFFF">
        <tr bgcolor="#fffff" align="center" valign="top">
<%
if objrs.state = 1 then 
For i=0 to objRs.Fields.Count-1
Response.write"<td><b>"&objRS.Fields(i).name&"</b></td>"
Next
Response.write "</tr>"
if objrs.eof then
else
DO While NOT objRS.Eof
Response.write "<tr>"
For i=0 to objRs.Fields.Count-1
Response.write"<td>"
If IsNull(objRs.Fields(i).value) or objRs.Fields(i).value="" or objRs.Fields(i).value=" " then
response.write "&nbsp;"
else
  Response.write Server.HTMLEncode(objRs.Fields(i).value)
 end if
Response.write"</td>"
Next
Response.write"</tr>"
objRS.MoveNext
j=j+1
Loop
end if
end if
set objRs = nothing
set objTableRS = nothing
objConn.Close
set objConn = nothing
Response.Write "</table><br>"
if request("cmd")<>"" then response.Write("SQL命令执行成功，返回 <font color=""#FF0000"">"&j&"</font> 条记录")
Response.Write "</table></tr></table>"


End If
%>

<form name="form1" action="?action=do&tname=<%=tname%>" method="post" onSubmit="return chk(this)">
<table width="87%" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td height="61"><div align="center">
        <input name="cmd" type="text" id="cmd" size="60">
        <input name="submit" type="submit" value="执行SQL">
      </div></td>
  </tr>
</table>
