static void Sa_address(Args _args)
{
SysExcelApplication application;
SysExcelWorkbooks workbooks;
SysExcelWorkbook workbook;
SysExcelWorksheets worksheets;
SysExcelWorksheet worksheet;
SysExcelCells cells;
COMVariantType type1;
int row;
CustTable custTable1;
DirPartyTable dirPartyTable1;
LogisticsPostalAddress postalAddres1;
LogisticsLocation location;
FileName filename;
Dialog dialog;
DialogField dialogfield;
AccountNum custAccount;
Name custName;
Description description,address;
// excell data convert ionto string
str comvariant2str(comvariant _cv, int _decimals = 0,int _characters = 0,int _separator1 = 0,int _separator2 = 0)
{
switch(_cv.varianttype())
{
case (comvarianttype::vt_bstr):
return _cv.bstr();
case (comvarianttype::vt_r4):
return num2str(_cv.float(),_characters,_decimals, _separator1,_separator2);
case (comvarianttype::vt_r8):
return num2str(_cv.double(),_characters,_decimals,_separator1,_separator2);
case (comvarianttype::vt_decimal):
return num2str(_cv.decimal(),_characters,_decimals, _separator1, _separator2);
case (comvarianttype::vt_date):
return date2str(_cv.date(),123,2,1,2, 1,4);
case (comvarianttype::vt_empty):
return "";
default:
throw error(strfmt("@sys26908",_cv.varianttype()));
}
return "";
}
// selecting the required excel file
dialog = new dialog('Excel Import');
dialogfield = dialog.addField(extendedTypeStr(FilenameOpen), 'File Name');
dialog.run();
filename =(dialogfield.value()); //file path
try
{
application = SysExcelApplication::construct();
workbooks = application.workbooks();
workbooks.open(filename);
}
catch (Exception::Error)
{
throw error("File cannot be opened.");
}
workbook = workbooks.item(1);
worksheets = workbook.worksheets();
worksheet = worksheets.itemFromNum(1);
cells = worksheet.cells();
row =1;
do
{
row++;
custAccount = cells.item(row, 1).value().bStr();
description = COMVariant2Str(cells.item(row, 2).value());
address = COMVariant2Str(cells.item(row, 3).value());
select custTable1 where custTable1.AccountNum == custAccount
join dirPartyTable1 where custTable1.Party == dirPartyTable1.RecId
join location where location.RecId == dirPartyTable1.PrimaryAddressLocation
join postalAddres1 where postalAddres1.Location == location.RecId;
if(location.RecId)
{
ttsBegin;
Location.description = description;
Location.selectForUpdate(true);
Location.update();
ttsCommit;
}
if(postalAddres1.RecId)
{
ttsBegin;
postalAddres1.Address = Address;
postalAddres1.selectForUpdate(true);
postalAddres1.validTimeStateUpdateMode(ValidTimeStateUpdate::Correction);
postalAddres1.doUpdate();
ttsCommit;
}
type1 = cells.item(row+1, 1).value().variantType();
}
while (type1 != COMVariantType::VT_EMPTY);
application.quit();
info("import operation completed");
}
{
SysExcelApplication application;
SysExcelWorkbooks workbooks;
SysExcelWorkbook workbook;
SysExcelWorksheets worksheets;
SysExcelWorksheet worksheet;
SysExcelCells cells;
COMVariantType type1;
int row;
CustTable custTable1;
DirPartyTable dirPartyTable1;
LogisticsPostalAddress postalAddres1;
LogisticsLocation location;
FileName filename;
Dialog dialog;
DialogField dialogfield;
AccountNum custAccount;
Name custName;
Description description,address;
// excell data convert ionto string
str comvariant2str(comvariant _cv, int _decimals = 0,int _characters = 0,int _separator1 = 0,int _separator2 = 0)
{
switch(_cv.varianttype())
{
case (comvarianttype::vt_bstr):
return _cv.bstr();
case (comvarianttype::vt_r4):
return num2str(_cv.float(),_characters,_decimals, _separator1,_separator2);
case (comvarianttype::vt_r8):
return num2str(_cv.double(),_characters,_decimals,_separator1,_separator2);
case (comvarianttype::vt_decimal):
return num2str(_cv.decimal(),_characters,_decimals, _separator1, _separator2);
case (comvarianttype::vt_date):
return date2str(_cv.date(),123,2,1,2, 1,4);
case (comvarianttype::vt_empty):
return "";
default:
throw error(strfmt("@sys26908",_cv.varianttype()));
}
return "";
}
// selecting the required excel file
dialog = new dialog('Excel Import');
dialogfield = dialog.addField(extendedTypeStr(FilenameOpen), 'File Name');
dialog.run();
filename =(dialogfield.value()); //file path
try
{
application = SysExcelApplication::construct();
workbooks = application.workbooks();
workbooks.open(filename);
}
catch (Exception::Error)
{
throw error("File cannot be opened.");
}
workbook = workbooks.item(1);
worksheets = workbook.worksheets();
worksheet = worksheets.itemFromNum(1);
cells = worksheet.cells();
row =1;
do
{
row++;
custAccount = cells.item(row, 1).value().bStr();
description = COMVariant2Str(cells.item(row, 2).value());
address = COMVariant2Str(cells.item(row, 3).value());
select custTable1 where custTable1.AccountNum == custAccount
join dirPartyTable1 where custTable1.Party == dirPartyTable1.RecId
join location where location.RecId == dirPartyTable1.PrimaryAddressLocation
join postalAddres1 where postalAddres1.Location == location.RecId;
if(location.RecId)
{
ttsBegin;
Location.description = description;
Location.selectForUpdate(true);
Location.update();
ttsCommit;
}
if(postalAddres1.RecId)
{
ttsBegin;
postalAddres1.Address = Address;
postalAddres1.selectForUpdate(true);
postalAddres1.validTimeStateUpdateMode(ValidTimeStateUpdate::Correction);
postalAddres1.doUpdate();
ttsCommit;
}
type1 = cells.item(row+1, 1).value().variantType();
}
while (type1 != COMVariantType::VT_EMPTY);
application.quit();
info("import operation completed");
}
No comments:
Post a Comment