01)using TextBuffer class handle
//1,使用TextBuffer从Ax 2009中导出数据到CSV文件中:
//http://www.qiuhao.com/forum-redirect-tid-13763-goto-lastpost.html#lastpost
static void Jimmy_ExportToCSVFile01(Args _args)
{
TextBuffer textBuffer = new TextBuffer();
InventTable inventTable;
FileIoPermission perm;
counter Lines;
#define.ExampleFile(@"c:\test.csv")
#define.ExampleOpenMode("W")
;
try
{
// Set code access permission to help protect the use of
perm = new FileIoPermission(#ExampleFile, #ExampleOpenMode);
perm.assert();
textBuffer.appendText("Item Id,");//must be "," suffix
textBuffer.appendText("Item Name,");//must be "," suffix
textBuffer.appendText("Item Type");
textBuffer.appendText("\n");//next line must be "\n" suffix
while select InventTable
where inventTable.ItemType == ItemType::BOM
&& inventTable.ItemId like "10*"
{
textBuffer.appendText(strfmt("%1,",inventTable.ItemId));
textBuffer.appendText(strfmt("%1,",global::strReplace(inventTable.ItemName,",","")));//must be repace "," to ""
textBuffer.appendText(enum2str(inventTable.ItemType));
textBuffer.appendText("\n");
}
Lines = textBuffer.numLines();
try
{
if (textBuffer.toFile(#ExampleFile))
info( strfmt("File Generated as %1.total insert %2 Lines",#ExampleFile,Lines));
}
catch ( Exception::Error )
{
error ("Generated file error.");
}
// Close the code access permission scope.
CodeAccessPermission::revertAssert();
}
catch (Exception::Deadlock)
{
retry;
}
}
//http://www.qiuhao.com/forum-redirect-tid-13763-goto-lastpost.html#lastpost
static void Jimmy_ExportToCSVFile01(Args _args)
{
TextBuffer textBuffer = new TextBuffer();
InventTable inventTable;
FileIoPermission perm;
counter Lines;
#define.ExampleFile(@"c:\test.csv")
#define.ExampleOpenMode("W")
;
try
{
// Set code access permission to help protect the use of
perm = new FileIoPermission(#ExampleFile, #ExampleOpenMode);
perm.assert();
textBuffer.appendText("Item Id,");//must be "," suffix
textBuffer.appendText("Item Name,");//must be "," suffix
textBuffer.appendText("Item Type");
textBuffer.appendText("\n");//next line must be "\n" suffix
while select InventTable
where inventTable.ItemType == ItemType::BOM
&& inventTable.ItemId like "10*"
{
textBuffer.appendText(strfmt("%1,",inventTable.ItemId));
textBuffer.appendText(strfmt("%1,",global::strReplace(inventTable.ItemName,",","")));//must be repace "," to ""
textBuffer.appendText(enum2str(inventTable.ItemType));
textBuffer.appendText("\n");
}
Lines = textBuffer.numLines();
try
{
if (textBuffer.toFile(#ExampleFile))
info( strfmt("File Generated as %1.total insert %2 Lines",#ExampleFile,Lines));
}
catch ( Exception::Error )
{
error ("Generated file error.");
}
// Close the code access permission scope.
CodeAccessPermission::revertAssert();
}
catch (Exception::Deadlock)
{
retry;
}
}