<%
local lcStoreID, lcXML, lcTable, lcFile, lcCursor
lcStoreID = upper(alltrim(Request.Form("StoreID")))
lcXML = Request.form("XML")
lcTable = upper(alltrim(Request.form("DBF")))
if UPPER(lcTable) = 'NOTES'
response.write("SUCCESS")
RETURN
ENDIF
if empty(lcStoreID)
response.write("Empty store id")
return
endif
if empty(lcXML)
response.write("empty xml file")
return
endif
if empty(lcTable)
response.write("empty table name")
return
endif
if not used('toyzsync')
use c:\foxweb\toyzsync.dbf in 0
endif
lcCursor = sys(2015)
lcLoc = "\\toyzfinance\finance\toyz" + alltrim(lcStoreID) + "\Data\" + alltrim(lcTable) + ".dbf"
if not file(lcLoc)
select ToyzSync
set order to StoreID
if not seek(lcStoreID)
append blank
replace StoreId with lcStoreID
endif
replace LastError with datetime()
replace errorMsg with 'File does not exist: ' + lcLoc
response.write("File does not exist: " + lcLoc)
return
endif
lcfile = alltrim(lcStoreID) + SYS(2015)+alltrim(lcTable)+".xml"
try
if used(lcTable)
use in sele(lcTable)
endif
use (lcLoc) in 0
lcXML = strtran(lcXML,'1.E+6','999')
lcXML = strtran(lcXML,'8.E+6','999')
lcXML = strtran(lcXML,'9.E+6','999')
lcXML = strtran(lcXML,'5.E+6','999')
lcXML = strtran(lcXML,'3.E+6','999')
lcXML = strtran(lcXML,'4.E+6','999')
lcXML = strtran(lcXML,'6.E+6','999')
lcXML = strtran(lcXML,'7.E+6','999')
lcXML = strtran(lcXML,'2.E+6','999')
lcXML = strtran(lcXML,'10.E+6','999')
lcXML = strtran(lcXML,'<length>**</length>','<length>0</length>')
lcXML = strtran(lcXML,'<qty>******</qty>','<qty>999</qty>')
lcXML = strtran(lcXML,chr(2),'')
lcXML = strtran(lcXML,chr(17),'')
lcXML = strtran(lcXML,chr(14),'')
strtofile(lcXML,lcFile)
xmltocursor(lcFile,lcCursor,512)
m.lDel = .f.
SELECT (lcCursor)
lnCount = 0
SCAN
SCATTER MEMVAR memo
release m.PKServer && since the table would have one from the store.
m.PKServer = m.IID && we want the pkserver to be the IID of the store
RELEASE m.IID && that's auto inc, so remove it
m.LastUpdate = date()
SELECT (lcTable)
SET ORDER TO pkServer
IF NOT SEEK(m.pkServer)
APPEND BLANK
endif
if m.lDel
Delete
else
GATHER MEMVAR memo
endif
lnCount = lnCount + 1
ENDSCAN
response.write('SUCCESS')
*strtofile("storeid: " + lcStoreID + " table: " + lcTable + ' Datetime: ' + ttoc(datetime()) + ' Records: ' + Trans(lnCount) + chr(10) + chr(13),"c:\sync.txt",1)
sele ToyzSync
set order to StoreID
if not seek(lcStoreID)
append blank
replace StoreId with lcStoreID
endif
replace LastSync with datetime()
use in sele('Toyzsync')
use in select(lcCursor)
use in select(lcTable)
if file(lcFile)
erase (lcFile)
endif
catch to loExp
response.write('ERROR')
strtofile("Datetime: " + ttoc(datetime()) + " Store ID: " + lcStoreID + " Table: " + lcTable + " Message: " + loExp.Message + "Line: " + trans(loExp.LineNo) + chr(13)+chr(10),"c:\foxweb\SyncError.txt",1)
if not used('toyzsync')
use c:\foxweb\toyzsync.dbf in 0
endif
sele ToyzSync
set order to StoreID
if not seek(lcStoreID)
append blank
replace StoreId with lcStoreID
endif
replace LastError with datetime()
replace errorMsg with 'Message: ' + loExp.Message + chr(10) + chr(13) + 'Line: ' + trans(loExp.LineNo)
use in sele('Toyzsync')
if file(lcFile)
erase (lcFile)
endif
use in select(lctable)
use in select(lcCursor)
exit
endtry
%>
|