Alpha Software
 
Alpha Software
 
How to Interact with data in an

How to Interact with data in an Alpha Five Table (.dbf file) on a Server from a Desktop Application

Assume you have a web application created with Alpha Five. The server is running the Alpha Five Application Server and has several Alpha Five tables (i.e. .dbf files) on it. You also have a desktop application, and you want to be able to insert, edit and delete records in those tables from your desktop application.

Here is how this can be done.

The first step is to create .a5w pages on the server that will do the work of inserting, updating or deleting records in your tables. Having created those pages, you can then 'execute' those pages from your desktop application using the http_get_page2() function.

Assume that the 'customer' table from Alphasports is on your server and you want to enter a new record into this table.

First, you would create a new page on the server called (say) 'enterCustomer.a5w'. The code in this page would look like this:

<%a5
dim result as c
on error goto failedToOpen
t = table.open("c:\demo\customer.dbf")
on error goto failed

'define default values for any variables that are NOT submitted when the page is called
dim firstname as c = default ""
dim Lastname as c = default ""
dim Company as c = default ""
dim Phone as c = default ""
dim Fax as c = default ""
dim Bill_address_1 as c = default ""
dim Bill_address_2 as c = default ""
dim Bill_city as c = default ""
dim Bill_state_region as c = default ""
dim Bill_postal_code as c = default ""
dim Bill_country as c = default ""
dim Ship_address_1 as c = default ""
dim Ship_address_2 as c = default ""
dim Ship_city as c = default ""
dim Ship_state_region as c = default ""
dim Ship_postal_code as c = default ""
dim Ship_country as c = default ""
dim Ship_same as l = default .t.
dim Email as c = default ""

'enter a new record
t.enter_begin()
t.Firstname= Firstname
t.Lastname= Lastname
t.Company= Company
t.Phone= Phone
t.Fax= Fax
t.Bill_address_1= Bill_address_1
t.Bill_address_2= Bill_address_2
t.Bill_city= Bill_city
t.Bill_state_region= Bill_state_region
t.Bill_postal_code= Bill_postal_code
t.Bill_country= Bill_country
t.Ship_address_1= Ship_address_1
t.Ship_address_2= Ship_address_2
t.Ship_city= Ship_city
t.Ship_state_region= Ship_state_region
t.Ship_postal_code= Ship_postal_code
t.Ship_country= Ship_country
t.Ship_same= Ship_same
t.Email= Email
t.enter_end(.t.)
t.close()
result = "Success"

'report the results
?result
end
failed:
result = "Failed. Error: " + error_text_get()
?result
t.close()
end
failedToOpen:
result = "Could not open table."
?result
end
%>

Notice that this .a5w page is all Xbasic code. It does not display any HTML.

The key aspects of the page are:

1. All of the variables are dimmed with a default value. This means that if the variable is not defined in the query string that calls the page, the variable will still have a value.

2. The page response (is either 'success'

To test this page from the Interactive window in Alpha Five, you would type this:

data = "firstname=selwyn&lastname=rabins&company=alphasoftware"
baseurl = "http://localhost:8090/enterCustomer.a5w"
?http_get_page2(baseurl + "?" + data)
= "Success"
 

The 'data' variable is simply a list of name/value pairs giving values to each of the fields in the new record that you want to update. It is in the standard format of URL query string.

The 'baseurl' variable just points to the 'enterCustomer.a5w' page on our server.

We then use the http_get_page2() function to execute the page, passing in the data as part of the URL.

The response we get from the server is 'success', indicating that the new record was added to the table.

Now, for the next step we can create an Xdialog on in our desktop application to prompt the user for the field values. The Xdialog will then construct the URL and call the http_get_page2() function.

Here is the Xdialog (simplified to prompt for just a few fields in the record).

Notice that we don't prompt for the customer_id field because this is an auto-increment field - its value is set automatically when a new record is added.

dim firstname as c
dim lastname as c
dim bill_city as c

dim flagOK as l = .f.
ui_dlg_box("Enter",<<%dlg%
{region}
Firstname: |[.20firstname];
Lastname: |[.20lastname];
City: |[.20bill_city];
{endregion};
<10&OK!ok> <10&Cancel>;
%dlg%,<<%code%
if a_dlg_button = "ok" then
flagOK = .t.
end if

%code%)

if flagOK = .t. then
    dim data as c
    data = "firstname="+firstname + "&lastname=" + lastname + "&bill_city=" + bill_city
    baseurl = "http://localhost:8090/enterCustomer.a5w"
    result = http_get_page2(baseurl + "?" + data)
    ui_msg_box("Notice",result)
end if

 


 

 

 

 

Alpha Software

Alpha Software, Inc. 70 Blanchard Road Burlington, MA 01803 781.229.4500
Affiliate Program Powered by TrafficSynergy Affiliate Network
© Copyright 2000-2009 Alpha Software, Inc. All Rights Reserved.
Intranet Solution