void clicked()
{
Dialog dialog;
DialogField dialogField;
FileName filename;
SysExcelApplication application;
SysExcelWorkbooks workbooks;
SysExcelWorkbook workbook;
SysExcelWorksheets worksheets;
SysExcelWorksheet worksheet;
SysExcelCells cells;
COMVariantType type;
InventDim locinventDim,locToInventDim;
InventJournalTrans locinventJournalTrans;
InventJournalTable inventjournaltable;
InventTable inventTable;
int row=1;
InventUpd_Estimated estimated;
SalesLine SalesLine;
//int coun;
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 "";
}
//Define File name.
dialog = new Dialog("Select file");
dialogField = dialog.addField(extendedTypeStr("FileNameOpen"),"Select File Source");
if (dialog.run()) {
fileName = dialogField.value();
}
if (fileName)
{
application = SysExcelApplication::construct();
workbooks = application.workbooks();
//Open Excel workbook.
try {
workbooks.open(filename);
}
catch (Exception::Error) {
throw error("File cannot be opened.");
}
//Open Excel Sheet
workbook = workbooks.item(1);
worksheets = workbook.worksheets();
worksheet = worksheets.itemFromNum(1);//which shows excel sheet number.
cells = worksheet.cells();
ttsbegin;
type = cells.item(row, 1).value().variantType();
while (cells.item(row 1, 1).value().variantType() != COMVariantType::VT_EMPTY)
{
locinventJournalTrans.clear();
locinventJournalTrans.TransDate =str2DateDMY(cells.item(row, 1).value().bStr());
locinventJournalTrans.ItemId =COMVariant2Str(cells.item(row, 2).value());
locinventDim.configId =COMVariant2Str(cells.item(row, 3).value());
locinventJournalTrans.initFromInventTable(InventTable::find(locinventJournalTrans.ItemId));
locinventDim.InventSizeId =COMVariant2Str(cells.item(row, 4).value());
locinventDim.InventColorId =COMVariant2Str(cells.item(row, 5).value());
locinventDim.InventLocationId =COMVariant2Str(cells.item(row, 6).value());
locinventDim.InventSiteId =COMVariant2Str(cells.item(row, 7).value()) ;
locinventDim.inventBatchId =COMVariant2Str(cells.item(row, 8).value());
locinventDim.wMSLocationId =COMVariant2Str(cells.item(row, 9).value());
locinventDim.inventSerialId =COMVariant2Str(cells.item(row, 10).value());
locinventJournalTrans.MZNPurchUnit =COMVariant2Str(cells.item(row, 11).value());
locinventJournalTrans.Qty =any2real(cells.item(row, 12).value().bStr());
locinventJournalTrans.InventDimId = InventDim::findOrCreate(locInventDim).inventDimId;
// Insert the data into the appropriate tables.
if (inventTable.ItemType == ItemType::Item)
{
inventTable.insert(true);
}
else
{
inventTable.ItemType = ItemType::Service;
checkFailed(strFmt("@FPK270056"));
}
//If(InventTable::find(SalesLine.ItemID).isStocked())
//{
//estimated= InventUpd_Estimated::newInventMovement(estimated.updateNow());
//}
//if (inventTable.ItemType == ItemType::Item && inventTable.isStocked())
//{
//estimated = InventUpd_Estimated::newInventMovement( estimated.updateNow());
//}
locinventJournalTrans.insert();
ttscommit;
// coun ;
// print('coun');
row ;
}
//info(int2str(coun));
application.quit();
super();
InventJournalTrans_ds.refresh();
InventJournalTrans_ds.research();
info('Done');
}
}
While Import Excel File in Movement Journal there issues create on ItemType::Item and ItemType::Service..