Diese Seite mit anderen teilen ...

Informationen zum Thema:
Forum:
WinDev Forum
Beiträge im Thema:
10
Erster Beitrag:
vor 8 Jahren, 10 Monaten
Letzter Beitrag:
vor 8 Jahren, 10 Monaten
Beteiligte Autoren:
Stefan Bentvelsen, Hans60

Export Import Data using WDM

Startbeitrag von Hans60 am 12.10.2009 14:14

Functions like HExportXML() etc do not exist on WDM.
How can I export import database memory info using PPC?
Any hint appreciated...


Thanks

Antworten:

Hi Hans60,

we use a simpel textfile to export data from server/pc to PPC and the same for exporting from PPC to server/pc. The textfile is send by email to the PPC and also by email back to the server/pc. We wrote procedures in W-language to put the data of a (set of) record(s) in a textfile and to pick it up from the textfile back to a HyperFile file.

von Stefan Bentvelsen - am 13.10.2009 17:45
Hi Stefan,
sounds interesting, how do you export data and what command is used to import data. I have a need for such a feature to export import data in to a PPC tool. It is a database with 40000 records each record has a Memo field, so a user can add his private comments. As the main database will be updated by a admin the private memo data record should not be overwritten and a user should be able to do a backup copy.

I also like to add a feature where additional single records can be imported and shared amongst PPC user....

I would be interested in your procedures..

Regards
Hans

von Hans60 - am 14.10.2009 13:15
Hi Hans,

I'll try to make a complete picture, but it is about 2,5 year ago I wrote this, so I it's not so fresh in my mind anymore. Note that I'm not saying that this is the best method to do it, but for it works fine!

In my window I have the following global declarations:

gsBestVolgorde is string // list of filenames separated by TAB
gsBestData is array of 20 string // structure of each file in gsBestVolgorde (max. 20)
giIdx is int // Index used in RecordToSeqfile()


Open a textfile:


iFil=fOpen(PADNAAM,foCreate+foWrite)
IF iFil=-1 THEN
Error(Replace("Bestand BESTAND kan niet aangemaakt/geopend worden !","BESTAND",PADNAAM))
RESULT bResult
END



For each file to process add a piece of code like this (A10 is a file of mine). I put here only the relevant code:


sBest="A10"
VulStructuurtabel(sBest)
HReadFirst("A10","afkorting")
WHILE NOT HOut(A10)
fWriteLine(iFil,"*** "+sBest+"+"+A10.afkorting) // A10.afkorting is the uniq identifier of the file
RecordToSeqFile(iFil,sBest)
HReadNext("A10","afkorting")
END


Procedure VulStructuurtabel:


PROCEDURE VulStructuurtabel(pBest)

sFData,sFField is string
sFName,sFType is string
iFNumber,iHlp is int
iHFType,iIdx is int

IF Position(gsBestVolgorde,pBest)>0 THEN
// Bepaal index in volgorde ...
iIdx=1
sFField=ExtractString(gsBestVolgorde,iIdx)
WHILE sFFieldEOT
IF sFField=pBest THEN BREAK
iIdx++
sFField=ExtractString(gsBestVolgorde,iIdx)
END
ELSE
IF gsBestVolgorde"" THEN
iIdx=StringCount(gsBestVolgorde,TAB)+1
ELSE
iIdx=0
END
iIdx++ // Te gebruiken index in array gsBestData ...
sFData=HListItem(pBest,hLstDetail)
iHlp=1
sFField=ExtractString(sFData,iHlp,CR)
WHILE sFFieldEOT
IF gsBestData[iIdx]"" THEN gsBestData[iIdx]+=CR
gsBestData[iIdx]+=(NoSpace(ExtractString(sFField,1))+TAB)
gsBestData[iIdx]+=(NoSpace(ExtractString(sFField,2))+TAB)
gsBestData[iIdx]+=(ExtractString(sFField,5)+TAB)
gsBestData[iIdx]+=ExtractString(sFField,3)
iHlp++
sFField=ExtractString(sFData,iHlp,CR)
END
IF gsBestVolgorde"" THEN gsBestVolgorde+=TAB
gsBestVolgorde+=pBest
END
giIdx=iIdx




PROCEDURE RecordToSeqFile(pTmp,pBest)

// Deze procedure schrijft voor elk veld in het meegegeven bestand(pBest) een regeltje in
// het sequentiele bestand waarvan de identifier (pTmp) ook meegegeven is.

iHlp,iInx is int
iFNumber is int
iHFType is int
sBest is string=pBest
sFName,sFType is string
sTekst is string

iIdx is int
sDeel is string

iIdx=1
sDeel=ExtractString(gsBestData[giIdx],iIdx,CR)
WHILE sDeelEOT
sFName=ExtractString(sDeel,1)
sFType=ExtractString(sDeel,2)
iFNumber=Val(ExtractString(sDeel,3))
iHFType=Val(ExtractString(sDeel,4))
IF iFNumber>1 THEN
FOR iInx=1 TO iFNumber
IF sFType="T" AND iHFType17 THEN
sTekst=Left({sBest+"."+sFName}[iInx])
sTekst=Replace(sTekst,CR,"/~")
fWriteLine(pTmp,sFName+"["+NumToString(iInx)+"]="+sTekst)
ELSE
fWriteLine(pTmp,sFName+"["+NumToString(iInx)+"]="+NumToString({sBest+"."+sFName}[iInx]))
END
END
ELSE
IF sFType="T" AND iHFType17 THEN
sTekst=Left({sBest+"."+sFName})
sTekst=Replace(sTekst,CR,"/~")
fWriteLine(pTmp,sFName+"="+sTekst)
ELSE
fWriteLine(pTmp,sFName+"="+NumToString({sBest+"."+sFName}))
END
END
iIdx++
sDeel=ExtractString(gsBestData[giIdx],iIdx,CR)
END


This is the part to create and fill the textfile. In a next forum item I will show you the part to read the textfile and fill the hyperfiles.

von Stefan Bentvelsen - am 15.10.2009 09:11
Hi Hans,

to read the data from the textfile into HyperFiles I use the following code:

Open the textfile ...


iFil=fOpen(pPadnaam,foRead)
IF iFil=-1 THEN
Error(Replace("Bestand BESTAND kan niet geopend/gelezen worden !","BESTAND",pPadnaam))
RESULT bResult
END


Read a line and proces the file:


sLine=fReadLine(iFil)

WHILE sLineEOT
SWITCH ExtractString(sLine,1,"+")
CASE "*** A10": sLine=SchrijfEenheden(iFil,sLine)
CASE "*** DEB": sLine=SchrijfKlanten(iFil,sLine)
CASE "*** WERKNMRS": sLine=SchrijfWerknemers(iFil,sLine)
CASE "*** CRD": sLine=SchrijfLeveranciers(iFil,sLine)
CASE "*** PROJECT": sLine=SchrijfProjecten(iFil,sLine)
CASE "*** PROJART": sLine=SchrijfProjArt(iFil,sLine)
CASE "*** URENSRT": sLine=SchrijfUrensrtn(iFil,sLine)
CASE "*** WERKZH": sLine=SchrijfWerkzaamheden(iFil,sLine)
CASE "*** PLOEGEN": sLine=SchrijfPloegen(iFil,sLine)

OTHER CASE
// Doorlezen totdat nieuwe regel gevonden is beginnend met "***"
// of totdat einde van het bestand bereikt is
sLine=fReadLine(iFil)
WHILE sLineEOT
IF sLine[[1 TO 3]]="***" THEN BREAK
sLine=fReadLine(iFil)
END
END
END
fClose(iFil)


I have several procedures Schrijf*(). For each file one. As an example I show you the one for file A10:


PROCEDURE SchrijfEenheden(pTmp,pLine)

sBest,sTekst is string
saveBest is string
sLine is string=pLine
sUniekeKey is string
sUniekeHlp is string
bGevuld is boolean=False
bOverslaan is boolean=False
bRecFound is boolean=False
nIHlp is int
nIHlp2 is int
nIHlp3 is int
nIHlp4 is int
nLUniekeKey is int
nLUniekeHlp is int
nLHlp is int

// Deze procedure moet de gegevens in het tekstbestand 3BImport.txt
// in de huidige administratie zetten.

WHILE sLineEOT
IF NoSpace(sLine)[[1 TO 3]]="***" THEN
IF bGevuld THEN
IF bRecFound THEN
HModify(sBest)
ELSE
HAdd(sBest)
END
IF HErrorDuplicates() THEN DuplM(sBest)
IF HErrorIntegrity() THEN IntegM(sBest)
bGevuld=False
END

// Bestandnaam bepalen (regel is: '*** +
sBest=Upper(ExtractString(NoSpace(sLine)[[5 TO]],1,"+"))
// Waarde unieke key bepalen ...
sUniekeHlp=ExtractString(NoSpace(sLine)[[5 TO]],2,"+")
IF sUniekeHlp="" THEN sUniekeHlp=" "

// Als het niet het juiste bestand betreft dan procedure verlaten ...
IF Position("A10",sBest)=0 THEN BREAK

IF sUniekeHlp"" THEN
// Controleren of de unieke waarde al bestaat in het bestand A10.
// Zo niet is er niets aan de hand, zo ja dan moeten alle volgende "records"
// overgeslagen worden die betrekking hebben op dit project ...
IF HReadSeekFirst("A10","afkorting",Complete(sUniekeHlp,8)) THEN
bRecFound=True
ELSE
bRecFound=False
END
sUniekeKey=sUniekeHlp
END

IF sBestsaveBest THEN
saveBest=sBest
// Structuur ophalen van het betreffende bestand ...
VulStructuurtabel(sBest)

// Record initialiseren ...
HReset(sBest)
END
ELSE
IF VulRubriek(sBest,sLine) THEN
bGevuld=True
END
END
sLine=fReadLine(pTmp)
END

IF bGevuld THEN
IF bRecFound THEN
HModify(sBest)
ELSE
HAdd(sBest)
END
IF HErrorDuplicates() THEN DuplM(sBest)
IF HErrorIntegrity() THEN IntegM(sBest)
bGevuld=False
END

RESULT sLine



Here is a different procedure to get the file structure. It is an older method and uses a invisible memorytable TBSTR with the columns: NAAM_STR (string, 50 char.), TYPE_STR (string, 1 char.), NUM_STR (numeric), HFTYPE_STR (numeric).


PROCEDURE VulStructuurtabel(pBest)

sFData,sFField is string
sFName,sFType is string
iFNumber,iHlp is int

TableDeleteAll("TBSTR")

sFData=HListItem(pBest,hLstDetail)
iHlp=1
sFField=ExtractString(sFData,iHlp,CR)
WHILE sFFieldEOT
sFName=NoSpace(ExtractString(sFField,1))
sFType=NoSpace(ExtractString(sFField,2))
iFNumber=Val(ExtractString(sFField,5))
TableAdd("TBSTR",sFName+TAB+sFType+TAB+iFNumber)
iHlp++
sFField=ExtractString(sFData,iHlp,CR)
END


And procedure VulRubriek():


PROCEDURE VulRubriek(pBest,pLine)

iHlp is int
iHlp2 is int
iHlp3 is int
iHlp4 is int
sTekst is string
sBest is string=pBest
sLine is string=pLine
bGevuld is boolean=False

iHlp=TableSeek("NAAM_STR",ExtractString(sLine,1,"="))
IF iHlp=-1 THEN
iHlp=TableSeek("NAAM_STR",ExtractString(sLine,1,"["))
END
IF iHlp-1 THEN
IF NUM_STR[iHlp]>1 THEN
iHlp2=Position(sLine,"[")
iHlp3=Position(sLine,"]")
IF iHlp2>0 AND iHlp3>iHlp2 THEN
iHlp4=Val(sLine[[iHlp2+1 TO iHlp3-1]])
IF iHlp4


von Stefan Bentvelsen - am 15.10.2009 09:38
Hi Stefan,
many thanks for sharing your expertise and sharing the code! I will try to use some in my project.
Is it correct to say that there is no windev function to export / import data using WDM functions? At least I did not find any only for WD. I am a bit surprised about that.....

Thanks again
Hans

von Hans60 - am 15.10.2009 21:52
Hi Hans,

it look likes you are right about the import- and exportfunctions in WinDev Mobile. The helpfile says that HExportXML, hImportXML and HImportText are not available in WDM.
Maybe we can create some functions for that.

von Stefan Bentvelsen - am 16.10.2009 07:06
Hi Stefan,
yes that is too bad! I have a requirement to export just a Memo field from a database in order to reimport later. However I am not experienced enough create such a function....
Regards
Hans

von Hans60 - am 20.10.2009 09:42
Hi Hans,

my procedures also do process textmemos, no binary memos. In textmemos the CR characters (Carriage return+Linefeed) are replaced my a combination of other characters and when imported by the mobile device, replaced back to CR characters.


von Stefan Bentvelsen - am 20.10.2009 14:51
Stefan,
may I in this regard send you a private mail? My address dev at ch4.net

Thanks
Hans

von Hans60 - am 21.10.2009 08:13
Zur Information:
MySnip.de hat keinen Einfluss auf die Inhalte der Beiträge. Bitte kontaktieren Sie den Administrator des Forums bei Problemen oder Löschforderungen über die Kontaktseite.
Falls die Kontaktaufnahme mit dem Administrator des Forums fehlschlägt, kontaktieren Sie uns bitte über die in unserem Impressum angegebenen Daten.