zoukankan      html  css  js  c++  java
  • InfoPath表单托管代码示例

    前段时间项目中一个有多个View的Form需要使用代码来完成一些特殊的功能,网上的资料不太好找,现整理出来,全当抛砖引玉。注意:InfoPath编码思想比较特别,控件都是绑定到数据源上,修改的都是数据源,而不是通过控件的属性来修改。
    1、获取非主数据源
        XPathNavigator myNavigator = this.DataSources["SecondaryDataSource"].CreateNavigator();
        MessageBox.Show(myNavigator.OuterXml.ToString(),"Secondary Data Source XML");


    2、获取当前View的信息
         if (this.CurrentView.ViewInfo.Name == "ViewName")       //判断当前View名称
        { }

        在public void FormEvents_ViewSwitched(object sender, ViewSwitchedEventArgs e)事件中可以使用以上判断来对特定的View进行操作。

    3、获取/设置某个数据源的值,
         XPathNavigator root = this.MainDataSource.CreateNavigator();
         XPathNavigator nameField = root .SelectSingleNode("/my:myFields/my:MainName/my:name", NamespaceManager);
         nameField.SetValue("Hello");
         string >
    4、遍历Repeat控件,获取用户输入的数据
        string message="";
        XPathNavigator root = MainDataSource.CreateNavigator();
       
    XPathNodeIterator nameNodes = root.Select("/my:myFields/my:MainName/my:name", NamespaceManager);
        while (nameNodes.MoveNext())
        {
            message += nameNodes.Current.Value + System.Environment.NewLine;
        }

        MessageBox.Show(message);

    5、动态添加控件
        CurrentView.ExecuteAction(ActionType.XCollectionInsert, "Group_1");

    6、使数据源所对应的文本值处于选中状态
        XPathNavigator textNode = CreateNavigator().SelectSingleNode("/my:myFields/my:field1", NamespaceManager);
       
    CurrentView.SelectText(textNode);
        CurrentView.ExecuteAction(ActionType.Cut);

    7、调用WebService
        // Open connection.
        WebServiceConnection wsc = (WebServiceConnection)this.DataConnections["Main query"];
       
    // Create XmlDocuments.
        XmlDocument inputDocument = new XmlDocument();
        XmlDocument outputDocument = new XmlDocument();
        XmlDocument errorsDocument = new XmlDocument();
       
    // Load input document.
        inputDocument.LoadXml("<inputValue1>Test</inputValue1><inputValue2>5</inputValue2>");
       
    // Create XPathNavigator objects for documents.
        XPathNavigator inputNav = inputDocument.CreateNavigator();
        XPathNavigator outputNav = outputDocument.CreateNavigator();
        XPathNavigator errorsNav = errorsDocument.CreateNavigator();
       
    // Call Execute method.
        wsc.Execute(inputNav, outputNav, errorsNav);

      
          获取Repeat控件内部的数据时,我采用DataSet存储,因为我发现遍历每个Repeat时,无法遍历其下子控件的值。比如。Repeat DataTable有3个,子控件TextBox控件的值也有3个。通过XPathNodeIterator实例遍历DataTable的时候无法获取对应的TextBox的值,默认都是获取第一次出现的值,所以只好借助于DataRow分别遍历给不同的Column赋值。不知道园子里谁有更好的方法,请告知。谢谢


  • 相关阅读:
    POJ 3259 Wormholes【BellmanFord】
    POJ 2960 SNim【SG函数的应用】
    ZOJ 3578 Matrixdp水题
    HDU 2897 邂逅明下【bash博弈】
    BellmanFord 算法及其优化【转】
    【转】几个Java的网络爬虫
    thinkphp 反字符 去标签 自动加点 去换行 截取字符串 冰糖
    php 二维数组转 json文本 (jquery datagrid 数据格式) 冰糖
    PHP 汉字转拼音(首拼音,所有拼音) 冰糖
    设为首页与加入收藏 兼容firefox 冰糖
  • 原文地址:https://www.cnblogs.com/IsNull/p/1877884.html
Copyright © 2011-2022 走看看