麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 開發(fā) > XML > 正文

實(shí)戰(zhàn)ASP(8):使用ASP、VB和XML建立運(yùn)行于互聯(lián)網(wǎng)上的應(yīng)用程序(下)

2024-09-05 20:55:41
字體:
供稿:網(wǎng)友
使用asp、vb和xml建立運(yùn)行于互聯(lián)網(wǎng)上的應(yīng)用程序(2)
      在實(shí)際的編程過程中,你們應(yīng)當(dāng)使用一些方法使應(yīng)用程序更加有高效性。你可以把a(bǔ)sp中的關(guān)于取得數(shù)據(jù)的代碼端搬到一個(gè)com應(yīng)用程序中去然后創(chuàng)建一個(gè)xslt變換來顯示返回的數(shù)據(jù)。好,我不多說了,現(xiàn)在你所要做的就是試一試吧!

   option explicit
   private rcommands as recordset
   private rcustomers as recordset
   private rcust as recordset
   private scustlistcommand as string
   private const dataurl = "http://localhost/xhttprequest/getdata.asp"
   private arrcustomerids() as string
   private enum actionenum
   view_history = 0
   view_recent_product = 1
  end enum

  private sub dgcustomers_click()
   dim customerid as string
   customerid = rcustomers("customerid").value
   if customerid <> "" then
    if optaction(view_history).value then
     call getcustomerdetail(customerid)
    else
     call getrecentproduct(customerid)
    end if
   end if
  end sub

  private sub form_load()
   call initialize
   call getcustomerlist
  end sub

  sub initialize()
   ' 從數(shù)據(jù)庫返回命令名和相應(yīng)的值

   dim sxml as string
   dim vret as variant
   dim f as field
   sxml = "<?xml version=""1.0""?>"
   sxml = sxml & "<command><commandtext>initialize</commandtext>"
   sxml = sxml & "<returnsdata>true</returnsdata>"
   sxml = sxml & "</command>"
   set rcommands = getrecordset(sxml)
   do while not rcommands.eof
    for each f in rcommands.fields
     debug.print f.name & "=" & f.value
    next
    rcommands.movenext
   loop
  end sub

  function getcommandxml(command_name as string) as string
   rcommands.movefirst
   rcommands.find "command_name='" & command_name & "'", , adsearchforward, 1
   if rcommands.eof then
    msgbox "cannot find any command associated with the name '" & command_name & "'."
    exit function
   else
    getcommandxml = rcommands("command_xml")
   end if
  end function

  sub getrecentproduct(customerid as string)
   dim sxml as string
   dim xml as domdocument
   dim n as ixmldomnode
   dim productname as string
   sxml = getcommandxml("recentpurchasebycustomerid")
   set xml = new domdocument
   xml.loadxml sxml
   set n = xml.selectsinglenode("command/param[name='customerid']/value")
   n.text = customerid
   set xml = executespwithreturn(xml.xml)
   productname = xml.selectsinglenode("values/productname").text
   ' 顯示text域
   txtresult.text = ""
   me.txtresult.visible = true
   dgresult.visible = false
   ' 顯示product名
   txtresult.text = "最近的產(chǎn)品是: " & productname
  end sub

  sub getcustomerlist()
   dim sxml as string
   dim i as integer
   dim s as string
   sxml = getcommandxml("getcustomerlist")
   set rcustomers = getrecordset(sxml)
   set dgcustomers.datasource = rcustomers
  end sub

  sub getcustomerdetail(customerid as string)
   ' 找出列表中相關(guān)聯(lián)的id號(hào)
   dim sxml as string
   dim r as recordset
   dim f as field
   dim s as string
   dim n as ixmldomnode
   dim xml as domdocument
   sxml = getcommandxml("custorderhist")
   set xml = new domdocument
   xml.loadxml sxml
   set n = xml.selectsinglenode("command/param[name='customerid']/value")
   n.text = customerid
   set r = getrecordset(xml.xml)
   ' 隱藏 text , 因?yàn)樗且粋€(gè)記錄集
   txtresult.visible = false

   dgresult.visible = true
   set dgresult.datasource = r
  end sub

  function getrecordset(sxml as string) as recordset
   dim r as recordset
   dim xml as domdocument
   set xml = getdata(sxml)
    debug.print typename(xml)
   on error resume next
   set r = new recordset
   r.open xml
   if err.number <> 0 then
    msgbox err.description
    exit function
   else
    set getrecordset = r
   end if
  end function

  function executespwithreturn(sxml as string) as domdocument
   dim d as new dictionary
   dim xml as domdocument
   dim nodes as ixmldomnodelist
   dim n as ixmldomnode
   set xml = getdata(sxml)
   if xml.documentelement.nodename = "values" then
    set executespwithreturn = xml
   else
    '發(fā)生錯(cuò)誤
 
    set n = xml.selectsinglenode("response/data")
    if not n is nothing then
     msgbox n.text
     exit function
    else
     msgbox xml.xml
     exit function
    end if
   end if
  end function

  function getdata(sxml as string) as domdocument
   dim xhttp as new xmlhttp30
   xhttp.open "post", dataurl, false
   xhttp.send sxml
   debug.print xhttp.responsetext
   set getdata = xhttp.responsexml
  end function

  private sub optaction_click(index as integer)
   call dgcustomers_click
  end sub


  代碼二、getdata.asp

   <%@ language=vbscript %>
   <% option explicit %>
   <%
    sub responseerror(sdescription)
    response.write "<res

|||中國最大的web開發(fā)資源網(wǎng)站及技術(shù)社區(qū),
ponse><data>error: " & sdescription & "</data></response>"
    response.end
   end sub

   response.contenttype="text/xml"
   dim xml
   dim commandtext
   dim returnsdata
   dim returnsvalues
   dim recordsaffected
   dim param
   dim paramname
   dim paramtype
   dim paramdirection
   dim paramsize
   dim paramvalue
   dim n
   dim nodename
   dim nodes
   dim conn
   dim sxml
   dim r
   dim cm

    ' 創(chuàng)建domdocument對(duì)象
   set xml = server.createobject("msxml2.domdocument")
   xml.async = false

   ' 裝載post數(shù)據(jù)
   xml.load request
   if xml.parseerror.errorcode <> 0 then
    call responseerror("不能裝載 xml信息。 描述: " & xml.parseerror.reason & "<br>行數(shù): " & xml.parseerror.line)
   end if

   ' 客戶端必須發(fā)送一個(gè)commandtext元素
   set n = xml.selectsinglenode("command/commandtext")
   if n is nothing then
    call responseerror("missing <commandtext> parameter.")
   else
    commandtext = n.text
   end if

   ' 客戶端必須發(fā)送一個(gè)returnsdata或者returnsvalue元素
   set n = xml.selectsinglenode("command/returnsdata")
   if n is nothing then
    set n = xml.selectsinglenode("command/returnsvalues")
    if n is nothing then
     call responseerror("missing <returnsdata> or <returnsvalues> parameter.")
    else
     returnsvalues = (lcase(n.text)="true")
    end if
   else
    returnsdata=(lcase(n.text)="true")
   end if

   set cm = server.createobject("adodb.command")
   cm.commandtext = commandtext
   if instr(1, commandtext, " ", vbbinarycompare) > 0 then
    cm.commandtype=adcmdtext
   else
    cm.commandtype = adcmdstoredproc
   end if

   ' 創(chuàng)建參數(shù)
   set nodes = xml.selectnodes("command/param")
   if nodes is nothing then' 如果沒有參數(shù)
   elseif nodes.length = 0 then
     ' 如果沒有參數(shù)
   else
     for each param in nodes
      ' response.write server.htmlencode(param.xml) & "<br>"
      on error resume next
      paramname = param.selectsinglenode("name").text
      if err.number <> 0 then
       call responseerror("創(chuàng)建參數(shù): 不能發(fā)現(xiàn)名稱標(biāo)簽。")
      end if
      paramtype = param.selectsinglenode("type").text
      paramdirection = param.selectsinglenode("direction").text
      paramsize = param.selectsinglenode("size").text
      paramvalue = param.selectsinglenode("value").text
      if err.number <> 0 then
        call responseerror("參數(shù)名為 '" & paramname & "'的參數(shù)缺少必要的域")
      end if
      cm.parameters.append                    cm.createparameter(paramname,paramtype,paramdirection,paramsize,paramvalue)
      if err.number <> 0 then
       call responseerror("不能創(chuàng)建或添加名為 '" & paramname & "的參數(shù).' " & err.description)
        response.end
      end if
     next
     on error goto 0
    end if

   '打開連結(jié)
   set conn = server.createobject("adodb.connection")
   conn.mode=admodereadwrite
   conn.open application("connectionstring")
   if err.number <> 0 then
    call responseerror("連結(jié)出錯(cuò): " & err.description)
    response.end
   end if

  ' 連結(jié)command對(duì)象
  set cm.activeconnection = conn

  ' 執(zhí)行命令
  if returnsdata then
   ' 用命令打開一個(gè)recordset
    set r = server.createobject("adodb.recordset")
    r.cursorlocation = aduseclient
    r.open cm,,adopenstatic,adlockreadonly
  else
    cm.execute recordsaffected, ,adexecutenorecords
  end if
   if err.number <> 0 then
    call responseerror("執(zhí)行命令錯(cuò)誤 '" & commandtext & "': " & err.description)
    response.end
   end if

   if returnsdata then
    r.save response, adpersistxml
    if err.number <> 0 then
     call responseerror("數(shù)據(jù)集發(fā)生存儲(chǔ)錯(cuò)誤,在命令'" & commandtext & "': " & err.description)
     response.end
    end if
   elseif returnsvalues then
    sxml = "<?xml version=""1.0"" encoding=""gb2312""?>" & vbcrlf & "<values>"
    set nodes = xml.selectnodes("command/param[direction='2']")
    for each n in nodes
     nodename = n.selectsinglenode("name").text
     sxml = sxml & "<" & nodename & ">" & cm.parameters(nodename).value & "" & "</" & nodename & ">"
     next
     sxml = sxml & "</values>"
     response.write sxml
   end if

   set cm = nothing
   conn.close
   set r = nothing
   set conn = nothing
   response.end
  %>

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 欧美人与性禽动交精品 | 国产亚洲美女精品久久久2020 | 日本aaaa片毛片免费观蜜桃 | 成人毛片在线 | 欧美精品久久久久久久久久 | 羞羞视频免费观看网站 | 在线无码 | 国产精品一区二区三区在线 | 九一国产精品 | 久久羞羞| 欧美一级做| 一级毛片真人免费播放视频 | 久在线观看福利视频69 | 成人午夜视频在线观看 | 精品国产一区二区久久 | 国产女同玩人妖 | 凹凸成人精品亚洲精品密奴 | 成年人黄色免费网站 | 久久国产精品二国产精品 | 国产精品成人免费一区久久羞羞 | www久| 日本在线观看中文字幕 | 91短视频免费 | 欧美成人免费在线视频 | 欧美一区在线观看视频 | 国产一级片91 | 欧美黄色一级生活片 | 91短视频网页版 | 一区二区三区视频在线观看 | 日本最新免费二区三区 | 日韩大片在线永久观看视频网站免费 | 久久久成人免费视频 | 国产美女白浆 | 成人免费看视频 | 久久久久久免费 | www日韩大片 | 国产视频在线播放 | 人禽l交免费视频观看 视频 | 欧美xxxx精品另类 | 精品无吗乱吗av国产爱色 | 国产乱乱视频 |