Use ASP, VB and XML to build Internet Applications (4)

Source: Internet
Author: User
Tags ntfs permissions
xml| Program | The internet we've already introduced mixed programming with ASP and XML, because ASP pages make it easy for us to see what the application is doing, but if you don't want to use ASP, you can use any technology you know to create a client program. Below, I provide a section of VB code, its function and ASP page, can also display the same data, but this VB program will not create the XML string sent to the server. It queries the contents of the Clientcommands table by running a stored procedure called Initialize and retrieving the XML string from the server.

The Clientcommands table includes two domains: Command_name domain and Command_xml domain. The client program requires three specific command_name domains: Getcustomerlist,custorderhist and Recentpurchasebycustomerid. The command_ of every command An XML field includes an XML string that a program sends to a getdata.asp page, so that you can centralize control over an XML string, just as the stored procedure name means, before sending an XML string to GetData.asp, the client program uses the XML Dom to set the parameter values of the stored procedure. The code that I provide contains the SQL statements that define the initialize process and the Clientcommands table to create.

The routines I provide also explain how to use the Xhttprequest object to implement the commitments I made at the outset of this article: GetData.asp can be accessed by applications on any remote machine; Of course, you can also restrict access to ASP pages by setting IIS and NTFS permissions, and you can store global application settings on the server rather than on the client computer, and you can avoid the pitfalls of sending database username and password over the network. Also, in IE, an application can display only the data that is needed without refreshing the entire page.

In the actual programming process, you should use a number of methods to make your application more efficient. You can move the code in the ASP to a COM application and then create an XSLT transformation to display the returned data. Well, I don't say much, now all you have to do is try it!

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 ()
' Returns the command name and corresponding value from the database

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 as 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 no 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
' Show Text field
Txtresult.text = ""
Me.txtResult.Visible = True
Dgresult.visible = False
' Show product name
Txtresult.text = "The most recent product is:" & 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)
' Find the ID number associated with the list
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)
' Hide text because it's a recordset
Txtresult.visible = False

Dgresult.visible = True
Set Dgresult.datasource = R
End Sub

Function GetRecordSet (SXML as String) as Recordset
Dim R as Recordset



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.