百度360必应搜狗淘宝本站头条
当前位置:网站首页 > IT技术 > 正文

上位机外挂报表第3课---完结篇(上位机软件安装与使用方法)

wptr33 2025-04-06 22:15 19 浏览

前面2课叙述了如何准备数据---将数据写入数据库,如何查询、导出和打印日报表。

对于月报表、年报表的操作其实同日报表一样,只是需要做一个系统后台程序,将数据库的每天/每月的数据进行计算,然后写入数据库的月表单和年表单即可。

对于月报表和日报表的界面可以参考设计如下:

对于后台运行程序设计代码如下:

Const g_conString = " Provider=MSDASQL.1;Persist Security Info=False;Data Source=SQL_KEP;Initial Catalog=SQL_KEP" '链接数据库

Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long

Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long

Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long

Dim g_where As String

Dim g_where2 As String

Dim g_startDate As String

Dim g_mou As Boolean

Dim zou As Boolean

Dim yue As Boolean

Private Sub dayreport(i As Integer) '月报表数据

Dim strsql

Dim cn As ADODB.Connection

Dim record As ADODB.Recordset

Set cn = New ADODB.Connection

cn.Open g_conString


Set record = New ADODB.Recordset

st = Str(Date)

g_where = "tt>='" + Str(DateAdd("d", -1, st)) + " 0:20:0' and tt<='" + st + " 0:30:50'"

strsql = "select avg(t1),avg(t2),avg(t3),avg(t4),avg(t5),avg(t6),avg(t7),avg(t8),avg(t9),avg(t10),avg(t11),avg(t12),avg(t13),avg(t14),avg(t15),avg(t16),avg(t17),avg(t18) from tt1 where " + g_where

'计算本月的平均值插入tt2

record.Open strsql, cn

If record.EOF = False Then

V1 = Format(record.Fields(0).Value, "0.00")

V2 = Format(record.Fields(1).Value, "0.00")

V3 = Format(record.Fields(2).Value, "0.00")

V4 = Format(record.Fields(3).Value, "0.00")

V5 = Format(record.Fields(4).Value, "0.00")

V6 = Format(record.Fields(5).Value, "0.00")

V7 = Format(record.Fields(6).Value, "0.00")

V8 = Format(record.Fields(7).Value, "0.00")

V9 = Format(record.Fields(8).Value, "0.00")

V10 = Format(record.Fields(9).Value, "0.00")

V11 = Format(record.Fields(10).Value, "0.00")

V12 = Format(record.Fields(11).Value, "0.00")

V13 = Format(record.Fields(12).Value, "0.00")

V14 = Format(record.Fields(13).Value, "0.00")

V15 = Format(record.Fields(14).Value, "0.00")

V16 = Format(record.Fields(15).Value, "0.00")

V17 = Format(record.Fields(16).Value, "0.00")

V18 = Format(record.Fields(17).Value, "0.00")

End If

Set record = Nothing

Set record = New ADODB.Recordset

strsql = "insert INTO tt2 (tt,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13,t14,t15,t16,t17,t18 ) VALUES ('" + Str(DateAdd("d", -1, st)) + "','" + V1 + "','" + V2 + "','" + V3 + "','" + V4 + "','" + V5 + "','" + V6 + "','" + V7 + "','" + V8 + "','" + V9 + "','" + V10 + "','" + V11 + "','" + V12 + "','" + V13 + "','" + V14 + "','" + V15 + "','" + V16 + "','" + V17 + "','" + V18 + "')"


'MsgBox strsql

record.Open strsql, cn


'record.Close

Set record = Nothing

cn.Close

Set cn = Nothing


End Sub


Private Sub moureport(i As Integer) '年报表


Dim strsql

Dim cn As ADODB.Connection

Dim record As ADODB.Recordset

Set cn = New ADODB.Connection

cn.Open g_conString


Set record = New ADODB.Recordset

st = Str(Date)

g_where = "tt>='" + Str(DateAdd("m", -1, st)) + " 0:0:0' and tt<='" + st + " 0:30:50'"


strsql = "select avg(t1),avg(t2),avg(t3),avg(t4),avg(t5),avg(t6),avg(t7),avg(t8),avg(t9),avg(t10),avg(t11),avg(t12),avg(t13),avg(t14),avg(t15) ,avg(t16),avg(t17),avg(t18)from tt2 where " + g_where

'计算本年月度平均值插入到tt3

record.Open strsql, cn


If record.EOF = False Then

V1 = Format(record.Fields(0).Value, "0.00")

V2 = Format(record.Fields(1).Value, "0.00")

V3 = Format(record.Fields(2).Value, "0.00")

V4 = Format(record.Fields(3).Value, "0.00")

V5 = Format(record.Fields(4).Value, "0.00")

V6 = Format(record.Fields(5).Value, "0.00")

V7 = Format(record.Fields(6).Value, "0.00")

V8 = Format(record.Fields(7).Value, "0.00")

V9 = Format(record.Fields(8).Value, "0.00")

V10 = Format(record.Fields(9).Value, "0.00")

V11 = Format(record.Fields(10).Value, "0.00")

V12 = Format(record.Fields(11).Value, "0.00")

V13 = Format(record.Fields(12).Value, "0.00")

V14 = Format(record.Fields(13).Value, "0.00")

V15 = Format(record.Fields(14).Value, "0.00")

V16 = Format(record.Fields(15).Value, "0.00")

V17 = Format(record.Fields(16).Value, "0.00")

V18 = Format(record.Fields(17).Value, "0.00")

End If

Set record = Nothing

Set record = New ADODB.Recordset



strsql = "insert INTO tt3 (tt,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13,t14,t15,t16,t17,t18 ) VALUES ('" + Str(DateAdd("d", -1, st)) + "','" + V1 + "','" + V2 + "','" + V3 + "','" + V4 + "','" + V5 + "','" + V6 + "','" + V7 + "','" + V8 + "','" + V9 + "','" + V10 + "','" + V11 + "','" + V12 + "','" + V13 + "','" + V14 + "','" + V15 + "','" + V16 + "','" + V17 + "','" + V18 + "')"

'MsgBox strsql

record.Open strsql, cn

'record.Close

Set record = Nothing

cn.Close

Set cn = Nothing

End Sub


Private Sub Timer1_Timer()

If Hour(Now()) = 0 And g_mou = False Then

dayreport (1) '调用月报表插入数据

g_mou = True

End If


If Hour(Now()) = 0 And Day(Now()) = 1 And yue = False Then

moureport (1) '调用年报表插入数据

yue = True

End If


If Hour(Now()) > 0 Then

g_mou = False

yue = False

zou = False

End If

End Sub


收录于合集 #数据库

5个

上一篇基于物联网关OPC软件采集数据并存入数据库下一篇上位机外挂报表第2课--日报表设计

相关推荐

redis的八种使用场景

前言:redis是我们工作开发中,经常要打交道的,下面对redis的使用场景做总结介绍也是对redis举报的功能做梳理。缓存Redis最常见的用途是作为缓存,用于加速应用程序的响应速度。...

基于Redis的3种分布式ID生成策略

在分布式系统设计中,全局唯一ID是一个基础而关键的组件。随着业务规模扩大和系统架构向微服务演进,传统的单机自增ID已无法满足需求。高并发、高可用的分布式ID生成方案成为构建可靠分布式系统的必要条件。R...

基于OpenWrt系统路由器的模式切换与网页设计

摘要:目前商用WiFi路由器已应用到多个领域,商家通过给用户提供一个稳定免费WiFi热点达到吸引客户、提升服务的目标。传统路由器自带的Luci界面提供了工厂模式的Web界面,用户可通过该界面配置路...

这篇文章教你看明白 nginx-ingress 控制器

主机nginx一般nginx做主机反向代理(网关)有以下配置...

如何用redis实现注册中心

一句话总结使用Redis实现注册中心:服务注册...

爱可可老师24小时热门分享(2020.5.10)

No1.看自己以前写的代码是种什么体验?No2.DooM-chip!国外网友SylvainLefebvre自制的无CPU、无操作码、无指令计数器...No3.我认为CS学位可以更好,如...

Apportable:拯救程序员,IOS一秒变安卓

摘要:还在为了跨平台使用cocos2d-x吗,拯救objc程序员的奇葩来了,ApportableSDK:FreeAndroidsupportforcocos2d-iPhone。App...

JAVA实现超买超卖方案汇总,那个最适合你,一篇文章彻底讲透

以下是几种Java实现超买超卖问题的核心解决方案及代码示例,针对高并发场景下的库存扣减问题:方案一:Redis原子操作+Lua脚本(推荐)//使用Redis+Lua保证原子性publicbo...

3月26日更新 快速施法自动施法可独立设置

2016年3月26日DOTA2有一个79.6MB的更新主要是针对自动施法和快速施法的调整本来内容不多不少朋友都有自动施法和快速施法的困扰英文更新日志一些视觉BUG修复就不翻译了主要翻译自动施...

Redis 是如何提供服务的

在刚刚接触Redis的时候,最想要知道的是一个’setnameJhon’命令到达Redis服务器的时候,它是如何返回’OK’的?里面命令处理的流程如何,具体细节怎么样?你一定有问过自己...

lua _G、_VERSION使用

到这里我们已经把lua基础库中的函数介绍完了,除了函数外基础库中还有两个常量,一个是_G,另一个是_VERSION。_G是基础库本身,指向自己,这个变量很有意思,可以无限引用自己,最后得到的还是自己,...

China&#39;s top diplomat to chair third China-Pacific Island countries foreign ministers&#39; meeting

BEIJING,May21(Xinhua)--ChineseForeignMinisterWangYi,alsoamemberofthePoliticalBureau...

移动工作交流工具Lua推出Insights数据分析产品

Lua是一个适用于各种职业人士的移动交流平台,它在今天推出了一项叫做Insights的全新功能。Insights是一个数据平台,客户可以在上面实时看到员工之间的交流情况,并分析这些情况对公司发展的影响...

Redis 7新武器:用Redis Stack实现向量搜索的极限压测

当传统关系型数据库还在为向量相似度搜索的性能挣扎时,Redis7的RedisStack...

Nginx/OpenResty详解,Nginx Lua编程,重定向与内部子请求

重定向与内部子请求Nginx的rewrite指令不仅可以在Nginx内部的server、location之间进行跳转,还可以进行外部链接的重定向。通过ngx_lua模块的Lua函数除了能实现Nginx...