//============================================================================* // Copy() //============================================================================* public void Copy(cAmmoTest AmmoTest) { m_Ammo = AmmoTest.m_Ammo; m_Firearm = AmmoTest.m_Firearm; m_TestDate = AmmoTest.m_TestDate; m_dBarrelLength = AmmoTest.m_dBarrelLength; m_dTwist = AmmoTest.m_dTwist; m_nNumRounds = AmmoTest.m_nNumRounds; m_nMuzzleVelocity = AmmoTest.m_nMuzzleVelocity; m_dBestGroup = AmmoTest.m_dBestGroup; m_dBestGroupRange = AmmoTest.m_dBestGroupRange; m_strNotes = AmmoTest.m_strNotes; m_TestShotList = new cTestShotList(AmmoTest.TestShotList); }
//============================================================================* // UpdateAmmoTest() //============================================================================* public void UpdateAmmoTest(cAmmoTest AmmoTest, bool fSelect = false) { foreach (ListViewItem Item in Items) { if ((Item.Tag as cAmmoTest).Equals(AmmoTest)) { SetAmmoTestData(Item, AmmoTest); Item.Selected = fSelect; if (SelectedItems.Count > 0) { SelectedItems[0].EnsureVisible(); } return; } } AddAmmoTest(AmmoTest, fSelect); }
//============================================================================* // SetAmmoTestData() //============================================================================* public void SetAmmoTestData(ListViewItem Item, cAmmoTest AmmoTest) { Item.SubItems.Clear(); Item.Text = AmmoTest.TestDate.ToShortDateString(); Item.Tag = AmmoTest; Item.SubItems.Add(AmmoTest.Firearm != null ? AmmoTest.Firearm.ToString() : "Factory"); Item.SubItems.Add(String.Format("{0:G0}", cDataFiles.StandardToMetric(AmmoTest.MuzzleVelocity, cDataFiles.eDataType.Velocity))); Item.SubItems.Add(String.Format(m_strGroupFormat, cDataFiles.StandardToMetric(AmmoTest.BestGroup, cDataFiles.eDataType.GroupSize))); double dBestGroup = AmmoTest.BestGroup; double dBestGroupRange = AmmoTest.BestGroupRange; double dMOA = (dBestGroup != 0.0 && dBestGroupRange != 0.0) ? dBestGroup / ((dBestGroupRange / 100.0) * 1.047) : 0.0; Item.SubItems.Add(String.Format("{0:F3}", dMOA)); Item.SubItems.Add(String.Format("{0:N0}", cDataFiles.StandardToMetric(AmmoTest.BestGroupRange, cDataFiles.eDataType.Range))); }
//============================================================================* // AddAmmoTest() //============================================================================* public ListViewItem AddAmmoTest(cAmmoTest AmmoTest, bool fSelect = false) { //----------------------------------------------------------------------------* // Verify that the test shoudl be added //----------------------------------------------------------------------------* if (!VerifyAmmoTest(AmmoTest)) { return(null); } //----------------------------------------------------------------------------* // Create the new Item //----------------------------------------------------------------------------* ListViewItem Item = new ListViewItem(); SetAmmoTestData(Item, AmmoTest); base.AddItem(Item, fSelect); return(Item); }
//============================================================================* // Comparer() //============================================================================* public static int Comparer(cAmmoTest AmmoTest1, cAmmoTest AmmoTest2) { if (AmmoTest1 == null) { if (AmmoTest2 != null) { return(-1); } else { return(0); } } else { if (AmmoTest2 == null) { return(1); } } return(AmmoTest1.CompareTo(AmmoTest2)); }
//============================================================================* // cAmmoTestForm() - Constructor //============================================================================* public cAmmoTestForm(cAmmo Ammo, cAmmoTest AmmoTest, cDataFiles DataFiles, bool fViewOnly = false) { InitializeComponent(); m_DataFiles = DataFiles; m_fViewOnly = fViewOnly; string strTitle = ""; if (AmmoTest == null) { m_AmmoTest = new cAmmoTest(); m_AmmoTest.Ammo = Ammo; m_AmmoTest.TestDate = DateTime.Today; if (Ammo.TestList.Count == 0) { m_AmmoTest.Firearm = null; } else { foreach (cFirearm Firearm in m_DataFiles.FirearmList) { if (Firearm.HasCaliber(Ammo.Caliber)) { m_AmmoTest.Firearm = Firearm; break; } } } strTitle = "Add"; OKButton.Text = "Add"; } else { m_AmmoTest = new cAmmoTest(AmmoTest); if (m_AmmoTest.Ammo == null) { m_AmmoTest.Ammo = Ammo; } if (Ammo != null && Ammo.TestList.Count == 0) { m_AmmoTest.Firearm = null; } if (!m_fViewOnly) { strTitle = "Edit"; OKButton.Text = "Update"; } else { AmmoTestCancelButton.Text = "Close"; OKButton.Visible = false; int nButtonX = (this.Size.Width / 2) - (AmmoTestCancelButton.Width / 2); AmmoTestCancelButton.Location = new Point(nButtonX, AmmoTestCancelButton.Location.Y); strTitle = "View"; } } SetClientSizeCore(AmmoDataGroupBox.Location.X + AmmoDataGroupBox.Width + 10, AmmoTestCancelButton.Location.Y + AmmoTestCancelButton.Height + 20); //----------------------------------------------------------------------------* // Dialog Title //----------------------------------------------------------------------------* strTitle += " Ammo Test"; Text = strTitle; //----------------------------------------------------------------------------* // Event Handlers //----------------------------------------------------------------------------* if (!m_fViewOnly) { TestDatePicker.TextChanged += OnDateChanged; BarrelLengthTextBox.TextChanged += OnTextChanged; TwistTextBox.TextChanged += OnTextChanged; NumShotsTextBox.TextChanged += OnTextChanged; MuzzleVelocityTextBox.TextChanged += OnTextChanged; BestGroupTextBox.TextChanged += OnTextChanged; BestGroupRangeTextBox.TextChanged += OnTextChanged; NumShotsTextBox.TextChanged += OnNumShotsTextChanged; OKButton.Click += OnOKClicked; } else { NumShotsTextBox.ReadOnly = true; BestGroupTextBox.ReadOnly = true; BestGroupRangeTextBox.ReadOnly = true; NotesTextBox.ReadOnly = true; } EditShotsButton.Click += OnEditShotsClicked; //----------------------------------------------------------------------------* // Populate Ammo Data //----------------------------------------------------------------------------* SetStaticToolTips(); SetInputParameters(); ManufacturerLabel.Text = m_AmmoTest.Ammo.Manufacturer.ToString(); CaliberLabel.Text = m_AmmoTest.Ammo.Caliber.ToString(); PartNumberLabel.Text = m_AmmoTest.Ammo.PartNumber; TypeLabel.Text = m_AmmoTest.Ammo.Type; BulletWeightLabel.Text = String.Format("{0:G0} {1}", cDataFiles.StandardToMetric(m_AmmoTest.Ammo.BulletWeight, cDataFiles.eDataType.BulletWeight), cDataFiles.MetricString(cDataFiles.eDataType.BulletWeight)); BulletDiameterLabel.Text = String.Format("{0:F3} {1}", cDataFiles.StandardToMetric(m_AmmoTest.Ammo.BulletDiameter, cDataFiles.eDataType.Dimension), cDataFiles.MetricString(cDataFiles.eDataType.Dimension)); BallisticCoefficientLabel.Text = String.Format("{0:F3}", m_AmmoTest.Ammo.BallisticCoefficient); switch (m_AmmoTest.Ammo.FirearmType) { case cFirearm.eFireArmType.Handgun: FirearmTypeLabel.Text = "Handgun"; break; case cFirearm.eFireArmType.Rifle: FirearmTypeLabel.Text = "Rifle"; break; case cFirearm.eFireArmType.Shotgun: FirearmTypeLabel.Text = "Shotgun"; break; } //----------------------------------------------------------------------------* // Populate Firearm Combo //----------------------------------------------------------------------------* if (!m_AmmoTest.Ammo.Reload && (m_AmmoTest.Firearm == null || m_AmmoTest.Ammo.TestList.Count == 0)) { FirearmCombo.Items.Add("Factory"); FirearmCombo.SelectedIndex = 0; FirearmCombo.Enabled = false; } else { foreach (cFirearm Firearm in m_DataFiles.FirearmList) { if (Firearm.FirearmType == m_AmmoTest.Ammo.FirearmType && Firearm.HasCaliber(m_AmmoTest.Ammo.Caliber)) { FirearmCombo.Items.Add(Firearm); } } FirearmCombo.SelectedItem = m_AmmoTest.Firearm; if (FirearmCombo.SelectedIndex < 0 && FirearmCombo.Items.Count > 0) { FirearmCombo.SelectedIndex = 0; } if (FirearmCombo.SelectedIndex >= 0) { m_AmmoTest.Firearm = (cFirearm)FirearmCombo.SelectedItem; } else { m_AmmoTest.Firearm = null; } } //----------------------------------------------------------------------------* // Populate Test Data //----------------------------------------------------------------------------* TestDatePicker.Value = m_AmmoTest.TestDate; if (m_AmmoTest.Firearm != null) { BarrelLengthTextBox.Value = cDataFiles.StandardToMetric(m_AmmoTest.Firearm.BarrelLength, cDataFiles.eDataType.Firearm); TwistTextBox.Value = cDataFiles.StandardToMetric(m_AmmoTest.Firearm.Twist, cDataFiles.eDataType.Firearm); BarrelLengthTextBox.Enabled = false; TwistTextBox.Enabled = false; } else { BarrelLengthTextBox.Value = cDataFiles.StandardToMetric(m_AmmoTest.BarrelLength, cDataFiles.eDataType.Firearm); TwistTextBox.Value = cDataFiles.StandardToMetric(m_AmmoTest.Twist, cDataFiles.eDataType.Firearm); BarrelLengthTextBox.Enabled = true; TwistTextBox.Enabled = true; } PopulateShotList(); NumShotsTextBox.Value = m_AmmoTest.NumRounds; BestGroupTextBox.Value = cDataFiles.StandardToMetric(m_AmmoTest.BestGroup, cDataFiles.eDataType.GroupSize); BestGroupRangeTextBox.Value = (int)cDataFiles.StandardToMetric(m_AmmoTest.BestGroupRange, cDataFiles.eDataType.Range); MuzzleVelocityTextBox.Value = (int)cDataFiles.StandardToMetric(m_AmmoTest.MuzzleVelocity, cDataFiles.eDataType.Velocity); if (m_AmmoTest.Firearm == null) { NumShotsTextBox.Enabled = false; BestGroupTextBox.Enabled = false; BestGroupRangeTextBox.Enabled = false; MuzzleVelocityTextBox.Enabled = true; } else { MuzzleVelocityTextBox.Enabled = true; NumShotsTextBox.Enabled = true; BestGroupTextBox.Enabled = true; BestGroupRangeTextBox.Enabled = true; MuzzleVelocityTextBox.Enabled = true; } NotesTextBox.Text = m_AmmoTest.Notes; PopulateShotList(); m_fInitialized = true; UpdateButtons(); }
//============================================================================* // VerifyAmmoTest() //============================================================================* public bool VerifyAmmoTest(cAmmoTest AmmoTest) { // All tests are verified return(true); }
//============================================================================* // Append() //============================================================================* public int Append(cAmmoTest AmmoTest, bool fCountOnly = false) { int nUpdateCount = 0; if (m_dBarrelLength == 0.0 && AmmoTest.m_dBarrelLength != 0.0) { if (!fCountOnly) { m_dBarrelLength = AmmoTest.m_dBarrelLength; } nUpdateCount++; } if (m_dTwist == 0.0 && AmmoTest.m_dTwist != 0.0) { if (!fCountOnly) { m_dTwist = AmmoTest.m_dTwist; } nUpdateCount++; } if (m_nNumRounds == 0 && AmmoTest.m_nNumRounds != 0) { if (!fCountOnly) { m_nNumRounds = AmmoTest.m_nNumRounds; } nUpdateCount++; } if (m_nMuzzleVelocity == 0 && AmmoTest.m_nMuzzleVelocity != 0) { if (!fCountOnly) { m_nMuzzleVelocity = AmmoTest.m_nMuzzleVelocity; } nUpdateCount++; } if (m_dBestGroup == 0.0 && AmmoTest.m_dBestGroup != 0.0) { if (!fCountOnly) { m_dBestGroup = AmmoTest.m_dBestGroup; } nUpdateCount++; } if (m_dBestGroupRange == 0.0 && AmmoTest.m_dBestGroupRange != 0.0) { if (!fCountOnly) { m_dBestGroupRange = AmmoTest.m_dBestGroupRange; } nUpdateCount++; } if (String.IsNullOrEmpty(m_strNotes) && !String.IsNullOrEmpty(AmmoTest.m_strNotes)) { if (!fCountOnly) { m_strNotes = AmmoTest.m_strNotes; } nUpdateCount++; } return(nUpdateCount); }
//============================================================================* // cAmmoTest() - Copy Constructor //============================================================================* public cAmmoTest(cAmmoTest AmmoTest) { Copy(AmmoTest); }
//============================================================================* // CompareTo() //============================================================================* public int CompareTo(cAmmoTest AmmoTest) { if (AmmoTest == null) { return(1); } //----------------------------------------------------------------------------* // Date //----------------------------------------------------------------------------* int rc = m_TestDate.CompareTo(AmmoTest.m_TestDate); //----------------------------------------------------------------------------* // Firearm //----------------------------------------------------------------------------* if (rc == 0) { if (m_Firearm == null) { if (AmmoTest.m_Firearm != null) { rc = -1; } else { rc = 0; } } else { if (AmmoTest.m_Firearm == null) { rc = 1; } else { rc = m_Firearm.CompareTo(AmmoTest.m_Firearm); } } //----------------------------------------------------------------------------* // NumRounds //----------------------------------------------------------------------------* if (rc == 0) { rc = m_nNumRounds.CompareTo(AmmoTest.m_nNumRounds); //----------------------------------------------------------------------------* // Detail Data //----------------------------------------------------------------------------* if (rc == 0) { rc = m_nMuzzleVelocity.CompareTo(AmmoTest.m_nMuzzleVelocity); if (rc == 0) { rc = m_dBarrelLength.CompareTo(AmmoTest.m_dBarrelLength); if (rc == 0) { rc = m_dTwist.CompareTo(AmmoTest.m_dTwist); if (rc == 0) { rc = m_dBestGroup.CompareTo(AmmoTest.m_dBestGroup); if (rc == 0) { rc = m_dBestGroupRange.CompareTo(AmmoTest.m_dBestGroupRange); if (rc == 0) { if (m_strNotes == null) { m_strNotes = ""; } rc = m_strNotes.CompareTo(AmmoTest.m_strNotes); } } } } } } } } return(rc); }