Hi,
I have a simple dataset with 3 tables:
Main (just parent entry)
Itemrows (rows belong to main entry)
Total (total belong to main entry)
If I merge these with a document (see down below), it only merges the Main and leaves the rest for what it is.
My document as the following setup:
«GroupStart:Main»«Description»
«TableStart:Itemrows»«Rowdesc»«RowPriceO»«Rowpricem»«TableEnd:Itemrows»
test
«TableStart:Total»«Rowpriceot»«Rowpricemt»«TableEnd:Total»
«GroupEnd:Main»
I fill the dataset mainly by simple code:
//Merge Calculation fields.
DataSet ds = new DataSet();
//Main entry
ds.Tables.Add("Main");
ds.Tables["Main"].Columns.Add("Id", typeof(int));
ds.Tables["Main"].Columns.Add("Description", typeof(string));
//Add one entry row
ds.Tables["Main"].Rows.Add();
ds.Tables["Main"].Rows[0]["Id"] = 1;
ds.Tables["Main"].Rows[0]["Description"] = "Main Entry";
//Item Rows
ds.Tables.Add("Itemrows");
ds.Tables["Itemrows"].Columns.Add("Id", typeof(int));
ds.Tables["Itemrows"].Columns.Add("Mainid", typeof(int));
ds.Tables["Itemrows"].Columns.Add("Rowdesc", typeof(String));
ds.Tables["Itemrows"].Columns.Add("Rowpriceo", typeof(decimal));
ds.Tables["Itemrows"].Columns.Add("Rowpricem", typeof(decimal));
ds.Tables["Itemrows"].Columns["Id"].AutoIncrement = true;
//Total
ds.Tables.Add("Total");
ds.Tables["Total"].Columns.Add("Id", typeof(int));
ds.Tables["Total"].Columns.Add("Mainid", typeof(int));
ds.Tables["Total"].Columns.Add("Rowpriceot", typeof(decimal));
ds.Tables["Total"].Columns.Add("Rowpricemt", typeof(decimal));
ds.Tables["Total"].Columns["Id"].AutoIncrement = true;
decimal Tot_PriceOnce = 0;
decimal Tot_PriceMonthly = 0;
foreach (DOCU_DocTextCalcItem rw in ListOfDocTextCalcList)
{
ds.Tables["Itemrows"].Rows.Add();
ds.Tables["Itemrows"].Rows[ds.Tables["Itemrows"].Rows.Count - 1]["Mainid"] = 1;
ds.Tables["Itemrows"].Rows[ds.Tables["Itemrows"].Rows.Count - 1]["Rowdesc"] = rw.Description_Value;
ds.Tables["Itemrows"].Rows[ds.Tables["Itemrows"].Rows.Count - 1]["Rowpriceo"] = rw.PriceOnce;
ds.Tables["Itemrows"].Rows[ds.Tables["Itemrows"].Rows.Count - 1]["Rowpricem"] = rw.PriceMonthly;
Tot_PriceOnce += rw.PriceOnce;
Tot_PriceMonthly += rw.PriceMonthly;
}
ds.Tables["Total"].Rows.Add();
ds.Tables["Total"].Rows[ds.Tables["Total"].Rows.Count - 1]["Mainid"] = 1;
ds.Tables["Total"].Rows[ds.Tables["Total"].Rows.Count - 1]["Rowpriceot"] = Tot_PriceOnce;
ds.Tables["Total"].Rows[ds.Tables["Total"].Rows.Count - 1]["Rowpricemt"] = Tot_PriceMonthly;
List<DictionaryEntry> DicList = new List<DictionaryEntry>
{
new DictionaryEntry("Main", String.Empty),
new DictionaryEntry("Itemrows", "Mainid = %Main.Id%"),
new DictionaryEntry("Total", "Mainid = %Main.Id%")
};
FinalDocument.MailMerge.ClearFields = false;
FinalDocument.MailMerge.HideEmptyGroup = false;
FinalDocument.MailMerge.HideEmptyParagraphs = false;
int mergedRowIndex = 0;
FinalDocument.MailMerge.MergeField += delegate(object sender, Spire.Doc.Reporting.MergeFieldEventArgs e)
{
if (e.TableName == "Main")
{
if (e.RowIndex > mergedRowIndex)
{
mergedRowIndex = e.RowIndex;
//insert page break symbol before the paragraph of current field
//InsertPageBreak(e.CurrentMergeField);
}
}
else if (e.TableName == "Detail" && e.FieldName == "Discount")
{
double discount = Convert.ToDouble(e.FieldValue) * 100;
e.Text = Convert.ToString(discount);
}
};
FinalDocument.MailMerge.ExecuteWidthNestedRegion(ds,DicList);
Can anyone give me a hint?
Thx a lot,
S