So someone on this forum might have an good input to how to solve this easy, I'm trying to wrap my head around what might be the best ide to this. Below is a extract of my code and what it does is read incoming message which in this case is a XML that has declaration like this
<Key> Avg_exkl_moms </Key>
<Value>123</Value>
<Key> Tjal_exkl_moms </Key>
<Value>321</Value>
<Key> Prov_exkl_moms </Key>
<Value>7375</Value>
<Key> Avg _moms </Key>
<Value>13</Value>
<Key> Tjal _moms </Key>
<Value>31</Value>
<Key> Prov _moms </Key>
<Value>75</Value>
<Key> Avg_ inkl _moms </Key>
<Value>456</Value>
<Key> Tjal_ inkl _moms </Key>
<Value>555</Value>
<Key> Prov_ inkl _moms </Key>
<Value>555</Value>
The word document has the corresponding contentControlTagName so Avg_inkl_moms will be populated with the filed value which is 7375 Below is the extracted code that does fil the document.
private static void FillContentControls(Dictionary<string, string> parameters, MemoryStream stream)
{
using (WordprocessingDocument wordDoc = WordprocessingDocument.Open(stream, true))
{
foreach (KeyValuePair<string, string> parameter in parameters)
{
string contentControlTagName = parameter.Key;
string newValue = parameter.Value;
IEnumerable<XElement> contentControls = wordDoc.MainDocumentPart.GetXDocument().Descendants(sdt)
.Elements(sdtContent)
.Descendants(wordText)
.Where(e => ((string)e.Ancestors(sdt)
.Elements(sdtPr)
.Elements(tag)
.Attributes(tagVal).First().Value == contentControlTagName));
int i = 0;
foreach (XElement element in contentControls)
{
element.Value = (i == 0 ? newValue : String.Empty);
i++;
}
Now what I would like to do is to SUM the different values
Avg_exkl_moms + Tjal_exkl_moms + Prov_exkl_moms = total_exlk_moms
Avg_moms + Tjal_moms + Prov_moms = total_moms
Avg_inkl_moms + Tjal_ inkl _moms + Prov_ inkl _moms = total_ inkl _moms
And then place them in corresponding contentControlTagName.
Any suggestions on how to approach this ?
Just pretty basic, created 3 lists which adds all the values and then sum it all up.