private void SetupPrecision(Structs.CompetitionTypeEnum CompetitionType, bool Norwegian, out ResultsReturn obj1, out ResultsReturn obj2, string testName, Structs.CompetitionChampionshipEnum ChampionShip) { obj1 = new ResultsReturn(CompetitionType, Norwegian, ChampionShip); obj1.ClubId = "01-42"; obj1.CompetitorId = 1; obj1.FigureHitsTotal = 12; obj1.FinalShootingPlace = 100; obj1.HitsTotal = 100; obj1.PointsTotal = 0; obj1.ShooterName = "First Shooter " + testName; obj1.HitsPerStn = new int[] { 50, 50 }; obj1.FigureHitsPerStn = new int[] { 0, 0 }; obj1.PointsPerStn = new int[] { 0, 0 }; obj2 = new ResultsReturn(CompetitionType, Norwegian, ChampionShip); obj2.ClubId = "01-42"; obj2.CompetitorId = 1; obj2.FigureHitsTotal = 12; obj2.FinalShootingPlace = 100; obj2.HitsTotal = 100; obj2.PointsTotal = 0; obj2.ShooterName = "Second Shooter " + testName; obj2.HitsPerStn = new int[] { 50, 50 }; obj2.FigureHitsPerStn = new int[] { 0, 0 }; obj2.PointsPerStn = new int[] { 0, 0 }; }
private void SetupField(Structs.CompetitionTypeEnum CompetitionType, bool Norwegian, out ResultsReturn obj1, out ResultsReturn obj2, string testName, Structs.CompetitionChampionshipEnum ChampionShip) { obj1 = new ResultsReturn( CompetitionType, Norwegian, ChampionShip); obj1.ClubId = "01-42"; obj1.CompetitorId = 1; obj1.FigureHitsTotal = 12; obj1.FinalShootingPlace = 100; obj1.HitsTotal = 12; obj1.PointsTotal = 10; obj1.ShooterName = "First Shooter " + testName; obj1.HitsPerStn = new int[] {6, 6}; obj1.FigureHitsPerStn = new int[] {2, 2}; obj1.PointsPerStn = new int[] {0,11}; obj2 = new ResultsReturn( CompetitionType, Norwegian, ChampionShip); obj2.ClubId = "01-42"; obj2.CompetitorId = 1; obj2.FigureHitsTotal = 12; obj2.FinalShootingPlace = 100; obj2.HitsTotal = 12; obj2.PointsTotal = 10; obj2.ShooterName = "Second Shooter " + testName; obj2.HitsPerStn = new int[] {6,6}; obj2.FigureHitsPerStn = new int[] {2,2}; obj2.PointsPerStn = new int[] {0,11}; }
internal CResultHolder(Structs.ResultWeaponsClass wclass, Structs.ShootersClass uclass, bool norwegianCount, bool finalResults, ResultsReturn[] results) { WClass = wclass; UClass = uclass; NorwegianCount = norwegianCount; FinalResults = finalResults; Results = results; }
string getResultStringField(ResultsReturn result) { string toReturn; if (!CommonCode.CompetitionCurrent.NorwegianCount) { toReturn = result.HitsTotal.ToString() + "/" + result.FigureHitsTotal.ToString() + " (" + result.PointsTotal.ToString() + " p)"; } else { toReturn = (result.HitsTotal + result.FigureHitsTotal).ToString() + " (" + result.PointsTotal.ToString() + " p)"; } return(toReturn); }
private void runCheck(ResultsReturn obj1, ResultsReturn obj2) { List<ResultsReturn> list = new List<ResultsReturn>(); list.Add(obj1); list.Add(obj2); list.Sort(); Assert.AreEqual(obj1, list[0], "Sorting nr 1-1 failed!"); Assert.AreEqual(obj2, list[1], "Sorting nr 1-2 failed!"); list = new List<ResultsReturn>(); list.Add(obj2); list.Add(obj1); list.Sort(); Assert.AreEqual(obj1, list[0], "Sorting nr 2-1 failed!"); Assert.AreEqual(obj2, list[1], "Sorting nr 2-2 failed!"); }
private void runCheck(ResultsReturn obj1, ResultsReturn obj2) { List <ResultsReturn> list = new List <ResultsReturn>(); list.Add(obj1); list.Add(obj2); list.Sort(); Assert.AreEqual(obj1, list[0], "Sorting nr 1-1 failed!"); Assert.AreEqual(obj2, list[1], "Sorting nr 1-2 failed!"); list = new List <ResultsReturn>(); list.Add(obj2); list.Add(obj1); list.Sort(); Assert.AreEqual(obj1, list[0], "Sorting nr 2-1 failed!"); Assert.AreEqual(obj2, list[1], "Sorting nr 2-2 failed!"); }
internal ResultsReturn ResultsGetCompetitor( Structs.Competitor competitor) { Structs.Competition competition = myInterface.CompetitionCurrent; ResultsReturn toReturn = new ResultsReturn( competition.Type, competition.NorwegianCount, competition.Championship); Structs.Shooter shooter = myInterface.GetShooter(competitor.ShooterId); Structs.CompetitorResult[] results = myInterface.GetCompetitorResults(competitor.CompetitorId); int figureHits = 0; int hits = 0; int points = 0; foreach (Structs.CompetitorResult result in results) { figureHits += result.FigureHits; hits += result.Hits; points += result.Points; toReturn.AddHitsPerStn(result.Hits); toReturn.AddFigureHitsPerStn(result.FigureHits); toReturn.AddPointsPerStn(result.Points); } toReturn.ClubId = shooter.ClubId; toReturn.CompetitorId = competitor.CompetitorId; toReturn.FigureHitsTotal = figureHits; toReturn.HitsTotal = hits; toReturn.PointsTotal = points; toReturn.ShooterName = shooter.Surname + " " + shooter.Givenname; toReturn.FinalShootingPlace = competitor.FinalShootingPlace; return(toReturn); }
string getResultStringField(ResultsReturn result) { string toReturn; if (!CommonCode.CompetitionCurrent.NorwegianCount) { toReturn = result.HitsTotal.ToString() + "/" + result.FigureHitsTotal.ToString() + " (" + result.PointsTotal.ToString() + " p)"; } else { toReturn = (result.HitsTotal + result.FigureHitsTotal).ToString() + " (" + result.PointsTotal.ToString() + " p)"; } return toReturn; }
internal ResultsReturn ResultsGetCompetitor( Structs.Competitor competitor) { Structs.Competition competition = myInterface.CompetitionCurrent; ResultsReturn toReturn = new ResultsReturn( competition.Type, competition.NorwegianCount, competition.Championship); Structs.Shooter shooter = myInterface.GetShooter(competitor.ShooterId); Structs.CompetitorResult[] results = myInterface.GetCompetitorResults(competitor.CompetitorId); int figureHits = 0; int hits = 0; int points = 0; foreach (Structs.CompetitorResult result in results) { figureHits += result.FigureHits; hits += result.Hits; points += result.Points; toReturn.AddHitsPerStn(result.Hits); toReturn.AddFigureHitsPerStn(result.FigureHits); toReturn.AddPointsPerStn(result.Points); } toReturn.ClubId = shooter.ClubId; toReturn.CompetitorId = competitor.CompetitorId; toReturn.FigureHitsTotal = figureHits; toReturn.HitsTotal = hits; toReturn.PointsTotal = points; toReturn.ShooterName = shooter.Surname + " " + shooter.Givenname; toReturn.FinalShootingPlace = competitor.FinalShootingPlace; return toReturn; }
private string RenderResults(ResultsReturn[] results) { try { Structs.CompetitionTypeEnum compType = myInterface.CompetitionCurrent.Type; StringBuilder toReturn = new StringBuilder(); if (compType == Structs.CompetitionTypeEnum.Precision) { toReturn.Append("Plats\tNamn\tKlubb\tResultat\tTot\tStm\r\n"); } else { toReturn.Append("Plats\tNamn\tKlubb\tResultat\tTot\tPoäng\tStm\r\n"); } bool norwegianCount = myInterface.CompetitionCurrent.NorwegianCount; Hashtable clubs = new Hashtable(); int place = 0; foreach (ResultsReturn res in results) { place++; toReturn.Append(place.ToString() + "\t"); toReturn.Append(res.ShooterName + "\t"); if (clubs[res.ClubId] == null) { clubs[res.ClubId] = myInterface.GetClub(res.ClubId).Name; } toReturn.Append((string)clubs[res.ClubId] + "\t"); switch (compType) { case Structs.CompetitionTypeEnum.Field: if (norwegianCount) { foreach (string stnRes in res.HitsPerStnString.Split(';')) { toReturn.Append(stnRes + " "); } toReturn.Append("\t" + (res.HitsTotal + res.FigureHitsTotal).ToString() + "\t"); } else { toReturn.Append("\"" + res.HitsPerStnString.Replace(';', ' ') + "\"\t"); toReturn.Append("\" " + res.HitsTotal.ToString() + "/" + res.FigureHitsTotal.ToString() + "\"\t"); } break; case Structs.CompetitionTypeEnum.MagnumField: if (norwegianCount) { foreach (string stnRes in res.HitsPerStnString.Split(';')) { try { if (stnRes.Trim() != "") { int hits = int.Parse(stnRes.Split('/')[0]); int figures = int.Parse(stnRes.Split('/')[1]); toReturn.Append((hits + figures).ToString() + " "); } } catch (System.FormatException exc) { Trace.WriteLine(exc.ToString()); } } toReturn.Append("\t" + (res.HitsTotal + res.FigureHitsTotal).ToString() + "\t"); } else { toReturn.Append("\"" + res.HitsPerStnString.Replace(';', ' ') + "\"\t"); toReturn.Append("\" " + res.HitsTotal.ToString() + "/" + res.FigureHitsTotal.ToString() + "\"\t"); } break; case Structs.CompetitionTypeEnum.Precision: foreach (string stnRes in res.HitsPerStnString.Split(';')) { try { if (stnRes.Trim() != "") { toReturn.Append(stnRes.Trim() + " "); } } catch (System.FormatException exc) { Trace.WriteLine(exc.ToString()); } } toReturn.Append("\t" + (res.HitsTotal + res.FigureHitsTotal).ToString() + "\t"); break; default: throw new NotImplementedException(); } if (compType != Structs.CompetitionTypeEnum.Precision) { toReturn.Append(res.PointsTotal.ToString() + "\t"); } Structs.Medal medal = (Structs.Medal)res.Medal; switch (medal) { case Structs.Medal.StandardSilver: toReturn.Append("S\t"); break; case Structs.Medal.StardardBrons: toReturn.Append("B\t"); break; default: toReturn.Append("\t"); break; } toReturn.Append("\r\n"); } return toReturn.ToString(); } catch (Exception exc) { Trace.WriteLine(exc.ToString()); throw; } }
private void printCompetitor(PrintPageEventArgs ev, Structs.Competitor competitor, PrintLabel label) { Trace.WriteLine("Competitor: " + competitor.CompetitorId); ResultsReturn result = CommonCode.ResultsGetCompetitor(competitor); float y = label.Y + label.MarginalTop; float x = label.X + label.MarginalLeft; string shooterClass = getShooterClassString( CommonCode.GetCompetitor(result.CompetitorId)); ev.Graphics.DrawString( shooterClass, printFont, Brushes.Black, x, y, new StringFormat()); float indent = ev.Graphics.MeasureString("RES", printFont).Width; x = x + indent; ev.Graphics.DrawString( result.ShooterName, printFont, Brushes.Black, x, y, new StringFormat()); y += printFont.Height; Structs.Club club = CommonCode.GetClub( result.ClubId); ev.Graphics.DrawString( club.Name, printFont, Brushes.Black, x, y, new StringFormat()); y += printFont.Height; string resultString = ""; switch (CommonCode.CompetitionCurrent.Type) { case Structs.CompetitionTypeEnum.Field: resultString = getResultStringField(result); break; case Structs.CompetitionTypeEnum.MagnumField: resultString = getResultStringField(result); break; case Structs.CompetitionTypeEnum.Precision: resultString = result.HitsTotal.ToString() + " p"; break; } ev.Graphics.DrawString( resultString, printFont, Brushes.Black, x, y, new StringFormat()); y += printFont.Height; }
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 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 List <ResultsReturn> getAllCompetitors(Structs.ResultWeaponsClass wclass, Structs.ShootersClass uclass, bool standardMedalsCalculation) { List <ResultsReturn> results = new List <ResultsReturn>(); Structs.Competition competition = myInterface.CompetitionCurrent; Hashtable shooters = new Hashtable(); Hashtable weapons = new Hashtable(); string selectString = ""; string standardClass = "ShooterClass=" + ((int)Structs.ShootersClass.Klass1).ToString() + " or ShooterClass=" + ((int)Structs.ShootersClass.Klass2).ToString() + " or ShooterClass=" + ((int)Structs.ShootersClass.Klass3).ToString() + " or ShooterClass=" + ((int)Structs.ShootersClass.Öppen).ToString(); string damClass = "ShooterClass=" + ((int)Structs.ShootersClass.Damklass1).ToString() + " or ShooterClass=" + ((int)Structs.ShootersClass.Damklass2).ToString() + " or ShooterClass=" + ((int)Structs.ShootersClass.Damklass3).ToString(); string extraClasses = "ShooterClass=" + ((int)Structs.ShootersClass.Juniorklass).ToString() + " or ShooterClass=" + ((int)Structs.ShootersClass.VeteranklassYngre).ToString() + " or ShooterClass=" + ((int)Structs.ShootersClass.VeteranklassÄldre).ToString(); if (standardMedalsCalculation) { if (wclass == Structs.ResultWeaponsClass.C && (competition.Championship == Structs.CompetitionChampionshipEnum.SM | competition.Championship == Structs.CompetitionChampionshipEnum.Landsdel)) { switch (uclass) { case Structs.ShootersClass.Klass: selectString = standardClass; break; case Structs.ShootersClass.Klass1: selectString = standardClass; break; case Structs.ShootersClass.Klass2: selectString = standardClass; break; case Structs.ShootersClass.Klass3: selectString = standardClass; break; case Structs.ShootersClass.Öppen: selectString = "ShooterClass=" + ((int)uclass).ToString(); break; case Structs.ShootersClass.Damklass: selectString = damClass; break; case Structs.ShootersClass.Damklass1: selectString = damClass; break; case Structs.ShootersClass.Damklass2: selectString = damClass; break; case Structs.ShootersClass.Damklass3: selectString = damClass; break; case Structs.ShootersClass.Juniorklass: selectString = "ShooterClass=" + ((int)Structs.ShootersClass.Juniorklass).ToString(); break; case Structs.ShootersClass.VeteranklassYngre: selectString = "ShooterClass=" + ((int)Structs.ShootersClass.VeteranklassYngre).ToString(); break; case Structs.ShootersClass.VeteranklassÄldre: selectString = "ShooterClass=" + ((int)Structs.ShootersClass.VeteranklassÄldre).ToString(); break; default: throw new NotImplementedException("uclass: " + uclass.ToString()); } } else { selectString = ""; // Everyone in one calculation } } else { // Fetch the shooters switch (uclass) { case Structs.ShootersClass.Damklass: selectString = damClass; break; case Structs.ShootersClass.Klass: selectString = standardClass; break; case Structs.ShootersClass.Okänd: selectString = ""; break; default: selectString = "ShooterClass=" + ((int)uclass).ToString(); break; } } foreach (DatabaseDataset.CompetitorsRow row in database.Competitors.Select(selectString)) { // What shootersclass is current user? #if DEBUG Structs.ShootersClass currentUclass = (Structs.ShootersClass)row.ShooterClass; // TODO Remove #endif // Setup a cache for weapons. Structs.Weapon weapon; if (weapons.ContainsKey(row.WeaponId)) { weapon = (Structs.Weapon)weapons[row.WeaponId]; } else { weapon = myInterface.GetWeapon(row.WeaponId); weapons.Add(row.WeaponId, weapon); } // For each competitor, find the result (competitorresults) // and add together /*if ( (myInterface.ConvertWeaponsClassToResultClass( * weapon.WClass) == wclass | * wclass == Structs.ResultWeaponsClass.Unknown) * & * ( uclass == currentUclass | uclass == Structs.ShootersClass.Okänd))*/ if (myInterface.ConvertWeaponsClassToResultClass( weapon.WClass) == wclass | wclass == Structs.ResultWeaponsClass.Unknown) { ResultsReturn thisResult = ResultsGetCompetitor(row.CompetitorId); if (thisResult.HitsTotal > 0) { results.Add(thisResult); } } } return(results); }