public override void MergeField(Novacode.DocX doc) { base.MergeField(doc); doc.AddCustomProperty(new Novacode.CustomProperty("CostDetail.BuyingFormat", this.BuyingFormat)); doc.AddCustomProperty(new Novacode.CustomProperty("CostDetail.PrintingFormat", this.PrintingFormat)); }
public override void MergeField(Novacode.DocX doc) { base.MergeField(doc); var description = String.Empty; List<ProductPartPrintRollOption> optSeris = new List<ProductPartPrintRollOption>(); //serigraphy options where we can find the inks and types foreach (var item in this.TaskCost.ProductPartTask.ProductPartTaskOptions.OfType<ProductPartPrintRollOption>()) { description += item.TypeOfTaskPrint + " " + item.Ink + " " + item.Overlay + "%\n"; } doc.AddCustomProperty(new Novacode.CustomProperty("CostDetail.OptionTask", description)); }
private int FillCell(Novacode.Row rr, int col, ExcelPic p) { var c = rr.Cells[col]; var img = ImageData.Image.ImageFromId(p.ImageId); if (img != null) using (var os = img.ResizeToStream(200, 300, "crop")) { var pic = dd.AddImage(os).CreatePicture((pa.PicWidthPixels * 1.5).ToInt(), pa.PicWidthPixels); c.Paragraphs[0].InsertPicture(pic); } col++; c = rr.Cells[col]; //c.RemoveParagraphAt(0); c.Paragraphs[0].InsertText("{0}, {1}".Fmt(p.LastName, p.FirstName), false, pa.namebold); c.InsertParagraph(p.Email, false, pa.emailsmall); if (p.BirthDate.HasValue()) c.InsertParagraph("BD {0}".Fmt(p.BirthDay), false, pa.font); if (p.Spouse.HasValue()) c.InsertParagraph("Spouse: {0}".Fmt(p.Spouse), false, pa.font); if (p.Children.HasValue()) c.InsertParagraph("Kids: {0}".Fmt(p.Children), false, pa.font); col++; return col; }
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¢er=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; }
private static Novacode.Table CreateAndInsertInvoiceTableAfter(Novacode.Table t, ref DocX document, PapiroMVC.Models.Document d) { var docProd = d.DocumentProducts.Select(x => x.CodProduct).Distinct(); /* * The trick to replacing one Table with another, * is to insert the new Table after the old one, * and then remove the old one. */ Novacode.Table invoice_table = t.InsertTableAfterSelf(d.DocumentProducts.Count + 1, 4); invoice_table.Design = TableDesign.LightShadingAccent1; #region Table title Formatting table_title = new Formatting(); table_title.Bold = true; Type res = typeof(PapiroMVC.Models.Resources.Document.ResDocumentProduct); invoice_table.Rows[0].Cells[0].Paragraphs[0].InsertText( (string)res.GetProperty("Product").GetValue(null, null), false, table_title); invoice_table.Rows[0].Cells[0].Paragraphs[0].Alignment = Alignment.left; invoice_table.Rows[0].Cells[1].Paragraphs[0].InsertText( (string)res.GetProperty("Quantity").GetValue(null, null), false, table_title); invoice_table.Rows[0].Cells[1].Paragraphs[0].Alignment = Alignment.right; invoice_table.Rows[0].Cells[2].Paragraphs[0].InsertText( (string)res.GetProperty("UnitPrice").GetValue(null, null), false, table_title); invoice_table.Rows[0].Cells[2].Paragraphs[0].Alignment = Alignment.right; invoice_table.Rows[0].Cells[3].Paragraphs[0].InsertText( (string)res.GetProperty("TotalAmount").GetValue(null, null), false, table_title); invoice_table.Rows[0].Cells[3].Paragraphs[0].Alignment = Alignment.right; #endregion // Loop through the rows in the Table and insert data from the data source. for (int row = 1; row < invoice_table.RowCount; ) { Novacode.Paragraph cell_paragraph; foreach (var dp in docProd) { var sel = d.DocumentProducts.Where(y => y.CodProduct == dp).OrderBy(z => z.Quantity); var k = 0; foreach (var item in sel) { cell_paragraph = invoice_table.Rows[row].Cells[0].Paragraphs[0]; cell_paragraph.InsertText(k++ == 0 ? item.ProductName : "", false); invoice_table.Rows[row].Cells[0].Paragraphs[0].Alignment = Alignment.left; cell_paragraph = invoice_table.Rows[row].Cells[1].Paragraphs[0]; cell_paragraph.InsertText(item.Quantity.ToString(), false); invoice_table.Rows[row].Cells[1].Paragraphs[0].Alignment = Alignment.right; cell_paragraph = invoice_table.Rows[row].Cells[2].Paragraphs[0]; cell_paragraph.InsertText(item.UnitPrice, false); invoice_table.Rows[row].Cells[2].Paragraphs[0].Alignment = Alignment.right; cell_paragraph = invoice_table.Rows[row].Cells[3].Paragraphs[0]; cell_paragraph.InsertText(item.TotalAmount, false); invoice_table.Rows[row].Cells[3].Paragraphs[0].Alignment = Alignment.right; row++; } } } invoice_table.InsertRow(); // Let the tables coloumns expand to fit its contents. invoice_table.AutoFit = AutoFit.Contents; // Center the Table invoice_table.Alignment = Alignment.center; //Return the invloce table now that it has been created. return invoice_table; }
public bool ProcessChildPage(string parent_id, IEnumerable<Dictionary<string, object>> buildings, string[] zoom, string[] lat, string[] lng, ref Novacode.DocX docx, Dictionary<string, object> currentBuilding = null ) { OracleRepository repo = new OracleRepository(); var childIds = repo.LoadChildDocumentIDs(parent_id); foreach (var childId in childIds) { if (currentBuilding != null) { ProcessDocument(childId, currentBuilding, buildings, 0, ref docx, zoom, lat, lng); ProcessChildPage(childId.ToString(), buildings, zoom, lat, lng, ref docx, currentBuilding); return true; } int index = 0; foreach (Dictionary<string, object> b in buildings) { index++; if (!b.ContainsKey("INDEX")) { b.Add("INDEX", index); b.Add("SIZE_SQ_FORMATTED", ""); b.Add("BASE_RENT_FORMATTED", ""); b.Add("OP_COST_FORMATTED", ""); b.Add("TERM_FORMATTED", ""); b.Add("NET_RENTABLE_FORMATTED", ""); b.Add("FLOOR_PLATE_FORMATTED", ""); if (b["SIZE_SQ"] != null && b["SIZE_SQ"] != DBNull.Value) { b["SIZE_SQ_FORMATTED"] = String.Format("{0} sf", b["SIZE_SQ"]); } if (b["BASE_RENT"] != null && b["BASE_RENT"] != DBNull.Value) { b["BASE_RENT_FORMATTED"] = String.Format("$ {0} per sf", b["BASE_RENT"]); } if (b["LATEST_OP_COST_AMT"] != null && b["LATEST_OP_COST_AMT"] != DBNull.Value) { b["OP_COST_FORMATTED"] = String.Format("$ {0} (est {1})", b["LATEST_OP_COST_AMT"], b["OP_COST_YEAR"]); } if (b["TERM"] != null && b["TERM"] != DBNull.Value) { b["TERM_FORMATTED"] = String.Format("{0} years", b["TERM"]); } if (b["PARKING_RATIO"] != null && b["PARKING_RATIO"] != DBNull.Value) { b["PARKING_RATIO_FORMATTED"] = String.Format("1 stall per {0} sf", b["PARKING_RATIO"]); } if (b["NET_RENTABLE"] != null && b["NET_RENTABLE"] != DBNull.Value) { b["NET_RENTABLE_FORMATTED"] = String.Format("{0:N0} sf", b["NET_RENTABLE"]); } if (b["FLOOR_PLATE"] != null && b["FLOOR_PLATE"] != DBNull.Value) { b["FLOOR_PLATE_FORMATTED"] = String.Format("{0:N0} sf", b["FLOOR_PLATE"]); } } ProcessDocument(childId, b, buildings, index, ref docx, zoom, lat, lng); ProcessChildPage(childId.ToString(), buildings, zoom, lat, lng,ref docx, b); } } return true; }
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; }
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 bool ProcessUserTemplate(IEnumerable<Dictionary<string, object>> buildings, string[] zoom, string[] lat, string[] lng, ref Novacode.DocX docx, Dictionary<string, object> currentBuilding = null) { // docx. return true; }
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("¢er={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; }
public bool ProcessParkingList(decimal building_id, ref Novacode.DocX docx) { try { OracleRepository repo = new OracleRepository(); var parkingList = repo.QueryAll( String.Format(@" SELECT PARKING_ID, BUILDING_ID, PARKING_TYP, NUM_STALLS, COST_AMT, NOTE, INFO_AS_OF_DATE, CREATE_DATE, CREATE_USER, UPDATE_DATE, UPDATE_USER FROM VPARKING WHERE BUILDING_ID={0} ", building_id)); string strParkingList = ""; foreach (Dictionary<string, object> p in parkingList) { if (String.IsNullOrEmpty(String.Format("{0}", p["COST_AMT"]))) { strParkingList = String.Format("{0}", p["PARKING_TYP"]); } else { strParkingList += String.Format("$ {0} per stall, \n {1} ", p["COST_AMT"], p["PARKING_TYP"]); } } docx.ReplaceText("<PARKING_LIST>", strParkingList); } catch { } return true; }
public override void MergeField(Novacode.DocX doc) { base.MergeField(doc); if (ProductPartPrinting != null) { TaskexEcutorSelected = TaskExecutors.FirstOrDefault(x => x.CodTaskExecutor == CodTaskExecutorSelected); ProductPartPrinting.MergeField(doc); } }