组态王报表通过日历控件查询数据库(报表,日历控件,数据库)

360影视 欧美动漫 2025-05-14 21:10 1

摘要:float Ayear1;float Amonth1;float Aday1;string temp1;Ayear1=AD1.Year;Amonth1=AD1.Month;Aday1=AD1.Day;temp1=StrFromInt( Ayear1, 10 )

1.功能介绍

本文档讲解报表通过日历控件查询数据库。

1.1运行效果


1.3 环境说明

本例程测试环境是win10专业版系统,使用软件是Kingview7.5sp6。

2.功能实现过程

2.1 建立变量

在数据词典中新建如下变量,具体参数如图2.1

图2.1

2.2 添加ODBC数据源

在电脑开始菜单搜索“cmd”,以管理员身份运行32位odbc数据源,在“系统DSN”中建立数据源,关联数据库。

图2.3.1

2.3 建立记录体和表格模版

图2.3.1

2.4 新建1.亚控开始日期控件,控件事件写入脚本

脚本内容:

float Ayear1;float Amonth1;float Aday1;string temp1;Ayear1=AD1.Year;Amonth1=AD1.Month;Aday1=AD1.Day;temp1=StrFromInt( Ayear1, 10 );if(Amonth1temp1=temp1+"-0"+StrFromInt( Amonth1, 10 );elsetemp1=temp1+"-"+StrFromInt( Amonth1, 10 );if(Aday1temp1=temp1+"-0"+StrFromInt( Aday1, 10 );elsetemp1=temp1+"-"+StrFromInt( Aday1, 10 );\\local\开始日期=temp1;


复制代码

2.建立亚控开始时间控件,控件事件写入脚本

本内容

float AHour1;float AMinute1;float ASecond1;string a;AHour1=AT1.Hour;AMinute1=AT1.Minute;ASecond1=AT1.Second;//temp11=StrFromInt( AHour1, 10 )+":"+StrFromInt( AMinute1, 10 )+":"+StrFromInt(AMinute1, 10 ); //不进行补0拼接//时间判断补0if(AHour1a="0"+StrFromInt( AHour1, 10 );elsea=""+StrFromInt( AHour1, 10 );if(AMinute1a=a+":0"+StrFromInt( AMinute1, 10 );elsea=a+":"+StrFromInt( AMinute1, 10 );if(ASecond1a=a+":0"+StrFromInt( ASecond1, 10 );elsea=a+":"+StrFromInt( ASecond1, 10 );\\local\开始时间=a;


复制代码

3.建立结束日期控件,控件事件写入脚本,如下图所示:

脚本内容:

float Ayear2;float Amonth2;float Aday2;string temp2;Ayear2=AD2.Year;Amonth2=AD2.Month;Aday2=AD2.Day;temp2=StrFromInt( Ayear2, 10 );if(Amonth2temp2=temp2+"-0"+StrFromInt( Amonth2, 10 );elsetemp2=temp2+"-"+StrFromInt( Amonth2, 10 );if(Aday2temp2=temp2+"-0"+StrFromInt( Aday2, 10 );elsetemp2=temp2+"-"+StrFromInt( Aday2, 10 );\\local\结束日期=temp2;


复制代码

4.建立亚控结束时间控件,控件事件写入脚本,如下图所示:

脚本内容:

float AHour2;float AMinute2;float ASecond2;string a;AHour2=AT2.Hour;AMinute2=AT2.Minute;ASecond2=AT2.Second;//temp22=StrFromInt( AHour2, 10 )+":0"+StrFromInt( AMinute2, 10 )+":0"+StrFromInt(ASecond2, 10 );if(AHour2a="0"+StrFromInt( AHour2, 10 );elsea=""+StrFromInt( AHour2, 10 );if(AMinute2a=a+":0"+StrFromInt( AMinute2, 10 );elsea=a+":"+StrFromInt( AMinute2, 10 );if(ASecond2a=a+":0"+StrFromInt( ASecond2, 10 );elsea=a+":"+StrFromInt( ASecond2, 10 );\\local\结束时间=a;


复制代码

5.建立查询按钮,在弹起时写入查询脚本,如下图所示:

脚本内容:

long hang;long renum;long nRow;string whe1;string whe2;string whe3;whe1=\\local\开始日期+" "+\\local\开始时间;whe2=\\local\结束日期+" "+\\local\结束时间;whe3="日期时间 >= #"+whe1+"# AND 日期时间 SQLSelect( DeviceID, "Kingview", "查询记录", whe3, "" );renum=SQLNumRows( DeviceID );SQLFirst(DeviceID);hang=renum+1;//行数 表头是多少此处应该加多少。ReportSetRows("表1", hang);nRow =2; //插入的起始行while(renum>0) //while是循环执行操作{//操作员ReportSetCellString("表1", nRow, 1,\\local\查询日期时间);ReportSetCellValue2("表1", nRow , 2, hang, 2,\\local\查询液位); //表是控件的名称 nRow是起始行,1是起始列ReportSetCellValue2("表1", nRow , 3, hang, 3,\\local\查询压力);ReportSetCellValue2("表1", nRow , 4, hang, 4,\\local\查询流量);SQLNext(DeviceID);renum=renum-1;nRow = nRow +1;}SQLEndSelect( DeviceID );
复制代码

6.建立微软开始日历日期控件,控件事件写入脚本,如下图所示:

本内容:

float Ayear3;float Amonth3;float Aday3;string temp3;Ayear3=D1.Year;Amonth3=D1.Month;Aday3=D1.Day;temp3=StrFromInt( Ayear3, 10 );if(Amonth3temp3=temp3+"-0"+StrFromInt( Amonth3, 10 );elsetemp3=temp3+"-"+StrFromInt( Amonth3, 10 );if(Aday3temp3=temp3+"-0"+StrFromInt( Aday3, 10 );elsetemp3=temp3+"-"+StrFromInt( Aday3, 10 );\\local\开始日期=temp3;


复制代码

7.建立微软日历时间控件,控件事件写入脚本,如下图所示:

脚本内容:

float AHour3;float AMinute3;float ASecond3;string temp31;AHour3=D2.Hour;AMinute3=D2.Minute;ASecond3=D2.Second;if(AHour3temp31="0"+StrFromInt( AHour3, 10 );elsetemp31=""+StrFromInt( AHour3, 10 );if(AMinute3temp31=temp31+":0"+StrFromInt( AMinute3, 10 );elsetemp31=temp31+":"+StrFromInt( AMinute3, 10 );if(ASecond3temp31=temp31+":0"+StrFromInt( ASecond3, 10 );elsetemp31=temp31+":"+StrFromInt( ASecond3, 10 );//temp31=StrFromInt( AHour3, 10 )+":"+StrFromInt( AMinute3, 10 )+":"+StrFromInt(AMinute3, 10 );\\local\开始时间=temp31;


复制代码

8.建立微软日历结束日期控件,控件事件写入脚本,如下图所示:

脚本内容:

float Ayear4;float Amonth4;float Aday4;string temp4;Ayear4=D3.Year;Amonth4=D3.Month;Aday4=D3.Day;temp4=StrFromInt( Ayear4, 10 );if(Amonth4temp4=temp4+"-0"+StrFromInt( Amonth4, 10 );elsetemp4=temp4+"-"+StrFromInt( Amonth4, 10 );if(Aday4temp4=temp4+"-0"+StrFromInt( Aday4, 10 );elsetemp4=temp4+"-"+StrFromInt( Aday4, 10 );\\local\结束日期=temp4;


复制代码

9.建立微软日历结束时间控件,控件事件写入脚本,如下图所示:

脚本内容:

float AHour4;float AMinute4;float ASecond4;string temp41;AHour4=D4.Hour;AMinute4=D4.Minute;ASecond4=D4.Second;if(AHour4temp41="0"+StrFromInt( AHour4, 10 );elsetemp41=""+StrFromInt( AHour4, 10 );if(AMinute4temp41=temp41+":0"+StrFromInt( AMinute4, 10 );elsetemp41=temp41+":"+StrFromInt( AMinute4, 10 );if(ASecond4temp41=temp41+":0"+StrFromInt( ASecond4, 10 );elsetemp41=temp41+":"+StrFromInt( ASecond4, 10 );//temp31=StrFromInt( AHour3, 10 )+":"+StrFromInt( AMinute3, 10 )+":"+StrFromInt(AMinute3, 10 );\\local\结束时间=temp41;


复制代码

10.建立查询按钮,弹起时写入脚本

脚本内容:

long hang;long renum;long nRow;string whe1;string whe2;string whe3;whe1=\\local\开始日期+" "+\\local\开始时间;whe2=\\local\结束日期+" "+\\local\结束时间;whe3="日期时间 >= #"+whe1+"# AND 日期时间 Trace('test = %2s', whe3);SQLSelect( DeviceID, "Kingview", "查询记录", whe3, "" );renum=SQLNumRows( DeviceID );SQLFirst(DeviceID);hang=renum+1;//行数 表头是多少此处应该加多少。ReportSetRows("表1", hang);nRow =2; //插入的起始行while(renum>0) //while是循环执行操作{//操作员ReportSetCellString("表1", nRow, 1,\\local\查询日期时间);ReportSetCellValue2("表1", nRow , 2, hang, 2,\\local\查询液位); //表是控件的名称 nRow是起始行,1是起始列ReportSetCellValue2("表1", nRow , 3, hang, 3,\\local\查询压力);ReportSetCellValue2("表1", nRow , 4, hang, 4,\\local\查询流量);SQLNext(DeviceID);renum=renum-1;nRow = nRow +1;}SQLEndSelect( DeviceID );


复制代码

11.变量做模拟值输出

12.连接按钮里写入数据库连接脚本

13.建表按钮写入脚本,用来创建数据库表格

14.插入按钮弹起时写入脚本,用来数据库插入数据

15.新建ADO控件,右键控件属性,关联数据源

16.ADO控件全查询按钮弹起时写入脚本

3.运行和调试

进入运行系统,运行界面如图

工控人加入PLC工业自动化精英社群

西门子wincc提示缺少Audit RC/RT授权

西门子S7-400H MODBUS通讯

经典版WINCC、SQLserver数据库和Excel表格的数据交互

基于FactoryTalk View Studio和AB_CompactLogix中型PLC无线通讯方案

巨控GRM230自带IO液位远程联动水泵行业应用

基于巨控GRM230酒店高位水箱远程监控系统

基于巨控GRM560西门子1200PLC发邮件

AB PLC和西门子PLC之间需要交换数据

基于intouch和巨控GRM530的PLC无线通讯方案

巨控GRM530模块在污水泵站中的应用

WINCC 本地连接 巨控GRM300网关连接PLC和仪表

巨控GRM530实现PLC远程下载远程维护

巨控GRM530杀菌信息云存储及云检视技术创新改善

广州巨控远程模块在新能源生产项目的应用

记录一个巨控GRM532跨国沙特远程调试西门子1200PLC案例

AB1756PLC通过协议网关巨控GRM300读取多个MODBUS 仪表

西门子S7-1500双冗余巨控GRM530实现工业联网通讯

西门子1500PLC连接64个仪表巨控GRM300网关数据交互

石化工厂100个485仪表10KM通讯上位机组态IFIX

巨控GRM600通过OPCUA客户端协议访问WINCC7.5OPCUA服务器

巨控GRM600系列标准OPCUAserver协议链接UaExpert

巨控GRM560系列标准OPCUA客户端协议访问西门子1200PLC

巨控GRM230在辽油工区电锅炉远程平台的应用

intouch的报警怎么发到短信/微信上

巨控GRM530在制药企业质量管理中的应用

工控人加入PLC工业自动化精英社群

巨控科技NET400推出多网段通讯协议网关

西门子WINCC8.1带确认的输入/输出域

不用在PLC内编程,实现西门子与罗克韦尔(AB)PLC之间数据通讯

来源:微言教育资讯

相关推荐