Help! :)
So here's my code, and an attached picture of my data sources. I was essentially trying to follow what was going on here: http://www.bizsupportonline.net/infopath2007/4-way-programmatically-add-row-repeating-table.htm
Again, the goal is to copy the data from the secondary source to the main data source.
private void AddItem(string po_number, string qty_on_po, string line, string description, string start_box,
string end_box, string parts_per_box, string run_time, string setup_time, string comments)
{
XmlDocument doc = new XmlDocument();
XmlNode group = doc.CreateElement("q:production_items", NamespaceManager.LookupNamespace("my"));
XmlNode field = doc.CreateElement("PO_NUMBER", NamespaceManager.LookupNamespace("my"));
XmlNode node = group.AppendChild(field);
node.InnerText = po_number;
field = doc.CreateElement("QTY_ON_PO", NamespaceManager.LookupNamespace("my"));
node = group.AppendChild(field);
node.InnerText = qty_on_po;
field = doc.CreateElement("LINE", NamespaceManager.LookupNamespace("my"));
node = group.AppendChild(field);
node.InnerText = line;
field = doc.CreateElement("DESCRIPTION", NamespaceManager.LookupNamespace("my"));
node = group.AppendChild(field);
node.InnerText = description;
field = doc.CreateElement("BOX_START", NamespaceManager.LookupNamespace("my"));
node = group.AppendChild(field);
node.InnerText = start_box;
field = doc.CreateElement("BOX_END", NamespaceManager.LookupNamespace("my"));
node = group.AppendChild(field);
node.InnerText = end_box;
field = doc.CreateElement("PARTS_PER_BOX", NamespaceManager.LookupNamespace("my"));
node = group.AppendChild(field);
node.InnerText = parts_per_box;
field = doc.CreateElement("RUN_TIME", NamespaceManager.LookupNamespace("my"));
node = group.AppendChild(field);
node.InnerText = run_time;
field = doc.CreateElement("SETUP_TIME", NamespaceManager.LookupNamespace("my"));
node = group.AppendChild(field);
node.InnerText = setup_time;
field = doc.CreateElement("COMMENTS", NamespaceManager.LookupNamespace("my"));
node = group.AppendChild(field);
node.InnerText = comments;
doc.AppendChild(group);
//MessageBox.Show(doc.OuterXml.ToString());
// crashes on append
MainDataSource.CreateNavigator().SelectSingleNode("d:production_items",
NamespaceManager).AppendChild(doc.DocumentElement.CreateNavigator());
}
private void DeleteFirstEmptyItem()
{
XPathNavigator domNav = MainDataSource.CreateNavigator();
XPathNavigator itemNav = domNav.SelectSingleNode("/dfs:myFields/dfs:dataFields/d:production_record/d:production_items[1]", NamespaceManager);
if (itemNav != null)
itemNav.DeleteSelf();
}
public void CTRL224_7_Clicked(object sender, ClickedEventArgs e)
{
XPathNavigator secDSNav = DataSources["last_shift_query"].CreateNavigator();
// Retrieve the rows of the secondary data source
XPathNodeIterator rows = secDSNav.Select("/dfs:myFields/dfs:dataFields/d:previous_shift_production", NamespaceManager);
// Loop through the rows of the secondary data source and fill the repeating table
while (rows.MoveNext())
{
string po_number = rows.Current.SelectSingleNode("@PO_NUMBER", NamespaceManager).Value;
string qty_on_po = rows.Current.SelectSingleNode("@QTY_ON_PO", NamespaceManager).Value;
string line = rows.Current.SelectSingleNode("@LINE", NamespaceManager).Value;
string description = rows.Current.SelectSingleNode("@DESCRIPTION", NamespaceManager).Value;
string start_box = rows.Current.SelectSingleNode("@BOX_START", NamespaceManager).Value;
string end_box = rows.Current.SelectSingleNode("@BOX_END", NamespaceManager).Value;
string parts_per_box = rows.Current.SelectSingleNode("@PARTS_PER_BOX", NamespaceManager).Value;
string run_time = rows.Current.SelectSingleNode("@RUN_TIME", NamespaceManager).Value;
if (run_time == null) {
run_time = "";
}
string setup_time = rows.Current.SelectSingleNode("@SETUP_TIME", NamespaceManager).Value;
if (setup_time == null) {
setup_time = "";
}
string comments = rows.Current.SelectSingleNode("@COMMENTS", NamespaceManager).Value;
if (comments == null) {
comments = "";
}
// Add the item to the repeating table
AddItem(po_number, qty_on_po, line, description, start_box, end_box, parts_per_box, run_time, setup_time, comments);
}
// Remove the first empty item from the repeating table
DeleteFirstEmptyItem();
}