【问题标题】:Static classes and the Business Objects COM Library静态类和业务对象 COM 库
【发布时间】:2010-11-18 14:28:14
【问题描述】:

以下代码来自一个 winforms 应用程序,它在按钮事件上打开业务对象 6.5 的实例,刷新报表,然后将报表中的数据转储到 csv 文件中,然后退出业务对象实例。

我第一次运行代码时它可以完美运行,但是如果我再次运行它,我会遇到异常

boApp.LoginAs(userName, Password, false, null);

抛出的异常是“无效对象”。

我假设这是因为 boApp 尚未重新初始化,而问题在于我缺乏关于静态类的知识。

调用方法是这样的:

BO_Control.RefreshBusinessObjects(boReportsFolder, boExportsFolder, boReportName, exportFileName, startDate, endDate);

这是 BO_Control 类

static class BO_Control
{

    static busobj.Application boApp = new busobj.Application();
    static busobj.Document testDoc;


   public static void RefreshBusinessObjects(string reportFolder, string exportFolder ,string boReportName, string exportFileName, string startDate, string endDate)      
   {


        DateTime BoStart = DateTime.Now;

        boApp.LoginAs(userName, Password, false, null);

        boApp.Interactive = false;
        boApp.Visible = false;

        GetData(reportFolder, boReportName, startDate, endDate);
        ExportData(exportFolder, exportFileName);

        Console.WriteLine("BO_Export took {0} seconds.", DateTime.Now.Subtract(BoStart));

        boApp.Quit();          
   }

   static busobj.Document GetData(string reportFolder, string reportName, string startDate, string endDate)
   {
       Console.WriteLine(reportFolder + reportName);
       testDoc = (busobj.Document)boApp.Documents.Open(reportFolder + reportName, true, false, null, null);

       //Report Start Date
       testDoc.Variables[1].Value = startDate;
       //Report End Date
       testDoc.Variables[2].Value = endDate;
       //Area. Needs to be a semi-colon delimited string
       testDoc.Variables[3].Value = "L;B;H;";

       testDoc.Refresh();

       return testDoc;

   }

   static void ExportData(string exportFolder, string exportFileName)
   {
       testDoc.Reports.get_Item(1).ExportAsText(exportFolder + exportFileName);
       //2 = DoNotSaveChanges
       testDoc.Close(2);
   }

}

【问题讨论】:

    标签: .net business-objects static-classes


    【解决方案1】:

    我将 BOApp 的实例化移动到 RefreshBusinessObjects 方法中,这似乎可以解决问题

    【讨论】:

      【解决方案2】:

      我也使用这个登录代码,它可以工作,但它需要点击BO登录diaglog的OK按钮。有没有一些方法可以跳过这个点击按钮步骤?

      【讨论】:

      • 天哪,这是过去的爆炸。应设置此行,这将关闭所有业务对象交互 boApp.Interactive = false;您是否还确保 boApp.LoginAs(userName, Password, false, null); 中的用户名和密码正确?方法?
      • 我认为我的用户名和密码是正确的,请通过下面的链接查看我的代码,如果我点击 BO 登录对话框的 ok 按钮,bo 应用程序将照常运行click here for code跨度>
      • 我希望能进一步帮助您,但我无法再访问 Business objects 6.5 来测试它。
      猜你喜欢
      • 2012-07-01
      • 2013-06-20
      • 2012-12-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-22
      • 2011-08-02
      • 1970-01-01
      相关资源
      最近更新 更多