Create a class with the following code :
class importCSVCommaIO extends RunBase
{
Filename filename;
DialogField dialogFilename;
}
public static void main(Args _args)
{
importCSVCommaIO importDept = new importCSVCommaIO();
FormRun formRun;
Args args;
if(importDept.prompt())
{
importDept.importDeptTable();
}
}
public Object dialog()
{
DialogRunbase dialog = super();
dialogFilename = dialog.addField(extendedTypeStr(FilenameOpen));
dialogFilename.value(filename);
return dialog;
}
public boolean getFromDialog()
{
fileName = dialogFileName.value();
return super();
}
void importDeptTable()
{
CommaIo commaIO;
DepartmentTable department;
DepartmentTable departmentTable;
Container con;
boolean first = true;
FileIOPermission readPermission;
#file
readPermission = new FileIOPermission(filename,#io_read);
readPermission.assert();
commaIO = new CommaIo(filename,'r');
commaIO.inFieldDelimiter(',');
CodeAccessPermission::revertAssert();
if (commaIO)
{
while(commaIO.status() == IO_Status::OK)
{
con = commaIO.read();
if (conLen(con) > 0)
{
if(first)
{
first = false;
}
else
{
ttsbegin;
department = DepartmentTable ::find(conpeek(con,1), true);
if(department.RecId == 0)
{
department.DeptId = conpeek(con,1);
department.Description = conpeek(con,2);
department.insert();
}
else
{
department.selectForUpdate(true);
select departmentTable where departmentTable.DeptId == department.DeptId;
department.Description = conPeek(con,2);
department.update();
}
ttscommit;
}
}
}
}
}
select the csv file from the browse button and on press OK the data gets imported into the table.
class importCSVCommaIO extends RunBase
{
Filename filename;
DialogField dialogFilename;
}
public static void main(Args _args)
{
importCSVCommaIO importDept = new importCSVCommaIO();
FormRun formRun;
Args args;
if(importDept.prompt())
{
importDept.importDeptTable();
}
}
public Object dialog()
{
DialogRunbase dialog = super();
dialogFilename = dialog.addField(extendedTypeStr(FilenameOpen));
dialogFilename.value(filename);
return dialog;
}
public boolean getFromDialog()
{
fileName = dialogFileName.value();
return super();
}
void importDeptTable()
{
CommaIo commaIO;
DepartmentTable department;
DepartmentTable departmentTable;
Container con;
boolean first = true;
FileIOPermission readPermission;
#file
readPermission = new FileIOPermission(filename,#io_read);
readPermission.assert();
commaIO = new CommaIo(filename,'r');
commaIO.inFieldDelimiter(',');
CodeAccessPermission::revertAssert();
if (commaIO)
{
while(commaIO.status() == IO_Status::OK)
{
con = commaIO.read();
if (conLen(con) > 0)
{
if(first)
{
first = false;
}
else
{
ttsbegin;
department = DepartmentTable ::find(conpeek(con,1), true);
if(department.RecId == 0)
{
department.DeptId = conpeek(con,1);
department.Description = conpeek(con,2);
department.insert();
}
else
{
department.selectForUpdate(true);
select departmentTable where departmentTable.DeptId == department.DeptId;
department.Description = conPeek(con,2);
department.update();
}
ttscommit;
}
}
}
}
}
select the csv file from the browse button and on press OK the data gets imported into the table.
No comments:
Post a Comment