静态类和 Business Object COM 库

发布于 2024-10-03 07:50:00 字数 2013 浏览 0 评论 0 原文

下面的代码来自 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);
   }

}

The following code below is from a winforms application that on a button event opens up an instance of business objects 6.5, refreshes the report and then dumps the data in the report into a csv file, and then quits the business objects instance.

The first time i run the code it works perfectly, however if i run it again i get an exception on the line

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

The exception thrown is 'Invalid Object'.

I'm assuming this is down to the fact that boApp hasn't been re-initialised, and that it's my lack of knowledge regarding static classes that's the issue.

The calling method is this:

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

and this is the BO_Control class

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);
   }

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

So要识趣 2024-10-10 07:50:00

我将 BOApp 的实例化移至 RefreshBusinessObjects 方法中,这似乎成功了

I moved the instantiation of the BOApp into the RefreshBusinessObjects Method and that seemed to do the trick

梦醒时光 2024-10-10 07:50:00

我也使用这个登录代码,它可以工作,但需要单击 BO 登录对话框的“确定”按钮。有没有一些方法可以跳过这个点击按钮步骤?

i also use this login code, it works, but it need to click the OK button of BO login diaglog. is there some methods can skip this click button step?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文