Exemplo n.º 1
0
        public byte[] GetPdfTpuStampeBUS(XmlDocument tpu, XmlDocument pru)
        {
            Com.Delta.Print.PDFBuilder b = new Com.Delta.Print.PDFBuilder(new PRUBuilder(pru.InnerXml, null));
            b.setTPU(tpu);
            System.IO.Stream str = null;
            byte[]           ser = null;
            try
            {
                XDocument xTpu = XDocument.Parse(tpu.InnerXml);
                //elementi picture
                var picturesTag = from nd in xTpu.Root.DescendantNodesAndSelf().OfType <XElement>()
                                  where nd.Name.LocalName.Equals("pictureBox")
                                  select nd;
                //estrae gli attributi delle picture
                var pictures = from nd in picturesTag
                               select new
                {
                    Name     = nd.Attribute("name").Value,
                    FileName = nd.Element("file").Attribute("value").Value,
                    Width    = int.Parse(nd.Attribute("width").Value),
                    Heigth   = int.Parse(nd.Attribute("height").Value)
                };
                //aggiunge le picture alla stampa
                foreach (var pic in pictures)
                {
                    String keyImg = System.IO.Path.GetFileNameWithoutExtension(pic.FileName);

                    Com.Delta.Web.Cache.Types.TpuBinaryResource im =
                        CacheManager <Com.Delta.Web.Cache.Types.TpuBinaryResource> .get(
                            (CacheKeys)Enum.Parse(typeof(CacheKeys), keyImg, true),
                            VincoloType.FILESYSTEM);

                    System.IO.MemoryStream ms = new System.IO.MemoryStream(im.File);
                    System.Drawing.Bitmap  bb = (System.Drawing.Bitmap)System.Drawing.Bitmap.FromStream(ms);
                    b.AddImage(pic.Name, bb, true);
                }
                ser = b.CreatePDF();
            }
            catch
            {
            }
            return(ser);
        }
Exemplo n.º 2
0
        public byte[] GetPdfTpuStampeTableBUS(XmlDocument tpu, XmlDocument pru)
        {
            ReportDocument document = new ReportDocument();

            document.setXML(tpu, tpu.DocumentElement.Name);
            System.IO.Stream str = null;
            Hashtable        ht  = new Hashtable();

            XmlDocument XMLData = new XmlDocument();

            XMLData.LoadXml(pru.OuterXml);

            // Estrae i valori dei parametri
            System.Xml.XmlNodeList nl = XMLData.SelectNodes("params/p");
            foreach (System.Xml.XmlNode xn in nl)
            {
                ht.Add(xn.Attributes["name"].Value, xn.InnerText);
            }

            document.SetParameters(ht);

            // Estrae le tabelle
            DataTable        dt          = new DataTable();
            StringCollection sCollection = new StringCollection();

            System.Xml.XmlNodeList nlt = XMLData.SelectNodes("params/t");
            foreach (System.Xml.XmlNode xn in nlt)
            {
                sCollection.Add(xn.InnerXml);
            }
            DataSet ds = new DataSet();

            System.IO.MemoryStream memStream;
            System.IO.StreamWriter sWriter;

            foreach (string tabella in sCollection)
            {
                ds.Tables.Clear();
                memStream = new System.IO.MemoryStream();
                sWriter   = new System.IO.StreamWriter(memStream);
                sWriter.Write(tabella);

                sWriter.Flush();
                memStream.Position = 0;

                ds.ReadXml(memStream);

                if (ds.Tables.Count > 0)
                {
                    dt = ds.Tables[0];
                }

                sWriter.Dispose();
                memStream.Dispose();
            }
            document.AddData(dt);
            byte[] ser = null;
            try
            {
                XDocument xTpu = XDocument.Parse(tpu.InnerXml);
                //elementi picture
                var picturesTag = from nd in xTpu.Root.DescendantNodesAndSelf().OfType <XElement>()
                                  where nd.Name.LocalName.Equals("pictureBox")
                                  select nd;
                //estrae gli attributi delle picture
                var pictures = from nd in picturesTag
                               select new
                {
                    Name     = nd.Attribute("name").Value,
                    FileName = nd.Element("file").Attribute("value").Value,
                    Width    = int.Parse(nd.Attribute("width").Value),
                    Heigth   = int.Parse(nd.Attribute("height").Value)
                };
                //aggiunge le picture alla stampa
                foreach (var pic in pictures)
                {
                    String keyImg = System.IO.Path.GetFileNameWithoutExtension(pic.FileName);

                    Com.Delta.Web.Cache.Types.TpuBinaryResource im =
                        CacheManager <Com.Delta.Web.Cache.Types.TpuBinaryResource> .get(
                            (CacheKeys)Enum.Parse(typeof(CacheKeys), keyImg, true),
                            VincoloType.FILESYSTEM);

                    System.IO.MemoryStream ms = new System.IO.MemoryStream(im.File);
                    System.Drawing.Bitmap  bb = (System.Drawing.Bitmap)System.Drawing.Bitmap.FromStream(ms);
                    document.AddPicture(pic.Name, bb, true);
                }

                ser = document.SerializeToPdfStream();
            }
            catch
            {
            }
            return(ser);
        }