public TSS_SurveyDocument SurveyBySiteSurveyId(Int64 SiteSurveyId) { var sur = new TSS_SurveyDocument(); var sd = new TSS_SectionDL(); var dt = sd.Get("By_SiteSurveyId_Only_Sections", SiteSurveyId.ToString()); if (dt.Rows.Count == 0) { return(sur); } sur.SiteId = int.Parse(dt.Rows[0]["SiteId"].ToString()); sur.SiteCode = dt.Rows[0]["SiteCode"].ToString(); sur.WoRefId = dt.Rows[0]["WoRefId"].ToString(); sur.Status = dt.Rows[0]["Status"].ToString(); sur.ClientName = dt.Rows[0]["ClientName"].ToString(); sur.CityName = dt.Rows[0]["CityName"].ToString(); sur.Scope = dt.Rows[0]["Scope"].ToString(); sur.Category = dt.Rows[0]["Category"].ToString(); sur.SubCategory = dt.Rows[0]["SubCategory"].ToString(); sur.Latitude = dt.Rows[0]["Latitude"].ToString(); sur.Longitude = dt.Rows[0]["Longitude"].ToString(); ; sur.SurveyId = int.Parse(dt.Rows[0]["SurveyId"].ToString()); sur.SiteSurveyId = int.Parse(dt.Rows[0]["SiteSurveyId"].ToString()); sur.SurveyTitle = dt.Rows[0]["SurveyTitle"].ToString(); sur.Description = dt.Rows[0]["Sur Descp"].ToString(); var tempSections = dt.AsEnumerable() .GroupBy(r => new { Col1 = r["SiteSectionId"] }) .Select(g => g.OrderBy(r => r["SiteSectionId"]).First()) .CopyToDataTable(); sur.Sections = new TSS_SurveyDocumentBL().GetSections("SURVEY_SECTIONS_BY_SITESURVEYID", SiteSurveyId.ToString(), true); //sur.Sections = new TSS_SurveyDocumentBL().FillRecursive(sur.Sections, 0); return(sur); }
public TSS_SurveyDocument SurveyBySiteId(Int64 SiteSurveyId) { var sur = new TSS_SurveyDocument(); var sd = new TSS_SectionDL(); var dt = sd.Get("By_SiteSurveyId_Only_Sections", SiteSurveyId.ToString()); if (dt.Rows.Count == 0) { return(sur); } sur.SiteId = int.Parse(dt.Rows[0]["SiteId"].ToString()); sur.SiteAddress = dt.Rows[0]["SiteAddress"].ToString(); sur.SiteCode = dt.Rows[0]["SiteCode"].ToString(); sur.WoRefId = dt.Rows[0]["WoRefId"].ToString(); sur.Status = dt.Rows[0]["Status"].ToString(); sur.ClientName = dt.Rows[0]["ClientName"].ToString(); sur.CityName = dt.Rows[0]["CityName"].ToString(); sur.Scope = dt.Rows[0]["Scope"].ToString(); sur.Category = dt.Rows[0]["Category"].ToString(); sur.SubCategory = dt.Rows[0]["SubCategory"].ToString(); sur.Latitude = dt.Rows[0]["Latitude"].ToString(); sur.Longitude = dt.Rows[0]["Longitude"].ToString(); sur.SurveyId = int.Parse(dt.Rows[0]["SurveyId"].ToString()); sur.SiteSurveyId = int.Parse(dt.Rows[0]["SiteSurveyId"].ToString()); sur.SurveyTitle = dt.Rows[0]["SurveyTitle"].ToString(); sur.Description = dt.Rows[0]["Sur Descp"].ToString(); sur.ProjectName = dt.Rows[0]["ProjectName"].ToString(); sur.WODescription = dt.Rows[0]["WODescription"].ToString(); sur.SiteTpye = dt.Rows[0]["SiteType"].ToString(); var tempSections = dt.AsEnumerable() .GroupBy(r => new { Col1 = r["SiteSectionId"] }) .Select(g => g.OrderBy(r => r["SiteSectionId"]).First()) .CopyToDataTable(); sur.Sections = new TSS_SurveyDocumentBL().GetSections("SURVEY_SECTIONS_BY_SITESURVEYID", sur.SiteSurveyId.ToString(), true, 0, 0, true); sur.CompletetionSections = new TSS_SurveyDocumentBL().GetSections("SURVEY_SECTIONS_BY_SITESURVEYID_FOR_COMPLETION", sur.SiteSurveyId.ToString(), true, 0, 0, true); sur.SiteAttendeesList = new TSS_DashboardBL().GetSiteAttendees("Get_Site_Attendees_For_Dashboard", Convert.ToInt32(sur.SiteId), Convert.ToInt32(sur.SiteSurveyId)); sur.SectorLocationList = new TSS_SurveyDocumentBL().GetSectorLocations(Convert.ToInt64(sur.SiteSurveyId)); //foreach (var q in sur.Sections) //{ // if (q.IsRepeatable) continue; // var que = new TSS_QuestionBL().GetQuestionsWithOptions("GET_Questions_BY_SECTIONID_API", 0, q.SiteSectionId.ToString(), true); // if (que.Any()) // q.Questions.AddRange(que); //} ////sur.Sections = sur.Sections.OrderBy(s => s.PSectionId).ThenBy(s => s.SiteSectionId).ToList(); //sur.Sections = new TSS_SurveyDocumentBL().FillChildRecursive(sur.Sections, 0); return(sur); }
public dynamic Manage(string Filter, TSS_SurveyDocument sd) { return(add.Manage(Filter, sd.ClientId, sd.CityId, sd.SurveyId, sd.SurveyTitle, sd.Description, sd.CategoryId, sd.SubCategoryId, sd.IsActive, sd.UnitSystemId, sd.CreatedBy, sd.IsPublished, sd.IsGlobal)); }
public TSS_SurveyDocument SurvayBySite(Int64 SiteSurveyId) { TSS_SurveyDocument sur = new TSS_SurveyDocument(); TSS_SectionBL sb = new TSS_SectionBL(); //---------------------------------------- //var result = myList.GroupBy(test => test.id) //.Select(grp => grp.First()) //.ToList(); TSS_SectionDL sd = new TSS_SectionDL(); DataTable dt = sd.Get("By_SiteSurveyId", SiteSurveyId.ToString()); if (dt.Rows.Count != 0) { foreach (DataRow item in dt.Rows) { sur.SiteId = int.Parse(dt.Rows[0]["SiteId"].ToString()); sur.SiteCode = dt.Rows[0]["SiteCode"].ToString(); sur.WoRefId = dt.Rows[0]["WoRefId"].ToString(); sur.Status = dt.Rows[0]["Status"].ToString(); sur.ClientName = dt.Rows[0]["ClientName"].ToString(); sur.CityName = dt.Rows[0]["CityName"].ToString(); sur.Scope = dt.Rows[0]["Scope"].ToString(); sur.Category = dt.Rows[0]["Category"].ToString(); sur.SubCategory = dt.Rows[0]["SubCategory"].ToString(); sur.Latitude = dt.Rows[0]["Latitude"].ToString(); sur.Longitude = dt.Rows[0]["Longitude"].ToString(); sur.SurveyId = int.Parse(dt.Rows[0]["SurveyId"].ToString()); sur.SiteSurveyId = int.Parse(dt.Rows[0]["SiteSurveyId"].ToString()); sur.SurveyTitle = dt.Rows[0]["SurveyTitle"].ToString(); sur.Description = dt.Rows[0]["Sur Descp"].ToString(); break; } var temp = dt.AsEnumerable() .GroupBy(r => new { Col1 = r["SiteSectionId"] }) .Select(g => g.OrderBy(r => r["SiteSectionId"]).First()) .CopyToDataTable(); List <TSS_Section> sec = temp.ToList <TSS_Section>(); TSS_QuestionBL qb = new TSS_QuestionBL(); foreach (var q in sec) { var que = qb.ToList("GET_QUESTION_BY_SECTION", q.SiteSectionId.ToString()); if (que != null) { q.Questions.AddRange(que); } TSS_ResponseBL rb = new TSS_ResponseBL(); RequiredActionsBL reqA = new RequiredActionsBL(); foreach (var r in que) { var resp = rb.ToList("GET_RESPONSE_BY_SITEQUESTION", r.QuestionId.ToString()); if (resp != null) { r.Responses.AddRange(resp); } } foreach (var r in que) { var rAction = reqA.ToList("GET_REQACTION_BY_SITEQUESTION", r.QuestionId.ToString()); if (rAction != null) { r.ReqActions.AddRange(rAction); } } } sur.Sections = sec; //var temp = dt.AsEnumerable() // .GroupBy(r => new { Col1 = r["SiteSectionId"] }) // .Select(g => g.OrderBy(r => r["SiteSectionId"]).First()) // .CopyToDataTable(); //List<TSS_Section> sec = temp.ToList<TSS_Section>(); //foreach (var item in sec) //{ // dt.DefaultView.RowFilter = "SiteSectionId='" + item.SiteSectionId + "'"; // DataTable ques = (dt.DefaultView).ToTable(); // item.Questions = ques.ToList<TSS_Question>(); // foreach (var res in item.Questions) // { // dt.DefaultView.RowFilter = "QuestionId='" + res.QuestionId + "'"; // DataTable quesLogic = (dt.DefaultView).ToTable(); // res.QuestionLogics = quesLogic.ToList<TSS_QuestionLogic>(); // dt.DefaultView.RowFilter = "QuestionId='" + res.QuestionId + "'"; // DataTable response = (dt.DefaultView).ToTable(); // res.Responses = response.ToList<TSS_Response>(); // dt.DefaultView.RowFilter = "SiteQuestionId='" + res.QuestionId + "'"; // DataTable reqAction = (dt.DefaultView).ToTable(); // res.ReqActions = reqAction.ToList<RequiredActions>(); // } //} //sur.Sections = sec; //------------------------------- } return(sur); }
public FileContentResult PDFView <T>(T model, string viewPath, string Page = "Potrait") { TSS_SurveyDocument TempModel = model as TSS_SurveyDocument; var Title = TempModel.SurveyTitle + " " + TempModel.SiteCode.ToString(); var html = WebUtility.HtmlDecode(GetHtml(model, viewPath)); byte[] bytes; using (var ms = new MemoryStream()) { using (var doc = new Document()) { using (var writer = PdfWriter.GetInstance(doc, ms)) { doc.Open(); try { var tagProcessors = (DefaultTagProcessorFactory)Tags.GetHtmlTagProcessorFactory(); tagProcessors.RemoveProcessor(HTML.Tag.IMG); // remove the default processor tagProcessors.AddProcessor(HTML.Tag.IMG, new CustomImageTagProcessor()); // use our new processor CssFilesImpl cssFiles = new CssFilesImpl(); cssFiles.Add(XMLWorkerHelper.GetInstance().GetDefaultCSS()); var cssResolver = new StyleAttrCSSResolver(cssFiles); cssResolver.AddCss(@"code { padding: 2px 4px; }", "utf-8", true); var charset = Encoding.UTF8; var hpc = new HtmlPipelineContext(new CssAppliersImpl(new XMLWorkerFontProvider())); hpc.SetAcceptUnknown(true).AutoBookmark(true).SetTagFactory(tagProcessors); // inject the tagProcessors var htmlPipeline = new HtmlPipeline(hpc, new PdfWriterPipeline(doc, writer)); var pipeline = new CssResolverPipeline(cssResolver, htmlPipeline); var worker = new XMLWorker(pipeline, true); var xmlParser = new XMLParser(true, worker, charset); xmlParser.Parse(new StringReader(html)); } catch (Exception ex) { var tagProcessors = (DefaultTagProcessorFactory)Tags.GetHtmlTagProcessorFactory(); tagProcessors.RemoveProcessor(HTML.Tag.IMG); // remove the default processor tagProcessors.AddProcessor(HTML.Tag.IMG, new CustomImageTagProcessor()); // use our new processor CssFilesImpl cssFiles = new CssFilesImpl(); cssFiles.Add(XMLWorkerHelper.GetInstance().GetDefaultCSS()); var cssResolver = new StyleAttrCSSResolver(cssFiles); cssResolver.AddCss(@"code { padding: 2px 4px; }", "utf-8", true); var charset = Encoding.UTF8; var hpc = new HtmlPipelineContext(new CssAppliersImpl(new XMLWorkerFontProvider())); hpc.SetAcceptUnknown(true).AutoBookmark(true).SetTagFactory(tagProcessors); // inject the tagProcessors var htmlPipeline = new HtmlPipeline(hpc, new PdfWriterPipeline(doc, writer)); var pipeline = new CssResolverPipeline(cssResolver, htmlPipeline); var worker = new XMLWorker(pipeline, true); var xmlParser = new XMLParser(true, worker, charset); xmlParser.Parse(new StringReader("<p>Some Content Failed to Load!</p>")); } finally { doc.Close(); } } } bytes = ms.ToArray(); } using (var reader = new PdfReader(bytes)) { using (var ms = new MemoryStream()) { using (var stamper = new PdfStamper(reader, ms)) { int PageCount = reader.NumberOfPages; for (int i = 1; i <= PageCount; i++) { ColumnText.ShowTextAligned(stamper.GetOverContent(i), Element.ALIGN_RIGHT, new Phrase(String.Format("Page {0} of {1}", i, PageCount), new Font(Font.FontFamily.HELVETICA, 8)), 560, 10, 0); } } bytes = ms.ToArray(); } } return(new FileContentResult(bytes, "application/pdf")); }
public FileContentResult PDFViewMultiple <T>(List <T> models, string viewPath, string Page = "Potrait") { List <byte[]> listBytes = new List <byte[]>(); int CheckModels = 0; TSS_SurveyDocument GetFirstSurvey = models[0] as TSS_SurveyDocument; string SiteSubCategory = GetFirstSurvey.SubCategory; float marginTop = 220; foreach (var model in models) { CheckModels++; TSS_SurveyDocument TempModel = model as TSS_SurveyDocument; var Title = TempModel.SurveyTitle + " " + TempModel.SiteCode.ToString(); TempModel.ChecklistCount = CheckModels; var html = WebUtility.HtmlDecode(GetHtml(TempModel, viewPath)); byte[] bytes; using (var ms = new MemoryStream()) { using (var doc = new Document(iTextSharp.text.PageSize.A4.Rotate(), 10, 10, marginTop, 10)) { using (var writer = PdfWriter.GetInstance(doc, ms)) { doc.Open(); try { doc.NewPage(); doc.SetPageSize(PageSize.A4.Rotate()); var tagProcessors = (DefaultTagProcessorFactory)Tags.GetHtmlTagProcessorFactory(); tagProcessors.RemoveProcessor(HTML.Tag.IMG); // remove the default processor tagProcessors.AddProcessor(HTML.Tag.IMG, new CustomImageTagProcessor()); // use our new processor CssFilesImpl cssFiles = new CssFilesImpl(); cssFiles.Add(XMLWorkerHelper.GetInstance().GetDefaultCSS()); var cssResolver = new StyleAttrCSSResolver(cssFiles); cssResolver.AddCss(@"code { padding: 2px 4px; }", "utf-8", true); var charset = Encoding.UTF8; var hpc = new HtmlPipelineContext(new CssAppliersImpl(new XMLWorkerFontProvider())); hpc.SetAcceptUnknown(true).AutoBookmark(true).SetTagFactory(tagProcessors); // inject the tagProcessors var htmlPipeline = new HtmlPipeline(hpc, new PdfWriterPipeline(doc, writer)); var pipeline = new CssResolverPipeline(cssResolver, htmlPipeline); var worker = new XMLWorker(pipeline, true); var xmlParser = new XMLParser(true, worker, charset); xmlParser.Parse(new StringReader(html)); } catch (Exception Ex) { doc.NewPage(); doc.SetPageSize(PageSize.A4.Rotate()); var tagProcessors = (DefaultTagProcessorFactory)Tags.GetHtmlTagProcessorFactory(); tagProcessors.RemoveProcessor(HTML.Tag.IMG); // remove the default processor tagProcessors.AddProcessor(HTML.Tag.IMG, new CustomImageTagProcessor()); // use our new processor CssFilesImpl cssFiles = new CssFilesImpl(); cssFiles.Add(XMLWorkerHelper.GetInstance().GetDefaultCSS()); var cssResolver = new StyleAttrCSSResolver(cssFiles); cssResolver.AddCss(@"code { padding: 2px 4px; }", "utf-8", true); var charset = Encoding.UTF8; var hpc = new HtmlPipelineContext(new CssAppliersImpl(new XMLWorkerFontProvider())); hpc.SetAcceptUnknown(true).AutoBookmark(true).SetTagFactory(tagProcessors); // inject the tagProcessors var htmlPipeline = new HtmlPipeline(hpc, new PdfWriterPipeline(doc, writer)); var pipeline = new CssResolverPipeline(cssResolver, htmlPipeline); var worker = new XMLWorker(pipeline, true); var xmlParser = new XMLParser(true, worker, charset); xmlParser.Parse(new StringReader("<p>Content Load Failed!</p>")); } finally { doc.Close(); } } } bytes = ms.ToArray(); } using (var reader = new PdfReader(bytes)) { using (var ms = new MemoryStream()) { using (var stamper = new PdfStamper(reader, ms)) { int PageCount = reader.NumberOfPages; for (int i = 1; i <= PageCount; i++) { if (SiteSubCategory.ToUpper() == "CRAN" || SiteSubCategory.ToUpper() == "AIRSCALE") { iTextSharp.text.Image image = iTextSharp.text.Image.GetInstance(Server.MapPath("~/Content/Images/ClientLogo/verizon_logo_mini.png")); var pdfContentByte = stamper.GetOverContent(i); image.SetAbsolutePosition(305, 495); pdfContentByte.AddImage(image); } else { iTextSharp.text.Image image = iTextSharp.text.Image.GetInstance(Server.MapPath("~/Content/Images/ClientLogo/rsz_amp-slide-bkg.jpg")); var pdfContentByte = stamper.GetOverContent(i); image.SetAbsolutePosition(285, 465); pdfContentByte.AddImage(image); } if (listBytes.Count == 0) { if (i != 1) { //ColumnText.ShowTextAligned(stamper.GetOverContent(i), Element.ALIGN_CENTER, // new Phrase(Title, new Font(Font.FontFamily.UNDEFINED, 15, Font.BOLD)), 420, 430, 0); } else { if (SiteSubCategory.ToUpper() == "MICROWAVE" || SiteSubCategory.ToUpper() == "CORRECTION" || SiteSubCategory.ToUpper() == "MAINTENANCE" || SiteSubCategory.ToUpper() == "LOS COP" || SiteSubCategory.ToUpper() == "FASTBACK") { ColumnText.ShowTextAligned(stamper.GetOverContent(i), Element.ALIGN_CENTER, new Phrase("Completed by AMP Communications LLC", new Font(Font.FontFamily.UNDEFINED, 15, Font.BOLD)), 430, 20, 0); } } } else { //ColumnText.ShowTextAligned(stamper.GetOverContent(i), Element.ALIGN_CENTER, // new Phrase(Title, new Font(Font.FontFamily.UNDEFINED, 15, Font.BOLD)), 420, 430, 0); } //ColumnText.ShowTextAligned(stamper.GetOverContent(i), Element.ALIGN_RIGHT, new Phrase(String.Format("Page {0} of {1}", i, PageCount), new Font(Font.FontFamily.HELVETICA, 8)), 760, 10, 0); } } listBytes.Add(ms.ToArray()); } } } byte[] Multiplebytes = CombineMultipleByteArrays(listBytes); return(new FileContentResult(Multiplebytes, "application/pdf")); }