【问题标题】:How to create an Crystal Report from a XML (XML is from a Web Service) in C#如何在 C# 中从 XML(XML 来自 Web 服务)创建 Crystal Report
【发布时间】:2012-12-23 02:06:13
【问题描述】:

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

这是我如何从 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

【问题讨论】:

  • 您熟悉阅读 XMLDocument..吗?你能不能说明这个.xml文件的文件路径是什么,这样我就可以给你一个有效的例子..
  • @DJKRAZE ,没有xml文件,结果来自一个web服务的函数
  • 您尝试创建的报告的名称是什么。我会将其添加到我的答案中。
  • @DJKRAZE, TransReport :D

标签: c# xml crystal-reports linq-to-xml crystal-reports-2010


【解决方案1】:

这还没有经过测试,但您可以尝试以下类似的方法

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 updating child objects on refresh

【讨论】:

  • 为什么会有路径?我可以做一些事情吗 TransReport rpt = new TransReport(); rpt.SetDataSource(数据); CrystalReportViewer1.ReportSource = rpt; ??
  • 出现错误“错误 2 参数 1:无法从 'System.Xml.Linq.XDocument' 转换为 'System.Xml.XmlReader'”
  • 我不能调用“crystalReportViewer1.ViewCore?我只使用”crystalReportViewer1.ReportSource = report; "
  • 这里也是一个很好的链接,用于 xDocument 到 XmlReader stackoverflow.com/questions/1508572/…
  • 仍然出现错误“错误 2 参数 1:无法从 'System.Xml.XmlDocument' 转换为 'System.Xml.XmlReader'”
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-04-18
  • 1970-01-01
  • 2010-09-08
  • 2018-12-17
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多