public class Ale_ImportCustomerDetails
{
SysExcelApplication application;
SysExcelWorkbooks workbooks;
SysExcelWorkbook workbook;
SysExcelWorksheets worksheets;
SysExcelWorksheet worksheet;
SysExcelCells cells;
}
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 "";
}
public void importCustomerDetails()
{
Dialog dialog;
DialogGroup dialogGroup;
DialogField dialogfilename;
Filename filename;
COMVariantType type;
int row;
NoYesCombo NoYes;
NoYes NoYes1;
CustVendorBlocked CustVendorBlocked;
AccountNum custAccount;
custTable custTable;
CustTable custTablePrimaryContact;
int arrindex;
Struct struct = new Struct();
container defaultDimension;
container attrib , value ;
;
dialog = new Dialog("Select File For customer Master Import");
dialogGroup = dialog.addGroup("Excel File");
dialogfilename = dialog.addField(typeId(FilenameOpen));
if (dialog.run())
{
application = SysExcelApplication::construct();
workbooks = application.workbooks();
filename=dialogfilename.value();
try
{
workbooks.open(filename);
}
catch (Exception::Error)
{
throw error(strFmt("@GLS101746",filename));
}
workbook = workbooks.item(1);
worksheets = workbook.worksheets();
worksheet = worksheets.itemFromNum(1);
cells = worksheet.cells();
row = 1;
ttsBegin;
do
{
row++;
custAccount = this.COMVariant2Str(cells.item(row, 1).value());
Select forupdate * from custTable
where custTable.AccountNum == custAccount;
if (custTable)
{
custTable.initValue();
//custTable.AccountNum = this.COMVariant2Str(cells.item(row, 1).value());
custTable.GSTNumber_IN = this.COMVariant2Str(cells.item(row, 2).value());
custTable.update();
}
type = cells.item(row+1, 1).value().variantType();
}
while (type != COMVariantType::VT_EMPTY);
ttsCommit;
workbooks.close();
info(strFmt("%1 records successfully inserted", row - 1));
application.quit();
}
}
{
SysExcelApplication application;
SysExcelWorkbooks workbooks;
SysExcelWorkbook workbook;
SysExcelWorksheets worksheets;
SysExcelWorksheet worksheet;
SysExcelCells cells;
}
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 "";
}
public void importCustomerDetails()
{
Dialog dialog;
DialogGroup dialogGroup;
DialogField dialogfilename;
Filename filename;
COMVariantType type;
int row;
NoYesCombo NoYes;
NoYes NoYes1;
CustVendorBlocked CustVendorBlocked;
AccountNum custAccount;
custTable custTable;
CustTable custTablePrimaryContact;
int arrindex;
Struct struct = new Struct();
container defaultDimension;
container attrib , value ;
;
dialog = new Dialog("Select File For customer Master Import");
dialogGroup = dialog.addGroup("Excel File");
dialogfilename = dialog.addField(typeId(FilenameOpen));
if (dialog.run())
{
application = SysExcelApplication::construct();
workbooks = application.workbooks();
filename=dialogfilename.value();
try
{
workbooks.open(filename);
}
catch (Exception::Error)
{
throw error(strFmt("@GLS101746",filename));
}
workbook = workbooks.item(1);
worksheets = workbook.worksheets();
worksheet = worksheets.itemFromNum(1);
cells = worksheet.cells();
row = 1;
ttsBegin;
do
{
row++;
custAccount = this.COMVariant2Str(cells.item(row, 1).value());
Select forupdate * from custTable
where custTable.AccountNum == custAccount;
if (custTable)
{
custTable.initValue();
//custTable.AccountNum = this.COMVariant2Str(cells.item(row, 1).value());
custTable.GSTNumber_IN = this.COMVariant2Str(cells.item(row, 2).value());
custTable.update();
}
type = cells.item(row+1, 1).value().variantType();
}
while (type != COMVariantType::VT_EMPTY);
ttsCommit;
workbooks.close();
info(strFmt("%1 records successfully inserted", row - 1));
application.quit();
}
}
No comments:
Post a Comment