| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 415 人关注过本帖
标题:有没有人为为我解释一下!!
只看楼主 加入收藏
yezhihuijie
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2006-12-14
收藏
 问题点数:0 回复次数:4 
有没有人为为我解释一下!!

<%@LANGUAGE="VBSCRIPT" CodePage=65001%>
<% option explicit %>
<!--#include file="adovbs.inc" -->
<!--#include file="connection.inc" -->
<%

'*********************************************
' Code by Philippe Nomail, http://philflash.inway.fr/
'*********************************************

Dim saveUpdatePacket, aspdebug
' For debug
saveUpdatePacket = False
' saveUpdatePacket = True

aspdebug = request.querystring("debug")

' ----- DB Connection -----
' use DB_connection declared in connection.inc
Dim objConn
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.Open DB_connection

' ----- Define Result Doc: UpdatePacket -----
Dim resultdoc
Set resultdoc = Server.CreateObject("Microsoft.XMLDOM")
resultdoc.async = False
resultdoc.loadXML( "<?xml version=""1.0"" encoding=""UTF-8"" ?><update_packet></update_packet>")


' ----- Read XML -----
Dim xmldoc
Set xmldoc = Server.CreateObject("Microsoft.XMLDOM")
xmldoc.async = False

If aspdebug = "1" Then
xmldoc.load(Server.MapPath("updatePacket.xml"))
Else
If Request.TotalBytes = 0 Then
xmldoc.loadXML( "<?xml version=""1.0"" encoding=""UTF-8"" ?><update_packet tableName=""TEST"" nullValue=""_NULL_"" transID=""""></update_packet>")
Else
xmldoc.load Request
End If
If saveUpdatePacket Then
xmldoc.save(Server.MapPath("updatePacket.xml"))
End If
End If

' ----- Parse UpdatePacket -----
Dim rootNode, table, nullValue, transID
Set rootNode = xmldoc.documentElement
table = rootNode.getAttribute("tableName")
nullValue = rootNode.getAttribute("nullValue")
transID = rootNode.getAttribute("transID")

' ----- Prepare resultDoc -----
Dim resultRootNode
Set resultRootNode = xmldoc.createElement("update_packet")
Set resultdoc.documentElement = resultRootNode
resultRootNode.setAttribute "transID", transID

' ----- process "update" nodes -----
Dim nodes, node, fields, field
Dim kname, ktype, kvalue, stmt
Dim fname, ftype, fvalue
Dim objRS, strSQL, newId
Dim operationId
Set nodes = rootNode.getElementsByTagName("update")
For Each node In nodes
operationId = node.getAttribute("id")
Set fields = node.getElementsByTagName("field")
' -- find key --
For Each field in fields
If field.getAttribute("key") = "true" Then
kname = field.getAttribute("name")
ktype = field.getAttribute("type")
kvalue = field.getAttribute("oldValue")
stmt = kvalue
If ktype = "Integer" Or ktype = "Number" Then
stmt = kname & "=" & kvalue
Else
kvalue = Replace(kvalue, "'", "''")
stmt = kname & "= """ & kvalue & """"
End If
Exit For
End If
Next

strSQL = "SELECT * FROM " & table & " WHERE " & stmt
Set objRS = Server.CreateObject("ADODB.RecordSet")
objRS.Open strSQL, objConn, adOpenKeySet, adLockPessimistic
If objRS.EOF Then
' Cas record supprim?
Else
' -- update record --
For Each field in fields
If field.getAttribute("key") = "false" Then
fname = field.getAttribute("name")
ftype = field.getAttribute("type")
fvalue = field.getAttribute("newValue")

' -- check NullValue --
If fvalue = nullValue Then
fvalue = Null
End If

objRS.Fields(fname) = fvalue
End If
Next
objRS.Update
End If
objRS.Close
Set objRS = Nothing
Next

' ----- process "delete" nodes -----
Set nodes = rootNode.getElementsByTagName("delete")
For Each node In nodes
operationId = node.getAttribute("id")
Set fields = node.getElementsByTagName("field")
' -- find key --
For Each field in fields
If field.getAttribute("key") = "true" Then
kname = field.getAttribute("name")
ktype = field.getAttribute("type")
kvalue = field.getAttribute("oldValue")
stmt = kvalue
If ktype = "Integer" Or ktype = "Number" Then
stmt = kname & "=" & kvalue
Else
kvalue = Replace(kvalue, "'", "''")
stmt = kname & "= '" & kvalue & "'"
End If
Exit For
End If
Next

strSQL = "DELETE FROM " & table & " WHERE " & stmt
objConn.Execute(strSQL)
Next

' ----- process "insert" nodes -----
Set nodes = rootNode.getElementsByTagName("insert")
For Each node In nodes
operationId = node.getAttribute("id")
Set fields = node.getElementsByTagName("field")
' -- find key --
For Each field in fields
If field.getAttribute("key") = "true" Then
kname = field.getAttribute("name")
ktype = field.getAttribute("type")
Exit For
End If
Next

Set objRS = Server.CreateObject("ADODB.RecordSet")
objRS.Open table, objConn, adOpenKeySet, adLockPessimistic, adCmdTable

objRS.AddNew
' -- insert record --
For Each field in fields
If field.getAttribute("key") = "false" Then
fname = field.getAttribute("name")
ftype = field.getAttribute("type")
fvalue = field.getAttribute("newValue")

' -- check NullValue --
If fvalue = nullValue Then
fvalue = Null
End If

objRS.Fields(fname) = fvalue
End If
Next
objRS.Update

newId = objRS.Fields(kname)

' -- append result doc for newId --
Dim roperationNode, rfieldNode
Set roperationNode = resultdoc.createElement("operation")
roperationNode.setAttribute "op", "update"
roperationNode.setAttribute "id", operationId

Set rfieldNode = resultdoc.createElement("field")
rfieldNode.setAttribute "name", kname
rfieldNode.setAttribute "curValue", newId

roperationNode.appendChild(rfieldNode)
resultRootNode.appendChild(roperationNode)

objRS.Close
Set objRS = Nothing
Next


' Send XML to Response
resultdoc.save(Response)

objConn.Close
Set objConn = Nothing

Set xmldoc=Nothing
Set resultdoc=Nothing

%>

搜索更多相关主题的帖子: 解释 
2006-12-14 01:07
gdk2006
Rank: 4
等 级:业余侠客
威 望:8
帖 子:928
专家分:270
注 册:2006-7-2
收藏
得分:0 
这是什么跟什么啊!

程序员的悲哀如何找女朋友?
追女解决方案百度“让她着迷”!
2006-12-14 08:42
探拓者
Rank: 1
等 级:新手上路
帖 子:62
专家分:0
注 册:2005-10-13
收藏
得分:0 
这也太乱了吧!!!

2006-12-14 09:16
lq7350684
Rank: 6Rank: 6
等 级:贵宾
威 望:20
帖 子:5089
专家分:98
注 册:2006-11-6
收藏
得分:0 
晕!自己看去吧,懒的看.
2006-12-14 17:20
xujinhuang
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2006-12-10
收藏
得分:0 
就是的啊,什么东西啊!叫别人帮你你就要先让别人看得懂
这么乱谁看了都晕
2006-12-14 17:33
快速回复:有没有人为为我解释一下!!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017970 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved