static void ImportfromCSV(Args _args)
{
TTC_AppOfPF appOfPF;
Dialog dialog = new Dialog();
DialogField dialogField;
AsciiIo importFile;
str filePath,fileNameOnly;
filetype type;
container record;
str Delimiter = ",";
int totalRecords;
dialogField=dialog.addField(extendedTypeStr(FilenameOpen),"Select File","Select file to import");
dialog.caption("Import Worker's File");
dialog.filenameLookupFilter(['csv','*.csv']);
if(!dialog.run())
return;
[filePath, fileNameOnly, type] = fileNameSplit(dialogField.value());
importFile = new AsciiIo(dialogField.value(), 'R');
if((!importFile) || (importFile.status() != IO_Status::Ok))
{
warning("Error in opening import file");
throw(Exception::Error);
}
importFile.inFieldDelimiter(Delimiter);
if((!importFile) || (importFile.status() != IO_Status::Ok))
{
warning("Error in opening log file");
throw(Exception::Error);
}
try
{
ttsbegin;
record = importFile.read();
while(importFile.status() == IO_Status::Ok)
{
record = importFile.read();
if(!record)
break;
totalRecords = totalRecords + 1;
appOfPF.clear();
appOfPF.Worker = conPeek(record,1);
appOfPF.PersonnelNumber = conPeek(record,2);
appOfPF.PFAccountNum = conPeek(record,3);
appOfPF.insert();
}
ttscommit;
}
catch(Exception::Error)
{
Throw(Exception::Error);
}
info(strFmt("Total read records = %1",totalRecords));
}