此为Excel导入原文https://maryd.cn/?id=81,需要的数据可在此文章中下载
在导入Excel的情况下增加进度条,具体看注释部分
do while需要注意的是while的判断条件要在do中变化
static void ImportFromExcel(Args _args)
{
#AviFiles
Dialog _dialog;
DialogField _file;
//进度条
SysOperationProgress _progress;
SysExcelApplication application;
SysExcelWorkbooks workbooks;
SysExcelWorkbook workbook;
SysExcelWorksheets worksheets;
SysExcelWorksheet worksheet;
SysExcelCells cells;
COMVariantType type;
Name name;
FileName filename;
ImportTable importTable; //Declaring Table Name
int row = 1,m_total = 2;
str _itemid;
real _qty;
real _price;
str _purchunit;
real _lineamount;
_dialog = new Dialog("Please select the file to load");
_dialog.addText("Select file:");
_file = _dialog.addField(ExtendedTypeStr("FilenameOpen"));
_dialog.run();
if (_dialog.closedOK())
{
info(_file.value() );
application = SysExcelApplication::construct();
workbooks = application.workbooks();
//specify the file path that you want to read
filename =_file.value(); //ExcelSheet File Name
try
{
workbooks.open(filename);
}
catch (Exception::Error)
{
throw error('File cannot be opened');
}
workbook = workbooks.item(1);
worksheets = workbook.worksheets();
worksheet = worksheets.itemFromNum(1); //Here 1 is the worksheet Number
cells = worksheet.cells();
//add 注解的do while或While获取Excel数据是否为空,直到数据为空,统计总数据m_total++,其中do内包含while的判断条件
type = cells.item(row + 1,1).value().variantType();
// do
// {
// m_total++;
// type = cells.item(m_total + 1,1).value().variantType();
// }
//while (type != COMVariantType::VT_EMPTY);
//info(strFmt("%1",m_total));
while(type != COMVariantType::VT_EMPTY)
{
m_total++;
type = cells.item(m_total + 1,1).value().variantType();
}
//进度条界面,newGeneral(界面格式,显示内容,数据总条数)
_progress = SysOperationProgress::newGeneral(#AviUpdate,"测试导入。。。",m_total-2);
do
{
row++;
_itemid = cells.item(row, 1).value().bStr();
_qty = cells.item(row, 2).value().double();
_price = cells.item(row, 3).value().double();
_purchunit = cells.item(row, 4).value().bStr();
_lineamount = cells.item(row, 5).value().double();
//动态显示百分比%1和当前数据%2
_progress.setText(strFmt("进行中:%1%,%2",row/(m_total-2)*100,cells.item(row, 1).value().bStr()));
//整条为百分百则,单格增长为百分之1(个人理解),或用_progress.setCount(row)当前到的第几条数据
_progress.incCount(1);
//_progress.setCount(row);
importTable.ItemId = _itemid;
importTable.Qty = _qty;
importTable.Price = _price;
importTable.PurchUnit = _purchunit;
importTable.LineAmount = _lineamount;
importTable.insert();
type = cells.item(row+1, 1).value().variantType();
}
while (type != COMVariantType::VT_EMPTY);
application.quit();
info("Data is Imported");
}
}How to: Create Progress Indicators
AX官方文档地址:
https://docs.microsoft.com/en-us/dynamicsax-2012/developer/how-to-create-progress-indicators
示例:显示沙漏指针
下面的示例重写在窗体控件上单击的方法以刷新数据库日志。
void clicked()
{
super();
startLengthyOperation();
sysDatabaseLog_ds.research();
endLengthyOperation();
}显示进度条
初始化SysOperationProgress变量。
通过使用SysOperationProgress.setCaption方法设置表单的标题。
使用SysOperationProgress.setAnimation方法将动画设置为在操作进行时运行。
Microsoft Dynamics AX提供了许多动画。要查看它们,请运行Tutorial_ShowAVIFiles类。如果使用这些动画文件之一,则需要在代码顶部声明AviFiles宏。
指定操作步骤的总数。
这对于剩余时间计算是必需的。如果您未设置操作步骤总数,则不会显示进度指示器。总数通常是记录数量的计数,并且可能很耗时。如果计算记录所花费的时间与操作所花费的总时间相当,则不要指定总计。
执行操作。对于每个步骤,请指定说明和步骤编号。例如:
for (i = 1; i <= 100; i++)
{
progress.setText(strfmt("Step %1", i));
progress.incCount();
}该描述必须简短且内容丰富,因为在执行过程中它可能会快速更改。
作为incCount()的替代方法,可以使用setCount(int i)。
在执行期间,进度指示器将相应更新。计算并显示估计的剩余时间。
默认更新间隔为3秒。如果由于网络连接上的延迟而导致更新显示器的任务花费了更新间隔的10%以上,则更新间隔将增加1秒。
示例:使用单个进度指示器
static void operationProgress(Args _args)
{
#AviFiles
SysOperationProgress progress = new SysOperationProgress();
int i;
;
progress.setCaption("My Task");
progress.setAnimation(#AviUpdate);
progress.setTotal(30000);
for (i = 1; i <= 30000; i++)
{
progress.setText(strfmt("Step %1", i));
progress.setCount(i, 1);
}
}使用不止一个进度指示器
如果您执行的操作更为复杂,则可以有多个进度指示器。前面介绍的所有方法均具有默认参数,该默认参数指示正在引用哪个进度指示器(或条)。
注意:剩余时间的计算仅在第一个小节上进行。第一栏必须始终显示整体进度。
示例:使用三个进度指示器
static void SysOperationProgress(Args _args)
{
#define.count1(10)
#define.count2(5)
#define.count3(200)
#AviFiles
// 3 bars.
SysOperationProgress progress = new SysOperationProgress(3);
int i, j, k;
;
progress.setCaption("My Task");
progress.setAnimation(#AviUpdate);
// Bar 1.
progress.setTotal(#count1, 1);
// Bar 2.
progress.setTotal(#count2, 2);
// Bar 3.
progress.setTotal(#count3, 3);
for (i=0; i<#count1; i++)
{
// Bar 1.
progress.setText(strfmt("Bar 1 - Step %1 of %2", i, #count1), 1);
progress.setCount(i, 1);
for (j=0; j<#count2; j++)
{
// Bar 2.
progress.setText(strfmt("Bar 2 - Step %1 of %2", j, #count2), 2);
progress.setCount(j, 2);
for (k=0; k<#count3; k++)
{
// Bar 3.
progress.setText(
strfmt("Bar 3 - Step %1 of %2", k, #count3), 3);
progress.setCount(k, 3);
sleep(20); // Time-consuming task.
}
}
}
}操作过程中的用户输入
以下是在操作过程中用户输入的进度指示器选项:
SysOperationProgress.hide –隐藏进度表并暂停剩余时间的计算。随后调用setCount,incCount或setText时,进度指示器将重新出现。
SysOperationProgress.kill –终止进度表,然后再次启动进度。您不必重置字幕,动画和总计。
将进度指示器与Runbase框架一起使用
Runbase是作业执行的标准框架,并且必须具有进度指示器。在标准应用程序中,大多数进度指示器都来自RunBase框架。
使用RunBase.progressInit方法初始化进度指示器:
public void progressInit( str caption, int total, Filename animation, int updateInterval = 1, int numOfBars = 1)
指示实际操作过程中的进度与标准“操作进度”框架相似。使用成员变量progress:
progress.incCount();
如果您有多个进度条,请使用RunBase中定义的progress变量。它指向在progressInit方法中初始化的Progress类。例如:
{
this.progressInit("Caption",10,#AviFileCopy,1,2);
progress.setCount(bar1count);
progress.setTotal(maxBar2Count,bar2count);
...
...
progress.setCount(bar2count,2);
}



留言评论
暂无留言