以前做过的一个项目,现在要求再加一个打印历史趋势的功能。
详细点说,举个例子,有一个画面,上面有趋势控件,反映实时趋势曲线,有个打印按
钮,不如今天是7月21日,我要打7月10日的,在趋势控件上是有个“时间选择”选项(
用过Wincc就知道),要求在选择时间之后,画面随之变化,之后打印当前选择的时间曲
线和数据。
我是这么做的:
第一,做布局。新建个布局,放个动态图元文件和表格上去,分别设置好,连好变量什
么的,之后就是读取时间了,读谁的时间呢,自然是趋势控件的。
代码如下:
char *aaa,*iii ;
int j ,i , slen ;
SYSTEMTIME st1,st2;
aaa=GetPropChar(lpszPictureName,"控件1","BeginTime");
SetTagChar("HELP4",aaa);
StrToSystemtime(aaa,&st1);
iii=GetPropChar(lpszPictureName,"控件1","EndTime");
SetTagChar("HELP5",iii);
StrToSystemtime(iii,&st2);
PrintRange(st1,st2,"温度趋势");
RPTJobPreview("温度趋势");
因为读到的变量是文本型,所以我转换了一下,
代码如下:
#include "apdefap.h"
void StrToSystemtime(char* aaa, SYSTEMTIME * st)
{
int j ,i , slen ;
slen = strlen( aaa) ;
j = 0 ;
for ( i = j; i< slen;i++){
if( aaa[i] == '-' ){
aaa[i] = 0x00 ;
st->wYear = atoi(aaa+j);
j = i+1 ;
break ;
}
}
for ( i = j; i< slen;i++){
if( aaa[i] == '-' ){
aaa[i]=0x00 ;
st->wMonth = atoi(aaa+j);
j = i+1 ;
break ;
}
}
for ( i = j; i< slen;i++){
if( aaa[i] == ' ' ){
aaa[i]=0x00 ;
st->wDay = atoi(aaa+j);
j = i+1 ;
break ;
}for ( i = j; i< slen;i++){
if( aaa[i] == ':' ){
aaa[i]=0x00 ;
st->wHour = atoi(aaa+j);
j = i+1 ;
break ;
}
}
for ( i = j; i< slen;i++){
if( aaa[i] == ':' ){
aaa[i]=0x00 ;
st->wMinute = atoi(aaa+j);
j = i+1 ;
break ;
}
}
}
st->wSecond = atoi(aaa+j);
}
之后是写下去,这是仿照着手册上来着,大家看手册就行。
代码如下:
BOOL PrintRange(SYSTEMTIME st1 ,SYSTEMTIME st2 , char jobname[200] )
{
BOOL fRet ;
PCMN_ERROR err_m;
HPROPERTIES hp ;
LPVOID pt1,pt2 ;
DWORD typ , dw ;
char pn1[200] ,pn2[200] ;
TCHAR tm[MAX_PATH+1] ;
typ = VT_DATE ;
strcpy( pn1 , "ABSOLUTESELECTIONFROM") ;
strcpy( pn2 , "ABSOLUTESELECTIONTO") ;
pt1 = (LPVOID)&st1 ;
pt2 = (LPVOID)&st2;
if (!DMGetRuntimeProject( tm ,MAX_PATH,err_m) ){
printf("ERROR DMGetRuntimeProjec\r\n" ) ;
return FALSE ;
}
hp=RPJCreatePropertyHandle( tm , err_m);
if (!hp ){
printf("ERROR RPJCreatePropertyHandle\r\n" ) ;
return FALSE ;
}
if (!RPJGetJobProps( hp ,jobname,err_m) ){
printf("ERROR PRJGetJobProps\r\n" ) ;
RPJDeletePropertyHandle( hp , err_m);
return FALSE ;
}
if (!RPJSetProperty( hp ,pn1,pt1, (VARTYPE)typ, 200,err_m) ){
printf("ERROR PRJSetJobProperty\r\n" ) ;
RPJDeletePropertyHandle( hp , err_m);
return FALSE ;
}
if (!RPJSetJobProps( hp ,jobname,err_m) ){
printf("ERROR RPJSetJobProps(\r\n" ) ;
RPJDeletePropertyHandle( hp , err_m);
return FALSE ;
}
if (!hp ){
printf("ERROR RPJCreatePropertyHandle\r\n" ) ;
return FALSE ;
}
if (!RPJGetJobProps( hp ,jobname,err_m) ){
printf("ERROR PRJGetJobProps\r\n" ) ;
RPJDeletePropertyHandle( hp , err_m);
return FALSE ;
}
if (!RPJSetProperty( hp ,pn2,pt2, (VARTYPE)typ, 200,err_m) ){
printf("ERROR PRJSetJobProperty\r\n" ) ;
RPJDeletePropertyHandle( hp , err_m);
return FALSE ;
}
if (!RPJSetJobProps( hp ,jobname,err_m) ){
printf("ERROR RPJSetJobProps(\r\n" ) ;
RPJDeletePropertyHandle( hp , err_m);
return FALSE ;
}
fRet = RPJDeletePropertyHandle( hp , err_m) ;
return TRUE ;
}
没有了,有问题欢迎大家讨论。