internal ResultsReturnTeam[] GetTeamResults(Structs.ResultWeaponsClass wclass, 
			Structs.Competition competition)
		{
			Trace.WriteLine("CResults.GetResults(" + wclass.ToString() +
				") started on thread \"" +
				System.Threading.Thread.CurrentThread.Name + "\" ( " +
				System.Threading.Thread.CurrentThread.ManagedThreadId.ToString() + " )");

			while (resultsAlreadyRunning)
				System.Threading.Thread.Sleep(50);

			Trace.WriteLine("CResults: GetResults() " + 
				" locking \"GetResultsLock\" on thread \"" +
				Thread.CurrentThread.Name + "\" ( " +
				System.Threading.Thread.CurrentThread.ManagedThreadId.ToString() + " )");

			lock(GetResultsLock)
			{
				Trace.WriteLine("CResults: GetResults() " + 
					" locked \"GetResultsLock\" on thread \"" +
					Thread.CurrentThread.Name + "\" ( " +
					System.Threading.Thread.CurrentThread.ManagedThreadId.ToString() + " )");

				try
				{
					resultsAlreadyRunning = true;
					CompetitionType = myInterface.CompetitionCurrent.Type;
					database = myInterface.databaseClass.Database;

					useNorwegianCount = competition.NorwegianCount;

					// Ok, now lets count the real ones
					DSResults results = getAllTeams(wclass);
					results = sortTeams(results);

					ResultsReturnTeam[] toReturn = 
						convertIntoArray(results);

					return toReturn;
				}
				finally
				{
					Trace.WriteLine("CResultsTeam: GetResults() " + 
						" unlocking \"GetResultsLock\" on thread \"" +
						Thread.CurrentThread.Name + "\" ( " +
						System.Threading.Thread.CurrentThread.ManagedThreadId.ToString() + " )");

					Trace.WriteLine("CResults.GetResults ended.");
					resultsAlreadyRunning = false;
				}
			}
		}
		internal Structs.Patrol[] getPatrols(
			Structs.PatrolClass patrolClass, 
			bool alsoIncludeUnknownClass,
			bool OnlyIncludePatrolsWithSpace,
			int PatrolIdToAlwaysView)
		{
			Trace.WriteLine("CDatabase: Entering getPatrols(PatrolClass=" + 
				patrolClass.ToString() + ", alsoIncludeUnknownClass=" +
				alsoIncludeUnknownClass.ToString() + ")");

			string select = "PClass=" + ((int)patrolClass).ToString();
			if (alsoIncludeUnknownClass)
				select += " or PClass=" + 
					((int)Structs.PatrolClass.Okänd).ToString();

			ArrayList patrols = new ArrayList();
			Structs.Patrol patrol = new Structs.Patrol();
			
			Structs.Competition competition = getCompetitions()[0];
			DateTime compStart = competition.StartTime;
			foreach(DatabaseDataset.PatrolsRow row in Database.Patrols.Select(
				select, "PatrolId"))
			{
				patrol = new Structs.Patrol();
				patrol.CompetitionId = row.CompetitionId;
				patrol.PatrolId = row.PatrolId;
				patrol.StartDateTime = compStart.AddMinutes(row.StartDateTime);
				patrol.PClass = (Structs.PatrolClass)row.PClass;
				if (row.StartDateTimeDisplay > -1054800000)
					patrol.StartDateTimeDisplay = compStart.AddMinutes(row.StartDateTimeDisplay);
				else
					patrol.StartDateTimeDisplay = patrol.StartDateTime;
				patrol.LockedForAutomatic = row.Automatic;

				if (!OnlyIncludePatrolsWithSpace |
					Database.Competitors.Select("PatrolId=" + 
						patrol.PatrolId.ToString()).Length<competition.PatrolSize |
					patrol.PatrolId == PatrolIdToAlwaysView)
				{
					patrols.Add(patrol);
				}
			}
			return (Structs.Patrol[])patrols.ToArray(patrol.GetType());
		}
		private string createTeamResults(Structs.ResultsReturnTeam[] results, 
			Structs.ResultWeaponsClass wclass)
		{
			StringBuilder html = new StringBuilder();
			html.Append("<h1>Lagtävling</h1>");
			html.Append("Vapenklass " + wclass.ToString() + ":");
			html.Append("<table>\r\n");
			html.Append("<tr>" +
				"<td><b>Pl</b></td>" +
				"<td><b>Klubb</b></td>" +
				"<td><b>Lag</b></td>" +
				"<td><b>Resultat</b></td>" + 
				"</tr>\r\n");

			int place = 0;
			foreach(Structs.ResultsReturnTeam result in results)
			{
				place++;
				html.Append("<tr>");
				html.Append("<td class=\"resultevenline\">" + place.ToString() + "</td>");
				html.Append("<td class=\"resultevenline\">" + myInterface.GetClub( result.ClubId ).Name + "</td>");
				html.Append("<td class=\"resultevenline\">" + result.TeamName + "</td>");
				if (myInterface.GetCompetitions()[0].NorwegianCount)
					html.Append("<td class=\"resultevenline\">" + (result.Hits + result.FigureHits).ToString() + "</td>");
				else
					html.Append("<td class=\"resultevenline\">" + result.Hits.ToString() + "/" + result.FigureHits.ToString() + "</td>");
				html.Append("</tr>\r\n");

				// The total results
				html.Append("<tr><td colspan=2></td>");
				html.Append("<td colspan=2>" + result.HitsPerStn.Replace(";", " ") + "</td>");
				html.Append("</tr>\r\n");

				Structs.Team team = myInterface.GetTeam( result.TeamId );
				ArrayList comps = new ArrayList();
				if (team.CompetitorId1 != -1)
					comps.Add(team.CompetitorId1);
				if (team.CompetitorId2 != -1)
					comps.Add(team.CompetitorId2);
				if (team.CompetitorId3 != -1)
					comps.Add(team.CompetitorId3);
				if (team.CompetitorId4 != -1)
					comps.Add(team.CompetitorId4);

				foreach(int compId in (int[])comps.ToArray(typeof(int)))
				{
					Structs.Competitor comp = myInterface.GetCompetitor(compId);
					html.Append("<tr><td colspan=2></td>");
					html.Append("<td>" + GetNameForCompetitor(comp) + "</td>");
					html.Append("<td>" + GetResultForCompetitor(comp) + "</td>");
					html.Append("</tr>\r\n");
				}
			}
			html.Append("</table>");
			return html.ToString();
		}
Example #4
0
		internal Structs.ShootersClass[] ResultsGetUClasses(
			Structs.ResultWeaponsClass wclass)
		{
			Trace.WriteLine("CResult.ResultsGetUClasses(\"" + 
				wclass.ToString() + "\") " +
				"started on thread \"" +
				System.Threading.Thread.CurrentThread.Name + "\" ( " +
				System.Threading.Thread.CurrentThread.ManagedThreadId.ToString() + " )");
			DateTime start = DateTime.Now;

			database = myInterface.databaseClass.Database;
			List<int> sClassesIntTable = new List<int>();
			List<Structs.ShootersClass> shooterClasses = new List<Structs.ShootersClass>();

			foreach(DatabaseDataset.CompetitorsRow row in
				database.Competitors)
			{
				Structs.Weapon weapon = myInterface.GetWeapon(row.WeaponId);
				if (myInterface.ConvertWeaponsClassToResultClass(weapon.WClass) == 
					wclass)
				{
					if (row.GetChildRows("CompetitorsCompetitorResults").Length > 0)
					{
						if (!sClassesIntTable.Contains(row.ShooterClass))
						{
							sClassesIntTable.Add(row.ShooterClass);
							Structs.ShootersClass uclass =
								(Structs.ShootersClass)row.ShooterClass;
							shooterClasses.Add(uclass);
						}
					}
				}
			}

			if (myInterface.CompetitionCurrent.OneClass)
			{
				if (shooterClasses.Contains(Structs.ShootersClass.Klass1) ||
					shooterClasses.Contains(Structs.ShootersClass.Klass2) ||
					shooterClasses.Contains(Structs.ShootersClass.Klass3))
				{
					shooterClasses.Add(Structs.ShootersClass.Klass);
					shooterClasses.Remove(Structs.ShootersClass.Klass1);
					shooterClasses.Remove(Structs.ShootersClass.Klass2);
					shooterClasses.Remove(Structs.ShootersClass.Klass3);
				}

				if (shooterClasses.Contains(Structs.ShootersClass.Damklass1) ||
					shooterClasses.Contains(Structs.ShootersClass.Damklass2) ||
					shooterClasses.Contains(Structs.ShootersClass.Damklass3))
				{
					shooterClasses.Add(Structs.ShootersClass.Damklass);
					shooterClasses.Remove(Structs.ShootersClass.Damklass1);
					shooterClasses.Remove(Structs.ShootersClass.Damklass2);
					shooterClasses.Remove(Structs.ShootersClass.Damklass3);
				}
			}

			/*for(int i=0 ; i<=Structs.ShootersClassMax ; i++)
			{
				try
				{
					if (sClassesIntTable.Contains(i))
					{
						int.Parse(((Structs.ShootersClass)i).ToString());
					}
				}
				catch(System.FormatException)
				{
					// Ok, we got a class
					Structs.ShootersClass uclass = 
						(Structs.ShootersClass)i;
					shooterClasses.Add(uclass);
				}
			}*/

			shooterClasses.Sort();

			Trace.WriteLine("CResult.ResultsGetUClasses(\"" + 
				wclass.ToString() + "\") " +
				"ending after " + 
				(DateTime.Now-start).TotalMilliseconds.ToString() + 
				" ms.");

			return shooterClasses.ToArray();
		}
Example #5
0
		internal ResultsReturn[] GetResults(
			Structs.ResultWeaponsClass wclass, 
			Structs.ShootersClass uclass,
			Structs.Competition competition,
			bool finalResults)
		{
			Trace.WriteLine("CResults.GetResults(" + wclass.ToString() 
				+ ", " + uclass.ToString() + 
				") started on thread \"" +
				System.Threading.Thread.CurrentThread.Name + "\" ( " +
				System.Threading.Thread.CurrentThread.ManagedThreadId.ToString() + " )");

			while (resultsAlreadyRunning)
				System.Threading.Thread.Sleep(50);

			Trace.WriteLine("CResults: GetResults() " + 
				" locking \"GetResultsLock\" on thread \"" +
				Thread.CurrentThread.Name + "\" ( " +
				System.Threading.Thread.CurrentThread.ManagedThreadId.ToString() + " )");

			lock(GetResultsLock)
			{
				Trace.WriteLine("CResults: GetResults() " + 
					" locked \"GetResultsLock\" on thread \"" +
					Thread.CurrentThread.Name + "\" ( " +
					System.Threading.Thread.CurrentThread.ManagedThreadId.ToString() + " )");

				try
				{
					resultsAlreadyRunning = true;

					database = myInterface.databaseClass.Database;

					useNorwegianCount = competition.NorwegianCount;

					// First find out about the standard medals
					calculateStandardMedals(wclass, uclass);

					// Ok, now lets count the real ones
					if (competition.OneClass)
					{
						switch (uclass)
						{
							case Structs.ShootersClass.Damklass:
								uclass = Structs.ShootersClass.Damklass;
								break;
							case Structs.ShootersClass.Damklass1:
								uclass = Structs.ShootersClass.Damklass;
								break;
							case Structs.ShootersClass.Damklass2:
								uclass = Structs.ShootersClass.Damklass;
								break;
							case Structs.ShootersClass.Damklass3:
								uclass = Structs.ShootersClass.Damklass;
								break;
							case Structs.ShootersClass.Juniorklass:
								break;
							case Structs.ShootersClass.Klass:
								uclass = Structs.ShootersClass.Klass;
								break;
							case Structs.ShootersClass.Klass1:
								uclass = Structs.ShootersClass.Klass;
								break;
							case Structs.ShootersClass.Klass2:
								uclass = Structs.ShootersClass.Klass;
								break;
							case Structs.ShootersClass.Klass3:
								uclass = Structs.ShootersClass.Klass;
								break;
							case Structs.ShootersClass.VeteranklassYngre:
								break;
							case Structs.ShootersClass.VeteranklassÄldre:
								break;
							case Structs.ShootersClass.Öppen:
								break;
							default:
								throw new NotSupportedException("Structs.ShootersClass." +
									uclass.ToString() + " is not supported");
						}
					}
					List<ResultsReturn> results = getAllCompetitors(wclass, uclass, false);
					results.Sort();
					if (myInterface.CompetitionCurrent.Championship !=
						Structs.CompetitionChampionshipEnum.Club)
					{
						results = markMedals(results);
					}
					else
					{
						// Mark all as not having medals
						foreach (ResultsReturn row in results)
						{
							row.Medal = Structs.Medal.None;
						}
					}

					if (finalResults)
					{
						results = markPriceMoney(results);
					}

					return results.ToArray();
				}
				finally
				{
					Trace.WriteLine("CResults: GetResults() " + 
						" unlocking \"GetResultsLock\" on thread \"" +
						Thread.CurrentThread.Name + "\" ( " +
						System.Threading.Thread.CurrentThread.ManagedThreadId.ToString() + " )");

					Trace.WriteLine("CResults.GetResults ended.");
					resultsAlreadyRunning = false;
				}
			}
		}
		internal void delCompetitorResult(Structs.CompetitorResult res)
		{
			Trace.WriteLine("CDatabase: Entering delCompetitorResult(" + 
				res.ToString() + ")");

			Trace.WriteLine("CDatabase: delCompetitorResult() " + 
				" locking \"DatabaseLocker\" on thread \"" +
				Thread.CurrentThread.Name + "\" ( " +
				System.Threading.Thread.CurrentThread.ManagedThreadId.ToString() + " )");
			lock(_databaseLocker)
			{
				Trace.WriteLine("CDatabase: delCompetitorResult() " + 
					" locked \"DatabaseLocker\" on thread \"" +
					Thread.CurrentThread.Name + "\" ( " +
					System.Threading.Thread.CurrentThread.ManagedThreadId.ToString() + " )");

				foreach(DatabaseDataset.CompetitorResultsRow row in 
					Database.CompetitorResults.Select(
					"ResultId=" + res.ResultId.ToString()))
				{
					if(row.ResultId == res.ResultId)
					{
						row.Delete();
					}
				}

				Trace.WriteLine("CDatabase: delCompetitorResult() " + 
					" unlocking \"DatabaseLocker\" on thread \"" +
					Thread.CurrentThread.Name + "\" ( " +
					System.Threading.Thread.CurrentThread.ManagedThreadId.ToString() + " )");
			}
			MyInterface.updatedCompetitorResult(res);
			return;
		}
		internal void delWeapon(Structs.Weapon weapon)
		{
			Trace.WriteLine("CDatabase: Entering delWeapon(" + 
				weapon.ToString() + ")");

			Trace.WriteLine("CDatabase: delWeapon() " + 
				" locking \"DatabaseLocker\" on thread \"" +
				Thread.CurrentThread.Name + "\" ( " +
				System.Threading.Thread.CurrentThread.ManagedThreadId.ToString() + " )");

			lock(_databaseLocker)
			{
				Trace.WriteLine("CDatabase: delWeapon() " + 
					" locked \"DatabaseLocker\" on thread \"" +
					Thread.CurrentThread.Name + "\" ( " +
					System.Threading.Thread.CurrentThread.ManagedThreadId.ToString() + " )");

				foreach(DatabaseDataset.WeaponsRow row in Database.Weapons.Select(
					"WeaponId='" + weapon.WeaponId + "'"))
				{
					if(row.WeaponId == weapon.WeaponId)
					{
						row.Delete();
					}
				}

				Trace.WriteLine("CDatabase: delWeapon() " + 
					" unlocking \"DatabaseLocker\" on thread \"" +
					Thread.CurrentThread.Name + "\" ( " +
					System.Threading.Thread.CurrentThread.ManagedThreadId.ToString() + " )");
			}
			MyInterface.updatedWeapon();
			return;
		}
		internal void delShooter(Structs.Shooter shooter)
		{
			Trace.WriteLine("CDatabase: Entering delShooter(" + 
				shooter.ToString() + ")");

			Trace.WriteLine("CDatabase: delShooter() " + 
				" locking \"DatabaseLocker\" on thread \"" +
				Thread.CurrentThread.Name + "\" ( " +
				System.Threading.Thread.CurrentThread.ManagedThreadId.ToString() + " )");

			lock(_databaseLocker)
			{
				Trace.WriteLine("CDatabase: delShooter() " + 
					" locked \"DatabaseLocker\" on thread \"" +
					Thread.CurrentThread.Name + "\" ( " +
					System.Threading.Thread.CurrentThread.ManagedThreadId.ToString() + " )");

				foreach(DatabaseDataset.ShootersRow row in Database.Shooters
					.Select("ShooterId=" + shooter.ShooterId.ToString()))
				{
					if(row.ShooterId == shooter.ShooterId)
					{
						row.Delete();
					}
				}

				Trace.WriteLine("CDatabase: delShooter() " + 
					" unlocking \"DatabaseLocker\" on thread \"" +
					Thread.CurrentThread.Name + "\" ( " +
					System.Threading.Thread.CurrentThread.ManagedThreadId.ToString() + " )");
			}
			MyInterface.updatedShooter(shooter);
			return;
		}
		internal void updatePatrol(Structs.Patrol patrol, bool updateGui)
		{
			Trace.WriteLine("CDatabase: Entering updatePatrol(" + 
				patrol.ToString() + ", " + updateGui.ToString() + ")");

			DateTime compStart = getCompetitions()[0].StartTime;

			bool found = false;
			foreach(DatabaseDataset.PatrolsRow row in 
				Database.Patrols.Select("PatrolId=" + patrol.PatrolId.ToString())) 
			{
				if (row.PatrolId == patrol.PatrolId)
				{
					row.CompetitionId = patrol.CompetitionId;
					row.StartDateTime = (int)(patrol.StartDateTime-compStart).TotalMinutes;
					row.StartDateTimeDisplay = (int)(patrol.StartDateTimeDisplay-compStart).TotalMinutes;
					row.PClass = (int)patrol.PClass;
					row.Automatic = patrol.LockedForAutomatic;

					found = true;
				}
			}
			if (!found)
				throw new CannotFindIdException("Could not find PatrolId " +
					patrol.PatrolId.ToString() + " to update");
			else
				if (updateGui)
					MyInterface.updatedPatrol();
		}
Example #10
0
		internal void updateCompetition(Structs.Competition competition)
		{
			Trace.WriteLine("CDatabase: Entering updateCompetition(" + 
				competition.ToString() + ")");

			bool found = false;
			bool PatrolConnectionTypeChanged = false;
			foreach(DatabaseDataset.CompetitionRow row in Database.Competition.Select(
				"CompetitionId=" + competition.CompetitionId.ToString()))
			{
				if (row.CompetitionId == competition.CompetitionId)
				{					
					row.Name = competition.Name;
					row.NorwegianCount = competition.NorwegianCount;
					row.PatrolSize = competition.PatrolSize;
					row.PatrolTime = competition.PatrolTime;
					row.PatrolTimeBetween = competition.PatrolTimeBetween;
					row.PatrolTimeRest = competition.PatrolTimeRest;
					row.StartDate = competition.StartTime.Date;
					row.StartTime = (int)competition.StartTime.TimeOfDay.TotalMinutes;
					row.DoFinalShooting = competition.DoFinalShooting;
					row.FirstPrice = competition.FirstPrice;
					row.PriceMoneyPercentToReturn = competition.PriceMoneyPercentToReturn;
					row.ShooterFee1 = competition.ShooterFee1;
					row.ShooterFee2 = competition.ShooterFee2;
					row.ShooterFee3 = competition.ShooterFee3;
					row.ShooterFee4 = competition.ShooterFee4;
					row.UsePriceMoney = competition.UsePriceMoney;
					row.PriceMoneyShooterPercent = competition.PriceMoneyShooterPercent;
					row.Type = (int)competition.Type;
					row.Championship = (int)competition.Championship;
					row.OneClass = competition.OneClass;

					if (row.PatrolConnectionType != (int)competition.PatrolConnectionType)
					{
						PatrolConnectionTypeChanged = true;
						row.PatrolConnectionType = (int)competition.PatrolConnectionType;
					}

					found = true;
				}
			}

			if (!found)
				throw new CannotFindIdException("Could not find competitionId " +
					competition.CompetitionId.ToString() + " to update");
			else
				MyInterface.updatedCompetition();
			
			if (PatrolConnectionTypeChanged)
			{
				MyInterface.patrolClass.ChangePatrolConnectionType(competition.PatrolConnectionType);
			}
		}
Example #11
0
		internal void updateWeapon(Structs.Weapon weapon)
		{
			Trace.WriteLine("CDatabase: Entering updateWeapon(" + 
				weapon.ToString() + ")");

			bool found = false;
			foreach(DatabaseDataset.WeaponsRow row in Database.Weapons.Select(
				"WeaponId='" + weapon.WeaponId + "'"))
			{
				if (row.WeaponId == weapon.WeaponId)
				{
					row.Manufacturer = weapon.Manufacturer;
					row.Model = weapon.Model;
					row.Caliber = weapon.Caliber;
					row.Class = (int)weapon.WClass;
					row.Automatic = weapon.Automatic;
					row.ToAutomatic = weapon.ToAutomatic;
					row.LastUpdate = DateTime.Now;

					found = true;
				}
			}
			if (!found)
				throw new CannotFindIdException("Could not find WeaponId " +
					weapon.WeaponId.ToString() + " to update");
			else
				MyInterface.updatedWeapon();
		}
Example #12
0
		internal void updateCompetitor(Structs.Competitor competitor, 
			bool updateGui)
		{
			Trace.WriteLine("CDatabase: Entering updateCompetitor(" + 
				competitor.ToString() + ")");

			if (competitor.WeaponId == null)
			{
				Trace.WriteLine("CDatabase: updateCompetitor " + 
					"competitor.WeaponId is null.");
				throw new CannotFindIdException("competitor.WeaponId is null.");
			}

			bool found = false;
			foreach(DatabaseDataset.CompetitorsRow row in 
				Database.Competitors.Select("CompetitorId=" + 
					competitor.CompetitorId.ToString()))
			{
				lock(_databaseLocker)
				{
					int oldPatrol = -1;
					int newPatrol = -1;
					try
					{
						// Check there isn't anyone already on that lane and patrol
						if (Database.Competitors.Select("PatrolId=" + competitor.PatrolId +
							" and Lane=" + competitor.Lane + 
							" and CompetitorId<>" + competitor.CompetitorId).Length>0)
						{
							throw new PatrolAndLaneAlreadyTakenException(
								"There already exist a competitor with patrol " + 
								competitor.PatrolId + " and lane " + 
								competitor.Lane + ". Error occured when updating " +
								"competitorId " + competitor.CompetitorId.ToString());
						}

						// Save new and old values for patrols
						if (!row.IsPatrolIdNull())
							oldPatrol = row.PatrolId;
						newPatrol = competitor.PatrolId;

						row.CompetitionId = competitor.CompetitionId;
						if (competitor.PatrolId == -1)
							row.SetPatrolIdNull();
						else
							row.PatrolId = competitor.PatrolId;
						row.ShooterId = competitor.ShooterId;
						row.WeaponId = competitor.WeaponId;
						row.ShooterClass = (int)competitor.ShooterClass;

						if (competitor.PatrolId != -1)
						{
							if (competitor.Lane == -1)
							{
								try
								{
									competitor.Lane = 
										MyInterface.patrolClass
										.GetNextLane(competitor.PatrolId);
								}
								catch(PatrolAlreadyFullException)
								{
									competitor.PatrolId = -1;
									row.SetPatrolIdNull();
									row.SetLaneNull();
									throw;
								}
							}
						}
						else
						{
							competitor.Lane = -1;
						}
						if (competitor.Lane == -1)
							row.SetLaneNull();
						else
							row.Lane = competitor.Lane;
						row.FinalShootingPlace = competitor.FinalShootingPlace;

						found = true;
					}
					finally
					{
						// Update patroltypes
						checkForPatrolClassUpdate(oldPatrol, updateGui);
						checkForPatrolClassUpdate(newPatrol, updateGui);
					}
				}
			}
			if (!found)
				throw new CannotFindIdException("Could not find CompetitorId " +
					competitor.CompetitorId.ToString() + " to update");
			else
				if (updateGui)
					MyInterface.updatedCompetitor(competitor);
		}
Example #13
0
		internal void updateShooter(Structs.Shooter shooter)
		{
			Trace.WriteLine("CDatabase: Entering updateShooter(" + 
				shooter.ToString() + ")");
			
			bool found = false;
			foreach(DatabaseDataset.ShootersRow row in Database.Shooters.Select(
				"ShooterId=" + shooter.ShooterId.ToString()))
			{
				if (row.ShooterId == shooter.ShooterId)
				{
					row.Arrived = shooter.Arrived;
					row.ClubId = shooter.ClubId;
					row.Cardnr = shooter.CardNr;
					row.Email = shooter.Email;
					row.Givenname = shooter.Givenname;
					row.Payed = shooter.Payed;
					row.Surname = shooter.Surname;
					row.ToAutomatic = shooter.ToAutomatic;
					row.Automatic = shooter.Automatic;
					row.Class = (int)shooter.Class;
					row.LastUpdate = DateTime.Now;
					found = true;
				}
			}
			if (!found)
				throw new CannotFindIdException("Could not find shooterId " +
					shooter.ShooterId.ToString() + " to update");
			else
				MyInterface.updatedShooter(shooter);
		}
Example #14
0
		internal void updateClub(Structs.Club club)
		{
			Trace.WriteLine("CDatabase: Entering updateClub(" + 
				club.ToString() + ")");

			bool found = false;
			foreach(DatabaseDataset.ClubsRow row in Database.Clubs.Select(
				"ClubId='" + club.ClubId + "'"))
			{
				if (row.ClubId == club.ClubId)
				{
					row.Country = club.Country;
					row.Name = club.Name;
					row.Automatic = club.Automatic;
					row.ToAutomatic = club.ToAutomatic;
					row.Plusgiro = club.Plusgiro;
					row.Bankgiro = club.Bankgiro;
					row.LastUpdate = DateTime.Now;

					found = true;
				}
			}
			if (!found)
				throw new CannotFindIdException("Could not find ClubId " +
					club.ClubId.ToString() + " to update");
			else
				MyInterface.updatedClub();
		}
Example #15
0
		internal bool getCompetitorResultsExist(Structs.ResultWeaponsClass wclass,
			Structs.ShootersClass uclass)
		{
			Trace.WriteLine("CDatabase: Entering getCompetitorResultsExist(" +
				wclass.ToString() + ", " + uclass.ToString() + ") on thread \"" +
				System.Threading.Thread.CurrentThread.Name + "\" ( " +
				System.Threading.Thread.CurrentThread.ManagedThreadId.ToString() + " ) ");

			try
			{
				Hashtable compsList = new Hashtable();
				Hashtable weaponsList = new Hashtable();
				foreach(DatabaseDataset.CompetitorResultsRow row in
					Database.CompetitorResults)
				{
					Structs.Competitor comp;
					if (compsList.ContainsKey(row.CompetitorId))
						comp = (Structs.Competitor)compsList[row.CompetitorId];
					else
					{
						comp = MyInterface.GetCompetitor(row.CompetitorId);
						compsList.Add(row.CompetitorId, comp);
					}
					Structs.Weapon weapon;
					if (weaponsList.ContainsKey(comp.WeaponId))
						weapon = (Structs.Weapon)weaponsList[comp.WeaponId];
					else
					{
						weapon = MyInterface.GetWeapon(comp.WeaponId);
						weaponsList.Add(comp.WeaponId, weapon);
					}
					if ( MyInterface.ConvertWeaponsClassToResultClass(
						weapon.WClass) == wclass)
					{
						// Weaponsclass is correct. Check Shooters class
						//Interface.Shooter shooter = 
						//	myInterface.GetShooter(comp.ShooterId);

						if (comp.ShooterClass == uclass)
							return true;
					}
				}
			}
			catch(System.InvalidOperationException)
			{
				// this occurs when the collection changed during testing.
				// try again
				Trace.WriteLine("CDatabase: getCompetitorResultsCount failed to changed collection. Retrying.");
				return getCompetitorResultsExist(wclass, uclass);
			}

			Trace.WriteLine("CDatabase: Leaving getCompetitorResultsExist()");
			return false;
		}
Example #16
0
		internal int newCompetitorResult(Structs.CompetitorResult res)
		{
			Trace.WriteLine("CDatabase: Entering newCompetitorResult(" + 
				res.ToString() + ")");

			DatabaseDataset.StationsRow stationsRow = 
				(DatabaseDataset.StationsRow)Database.Stations.Select("StationNr=" + res.Station.ToString())[0];

			DatabaseDataset.CompetitorResultsRow row =
				Database.CompetitorResults.NewCompetitorResultsRow();

			Random rnd = new Random();
			row.ResultId = 0 - rnd.Next(10000); // Will be automaticly set when updating database file
			row.CompetitorId = res.CompetitorId;
			row.Hits = res.Hits;
			row.StationId = stationsRow.StationId;
			row.FigureHits = res.FigureHits;
			row.Points = res.Points;
			row.StationFigureHits = res.StationFigureHits;

			Trace.WriteLine("CDatabase: newCompetitorResult() " + 
				" locking \"DatabaseLocker\" on thread \"" +
				Thread.CurrentThread.Name + "\" ( " +
				System.Threading.Thread.CurrentThread.ManagedThreadId.ToString() + " )");

			lock(_databaseLocker)
			{
				Trace.WriteLine("CDatabase: newCompetitorResult() " + 
					" locked \"DatabaseLocker\" on thread \"" +
					Thread.CurrentThread.Name + "\" ( " +
					System.Threading.Thread.CurrentThread.ManagedThreadId.ToString() + " )");

				// Check that there doesn't already exist a result
				// for this competitor and station
				if (Database.CompetitorResults.Select(
					"CompetitorId=" + row.CompetitorId + 
					" and StationId=" + row.StationId).Length > 0)
				{
					throw new ApplicationException(
						"Result for this competitor already exist!");
				}

				Database.CompetitorResults.AddCompetitorResultsRow(row);
				
				Trace.WriteLine("CDatabase: newCompetitorResult() " + 
					" unlocking \"DatabaseLocker\" on thread \"" +
					Thread.CurrentThread.Name + "\" ( " +
					System.Threading.Thread.CurrentThread.ManagedThreadId.ToString() + " )");
			}
			Console.WriteLine("New competitorResult:" + row.ResultId);
			MyInterface.updatedCompetitor( getCompetitor(res.CompetitorId) );
			return row.ResultId;
		}
Example #17
0
		internal void delClub(Structs.Club club)
		{
			Trace.WriteLine("CDatabase: Entering delClub(" + 
				club.ToString() + ")");

			Trace.WriteLine("CDatabase: delClub() " + 
				" locking \"DatabaseLocker\" on thread \"" +
				Thread.CurrentThread.Name + "\" ( " +
				System.Threading.Thread.CurrentThread.ManagedThreadId.ToString() + " )");

			lock(_databaseLocker)
			{
				Trace.WriteLine("CDatabase: delClub() " + 
					" locked \"DatabaseLocker\" on thread \"" +
					Thread.CurrentThread.Name + "\" ( " +
					System.Threading.Thread.CurrentThread.ManagedThreadId.ToString() + " )");

				foreach(DatabaseDataset.ClubsRow row in Database.Clubs.Select(
					"ClubId='" + club.ClubId + "'"))
				{
					if(row.ClubId == club.ClubId)
					{
						row.Delete();
					}
				}
				Trace.WriteLine("CDatabase: delClub() " + 
					" unlocking \"DatabaseLocker\" on thread \"" +
					Thread.CurrentThread.Name + "\" ( " +
					System.Threading.Thread.CurrentThread.ManagedThreadId.ToString() + " )");
			}
			MyInterface.updatedClub();
			return;
		}
Example #18
0
		internal void updateCompetitorResult(Structs.CompetitorResult competitorResult,
			bool UpdateInterface)
		{
			Trace.WriteLine("CDatabase: Entering updateCompetitorResult(" + 
				competitorResult.ToString() + ")");

			foreach(DatabaseDataset.CompetitorResultsRow row in 
				Database.CompetitorResults.Select(
				"ResultId=" + competitorResult.ResultId))
			{
				DatabaseDataset.StationsRow stationsRow = 
					(DatabaseDataset.StationsRow)Database.Stations.Select("StationId=" + row.StationId.ToString())[0];

				if (row.ResultId == competitorResult.ResultId)
				{
					row.CompetitorId = competitorResult.CompetitorId;
					row.Hits = competitorResult.Hits;
					if (stationsRow.StationNr != competitorResult.Station)
						throw new ApplicationException(
							"Ops. Updating a competitorresult with a new stationnr is not supported");
					row.FigureHits = competitorResult.FigureHits;
					row.Points = competitorResult.Points;
					row.StationFigureHits = competitorResult.StationFigureHits;

					if (UpdateInterface)
						MyInterface.updatedCompetitorResult(competitorResult);

					return;
				}
			}
			throw new CannotFindIdException("Could not find competitorResultId " +
					competitorResult.ResultId.ToString() + " to update");
		}
Example #19
0
		internal void delCompetitor(Structs.Competitor competitor, bool updateGui)
		{
			Trace.WriteLine("CDatabase: Entering delCompetitor(" + 
				competitor.ToString() + ")");

			Trace.WriteLine("CDatabase: delCompetitor() " + 
				" locking \"DatabaseLocker\" on thread \"" +
				Thread.CurrentThread.Name + "\" ( " +
				System.Threading.Thread.CurrentThread.ManagedThreadId.ToString() + " )");

			lock(_databaseLocker)
			{
				Trace.WriteLine("CDatabase: delCompetitor() " + 
					" locked \"DatabaseLocker\" on thread \"" +
					Thread.CurrentThread.Name + "\" ( " +
					System.Threading.Thread.CurrentThread.ManagedThreadId.ToString() + " )");

				foreach(DatabaseDataset.CompetitorsRow row in Database.Competitors
					.Select("CompetitorId=" + competitor.CompetitorId.ToString()))
				{
					if(row.CompetitorId == competitor.CompetitorId)
					{
						int patrolId = -1;
						if (!row.IsPatrolIdNull())
							patrolId = row.PatrolId;
						if (row.GetTeamsRowsByCompetitorsTeams1().Length > 0 ||
							row.GetTeamsRowsByCompetitorsTeams2().Length > 0 ||
							row.GetTeamsRowsByCompetitorsTeams3().Length > 0 ||
							row.GetTeamsRowsByCompetitorsTeams4().Length > 0 ||
							row.GetTeamsRowsByCompetitorsTeams5().Length > 0)
						{
							// Delete team membership in nr 1
							DatabaseDataset.TeamsRow[] teams1 =
								row.GetTeamsRowsByCompetitorsTeams1();
							foreach (DatabaseDataset.TeamsRow team in teams1)
							{
								team.SetCompetitorId1Null();
							}

							// Delete team membership in nr 2
							DatabaseDataset.TeamsRow[] teams2 =
								row.GetTeamsRowsByCompetitorsTeams2();
							foreach (DatabaseDataset.TeamsRow team in teams2)
							{
								team.SetCompetitorId2Null();
							}

							// Delete team membership in nr 3
							DatabaseDataset.TeamsRow[] teams3 =
								row.GetTeamsRowsByCompetitorsTeams3();
							foreach (DatabaseDataset.TeamsRow team in teams3)
							{
								team.SetCompetitorId3Null();
							}
							// Delete team membership in nr 4
							DatabaseDataset.TeamsRow[] teams4 =
								row.GetTeamsRowsByCompetitorsTeams4();
							foreach (DatabaseDataset.TeamsRow team in teams4)
							{
								team.SetCompetitorId4Null();
							}
							// Delete team membership in nr 5
							DatabaseDataset.TeamsRow[] teams5 =
								row.GetTeamsRowsByCompetitorsTeams5();
							foreach (DatabaseDataset.TeamsRow team in teams5)
							{
								team.SetCompetitorId5Null();
							}
							MyInterface.updatedTeam();
						}
						row.Delete();
						if (patrolId != -1)
							checkForPatrolClassUpdate(patrolId, updateGui);
					}
				}
				Trace.WriteLine("CDatabase: delCompetitor() " + 
					" unlocking \"DatabaseLocker\" on thread \"" +
					Thread.CurrentThread.Name + "\" ( " +
					System.Threading.Thread.CurrentThread.ManagedThreadId.ToString() + " )");
			}
			if (updateGui)
				MyInterface.updatedCompetitor(competitor);
			return;
		}
Example #20
0
		internal void newClub(Structs.Club club)
		{
			Trace.WriteLine("CDatabase: Entering newClub(" + 
				club.ToString() + ")");

			DatabaseDataset.ClubsRow row = Database.Clubs.NewClubsRow();
			row.ClubId = club.ClubId;
			row.Country = club.Country;
			row.Name = club.Name;
			row.Automatic = club.Automatic;
			row.ToAutomatic = club.ToAutomatic;
			row.Plusgiro = club.Plusgiro;
			row.Bankgiro = club.Bankgiro;
			row.LastUpdate = DateTime.Now;

			Trace.WriteLine("CDatabase: newClub() " + 
				" locking \"DatabaseLocker\" on thread \"" +
				Thread.CurrentThread.Name + "\" ( " +
				System.Threading.Thread.CurrentThread.ManagedThreadId.ToString() + " )");
			lock(_databaseLocker)
			{
				Trace.WriteLine("CDatabase: newClub() " + 
					" locked \"DatabaseLocker\" on thread \"" +
					Thread.CurrentThread.Name + "\" ( " +
					System.Threading.Thread.CurrentThread.ManagedThreadId.ToString() + " )");

				Database.Clubs.AddClubsRow(row);

				Trace.WriteLine("CDatabase: newClub() " + 
					" unlocking \"DatabaseLocker\" on thread \"" +
					Thread.CurrentThread.Name + "\" ( " +
					System.Threading.Thread.CurrentThread.ManagedThreadId.ToString() + " )");
			}
			MyInterface.updatedClub();
		}
Example #21
0
		internal void delPatrol(Structs.Patrol patrol, bool updateGui)
		{
			Trace.WriteLine("CDatabase: Entering delPatrol(" + 
				patrol.ToString() + ")");

			// TODO Remove all shooters that depend on this patrol

			Trace.WriteLine("CDatabase: delPatrol() " + 
				" locking \"DatabaseLocker\" on thread \"" +
				Thread.CurrentThread.Name + "\" ( " +
				System.Threading.Thread.CurrentThread.ManagedThreadId.ToString() + " )");
			lock(_databaseLocker)
			{
				Trace.WriteLine("CDatabase: delPatrol() " + 
					" locked \"DatabaseLocker\" on thread \"" +
					Thread.CurrentThread.Name + "\" ( " +
					System.Threading.Thread.CurrentThread.ManagedThreadId.ToString() + " )");

				foreach(DatabaseDataset.PatrolsRow row in Database.Patrols.Select(
					"PatrolId=" + patrol.PatrolId.ToString()))
				{
					if(row.PatrolId == patrol.PatrolId)
					{
						//database.Patrols.RemovePatrolsRow(row);
						row.Delete();
					}
				}
				Trace.WriteLine("CDatabase: delPatrol() " + 
					" unlocking \"DatabaseLocker\" on thread \"" +
					Thread.CurrentThread.Name + "\" ( " +
					System.Threading.Thread.CurrentThread.ManagedThreadId.ToString() + " )");
			}
			if (updateGui)
				MyInterface.updatedPatrol();
			return;
		}
Example #22
0
		internal int newShooter(Structs.Shooter shooter, bool updateGui)
		{
			Trace.WriteLine("CDatabase: Entering newShooter(" + 
				shooter.ToString() + ")");

			DatabaseDataset.ShootersRow row = 
				Database.Shooters.NewShootersRow();

			Random rnd = new Random();
			int shooterid = 0;
			try
			{
				while(true)
				{
					shooterid = -rnd.Next(20000)-200000;
					MyInterface.GetShooter(shooterid);
				}
			}
			catch(CannotFindIdException)
			{
				// Shooterid does not already exist. Very good.
			}
			row.ShooterId = shooterid; // Will be automaticly set when updating database file
			row.Arrived = shooter.Arrived;
			row.ClubId = shooter.ClubId;
			row.Cardnr = shooter.CardNr;
			row.Email = shooter.Email;
			row.Givenname = shooter.Givenname;
			row.Payed = shooter.Payed;
			row.Surname = shooter.Surname;
			row.ToAutomatic = shooter.ToAutomatic;
			row.Automatic = shooter.Automatic;
			row.Class = (int)shooter.Class;
			row.LastUpdate = DateTime.Now;

			Trace.WriteLine("CDatabase: newShooter() " + 
				" locking \"DatabaseLocker\" on thread \"" +
				Thread.CurrentThread.Name + "\" ( " +
				System.Threading.Thread.CurrentThread.ManagedThreadId.ToString() + " )");

			lock(_databaseLocker)
			{
				Trace.WriteLine("CDatabase: newShooter() " + 
					" locked \"DatabaseLocker\" on thread \"" +
					Thread.CurrentThread.Name + "\" ( " +
					System.Threading.Thread.CurrentThread.ManagedThreadId.ToString() + " )");

				Database.Shooters.AddShootersRow(row);

				Trace.WriteLine("CDatabase: newShooter() " + 
					" unlocking \"DatabaseLocker\" on thread \"" +
					Thread.CurrentThread.Name + "\" ( " +
					System.Threading.Thread.CurrentThread.ManagedThreadId.ToString() + " )");
			}
			if (updateGui)
			{
				MyInterface.updatedShooter(shooter);
			}
			else
			{
				UpdateDatabaseFile();
			}
			return row.ShooterId;
		}
Example #23
0
		internal void delStation(Structs.Station station, bool forcibleDelete)
		{
			Trace.WriteLine("CDatabase: Entering delStation(" + 
				station.ToString() + ")");

			Trace.WriteLine("CDatabase: delStation() " + 
				" locking \"DatabaseLocker\" on thread \"" +
				Thread.CurrentThread.Name + "\" ( " +
				System.Threading.Thread.CurrentThread.ManagedThreadId.ToString() + " )");
			lock(_databaseLocker)
			{
				Trace.WriteLine("CDatabase: delStation() " + 
					" locked \"DatabaseLocker\" on thread \"" +
					Thread.CurrentThread.Name + "\" ( " +
					System.Threading.Thread.CurrentThread.ManagedThreadId.ToString() + " )");

				string filter = "StationId=" + station.StationId.ToString();
				DatabaseDataset.CompetitorResultsRow[] compRows = 
					(DatabaseDataset.CompetitorResultsRow[])
					Database.CompetitorResults.Select(filter);

				if (forcibleDelete)
				{
					if (compRows.Length == 0)
					{
						foreach(DatabaseDataset.CompetitorResultsRow tstRow in
							Database.CompetitorResults.Rows)
						{
							if (tstRow.RowState != System.Data.DataRowState.Deleted)
								Trace.WriteLine("StationId: " + tstRow.StationId);
							else
								tstRow.Delete();
						}
					}
					foreach(DatabaseDataset.CompetitorResultsRow compRow in
						compRows)
					{
						compRow.Delete();
					}
					MyInterface.updatedCompetitorResult(new Structs.CompetitorResult());
				}
				else
				{
					if (compRows.Length != 0)
					{
						throw new ApplicationException("There is childrows in table CompetitorResultsRow");
					}
				}

				foreach(DatabaseDataset.StationsRow row in 
					Database.Stations.Select(
					"StationId=" + station.StationId.ToString()))
				{
					if(row.StationId == station.StationId)
					{
						row.Delete();
					}
				}

				Trace.WriteLine("CDatabase: delStation() " + 
					" unlocking \"DatabaseLocker\" on thread \"" +
					Thread.CurrentThread.Name + "\" ( " +
					System.Threading.Thread.CurrentThread.ManagedThreadId.ToString() + " )");
			}
			MyInterface.updatedStation();
			return;
		}
Example #24
0
		internal void newCompetitor(Structs.Competitor competitor, bool updateGui)
		{
			Trace.WriteLine("CDatabase: Entering newCompetitor(" + 
				competitor.ToString() + ")");

			if (competitor.WeaponId == null)
			{
				Trace.WriteLine("CDatabase: newCompetitor WeaponId is null.");
				throw new CannotFindIdException("competitors WeaponId is null");
			}

			checkCompetitorIsNotFullOnCompetitors(competitor.ShooterId);

			DatabaseDataset.CompetitorsRow row = 
				Database.Competitors.NewCompetitorsRow();

			Random rnd = new Random();
			int competitorid = 0;
			try
			{
				while(true)
				{
					competitorid = -rnd.Next(20000)-200000;
					MyInterface.GetCompetitor(competitorid);
				}
			}
			catch(CannotFindIdException)
			{
				// Competitorid does not already exist. Very good.
			}

			row.CompetitorId = competitorid; 
				// CompetitorId will be automaticly set when updating database file,
				// but it's important that it is unique since it's not safe
				// to assume that database file will be updated before next
				// competitor is added.
			row.CompetitionId = competitor.CompetitionId;
			row.ShooterId = competitor.ShooterId;
			row.WeaponId = competitor.WeaponId;
			row.ShooterClass = (int)competitor.ShooterClass;

			// Patrol
			if (competitor.PatrolId < 1)
				row.SetPatrolIdNull();
			else
				row.PatrolId = competitor.PatrolId;

			// Lane
			if (competitor.Lane < 1)
				row.SetLaneNull();
			else
				row.Lane = competitor.Lane;
			row.FinalShootingPlace = competitor.FinalShootingPlace;

			Trace.WriteLine("CDatabase: newCompetitor() " + 
				" locking \"DatabaseLocker\" on thread \"" +
				Thread.CurrentThread.Name + "\" ( " +
				System.Threading.Thread.CurrentThread.ManagedThreadId.ToString() + " )");

			lock(_databaseLocker)
			{
				Trace.WriteLine("CDatabase: newCompetitor() " + 
					" locked \"DatabaseLocker\" on thread \"" +
					Thread.CurrentThread.Name + "\" ( " +
					System.Threading.Thread.CurrentThread.ManagedThreadId.ToString() + " )");

				if (!row.IsPatrolIdNull())
				{
					if (Database.Competitors.Select("PatrolId=" + row.PatrolId.ToString() +
						" and Lane=" + row.Lane.ToString()).Length>0)
					{
						throw new ApplicationException(
							"There already exist a competitor with this patrol and lane");
					}
				}

				Database.Competitors.AddCompetitorsRow(row);

				Trace.WriteLine("CDatabase: newCompetitor() " + 
					" unlocking \"DatabaseLocker\" on thread \"" +
					Thread.CurrentThread.Name + "\" ( " +
					System.Threading.Thread.CurrentThread.ManagedThreadId.ToString() + " )");
			}
			if (!row.IsPatrolIdNull())
				checkForPatrolClassUpdate(row.PatrolId, updateGui);
			if (updateGui)
				MyInterface.updatedCompetitor(competitor);
		}
Example #25
0
		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;
		}
Example #26
0
		internal void newWeapon(Structs.Weapon weapon)
		{
			Trace.WriteLine("CDatabase: Entering newWeapon(" + 
				weapon.ToString() + ")");

			DatabaseDataset.WeaponsRow row =
				Database.Weapons.NewWeaponsRow();

			row.Class = (int)weapon.WClass;
			row.Manufacturer = weapon.Manufacturer;
			row.Model = weapon.Model;
			row.Caliber = weapon.Caliber;
			row.WeaponId = weapon.WeaponId;
			row.Automatic = weapon.Automatic;
			row.ToAutomatic = weapon.ToAutomatic;
			row.LastUpdate = DateTime.Now;

			Trace.WriteLine("CDatabase: newWeapon() " + 
				" locking \"DatabaseLocker\" on thread \"" +
				Thread.CurrentThread.Name + "\" ( " +
				System.Threading.Thread.CurrentThread.ManagedThreadId.ToString() + " )");

			lock(_databaseLocker)
			{
				Trace.WriteLine("CDatabase: newWeapon() " + 
					" locked \"DatabaseLocker\" on thread \"" +
					Thread.CurrentThread.Name + "\" ( " +
					System.Threading.Thread.CurrentThread.ManagedThreadId.ToString() + " )");

				Database.Weapons.AddWeaponsRow(row);

				Trace.WriteLine("CDatabase: newWeapon() " + 
					" unlocking \"DatabaseLocker\" on thread \"" +
					Thread.CurrentThread.Name + "\" ( " +
					System.Threading.Thread.CurrentThread.ManagedThreadId.ToString() + " )");
			}
			MyInterface.updatedWeapon();
		}
		private string createCompetitorResults(Structs.ResultWeaponsClass wclass, 
			Structs.ShootersClass uclass, bool finalResults)
		{
			StringBuilder html = new StringBuilder();

			html.Append("<p><table>");
			html.Append("<tr>");
			html.Append("<td width=" + internalTableWidthcol1.ToString() + 
				"><b>Vapenklass:</b></td>");
			html.Append("<td>" + wclass.ToString() + "</td>");
			html.Append("</tr>");
			html.Append("<tr>");
			html.Append("<td width=" + internalTableWidthcol1.ToString() + 
				"><b>Klass:</b></td>");
			html.Append("<td>" + uclass.ToString() + "</td>");
			html.Append("</tr>");

			html.Append("</table>");
			if (this.useWidth)
				html.Append("<table width=100% border=0 cellspacing=5 cellpadding=0>");
			else
				html.Append("<table border=0 cellspacing=0>");
			foreach(string columnName in this.colOrder)
			{
				html.Append("<th");
				if (useWidth)
					html.Append(" width=");
				switch (columnName)
				{
					case "Place":
						if (useWidth)
							html.Append(this.colPlaceWidth.ToString() + "%");
						html.Append(" align=center>Pl");
						break;
					case "Name":
						if (useWidth)
							html.Append(this.colNameWidth.ToString() + "%");
						html.Append(" align=left>Namn");
						break;
					case "Club":
						if (useWidth)
							html.Append(this.colClubWidth.ToString() + "%");
						html.Append(" align=left>Klubb");
						break;
					case "Result":
						if (useWidth)
							html.Append(this.colResultWidth.ToString() + "%");
						html.Append(" align=left colSpan=" + 
							(3 + myInterface.GetStationsCount()).ToString() +
							">Result");
						break;
					case "ResultTot":
						if (useWidth)
							html.Append(this.colResultTotWidth.ToString() + "%");
						html.Append(" align=center>Tot");
						break;
					case "Points":
						if (useWidth)
							html.Append(this.colPointsWidth.ToString() + "%");
						html.Append(" align=center>" + HttpUtility.HtmlEncode("Poäng"));
						break;
					case "StdMed":
						if (useWidth)
							html.Append(this.colStdMedWidth.ToString() + "%");
						html.Append(" align=center>Stm");
						break;
					case "PriceMoney":
						if (finalResults)
						{
							html.Append(" align=center>Pris");
						}
						else
						{
							html.Append(">");
						}
						break;

				}
				html.Append("</th>");
			}

			Structs.ResultsReturn[] results =
				myInterface.resultClass.GetResults(
					wclass, 
					uclass,
					myInterface.GetCompetitions()[0].NorwegianCount, finalResults);

			int place = 0;
			foreach(Structs.ResultsReturn result in results)
			{
				place++;
				html.Append("<tr>");
				foreach(string columnName in this.colOrder)
				{
					html.Append("<td");
					if (place%2 == 0)
						html.Append(" class=\"resultevenline\" ");
					else
						html.Append(" class=\"resultoddline\" ");

					if (useWidth)
						html.Append(" width=");
					switch (columnName)
					{
						case "Place":
							if (useWidth)
								html.Append(this.colPlaceWidth.ToString() + "%");
							html.Append(" align=center>" + place.ToString());
							break;
						case "Name":
							if (useWidth)
								html.Append(this.colNameWidth.ToString() + "%");
							html.Append(" align=left>" + 
								HttpUtility.HtmlEncode(result.ShooterName));
							break;
						case "Club":
							if (useWidth)
								html.Append(this.colClubWidth.ToString() + "%");
							html.Append(" align=left>" +  
								HttpUtility.HtmlEncode(
									myInterface.GetClub(result.ClubId).Name));
							break;
						case "Result":
							if (useWidth)
								html.Append(this.colResultWidth.ToString() + "%");
							
							if (myInterface.GetCompetitions()[0].NorwegianCount)
							{
								html.Append(" align=left></td>");
								foreach(string str in result.HitsPerStn.Split(';'))
								{
									if (str.Length>0)
									{
										string[] resparts = str.Split('/');
										int temp = int.Parse(resparts[0]) +
											int.Parse(resparts[1]);
										html.Append("<td");
										if (place%2 == 0)
											html.Append(" class=\"resultevenline\"");
										else
											html.Append(" class=\"resultoddline\"");

										html.Append(" align=right>" + 
											temp.ToString() + "</td>");
									}
								}
							}
							else
							{
								html.Append(" align=left></td>");
								foreach(string str in result.HitsPerStn.Split(';'))
								{
									html.Append("<td");
									if (place%2 == 0)
										html.Append(" class=\"resultevenline\"");
									else
										html.Append(" class=\"resultoddline\"");
									html.Append(" align=right>" + str + "</td>");
								}

							}
							html.Append("<td");
							if (place%2 == 0)
								html.Append(" class=\"resultevenline\"");
							else
								html.Append(" class=\"resultoddline\"");

							html.Append(" align=right>");
							if (result.FinalShootingPlace < 100 &
								result.FinalShootingPlace > 0)
							{
								html.Append("( " + result.FinalShootingPlace.ToString() +
									" )");
							}
							html.Append("</td>");

							break;
						case "Points":
							if (useWidth)
								html.Append(this.colPointsWidth.ToString() + "%");
							html.Append(" align=center>" + result.Points);
							break;
						case "ResultTot":
							if (useWidth)
								html.Append(this.colResultTotWidth.ToString() + "%");
							if (myInterface.GetCompetitions()[0].NorwegianCount)
							{
								html.Append(" align=center>" + 
									(result.Hits + result.FigureHits).ToString());
							}
							else
							{
								html.Append(" align=center>" + 
									result.Hits.ToString() + "/" + 
									result.FigureHits.ToString());
							}
							break;
						case "StdMed":
							if (useWidth)
								html.Append(this.colStdMedWidth.ToString() + "%");
							html.Append(" align=center>");
							switch(result.Medal)
							{
								case (int)Structs.Medal.StandardSilver:
									html.Append("S");
									break;
								case (int)Structs.Medal.StardardBrons:
									html.Append("B");
									break;
							}
							break;
						case "PriceMoney":
							if (finalResults)
							{
								html.Append(" align=right>");
								if (result.PriceMoney > 0)
									html.Append(result.PriceMoney.ToString() + ":-");
							}
							else
							{
								html.Append(">");
							}
							break;
					}
					if (columnName != "Result")
						html.Append("</td>");
				}
				html.Append("</tr>");
			}
			html.Append("</table></p>");
			return html.ToString();
		}
Example #28
0
		internal void newCompetition(Structs.Competition comp)
		{
			Trace.WriteLine("CDatabase: Entering newCompetition(" + 
				comp.ToString() + ")");

			DatabaseDataset.CompetitionRow row =
				Database.Competition.NewCompetitionRow();

			row.CompetitionId = -1; // Will be automaticly set when updating database file
			row.Name = comp.Name;
			row.NorwegianCount = comp.NorwegianCount;
			row.PatrolSize = comp.PatrolSize;
			row.PatrolTime = comp.PatrolTime;
			row.PatrolTimeBetween = comp.PatrolTimeBetween;
			row.PatrolTimeRest = comp.PatrolTimeRest;
			row.StartDate = comp.StartTime.Date;
			row.StartTime = (int)comp.StartTime.TimeOfDay.TotalMinutes;
			row.DoFinalShooting = comp.DoFinalShooting;
			row.FirstPrice = comp.FirstPrice;
			row.PriceMoneyPercentToReturn = comp.PriceMoneyPercentToReturn;
			row.ShooterFee1 = comp.ShooterFee1;
			row.ShooterFee2 = comp.ShooterFee2;
			row.ShooterFee3 = comp.ShooterFee3;
			row.ShooterFee4 = comp.ShooterFee4;
			row.UsePriceMoney = comp.UsePriceMoney;
			row.PriceMoneyShooterPercent = comp.PriceMoneyShooterPercent;
			row.Type = (int)comp.Type;
			row.Championship = (int)comp.Championship;
			row.PatrolConnectionType = (int)comp.PatrolConnectionType;
			row.OneClass = comp.OneClass;

			Trace.WriteLine("CDatabase: newCompetition() " + 
				" locking \"DatabaseLocker\" on thread \"" +
				Thread.CurrentThread.Name + "\" ( " +
				System.Threading.Thread.CurrentThread.ManagedThreadId.ToString() + " )");

			lock(_databaseLocker)
			{
				Trace.WriteLine("CDatabase: newCompetition() " + 
					" locked \"DatabaseLocker\" on thread \"" +
					Thread.CurrentThread.Name + "\" ( " +
					System.Threading.Thread.CurrentThread.ManagedThreadId.ToString() + " )");

				Database.Competition.AddCompetitionRow(row);

				Trace.WriteLine("CDatabase: newCompetition() " + 
					" unlocking \"DatabaseLocker\" on thread \"" +
					Thread.CurrentThread.Name + "\" ( " +
					System.Threading.Thread.CurrentThread.ManagedThreadId.ToString() + " )");
			}
			MyInterface.updatedCompetition();
		}
Example #29
0
		internal int newPatrol(Structs.Patrol patrol, bool NotifyGui)
		{
			Trace.WriteLine("CDatabase: Entering newPatrol(" + 
				patrol.ToString() + ", " + NotifyGui.ToString() + ")");
			Trace.WriteLine("CDatabase newPatrol: StartDateTime = " +
				patrol.StartDateTime.ToString());

			DateTime compStart = getCompetitions()[0].StartTime;
			DatabaseDataset.PatrolsRow row =
				Database.Patrols.NewPatrolsRow();

			Trace.WriteLine("CDatabase: newPatrol() " + 
				" locking \"DatabaseLocker\" on thread \"" +
				Thread.CurrentThread.Name + "\" ( " +
				System.Threading.Thread.CurrentThread.ManagedThreadId.ToString() + " )");

			lock(_databaseLocker)
			{
				Trace.WriteLine("CDatabase: newPatrol() " + 
					" locked \"DatabaseLocker\" on thread \"" +
					Thread.CurrentThread.Name + "\" ( " +
					System.Threading.Thread.CurrentThread.ManagedThreadId.ToString() + " )");

				row.PatrolId = getHighestPatrolId() + 1;
				row.CompetitionId = patrol.CompetitionId;
				row.StartDateTime = (int)(patrol.StartDateTime-compStart).TotalMinutes;
				row.PClass = (int)patrol.PClass;
				row.Automatic = patrol.LockedForAutomatic;
				if (patrol.StartDateTimeDisplay == new DateTime(1,1,1,0,0,0,0))
					row.StartDateTimeDisplay = (int)(patrol.StartDateTimeDisplay-compStart).TotalMinutes;
				else
					row.StartDateTimeDisplay = row.StartDateTime;

				Database.Patrols.AddPatrolsRow(row);

				Trace.WriteLine("CDatabase: newPatrol() " + 
					" unlocking \"DatabaseLocker\" on thread \"" +
					Thread.CurrentThread.Name + "\" ( " +
					System.Threading.Thread.CurrentThread.ManagedThreadId.ToString() + " )");
			}
			if (NotifyGui)
				MyInterface.updatedPatrol();
			return row.PatrolId;
		}
Example #30
0
		internal Structs.Competitor[] GetCompetitors(Structs.Club ClubToFetch, 
			Structs.ResultWeaponsClass wclass, string sorting)
		{
			Trace.WriteLine("CDatabase: Entering getCompetitors(" + 
				ClubToFetch.ToString() + ", " + wclass + ")");

			Structs.CompetitionTypeEnum compType = getCompetitions()[0].Type;

			ArrayList competitors = new ArrayList();
			Structs.Competitor competitor = new Structs.Competitor();

			foreach(DatabaseDataset.ShootersRow shooter in 
				Database.Shooters.Select("ClubId='" + ClubToFetch.ClubId + "'", sorting))
			{
				DatabaseDataset.CompetitorsRow[] compRows = shooter.GetCompetitorsRows();
				foreach(DatabaseDataset.CompetitorsRow compRow in compRows)
				{
					Structs.Weapon weapon = 
						MyInterface.GetWeapon(compRow.WeaponId);

					if (CConvert.ConvertWeaponsClassToResultClass(weapon.WClass, compType) == wclass)
					{
						Structs.Competitor comp = MyInterface.GetCompetitor(compRow.CompetitorId);
						competitors.Add(comp);
					}
				}
			}
			return (Structs.Competitor[])competitors.ToArray(competitor.GetType());
		}