I am Having Infopath form where i am having LeadId....while selecting LeadId from dropdown List....I am getting value in the repeating table the problem is that it only show first value .....i have to manually select second value from insert option and so on in repeting table.it is possible that i should get all the value in repeating table(without selecting insert option). although i have issued CAML query for that....so here are my code .....thank's in advance if one can help.....
using Microsoft.Office.InfoPath;
using System;
using System.Windows.Forms;
using System.Xml;
using System.Xml.XPath;
using mshtml;
using Microsoft.SharePoint;
namespace Quotation
{
public partial class FormCode
{
public void InternalStartup()
{
((ButtonEvent)EventManager.ControlEvents["CTRL101_5"]).Clicked += new ClickedEventHandler(CTRL101_5_Clicked);EventManager.XmlEvents["/my:myFields/my:group5"].Changed += new XmlChangedEventHandler(ddlLeadId_Changed);
}
public void CTRL101_5_Clicked(object sender, ClickedEventArgs e)
{
if (this.Errors.Count > 0)
{
this.Errors.DeleteAll();
}
XPathNavigator secDSNav = DataSources["CustomListCAML2"].CreateNavigator();
XPathNodeIterator iter = secDSNav.Select("/Batch/Method");
int methodNodeCount = iter.Count;
XPathNavigator firstMethodNav = secDSNav.SelectSingleNode("/Batch/Method[1]", NamespaceManager);XPathNavigator lastMethodNav = secDSNav.SelectSingleNode("/Batch/Method[" + methodNodeCount.ToString() + "]", NamespaceManager);
firstMethodNav.DeleteRange(lastMethodNav);
XPathNavigator root = MainDataSource.CreateNavigator();
XPathNodeIterator rows = root.Select("/my:myFields/my:group3/my:group4", NamespaceManager);
XPathNavigator QDF = this.MainDataSource.CreateNavigator();
string QuotNo = QDF.SelectSingleNode("/my:myFields/my:txtQuotationNo", NamespaceManager).Value;
string QuotDate = QDF.SelectSingleNode("/my:myFields/my:ddlDate", NamespaceManager).Value;
string LeadId = QDF.SelectSingleNode("/my:myFields/my:ddlLeadId", NamespaceManager).Value;
string CustomerName = QDF.SelectSingleNode("/my:myFields/my:txtCustomerName", NamespaceManager).Value;
string Address = QDF.SelectSingleNode("/my:myFields/my:txtAddress", NamespaceManager).Value;
string ContactPerson = QDF.SelectSingleNode("/my:myFields/my:txtContactPerson", NamespaceManager).Value;
string SubTotal = QDF.SelectSingleNode("/my:myFields/my:txtSubTotal", NamespaceManager).Value;
string VAT = QDF.SelectSingleNode("/my:myFields/my:txtVATAmount", NamespaceManager).Value;
string CST = QDF.SelectSingleNode("/my:myFields/my:txtCSTAmount", NamespaceManager).Value;
string ForwardCharges = QDF.SelectSingleNode("/my:myFields/my:txtFORWARDINGCHARGESAmount", NamespaceManager).Value;
string TotalAmount = QDF.SelectSingleNode("/my:myFields/my:txtTotalAmount", NamespaceManager).Value;
int counter = 1;
while (rows.MoveNext())
{
string ProductName = rows.Current.SelectSingleNode("my:txtItemName", NamespaceManager).Value;
string Desc = rows.Current.SelectSingleNode("my:txtItemDesc", NamespaceManager).Value;
string Qty = rows.Current.SelectSingleNode("my:txtQty", NamespaceManager).Value;
string Rate = rows.Current.SelectSingleNode("my:txtRate", NamespaceManager).Value;
string Amount = rows.Current.SelectSingleNode("my:txtAmount", NamespaceManager).Value;
AddMethodNode(counter, QuotNo, QuotDate, LeadId, CustomerName, Address, ContactPerson, SubTotal, VAT, CST, ForwardCharges, TotalAmount, ProductName, Desc, Qty, Rate, Amount);
counter++;
}
DataConnections["QuotSubmit"].Execute();
DataConnections["MainSubmit"].Execute();
XPathNavigator XPN = this.MainDataSource.CreateNavigator();System.Windows.Forms.MessageBox.Show("Record Saved Successfully........");
}
private void AddMethodNode(int id, string QuotNo, string QuotDate, string LeadId, string CustomerName, string Address, string ContactPerson, string SubTotal, string VAT, string CST, string ForwardCharges, string TotalAmount, string ProductName, string Desc, string Qty, string Rate, string Amount)
{
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.AppendFormat("<Method ID=\"{0}\" Cmd=\"New\">", id.ToString());
sb.AppendFormat("<Field Name=\"Title\">{0}</Field>", QuotNo);
sb.AppendFormat("<Field Name=\"Date\">{0}</Field>", QuotDate);
sb.AppendFormat("<Field Name=\"LeadID\">{0}</Field>", LeadId);
sb.AppendFormat("<Field Name=\"CustomerName\">{0}</Field>", CustomerName);
sb.AppendFormat("<Field Name=\"ContactPerson\">{0}</Field>", ContactPerson);
sb.AppendFormat("<Field Name=\"Address\">{0}</Field>", Address);
sb.AppendFormat("<Field Name=\"ProductName\">{0}</Field>", ProductName);
sb.AppendFormat("<Field Name=\"Description\">{0}</Field>", Desc);
sb.AppendFormat("<Field Name=\"Qty\">{0}</Field>", Qty);
sb.AppendFormat("<Field Name=\"Rate\">{0}</Field>", Rate);
sb.AppendFormat("<Field Name=\"Amount\">{0}</Field>", Amount);
sb.AppendFormat("<Field Name=\"SubTotal\">{0}</Field>", SubTotal);
sb.AppendFormat("<Field Name=\"VAT\">{0}</Field>", VAT);
sb.AppendFormat("<Field Name=\"CST\">{0}</Field>", CST);
sb.AppendFormat("<Field Name=\"ForwardingCharges\">{0}</Field>", ForwardCharges);
sb.AppendFormat("<Field Name=\"TotalAmount\">{0}</Field>", TotalAmount);
sb.AppendFormat("</Method>");
XmlDocument methodXML = new XmlDocument();
methodXML.LoadXml(sb.ToString());
XPathNavigator secDSNav = DataSources["CustomListCAML2"].CreateNavigator();XPathNavigator batchNav = secDSNav.SelectSingleNode("/Batch", NamespaceManager);
batchNav.AppendChild(methodXML.DocumentElement.CreateNavigator());
}
public void ddlLeadId_Changed(object sender, XmlEventArgs e)
{
XPathNavigator Demo = this.MainDataSource.CreateNavigator();using (SPSite siteCollection = new SPSite("http://RnDserver:10101/default.aspx"))
{
using (SPWeb web = siteCollection.OpenWeb())
{
string leadid = Demo.SelectSingleNode("/my:myFields/my:ddlLeadId", NamespaceManager).Value;
SPList list = web.Lists["Lead for Existing Product"];SPQuery query = new SPQuery();
query.Query =
"<Where>" +
"<Eq>" +
"<FieldRef Name='Lead_x0020_Id' />" +
"<Value Type='Text'>" + leadid +
"</Value>" +
"</Eq>" +
"</Where>";
SPListItemCollection collection = list.GetItems(query);foreach (SPListItem item in collection)
{
string myNamespace = NamespaceManager.LookupNamespace("my");
using (XmlWriter writer = MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:group3", NamespaceManager).AppendChild())
{
writer.WriteStartElement("group4", myNamespace);
writer.WriteElementString("txtItemName", myNamespace, item.Title);
writer.WriteElementString("txtItemDesc", myNamespace, item.Title);writer.WriteElementString("txtQty", myNamespace, item.Title);
writer.WriteEndElement();
writer.Close();
}
}
}
}
}
}
}