2011-04-06 79 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