重复表的操作

using Microsoft.Office.InfoPath;
using System;
using System.Xml;
using System.Xml.XPath;
using System.Windows.Forms;

namespace 重复表
{
    public partial class FormCode
    {
        // 启用浏览器功能的表单不支持成员变量。
        // 请使用代码从 FormState 词典
        // 写入和读取这些值,如下所示:
        //
        // private object _memberVariable
        // {
        //     get
        //     {
        //         return FormState["_memberVariable"];
        //     }
        //     set
        //     {
        //         FormState["_memberVariable"] = value;
        //     }
        // }

        // 注意: 以下是 Microsoft Office InfoPath 所需的过程。
        // 可以使用 Microsoft Office InfoPath 对其进行修改。
        public void InternalStartup()
        {
            ((ButtonEvent)EventManager.ControlEvents["CTRL5_5"]).Clicked += new ClickedEventHandler(CTRL5_5_Clicked);
            ((ButtonEvent)EventManager.ControlEvents["CTRL6_5"]).Clicked += new ClickedEventHandler(CTRL6_5_Clicked);
        }

       //添加新行
       public void CTRL5_5_Clicked(object sender, ClickedEventArgs e)
        {
            XPathNavigator group = MainDataSource.CreateNavigator().SelectSingleNode("/my:root/my:body/my:RepeatTable[last()]", NamespaceManager);
            XPathNavigator NewRow = group.Clone();
            NewRow.InsertBefore(group);

            //设置默认值
            NewRow.SelectSingleNode("my:A", NamespaceManager).SetValue("test");
            NewRow.SelectSingleNode("my:B", NamespaceManager).SetValue("999.99");
            NewRow.SelectSingleNode("my:C", NamespaceManager).SetValue("2009-01-20");


        }


        //删除行
        public void CTRL6_5_Clicked(object sender, ClickedEventArgs e)
        {
            XPathNavigator group = MainDataSource.CreateNavigator().SelectSingleNode("/my:root/my:body/my:RepeatTable[last()]", NamespaceManager);

            //如果确认就删除
            DialogResult YESorNO = System.Windows.Forms.MessageBox.Show("您确认删除" + group.SelectSingleNode("my:A", NamespaceManager).Value + "这一行?", "", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
            if (YESorNO == DialogResult.OK)
           {
               group.DeleteSelf();
           }

        }
    }
}

 


 

posted @ 2009-01-20 14:33  昕友软件开发  阅读(326)  评论(0编辑  收藏  举报
欢迎访问我的开源项目:xyIM企业即时通讯