【求助】wincc 报表 点击:128 | 回复:2



寒江雪柳

    
  • 精华:0帖
  • 求助:0帖
  • 帖子:2帖 | 128回
  • 年度积分:89
  • 历史总积分:259
  • 注册:2019年1月03日
发表于:2024-05-08 11:47:22
楼主

wincc 报表求助

4

0

2024-05-08 11:33:28

    Sub OnLButtonDown(ByVal Item, ByVal Flags, ByVal x, ByVal y)                       

    Dim kj1,kj2,kj3,kj4kj5,kj6

    Dim QR

    Dim MSFlexGrid1

    Dim LocalBeginTime,LocalEndTime,riqi

    Dim oRs,oRs1,n,n1,i,z,s1,s11,oCom,oCom1,strcn,conn,pj

    Dim zxy1

    Dim Date1,Date2,BY,Bm,Bd,Ey,Em,Ed,BeginDate,EndDate

    Set MSFlexGrid1=ScreenItems("zz")

    'riqi = Now


    Set Date1 = ScreenItems("s1")

    Set Date2 = ScreenItems("s2")

    By = Year(Date1.Value)

    Bm = Month(Date1.Value)

    Bd = Day(Date1.Value)

    Ey = Year(Date2.Value)

    Em = Month(Date2.Value)

    Ed = Day(Date2.Value)

    BeginDate = By & "-" & Bm & "-" & Bd & "  " & "00:00:00"

    EndDate = Ey & "-" & Em & "-" & Ed & " " & "23:59:59"


    '日期比较

    If ( By > Ey ) Or ( By = Ey And Bm > Em ) Or ( By = Ey And Bm = Em And Bd > Ed ) Then

    MsgBox "输入的时间不正确!", vbOK, "错误的起始时间"

    End If


    'LocalBeginTime = Year(riqi) & "-" & Month(riqi) & "-" & Day(riqi) & "  " & "00:00:00"

    'LocalEndTime = Year(riqi) & "-" & Month(riqi) & "-" & Day(riqi) & "  " & "23:59:59"


    s1 = "SELECT DT,B1,B2,B3,B4,B5,B6,B7,B8,B9   FROM BIAO WHERE DT BETWEEN '" & BeginDate & "' and'" & EndDate & "'ORDER BY DT"

    s11="SELECT DT,SUM(B1)AS B1,SUM(B2)AS B2,SUM(B3)AS B3,SUM(B4)AS B4,SUM(B5)AS B5,SUM(B6)AS B6,SUM(B7)AS B7,SUM(B8)AS B8,SUM(B9)AS B9 FROM BIAO WHERE DT BETWEEN '" & BeginDate & "' and'" & EndDate & "'ORDER BY DT"

     strcn = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist SecurityInfo=False;Initial Catalog=cbc;Data Source=CZBC0423\WINCC"

       Set conn = CreateObject("ADODB.Connection")

        conn.ConnectionString = strcn

        conn.CursorLocation = 3

        conn.Open

    '使用命令文本查询

        Set oRs = CreateObject("ADODB.Recordset")

        

        Set oCom = CreateObject("ADODB.Command")

        oCom.CommandType = 1

        Set oCom.ActiveConnection = conn

        oCom.CommandText = s1

       Set oRs = oCom.Execute

       n = oRs.RecordCount'查询到的记录数目

      

     ' Set oRs1 = CreateObject("ADODB.Recordset")

         

     Set oCom1 = CreateObject("ADODB.Command")

        oCom1.CommandType = 1

        Set oCom1.ActiveConnection = conn

        oCom1.CommandText = s11

       Set oRs1

    这个是vbs按钮查询,为什么不求和呢,


    

    楼主最近还看过

    

    liuweiplc

    • 精华:0帖
    • 求助:0帖
    • 帖子:1帖 | 82回
    • 年度积分:0
    • 历史总积分:311
    • 注册:2007年5月01日
    发表于:2024-05-08 13:15:18
    1楼

    求和要将查询的数据代入变量,然后变量累加求和

    liuweiplc

    • 精华:0帖
    • 求助:0帖
    • 帖子:1帖 | 82回
    • 年度积分:0
    • 历史总积分:311
    • 注册:2007年5月01日
    发表于:2024-05-08 13:18:37
    2楼

    先连接数据库,再查询

    
    热门招聘
    相关主题

    官方公众号

    智造工程师