private void saveCurrent()
		{
			int nrOfStations = (int)numNrOfSeries.Value;
			int nrOfShootsPerStation = (int)numNrOfShootPerSeries.Value;

			int shoots = 0;
			int figures = 0;
			switch (chkUseOnlyOneBoxForResult.Checked)
			{
				case true:
					figures = 1;
					shoots = 10 * nrOfShootsPerStation;
					break;
				case false:
					figures = nrOfShootsPerStation;
					shoots = 10 * nrOfShootsPerStation;
					break;
			}
			for(int i=1; i<=CommonCode.GetStationsCount(); i++)
			{
				Structs.Station station = CommonCode.GetStation(i, false);
				station.Figures = figures;
				station.Shoots = shoots;
				CommonCode.UpdateStation(station);
			}

			while(CommonCode.GetStationsCount() < nrOfStations)
			{
				Structs.Station station = new Structs.Station();
				station.CompetitionId = CommonCode.GetCompetitions()[0].CompetitionId;
				station.Figures = figures;
				station.Points = false;
				station.Shoots = shoots;
				station.StationNr = CommonCode.GetStationsCount() + 1;
				CommonCode.NewStation(station, false);
			}
			while(CommonCode.GetStationsCount() > nrOfStations)
			{
				Structs.Station station = CommonCode.GetStation(CommonCode.GetStationsCount(), false);
				CommonCode.DelStation(station);
			}
			
			Structs.Competition competition = CommonCode.GetCompetitions()[0];
			int timeAvailable = competition.PatrolTimeBetween;
			int timeNeeded = calculateTimeRequirements();
			if (timeNeeded > timeAvailable )
			{
				DialogResult res = MessageBox.Show("Du har avsatt " + timeAvailable.ToString() + 
					" minuter för varje skjutlag.\r\n\r\n" + 
					"Beräknad tid för varje skjutlag med hänsyn taget till " +
					"skjuttid (6 minuter per serie) och markeringstid " +
					"(6 minuter per serie) är " +
					timeNeeded.ToString() + " minuter.\r\n\r\n" +
					"Vill du öka upp avsatt tid?", 
					"Kontrollberäkning", 
					MessageBoxButtons.YesNo, 
					MessageBoxIcon.Warning);
				if (res == DialogResult.Yes)
				{
					competition.PatrolTimeBetween = timeNeeded;
					CommonCode.UpdateCompetition(competition);
					DateTime patrolStart = competition.StartTime;
					Structs.Patrol[] patrols = CommonCode.GetPatrols();
					for(int i=0;i<patrols.Length;i++)
					{
						Structs.Patrol patrol = patrols[i];

						//Trace.WriteLine(patrol.StartDateTimeDisplay.ToShortTimeString());
						patrol.StartDateTime = patrolStart;
						patrol.StartDateTimeDisplay = patrolStart;
						CommonCode.UpdatePatrol(patrol);

						patrolStart = patrolStart.AddMinutes(timeNeeded);
					}
				}
			}
		}
		private void saveCurrentStation()
		{
			Trace.WriteLine("FStations: saveCurrentStation on thread \"" +
				Thread.CurrentThread.Name + "\" ( " +
				AppDomain.GetCurrentThreadId().ToString() + " )");

			if (CommonCode.GetCompetitions().Length == 0)
				return;

			foreach(Structs.Station station in stationList)
			{
				if (station.StationNr == int.Parse(this.lblStationNr.Text))
				{
					// Found station, so change it by creating a new and 
					// updating with that
					Structs.Station updStation = station;

					updStation.CompetitionId = station.CompetitionId;
					updStation.Figures = (int)this.numNumberOfFigures.Value;
					updStation.Shoots = (int)this.numNumberOfShoots.Value;
					updStation.Points = this.chkPoints.Checked;
					updStation.StationId = station.StationId;
					updStation.StationNr = station.StationNr;

					CommonCode.UpdateStation(updStation);
					Trace.WriteLine("FStations: saveCurrentStation ended.");
					return;
				}
			}
			Structs.Station newStation = new Structs.Station();
			newStation.StationId = int.Parse(this.lblStationNr.Text);
			newStation.CompetitionId = CommonCode.GetCompetitions()[0].CompetitionId;
			newStation.Figures = (int)this.numNumberOfFigures.Value;
			newStation.Points = this.chkPoints.Checked;
			newStation.Shoots = (int)this.numNumberOfShoots.Value;
			newStation.StationNr = int.Parse(this.lblStationNr.Text);
			CommonCode.NewStation(newStation);

			Trace.WriteLine("FStations: saveCurrentStation ended.");
		}
		private void btnAddStation_Click(object sender, System.EventArgs e)
		{
			Structs.Station station = new Structs.Station();
			station.CompetitionId = CommonCode.GetCompetitions()[0].CompetitionId;
			station.Figures = 3;
			station.Points = false;
			station.Shoots = 6;
			station.StationNr = CommonCode.GetStationsCount() + 1;
			CommonCode.NewStation(station, false);
		}
		internal Structs.Station getStation(int StationNr, bool Distinguish)
		{
			Trace.WriteLine("CDatabase: Entering getStation(" + 
				StationNr.ToString() + ")");

			foreach(DatabaseDataset.StationsRow row in
				Database.Stations.Select("StationNr=" +  StationNr.ToString() +
				" and Distinguish=" + Distinguish.ToString(), "StationId"))
			{
				if (row.StationNr == StationNr)
				{
					Structs.Station station = new Structs.Station();
					station.CompetitionId = row.CompetitionId;
					station.Figures = row.Figures;
					station.Points = row.Points;
					station.Shoots = row.Shoots;
					station.StationNr = row.StationNr;
					station.StationId = row.StationId;
					station.Distinguish = row.Distinguish;
					return station;
				}
			}
			throw new CannotFindIdException("Could not find stationnr " + StationNr.ToString());
		}
		internal Structs.Station[] getStationsDistinguish()
		{
			Trace.WriteLine("CDatabase: Entering getStationsDistinguish()");

			List<Structs.Station> stations = new List<Structs.Station>();

			foreach (DatabaseDataset.StationsRow row in
				Database.Stations.Select("", "StationNr"))
			{
				if (row.Distinguish)
				{
					Structs.Station station = new Structs.Station();
					station.CompetitionId = row.CompetitionId;
					station.Figures = row.Figures;
					station.Points = row.Points;
					station.Shoots = row.Shoots;
					station.StationNr = row.StationNr;
					station.StationId = row.StationId;
					station.Distinguish = row.Distinguish;
					stations.Add(station);
				}
			}

			if (stations.Count > 0)
				return stations.ToArray();
			else
			{
				Structs.Station stn = new Structs.Station();
				stn.CompetitionId = getCompetitions()[0].CompetitionId;
				stn.StationNr = 1;
				stn.Points = false;
				switch (getCompetitions()[0].Type)
				{
					case Structs.CompetitionTypeEnum.Field:
						stn.Figures = 6;
						stn.Shoots = 6;
						break;
					case Structs.CompetitionTypeEnum.MagnumField:
						stn.Figures = 6;
						stn.Shoots = 6;
						break;
					case Structs.CompetitionTypeEnum.Precision:
						stn.Figures = 1;
						stn.Shoots = 50;
						break;
					default:
						throw new NotImplementedException(
							getCompetitions()[0].Type.ToString() +
							" is not implemented");
				}
				
				newStation(stn, true);
				return getStationsDistinguish();
			}
		}
		internal Structs.Station[] getStations()
		{
			Trace.WriteLine("CDatabase: Entering getStations()");

			List<Structs.Station> stations = new List<Structs.Station>();

			foreach(DatabaseDataset.StationsRow row in
				Database.Stations.Select("", "StationNr"))
			{
				if (!row.Distinguish)
				{
					Structs.Station station = new Structs.Station();
					station.CompetitionId = row.CompetitionId;
					station.Figures = row.Figures;
					station.Points = row.Points;
					station.Shoots = row.Shoots;
					station.StationNr = row.StationNr;
					station.StationId = row.StationId;
					station.Distinguish = row.Distinguish;
					stations.Add(station);
				}
			}
			return stations.ToArray();
		}