2011-04-06 56 views
1

我正在使用InfoPath 2007,并使用C#进行编码。我想要做的就是填充字段合同号,有多个领域,是合同期结束日期dtTo,这必须是在格式YYYY/MM,这是选择一个日期选择器),项目编号ddlPortfolio,一个下拉列表中选择),序列号(这是从数据库中检索时,SQL Server 2005)和基金类型(bFundType,选择一个选项按钮)。使用多个字段值填充字段

现在我所做的是我已经使用了一种方法来尝试填充字段合同编号。该方法被称为生成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 

所以我的问题是,在按钮保存,它不填充合同编号字段。对不起,我是C#的新手。

回答

0

据我所见,你不需要返回值GenerateContractNo,所以使该方法有一个返回类型void。要设置值,请尝试使用此代码来代替:

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

背景:
根据对Value property的文档,它是空的Element节点。您的sSequence节点最有可能是元素节点。

关于你的方法popSeq

+0

感谢导游,还有......将这样做 – Martin 2011-04-06 08:59:25