예제 #1
0
        public bool ProcessFloorplan(decimal building_id, decimal building_vacancy_id, string building_vacancy_floor, Stream childFS, ref Novacode.DocX docx)
        {
            try
            {
                OracleRepository repo = new OracleRepository();

                string qry = String.Format(@" SELECT ID,FLOOR_NO  FROM TBUILDING_PICTURES WHERE BUILDING_ID ={0} AND BUILDING_VACANCY_ID = {1}", building_id, building_vacancy_id);

                var floors = repo.QueryAll(qry);
                string filename = "";
                string floor_no = "";
                foreach (var floor in floors)
                {
                    using (var childDocx = Novacode.DocX.Load(childFS))
                    {
                        using (var picStream = repo.GetPicture((decimal)floor["ID"], out filename, out floor_no))
                        {
                            int newHeight = 300;
                            using (var tempImg = System.Drawing.Bitmap.FromStream(picStream))
                            {
                                newHeight = (int)Math.Round(((double)tempImg.Height / (double)tempImg.Width) * 300);
                                using (System.Drawing.Bitmap bt = new System.Drawing.Bitmap(tempImg, 300, newHeight))
                                {
                                    using (MemoryStream ms = new MemoryStream())
                                    {
                                        bt.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
                                        ms.Seek(0, SeekOrigin.Begin);
                                        Novacode.Image img = childDocx.AddImage(ms); // Create image.
                                        Novacode.Picture pic1 = img.CreatePicture();     // Create picture.
                                        Novacode.Paragraph p = childDocx.InsertParagraph();
                                        p.InsertPicture(pic1); // Insert picture into paragraph.
                                    }
                                }
                            }
                        }
                        string picDesc = "";
                        if (floor["FLOOR_NO"]!=null && floor["FLOOR_NO"] != System.DBNull.Value)
                        {
                            picDesc = String.Format("({0})", floor["FLOOR_NO"]);
                        }
                        childDocx.ReplaceText(String.Format("<{0}>", "FLOOR_NO"), String.Format("{0}{1}", building_vacancy_floor, picDesc));
                        docx.InsertSectionPageBreak();
                        docx.InsertDocument(childDocx);

                    }
                }

            }
            catch { }
            return true;
        }
예제 #2
0
        protected bool ProcessFloorplan(Dictionary<string, Tuple<string, decimal>> floorplans, WordprocessingDocument wordDoc, List<SizeAttribute> sa)
        {
            OracleRepository repo = new OracleRepository();
            string imageid = "";
            string filename = "";
            string floor_no = "";
            foreach (var floor in floorplans.Keys)
            {
                using (var picStream = repo.GetPicture(floorplans[floor].Item2, out filename, out floor_no))
                {
                    picStream.Position = 0;
                    MainDocumentPart mainPart = wordDoc.MainDocumentPart;
                    ImagePart imagePart = mainPart.AddImagePart(ImagePartType.Jpeg);
                    imagePart.FeedData(picStream);

                    imageid = mainPart.GetIdOfPart(imagePart);
                }

                foreach (var txt in wordDoc.MainDocumentPart.Document.Body.Descendants<Text>().Where(x => x.Text == floor))
                {
                    try
                    {
                        long width = 3813048;
                        long height = 3813048;
                        foreach (var s in sa)
                        {
                            if (s.TransformedValue == txt.Text)
                            {
                                width = s.Width;
                                height = s.Height;
                            }
                        }
                        var el = AddImageToBody(imageid, width, height);
                        txt.Parent.AppendChild(el);
                        txt.Text = "";
                    }
                    catch { }
                }
            }

            return true;
        }
예제 #3
0
 public ActionResult GetPicture(decimal id)
 {
     OracleRepository repo = new OracleRepository();
     string filename;
     string floor_no;
     Stream st = repo.GetPicture(id, out filename, out floor_no);
     if (String.IsNullOrEmpty(filename))
     {
         filename = "unknown";
     }
     var cd = new System.Net.Mime.ContentDisposition
     {
         FileName = filename
     };
     Response.AppendHeader("Content-Disposition", cd.ToString());
     st.Position = 0;
     string mime = System.Web.MimeMapping.GetMimeMapping(filename);
     return new FileStreamResult(st, mime);
 }
예제 #4
0
        public bool ProcessPicture(List<decimal> building_ids, Stream childFS, ref Novacode.DocX docx, string [] zoom, string []lat, string []lng)
        {
            try
            {
                OracleRepository repo = new OracleRepository();

                var floors = repo.QueryAll(
                    String.Format(@" SELECT ID FROM TBUILDING_PICTURES WHERE BUILDING_ID ={0} ", 0));
                string filename = "";
                string floor_no = "";
                foreach (var floor in floors)
                {
                    using (var childDocx = Novacode.DocX.Load(childFS))
                    {
                        using (var picStream = repo.GetPicture((decimal)floor["ID"], out filename, out floor_no))
                        {
                            picStream.Seek(0, SeekOrigin.Begin);
                            Novacode.Image img = childDocx.AddImage(picStream); // Create image.
                            Novacode.Picture pic1 = img.CreatePicture(1, 1);     // Create picture.
                            Novacode.Paragraph p = childDocx.InsertParagraph();
                            p.InsertPicture(pic1); // Insert picture into paragraph.
                        }

                        string markers = "";
                        string building_id_csv = "";
                        List<string> buildingList = new List<string>();
                        foreach (var bid in building_ids)
                        {
                            if (String.IsNullOrEmpty(building_id_csv))
                            {
                                building_id_csv = bid.ToString();
                            }
                            else
                            {
                                building_id_csv += "," + bid;
                            }
                        }
                        var latLongs = repo.QueryAll(
                          String.Format(@" SELECT TBUILDING.BUILDING_NAME, LATITUDE, LONGITUDE FROM TBUILDING_LAT_LONG
                                                INNER JOIN TBUILDING ON TBUILDING_LAT_LONG.BUILDING_ID= TBUILDING.BUILDING_ID
                                                WHERE TBUILDING_LAT_LONG.BUILDING_ID  IN ({0}) ", building_id_csv));

                        int index = 0;
                        foreach (var latLong in latLongs)
                        {
                            index++;
                            markers += String.Format("&markers=label:{0}%7C{1},{2}", index, latLong["LATITUDE"], latLong["LONGITUDE"]);
                            buildingList.Add(index  + "." + latLong["BUILDING_NAME"]);
                        }

                        string zoomAmt = "";
                        string center = "";
                        if (zoom.Count()>0)
                        {
                            int z = 14;
                            if (int.TryParse(zoom[0], out z))
                            {
                                zoomAmt = "&zoom=" + z;
                            }
                        }
                        if (lat.Count()>0 && lng.Count()>0)
                        {
                            double latAmt = 0;
                            double lngAmt = 0;
                            if (double.TryParse(lat[0], out latAmt) && double.TryParse(lng[0], out lngAmt))
                            {
                                center = String.Format("&center={0},{1}", latAmt, lngAmt);
                            }
                        }
                        using (MemoryStream memStream = new MemoryStream())
                        {

                            WebRequest request = WebRequest.Create(
                                   String.Format("https://maps.googleapis.com/maps/api/staticmap?format=jpg{0}{1}{2}&size=400x400&key=AIzaSyB64gJHrp5QzW2fNMVRvRygTm8wCuBIrnc", markers, zoomAmt, center));

                            // Get the response.
                            WebResponse response = request.GetResponse();
                            // Get the stream containing content returned by the server.
                            Stream dataStream = response.GetResponseStream();
                            using (Stream rStream = response.GetResponseStream())
                            {

                                byte[] buffer = new byte[1024];
                                int byteCount;
                                do
                                {
                                    byteCount = rStream.Read(buffer, 0, buffer.Length);
                                    memStream.Write(buffer, 0, byteCount);
                                } while (byteCount > 0);
                            }
                            double newHeight = 1;
                            using (var tempImg = System.Drawing.Image.FromStream(memStream))
                            {
                                newHeight = (tempImg.Height / tempImg.Width) * 400;
                            }
                            memStream.Seek(0, SeekOrigin.Begin);
                            try
                            {

                                Novacode.Image img = childDocx.AddImage(memStream); // Create image.
                                Novacode.Picture pic1 = img.CreatePicture((int)newHeight,400);     // Create picture.
                                Novacode.Paragraph p = childDocx.InsertParagraph();
                                p.InsertPicture(pic1); // Insert picture into paragraph.
                                foreach (var s in buildingList)
                                {
                                    childDocx.InsertParagraph(s);
                                }
                            }
                            catch (Exception ex)
                            {
                                Novacode.Paragraph p = childDocx.InsertParagraph(ex.Message + " " + ex.StackTrace);
                            }
                            docx.InsertSectionPageBreak();
                            docx.InsertDocument(childDocx);

                        }
                    }
                }
            }
            catch { }
            return true;
        }