static void Na_DimensionFinancialTag(Args _args)
{
SysExcelApplication application;
SysExcelWorkbooks workbooks;
SysExcelWorkbook workbook;
SysExcelWorksheets worksheets;
SysExcelWorksheet worksheet;
SysExcelCells cells;
COMVariantType comtype;
DimensionAttribute dimensionAttribute;
DimensionFinancialTag dimensionFinancialTag;
FinancialTagCategory financialTagCategory;
DimensionAttributeDirCategory dimensionAttributeDirCategory;
int insertcount=0;
int row = 1;
Name Dimensionvale,Description;
Dialog dialog;
DialogField fileName;
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 "";
}
dialog = new Dialog();
dialog.caption("Select File");
fileName = dialog.addField(extendedTypeStr(FilenameOpen));
dialog.run();
application = SysExcelApplication::construct();
workbooks = application.workbooks();
try
{
workbooks.open(fileName.value());
}
catch
{
throw error("File cannot be opened");
}
workbook = workbooks.item(1);
worksheets = workbook.worksheets();
worksheet = worksheets.itemFromNum(1);
cells = worksheet.cells();
do
{
row++;
Dimensionvale = COMVariant2Str(cells.item(row,1).value());
Description = cells.item(row, 2).value().bStr();
try
{
ttsbegin;
select dimensionAttribute where dimensionAttribute.Name == "Entities";
if(dimensionAttribute)
{
select dimensionFinancialTag join financialTagCategory where dimensionFinancialTag.FinancialTagCategory == financialTagCategory.RecId
&& dimensionFinancialTag.Value == Dimensionvale
&& dimensionFinancialTag.Description == Description;
if(dimensionFinancialTag.RecId)
{
dimensionFinancialTag.Value = Dimensionvale;
dimensionFinancialTag.Description = Description;
dimensionFinancialTag.selectForUpdate(true);
dimensionFinancialTag.update();
info(strFmt('Employee %1 Updated', dimensionFinancialTag.Value));
}
else
{
select dimensionAttribute join dimensionAttributeDirCategory
join financialTagCategory
where dimensionAttributeDirCategory.DimensionAttribute == dimensionAttribute.RecId
&& dimensionAttributeDirCategory.DirCategory == financialTagCategory.RecId
&& dimensionAttribute.Name == "Entities";
dimensionFinancialTag.Value = Dimensionvale;
dimensionFinancialTag.Description = Description;
dimensionFinancialTag.FinancialTagCategory = financialTagCategory.RecId;
dimensionFinancialTag.insert();
info(strFmt('Employee %1 created', dimensionFinancialTag.Value));
}
insertcount++;
}
comtype = cells.item(row+1, 1).value().variantType();
ttsCommit;
}
catch(Exception::Error)
{
info(strFmt("Error in row %1", row));
}
}
while(comtype != COMVariantType::VT_EMPTY);
info(strFmt("%1 Record(s) inserted", insertcount));
application.quit();
}
{
SysExcelApplication application;
SysExcelWorkbooks workbooks;
SysExcelWorkbook workbook;
SysExcelWorksheets worksheets;
SysExcelWorksheet worksheet;
SysExcelCells cells;
COMVariantType comtype;
DimensionAttribute dimensionAttribute;
DimensionFinancialTag dimensionFinancialTag;
FinancialTagCategory financialTagCategory;
DimensionAttributeDirCategory dimensionAttributeDirCategory;
int insertcount=0;
int row = 1;
Name Dimensionvale,Description;
Dialog dialog;
DialogField fileName;
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 "";
}
dialog = new Dialog();
dialog.caption("Select File");
fileName = dialog.addField(extendedTypeStr(FilenameOpen));
dialog.run();
application = SysExcelApplication::construct();
workbooks = application.workbooks();
try
{
workbooks.open(fileName.value());
}
catch
{
throw error("File cannot be opened");
}
workbook = workbooks.item(1);
worksheets = workbook.worksheets();
worksheet = worksheets.itemFromNum(1);
cells = worksheet.cells();
do
{
row++;
Dimensionvale = COMVariant2Str(cells.item(row,1).value());
Description = cells.item(row, 2).value().bStr();
try
{
ttsbegin;
select dimensionAttribute where dimensionAttribute.Name == "Entities";
if(dimensionAttribute)
{
select dimensionFinancialTag join financialTagCategory where dimensionFinancialTag.FinancialTagCategory == financialTagCategory.RecId
&& dimensionFinancialTag.Value == Dimensionvale
&& dimensionFinancialTag.Description == Description;
if(dimensionFinancialTag.RecId)
{
dimensionFinancialTag.Value = Dimensionvale;
dimensionFinancialTag.Description = Description;
dimensionFinancialTag.selectForUpdate(true);
dimensionFinancialTag.update();
info(strFmt('Employee %1 Updated', dimensionFinancialTag.Value));
}
else
{
select dimensionAttribute join dimensionAttributeDirCategory
join financialTagCategory
where dimensionAttributeDirCategory.DimensionAttribute == dimensionAttribute.RecId
&& dimensionAttributeDirCategory.DirCategory == financialTagCategory.RecId
&& dimensionAttribute.Name == "Entities";
dimensionFinancialTag.Value = Dimensionvale;
dimensionFinancialTag.Description = Description;
dimensionFinancialTag.FinancialTagCategory = financialTagCategory.RecId;
dimensionFinancialTag.insert();
info(strFmt('Employee %1 created', dimensionFinancialTag.Value));
}
insertcount++;
}
comtype = cells.item(row+1, 1).value().variantType();
ttsCommit;
}
catch(Exception::Error)
{
info(strFmt("Error in row %1", row));
}
}
while(comtype != COMVariantType::VT_EMPTY);
info(strFmt("%1 Record(s) inserted", insertcount));
application.quit();
}
No comments:
Post a Comment