<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<% Option Explicit %>
<%
if session("superlogin")="" then
response.Write "<script>alert('您还没有登陆！');this.location.href='index.asp';</script>"
Response.End
elseif session("superadmin")<>"admin" then
response.Write "<script>alert('您不是超级管理员！您的权限不足！');this.location.href='index.asp';</script>"
Response.End
end if
	Const adEmpty = 0
	Const adTinyInt = 16
	Const adSmallInt = 2
	Const adInteger = 3
	Const adBigInt = 20
	Const adUnsignedTinyInt = 17
	Const adUnsignedSmallInt = 18
	Const adUnsignedInt = 19
	Const adUnsignedBigInt = 21
	Const adSingle = 4
	Const adDouble = 5
	Const adCurrency = 6
	Const adDecimal = 14
	Const adNumeric = 131
	Const adBoolean = 11
	Const adError = 10
	Const adUserDefined = 132
	Const adVariant = 12
	Const adIDispatch = 9
	Const adIUnknown = 13
	Const adGUID = 72
	Const adDate = 7
	Const adDBDate = 133
	Const adDBTime = 134
	Const adDBTimeStamp = 135
	Const adBSTR = 8
	Const adChar = 129
	Const adVarChar = 200
	Const adLongVarChar = 201
	Const adWChar = 130
	Const adVarWChar = 202
	Const adLongVarWChar = 203
	Const adBinary = 128
	Const adVarBinary = 204
	Const adLongVarBinary = 205
	Const adChapter = 136
	Const adFileTime = 64
	Const adPropVariant = 138
	Const adVarNumeric = 139
	Const adArray = &H2000
	
	'---- FieldAttributeEnum Values ----
	Const adFldMayDefer = &H00000002
	Const adFldUpdatable = &H00000004
	Const adFldUnknownUpdatable = &H00000008
	Const adFldFixed = &H00000010
	Const adFldIsNullable = &H00000020
	Const adFldMayBeNull = &H00000040
	Const adFldLong = &H00000080
	Const adFldRowID = &H00000100
	Const adFldRowVersion = &H00000200
	Const adFldCacheDeferred = &H00001000
	Const adFldIsChapter = &H00002000
	Const adFldNegativeScale = &H00004000
	Const adFldKeyColumn = &H00008000
	Const adFldIsRowURL = &H00010000
	Const adFldIsDefaultStream = &H00020000
	Const adFldIsCollection = &H00040000
	
	'---- SchemaEnum Values ----
	Const adSchemaProviderSpecific = -1
	Const adSchemaAsserts = 0
	Const adSchemaCatalogs = 1
	Const adSchemaCharacterSets = 2
	Const adSchemaCollations = 3
	Const adSchemaColumns = 4
	Const adSchemaCheckConstraints = 5
	Const adSchemaConstraintColumnUsage = 6
	Const adSchemaConstraintTableUsage = 7
	Const adSchemaKeyColumnUsage = 8
	Const adSchemaReferentialConstraints = 9
	Const adSchemaTableConstraints = 10
	Const adSchemaColumnsDomainUsage = 11
	Const adSchemaIndexes = 12
	Const adSchemaColumnPrivileges = 13
	Const adSchemaTablePrivileges = 14
	Const adSchemaUsagePrivileges = 15
	Const adSchemaProcedures = 16
	Const adSchemaSchemata = 17
	Const adSchemaSQLLanguages = 18
	Const adSchemaStatistics = 19
	Const adSchemaTables = 20
	Const adSchemaTranslations = 21
	Const adSchemaProviderTypes = 22
	Const adSchemaViews = 23
	Const adSchemaViewColumnUsage = 24
	Const adSchemaViewTableUsage = 25
	Const adSchemaProcedureParameters = 26
	Const adSchemaForeignKeys = 27
	Const adSchemaPrimaryKeys = 28
	Const adSchemaProcedureColumns = 29
	Const adSchemaDBInfoKeywords = 30
	Const adSchemaDBInfoLiterals = 31
	Const adSchemaCubes = 32
	Const adSchemaDimensions = 33
	Const adSchemaHierarchies = 34
	Const adSchemaLevels = 35
	Const adSchemaMeasures = 36
	Const adSchemaProperties = 37
	Const adSchemaMembers = 38
	Const adSchemaTrustees = 39
	Const adSchemaFunctions = 40
	Const adSchemaActions = 41
	Const adSchemaCommands = 42
	Const adSchemaSets = 43

	
	Dim sMainTblString
	sMainTblString ="<table width='100%' border='0' cellpadding='0' cellspacing='0' class='3d'>" & vbCrLf & _
					"  <tr> " & vbCrLf & _
					"    <td><table width='100%' border='0' cellpadding='3' cellspacing='0' class='tdTitle'>" & vbCrLf & _
					"        <tr> " & vbCrLf & _
					"          <td>[title]</td>" & vbCrLf & _
					"          <td>&nbsp;</td>" & vbCrLf & _
					"          <td align='right'>千纸鹤网站管理系统 数据库在线管理工具</td>" & vbCrLf & _
					"        </tr>" & vbCrLf & _
					"      </table></td>" & vbCrLf & _
					"  </tr>" & vbCrLf & _
					"  <tr> " & vbCrLf & _
					"    <td><table width='100%' border='0' cellpadding='3' cellspacing='1' class='tdTitle'>" & vbCrLf & _
					"	    [body]" & vbCrLf & _
					"      </table></td>" & vbCrLf & _
					"  </tr>" & vbCrLf & _
					"</table>"
		
	Function IIf(exp1,val1,val2)
		If (exp1) Then
			IIf = val1
		Else
			IIf = val2
		End If
	End Function
	
	Function String4Js(s)
		If isNull(s) Then String4Js="" : Exit Function
		String4Js = Replace(Replace(Replace(Replace(s,"\","\\"),"""","\"""),"'","\'"),vbCrLf,"\n")
	End Function
	
	Function GetFieldType(sType)
		Select Case sType 
		Case adEmpty 
			GetFieldType = "Empty" 
		Case adTinyInt 
			GetFieldType = "TinyInt" 
		Case adSmallInt 
			GetFieldType = "SmallInt" 
		Case adInteger 
			GetFieldType = "Int" 
		Case adBigInt 
			GetFieldType = "BigInt" 
		Case adUnsignedTinyInt 
			GetFieldType = "TinyInt" 
		Case adUnsignedSmallInt 
			GetFieldType = "UnsignedSmallInt" 
		Case adUnsignedInt 
			GetFieldType = "UnsignedInt" 
		Case adUnsignedBigInt 
			GetFieldType = "UnsignedBigInt" 
		Case adSingle 
			GetFieldType = "Real" 
		Case adDouble 
			GetFieldType = "Float" 
		Case adCurrency 
			GetFieldType = "Money" 
		Case adDecimal 
			GetFieldType = "Decimal" 
		Case adNumeric 
			GetFieldType = "Numeric" 
		Case adBoolean 
			GetFieldType = "Bit" 
		Case adError 
			GetFieldType = "Error" 
		Case adUserDefined 
			GetFieldType = "UserDefined" 
		Case adVariant 
			GetFieldType = "sql_Variant" 
		Case adIDispatch 
			GetFieldType = "IDispatch" 
		Case adIUnknown 
			GetFieldType = "IUnknown" 
		Case adGUID 
			GetFieldType = "UniqueIdentifier" 
		Case adDATE 
			GetFieldType = "DateTime" 
		Case adDBDate 
			GetFieldType = "DBDate" 
		Case adDBTime 
			GetFieldType = "DBTime" 
		Case adDBTimeStamp 
			GetFieldType = "DateTime" 
		Case adBSTR 
			GetFieldType = "BSTR" 
		Case adChar 
			GetFieldType = "Char" 
		Case adVarChar 
			GetFieldType = "VarChar" 
		Case adLongVarChar 
			GetFieldType = "Text" 
		Case adWChar 
			GetFieldType = "nChar" 
		Case adVarWChar 
			GetFieldType = "nVarChar" 
		Case adLongVarWChar 
			GetFieldType = "nText" 
		Case adBinary 
			GetFieldType = "TimeStamp" 
		Case adVarBinary 
			GetFieldType = "VarBinary" 
		Case adLongVarBinary 
			GetFieldType = "Image" 
		Case adChapter 
			GetFieldType = "Chapter" 
		Case adPropVariant 
			GetFieldType = "PropVariant" 
		Case else 
			GetFieldType = "Unknown" 
		End Select
	End Function

	
	Class CC_DBTools
		
		Dim sLastErrDescription, sSqlString
		Dim iPageSize, iPageCount, iCurrPage, iRecCount
		Dim iDbType, sDbPath, bDbActived
		Dim oConn, sConnString, sConnType
		Dim aOleDbString(2), aODBCString(2)
		Dim aObjList()
		
		Private Sub Class_Initialize
			'//初始化类
			Set oConn = Server.CreateObject("ADODB.Connection")
			aOleDbString(0) = "Provider=Microsoft.Jet.OleDb.4.0;Data Source="
			aODBCString(0) = "DRIVER={Microsoft Access Driver (*.mdb)};Dbq="
			aOleDbString(1) = "Provider=SQLOLEDB.1;Data Source="
			aODBCString(1) = "Driver={SQL Server};SERVER="
			iDbType = 0
			sConnType = "OleDb"
			sConnString = aOleDbString(iDbType)
			bDbActived = false
			sLastErrDescription = ""
			iPageSize=20
			iPageCount=0
			iCurrPage=1
			iRecCount=0
		End Sub
		
		Private Sub Class_Terminate
			'//结束类
			Set oConn = Nothing
		End Sub
		
		Public Property Let DataBaseType(s)
			Select Case s
			Case "MSSQL" : iDbType = 1
			Case "ACCESS" : iDbType = 0
			End Select
		End Property
		
		Public Property Let ConnType(s)
			sConnType = s
			Select Case s
			Case "ODBC" : sConnString = aODBCString(iDbType)
			Case "OLEDB" : sConnString = aOleDbString(iDbType)
			End Select
		End Property
		
		Public Property Let DbPath(s)
			sDbPath = s
			Select Case iDbType
			Case 0 
				If Len(sDbPath)<1 Then  Exit Property
				sConnString = sConnString & Server.MapPath(s) & ";"
			Case 1
				sConnString = sConnString & s & ";"
			End Select
		End Property
		
		Public Property Let DbUID(s)
			Select Case sConnType
			Case "ODBC" : sConnString = sConnString & "UID=" & s & ";"
			Case "OLEDB" : sConnString = sConnString & "User ID=" & s & ";"
			End Select
		End Property
		
		Public Property Let DbPWD(s)
			Select Case sConnType
			Case "ODBC" : sConnString = sConnString & "PWD=" & s & ";"
			Case "OLEDB" : sConnString = sConnString & "Password=" & s & ";"
			End Select
		End Property
		
		Public Property Let DbCatelog(s)
			Select Case iDbType
			Case 0
			Case 1
				Select Case sConnType
				Case "ODBC" : sConnString = sConnString & "DATABASE=" & s & ";"
				Case "OLEDB" : sConnString = sConnString & "DATABASE=" & s & ";"
				End Select
			End Select
		End Property
		
		Public Property Get ConnString
			ConnString = oConn.ConnectionString
		End Property
		
		Public Property Get isActive
			isActive = bDbActived
		End Property
		
		Public Function Open()
			on error Resume Next
			If Request.ServerVariables("REQUEST_METHOD")<>"POST" Then Exit Function
			oConn.ConnectionString = sConnString
			oConn.Open()
			If Err Then
				sLastErrDescription = Err.Description
				Err.Clear()
				Exit Function
			End If
			bDbActived = true
		End Function
		
		Public Property Get Conn
			Set Conn = oConn
		End Property
		
		Public Property Get GetLastError
			GetLastError = sLastErrDescription
		End Property
		
		Public Function GetDbObject()
			Dim rsObj
			ReDim aObjList(-1)
			If UBound(aObjList)>0 Then GetDbObject = aObjList : Exit Function
			Set rsObj = oConn.openSchema(20)
			rsObj.Filter = "TABLE_TYPE='TABLE' OR TABLE_TYPE='VIEW'"
			Do While Not rsObj.Eof
				ReDim Preserve aObjList(UBound(aObjList)+1)
				aObjList(UBound(aObjList)) = Array(rsObj("TABLE_NAME").value,rsObj("TABLE_TYPE").value)
				rsObj.MoveNext()
			Loop
			Set rsObj = Nothing
			GetDbObject = aObjList
		End Function
		
		Public Function doSql(s)
			On Error Resume Next
			sSqlString = Trim(s)
			IF StrComp(Left(sSqlString,6),"SELECT")=0 Then
				'Set doSql = doSelect(sSqlString,20,1)
				Set doSql = Nothing
				Exit Function
			Else
				oConn.Execute( s )
				Set doSql = Nothing
				If Err Then
					sLastErrDescription = Err.Description
					Err.Clear()
					Exit Function
				End If
				sLastErrDescription = "执行成功！"
			End If
		End Function
		
		Public Function doSelect(sSqlString,iPgSz,iPgNo)
			On Error Resume Next
			iCurrPage = iPgNo
			If Not isNumeric(iCurrPage) Then iCurrPage = 1
			If CInt(iCurrPage)<1 Then iCurrPage = 1
			Set doSelect = Server.CreateObject("ADODB.Recordset")
			doSelect.Open sSqlString,oConn,1,3
			If Err Then
				sLastErrDescription = Err.Description
				Err.Clear()
				Set doSelect = Nothing
				Exit Function
			End If
			If Not doSelect.Eof Then
				iRecCount = doSelect.RecordCount
				doSelect.PageSize = iPgSz
				iPageSize = iPgSz
				iPageCount = doSelect.PageCount
				If CInt(iCurrPage)>CInt(iPageCount) Then iCurrPage = iPageCount
				doSelect.AbsolutePage = CInt(iCurrPage)
			End If
			sLastErrDescription = "执行成功！"
		End Function
		
		Public Function GetPrimaryKey(sTName)
			on error Resume Next
			Dim rsPrimary
			GetPrimaryKey = ""
			Set rsPrimary = oConn.OpenSchema(adSchemaPrimaryKeys,Array(Empty,Empty,sTblName))
			If Not rsPrimary.Eof Then GetPrimaryKey = rsPrimary("COLUMN_NAME")
			Set rsPrimary = Nothing
		End Function
		
		Public Function GetColumnInfo(sTName,sCName)
			Set GetColumnInfo = oConn.OpenSchema(adSchemaColumns,Array(Empty,Empty,sTName,sCName))
		End Function
		
		Public Property Get PageCount
			PageCount = iPageCount
		End Property
		
		Public Property Get RecCount
			RecCount = iRecCount
		End Property
		
		Public Property Get PageNo
			If CInt(iCurrPage) > CInt(iPageCount) Then iCurrPage = iPageCount
			PageNo = iCurrPage
		End Property
	
	End Class
	
	On Error Resume Next
	Dim CCDbT, i, sTblType, iPageSize
	Dim aObjList, sShowBody, iPageNo
	Dim sSqlString, sOper, sTblName
	sSqlString = Request("sSqlString")
	sOper = Request("sOper")
	sTblName = Request("sTblName")
	sTblType = Request("sTblType")
	iPageNo = Request("PageNo")
	
	Set CCDbT = New CC_DBTools
	CCDbT.DataBaseType = Request("sDbType")
	CCDbT.ConnType = Request("sConnType")
	CCDbT.Dbpath = Request("sDbPath")
	CCDbT.DbUID = Request("sUID")
	CCDbT.DbPWD = Request("sPWD")
	CCDbT.DbCatelog = Request("sDbName")
	CCDbT.Open()
	
	iPageSize = 10
%>
<!--
'[ www.cocoon.6to23.com ]
-->
<html>
<head>
<title>飞扬网站管理系统 数据库在线管理工具</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<style type="text/css">
<!--

A:visited{TEXT-DECORATION: none;color:#000000;}
A:active{TEXT-DECORATION: none;color:red;}
A:link{text-decoration: none;color:000;}
A:hover {TEXT-DECORATION: none;color:red}
BODY{COLOR: #000000;background:D4D0C8; 
scrollbar-3d-light-color:#000000;
scrollbar-arrow-color:#000000;
scrollbar-base-color:#D4D0C8;
scrollbar-darkshadow-color:#000000;
scrollbar-face-color:#D4D0C8;
scrollbar-highlight-color:#ffffff;
scrollbar-shadow-color:#999999;
scrollbar-track-color:#D4D0C8;
overflow:auto}
FORM {PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0px; MARGIN: 0px; PADDING-TOP: 0px}
td{font-size: 9pt}
TABLE{FONT-SIZE: 9pt;BORDER-COLLAPSE: collapse;background:#d0d4c8}
.1BorderTable {border: 1px solid #000;}
.inputText {width: 100%;}
.bg{background:#d0d4c8}
.inputButton {width: 102px;background:#D4D0C8;color:#000;BORDER-RIGHT:1px solid #666;BORDER-TOP:1px solid #ffffff;border-left:1px solid #ffffff;BORDER-bottom:1px solid #666;font-size:9pt}
.tdTitle {color: #000;background-color: #d0d4c8;}
.inputText0Border {width: 100%;border: none;}
textarea{border: 1px solid #666666;color:000}
.button{background:#D4D0C8;color:#000;BORDER-RIGHT:1px solid #666;BORDER-TOP:1px solid #ffffff;border-left:1px solid #ffffff;BORDER-bottom:1px solid #666;font-size:9pt}
.3d{BORDER-RIGHT:1px solid #000;BORDER-TOP:1px solid #ffffff;border-left:1px solid #ffffff;BORDER-bottom:1px solid #000;}
.jinzhe{border:1px solid #666666;height:20}
-->
</style>
<script language="JavaScript">
var sNewFieldString = '<s'+'cript language="JavaScript">'
	+ '\n' + getObjByID.toString()
	+ '\n' + showFieldType.toString()
	+ '\n' + checkFieldType.toString()
	+ '\n' + checkInput.toString()
	+ '\n' +'function doNewField(o){'
	+ '\n' +'	var sSqlString = "";'
	+ '\n' +'	if(o.fieldName.value.length==0){alert("请输入字段名");o.fieldName.focus();return false;}'
	+ '\n' +'	if(!checkInput(o.fieldName.value)){alert("名称中包含非法字符，请重新输入");return false;}'
	+ '\n' +'	sSqlString = "ALTER TABLE ["+o.sTblName.value+"] \\n"'
	+ '\n' +'	+ "    ADD COLUMN ["+o.fieldName.value+"] "+o.fieldType[o.fieldType.selectedIndex].value'
	+ '\n' +'	+ (o.fieldSize.value?"("+o.fieldSize.value+")":"") + " "'
	+ '\n' +'	+ (o.isNULL.checked?"NULL":"NOT NULL") + " \\n"'
	+ '\n' +'	+ (o.fieldPK.checked?"PRIMARY KEY":"") + " "'
	+ '\n' +'	+ (parseInt(o.fieldSeed.value)&&parseInt(o.fieldIncre.value)?"IDENTITY ("+o.fieldSeed.value+","+o.fieldIncre.value+")":"") + " \\n"'
	+ '\n' +'	+ (o.fieldDefault.value?"DEFAULT "+o.fieldDefault.value+" WITH VALUES":"");'
	+ '\n' +'	var oFormSQL = window.opener.getObjByID("formSQL");'
	+ '\n' +'	oFormSQL.sSqlString.value = sSqlString;'
	+ '\n' +'	oFormSQL.sOper.value = "Design";'
	+ '\n' +'	if(!confirm("确认要添加新列吗？")) return false;'
	+ '\n' +'	oFormSQL.submit();'
	+ '\n' +'}'
	+ '\n' +'</scrip'+'t>'
	+ '\n' +'<table width="500" border="1" cellspacing="0" cellpadding="0">'
	+ '\n' +'  <form name="formAddFld" id="formAddFld" method="post" onSubmit="doNewField(this);return false;">'
	+ '\n' +'  <tr> '
	+ '\n' +'    <td colspan="2">为表 [table name] 添加新字段</td>'
	+ '\n' +'  </tr>'
	+ '\n' +'  <tr> '
	+ '\n' +'    <td width="30%">字段名</td>'
	+ '\n' +'    <td><input name="fieldName" type="text" id="fieldName" size="30"></td>'
	+ '\n' +'  </tr>'
	+ '\n' +'  <tr> '
	+ '\n' +'    <td>类型</td>'
	+ '\n' +'    <td>'
	+ '\n' +'<select id="fieldType" name="fieldType" onChange="checkFieldType(this.value,this[this.selectedIndex].sLength)" onBlur="showFieldType(0)" onFocus="window.currElement=this;" style="width:130">'
	+ '\n' +'<OPTION value=TinyInt sLength=1>TinyInt'
	+ '\n' +'<OPTION value=SmallInt sLength=1>SmallInt'
	+ '\n' +'<OPTION value=Int sLength=1>Int'
	+ '\n' +'<OPTION value=BigInt sLength=1>BigInt'
	+ '\n' +'<OPTION value=Real sLength=1>Real / Single'
	+ '\n' +'<OPTION value=Float sLength=1>Float / Double'
	+ '\n' +'<OPTION value=Money sLength=1>Money'
	+ '\n' +'<OPTION value=Decimal sLength=1>Decimal'
	+ '\n' +'<OPTION value=Numeric sLength=1>Numeric'
	+ '\n' +'<OPTION value=Bit sLength=1>Bit'
	+ '\n' +'<OPTION value=Variant>Variant'
	+ '\n' +'<OPTION value=UniqueIdentifier sLength=1>UniqueIdentifier'
	+ '\n' +'<OPTION value=DateTime sLength=1>DateTime'
	+ '\n' +'<OPTION value=Char selected>Char'
	+ '\n' +'<OPTION value=VarChar>VarChar'
	+ '\n' +'<OPTION value=Text sLength=1>Text'
	+ '\n' +'<OPTION value=nChar>nChar'
	+ '\n' +'<OPTION value=nVarChar>nVarChar'
	+ '\n' +'<OPTION value=nText sLength=1>nText'
	+ '\n' +'<OPTION value=TimeStamp sLength=1>TimeStamp'
	+ '\n' +'<OPTION value=VarBinary sLength=1>VarBinary'
	+ '\n' +'<OPTION value=Image sLength=1>Image'
	+ '\n' +'</select>'
	+ '\n' +'	</td>'
	+ '\n' +'  </tr>'
	+ '\n' +'  <tr> '
	+ '\n' +'    <td>宽度</td>'
	+ '\n' +'    <td><input name="fieldSize" type="text" id="fieldSize"  value="50" size="30"></td>'
	+ '\n' +'  </tr>'
	+ '\n' +'  <tr> '
	+ '\n' +'    <td>允许空</td>'
	+ '\n' +'    <td><input name="isNULL" type="checkbox" id="isNULL" value="checkbox" checked></td>'
	+ '\n' +'  </tr>'
	+ '\n' +'  <tr> '
	+ '\n' +'    <td>主键</td>'
	+ '\n' +'    <td><input name="fieldPK" type="checkbox" id="fieldPK" value="PRIMARY KEY"></td>'
	+ '\n' +'  </tr>'
	+ '\n' +'  <tr> '
	+ '\n' +'    <td>递增</td>'
	+ '\n' +'    <td>种子数 <input name="fieldSeed" type="text" id="fieldSeed" size="5">'
	+ '\n' +'      递增量 '
	+ '\n' +'      <input name="fieldIncre" type="text" id="fieldIncre" size="5"></td>'
	+ '\n' +'  </tr>'
	+ '\n' +'  <tr> '
	+ '\n' +'    <td>默认值</td>'
	+ '\n' +'    <td><input name="fieldDefault" type="text" id="fieldName4" size="30"></td>'
	+ '\n' +'  </tr>'
	+ '\n' +'  <tr>'
	+ '\n' +'    <td>&nbsp;</td>'
	+ '\n' +'    <td align="right">'
	+ '\n' +'	<input type="hidden" name="sTblName" value="[table name]">'
	+ '\n' +'	<input type="submit" name="Submit2" value="确定">'
	+ '\n' +'      <input name="Reset" type="reset" id="Reset" value="关闭" onClick="window.close();"></td>'
	+ '\n' +'  </tr>'
	+ '\n' +'  </form>'
	+ '\n' +'</table>';

var CCNS_program = "COCOON  DB Tools";
var CCNS_version = "Final Release";
function getObjByID(n) {

//This function was re-written form DreamWeaver v4.01 by Sunrise_Chen.
	var p,i,x;
	var d=document; 
	if(!(x=d[n])&&d.all) x=d.all[n];
	for(i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
	for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=getObjByID(n,d.layers[i].document);
	if(!x && d.getElementById) x=d.getElementById(n); 
	return x;
}

function doClick(o){
	var sObjName, sObjType, sSqlString;
	var oFormSql = getObjByID("formSQL");
	for(var i=0;i<o.form.objName.length;i++){
		if(o.form.objName[i].checked){
			sObjName = o.form.objName[i].objName;
			sObjType = o.form.objName[i].objType;
			break;
		}
	}
	switch(o.value){
	case "查看":
		if(!sObjName){alert("请选择对象"); return false;}
		sSqlString = "SELECT * FROM [" + sObjName + "]";
		oFormSql.sTblName.value = sObjName;
		oFormSql.sTblType.value = sObjType;
		oFormSql.sSqlString.value = sSqlString;
		oFormSql.sOper.value = "Select";
		oFormSql.submit();
		break;
	case "删除":
		if(!sObjName){alert("请选择对象"); return false;}
		switch(sObjType){
		case "TABLE" :
			sSqlString = "DROP TABLE [" + sObjName + "]";
			break;
		case "VIEW" :
			sSqlString = "DROP VIEW [" + sObjName + "]";
			break;
		}
		oFormSql.sSqlString.value = sSqlString;
		if(!confirm("你确认要删除 "+sObjName+' 对象吗？')) break;
		oFormSql.sTblName.value = "";
		oFormSql.sTblType.value = "";
		oFormSql.sOper.value = "";
		oFormSql.submit();
		break;
	case "新建表":
		var sObjName = prompt("请输入表名:",'');
		while(!checkInput(sObjName)){alert('名称中包含非法字符，请重新输入');sObjName = prompt("请输入表名",'');}
		if(sObjName){
			sSqlString   = "CREATE TABLE ["+sObjName+"] ( \n"
						 + "ID int IDENTITY(1,1) PRIMARY KEY CLUSTERED \n"
						 + ")"
			oFormSql.sTblName.value = sObjName;
			oFormSql.sTblType.value = "TABLE";
			oFormSql.sSqlString.value = sSqlString;
			if(!confirm("你确认要新建 "+sObjName+' 表吗？')) break;
			oFormSql.submit();
		}
		break;
	case "设计":
		if(!sObjName){alert("请选择对象"); return false;}
		sSqlString = "SELECT * FROM [" + sObjName + "]";
		oFormSql.sTblName.value = sObjName;
		oFormSql.sTblType.value = sObjType;
		//oFormSql.sSqlString.value = sSqlString;
		oFormSql.sSqlString.value = "";
		oFormSql.sOper.value = "Design";
		oFormSql.submit();
		break;
	case "显示所有对象" :
		oFormSql.sOper.value = "";
		oFormSql.sSqlString.value = "";
		oFormSql.sTblName.value = "";
		oFormSql.sTblType.value = "";
		oFormSql.submit();
		break;
	case "清空" :
		if(sObjType!="TABLE"){alert("你不能清空该对象。");break;}
		oFormSql.sOper.value = "";
		oFormSql.sSqlString.value = "DELETE * FROM ["+sObjName+"]";
		oFormSql.sTblName.value = sObjName;
		oFormSql.sTblType.value = sObjType;
		if(!confirm("你确认要清空 "+sObjName+' 表吗？')) break;
		oFormSql.submit();
		break;
	case "新建查询" :
		sTblName = prompt("请输入查询名称：","")
		while(!checkInput(sTblName)){alert('名称中包含非法字符，请重新输入');sTblName = prompt("请输入表名",'');}
		if(!sTblName) return false;
		sSqlString = "CREATE VIEW ["+sTblName+"] \nAS \n" 
		oFormSql.sSqlString.value = sSqlString;
		alert("请在SQL框里将语句填写完整。");
		oFormSql.sSqlString.focus();
	}
}

function showFieldType(o){
	var oDivType = getObjByID("divFieldType");
	var oFieldType = getObjByID("selFieldType");
	if(!o){if(oDivType) oDivType.style.display='none'; return;}
	if(!oFieldType) return;
	window.currElement = o;
	oFieldType.value = o.value;
	oDivType.style.top = event.y + document.body.scrollTop - event.offsetY -4 ;
	oDivType.style.left = event.x + document.body.scrollLeft - event.offsetX -4 ;
	oDivType.style.display="";
	oFieldType.focus();
}

function checkFieldType(s,i){
	if(window.currElement){
		window.currElement.value = s;
		if(i) window.currElement.form.fieldSize.value = "";
	}
}

function showDetial(o){
	if(!o) return;
	var iSW = parseInt(screen.AvailWidth);
	var iSH = parseInt(screen.AvailHeight);
	iW = 300;
	iH = 100;
	var newWin = open('about:blank','','width='+iW+',height='+iH+',top='+((iSH/2)-(iH/2))+',left='+((iSW/2)-(iW/2)));
	newWin.document.title = CCNS_program + " - Detial Page　　　　　　　　";
	newWin.document.body.innerHTML = o.title;
}

function doOper(o,sTblName){
	var iSW = parseInt(screen.AvailWidth);
	var iSH = parseInt(screen.AvailHeight);
	iW = 520;
	iH = 260;
	var oFormSql = getObjByID("formSQL");
	var sSqlString = "";
	switch(o.value){
	case "新增" :
	var newWin = open('about:blank','','width='+iW+',height='+iH+',top='+((iSH/2)-(iH/2))+',left='+((iSW/2)-(iW/2)));
		newWin.document.write(sNewFieldString.replace(/\[table name\]/g,sTblName));
		newWin.document.title = CCNS_program + " - New Field　　　　　　　　";
		break;
	case "删除" : 
		sSqlString = "ALTER TABLE [" + sTblName + "] \n"
			+ "    DROP COLUMN [" + o.form.fieldName.value + "]";
		oFormSql.sSqlString.value = sSqlString;
		if(!confirm("确认要删除“"+o.form.fieldName.value+"”列吗？")) return false;
		oFormSql.sOper.value = "Design";
		oFormSql.submit();
		break;
	case "修改" : 
		sSqlString = "ALTER TABLE [" + sTblName + "] \n"
			+ "    ALTER COLUMN [" + o.form.fieldName.value + "] "
			+ o.form.fieldType.value + " "
			+ (o.form.fieldSize.value.length?"("+o.form.fieldSize.value+")":"") + " "
			+ (o.form.fieldNull.checked?"NULL":"NOT NULL");
		oFormSql.sSqlString.value = sSqlString;
		if(!confirm("确认要修改“"+o.form.fieldName.value+"”列吗？")) return false;
		oFormSql.sOper.value = "Design";
		oFormSql.submit();
		break;
	case "新记录" :
		iW = 600;
		iH = 480;
		var newWin = open('about:blank','','scrollbars=yes,width='+iW+',height='+iH+',top='+((iSH/2)-(iH/2))+',left='+((iSW/2)-(iW/2)));
		newWin.document.write(sNewRecString);
		newWin.document.title = CCNS_program + " - New Record　　　　　　　　";
		break;
	case "删" :
		if(o.tblName.length<1||o.sCondition.length<1){alert("条件不正确，不能删除。");return false;}
		sSqlString = "DELETE * FROM ["+o.tblName+"] WHERE "+o.sCondition;
		oFormSql.sSqlString.value = sSqlString;
		if(!confirm("确认要删除吗？")) return false;
		oFormSql.submit();
		break;
	}
}

function changePage(o,i){
	var oFormSql = getObjByID("formSQL");
	switch(i){
	case 0 :
		oFormSql.PageNo.value = o.form.gotoPage.value;
		break;
	case 1 :
		oFormSql.PageNo.value = 1;
		break;
	case 2 :
		oFormSql.PageNo.value = parseInt(o.form.PageNo.value)-1;
		break;
	case 3 :
		oFormSql.PageNo.value = parseInt(o.form.PageNo.value)+1;
		break;
	case 4 :
		oFormSql.PageNo.value = 9999;
		break;
	}
	oFormSql.submit();
}

function doNewRec(o){
	var sSqlString = "INSERT INTO ["+o.tblName.value+"] ("
	for(var i=0;i<o.length;i++){
		if(o[i].type!="hidden"&&o[i].type!="submit"){
			sSqlString += "[" + o[i].name + "], "
		}
	}
	sSqlString = sSqlString.substr(0,sSqlString.length-2) + ") VALUES("
	for(var i=0;i<o.length;i++){
		if(o[i].type!="hidden"&&o[i].type!="submit"){
			sSqlString += "'" + o[i].value + "', ";
		}
	}
	sSqlString = sSqlString.substr(0,sSqlString.length-2) + ") "
	var oFormSQL = window.opener.getObjByID("formSQL");
	oFormSQL.sSqlString.value = sSqlString;
	if(!confirm("确认提交吗？")) return false;
	oFormSQL.submit();
}

function clearSubmitForm(o){
	var oFormSQL = getObjByID("formSQL");
	oFormSQL.sTblName.value = "";
	oFormSQL.sTblType.value = "";
	oFormSQL.sOper.value = "";
}

function doSelField(o){
	var bSelect = false;
	var oFormSQL = getObjByID("formSQL");
	var oForm = o;
	var sSqlString = "SELECT "
	for(var i=0;i<oForm.fieldName.length;i++){
		if(oForm.fieldName[i].checked){
			sSqlString += "[" + oForm.fieldName[i].value + "],";
			bSelect = true;
		}
	}
	sSqlString = sSqlString.substr(0,sSqlString.length-1);
	if(!bSelect) sSqlString += " *";
	sSqlString += (" FROM " + "[" + oForm.sTblName.value + "] ");
	if(oForm.orderField.selectedIndex>0){
		sSqlString += "ORDER BY [" + oForm.orderField[oForm.orderField.selectedIndex].value + "]";
		sSqlString += " " + oForm.orderBy[oForm.orderBy.selectedIndex].value;
	}
	oFormSQL.sSqlString.value = sSqlString;
	oFormSQL.submit();
}

function checkInput(s){
	if(s.indexOf('"')>=0||s.indexOf(' ')>=0) 
		return false; 
	return true;
}
</script>
</head>

<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">

<div id="divFieldType" style="position:absolute; left:6px; top:10px; z-index:99;display:none">
<select id="selFieldType" onChange="checkFieldType(this.value,this[this.selectedIndex].sLength)" onBlur='showFieldType(0)' style="width:130">
<OPTION value=TinyInt sLength=1>TinyInt
<OPTION value=SmallInt sLength=1>SmallInt
<OPTION value=Int sLength=1>Int
<OPTION value=BigInt sLength=1>BigInt
<OPTION value=Real sLength=1>Real / Single
<OPTION value=Float sLength=1>Float / Double
<OPTION value=Money sLength=1>Money
<OPTION value=Decimal sLength=1>Decimal
<OPTION value=Numeric sLength=1>Numeric
<OPTION value=Bit sLength=1>Bit
<OPTION value=Variant>Variant
<OPTION value=UniqueIdentifier sLength=1>UniqueIdentifier
<OPTION value=DateTime sLength=1>DateTime
<OPTION value=Char>Char
<OPTION value=VarChar>VarChar
<OPTION value=Text sLength=1>Text
<OPTION value=nChar>nChar
<OPTION value=nVarChar>nVarChar
<OPTION value=nText sLength=1>nText
<OPTION value=TimeStamp sLength=1>TimeStamp
<OPTION value=VarBinary sLength=1>VarBinary
<OPTION value=Image sLength=1>Image
<!--
<OPTION value=DBDate>DBDate
<OPTION value=DBTime>DBTime
<OPTION value=BSTR>BSTR
<OPTION value=Chapter>Chapter
<OPTION value=FileTime>FileTime
<OPTION value=PropVariant>PropVariant
<OPTION value=VarNumeric>VarNumeric
<OPTION value=Array>Array
<OPTION value=UnsignedTinyInt sLength=>UnsignedTinyInt
<OPTION value=UnsignedSmallInt sLength=>UnsignedSmallInt
<OPTION value=UnsignedInt sLength=>UnsignedInt
<OPTION value=UnsignedBigInt sLength=>UnsignedBigInt
<OPTION value=IDispatch>IDispatch
<OPTION value=IUnknown>IUnknown
<OPTION value=Error>Error
<OPTION value=UserDefined>UserDefined
<OPTION value=Empty>Empty
-->
</select>
</div>
<table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor=E9E7EB class=3d height=30>
  <form method="post" name="formLink" id="formLink">
  <tr> 
    <td>
	<div id="divLink">
	  &nbsp;连接数据库类型 
      <select name="sDbType" size="1" id="sDbType">
        <option value="ACCESS" selected>ACCESS</option>
        <option value="MSSQL">SQLServer</option>
      </select>
	  <div style="display:none">
      连接类型 
      <select name="sConnType" size="1" id="sConnType">
        <option value="ODBC">ODBC</option>
        <option value="OLEDB" selected>OLEDB</option>
      </select>
	  </div>
      位置 
      <input name="sDbPath" type="text" id="sDbPath" size="12" class=jinzhe>
	  <span title="输入SQLSERVER的库，Access不需填写">
      SQL库 
      <input name="sDbName" type="text" id="sDbName" size="10" class=jinzhe>
	  </span>
      用户名 
      <input name="sUID" type="text" id="sUID" size="8" class=jinzhe>
      密码 
      <input name="sPWD" type="password" id="sPWD" size="8" class=jinzhe> 
	  <input type="submit" name="Submit" value="连 接" class=button> 
	</div>
	<div id="divLinked" style="display:none">
	  <input type="text" name="sConnString" style="width:600" readonly="true">
	  <input type="button" name="Reset" value="重新连接" onClick="location.href='<%=Request.ServerVariables("URL")%>'" class=button>
	</div>
    </td>
  </tr>
  </form>
</table>
<script language="JavaScript">
	var oFormLink = getObjByID("formLink");
<% If Request.ServerVariables("REQUEST_METHOD")="POST" Then %>
	oFormLink.sDbType.value = "<%=String4Js(Request("sDbType"))%>";
	oFormLink.sConnType.value = "<%=String4Js(Request("sConnType"))%>";
	oFormLink.sDbPath.value = "<%=String4Js(Request("sDbPath"))%>";
	oFormLink.sDbName.value = "<%=String4Js(Request("sDbName"))%>";
	oFormLink.sUID.value = "<%=String4Js(Request("sUID"))%>";
	oFormLink.sPWD.value = "<%=String4Js(Request("sPWD"))%>";
	var oDivLink = getObjByID("divLink");
	var oDivLinked = getObjByID("divLinked");
	<% If Len(CCDbT.GetLastError)>0 Or CCDbT.isActive=true Then %>
	oDivLink.style.display = "none";
	oDivLinked.style.display = "";
	<% Else %>
	oDivLink.style.display = "";
	oDivLinked.style.display = "none";
	<% End If %>
	oFormLink.sConnString.value = "<%=String4Js(IIf(Len(CCDbT.GetLastError)<1,CCDbT.ConnString,CCDbT.GetLastError))%>";
<% End If %>
</script> 
<table width="100%" border="0" cellpadding="0" cellspacing="0" class=3d>
  <form method="post" name="formSQL" id="formSQL">
<tr>
<td   class="tdTitle" height=22>&nbsp;√&nbsp;SQL执行语句操作器</td>
</tr>
<tr><td nowrap><textarea name="sSqlString" wrap="VIRTUAL" style="width:100%;height:52px;color:red" onChange="clearSubmitForm(this.form)"></textarea> 

         
        <input name="sDbType" type="hidden" id="sDbType"> <input name="sConnType" type="hidden" id="sConnType"> 
        <input name="sDbPath" type="hidden" id="sDbPath"> <input name="sUID" type="hidden" id="sUID"> 
        <input name="sPWD" type="hidden" id="sPWD"> <input name="sTblName" type="hidden" id="sTblName">
	    <input name="sOper" type="hidden" id="sOper"> <input name="sDbName" type="hidden" id="sDbName">
		<input name="sTblType" type="hidden" id="sTblType"> <input name="PageNo" type="hidden" id="PageNo">
	 </td>
    </tr>
<tr><td style="border-top:1px solid #ffffff;border-bottom:1px solid #000000;" align=center height=25>
<input type="Submit" name="Submit" value="执行SQL语句" class="button"></td>
</table>
<table width="100%" border="0" cellpadding="0" cellspacing="1" class=3d bgcolor=#d0d4c8>
    <tr>
      <td align="center" nowrap class="tdTitle" width=45>状态</td>
      <td nowrap ><input name="sSqlState" type="text" id="sSQLState" style="width:100%" readonly="true"></td>
    </tr>
  </form>
</table>
<%
	Dim rsSql
	If Len(sSqlString)>0 Then
		Set rsSql = CCDbT.doSql(sSqlString)
	End If
	If Len(sTblName)=0 And StrComp(Left(sSqlString,6),"select",1)=0 Then
		sTblName = Trim(Mid(sSqlString,Instr(1,sSqlString," FROM ",1)+6))
		If Instr(sTblName," ")>0 Then sTblName = Mid(sTblName,Instr(sTblName," "))
	End If
	If Instr(sTblName,"[") Then
		sTblName = Left(sTblName,Len(sTblName)-1)
		sTblname = Mid(sTblName,2)
	End If

%>
<script language="JavaScript">
	var oFormSQL = getObjByID("formSQL");
	oFormSQL.sDbType.value = oFormLink.sDbType.value;
	oFormSQL.sConnType.value = oFormLink.sConnType.value;
	oFormSQL.sDbPath.value = oFormLink.sDbPath.value;
	oFormSQL.sUID.value = oFormLink.sUID.value;
	oFormSQL.sPWD.value = oFormLink.sPWD.value;
	oFormSQL.sDbName.value = oFormLink.sDbName.value;
	oFormSQL.sTblName.value = "<%=String4Js(Request("sTblName"))%>";
	oFormSQL.sTblType.value = "<%=String4Js(Request("sTblType"))%>";
	oFormSQL.sSqlString.value = "<%=String4Js(sSqlString)%>"
	oFormSQL.sSqlState.value = "<%=CCDbT.GetLastError%>"
	oFormSQL.sOper.value = "<%=sOper%>";
</script>

<%If CCDbT.isActive Then
sShowBody = "<form name=""formObjList"" id=""formObjList"" method=""post"">"
If Len(sTblName)=0 Then
aObjList = CCDbT.GetDbObject()
For i=0 To UBound(aObjList)
If (i Mod 2)=0 Then sShowBody = sShowBody & "<tr>" & vbCrLf
				sShowBody = sShowBody & "<td>" & vbCrLf
				sShowBody = sShowBody & "<input type=""radio"" name=""objName"" value="""&aObjList(i)(0)&""" objName="""&aObjList(i)(0)&""" objType="""&aObjList(i)(1)&""">" & vbCrLf
				sShowBody = sShowBody & aObjList(i)(0) & "<i style=""color:gray"">&nbsp;&nbsp;[ " & aObjList(i)(1) & " ]</i>" & vbCrLf
				sShowBody = sShowBody & "</td>" & vbCrLf
				If (i Mod 2)=1 Then sShowBody = sShowBody & "</tr>" & vbCrLf
			Next
			For i=(i Mod 2) To 1 Step -1
				sShowBody = sShowBody & "<td></td>"
			Next
			If Right(sShowBody,7)<>"</tr>"&vbCrLf Then sShowBody = sShowBody & "</tr>"&vbCrLf
		Else
			sShowBody = sShowBody & "<tr>" & vbCrLf
			sShowBody = sShowBody & "<td>"
			sShowBody = sShowBody & "<input type=""radio"" name=""objName"" value="""&sTblName&""" objName="""&sTblName&""" objType="""&sTblType&""">" & vbCrLf
			sShowBody = sShowBody & sTblName & "<i style=""color:gray"">&nbsp;&nbsp;[ " & sTblType & " ]</i>" & vbCrLf
			sShowBody = sShowBody & "</td>"
			sShowBody = sShowBody & "<td align=center><input type=""button"" class=""inputButton"" name=""btnShowObj"" onClick=""doClick(this)"" value=""显示所有对象""></td>"
			sShowBody = sShowBody & "</tr>" & vbCrLf
		End If
sShowBody = sShowBody & "<tr>" & vbCrLf & _
"<td colspan=""2"">" & vbCrLf & _
"<input type=""radio"" name=""objName"" style=""display:none"">" & vbCrLf & _
"<input type=""button"" name=""btnSelect"" value=""查看"" class=""inputButton"" onClick=""doClick(this)"">" & vbCrLf & _
"<input type=""button"" name=""btnDelete"" value=""设计"" class=""inputButton"" onClick=""doClick(this)"">" & vbCrLf & _
"<input type=""button"" name=""btnSelect"" value=""删除"" class=""inputButton"" onClick=""doClick(this)"">" & vbCrLf & _
"<input type=""button"" name=""btnSelect"" value=""清空"" class=""inputButton"" onClick=""doClick(this)"">" & vbCrLf & _
"<input type=""button"" name=""btnSelect"" value=""新建表"" class=""inputButton"" onClick=""doClick(this)"">" & vbCrLf & _
"<input type=""button"" name=""btnSelect"" value=""新建查询"" class=""inputButton"" onClick=""doClick(this)"">" & vbCrLf & _
"</td>" & vbCrLf & _
"</tr>"
sShowBody = sShowBody & "</form>" & vbCrLf
Response.Write(Replace(Replace(sMainTblString,"[title]","对象列表"),"[body]",sShowBody))
Response.Write("<script language=""JavaScript"">" & vbCrLf & _
						"var oFormObjList = getObjByID(""formObjList"");" & vbCrLf & _
						"for(var i=0;i<oFormObjList.objName.length;i++)" & vbCrLf & _
						"	if(oFormObjList.objName[i].value=="""&sTblName&""")" & vbCrLf & _
						"		oFormObjList.objName[i].checked=true;" & vbCrLf & _
						"</script>" & vbCrLf)
	End If
%>
<%
	Dim rsList, sCondition, rsFields
	If StrComp(Left(sSqlString,6),"select",1)=0 Then
		sShowBody = ""
		sPrimaryKey = CCDbT.GetPrimaryKey(sTblName)
		Set rsList = CCDbT.doSelect(IIf(Len(sSqlString)=0,"SELECT * FROM ["&sTblName&"]",sSqlString),iPageSize,iPageNo)
		Dim sOrder, sOrderBy
		sOrderBy = "ASC"
		If Instr(1,sSqlString," ORDER BY ",1) Then	
			sOrder = Trim(Mid(sSqlString,Instr(1,sSqlString," ORDER BY ",1)+10))
			If InStr(sOrder," ") Then 
				sOrderBy = UCase(Trim(Mid(sOrder,InStr(sOrder," "))))
				sOrder = Replace(Replace(UCase(Trim(Left(sOrder,InStr(sOrder," ")))),"[",""),"]","")
			End If
			sSqlString = Left(sSqlString,InStr(1,sSqlString," ORDER BY ",1))
		End If
		
		If Not isEmpty(rsList) Then
			Response.Write("<script language=Javascript>" & vbCrLf & _
				"var sNewRecString = """"" & vbCrLf)
			For x=0 To rsList.Fields.Count-1
				If rsList.Fields(x).name<>sPrimaryKey Then
					Response.Write("+""<tr>\n""" & vbCrLf & _
						"+""<td width=\""30%\"" nowrap>"&rsList(x).Name&"&nbsp;&nbsp;<font color=#999999>[ "&GetFieldType(rsList(x).Type)&" ]</font>"&"</td>\n""" & vbCrLf & _
						"+""<td>"&IIf(rsList(x).DefinedSize>100,"<textarea name=\"""&rsList(x).Name&"\""></textarea>","<input name=\"""&rsList(x).Name&"\"" size="&rsList(x).DefinedSize&" type=text>")&"</td>\n""" & vbCrLf & _
						"+""</tr>\n""" & vbCrLf)
				End If
			Next
			Response.Write("sNewRecString = ""<table border=1><form name=formNewRec id=formNewRec method=post onsubmit=\""doNewRec(this);return false;\"">\n"" + sNewRecString;" & vbCrLf & _
				"sNewRecString += ""<tr><td colspan=2 align=right><input type=submit name=submit value=提交></td></tr>\n""" & vbCrLf & _
				"sNewRecString += ""<input type=hidden name=tblName value=\"""&sTblName&"\""></form></table>\n""" & vbCrLf & _
				"sNewRecString += ""<s""+""cript>""+doNewRec.toString()+""</scrip""+""t>""" & vbCrLf & _
				"</script>" & vbCrLf)
			'//选择字段
			Set rsFields = CCDbT.Conn.Execute("SELECT * FROM ["&sTblName&"]")
			sShowBody = sShowBody & "<form name=""formSelField"" id=""formSelField"" method=post onsubmit=""doSelField(this);return false;"">" & vbCrLf & _
				"<tr>" & vbCrLf & _
				"<input type=""hidden"" name=sTblName value="""&sTblName&""" >" & vbCrLf & _
				"<td style=""word-break:break-all"" colspan="""&(rsList.Fields.Count+1)&""">" & vbCrLf
			For x=0 To rsFields.Fields.Count-1
				sShowBody = sShowBody & "<span style=""width:120;height:16px;word-break:keep-all"">"& vbCrLf & _
					"<input type=""checkbox"" value="""&rsFields(x).Name&""" name=""fieldName"" "&IIf(Instr(1,sSqlString,"["&rsFields(x).Name&"]",1)>0,"checked","")&">"&rsFields(x).Name&"&nbsp;" & vbCrLf & _
					"</span> " & vbCrLf
			Next
			sShowBody = sShowBody & "<select name=""orderField"">" & vbCrLf 
			sShowBody = sShowBody & "<option value="""">选择排序字段" & vbCrLf
			For x=0 To rsFields.Fields.Count-1
				sShowBody = sShowBody & "<OPTION value=""" & UCase(rsFields(x).Name)&""">" & rsFields(x).Name & vbCrLf
			Next
			sShowBody = sShowBody & "</select>" & vbCrLf & _
				"<select name=""orderBy""><option value=""ASC"">升序<option value=""DESC"">绛序" & vbCrLf & _
				"<input type=submit name=submit value=""提交""> </td></tr></form>" & vbCrLf & _
				"<script language=""JavaScript"">" & vbCrLf & _
				"	var oForm = getObjByID(""formSelField"");" & vbCrLf
			If Len(sOrder)>0 Then sShowBody = sShowBody & "	oForm.orderField.value="""&sOrder&"""" & vbCrLf
			sShowBody = sShowBody & "	oForm.orderBy.value="""&sOrderBy&"""" & vbCrLf
			sShowBody = sShowBody & "</script>"
			'//列出字段
			sShowBody = sShowBody & "<tr>" & vbCrLf & _
				"<td></td>" & vbCrLf
			For x=0 To rsList.Fields.Count-1
				sShowBody = sShowBody & "<td>"&rsList(x).Name&"</td>" & vbCrLf
			Next
			sShowBody = sShowBody & "</tr>" & vbCrLf 
			For i=1 To iPageSize
				If rsList.Eof Then Exit For
				sCondition = ""
				If Len(sPrimaryKey)>0 Then sCondition = "["&sPrimaryKey&"]=\"""&rsFields(sPrimaryKey).value&"\"""
				sShowBody = sShowBody & "<tr>" & vbCrLf & _
					"<td><input type=button name=btn1 value=删 onClick=""doOper(this)"" tblName="""&sTblName&""" sCondition="""&sCondition&"""></td>" & vbCrLf
				For x=0 To rsList.Fields.Count-1
					sShowBody = sShowBody & "<td>"&Left(rsList(x).value&"",200)&"</td>" & vbCrLf
				Next
				sShowBody = sShowBody & "</tr>" & vbCrLf 
				rsList.MoveNext()
			Next
			sShowBody = sShowBody & "<tr>" & vbCrLf
			sShowBody = sShowBody & "<form name=""Pager"" id=""Pager"" method=""post"" onSubmit=""return false;"">" & vbCrLf
			sShowBody = sShowBody & "<td colspan="""&(rsList.Fields.Count+1)&""" nowrap align=right>" & vbCrLf
			sShowBody = sShowBody & "&nbsp;第 "&CCDbT.PageNo&" 页 / 共 "&CCDbT.PageCount&" 页;"
			sShowBody = sShowBody & "&nbsp;共 "&(CCDbT.RecCount)&" 条记录。"
			sShowBody = sShowBody & "&nbsp;<input type=""hidden"" value="""&(CCDbT.PageNo)&""" name=""PageNo"">"
			sShowBody = sShowBody & "&nbsp;跳转到 <input type=""text"" name=""gotoPage"" value="""&CCDbT.PageNo&""" style=""width:30px;text-align:center"">"
			sShowBody = sShowBody & "&nbsp;<input name=""go"" value=""Go"" type=""button"" onClick=""changePage(this,0)"">"
			sShowBody = sShowBody & "&nbsp;<input type=""button"" value=""|&lt; "" name=""btnPage"" onClick=""changePage(this,1)"" onload=""if(parseInt(this.form.PageNo.value)==1) this.disabled=true;"">"
			sShowBody = sShowBody & "&nbsp;<input type=""button"" value="" &lt; "" name=""btnPage"" onClick=""changePage(this,2)"">"
			sShowBody = sShowBody & "&nbsp;<input type=""button"" value="" &gt; "" name=""btnPage"" onClick=""changePage(this,3)"">"
			sShowBody = sShowBody & "&nbsp;<input type=""button"" value="" &gt;|"" name=""btnPage"" onClick=""changePage(this,4)"">"
			sShowBody = sShowBody & "&nbsp;&nbsp;&nbsp;"
			sShowBody = sShowBody & "&nbsp;<input type=""button"" value=""新记录"" name=""btnPage"" onClick=""doOper(this)"">"
			sShowBody = sShowBody & "</td>" & vbCrLf
			sShowBody = sShowBody & "</form>" & vbCrLf
			sShowBody = sShowBody & "</tr>" & vbCrLf 
			Response.Write(""&Replace(Replace(sMainTblString,"[title]","查看对象 [ "&sTblType&": "&sTblName&" ]"),"[body]",sShowBody))
			Response.Write("<script language=javascript>" & vbCrLf & _
				"var oPager = getObjByID(""Pager"");" & vbCrLf & _
				"if(parseInt(oPager.PageNo.value)<=1){" & vbCrLf & _
				"oPager.btnPage[0].disabled=true;" & vbCrLf & _
				"oPager.btnPage[1].disabled=true;" & vbCrLf & _
				"}" & vbCrLf & _
				"if(parseInt(oPager.PageNo.value)>=parseInt("""&CCDbT.PageCount&""")){" & vbCrLf & _
				"oPager.btnPage[2].disabled=true;" & vbCrLf & _
				"oPager.btnPage[3].disabled=true;" & vbCrLf & _
				"}" & vbCrLf & _
				"</script>")
		End If
	End If
	Set rsFields = Nothing
%>
<%
	Dim sPrimaryKey, rsField, x
	Dim sFldName, bFldIsNull, sFldType, sFldDefault, sFldDescription, sFldAttrib, iFldSize, bFldIsAuto
	If sOper="Design" Then
		sSqlString = "SELECT * FROM [" & sTblName & "]"
		Set rsSql = Server.CreateObject("ADODB.Recordset")
		rsSql.Open sSqlString, CCDbT.Conn, 1, 3
		sPrimaryKey = CCDbT.GetPrimaryKey(sTblName)
		sShowBody = "<form name=""formDesign"" id=""formDesign"" method=""post"">" & vbCrLf
		sShowBody = sShowBody & "<tr>" & vbCrLf & _
						"<td>字段名</td>" & vbCrLf & _
						"<td align=""center"">类型</td>"  & vbCrLf & _
						"<td align=""center"">宽度</td>"  & vbCrLf & _
						"<td align=""center"">空值</td>"  & vbCrLf & _
						"<td align=""center"">主键</td>"  & vbCrLf & _
						"<td align=""center"">自增</td>"  & vbCrLf & _
						"<td align=""center"">默认值</td>"  & vbCrLf & _
						"<td align=""center"">描述</td>"  & vbCrLf & _
						"<td align=""center"">操作</td>"  & vbCrLf & _
						"</tr>" & vbCrLf

		For i=0 To rsSql.Fields.Count-1
			sFldName = rsSql(i).Name
			sFldType = rsSql(i).Type
			iFldSize = rsSql(i).DefinedSize
			sFldAttrib = rsSql(i).Attributes
			bFldIsAuto = rsSql(i).Properties("ISAUTOINCREMENT")
			Set rsField = CCDbT.GetColumnInfo(sTblName,rsSql(i).Name)
			If Not rsField.Eof Then
				bFldIsNull = rsField("IS_NULLABLE")
				sFldDefault = String4Js(rsField("COLUMN_DEFAULT"))
				sFldDescription = String4Js(rsField("DESCRIPTION"))
			Else
				bFldIsNull = False
				sFldDefault = ""
				sFldDescription = ""
			End If
			
'			For x=0 To rsField.Fields.Count-1
'				If Len(rsField(x).Value)>0 Then
'					Response.Write(rsField(x).Name)
'					Response.Write(" = ")
'					Response.Write(rsField(x).Value)
'					Response.Write("<br>")
'				End If
'			Next
'			Response.Write("<br>")
			Set rsField = Nothing

			sShowBody = sShowBody & "<form name=""formStru"" id=""formStru"" method=""post"">" & vbCrLf & _
						"<tr>" & vbCrLf & _
						"<td width=""180"">" & vbCrLf & _
						"<input type=""text"" readonly=""true"" name=""fieldName"" class=""inputText0Border"" value="""&rsSql(i).Name&""">" & vbCrLf & _
						"</td>" & vbCrLf & _
						"<td width=""130"">" & vbCrLf & _
						"<input type=""text"" name=""fieldType"" class=""inputText"" onFocus=""showFieldType(this)"" value="""&GetFieldType(sFldType)&""" readonly=""true"">" & vbCrLf & _
						"</td>" & vbCrLf & _
						"<td width=""40"">" & vbCrLf & _
						"<input type=""text"" name=""fieldSize"" class=""inputText"" value="""&iFldSize&""">" & vbCrLf & _
						"</td>" & vbCrLf & _
						"<td align=""center"" width=""30"">" & vbCrLf & _
						"<input type=""checkbox"" name=""fieldNull"" class=""inputText"" "&IIf((bFldIsNull)<>0,"checked","")&">" & vbCrLf & _
						"</td>" & vbCrLf & _
						"<td align=""center"" width=""30"">" & vbCrLf & _
						IIf(rsSql(i).Name=sPrimaryKey,"√","") & vbCrLf & _
						"</td>" & vbCrLf & _
						"<td align=""center"" width=""30"">" & vbCrLf & _
						IIf(bFldIsAuto,"√","") & vbCrLf & _
						"</td>" & vbCrLf & _
						"<td align=""center"">" & vbCrLf & _
						"<input type=""text"" style=""text-align:center;"" name=""fieldDefault"" readonly=""true"" class=""inputText0Border"" value="""&Replace(sFldDefault,"\""","""")&""">" & vbCrLf & _
						"</td>" & vbCrLf & _
						"<td align=""center"" width=""30"">" & vbCrLf & _
						"<input type=""button"" value=""@"" title="""&sFldDescription&""" onClick=""showDetial(this)"" FldName="""&sFldName&""" "&IIf(Len(sFldDescription)<1,"Disabled","")&">" & vbCrLf & _
						"</td>" & vbCrLf & _
						"<td align=""center"" width=""130"">" & vbCrLf & _
"<input type=""button"" class=button name=""ModiField"" value=""修改"" onClick=""doOper(this,'"&sTblName&"')"">" & vbCrLf & _
"<input type=""button""  class=button name=""deleteField"" value=""删除"" onClick=""doOper(this,'"&sTblName&"')"">" & vbCrLf & _
"<input type=""button"" class=button name=""NewField"" value=""新增"" onClick=""doOper(this,'"&sTblName&"')"">" & vbCrLf & _
"</td>" & vbCrLf & vbCrLf & _
"</tr>" & vbCrLf & vbCrLf & _
"</form>"
		Next
		sShowBody = sShowBody & "</form>"
		Response.Write("<br>"&Replace(Replace(sMainTblString,"[title]","设计对象"),"[body]",sShowBody))
	End If
%>

<script language="JavaScript">
var CCNS_program = "COCOONDBTOOLS";
var CCNS_version = "Final Release Build 1121";
</script>
</body>
</html>
<%Set CCDbT = Nothing%>
