public void TestStandardFieldTwoShooters()
		{
			Structs.Competition competition = new Structs.Competition();
			competition.Championship = Structs.CompetitionChampionshipEnum.Club;
			competition.DoFinalShooting = false;
			competition.FirstPrice = 400;
			competition.Name = "Unittest Field Two Shooters";
			competition.NorwegianCount = false;
			competition.PatrolConnectionType = Structs.PatrolConnectionTypeEnum.AR_B_C_M;
			competition.Type = Structs.CompetitionTypeEnum.Field;
			intf.NewCompetition(competition);

			createShooter(1);
			createShooter(2);
			createShooter(3);
			createShooter(4);
		}
		internal CPrintResultlist(ref Common.Interface newCommon, 
			Structs.ResultWeaponsClass wclasswanted,
			Structs.ShootersClass uclasswanted,
			bool prelResults,
			string clubIdwanted) : base ()  
		{
			CommonCode = newCommon;
			wclass = wclasswanted;
			uclass = uclasswanted;
			printPrelResults = prelResults;
			clubId = clubIdwanted;

			competition = CommonCode.GetCompetitions()[0];
			CompetitionType = competition.Type;
		}
		private void btnSave_Click(object sender, System.EventArgs e)
		{
			// Check input
			try
			{
				int.Parse(this.txtShooterFee1.Text);
			}
			catch(System.FormatException)
			{
				MessageBox.Show("Anmälningsavgift verkar innehålla annat än siffror.", 
					"Inmatningsfel", 
					MessageBoxButtons.OK, 
					MessageBoxIcon.Warning);
				this.txtShooterFee1.Focus();
				return;
			}
			try
			{
				int.Parse(this.txtFirstPrice.Text);
			}
			catch(System.FormatException)
			{
				MessageBox.Show("Förstapris verkar innehålla annat än siffror.", 
					"Inmatningsfel", 
					MessageBoxButtons.OK, 
					MessageBoxIcon.Warning);
				this.txtFirstPrice.Focus();
				return;
			}

			if ((Structs.PatrolConnectionTypeEnum)DDPatrolConnectionType.SelectedIndex !=
				competition.PatrolConnectionType)
			{
				if (!checkChangePatrolConnectionTypeIsPossible())
					return;
			}

			// ok, now save
			comps = CommonCode.GetCompetitions();

			if (comps.Length >= 1)
				competition = comps[0];

			competition.Name = this.txtName.Text;
			competition.Type = Structs.CompetitionTypeEnum.Field;
			competition.NorwegianCount = false;
			competition.PatrolSize = (int)this.numPatrolSize.Value;
			competition.PatrolTimeBetween = (int)this.numPatrolTimeBetween.Value;
			competition.StartTime = this.dateTimePicker1.Value.Date;
			competition.StartTime =
				competition.StartTime.AddHours((double)this.numStartHour.Value)
				.AddMinutes((double)this.numStartMinute.Value);
			competition.DoFinalShooting = this.chkFinal.Checked;
			competition.UsePriceMoney = this.chkUsePriceMoney.Checked;
			competition.ShooterFee1 = int.Parse(this.txtShooterFee1.Text);
			competition.ShooterFee2 = int.Parse(this.txtShooterFee2.Text);
			competition.ShooterFee3 = int.Parse(this.txtShooterFee3.Text);
			competition.ShooterFee4 = int.Parse(this.txtShooterFee4.Text);
			competition.FirstPrice = int.Parse(this.txtFirstPrice.Text);
			competition.PriceMoneyPercentToReturn = (int)this.numPriceMoneyReturn.Value;
			competition.PriceMoneyShooterPercent = (int)numShoterPercentWithPrice.Value;
			competition.Type = Structs.CompetitionTypeEnum.Precision;
			competition.Championship = 
				(Structs.CompetitionChampionshipEnum)DDChampionship.SelectedIndex;
			competition.PatrolConnectionType =
				(Structs.PatrolConnectionTypeEnum)DDPatrolConnectionType.SelectedIndex;
			competition.OneClass = chkOneClass.Checked;

			if (comps.Length>0)
			{
				competition.CompetitionId = comps[0].CompetitionId;
				CommonCode.UpdateCompetition(competition);
			}
			else
				CommonCode.NewCompetition(competition);
			
			this.Visible = false;
			this.EnableMain();
		}
		internal Structs.Competition[] getCompetitions()
		{
			Trace.WriteLine("CDatabase: Entering getCompetitions() on thread \"" +
				System.Threading.Thread.CurrentThread.Name + "\" ( " +
				System.Threading.Thread.CurrentThread.ManagedThreadId.ToString() + " ) ");

			ArrayList competitions = new ArrayList();
			Structs.Competition competition = 
				new Structs.Competition();

			foreach(DatabaseDataset.CompetitionRow row in Database.Competition)
			{
				competition = new Structs.Competition();
				competition.CompetitionId = row.CompetitionId;
				competition.Name = row.Name;
				competition.NorwegianCount = row.NorwegianCount;
				competition.PatrolSize = row.PatrolSize;
				competition.PatrolTime = row.PatrolTime;
				competition.PatrolTimeBetween = row.PatrolTimeBetween;
				competition.PatrolTimeRest = row.PatrolTimeRest;
				competition.StartTime = row.StartDate.AddMinutes(row.StartTime);
				competition.DoFinalShooting = row.DoFinalShooting;
				competition.FirstPrice = row.FirstPrice;
				competition.PriceMoneyPercentToReturn = row.PriceMoneyPercentToReturn;
				competition.ShooterFee1 = row.ShooterFee1;
				competition.ShooterFee2 = row.ShooterFee2;
				competition.ShooterFee3 = row.ShooterFee3;
				competition.ShooterFee4 = row.ShooterFee4;
				competition.UsePriceMoney = row.UsePriceMoney;
				competition.PriceMoneyShooterPercent = row.PriceMoneyShooterPercent;
				competition.Type = (Structs.CompetitionTypeEnum)row.Type;
				competition.Championship = (Structs.CompetitionChampionshipEnum)row.Championship;
				competition.PatrolConnectionType = (Structs.PatrolConnectionTypeEnum)row.PatrolConnectionType;
				competition.OneClass = row.OneClass;
				competitions.Add(competition);
			}
			return (Structs.Competition[])competitions.ToArray(competition.GetType());
		}
		private void wizardPageFinish_CloseFromNext(object sender, PageEventArgs e)
		{
			Trace.WriteLine(e.ToString());
			Structs.Competition comp = new Structs.Competition();

			comp.DoFinalShooting = this.chkDoFinalShooting.Checked;
			comp.FirstPrice = (int)this.numPriceFirst.Value;
			comp.Name = this.txtName.Text;
			if (this.radioFieldStandard.Checked)
			{
				comp.Type = Structs.CompetitionTypeEnum.Field;
				comp.NorwegianCount = false;
			}
			else if (this.radioFieldNorwegian.Checked)
			{
				comp.Type = Structs.CompetitionTypeEnum.Field;
				comp.NorwegianCount = true;
			}
			else if (this.radioFieldMagnum.Checked)
			{
				comp.Type = Structs.CompetitionTypeEnum.MagnumField;
				comp.NorwegianCount = false;
			}
			else if (this.radioBanskytte.Checked)
			{
				comp.Type = Structs.CompetitionTypeEnum.Precision;
				comp.NorwegianCount = false;
			}
			switch(comp.Type)
			{
				case Structs.CompetitionTypeEnum.Field:
				{
					comp.PatrolSize = (int)this.numFieldPatrolSize.Value;
					comp.PatrolTime = (int)this.numFieldPatrolTime.Value;
					comp.PatrolTimeBetween = (int)this.numFieldPatrolTimeBetween.Value;
					comp.PatrolTimeRest = (int)this.numFieldPatrolRestTime.Value;
					comp.PatrolConnectionType = (Structs.PatrolConnectionTypeEnum)
						DDFieldPatrolConnectionType.SelectedIndex;
					break;
				}
				case Structs.CompetitionTypeEnum.MagnumField:
				{
					comp.PatrolSize = (int)this.numFieldPatrolSize.Value;
					comp.PatrolTime = (int)this.numFieldPatrolTime.Value;
					comp.PatrolTimeBetween = (int)this.numFieldPatrolTimeBetween.Value;
					comp.PatrolTimeRest = (int)this.numFieldPatrolRestTime.Value;
					comp.PatrolConnectionType = (Structs.PatrolConnectionTypeEnum)
						DDFieldPatrolConnectionType.SelectedIndex;
					break;
				}
				case Structs.CompetitionTypeEnum.Precision:
				{
					comp.PatrolSize = (int)this.numPrecisionPatrolSize.Value;
					//comp.PatrolTime = (int)this.numPrecisionPatrolTime.Value;
					comp.PatrolTimeBetween = (int)this.numPrecisionPatrolTimeBetween.Value;
					comp.PatrolTimeRest = 0;
					comp.PatrolConnectionType = (Structs.PatrolConnectionTypeEnum)
						DdPrecisionPatrolConnectionType.SelectedIndex;
					break;
				}
				default:
				{
					throw new ApplicationException("Not implemented yet");
				}
			}
			comp.PriceMoneyPercentToReturn = (int)this.numPriceRepay.Value;
			comp.PriceMoneyShooterPercent = (int)this.numPriceShooters.Value;
			comp.ShooterFee1 = (int)this.numPriceDeposit1.Value;
			comp.ShooterFee2 = (int)this.numPriceDeposit2.Value;
			comp.ShooterFee3 = (int)this.numPriceDeposit3.Value;
			comp.ShooterFee4 = (int)this.numPriceDeposit4.Value;

			DateTime starttime = this.dateTimePickerStart.Value;
			int hour = int.Parse(this.txtStartTime.Text.Split(':')[0]);
			int minute = int.Parse(this.txtStartTime.Text.Split(':')[1]);
			starttime = starttime.AddHours(hour);
			starttime = starttime.AddMinutes(minute);
			comp.StartTime = starttime;
			comp.UsePriceMoney = this.chkPriceMoney.Checked;

			comp.Championship = (Structs.CompetitionChampionshipEnum)
				ddChampionshipType.SelectedIndex;
			if (comp.Championship == Structs.CompetitionChampionshipEnum.Nationell ||
				comp.Championship == Structs.CompetitionChampionshipEnum.SM)
				comp.OneClass = true;
			else
				comp.OneClass = false;

			CommonCode.NewCompetition(comp);
			this.EnableMain();
		}
		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 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;
		}