public JsonResult PublishShow(int ShowId) { Shows show = new Shows(ShowId); if ((Shows.SHOW_STATUS) show.Status == Shows.SHOW_STATUS.NOT_PUBLISHED) { show.setStatus(Shows.SHOW_STATUS.PUBLISHED); } else { show.setStatus(Shows.SHOW_STATUS.NOT_PUBLISHED); } return Json(new { Status = 0 }); }
public void ProcessRequest(HttpContext context) { //PDFBuilder.HtmlToPdfBuilder builder = new HtmlToPdfBuilder(PageSize.A4); //builder.AddPage(); //builder.ImportStylesheet(context.Server.MapPath("pdfstylesheet.css")); int ShowID = Convert.ToInt32(context.Request["showid"]); Shows show = new Shows(ShowID); if ((Shows.SHOW_STATUS)show.Status == Shows.SHOW_STATUS.NOT_PUBLISHED) { show.setStatus(Shows.SHOW_STATUS.PUBLISHED); } else { show.setStatus(Shows.SHOW_STATUS.NOT_PUBLISHED); } return; /* ShowDetails sd = new ShowDetails(); DataTable table = sd.GetShowDetails(ShowID).Tables[0]; String pdfPath = context.Server.MapPath("PreviewSchedule.pdf"); String contents = File.ReadAllText(context.Server.MapPath("schedule1FrontPage.html")); Boolean publish = false; if (!String.IsNullOrEmpty(context.Request["publish"]) && context.Request["publish"].ToString() == "1") publish = true; String logoImg = context.Server.MapPath("../Assets/FirstContactAgility.png") ; context.Response.Write("logoImg=" + logoImg + "/r/n<br>"); try { contents = contents.Replace("[CLUBLOGO]", "src='" + logoImg + "'"); contents = contents.Replace("[SHOWDATES]", show.ShowDate.ToString("dddd, dd MMM yyyy")); contents = contents.Replace("[CLUBNAME]", show.ShowName); contents = contents.Replace("[SHOWVENUE]", show.Venue + ", " + show.VenuePostcode); contents = contents.Replace("[OPENTIME]", "8:00am"); contents = contents.Replace("[BRIEFING]", "8:15am"); contents = contents.Replace("[JUDGINGSTARTS]", "8:30am"); contents = contents.Replace("[SdHOWVENUE]", show.Venue + "," + show.VenuePostcode); contents = contents.Replace("[CLOSINGDATE]", show.ClosingDate.ToString("dd MMM yyyy")); contents = contents.Replace("[CHAIRMANNAME]", show.Chairman.Name); contents = contents.Replace("[CHAIRMANADDRESS]", show.Chairman.AddressDetails); contents = contents.Replace("[SECRETARYNAME]", show.Secretary.Name); contents = contents.Replace("[SECRETARYADDRESS]", show.Secretary.AddressDetails); contents = contents.Replace("[TREASURERNAME]", show.Treasurer.Name); contents = contents.Replace("[TREASURERADDRESS]", show.Treasurer.AddressDetails); contents = contents.Replace("[SHOWSECNAME]", show.ShowSec.Name); contents = contents.Replace("[SHOWSECADDRESS]", show.ShowSec.AddressDetails); contents = contents.Replace("[SHOWMANAGERNAME]", show.ShowManager.Name); contents = contents.Replace("[SHOWMANAGERADDRESS]", show.ShowManager.AddressDetails); contents = contents.Replace("[EQUIPMENTNAME]", show.Equipment.Name); contents = contents.Replace("[EQUIPMENTADDRESS]", show.Equipment.AddressDetails); contents = contents.Replace("[VETNAME]", show.Vet.Name); contents = contents.Replace("[VETADDRESS]", show.Vet.AddressDetails); contents = contents.Replace("[SHOWENTRIESNAME]", show.ShowEntries.Name); contents = contents.Replace("[SHOWENTRIESADDRESS]", show.ShowEntries.AddressDetails); contents = contents.Replace("[PAYABLENAME]", show.Payable.Name); contents = contents.Replace("[PAYABLEADDRESS]", show.Payable.AddressDetails); } catch (Exception e) { context.Response.Write("Error creating content/r/n<br>" + e.Message + "/r/n<br>"); } Document doc = new Document(PageSize.A4, 25, 10, 10, 10); Stream output ; if (publish) { String path = context.Server.MapPath(@"..\schedules\"); path += DateTime.Today.ToString("yyyy"); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } path += String.Format("\\{0:yyyyMMM}_{1}.pdf", show.ShowDate, show.ShowName); output = new FileStream(path, FileMode.Create); show.setStatus(Shows.SHOW_STATUS.PUBLISHED); } else { output = new MemoryStream(); } var writer = PdfWriter.GetInstance(doc, output); StyleSheet sheet = new StyleSheet(); doc.Open(); var parsedHTML = HTMLWorker.ParseToList(new StringReader(contents), sheet); foreach (var htmlElement in parsedHTML) { doc.Add(htmlElement as IElement); } doc.NewPage(); foreach (DataRow row in table.Rows) { ShowDetails _showDetails = new ShowDetails(row); DataTable showDayTable = _showDetails.GetDayData(true); String dayHtml = generateClassesForDay(_showDetails.ShowDetailsID, showDayTable); doc.NewPage(); var dayClasses = HTMLWorker.ParseToList(new StringReader(dayHtml), sheet); foreach (var htmlElement in dayClasses) { doc.Add(htmlElement as IElement); } }; doc.NewPage(); contents = File.ReadAllText(context.Server.MapPath("schedule2RulesNRegs.html")); parsedHTML = HTMLWorker.ParseToList(new StringReader(contents), sheet); foreach (var htmlElement in parsedHTML) { doc.Add(htmlElement as IElement); } #if TEST foreach (DataRow row in table.Rows) { PdfPTable pdfTable = new PdfPTable(5); ShowDetails _showDetails = new ShowDetails(row); DataTable showDayTable = _showDetails.GetDayData(true); String dateThing = getDateOrdinalSuffix(_showDetails.ShowDate.Day); String datestr = _showDetails.ShowDate.ToString("dddd MMM d").ToUpper() + dateThing; PdfPCell pdfCell = new PdfPCell(); pdfCell = new PdfPCell(new Phrase(datestr )); pdfCell.Colspan = 5; pdfTable.AddCell(pdfCell); pdfTable.AddCell("ClsNo"); pdfCell = new PdfPCell(new Phrase("Name")); pdfCell.Colspan = 3; pdfTable.AddCell(pdfCell); pdfTable.AddCell("Grades"); pdfTable = new PdfPTable(5); foreach (DataRow clsRow in showDayTable.Rows) { PdfPTable grades = new PdfPTable(7); String str = clsRow["grades"].ToString(); for (int i = 1; i <= 7; i++) { if (str.IndexOf((char)(i + 48)) > -1) { grades.AddCell(i.ToString()); } else { grades.AddCell(" "); } } pdfTable.AddCell(clsRow["ClsNo"].ToString() ); pdfCell = new PdfPCell(new Phrase(clsRow["Name"].ToString())); pdfCell.Colspan = 3; pdfTable.AddCell(pdfCell); pdfTable.AddCell(grades); doc.Add(pdfTable); } doc.NewPage(); } #endif doc.Close(); if (publish) { } else { context.Response.ClearContent(); context.Response.ContentType = "application/pdf"; context.Response.AddHeader("content-disposition", String.Format("inline;filename=PreviewSchedule.pdf")); context.Response.BinaryWrite( (output as MemoryStream).ToArray()); } * */ }
public JsonResult PublishRunningPlans(int ShowId, string Action) { Shows show = new Shows(ShowId); show.setStatus((Action == "unpublish" ? Shows.SHOW_STATUS.CLOSED : Shows.SHOW_STATUS.SHOWDOCS_AVAILABLE)); return Json(new { Status = 0, NewText = (Action == "unpublish" ? "Publish Running Plans" : "Unpublish Running Plans"), NewAction = (Action == "unpublish" ? "publish" : "unpublish") }); }