[转贴]水晶报表

来源:互联网 发布:python get函数的用法 编辑:程序博客网 时间:2024/04/29 11:08
     I am using VC++ 6 with crystal reports 9 . I have a problem with the report viewer control.
     The following code couldn't automatically refresh the data in reports. It always shows the data which I had given at the design time.
But when I manually click the refresh button in reports , it shows the updated data.
 
Here is my code :
......................................................................................................
 CCrystalReportViewer9 m_viewer;

 m_viewer.SetReportSource(m_Report);
 SendMessage(WM_SYSCOMMAND, SC_MAXIMIZE, NULL);
 CRect rect;
 this->GetClientRect(&rect);
 int nWidth=rect.right-rect.left;
 int nHeight=rect.bottom-rect.top;
 
 m_viewer.SetWindowPos(&wndTopMost, 0, 0, nWidth, nHeight, SWP_SHOWWINDOW);
 
 IReportObjectsPtr pRepObjects = NULL;
 IReportObjectPtr pRepObject = NULL;
 ISubreportObjectPtr pSubObject = NULL;
 IReportPtr pSubreport = NULL;
 
 int a=m_Report->Sections->Count;
 ISectionsPtr secsObj;
 for(int i=1; i<=a; i++)
 {
    secsObj=m_Report->GetSections();
    // Create a variant to hold the value of i
  VARIANT var2;
  VariantInit(&var2);
  var2.vt = VT_I4;
  var2.lVal = i;
  
  ISectionPtr secObj;
  // Pass the value of i to get the i-th section
  secObj = secsObj->GetItem(var2);
  
  //  secsObj->get_Item(i, &secObj);
  
  if(secObj!=NULL)
  {
   int p=secObj->ReportObjects->Count;
   for(int j=1; j<=p; j++)
   {
    pRepObjects = secObj->GetReportObjects();
    // as long as there are report object....
    if (!pRepObjects->GetCount() == 0)
    {
     // ... loop through each
     for (long k = 1;k <= pRepObjects->GetCount(); k++)
     {
      // Create a variant to hold the value of j
      VARIANT var;
      VariantInit(&var);
      var.vt = VT_I4;
      var.lVal = k;
      // Pass the value of j to the the j-th report
      // object
      pRepObject = pRepObjects->GetItem(var); 
      if (pRepObject->GetKind() == crSubreportObject)
      {
       pSubObject = pRepObject;
       pSubreport = pSubObject->OpenSubreport();
       IDatabaseTablesPtr pTables=pSubreport->Database->GetTables();
       for(long d=1; d<=pTables->GetCount();d++)
       {
       
        IDatabaseTablePtr pTable=pTables->GetItem(d);
        pTable->Location=(_bstr_t) "..//Data//Report.mdb";
       }
      }
     }
     }
   }
  }
  }
 
 m_viewer.Refresh();
// m_viewer.RefreshEx(true);     
 m_viewer.ViewReport();
 
原创粉丝点击