Exemplo n.º 1
0
        public bool ProcessMap(decimal[] bulding_ids, Stream childFS, ref Novacode.DocX docx)
        {
            using (var childDocx = Novacode.DocX.Load(childFS))
            {
                using (MemoryStream memStream = new MemoryStream())
                {
                    WebRequest request = WebRequest.Create(
                           "https://maps.googleapis.com/maps/api/staticmap?format=jpg&center=Calgary&zoom=14&size=400x400&key=AIzaSyB64gJHrp5QzW2fNMVRvRygTm8wCuBIrnc");

                    // 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);
                    }
                    memStream.Seek(0, SeekOrigin.Begin);
                    try
                    {
                        Novacode.Image img = childDocx.AddImage(memStream); // Create image.
                        Novacode.Picture pic1 = img.CreatePicture();     // Create picture.
                        Novacode.Paragraph p = childDocx.InsertParagraph();
                        p.InsertPicture(pic1); // Insert picture into paragraph.
                    }
                    catch (Exception ex)
                    {
                        Novacode.Paragraph p = childDocx.InsertParagraph(ex.Message + " " + ex.StackTrace);
                    }
                    docx.InsertSectionPageBreak();
                    docx.InsertDocument(childDocx);

                }

            }

            return true;
        }
Exemplo n.º 2
0
        private bool ProcessDocument(decimal childId, Dictionary<string, object> b, IEnumerable<Dictionary<string, object>> buildings, int index, ref Novacode.DocX docx, string [] zoom, string [] lat, string [] lng)
        {
            OracleRepository repo = new OracleRepository();
            string docType;
            using (Stream childFS = repo.LoadDocument(childId.ToString(), out docType))
            {
                //process floorplan and maps here
                if (docType == "FLOORPLAN")
                {
                    List<string> floorList = new List<string>();
                    floorList.Add(String.Format("{0}", b["FLOOR"]));
                    ProcessFloorplan((decimal)b["BUILDING_ID"], (decimal)b["BUILDING_VACANCY_ID"], (string)b["FLOOR"], childFS, ref docx);
                }
                else if (docType == "MAP")
                {
                    if (index == 1)
                    {

                        List<decimal> ids = new List<decimal>();
                        foreach (var b1 in buildings)
                        {
                            ids.Add((decimal)b1["BUILDING_ID"]);
                        }
                        ProcessPicture(ids, childFS, ref docx, zoom, lat, lng);
                        // ProcessMap(ids.ToArray(), childFS, ref docx);
                    }
                }
                else
                {
                    var docxChild = Novacode.DocX.Load(childFS);
                    foreach (var bm in docxChild.Bookmarks.Where(x => x.Name == "IMAGE"))
                    {
                        string filename;

                        using (var picStream = repo.GetBuildingPicture((decimal)b["BUILDING_ID"], out filename))
                        {
                            if (!String.IsNullOrEmpty(filename))
                            {
                                double newHeight = 1;
                                using (var tempImg = System.Drawing.Image.FromStream(picStream))
                                {
                                    newHeight = (tempImg.Height / tempImg.Width) * 300;
                                }

                                picStream.Seek(0, SeekOrigin.Begin);
                                Novacode.Image img = docxChild.AddImage(picStream); // Create image.

                                Novacode.Picture pic1 = img.CreatePicture((int)newHeight,300);     // Create picture.
                                bm.Paragraph.AppendPicture(pic1);
                            }

                        }
                    }
                    foreach (var k in b.Keys)
                    {
                        docxChild.ReplaceText(String.Format("<{0}>", k), String.Format("{0}", b[k]));
                    }
                    if (docxChild.FindAll("<PARKING_LIST>").Count() > 0)
                    {
                        ProcessParkingList((decimal)b["BUILDING_ID"], ref docxChild);
                    }
                    else
                    {
                        docxChild.ReplaceText("<PARKING_LIST>", "");
                    }

                    docx.InsertSectionPageBreak();
                    docx.InsertDocument(docxChild);

                }
            }
            return true;
        }
Exemplo n.º 3
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;
        }
Exemplo n.º 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;
        }