4

我想知道如何从 XML(XML 来自 Web 服务)创建水晶报表,我在一些教程中读到它需要找到文件并拖动报表中的字段,但是来自网络服务?

这是我如何从 Web 服务获取 XML 的代码

  var doc = XDocument.Parse(trx.GetCardTrx("xxxxx", "xxxx", "xxx", "", dateTimePicker1.Text, dateTimePicker2.Text, "", "", "", "", "", "", "", "", "", "", "", "FALSE", "", "", "", "", "", "", "", "", "", "", ""));
MessageBox.Show(doc.ToString());

所以这段代码返回这种值(From MessageBox.Show(doc.ToString()

在此处输入图像描述

这是应该在报告中的选定值的代码

var summary = from r in doc.Descendants("TrxDetailCard") 
                      select new 
                      {
                          Account_Type = r.Element("Account_Type_CH").Value,
                          Captured = r.Element("Captured").Value,
                          Trans_Type_ID = r.Element("Trans_Type_ID").Value,
                          Acct_Num_CH = r.Element("Acct_Num_CH").Value,
                          Tip_Amt_MN = r.Element("Tip_Amt_MN").Value,
                          Total_Amt_MN = r.Element("Total_Amt_MN").Value,
                          Date_DT = r.Element("Date_DT").Value,
                      };

而我想要发生的是使用 Crystal Reports 创建一个具有此值的报表,而不是所有值。仅选定的值。我怎么可能做到这一点?任何想法都会有很大帮助谢谢:D

4

1 回答 1

2

这尚未经过测试,但您可以尝试以下类似的方法

using System.Xml;
using System.Xml.Linq;

var doc = XDocument.Parse(trx.GetCardTrx("xxxxx", "xxxx", "xxx", "", dateTimePicker1.Text, dateTimePicker2.Text, "", "", "", "", "", "", "", "", "", "", "", "FALSE", "", "", "", "", "", "", "", "", "", "", ""));

  var data = new DataSet();
  var context = new XmlParserContext(null, new XmlNamespaceManager(new NameTable()), null, XmlSpace.None);
  var reader = doc
  data.ReadXml(reader);

  var report = new ReportDocument();

  report.SetDataSource(data);
  this.crystalReportViewer1.ReportSource.ReportSource = report;

理论上的想法应该可以工作,但您可以从此链接引用类似的东西 XML-based Crystal Report not updated child objects on refresh

于 2012-12-23T02:24:03.290 回答