Example #1
0
        public override void CreateFromTemplate(XElement node, Hashtable boundFields)
        {
            base.CreateFromTemplate(node, boundFields);

            XAttribute tempAttr = node.Attribute("font");

            if (tempAttr != null)
            {
                font.LoadFromString(tempAttr.Value);
            }

            tempAttr = node.Attribute("text");
            if (tempAttr != null)
            {
                Text = tempAttr.Value;
            }

            tempAttr = node.Attribute("sourceField");
            if (tempAttr != null)
            {
                SourceField = tempAttr.Value;
            }

            tempAttr = node.Attribute("format");
            if (tempAttr != null)
            {
                Format = tempAttr.Value;
            }

            tempAttr = node.Attribute("sourceFormat");
            if (tempAttr != null)
            {
                SourceFormat = tempAttr.Value;
            }

            tempAttr = node.Attribute("trimming");
            if (tempAttr != null)
            {
                try {
                    Trimming = (StringTrimming)Enum.Parse(typeof(StringTrimming), tempAttr.Value, true);
                } catch {
                    Trimming = StringTrimming.None;
                }
            }

            tempAttr = node.Attribute("wrap");
            bool value;

            if (tempAttr != null && bool.TryParse(tempAttr.Value, out value))
            {
                Wrap = value;
            }

            RefreshBoundFields(boundFields);
        }
        public override void CreateFromTemplate(XElement node, Hashtable boundFields)
        {
            XAttribute tempAttr = node.Attribute("style");

            if (tempAttr != null)
            {
                style.LoadFromString(tempAttr.Value);
                itemStyle.LoadFromString(tempAttr.Value);
            }

            tempAttr = node.Attribute("font");
            if (tempAttr != null)
            {
                itemFont.LoadFromString(tempAttr.Value);
            }

            TextBox tb;

            tempAttr = node.Attribute("text");
            if (tempAttr != null)
            {
                tb       = DocumentHelper.FormObjectCreator.CreateTextBox();
                tb.Text  = tempAttr.Value;
                tb.Style = (ObjectStyle)itemStyle.Clone();
                tb.Font  = (ObjectFont)itemFont.Clone();
                itemTemplate.Clear();
                itemTemplate.Add(tb);
            }

            tempAttr = node.Attribute("sourceField");
            if (tempAttr != null)
            {
                tb             = DocumentHelper.FormObjectCreator.CreateTextBox();
                tb.SourceField = tempAttr.Value;
                if (boundFields [tempAttr.Value] != null)
                {
                    tb.Text = boundFields [tempAttr.Value].ToString();
                }
                tb.Style = (ObjectStyle)itemStyle.Clone();
                tb.Font  = (ObjectFont)itemFont.Clone();
                itemTemplate.Clear();
                itemTemplate.Add(tb);
            }

            foreach (XElement child in node.Elements())
            {
                XAttribute styleAttr;
                switch (child.Name.LocalName.ToLowerInvariant())
                {
                case "template":
                    styleAttr = child.Attribute("style");
                    if (styleAttr != null)
                    {
                        itemStyle.LoadFromString(styleAttr.Value);
                    }

                    if (child.HasElements)
                    {
                        CreateChildrenFromTemplate(child, boundFields, ref itemTemplate);
                    }
                    break;

                case "header":
                    styleAttr = child.Attribute("style");
                    if (styleAttr != null)
                    {
                        headerStyle.LoadFromString(styleAttr.Value);
                    }

                    tempAttr = node.Attribute("font");
                    if (tempAttr != null)
                    {
                        headerFont.LoadFromString(tempAttr.Value);
                    }

                    tempAttr = child.Attribute("text");
                    if (tempAttr != null)
                    {
                        tb       = DocumentHelper.FormObjectCreator.CreateTextBox();
                        tb.Text  = tempAttr.Value;
                        tb.Style = (ObjectStyle)headerStyle.Clone();
                        tb.Font  = (ObjectFont)headerFont.Clone();
                        headerTemplate.Clear();
                        headerTemplate.Add(tb);
                    }

                    tempAttr = child.Attribute("sourceField");
                    if (tempAttr != null)
                    {
                        tb             = DocumentHelper.FormObjectCreator.CreateTextBox();
                        tb.SourceField = tempAttr.Value;
                        tb.Text        = boundFields [tempAttr.Value].ToString();
                        tb.Style       = (ObjectStyle)headerStyle.Clone();
                        tb.Font        = (ObjectFont)headerFont.Clone();
                        headerTemplate.Clear();
                        headerTemplate.Add(tb);
                    }

                    if (child.HasElements)
                    {
                        CreateChildrenFromTemplate(child, boundFields, ref headerTemplate);
                    }
                    break;

                case "footer":
                    styleAttr = child.Attribute("style");
                    if (styleAttr != null)
                    {
                        footerStyle.LoadFromString(styleAttr.Value);
                    }

                    tempAttr = node.Attribute("font");
                    if (tempAttr != null)
                    {
                        footerFont.LoadFromString(tempAttr.Value);
                    }

                    tempAttr = child.Attribute("text");
                    if (tempAttr != null)
                    {
                        tb       = DocumentHelper.FormObjectCreator.CreateTextBox();
                        tb.Text  = tempAttr.Value;
                        tb.Style = (ObjectStyle)footerStyle.Clone();
                        tb.Font  = (ObjectFont)footerFont.Clone();
                        footerTemplate.Clear();
                        footerTemplate.Add(tb);
                    }

                    tempAttr = child.Attribute("sourceField");
                    if (tempAttr != null)
                    {
                        tb             = DocumentHelper.FormObjectCreator.CreateTextBox();
                        tb.SourceField = tempAttr.Value;
                        tb.Text        = boundFields [tempAttr.Value].ToString();
                        tb.Style       = (ObjectStyle)footerStyle.Clone();
                        tb.Font        = (ObjectFont)footerFont.Clone();
                        footerTemplate.Clear();
                        footerTemplate.Add(tb);
                    }

                    if (child.HasElements)
                    {
                        CreateChildrenFromTemplate(child, boundFields, ref footerTemplate);
                    }
                    break;
                }
            }
        }