Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Export records from main app, import to another app and return 1

Status
Not open for further replies.

Steve-vfp9user

Programmer
Feb 5, 2013
337
GB
Hello all

Part of an app I am currently putting together involves emailing jobs to users who then import that job into another app I have produced.
The current system works like this:
[ul]
[li]I select the job to be emailed[/li]
[li]The relevant coding zips a .dbf and an .fpt file to a zipped file (The record contains several memo fields hence the .fpt file)[/li]
[li]The zipped file is emailed to the user (all the above is working perfectly)[/li]
[li]The user will then run their app which unzips the zipped folder, imports the record contained in the zipped file and is updated by the user[/li]
[/ul]
I’ve not yet got as far as unzipping the zipped folder on the Windows tablet (albeit I have tested an un associated small app with VFP9 to ensure it works), import the record contained in the zipped file and allow the user to update and return the record by email yet as so far this process appears to be somewhat cumbersome.

The code to zip the file was produced by craigsboyd (Sweet Potato) and works as it should (Of course).
My question is: What is the best way to export or send relevant records from a dbf table to a user via email for them to pick up, update and send it back?

It’s only the best way to automate I need advice on, I’m doing ok with the coding so far and here is the code for zipping the file with credit as above:

Code:
mcurr=SYS(5)+SYS(2003)
SET LIBRARY TO LOCFILE("vfpcompression.fll")
?ZipFolderQuick(mcurr+"\exportopjob\exportopjob")
?ZipFolderQuick(mcurr, .T., "MyPassword")
?ZipFolderQuick(mcurr, .F., "MyPassword")
SET LIBRARY TO

Here is part of the code I use to send the email (edited):

Code:
oOutlook = Createobject('Outlook.Application')
oNameSpace = oOutlook.getnamespace('MAPI')
oOutbox = oNameSpace.GetDefaultFolder(4)

oItems = oOutbox.Items
oMailItem = oItems.Add(0)
oMailItem.To = ALLTRIM(recipient)
oMailItem.Subject = TRIM(subject)
oMailItem.Body = TRIM(themessage)
oMailItem.attachments.add(thefile)
oMailItem.ReadReceiptRequested = .T.
oMailItem.Send

I’m using VFP9 SP2, Windows 10 on my desktop and 7 on the Windows tablet



Thank you

Steve
 
I must not understand what your question is. You seem to show code that answers the question of how to send the DBF to a user by email.

Tamar
 
As Tamar says, you already have one way that seems as though it would work.

Another way to make it work, possibly more expeditiously, would be to incorporate Web Services - especially on the "update and send it back" side.

The Web Service would be up-and-running 24/7 to receive input from the 'remote' devices.
Upon receiving an update, it would automatically integrate the new data into the existing tables.

Another Web Service could deliver the 'jobs' to the users, but the user and, or the VFP application itself, would need to launch a 'see if any new jobs waiting'.
Or continue to use the outgoing email process you already have for this part.

Good Luck,
JRB-Bldr


 
Tamargranor: My initial attempt does send an email with an attachment which the user will have to copy into a folder, then run another process. I am looking for a way that I might be able to directly import the attachment from an Outlook email (Apologies if I didn't explain this correctly)

jrbbldr: Thank you for your post. Are you saying that the user would directly access data from online tables to receive / update / send back?

Thank you

Steve
 
If you transferred data via Web Services, you would not be directly accessing the data tables.
Instead you would be sending/receiving data in a text format that represented the desired records.

On the user's side, when the data was received it would be imported into the appropriate data table and utilized as needed.

Receiving data is usually a response by the Web Service to a Request from the user's side/application. The Web Service receives the request and then prepares the data which can then be received by the user's application.

Then, when done, the data would again be sent as text to the host side via a Web Service. The Web Service would then import that data back into the needed data table(s).

You might want to study a few of the 'finds' from a Google search for: vfp using web service

Good Luck,
JRB-Bldr
 
jrbbldr: Very useful post for which I'm grateful. When I have found a solution I'll post back

Thank you

Steve
 
Ok so this is what I did (If it helps anyone else searching this forum):

Code:
WAIT "Checking Internet Connection, please wait...." WINDOW NOWAIT

DECLARE INTEGER GetRTTAndHopCount IN Iphlpapi ;
  INTEGER DestIpAddress, LONG @HopCount, ;
  INTEGER MaxHops, LONG @RTT

DECLARE INTEGER inet_addr IN ws2_32 STRING cp

LOCAL lnDst, lnHop, lnRTT
lnDst = inet_addr("212.58.246.91") && BBC
STORE 0 TO lnHop, lnRTT

IF GetRTTAndHopCount(lnDst, @lnHop, 50, @lnRTT) = 0
  WAIT CLEAR
  =MESSAGEBOX("CANNOT establish an Internet Connection"+ ;
    space(10),0+16+0,"System Message")
  RETURN
ENDIF
	
WAIT CLEAR

* To test the upload and download I used simple .txt files

* To download the relevant data, there are two files:

Code:
************
* getftp.prg
************

WAIT "Starting job retrieval and import process...." WINDOW NOWAIT

RUN ftp  -i -s:[b]getfile.txt[/b]

SET SAFETY OFF

IF FILE("testfile.txt")
  WAIT "File has been downloaded, process starting...." WINDOW NOWAIT
ELSE
  WAIT "Failed to find any files" WINDOW NOWAIT
  RETURN
ENDIF

* Now run the necessary code

* More code here....

CLEAR
RETURN

* getfile.txt

Code:
open ftp.mywebsite.com
myusername
mypassword
binary
get testfile.txt
close
bye
exit

To upload the relevant updated records back to the server, there are two files:

*************
* sendftp.prg
*************

Code:
CLEAR
CLOSE DATABASES

WAIT "Starting upload and export process...." WINDOW NOWAIT

RUN ftp  -i -s:[b]send.txt[/b]

SET SAFETY OFF

WAIT "File has been uploaded" WINDOW NOWAIT

CLEAR
RETURN

* send.txt

Code:
open ftp.mywebsite.com
myusername
mypassword
binary
send testfile.txt
close
bye
exit

So this means that I can now incorporate coding that will automatically upload/download the relevant data files and import/export without the need for email automation.


Thank you

Steve
 
I'm glad you got things working with FTP transfers.
That is not a "Web Service", but who cares - it is MUCH better than email and, most importantly, it works for you.

Good Luck,
JRB-Bldr
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top