悠闲小风专栏

SharePoint & Workflow 解决方案

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
  56 随笔 :: 0 文章 :: 33 评论 :: 46777 阅读
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

用infopath 引用外部数据源,进行数据操作,是一件非常方便的事情,比如连接SQL数据库,引用webServices、xml、sharepoint list等,但是我们发现了一个问题,infopath引用数据源时,会将数据缓存在客户端,当我们引用的数居源数据量大的时候,会产生用户操作缓慢的问题。这个时候我们希望下载下来数据能够,既小又准确。我们能够通过自定义数据源加参数的方法,实现动态的数据源查询。在VSTA中动态改变数据源查询参数与反回查询结果,可以参考如下代码:

 

复制代码
代码
 public void CTRL1_14_Clicked(object sender, ClickedEventArgs e)
        {
            
// 在此处编写代码。
            System.Xml.XPath.XPathNavigator root;
            root 
= this.MainDataSource.CreateNavigator();
            DataConnection dc 
= ((DataConnection)DataSources["GetData"].QueryConnection);//获取数据源对象

            
if (dc is WebServiceConnection)
            {
                
string queryField = ""
                                     
+ "<tns:GetData xmlns:tns=\"http://tempuri.org/\"><tns:SecuCode>" + root.SelectSingleNode("//ns2:证券代码", this.NamespaceManager).Value + "</tns:SecuCode>"

                                   
+ "   <tns:TradingDay>" + root.SelectSingleNode("//ns2:查询日期"this.NamespaceManager).Value + "</tns:TradingDay>"
                                   
+ "   </tns:GetData>"
                                   
+ "";
                XmlDocument inputDocument
=new XmlDocument();
                inputDocument.LoadXml(queryField);
                XPathNavigator inputNav
= inputDocument.CreateNavigator();

                XmlDocument outputDocument 
= new XmlDocument();
               XPathNavigator outputNav 
= outputDocument.CreateNavigator();

                Microsoft.Office.InfoPath.WebServiceConnection fqc 
= (Microsoft.Office.InfoPath.WebServiceConnection)dc;

                fqc.Execute(inputNav, outputNav, 
null);//执行数据查询
                
//MessageBox.Show(outputNav.OuterXml);

                
string outXml = outputNav.OuterXml.Replace("xmlns=\"http://tempuri.org/\"", "");
                outputDocument.LoadXml(outXml);

                XmlElement nodeElement 
= (XmlElement)outputDocument.SelectSingleNode("GetDataResponse/GetDataResult/证券简称");
                XPathNavigator setNode 
= root.SelectSingleNode("//ns2:公司名称"this.NamespaceManager);
                DeleteNil(setNode);
                setNode.SetValue(nodeElement.InnerText);//对infopath域进行附值

                nodeElement 
= (XmlElement)outputDocument.SelectSingleNode("GetDataResponse/GetDataResult/交易日期");
                setNode 
= root.SelectSingleNode("//ns2:交易日期"this.NamespaceManager);
                DeleteNil(setNode);
                setNode.SetValue(nodeElement.InnerText);

            }
        }
        
public void DeleteNil(XPathNavigator node)
        {
            
if (node.MoveToAttribute(
               
"nil""http://www.w3.org/2001/XMLSchema-instance"))
                node.DeleteSelf();
        }
复制代码

 

 

posted on   陈典洪  阅读(576)  评论(0编辑  收藏  举报
编辑推荐:
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
历史上的今天:
2009-07-27 如何控制列表视图栏位的宽度?
点击右上角即可分享
微信分享提示