-
Take On
Customer
Records
|
+
Get FileName and check
for empty file
|
.
GotFileName <-- GetFileOpenName("Select a File", FilePath, FileName,"","Text Files (*.TXT),*.txt")
|
|
-
GotFileName <> 1
|
.
messagebox("No File Selected", "Try again if needed...")
return
|
|
|
.
CustomerFile <-- fileopen(FilePath)
|
|
-
CustomerFile = -1
|
.
messagebox("Unable to open Selected File", FilePath + " could not be opened")
return
|
|
|
.
ReadResult <-- fileread(CustomerFile, CustomerRec)
|
|
|
-
ReadResult < 0
|
.
messagebox("Empty File", FilePath + " is an empty file...")
fileclose(CustomerFile)
return
|
|
|
|
+
Initialize counters
|
.
ReadCounter <-- 0
AlreadyThereCounter <-- 0
InsertCounter <-- 0
|
|
|
+
Connect to the database
|
-
SQLCA.SQLCode <> 0 and
<> -1
|
.
messagebox("Unable to CONNECT", "SQLCode=" + string(SQLCA.SQLCode))
return
|
|
|
|
+
Process the file
|
.
ReadCounter += 1
Extract fields using mid & trim functions
|
|
-
Check if this is already
in the database
|
.
SELECT id INTO :BeId FROM be where
first_name = :FirstName and
last_name = :LastName and
street = :Street
|
|
|
or
-
Else
|
.
INSERT new record into be
InsertCounter ++
|
|
|
-
SQLCode <> 0
|
.
messagebox("Insert Failed", "SQLCode=" + string(SQLCA.SQLCode)
return
|
|
|
|
|
.
ReadResult <-- fileread(CustomerFile, CustomerRec)
|
|
|
|
+
Wrapup
|
.
fileclose(CustomerFile)
DISCONNECT
messagebox("Customer TakeOn Results", string(ReadCounter) + " read" + CrLf +
string(AlreadyThereCounter) + " duplicates avoided" + CrLf +
string(InsertCounter) + " new records taken on")
|
|
|
|