Reader CSV file
// Changed on 17 April 2012 at 10:12:15 by Jimmy xie
static void THK_csvRead(Args _args)
{
#AviFiles
SysOperationProgress progress = new SysOperationProgress(1,true);
str filename;
FileNameFilter filter = ['All files','*.CSV'];
CommaIO commaIO;
container InData;
InventItemLocation itemLocation;
Int i = 0;
Int j = 0;
InventDimId inventDimId;
;
filename = Winapi::getOpenFileName(0, filter, '', "Select file for upload onhand", '','');
if (!winAPI::fileExists(filename,false))
return;
commaIO = new CommaIO(filename, 'r');
commaIO.inFieldDelimiter(',');
if (!commaIO)
return;
if (!Box::yesNo(strfmt("Upload this file %1", filename), dialogButton::No))
return;
progress.setCaption("Upload Items");
progress.setAnimation(#AviUpdate);
setprefix(filename);
while (commaIO.status() == IO_Status::Ok)
{
inData = commaIO.read();
if ( conLen(inData) > 0 )
{
j++;
info( strfmt("%10 : 1[%1] - 2[%2] - 3[%3] - 4[%4] - 5[%5] - 6[%6] - 7[%7] - 8[%8] - 9[%9]",
conpeek(inData,1),
conpeek(inData,2),
conpeek(inData,3),
conpeek(inData,4),
conpeek(inData,5),
conpeek(inData,6),
conpeek(inData,7),
conpeek(inData,8),
conpeek(inData,9),j)
);
progress.setText(strfmt("%1: %2", conpeek(inData,1), conpeek(inData,2)));
}
}
progress.finalize();
progress = null;
info( strfmt("total read %1 records", int2str(j)) );
}
---------------------------
Write as CSV file
// VAR Changed on 21 April 2012 at 15:01:19 by Jimmy Xie
static void THK_csvWrite(Args _args)
{
#File
#WINAPI
#AviFiles
SysOperationProgress progress;
FileNameFilter Filter = ["CSV file", "*.csv"];
custTable custTable;
FileIOPermission permission;
FileName FileName,initFilename;
CommaIO commaIO;
container mycon;
int i;
;
initFilename = WinAPI::getFolderPath(#CSIDL_Personal) + "\\" + "init.csv";
if(Winapi::fileExists(initFilename))
winAPI::deleteFile(initFilename);
FileName = winapi::getSaveFileName(infolog.hWnd(), filter, WinAPI::getFolderPath(#CSIDL_Personal), "Save as CSV file","csv","init");
//FileName = winapi::getSaveFileName(infolog.hWnd(), filter, @"c:\...\desktop", "Save as CSV file","csv","Customer Infomation");
if(!FileName)
return ;
permission = new FileIOPermission(fileName,#io_write);
permission.assert();
commaIO = new CommaIO(FileName, #io_write);
if(!commaIO)
return;
select count(recId) from custTable;
progress = SysOperationProgress::newGeneral(#AviUpdate,"Waitting ... write CSV file",custTable.RecId);
while select custTable
{
i++;
progress.setText(strfmt("%1: %2", i, custTable.AccountNum));
commaIO.writeExp([ custTable.AccountNum,
custTable.Name,
custTable.Email,
custTable.Address,
custTable.TeleFax,
custTable.PaymTermId]
);
}
CodeAccessPermission::revertAssert();
if(WinAPI::fileExists(FileName))
Winapi::shellExecute(FileName);
info(strfmt("Total export %1 records",i));
}
没有评论:
发表评论