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; }
public ActionResult GetListingPicture(decimal id) { OracleRepository repo = new OracleRepository(); string filename; Stream st = repo.GetBuildingPicture(id, out filename); 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); }
public ActionResult ApplyDocumentOpenXml(string id, string building_vacancy_ids, string[] zoom, string[] lat, string[] lng) { OracleRepository repo = new OracleRepository(); var buildings = repo.QueryAll(String.Format(@" Select VBUILDING.BUILDING_ID, VBUILDING.EXT_REF_ID, VBUILDING.BUILDING_NAME, VBUILDING.CLASS_TYP_ID, VBUILDING.CLASS_TYP, VBUILDING.LOCATION_TYP_ID, VBUILDING.LOCATION_TYP, VBUILDING.QRTRLY_RPT_FLAG, VBUILDING.CONTACT_MECH_ID, VBUILDING.ADDRESS1, VBUILDING.POSTAL_CODE, VBUILDING.YEAR_BUILT, VBUILDING.STOREYS, VBUILDING.NET_RENTABLE, VBUILDING.FLOOR_PLATE, VBUILDING.PARKING_RATIO, VBUILDING.PARKING_RATIO_FORMATTED, VBUILDING.LATEST_OP_COST_AMT, VBUILDING.OP_COST_YEAR, VBUILDING.LANDLORD_CONTACT_ID, VBUILDING.LANDLORD_NAME, VBUILDING.OWNER_CONTACT_ID, VBUILDING.OWNER_NAME, VBUILDING.CREATE_DATE, VBUILDING.CREATE_USER, VBUILDING.UPDATE_DATE, VBUILDING.UPDATE_USER, VBUILDING_VACANCY.BUILDING_VACANCY_ID, VBUILDING_VACANCY.LEASE_TYP_ID, VBUILDING_VACANCY.LEASE_TYP_CODE, VBUILDING_VACANCY.LEASE_TYP, VBUILDING_VACANCY.SUITE_NO, VBUILDING_VACANCY.FLOOR, VBUILDING_VACANCY.FLOOR_NUMERIC, VBUILDING_VACANCY.SIZE_SQ, VBUILDING_VACANCY.SMALLEST_DIV, VBUILDING_VACANCY.INDUCEMENTS, VBUILDING_VACANCY.BASE_RENT, VBUILDING_VACANCY.TERM, VBUILDING_VACANCY.ARCHIVED_YN, VBUILDING_VACANCY.LAST_ARCHIVED_DATE, VBUILDING_VACANCY.RETAIL_YN, VBUILDING_VACANCY.EXCLUSIVE_YN, VBUILDING_VACANCY.VACANCY_DESC, VBUILDING_VACANCY.BROKER_NOTES, TBUILDING_LAT_LONG.LATITUDE, TBUILDING_LAT_LONG.LONGITUDE from VBUILDING inner join VBUILDING_VACANCY on VBUILDING.BUILDING_ID= VBUILDING_VACANCY.BUILDING_ID left join TBUILDING_LAT_LONG on VBUILDING.BUILDING_ID = TBUILDING_LAT_LONG.BUILDING_ID where BUILDING_VACANCY_ID In ({0}) ORDER BY VBUILDING.BUILDING_NAME ", building_vacancy_ids)); Dictionary<string, Tuple<int, string,decimal>> buildingIndices = new Dictionary<string, Tuple<int, string, decimal>>(); Dictionary<string, Tuple<string, decimal>> floorplanIndices = new Dictionary<string, Tuple<string, decimal>>(); Dictionary<int, XElement> buildingXML = new Dictionary<int, XElement>(); Stream st = new MemoryStream(); string docType = "PARENT TEMPLATE"; List<SizeAttribute> sa = new List<SizeAttribute>(); string imageid = ""; using (Stream fs = repo.LoadDocument(id, out docType))//new MemoryStream())// { /* using (FileStream fs1 = System.IO.File.OpenRead(@"d:\CurrentDevelopment\Cresa\Cresa\templates\TOC.dotx")) { fs1.CopyTo(fs); }*/ WmlDocument wmlDoc = new WmlDocument("template1.docx", fs as MemoryStream, true); WmlDocument wmlAssembledDoc; var xml = GenerateDataFromDataSource(buildings.ToList(), ref buildingIndices, ref floorplanIndices, ref buildingXML); if (docType=="PARENT TEMPLATE") { List<Source> sources = new List<Source>(); sources.Add(new Source (wmlDoc,true)); List<Tuple<WmlDocument, string>> docs = new List<Tuple<WmlDocument,string>>(); docs = LoadDocuments(int.Parse(id)); int index = 0; foreach (var b in buildings.ToList()) { foreach (var d in docs) { if (index==0 || d.Item2=="DETAIL") { if (d.Item2 == "SUMMARY") { sources.Add(LoadDocumentToSource(d.Item1, xml,buildingIndices,zoom,lat,lng, sa)); } else { sources.Add(LoadDocumentToSource(d.Item1, buildingXML[index],null, null,null,null, sa)); } } } index++; } wmlAssembledDoc = DocumentBuilder.BuildDocument(sources); } else { bool templateError; wmlAssembledDoc = DocumentAssembler.AssembleDocument(wmlDoc, xml, out templateError, sa); } OpenXmlMemoryStreamDocument streamDoc = new OpenXmlMemoryStreamDocument(wmlAssembledDoc); streamDoc.GetModifiedDocument().WriteByteArray(st); string filename = ""; using (WordprocessingDocument wordDoc = WordprocessingDocument.Open(st, true)) { int index = 0; List<decimal> building_ids = new List<decimal>(); foreach (var building in buildings) { building_ids.Add((decimal)building["BUILDING_ID"]); } ProcessMap(buildingIndices, wordDoc, zoom, lat, lng, sa); ProcessFloorplan(floorplanIndices, wordDoc, sa); foreach (var b in buildingIndices.Keys) { using (var picStream = repo.GetBuildingPicture(buildingIndices[b].Item3, out filename)) { 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 == b)) { try { long width = 1906524; long height = 1906524; 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 { } } index++; } } } string ext = "doc"; var cd = new System.Net.Mime.ContentDisposition { FileName = "template." + ext, // always prompt the user for downloading, set to true if you want // the browser to try to show the file inline Inline = false, }; Response.AppendHeader("Content-Disposition", cd.ToString()); st.Position = 0; return new FileStreamResult(st, "application/msword"); }