/// <summary> /// Class's constructor /// </summary> /// <param name="Title">Bookmark's title</param> /// <param name="Page">Destination Page</param> /// <param name="openBookmark">The visibility of bookmark's childs</param> /// <param name="Destination">Destination object</param> public pdfBookmarkNode(string Title, pdfPage Page, bool openBookmark, IPdfDestination Destination) { _Title = Title; _Page = Page; _Destination = Destination; _prev = 0; _next = 0; _first = 0; _last = 0; _parent = 0; _childCount = 0; _open = openBookmark; }
internal byte[] ExportResults(Structs.ResultWeaponsClass wclass, Structs.ShootersClass uclass, bool finalResults) { if (finalResults != true) { throw new ApplicationException("Not implemented yet"); } double yPos = topMargin; sharpPDF.pdfPage page = null; return(ExportResults(wclass, uclass, finalResults, true, ref page, ref yPos)); }
private byte[] ExportTeamResults(Structs.ResultWeaponsClass wclass, bool finalResults, bool returnDocument, ref pdfPage page, ref double yPos) { if (yPos + conversionPixelsToMM * 3 * fontSize >= bottomMargin) { page = this.getNewPage(ref yPos); } ResultsReturnTeam[] results = myInterface.ResultsGetTeams(wclass, myInterface.GetCompetitions()[0]); if (results.Length == 0) { if (returnDocument) { return returnPdfInBytes(); } else { return new byte[0]; } } // Write headers yPos = writeResultsPageTeamHeader(page, yPos, wclass); yPos = writeResultsTeamHeader(page, yPos); int i=0; foreach(ResultsReturnTeam result in results) { if (yPos + calculateTeamHeight(result) >= bottomMargin) { page = this.getNewPage(ref yPos); yPos = writeResultsPageTeamHeader(page, yPos, wclass); if (yPos < TextStart) { yPos = TextStart; } yPos = writeResultsTeamHeader(page, yPos); } i++; yPos = writeResultsTeam(page, yPos, result, i); } // Return what we've created if (returnDocument) { return returnPdfInBytes(); } else { return new byte[0]; } }
private double writeResultsTeam(pdfPage page, double yPos, ResultsReturnTeam result, int place) { double newYPos = yPos; Structs.Club club = myInterface.GetClub(result.ClubId); if (competition.CompetitionId == 0) competition = myInterface.GetCompetitions()[0]; addText(page, place.ToString(), this.leftMargin, yPos, font, fontResultSize); addText(page, result.TeamName, this.colResultNamePos, yPos, colResultClubPos-colResultNamePos,font, fontResultSize); addText(page, club.Name, this.colResultClubPos, yPos, colResultResultPos-colResultClubPos,font, fontResultSize); switch(competition.Type) { case Structs.CompetitionTypeEnum.Field: { if (competition.NorwegianCount) { addText(page, (result.Hits + result.FigureHits).ToString(), colResultTotPos, yPos, font, fontResultSize); } else { addText(page, result.Hits.ToString() + "/" + result.FigureHits.ToString(), colResultTotPos, yPos, font, fontResultSize); } addText(page, result.Points.ToString(), this.colResultPointsPos, yPos, font, fontResultSize); break; } case Structs.CompetitionTypeEnum.Precision: { addText(page, result.Hits.ToString(), this.colResultPointsPos, yPos, font, fontResultSize); break; } default: throw new ApplicationException("Not implemented yet"); } /*if (competition.UsePriceMoney && result.PriceMoney != 0) { newYPos = addText(page, result.PriceMoney.ToString() + ":-", this.colResultPricePos, yPos, font, fontResultSize); }*/ string[] HitsPerStn = result.HitsPerStn.Split(';'); double xPos = colResultResultPos; double xMaxPos = colResultTotPos; foreach(string thisStn in HitsPerStn) { int maxXSizeInPoints = (int)((xMaxPos-xPos)/conversionPixelsToMM); if (font.getWordWidth(thisStn, fontSize) > maxXSizeInPoints) { xPos = colResultResultPos; yPos = newYPos; } newYPos = addText(page, thisStn, xPos, yPos, font, fontResultSize); xPos += conversionPixelsToMM*font.getWordWidth(thisStn, fontSize); } Structs.Team team = myInterface.GetTeam(result.TeamId); foreach (int compid in (int[])team.CompetitorIds.ToArray(typeof(int))) { newYPos = writeResultsTeam(page, newYPos, colResultResultPos, colResultTotPos, compid); } return newYPos; }
private double writeResultsTeamHeader(pdfPage page, double yPos) { drawLine(page, this.leftMargin, yPos+1, 225, yPos+1, 1); addText(page, "Pl", leftMargin, yPos, fontHeader, fontCompetitionHeaderSize); addText(page, "Lag", colResultNamePos, yPos, fontHeader, fontCompetitionHeaderSize); addText(page, "Klubb", colResultClubPos, yPos, fontHeader, fontCompetitionHeaderSize); addText(page, "Resultat", colResultResultPos, yPos, fontHeader, fontCompetitionHeaderSize); addText(page, "Tot", colResultTotPos, yPos, fontHeader, fontCompetitionHeaderSize); yPos = addText(page, "P", colResultPointsPos, yPos, fontHeader, fontCompetitionHeaderSize); //addText(page, "Stm", colResultStmPos, yPos, fontHeader, fontCompetitionHeaderSize); //addText(page, "Pris", colResultPricePos, yPos, fontHeader, fontCompetitionHeaderSize); return yPos; }
private double writeResultsUser(pdfPage page, double yPos, ResultsReturn result, int place) { double newYPos = yPos; Structs.Club club = myInterface.GetClub(result.ClubId); if (competition.CompetitionId == 0) competition = myInterface.GetCompetitions()[0]; addText(page, place.ToString(), this.leftMargin, yPos, font, fontResultSize); addText(page, result.ShooterName, this.colResultNamePos, yPos, colResultClubPos-colResultNamePos,font, fontResultSize); addText(page, club.Name, this.colResultClubPos, yPos, colResultResultPos-colResultClubPos,font, fontResultSize); switch(competition.Type) { case Structs.CompetitionTypeEnum.Field: { if (competition.NorwegianCount) { addText(page, (result.HitsTotal + result.FigureHitsTotal).ToString(), colResultTotPos, yPos, font, fontResultSize); } else { addText(page, result.HitsTotal.ToString() + "/" + result.FigureHitsTotal.ToString(), colResultTotPos, yPos, font, fontResultSize); } addText(page, result.PointsTotal.ToString(), this.colResultPointsPos, yPos, font, fontResultSize); break; } case Structs.CompetitionTypeEnum.Precision: { addText(page, result.HitsTotal.ToString(), this.colResultPointsPos, yPos, font, fontResultSize); break; } default: throw new ApplicationException("Not implemented yet"); } string medalText = ""; switch((Structs.Medal)result.Medal) { case Structs.Medal.StandardSilver: medalText = "S"; break; case Structs.Medal.StardardBrons: medalText = "B"; break; } newYPos = addText(page, medalText, this.colResultStmPos, yPos, font, fontResultSize); if (competition.UsePriceMoney && result.PriceMoney != 0) { newYPos = addText(page, result.PriceMoney.ToString() + ":-", this.colResultPricePos, yPos, font, fontResultSize); } string[] HitsPerStn = result.HitsPerStnString.Split(';'); double xPos = colResultResultPos; double xMaxPos = colResultTotPos; foreach(string thisStnPre in HitsPerStn) { if (thisStnPre != "") { string thisStn = thisStnPre; switch(competition.Type) { case Structs.CompetitionTypeEnum.Field: { if (competition.NorwegianCount) { } else { string[] parts = thisStn.Split('/'); int hits = int.Parse(parts[0]); int figureHits; figureHits = int.Parse(parts[1]); thisStn = hits.ToString(); } break; } case Structs.CompetitionTypeEnum.MagnumField: { string[] parts = thisStn.Split('/'); int hits = int.Parse(parts[0]); int figureHits; figureHits = int.Parse(parts[1]); if (competition.NorwegianCount) { thisStn = (hits + figureHits).ToString(); } else { thisStn = hits.ToString(); } break; } case Structs.CompetitionTypeEnum.Precision: { break; } default: throw new NotImplementedException(); } int maxXSizeInPoints = (int)((xMaxPos - xPos) / conversionPixelsToMM); if (font.getWordWidth(thisStn, fontSize) > maxXSizeInPoints) { xPos = colResultResultPos; yPos = newYPos; } newYPos = addText(page, thisStn, xPos, yPos, font, fontResultSize); xPos += conversionPixelsToMM * font.getWordWidth(thisStn, fontSize); } } if (result.FinalShootingPlace != 100) { addText(page, "(" + result.FinalShootingPlace.ToString() + ")", xPos, yPos, font, fontResultSize); } return newYPos; }
private double writeResultsPageTeamHeader(pdfPage page, double yPos, Structs.ResultWeaponsClass wclass) { Structs.Competition comp = myInterface.GetCompetitions()[0]; addText(page, "Tävling:", leftMargin, yPos, fontCompetitionHeader, fontCompetitionHeaderSize); yPos = addText(page, comp.Name + ", " + comp.StartTime.ToShortDateString(), leftMargin + 30, yPos , fontCompetitionHeader, fontCompetitionHeaderSize); addText(page, "Vapen:", leftMargin, yPos, fontCompetitionHeader, fontCompetitionHeaderSize); yPos = addText(page, wclass.ToString(), leftMargin + 30, yPos , fontCompetitionHeader, fontCompetitionHeaderSize); /*addText(page, "Klass:", leftMargin, yPos, fontCompetitionHeader, fontCompetitionHeaderSize); yPos = addText(page, uclass.ToString(), leftMargin + 30, yPos , fontCompetitionHeader, fontCompetitionHeaderSize);*/ yPos = yPos + 4; return yPos; }
private double writeResultsHeader(pdfPage page, double yPos) { drawLine(page, this.leftMargin, yPos+1, 225, yPos+1, 1); double newYPos = addText(page, "Pl", leftMargin, yPos, fontHeader, fontCompetitionHeaderSize); addText(page, "Namn", colResultNamePos, yPos, fontHeader, fontCompetitionHeaderSize); addText(page, "Klubb", colResultClubPos, yPos, fontHeader, fontCompetitionHeaderSize); addText(page, "Resultat", colResultResultPos, yPos, fontHeader, fontCompetitionHeaderSize); addText(page, "Tot", colResultTotPos, yPos, fontHeader, fontCompetitionHeaderSize); addText(page, "P", colResultPointsPos, yPos, fontHeader, fontCompetitionHeaderSize); addText(page, "Stm", colResultStmPos, yPos, fontHeader, fontCompetitionHeaderSize); if (myInterface.CompetitionCurrent.UsePriceMoney) { addText(page, "Pris", colResultPricePos, yPos, fontHeader, fontCompetitionHeaderSize); } return newYPos; }
private double addText(pdfPage page, string text, double xPosInMM, double yPosInMM, double maxXSizeInMM, pdfAbstractFont writeFont, int writeFontSize) { int maxXSizeInPoints = (int)(maxXSizeInMM/conversionPixelsToMM); while (writeFont.getWordWidth(text, writeFontSize) > maxXSizeInPoints) { text = text.Substring(0, text.Length-1); } int xInPoints = (int)(xPosInMM/conversionPixelsToMM); int yInPoints = page.height - (int)(yPosInMM/conversionPixelsToMM); page.addText(text,xInPoints,yInPoints,writeFont,writeFontSize); double newY = (double)(page.height-yInPoints+writeFontSize); newY = conversionPixelsToMM*newY; return newY; }
private double writePatrol(ref pdfPage page, Structs.Patrol patrol, ref double yPos) { if (yPos + conversionPixelsToMM * fontSize > bottomMargin) { page = getNewPage(ref yPos); yPos = writePatrolHeader(page, yPos); } addText(page, patrol.PatrolId.ToString() + " ( " + patrol.StartDateTimeDisplay.ToShortTimeString() + " )", columnPatrolsPatrolPos, yPos, font, fontSize); foreach(Structs.Competitor comp in myInterface.GetCompetitors(patrol)) { if (yPos + conversionPixelsToMM * fontSize > bottomMargin) { page = getNewPage(ref yPos); yPos = writePatrolHeader(page, yPos); } Structs.Shooter shooter = myInterface.GetShooter(comp.ShooterId); Structs.Club club = myInterface.GetClub(shooter.ClubId); Structs.Weapon weapon = myInterface.GetWeapon(comp.WeaponId); string weaponString = getWeapon(weapon); addText(page, shooter.Givenname + ", " + shooter.Surname, columnPatrolsNamePos, yPos, columnPatrolsClubNamePos - columnPatrolsNamePos, font, fontSize); addText(page, club.Name, columnPatrolsClubNamePos, yPos, columnPatrolsWeaponPos - columnPatrolsClubNamePos, font, fontSize); yPos = addText(page, weaponString, columnPatrolsWeaponPos, yPos, font, fontSize); yPos += 1; } return yPos; }
internal byte[] ExportResults(bool finalResults, bool allOnOnePage) { if (finalResults != true) throw new ApplicationException("Not implemented yet"); Structs.ResultWeaponsClass[] wclasses = myInterface.resultClass.ResultsGetWClasses(); double yPos = topMargin; page = getNewPage(ref yPos); yPos = writeResultsPageHeader(page, yPos); foreach(Structs.ResultWeaponsClass wclass in wclasses) { foreach(Structs.ShootersClass uclass in myInterface.resultClass.ResultsGetUClasses(wclass)) { if (page == null | !allOnOnePage) { page = getNewPage(ref yPos); } ExportResults(wclass, uclass, finalResults, false, ref page, ref yPos); yPos += 10; } } foreach(Structs.ResultWeaponsClass wclass in wclasses) { //foreach(Structs.ShootersClass uclass in myInterface.resultClass.ResultsGetUClasses(wclass)) { if (page == null | !allOnOnePage) { page = getNewPage(ref yPos); } ExportTeamResults(wclass, finalResults, false, ref page, ref yPos); yPos += 10; } } return returnPdfInBytes(); }
private byte[] ExportResults(Structs.ResultWeaponsClass wclass, Structs.ShootersClass uclass, bool finalResults, bool returnDocument, ref pdfPage page, ref double yPos) { if (yPos + conversionPixelsToMM * 3*fontSize >= bottomMargin) { page = this.getNewPage(ref yPos); } // Write headers yPos = writeResultsClassHeader(page, yPos, wclass, uclass); if (yPos < TextStart) { yPos = TextStart; } yPos = writeResultsHeader(page, yPos); ResultsReturn[] results = myInterface.resultClass.GetResults(wclass, uclass, myInterface.CompetitionCurrent, true); int i=0; foreach(ResultsReturn result in results) { if (yPos + conversionPixelsToMM * fontSize >= bottomMargin) { page = this.getNewPage(ref yPos); yPos = writeResultsClassHeader(page, yPos, wclass, uclass); if (yPos < TextStart) { yPos = TextStart; } yPos = writeResultsHeader(page, yPos); } i++; yPos = writeResultsUser(page, yPos, result, i); } // Return what we've created if (returnDocument) { return returnPdfInBytes(); } else { return new byte[0]; } }
private double writePatrolByClub(ref pdfPage page, Structs.Shooter[] shooters, ref double yPos) { Structs.Club club = myInterface.GetClub(shooters[0].ClubId); if (yPos + conversionPixelsToMM * (2*fontSize + fontHeaderSize) > bottomMargin) { // Paging page = getNewPage(ref yPos); yPos = writePatrolByClubHeader(page, yPos); } addText(page, club.ClubId, columnPatrolsByClubClubIdPos, yPos, fontHeader, fontHeaderSize); yPos = addText(page, club.Name, columnPatrolsByClubNamePos, yPos, fontHeader, fontHeaderSize); foreach(Structs.Shooter shooter in shooters) { if (yPos + 2 * conversionPixelsToMM * fontSize > bottomMargin) { // Paging page = getNewPage(ref yPos); yPos = writePatrolByClubHeader(page, yPos); } foreach(Structs.Competitor comp in myInterface.GetCompetitors(shooter.ShooterId, "PatrolId")) { if (yPos + 2 * conversionPixelsToMM * fontSize > bottomMargin) { // Paging page = getNewPage(ref yPos); yPos = writePatrolByClubHeader(page, yPos); } if (comp.PatrolId >= 1) { Structs.Patrol patrol = myInterface.GetPatrol(comp.PatrolId); string weaponText = getWeapon(myInterface.GetWeapon(comp.WeaponId)); addText(page, shooter.Givenname + ", " + shooter.Surname, columnPatrolsByClubNamePos, yPos, font, fontSize); addText(page, patrol.PatrolId.ToString() + " (" + patrol.StartDateTimeDisplay.ToShortTimeString() + ")", columnPatrolsByClubPatrolPos, yPos, font, fontSize); addText(page, weaponText, columnPatrolsByClubWeaponPos, yPos, font, fontSize); Structs.ShootersClassShort sc = (Structs.ShootersClassShort)(int)comp.ShooterClass; string classText = sc.ToString().Replace("Klass", "").Replace("Damklass", "D"); classText += myInterface.GetWeapon(comp.WeaponId).WClass.ToString().Substring(0,1); yPos = addText(page, classText, columnPatrolsByClubClassPos, yPos, font, fontSize); yPos += 1; } } } return yPos+5; }
private double writePatrolByClubHeader(pdfPage page, double yPos) { yPos += 1; drawLine(page, leftMargin, yPos, leftMargin + 120, yPos, 1); yPos -= 1; addText(page, "Klubb", this.leftMargin, yPos, fontHeader, fontHeaderSize); addText(page, "Namn", columnPatrolsByClubNamePos, yPos, fontHeader, fontHeaderSize); addText(page, "Patrull", columnPatrolsByClubPatrolPos, yPos, fontHeader, fontHeaderSize); addText(page, "Vapen", columnPatrolsByClubWeaponPos, yPos, fontHeader, fontHeaderSize); yPos = addText(page, "Klass", columnPatrolsByClubClassPos, yPos, fontHeader, fontHeaderSize); yPos += 1; return yPos; }
private double writePatrolHeader(pdfPage page, double yPos) { yPos += 1; drawLine(page, leftMargin, yPos, columnPatrolsWeaponPos + 25, yPos, 1); yPos -= 1; addText(page, "Patrull", columnPatrolsPatrolPos, yPos, fontHeader, fontHeaderSize); addText(page, "Namn", columnPatrolsNamePos, yPos, fontHeader, fontHeaderSize); addText(page, "Klubb", columnPatrolsClubNamePos, yPos, fontHeader, fontHeaderSize); yPos = addText(page, "Vapen", this.columnPatrolsWeaponPos, yPos, fontHeader, fontHeaderSize); yPos += 1; return yPos; }
private double writeResultsTeam(pdfPage page, double yPos, double xPos1, double xPos2, int competitorId) { double newYPos = yPos; Structs.Competitor competitor = myInterface.GetCompetitor(competitorId); Structs.Shooter shooter = myInterface.GetShooter(competitor.ShooterId); newYPos = addText(page, shooter.Surname + " " + shooter.Givenname, xPos1, yPos, font, fontResultSize); int hits = 0; int figurehits = 0; foreach (Structs.CompetitorResult res in myInterface.GetCompetitorResults(competitor.CompetitorId)) { hits += res.Hits; figurehits += res.FigureHits; } switch (competition.Type) { case Structs.CompetitionTypeEnum.Field: { if (competition.NorwegianCount) { addText(page, (hits + figurehits).ToString(), xPos2, yPos, font, fontResultSize); } else { addText(page, hits.ToString() + "/" + figurehits.ToString(), xPos2, yPos, font, fontResultSize); } break; } case Structs.CompetitionTypeEnum.MagnumField: { addText(page, hits.ToString() + "/" + figurehits.ToString(), xPos2, yPos, font, fontResultSize); break; } case Structs.CompetitionTypeEnum.Precision: { addText(page, hits.ToString(), xPos2, yPos, font, fontResultSize); break; } default: throw new ApplicationException("Unknown CompetitionType"); } return newYPos; }
private double addText(pdfPage page, string text, double xPosInMM, double yPosInMM, pdfAbstractFont writeFont, int writeFontSize) { if (page == null) page = getNewPage(ref yPosInMM); int xInPoints = (int)(xPosInMM/conversionPixelsToMM); int yInPoints = page.height - (int)(yPosInMM/conversionPixelsToMM); page.addText(text,xInPoints,yInPoints,writeFont,writeFontSize); double newY = (double)(page.height-yInPoints+writeFontSize); newY = conversionPixelsToMM*newY; return newY; }
private double writeResultsPageHeader(pdfPage page, double yPos) { Structs.Competition comp = myInterface.GetCompetitions()[0]; addText(page, "Tävling:", leftMargin, yPos, fontCompetitionHeader, fontCompetitionHeaderSize); yPos = addText(page, comp.Name + ", " + comp.StartTime.ToShortDateString(), leftMargin + 30, yPos , fontCompetitionHeader, fontCompetitionHeaderSize); yPos = yPos + 4; return yPos; }
private void drawLine(pdfPage page, double x1, double y1, double x2, double y2, int lineSize) { int x1InPoints = (int)(x1/conversionPixelsToMM); int x2InPoints = (int)(x2/conversionPixelsToMM); int y1InPoints = page.height - (int)(y1/conversionPixelsToMM); int y2InPoints = page.height - (int)(y2/conversionPixelsToMM); page.drawLine(x1InPoints, y1InPoints, x2InPoints, y2InPoints, predefinedLineStyle.csNormal, pdfColor.Black, lineSize); }
private double writeResultsClassHeader(pdfPage page, double yPos, Structs.ResultWeaponsClass wclass, Structs.ShootersClass uclass) { Structs.ShootersClassShort uclassshort = (Structs.ShootersClassShort)(int)uclass; string klass = uclassshort.ToString().Replace("Klass", "") + wclass.ToString(); addText(page, "Klass:", leftMargin, yPos, fontCompetitionHeader, fontCompetitionHeaderSize); yPos = addText(page, klass, leftMargin + 30, yPos, fontCompetitionHeader, fontCompetitionHeaderSize); yPos = yPos + 4; return yPos; }
private byte[] returnPdfInBytes() { System.IO.MemoryStream stream = new MemoryStream(); document.createPDF(stream); document = null; page = null; return stream.ToArray(); }