Making Web pages with VFP (II.)

Source: Internet
Author: User
Tags iis ticket

Example Tutorial

Overview

This is a computer intermediate test results Query system, can be named or the ticket number of the exam results, query interface is such:

If there is a result returned, the result returned will appear as follows:

If no records are found, this page will be displayed:

Code Analysis

Index.htm

This is the query interface on the client browser that is responsible for sending requests to the WEB server. The key code is:

<form name=search onsubmit= "return Validate_form ()" Action=search.asp method=post>

Represents an ASP page with the POST method calling the name Search.asp. When a request is submitted here, it passes the values of the client control cxxx and CXNR to the WEB server. Where cxxx represents the query keyword: is according to the name of the query or according to the admission ticket query, CXNR said the query content, is the specific name or ticket number.

Search.asp

Then is search.asp, just now the client indicates that the WEB server uses search.asp to correspond to the client's request. All code, as follows:

<%
Set Ox=server.createobject ("Vfpweb.computertest")
Response.Write Ox.search (CBool ("cxxx"), CStr (Request ("CXNR"))
Set ox=nothing
%>

This is written in VB script ASP scripting, very simple. First you create a COM object instance, which is similar to the CreateObject () in Visual FoxPro:

Set Ox=server.createobject ("Vfpweb.computertest")

Once you have created a COM object instance, you will call it. At this time through the ASP request object to get query parameters cxxx and CXNR, because VB Script only one type of data is Variant, in order to ensure that COM communication, parameter data type error, we make mandatory type conversion; Call search function and waits for the search function to return the HTML code. Finally, the resulting HTML code is returned to the client browser.

Response.Write Ox.search (CBool ("cxxx"), CStr (Request ("CXNR"))

Visual FoxPro COM Build source code

Here, we analyze the core code:

FUNCTION Search (P1 as Boolean, p2 as String) as String
Local cHtml as String

Chtml= ""
TRY
IF P1
SELECT zkzh,xm,sfzh,dw,fs1,fs2,fs3,fs4,fs5,zfs from hmhg WHERE Zkzh=alltrim (p2) into CURSOR Temp
ELSE
SELECT zkzh,xm,sfzh,dw,fs1,fs2,fs3,fs4,fs5,zfs from hmhg WHERE xm like "%" +alltrim (p2) + "%" into CURSOR Temp
ENDIF

IF _tally=0
Chtml=this. Norecord ()
ELSE
Chtml=this. GetResult ()
ENDIF
CATCH to Oerror
Chtml=this. Errorresult ()
Strtofile (' ERROR: ' +oerror.errormessage+transform (DateTime ()) +cl+cl, ' C:\log.txt ',. T.)
Endtry

Return cHtml

Endfunc

Use different query statements based on different query keywords.

If no data is queried (the number of records in the query result Cursor is 0), the function Norecord is invoked and the HTML description returned by Norecord is returned to the calling program (ASP);

If the result Cursor does not exist, this indicates an error occurred in the query. Then call the function Errorresult and return the HTML description of the Errorresult back to the caller (here is the ASP);

If the result is found, the function getresult is called, and the query result Cursor is configured by GetResult to generate an HTML description to return to the caller (here is ASP).

Here's a point you should be aware that the Norecord, GetResult, errorresult functions all use the Hidden keyword when declaring that they are not visible outside of the class!

Next, we will analyze the function GetResult source code:

HIDDEN FUNCTION GetResult () as String
Local Cresult,cxml as String
TEXT to Cresult Textmerge noshow
<HTML>
<style>
<!--
. title {font-family:verdana; font-size:1em; color: #FF0000; letter-spacing:1pt;
Font-weight:bold; Background-color: #C0C0C0}
-->
</style>
<HEAD></HEAD>
<TITLE> Computer test Results Query </TITLE>
<BODY>
<xml id=xmlresult>
Endtext

Cursortoxml ("temp", "cXml", 1,16,0, "")

Cresult=cresult+cxml

TEXT to Cresult textmerge additive noshow
</XML>

<table id=tblresult datasrc= #xmlresult datapagesize=10 border=2 cellpadding=2 datapagesize=10 "# 800000 "bordercolordark=" #808080 "style=" Border-collapse:collapse "bordercolor=" #111111 "cellspacing=" 1 ">
<THEAD>
<tr class= "title" >
<TH> Admission Number </TH>
<TH> name </TH>
<TH> ID Number </TH>
<TH> Unit </TH>
<TH> score _1</th>
<TH> score _2</th>
<TH> score _3</th>
<TH> score _4</th>
<TH> score _5</th>
<TH> Total Score </TH>
</TR>
</THEAD>

<TR>
<td><div datafld= "Zkzh" ></DIV></TD>
<td><div datafld= "XM" ></DIV></TD>
<td><div datafld= "Sfzh" ></DIV></TD>
<td><div datafld= "DW" ></DIV></TD>
<td><div datafld= "FS1" ></DIV></TD>
<td><div datafld= "FS2" ></DIV></TD>
<td><div datafld= "FS3" ></DIV></TD>
<td><div datafld= "Fs4" ></DIV></TD>
<td><div datafld= "FS5" ></DIV></TD>
<td><div datafld= "ZFS" ></DIV></TD>
</TR>

</TABLE>

<P> display the number of records per page: <input type=text value=10 style= "Width:20"
Onblur= "Tblresult.datapagesize=this.value;" >
</p>
<button id=first onclick= "Tblresult.firstpage ()" >&lt;&lt;</BUTTON>
<button id=previous onclick= "Tblresult.previouspage ()" >&lt;</BUTTON>
<button id=next onclick= "Tblresult.nextpage ()" >&gt;</BUTTON>
<button id=last onclick= "Tblresult.lastpage ()" >&gt;&gt;</BUTTON>
</BOBY>
</HTML>
Endtext
Return Cresult
Endfunc

Here with the text to command the text to Cresult textmerge additive noshow ... The HTML description in the Endtext is conveniently fed into the memory variable Cresult. This section is "dead" HTML code that defines the frame, title, style table of the returned page, and the table used to display the results of the query.

Well, to get here, you just have to turn the query result data into HTML. Here I just use two lines of code to achieve:

Cursortoxml ("temp", "cXml", 1,16,0, "")
* Cursor The query result into an XML string and feeds into the memory variable cXml
Cresult=cresult+cxml
* Splicing the query results with the HTML frame description

Summary

Send a request from the client, to the server-side response, and then to the COM component's invocation and operation, the final return to the client browser can parse the HTML code description (here Our return information, also contains XML, DHTML, CSS, so not all browsers can parse these dongdong, I think IE More than 5.5 should be fine. If the code you want to return is suitable for more browsers, return the standard HTML code as much as possible.

Compiling, publishing com

Compile the project into a multithreaded in-process component in Visual FoxPro;

To create a virtual directory in IIS:

Here, you may want to ask: in the local directory D:\myweb need to have some of the files, my COM is not to put in there, and my database is also to be stored in this directory?

My answer is: COM does not need to be stored in this directory, you can compile the COM in any directory, so those who like to use software such as webzip to download the entire site, on the core of our programs can not, haha, how good!!!

Here, the data source hmhg.dbf is stored in the C:\ One of the directories below, is this safe?

In other settings in IIS, use the default value on the line!

For half a day, I arranged the catalogue on my machine for you to see:

C:\vfp_data\ Storage hmhg.dbf

D:\vfpweb\ store Vfpweb.dll, Vfpweb.tbl, VFPWEB.VBR

D:\myweb\ is the corresponding local directory for IIS. It's stored here, index.htm, search.asp, and some pictures.

End

Finally finished, I found that my "bragging" level is really good-not done any ASP program I, it's a big blow here. A universal asp+com implementation of the Web Server, if we feel dissatisfied, I have no way, the technology to do this ...

I think that as a good WEB developer, it should be a generalist (unless you're in a big company with a clear division of labor)--both ASP programming and web making, preferably component development. In short, the web programmer that will not develop the component, is just a scripting language programmer, and of course the programmer that will develop the component, like me, is just a Visual FoxPro programmer, leaving the WEB programmer, still a long way away ...

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.