1

我正在使用 InfoPath 2007,并使用 C# 进行编码。我想要做的是用多个字段填充字段Contract Number,即Contract Period End DatedtTo,其格式必须为YYYY/MM,这是一个选择的日期选择器),Project NumberddlPortfolio,a下拉列表选择),序列号(从数据库中检索,SQL Server 2005)和基金类型(bFundType,选择一个选项按钮)。

现在我所做的是我使用了一种方法来尝试填充字段合同编号。该方法称为 Generate ContractNo,它是:

public string GenerateContractNo()
    {
        string sSequence = "";

        //IPCode.popSeq(this.CreateNavigator(), this.NamespaceManager, DataSources, this.MainDataSource);


        //string seqNo = this.CreateNavigator().SelectSingleNode("/my:myRoot/my:SectionHeading/my:sSequence", NamespaceManager).InnerXml;



        string sPortfolio = this.CreateNavigator().SelectSingleNode("/my:myRoot/my:SectionHeading/my:ddlPortfolio", NamespaceManager).InnerXml;
        string sYear = this.CreateNavigator().SelectSingleNode("/my:myRoot/my:SectionHeading/my:dtTo", NamespaceManager).InnerXml;
        string sMonth = this.CreateNavigator().SelectSingleNode("/my:myRoot/my:SectionHeading/my:dtTo", NamespaceManager).InnerXml;
        //string sSeq = this.CreateNavigator().SelectSingleNode("/my:myRoot/my:SectionHeading/my:sSequence", NamespaceManager).InnerXml;
        string sFundType = this.CreateNavigator().SelectSingleNode("/my:myRoot/my:SectionHeading/my:bFundType", NamespaceManager).InnerXml;

        //Convert.ToInt16(sSeq);

       // return sYear + "/" + sMonth + "/" + sPortfolio + "/" + sSeq + "/" + sFundType;

        sSequence = sYear + "/" + sMonth + "/" + sPortfolio + "/" + sFundType;

        this.CreateNavigator().SelectSingleNode("/my:myRoot/my:SectionHeading/my:sSequence", this.NamespaceManager).SetValue(sSequence); 

        //CourseDetails = dtSDate.ToLongDateString() + " - " + dtEDate.ToLongDateString() + " | " + sLocation + " | " + SDCategory;

        //CourseDetailsFields = sTitle + "|" + dtSDate.ToLongDateString() + "|" + dtEDate.ToLongDateString() + "|" + sLocation + "|" + SDCategory;

        //lstDetails.Add(CourseDetailsFields, CourseDetailsFields); 
        return null;

    }

我还尝试使用名为 PopSeq 的类来填充序列号字段,并使用来自数据库的序列号,该序列号调用名为 uspGetSeqNo 的存储过程。以下是类,以及存储过程:

static public int popSeq(XPathNavigator xnMyForm, XmlNamespaceManager ns, DataSourceCollection ds, DataSource mds)
    {

        try
        {

            SqlConnection conn = new SqlConnection(IPCode.defaultConnectionString);
            SqlCommand command = new SqlCommand("[uspGetSeqNo]", conn);

            conn.Open();            
            command.CommandType = CommandType.StoredProcedure;

            //XPathNavigator domNav = mds.CreateNavigator();
            //string sVendor = domNav.SelectSingleNode("/my:myRoot/my:SectionHeading/my:ddlVendor", this.NamespaceManager).ToString();

            //command.Parameters.AddWithValue("@iSequence", s);

            SqlDataReader myReader = command.ExecuteReader();



            while (myReader.Read())
            {
                string iSequence = Convert.ToString(myReader.GetOrdinal("iSequence"));
               //return Convert.ToInt16(sSeq);                    
            }
        }
        catch (Exception ex)
        {
            throw ex;

        }
        return 0;
    }

存储过程:

USE [TAU_PANEL]
GO
/****** Object:  StoredProcedure [dbo].[uspGetSeqNo]    Script Date: 04/06/2011      08:52:14 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


ALTER PROCEDURE [dbo].[uspGetSeqNo]

AS

SELECT     MAX(iSequence) + 1 AS seq
FROM         dbo.ResAllocations

所以我的问题是,在按钮 save 上,它没有填充 Contract Number 字段。抱歉,我是 C# 的新手。

4

1 回答 1

0

据我所知,您不需要 的返回值GenerateContractNo,因此使该方法的返回类型为void。要设置该值,请尝试使用以下代码:

this.CreateNavigator().
    SelectSingleNode("/my:myRoot/my:SectionHeading/my:sSequence", 
        this.NamespaceManager).InnerText = sSequence; 

背景:
根据Value属性的文档,元素节点为空。您的 sSequence 节点很可能Element 节点。

关于你的方法popSeq

于 2011-04-06T08:53:43.130 回答