Run Base Class For CSV Import
Class Declaration:
class NRG_CSV_Import extends RunBase
{
DialogField dlgFileNameImport;
DialogField dlgFileNameExportSuccess;
DialogField dlgFileNameExportError;
FileName fileNameImport;
FileName fileNameExportSuccess;
FileName fileNameExportError;
commaIO fileImport;
commaIO fileExportSuccess;
commaIO fileExportError;
Container fileCon;
// Pack/Unpack settings
#define.CurrentVersion(1)
#localmacro.CurrentList
fileNameImport,
fileNameExportSuccess,
fileNameExportError
#endmacro
}
Caption:
public ClassDescription caption()
{
return "@MCS1411"; // Billing invoice run
}
Dialog:
public Object dialog()
{
DialogRunbase dialog = super();
;
dlgFileNameImport = dialog.addField(typeid(FileNameOpen), "@SYS4820");
return dialog;
}
GetFromDialog:
public boolean getFromDialog()
{
boolean ret;
;
ret = super();
if (ret)
{
fileNameImport = dlgFileNameImport.value();
//fileNameExportSuccess = dlgFileNameExportSuccess.value();
//fileNameExportError = dlgFileNameExportError.value();
}
return ret;
}
New Method ( importcSVImportTest():)
void importcSVImportTest()
{
CSVImportTest cSVImportTest;
DictTable dictTable;
DictField dictField;
boolean error = false;
int x;
#define.AccountNum (2)
#define.Name (3)
#define.CustGroup (4)
#define.PaymTermId (5)
#define.Currency (6)
#define.CountryRegionId (7)
#define.PaymMode (8)
#define.LanguageId (9)
#define.ZipCode (10)
#define.City (11)
#define.Street (12)
;
cSVImportTest.CustAccNo = conPeek(fileCon, #AccountNum);
cSVImportTest.Name = conPeek(fileCon, #Name);
cSVImportTest.CustGroupId = conPeek(fileCon, #CustGroup);
cSVImportTest.PaymTermId = conPeek(fileCon, #PaymTermId);
cSVImportTest.CurrencyCode = conPeek(fileCon, #Currency);
cSVImportTest.AddressCountryRegionId = conPeek(fileCon, #CountryRegionId);
cSVImportTest.PaymMode = conPeek(fileCon, #PaymMode);
cSVImportTest.LanguageId = conPeek(fileCon, #LanguageId);
cSVImportTest.AddressZipCodeId = conPeek(fileCon, #ZipCode);
cSVImportTest.AddressCity = conPeek(fileCon, #City);
cSVImportTest.AddressStreet = conPeek(fileCon, #Street);
cSVImportTest.validateWrite();
cSVImportTest.insert();
/* dictTable = new DictTable(cSVImportTest.TableId);
for (x = 1; x <= dictTable.fieldCnt(); x++)
{
dictField = new DictField(dictTable.id(), dictTable.fieldCnt2Id(x));
if (!cSVImportTest.validateField(dictField.id()))
{
error = true;
}
}
if (cSVImportTest.validateWrite() && !error)
{
try
{
cSVImportTest.doinsert();
this.writeSuccess();
}
catch
{
this.writeError();
}
}
else
{
this.writeError();
}
*/
}
New Method (importOtherTable():)
void importOtherTable()
{
;
fileExportSuccess.write(fileCon);
}
initFiles:
void initFiles()
{
;
fileImport = new CommaIO(fileNameImport, 'r');
fileImport.inFieldDelimiter(',');
fileImport.inRecordDelimiter('\r\n');
}
New:
void new()
{
;
super();
}
Pack:
public container pack()
{
;
return [#CurrentVersion,#CurrentList];
}
Run:
public void run()
{
counter cols,x, lines;
textbuffer txt = new textbuffer()
;
//txt.fromFile(fileNameImport);
//txt.numLines();
// this.initFiles();
fileImport = new CommaIO(fileNameImport, 'r');
fileImport.inFieldDelimiter(',');
fileImport.inRecordDelimiter('\r\n');
fileCon = fileImport.read();
ttsbegin;
/*while (fileImport.status() == IO_Status::Ok)
{
switch (conPeek(fileCon, 1))
{
case "1":
this.importcSVImportTest();
break;
case "2":
this.importOtherTable();
break;
default:
// Unknow row format
this.writeError();
}
fileCon = fileImport.read();
}*/
if (fileImport.status() == IO_Status::Ok)
{
fileCon = fileImport.read();
while (fileCon)
{
/*
cols = conLen(fileCon);
for(x=1;x<=cols;x++)
{
*/
// fileCon = fileImport.read();
this.importcSVImportTest();
// info(strfmt(" %1--%2",conpeek(filecon,1),conpeek(filecon,2) ) );
// }
fileCon = fileImport.read();
}
}
ttscommit;
//infolog.clear(0);
info("@SYS70405");
}
Unpack:
public boolean unpack(container packedClass)
{
int version = RunBase::getVersion(packedClass);
;
switch (version)
{
case #CurrentVersion:
[version,#CurrentList] = packedClass;
return true;
default :
return false;
}
return false;
}
WriteError:
void writeError()
{
;
fileExportError.write(fileCon);
}
Write Success:
void writeSuccess()
{
;
fileExportSuccess.write(fileCon);
}
Main:
public static void main(Args args)
{
NRG_CSV_Import importCSV;
;
importCSV = new NRG_CSV_Import();
if (importCSV.prompt())
{
importCSV.run();
}
}
Class Declaration:
class NRG_CSV_Import extends RunBase
{
DialogField dlgFileNameImport;
DialogField dlgFileNameExportSuccess;
DialogField dlgFileNameExportError;
FileName fileNameImport;
FileName fileNameExportSuccess;
FileName fileNameExportError;
commaIO fileImport;
commaIO fileExportSuccess;
commaIO fileExportError;
Container fileCon;
// Pack/Unpack settings
#define.CurrentVersion(1)
#localmacro.CurrentList
fileNameImport,
fileNameExportSuccess,
fileNameExportError
#endmacro
}
Caption:
public ClassDescription caption()
{
return "@MCS1411"; // Billing invoice run
}
Dialog:
public Object dialog()
{
DialogRunbase dialog = super();
;
dlgFileNameImport = dialog.addField(typeid(FileNameOpen), "@SYS4820");
return dialog;
}
GetFromDialog:
public boolean getFromDialog()
{
boolean ret;
;
ret = super();
if (ret)
{
fileNameImport = dlgFileNameImport.value();
//fileNameExportSuccess = dlgFileNameExportSuccess.value();
//fileNameExportError = dlgFileNameExportError.value();
}
return ret;
}
New Method ( importcSVImportTest():)
void importcSVImportTest()
{
CSVImportTest cSVImportTest;
DictTable dictTable;
DictField dictField;
boolean error = false;
int x;
#define.AccountNum (2)
#define.Name (3)
#define.CustGroup (4)
#define.PaymTermId (5)
#define.Currency (6)
#define.CountryRegionId (7)
#define.PaymMode (8)
#define.LanguageId (9)
#define.ZipCode (10)
#define.City (11)
#define.Street (12)
;
cSVImportTest.CustAccNo = conPeek(fileCon, #AccountNum);
cSVImportTest.Name = conPeek(fileCon, #Name);
cSVImportTest.CustGroupId = conPeek(fileCon, #CustGroup);
cSVImportTest.PaymTermId = conPeek(fileCon, #PaymTermId);
cSVImportTest.CurrencyCode = conPeek(fileCon, #Currency);
cSVImportTest.AddressCountryRegionId = conPeek(fileCon, #CountryRegionId);
cSVImportTest.PaymMode = conPeek(fileCon, #PaymMode);
cSVImportTest.LanguageId = conPeek(fileCon, #LanguageId);
cSVImportTest.AddressZipCodeId = conPeek(fileCon, #ZipCode);
cSVImportTest.AddressCity = conPeek(fileCon, #City);
cSVImportTest.AddressStreet = conPeek(fileCon, #Street);
cSVImportTest.validateWrite();
cSVImportTest.insert();
/* dictTable = new DictTable(cSVImportTest.TableId);
for (x = 1; x <= dictTable.fieldCnt(); x++)
{
dictField = new DictField(dictTable.id(), dictTable.fieldCnt2Id(x));
if (!cSVImportTest.validateField(dictField.id()))
{
error = true;
}
}
if (cSVImportTest.validateWrite() && !error)
{
try
{
cSVImportTest.doinsert();
this.writeSuccess();
}
catch
{
this.writeError();
}
}
else
{
this.writeError();
}
*/
}
New Method (importOtherTable():)
void importOtherTable()
{
;
fileExportSuccess.write(fileCon);
}
initFiles:
void initFiles()
{
;
fileImport = new CommaIO(fileNameImport, 'r');
fileImport.inFieldDelimiter(',');
fileImport.inRecordDelimiter('\r\n');
}
New:
void new()
{
;
super();
}
Pack:
public container pack()
{
;
return [#CurrentVersion,#CurrentList];
}
Run:
public void run()
{
counter cols,x, lines;
textbuffer txt = new textbuffer()
;
//txt.fromFile(fileNameImport);
//txt.numLines();
// this.initFiles();
fileImport = new CommaIO(fileNameImport, 'r');
fileImport.inFieldDelimiter(',');
fileImport.inRecordDelimiter('\r\n');
fileCon = fileImport.read();
ttsbegin;
/*while (fileImport.status() == IO_Status::Ok)
{
switch (conPeek(fileCon, 1))
{
case "1":
this.importcSVImportTest();
break;
case "2":
this.importOtherTable();
break;
default:
// Unknow row format
this.writeError();
}
fileCon = fileImport.read();
}*/
if (fileImport.status() == IO_Status::Ok)
{
fileCon = fileImport.read();
while (fileCon)
{
/*
cols = conLen(fileCon);
for(x=1;x<=cols;x++)
{
*/
// fileCon = fileImport.read();
this.importcSVImportTest();
// info(strfmt(" %1--%2",conpeek(filecon,1),conpeek(filecon,2) ) );
// }
fileCon = fileImport.read();
}
}
ttscommit;
//infolog.clear(0);
info("@SYS70405");
}
Unpack:
public boolean unpack(container packedClass)
{
int version = RunBase::getVersion(packedClass);
;
switch (version)
{
case #CurrentVersion:
[version,#CurrentList] = packedClass;
return true;
default :
return false;
}
return false;
}
WriteError:
void writeError()
{
;
fileExportError.write(fileCon);
}
Write Success:
void writeSuccess()
{
;
fileExportSuccess.write(fileCon);
}
Main:
public static void main(Args args)
{
NRG_CSV_Import importCSV;
;
importCSV = new NRG_CSV_Import();
if (importCSV.prompt())
{
importCSV.run();
}
}
No comments:
Post a Comment