• 【报表】一个在自己本机测试运行通过的RS脚本


    代码
    Dim pUser             As String = ""
    Dim pPwd              As String = ""
    Dim pParentFolder     As String = "PR"
    Dim pFilePath         As String = "C:\Users\BruceWoo\Desktop\Reports\"
    Dim pDataSourceName   As String = "DataSourcePR"
    Dim pConnectionString As String = "Data Source=(local);Initial Catalog=PR"
    Dim files(0 to 0As FileInfo
    Dim mDefinition As [Byte]() = Nothing
    Dim mWarnings As Warning() = Nothing
    Dim mParentPath As String = "/" + pParentFolder

    Public Sub Main()
        rs.Credentials 
    = System.Net.CredentialCache.DefaultCredentials
        
    Dim name As String
        
    Dim items As CatalogItem() = Nothing
        
    Dim folderExist, dataSourceExist As Boolean

        
    '列举PR根目录下所有项,判断目标目录是否已存在
        Try
            items 
    = rs.ListChildren("/"True)
            
    Dim i As Integer
            
    For i = 0 To items.length - 1
                
    If items(i).name.toUpper = pParentFolder.toUpper And items(i).Type = 1 Then '1 standfor Folder
                    folderExist = True
                
    End If
                
    If items(i).name.toUpper = pParentFolder.toUpper And items(i).Type = 5 Then '5 standfor DataSource
                    dataSourceExist = True
                
    End If
            
    Next
        
    Catch e As SoapException
            Console.WriteLine(e.Detail.InnerXml.ToString())
        
    End Try

        
    '创建目标目录
        If folderExist Then
            Console.WriteLine(
    "FOLDER EXISTED!")
        
    Else
            
    Try
                rs.CreateFolder(pParentFolder, 
    "/"Nothing)
                Console.WriteLine(
    "FOLDER:{0} CREATED SUCCESSFULLY!", pParentFolder)
            
    Catch e As Exception
                Console.WriteLine(e.Message)
            
    End Try
        
    End If

        
    '创建数据源
        If folderExist And dataSourceExist Then
            Console.WriteLine(
    "DATA SOURCE EXISTED!")
        
    Else
            CreateDataSource()
        
    End If

        
    Try
            
    Dim di As DirectoryInfo
            
    'If pFilePath = "" Then di = New DirectoryInfo(".") Else di = New DirectoryInfo(pFilePath)

    files(
    0= New FileInfo("C:\Users\BW\Desktop\Reports\RLS.rdl")

            Console.WriteLine(
    "TOTAL REPORT FILES: {0}", files.Length)
            
    Dim fiNext As FileInfo
            
    For Each fiNext In files
                
    '部署报表
                DeployReport(Microsoft.VisualBasic.Left(fiNext.name, fiNext.name.length - 4))
            
    Next
        
    Catch e As Exception
            Console.WriteLine(e.ToString())
        
    End Try
    End Sub

    ' Func: 创建数据源
    Public Sub CreateDataSource()
        
    Dim name As String = pDataSourceName
        
    Dim parent As String = "/" + pParentFolder

        
    Dim mDefinition As New DataSourceDefinition()

        
    If pUser <> "" And pPwd <> "" Then
            mDefinition.CredentialRetrieval 
    = CredentialRetrievalEnum.Store
            mDefinition.UserName 
    = pUser
            mDefinition.Password 
    = pPwd
        
    Else
            mDefinition.CredentialRetrieval 
    = CredentialRetrievalEnum.Integrated
        
    End If
        
        mDefinition.ConnectString 
    = pConnectionString
        mDefinition.Enabled 
    = True
        mDefinition.EnabledSpecified 
    = True
        mDefinition.Extension 
    = "SQL"
        mDefinition.ImpersonateUser 
    = False
        mDefinition.ImpersonateUserSpecified 
    = True
        mDefinition.Prompt 
    = Nothing
        mDefinition.WindowsCredentials 
    = False

        
    Try
            rs.CreateDataSource(name, parent, 
    True, mDefinition, Nothing)
            Console.WriteLine(
    "DATASOURCE:{0} CREATE SUCCESSFULLY!", name)
        
    Catch e As Exception
            Console.WriteLine(e.Message)
        
    End Try
    End Sub

    ' Func: 部署报表
    '
    Param: 
    '
          - reportName 报表名称
    Public Sub DeployReport(ByVal reportName As String)
        
    Try
    '这里 File.OpenRead() 很奇怪,必须通过 pFilePath + reportName + ".rdl" 这种组合形式传参,
    '而如果直接传入一个完整的路径,则rs.exe运行脚本时会出错(* 如果基于这种方式传参,则要确保所有 .rdl 文件都在同一目录)
            Dim stream As FileStream = File.OpenRead(pFilePath + reportName + ".rdl")
            mDefinition 
    = New [Byte](stream.Length - 1) {}  '注意维度为“stream.Length - 1”!

            stream.Read(mDefinition, 
    0CInt(stream.Length))
            stream.Close()
        
    Catch e As IOException
            Console.WriteLine(e.Message)
        
    End Try
        Console.WriteLine(reportName)
        
    Try
            mWarnings 
    = rs.CreateReport(reportName, mParentPath, True, mDefinition, Nothing)

            
    If Not (mWarnings Is NothingThen
                
    Dim warning As Warning
                
    For Each warning In mWarnings
                    Console.WriteLine(warning.Message)
                
    Next warning
            
    Else
                Console.WriteLine(
    "DEPLOY REPORT:{0} SUCCESSFULLY!", reportName)
            
    End If
        
    Catch e As Exception
            Console.WriteLine(e.Message)
        
    End Try
    End Sub


  • 相关阅读:
    ipv6 for openwrt odhcpd
    openwrt package Makefile
    openwrt 中个网络接口协议说明[转]
    openwrt Package aircrack-ng is missing dependencies for the following libraries:
    linux kernel 从cmdline 提取值
    js 上传文件进度条 [uboot使用]
    printk打印级别 [转]
    linux c 宏定义
    uboot 开发记录
    mac ssh scp命令
  • 原文地址:https://www.cnblogs.com/glife/p/1788929.html
Copyright © 2020-2023  润新知