private void AddRepeatSectoin(WordGroupDef wordDoc, XmlNode node) { var dataSetAttr = node.Attributes != null ? node.Attributes["dataset"] : null; var dataSet = dataSetAttr != null ? _dataSets[dataSetAttr.Value] : _dataSets.First().Value; var reset = node.Attributes != null && node.Attributes["reset"] != null; var oldStyle = new ContentStyle(_style); try { SetSectionStyle(node); var section = new WordRepeatSectionDef(dataSet) { Style = _style }; wordDoc.AddItem(section); _dataSetStack.Push(dataSet); try { section.ResetDatas = reset; BuildSections(section, node); } finally { _dataSetStack.Pop(); } } finally { _style.Assign(oldStyle); } }
private void AddTextOrField(WordGroupDef paraDef, XmlNode node) { if (node.NodeType == XmlNodeType.Element && String.Equals(node.Name, "field", StringComparison.OrdinalIgnoreCase)) { var dataSetAttr = node.Attributes != null ? node.Attributes["dataset"] : null; var dataSet = (dataSetAttr != null ? _dataSets[dataSetAttr.Value] : FindDataSetByFieldName(node.InnerText.Trim()) ?? _dataSetStack.Peek()) as SqlQueryDataSet; var format = node.Attributes != null ? node.Attributes["format"] : null; var funcName = node.Attributes != null ? node.Attributes["func"] : null; Func <object, object> func = null; if (funcName != null) { Functions.TryGetValue(funcName.Value, out func); } if (dataSet != null) { paraDef.AddItem( new WordDataField(dataSet.CreateField(node.InnerText.Trim()), format != null ? format.Value : null) { Style = _style, Func = func }); } } else { AddText(paraDef, node); } }
private static void AddPageBreak(WordGroupDef wordDoc, XmlNode node) { var step = 0; var stepAttr = node.Attributes != null ? node.Attributes["step"] : null; if (stepAttr != null) { int.TryParse(stepAttr.Value, out step); } wordDoc.AddItem(new PageBreak { Step = step }); }
private WordParagraphDef AddParagraph(WordGroupDef wordDoc, XmlNode node) { _paragraphCount++; var oldStyle = new ContentStyle(_style); try { SetTextStyle(node); SetSectionStyle(node); var pd = new WordParagraphDef(String.Empty, _style); wordDoc.AddItem(pd); if (node.NodeType == XmlNodeType.Text) { pd.AddItem(new WordParagraphTextDef(node.InnerText)); } else if (node.NodeType == XmlNodeType.Element) { if (!node.HasChildNodes) { pd.AddItem(new WordParagraphTextDef(node.InnerText) { Style = _style }); } else { foreach (XmlNode child in node.ChildNodes) { if (child.NodeType == XmlNodeType.Element && String.Equals(child.Name, "repeat", StringComparison.OrdinalIgnoreCase)) { AddRepeatSectoin(pd, child); } else { AddText(pd, child); } } } } return(pd); } finally { _style.Assign(oldStyle); _paragraphCount--; } }
private void AddTable(WordGroupDef wordDoc, XmlNode table) { var oldStyle = new ContentStyle(_style); try { SetSectionStyle(table); var tableDef = new WordTableDef { Style = _style }; wordDoc.AddItem(tableDef); var tableFullWidth = table.Attributes != null ? table.Attributes["fullwidth"] : null; tableDef.FitWidth = tableFullWidth != null; // var rowNo = 0; var repeatSection = true; foreach (XmlNode child in table.ChildNodes) { if (String.Equals(child.Name, "tr", StringComparison.OrdinalIgnoreCase)) { var tableSectionDef = repeatSection ? tableDef.AddSection(new WordTableSectionDef()) : tableDef.Sections.LastOrDefault(); AddTableRow(tableSectionDef, child /*, ref rowNo*/); repeatSection = false; } else if (String.Equals(child.Name, "repeat", StringComparison.OrdinalIgnoreCase)) { AddTableRepeatSection(tableDef, child /*, ref rowNo*/); repeatSection = true; } } } finally { _style.Assign(oldStyle); } }
private void AddText(WordGroupDef paraDef, XmlNode node) { var oldStyle = new ContentStyle(_style); try { SetTextStyle(node); SetSectionStyle(node); if (node.NodeType == XmlNodeType.Text) { paraDef.AddItem(new WordParagraphTextDef(node.InnerText) { Style = _style }); } else if (node.NodeType == XmlNodeType.Whitespace) { paraDef.AddItem(new WordParagraphTextDef(node.InnerText) { Style = _style }); } else if (node.NodeType == XmlNodeType.Element) { if (!node.HasChildNodes) { paraDef.AddItem(new WordParagraphTextDef(node.InnerText) { Style = _style }); } else if (node.NodeType == XmlNodeType.Element && String.Equals(node.Name, "field", StringComparison.OrdinalIgnoreCase)) { var dataSetAttr = node.Attributes != null ? node.Attributes["dataset"] : null; var dataSet = (dataSetAttr != null ? _dataSets[dataSetAttr.Value] : FindDataSetByFieldName(node.InnerText.Trim()) ?? _dataSetStack.Peek()) as SqlQueryDataSet; var format = node.Attributes != null ? node.Attributes["format"] : null; if (dataSet != null) { paraDef.AddItem( new WordDataField(dataSet.CreateField(node.InnerText.Trim()), format != null ? format.Value : null) { Style = _style }); } } else { foreach (XmlNode child in node.ChildNodes) { AddTextOrField(paraDef, child); } } } } finally { _style.Assign(oldStyle); } }
private void BuildSections(WordGroupDef wordDoc, XmlNode node) { if (node.NodeType == XmlNodeType.Element) { foreach (XmlNode child in node.ChildNodes) { if (child.NodeType == XmlNodeType.Text) { if (_paragraphCount == 0) { AddParagraph(wordDoc, child); } else { AddText(wordDoc, child); } } else if (child.NodeType == XmlNodeType.Element) { if (String.Equals(child.Name, "p", StringComparison.OrdinalIgnoreCase)) { if (_paragraphCount == 0) { AddParagraph(wordDoc, child); } else { AddText(wordDoc, child); } } else if (String.Equals(child.Name, "center", StringComparison.OrdinalIgnoreCase)) { if (_paragraphCount == 0) { AddParagraph(wordDoc, child); } else { AddText(wordDoc, child); } } else if (String.Equals(child.Name, "left", StringComparison.OrdinalIgnoreCase)) { if (_paragraphCount == 0) { AddParagraph(wordDoc, child); } else { AddText(wordDoc, child); } } else if (String.Equals(child.Name, "right", StringComparison.OrdinalIgnoreCase)) { if (_paragraphCount == 0) { AddParagraph(wordDoc, child); } else { AddText(wordDoc, child); } } else if (String.Equals(child.Name, "both", StringComparison.OrdinalIgnoreCase)) { if (_paragraphCount == 0) { AddParagraph(wordDoc, child); } else { AddText(wordDoc, child); } } else if (String.Equals(child.Name, "table", StringComparison.OrdinalIgnoreCase)) { AddTable(wordDoc, child); } else if (String.Equals(child.Name, "repeat", StringComparison.OrdinalIgnoreCase)) { AddRepeatSectoin(wordDoc, child); } // TODO: Дописать для FIELD!!!! else if (String.Equals(child.Name, "field", StringComparison.OrdinalIgnoreCase)) { //var pd = wordDoc.AddParagraph(String.Empty, _style); AddTextOrField(wordDoc, child); } else if (String.Equals(child.Name, "pagebreak", StringComparison.OrdinalIgnoreCase)) { //wordDoc.AddItem(new PageBreak()); AddPageBreak(wordDoc, child); } } } } }