Пример #1
0
		private void btnSave_Click(object sender, System.EventArgs e)
		{
			if (this.txtWeaponId.Text.Length == 0 |
				this.txtManufacturer.Text.Length == 0 |
				this.txtModel.Text.Length == 0)
			{
				MessageBox.Show("Du måste skriva något i vapnets tillverkare, modell och id");
				return;
			}
			if ((string)this.ddWeapons.SelectedValue == NewWeaponValue)
			{
				// New weapon

				Structs.Weapon weapon = new Structs.Weapon();
				weapon.WeaponId = this.txtWeaponId.Text;
				weapon.Manufacturer = this.txtManufacturer.Text;
				weapon.Model = this.txtModel.Text;
				weapon.Caliber = this.txtCaliber.Text;
				weapon.WClass = (Structs.WeaponClass)
					Convert.ToInt32(
					(string)this.ddClass.SelectedValue);
				weapon.Automatic = false;
				weapon.ToAutomatic = false;
				if (CommonCode.EnableInternetConnections)
				{
					DialogResult res =
						MessageBox.Show("Vill du lägga till vapnet \"" +
						this.txtManufacturer.Text + ", " + 
						this.txtModel.Text + 
						"\" till Internet-databasen?",
						"Internet-databasen", 
						MessageBoxButtons.YesNo, 
						MessageBoxIcon.Question);
					if (DialogResult.Yes == res)
						weapon.ToAutomatic = true;
				}

				CommonCode.NewWeapon(weapon);
			}
			else
			{
				Structs.Weapon updatedWeapon = CommonCode.GetWeapon((string)this.ddWeapons.SelectedValue);

				updatedWeapon.WClass = (Structs.WeaponClass)
					Convert.ToInt32(
					(string)this.ddClass.SelectedValue);
				updatedWeapon.Manufacturer = this.txtManufacturer.Text;
				updatedWeapon.Model = this.txtModel.Text;
				updatedWeapon.Caliber = this.txtCaliber.Text;
				updatedWeapon.Automatic = this.chkInternet.Checked;
				updatedWeapon.ToAutomatic = false;
				if (CommonCode.EnableInternetConnections)
				{
					string text = "Vill du ändra vapnet \"" +
						this.txtManufacturer.Text + "," +
						this.txtModel.Text + 
						"\" i Internet-databasen?";
					if (this.chkInternet.Checked == false)
						text = "Vill du lägga till vapnet \"" +
							this.txtManufacturer.Text + "," +
							this.txtModel.Text + "\" i Internet-databasen?";
					DialogResult res = MessageBox.Show(text,
						"Internet-databasen",
						MessageBoxButtons.YesNo, 
						MessageBoxIcon.Question);
					if (DialogResult.Yes == res)
						updatedWeapon.ToAutomatic = true;
				}
				CommonCode.UpdateWeapon(updatedWeapon);
			}

			restoreWindow();
		}
Пример #2
0
		internal Structs.Weapon[] getWeapons(string sorting)
		{
			Trace.WriteLine("CDatabase: Entering getWeapons()");

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

			ArrayList weapons = new ArrayList();
			Structs.Weapon weapon = new Structs.Weapon();

			foreach(DatabaseDataset.WeaponsRow row in Database.Weapons.Select("", sorting))
			{
				weapon = new Structs.Weapon();
				weapon.Manufacturer = row.Manufacturer;
				weapon.Model = row.Model;
				weapon.Caliber = row.Caliber;
				weapon.WClass = (Structs.WeaponClass)row.Class;
				weapon.WeaponId = row.WeaponId;
				weapon.Automatic = row.Automatic;
				weapon.ToAutomatic = row.ToAutomatic;

				if (comptype != Structs.CompetitionTypeEnum.MagnumField)
					weapons.Add(weapon);
				else
				{
					if (weapon.WClass.ToString().IndexOf("M") > -1 &
						weapon.WClass.ToString().Length > 1)
						weapons.Add(weapon);
				}
			}
			return (Structs.Weapon[])weapons.ToArray(weapon.GetType());
		}
Пример #3
0
		internal Structs.Weapon getWeapon(string weaponId)
		{
			Trace.WriteLine("CDatabase: Entering getWeapon(" + 
				weaponId + ") on thread \"" +
				System.Threading.Thread.CurrentThread.Name + "\" ( " +
				System.Threading.Thread.CurrentThread.ManagedThreadId.ToString() + " )");
			DateTime start = DateTime.Now;

			Structs.Weapon weapon = new Structs.Weapon();

			foreach(DatabaseDataset.WeaponsRow row in Database.Weapons.Select("WeaponId='" + weaponId + "'"))
			{
				if (row.WeaponId.ToUpper() == weaponId.ToUpper())
				{
					weapon.Manufacturer = row.Manufacturer;
					weapon.Model = row.Model;
					weapon.Caliber = row.Caliber;
					weapon.WClass = (Structs.WeaponClass)row.Class;
					weapon.WeaponId = row.WeaponId;
					weapon.Automatic = row.Automatic;
					weapon.ToAutomatic = row.ToAutomatic;

					Trace.WriteLine("CDatabase: Ending getWeapon() after " +
						(DateTime.Now-start).TotalMilliseconds.ToString() +
						" ms.");
					return weapon;
				}
			}
			throw new CannotFindIdException("Could not find WeapondId " + weaponId.ToString());
		}
Пример #4
0
		private void checkToEnableShooterClassX(SafeComboBox ddShooterClassX,
			DataTable shooterClassTableX,
			SafeComboBox ddWeaponX)
		{
			Trace.WriteLine("FCompetitors: checkToEnableShooterClassX() " +
				"started on thread \"" +
				Thread.CurrentThread.Name + 
				"\" ( " +
				Thread.CurrentThread.ManagedThreadId.ToString() + 
				" )");

			if (ddShooterClass.SelectedValue == null)
				return; // ops

			Structs.ShootersClass currentClass = 
				(Structs.ShootersClass)int.Parse((string)ddShooterClass.SelectedValue);
			
			string currentClassString = currentClass.ToString().Replace("Klass", "Klass ");
			object currentValue = null;
			try
			{
				currentValue = ddShooterClassX.SelectedValue;
			}
			catch(Exception)
			{
			}
			ddShooterClassX.SelectedIndex = -1;
			shooterClassTableX.Clear();

			Structs.Weapon weapon = new Structs.Weapon(); // This is just a fake to get throw
			if (ddWeaponX.SelectedValue == null)
			{
				if (ddWeaponX.Items.Count > 0)
				{
					ddWeaponX.SelectedIndex = 0;
					return; // This automaticly calls this procedure again
				}
			}
			else
			{
				weapon = CommonCode.GetWeapon((string)ddWeaponX.SelectedValue);
			}

			if (weapon.WClass == Structs.WeaponClass.C)
			{
				DataRow newRow1Default = shooterClassTableX.NewRow();
				newRow1Default["Id"] = 0;
				newRow1Default["Name"] = currentClassString;
				shooterClassTableX.Rows.Add(newRow1Default);

				DataRow newRow1Dam = shooterClassTableX.NewRow();
				newRow1Dam["Id"] = 1;
				newRow1Dam["Name"] = "Dam";
				shooterClassTableX.Rows.Add(newRow1Dam);

				DataRow newRow1Junior = shooterClassTableX.NewRow();
				newRow1Junior["Id"] = 2;
				newRow1Junior["Name"] = "Junior";
				shooterClassTableX.Rows.Add(newRow1Junior);

				DataRow newRow1VY = shooterClassTableX.NewRow();
				newRow1VY["Id"] = 3;
				newRow1VY["Name"] = "VY";
				shooterClassTableX.Rows.Add(newRow1VY);

				DataRow newRow1VA = shooterClassTableX.NewRow();
				newRow1VA["Id"] = 4;
				newRow1VA["Name"] = "VÄ";
				shooterClassTableX.Rows.Add(newRow1VA);

				DataRow newRow1ÖP = shooterClassTableX.NewRow();
				newRow1ÖP["Id"] = 5;
				newRow1ÖP["Name"] = "ÖP";
				shooterClassTableX.Rows.Add(newRow1ÖP);
			}
			else
			{
				DataRow newRow1Default = shooterClassTableX.NewRow();
				newRow1Default["Id"] = 0;
				newRow1Default["Name"] = currentClassString;
				shooterClassTableX.Rows.Add(newRow1Default);

				DataRow newRow1ÖP = shooterClassTableX.NewRow();
				newRow1ÖP["Id"] = 5;
				newRow1ÖP["Name"] = "ÖP";
				shooterClassTableX.Rows.Add(newRow1ÖP);
			}
			
			try
			{
				if (currentValue != null)
					ddShooterClassX.SelectedValue = currentValue;
				else
					ddShooterClassX.SelectedIndex = 0;
			}
			catch(Exception)
			{
				ddShooterClassX.SelectedIndex = 0;
			}
			
			Trace.WriteLine("FCompetitors: checkToEnableShooterClassX() ended.");
		}