Ejemplo n.º 1
0
        public override void Load(System.Xml.XmlNode element)
        {
            base.Load(element);

            UnitsManager unitMng = new UnitsManager();

            // Load info
            XmlNode node = element.SelectSingleNode("Info");

            if (node != null)
            {
                this.Description = node.Attributes["Description"].Value;
            }

            // Load page size
            node = element.SelectSingleNode("Size");
            if (node != null)
            {
                MeasureUnit   = unitMng.StringToUnit(node.Attributes["Width"].Value);
                WidthInUnits  = (float)(System.Convert.ToDouble(node.Attributes["Width"].Value.TrimEnd(unitMng.UnitToString(MeasureUnit).ToCharArray())));
                HeightInUnits = (float)(System.Convert.ToDouble(node.Attributes["Height"].Value.TrimEnd(unitMng.UnitToString(MeasureUnit).ToCharArray())));
            }
            else
            {
                // set default sizes
                MeasureUnit    = MeasureUnits.cm;
                WidthInUnits   = (float)unitMng.ConvertUnit(19, MeasureUnits.cm, MeasureUnits.point);
                HeightInPixels = (float)unitMng.ConvertUnit(21, MeasureUnits.cm, MeasureUnits.point);
            }

            // Load fill color
            node = element.SelectSingleNode("FillColor");
            if (node != null)
            {
                try
                {
                    int r = Convert.ToInt32(node.Attributes["R"].Value);
                    int g = Convert.ToInt32(node.Attributes["G"].Value);
                    int b = Convert.ToInt32(node.Attributes["B"].Value);
                    int a = Convert.ToInt32(node.Attributes["A"].Value);
                    this.FillColor = Color.FromArgb(a, r, g, b);
                }
                catch { }
            }

            // Load BackgroundImageName
            node = element.SelectSingleNode("BackgroundImage");
            if (node != null)
            {
                this.imageName = node.Attributes["Name"].Value;
            }

            // load embedded image if available
            node = element.SelectSingleNode("EmbeddedImage");
            if (node != null)
            {
                if (node.InnerText != null && node.InnerText.Length > 0)
                {
                    this.imageData    = Convert.FromBase64String(node.InnerText);
                    pictureForDisplay = Bitmap.FromStream(new MemoryStream(this.imageData));
                }
            }



            // Load none balloons items
            node = element.SelectSingleNode("Items");
            if (node != null)
            {
                foreach (XmlNode childNode in node.ChildNodes)
                {
                    if (childNode.Name == "Item")
                    {
                        // this is not valid for generator but this can be loaded into editor
                        string     itemType = childNode.Attributes["Type"].Value;
                        EditorItem newItem  = ReportPage.CreateItemFromType(itemType);
                        newItem.Load(childNode);
                        newItem.Parent = this;
                        //Children.Add(newItem);
                    }
                }
            }


            // Load balloons
            node = element.SelectSingleNode("Balloons");
            if (node != null)
            {
                foreach (XmlNode balloonNode in node.ChildNodes)
                {
                    if (balloonNode.Name == "Balloon")
                    {
                        string tmpType;
                        tmpType = balloonNode.Attributes["Type"].Value;
                        if (tmpType == "Static")
                        {
                            StaticBalloon child = new StaticBalloon();
                            //child.Parent = this;
                            child.Load(balloonNode);
                            child.Parent = this;
                            //Children.Add(child);
                        }
                        else if (tmpType == "Dynamic")
                        {
                            DynamicBalloon child = new DynamicBalloon();
                            //child.Parent = this;
                            child.Load(balloonNode);
                            child.Parent = this;
                            //Children.Add(child);
                        }
                    }
                    else if (balloonNode.Name == "Item")
                    {
                        // this is not valid for generator but this can be loaded into editor
                        string     itemType = balloonNode.Attributes["Type"].Value;
                        EditorItem newItem  = ReportPage.CreateItemFromType(itemType);
                        newItem.Load(balloonNode);
                        newItem.Parent = this;
                        //Children.Add(newItem);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public override void SaveItem(XmlDocument doc, XmlElement element)
        {
            XmlElement el = doc.CreateElement("Page");

            base.SaveItem(doc, el);


            UnitsManager unitMng = new UnitsManager();

            XmlAttribute attr = doc.CreateAttribute("Version");

            attr.Value = "1.0";
            el.SetAttributeNode(attr);

            // save info
            XmlElement el2 = doc.CreateElement("Info");

            attr       = doc.CreateAttribute("Description");
            attr.Value = this.Description;
            el2.SetAttributeNode(attr);
            el.AppendChild(el2);

            // save size
            el2        = doc.CreateElement("Size");
            attr       = doc.CreateAttribute("Width");
            attr.Value = this.WidthInUnits.ToString() + unitMng.UnitToString(MeasureUnit);
            el2.SetAttributeNode(attr);

            attr       = doc.CreateAttribute("Height");
            attr.Value = this.HeightInUnits.ToString() + unitMng.UnitToString(MeasureUnit);
            el2.SetAttributeNode(attr);
            el.AppendChild(el2);

            // FillColor
            el2  = doc.CreateElement("FillColor");
            attr = doc.CreateAttribute("R"); attr.Value = this.FillColor.R.ToString(); el2.SetAttributeNode(attr);
            attr = doc.CreateAttribute("G"); attr.Value = this.FillColor.G.ToString(); el2.SetAttributeNode(attr);
            attr = doc.CreateAttribute("B"); attr.Value = this.FillColor.B.ToString(); el2.SetAttributeNode(attr);
            attr = doc.CreateAttribute("A"); attr.Value = this.FillColor.A.ToString(); el2.SetAttributeNode(attr);
            el.AppendChild(el2);

            el2        = doc.CreateElement("BackgroundImage");
            attr       = doc.CreateAttribute("Name");
            attr.Value = this.ImageName;
            el2.SetAttributeNode(attr);
            el.AppendChild(el2);


            // embedd image data here if embeddImageToTemplate is used
            el2        = doc.CreateElement("EmbeddedImage");
            attr       = doc.CreateAttribute("Name");
            attr.Value = this.ImageName;
            el2.SetAttributeNode(attr);

            if (imageData != null && imageData.Length > 0)
            {
                attr = doc.CreateAttribute("EmbeddedDecodedImageLength"); attr.Value = imageData.Length.ToString(); el2.SetAttributeNode(attr);
                XmlText textValue = doc.CreateTextNode("EmdeddedImageData");
                textValue.Value = Convert.ToBase64String(imageData);
                attr            = doc.CreateAttribute("EmbeddedImageLength"); attr.Value = textValue.Value.Length.ToString(); el2.SetAttributeNode(attr);
                el2.AppendChild(textValue);
            }
            el.AppendChild(el2);

            // save children without balloons
            el2 = doc.CreateElement("Items");
            foreach (EditorItem child in this.Children)
            {
                if (child is Balloon)
                {
                }
                else
                {
                    child.Save(doc, el2);
                }
            }
            el.AppendChild(el2);


            // save children with balloons
            el2 = doc.CreateElement("Balloons");
            foreach (EditorItem child in this.Children)
            {
                if (child is Balloon)
                {
                    child.Save(doc, el2);
                }
            }
            el.AppendChild(el2);

            element.AppendChild(el);
        }