首页 力控(sun. 正文

回复

用力控报表功能实现显示设备启动、停止时间和运行时长的方法

力控(sunwayland) 浏览:6494 回复:12 收藏

zhongxxx  2012-04-28 15:55

之前写了一篇文章是《用组态王报表功能实现显示设备启动、停止时间和运行时长的方法》,最近闲来无事将其翻译成了力控的版本,思路都是一样的,只是脚本略有不同,希望能给需要的人以帮助。

1.建立报表

2.编写获取当前日期,时间的自定义函数

*******************************************

//Function name: GetCurrentDateTime
//Parameters:
strY=IntToStr($Year,10);
strM=IntToStr($Month, 10 );
strD=IntToStr($Day, 10 );

strH=IntToStr($Hour, 10 );
strMi=IntToStr($Minute, 10 );
strS=IntToStr($Second, 10 );

////确定日期的格式,并使长度和位置固定
if($Month<10) then  strM="0"+strM; ENDIF
if($Day<10) then strD="0"+strD;  ENDIF
if($Hour<10) then strH="0"+strH; ENDIF
if($Minute<10) then strMi="0"+strMi; ENDIF
if($Second<10) then strS="0"+strS; ENDIF

//组合,定义格式
RETURN strY+"/"+strM+"/"+strD+" "+strH+":"+strMi+":"+strS;

***************************************************************

3.编写填充报表的自定义函数

**********************************************

//启动设备时,将“序号”、“名称”、“启动时间”填充到报表中
strDate=GetCurrentDateTime();

if(var==1) then
num=currentRow-2;
id=IntToStr(num, 10 );

#DRAW1.#ReportHis.SetCellString(-1,currentRow,1,id,1);//序号
#DRAW1.#ReportHis.SetCellString(-1,currentRow,2,text,1);//名称
#DRAW1.#ReportHis.SetCellString(-1,currentRow,3,strDate,1);//开始时间

row=currentRow;//所在行=报表当前行
currentRow=currentRow+1;
   //停止设备时
else
startStr=#DRAW1.#ReportHis.GetCellString(-1,row,3);

startTime=LongTime(startStr);
endTime=LongTime(strDate);
////计算时间差
timeLength=endTime-startTime;//单位秒
////秒转换为小时
endStr=IntToStr( timeLength, 10 )+"秒";
////将“停止时间”和“运行时长”填充到报表中
#DRAW1.#ReportHis.SetCellString(-1,row,4,strDate,1);
#DRAW1.#ReportHis.SetCellString(-1,row,5,endStr,1);
endif

************************************************************

4.脚本中用到的中间变量

5.在数据改变动作中,引用自定义函数。

6.运行


我知道了