コード例 #1
0
        //============================================================================*
        // PopulateFirearmCombo()
        //============================================================================*

        private void PopulateFirearmCombo()
        {
            FirearmCombo.Items.Clear();

            FirearmCombo.Items.Add("No Specific Firearm");

            if (m_Target.BatchID == 0)
            {
                cFirearm SelectFirearm = null;

                foreach (cFirearm Firearm in m_DataFiles.FirearmList)
                {
                    if (Firearm.HasCaliber(m_Target.Caliber))
                    {
                        FirearmCombo.Items.Add(Firearm);

                        if (m_Target.Firearm != null && Firearm.CompareTo(m_Target.Firearm) == 0)
                        {
                            SelectFirearm = Firearm;
                        }
                    }
                }

                if (SelectFirearm != null)
                {
                    FirearmCombo.SelectedItem = SelectFirearm;
                }
            }
            else
            {
                if (m_Target.Firearm != null)
                {
                    FirearmCombo.Items.Clear();

                    FirearmCombo.Items.Add(m_Target.Firearm);

                    FirearmCombo.SelectedItem = m_Target.Firearm;
                }
            }

            if (FirearmCombo.SelectedIndex < 0 && FirearmCombo.Items.Count > 0)
            {
                FirearmCombo.SelectedIndex = 0;
            }
        }
コード例 #2
0
        //============================================================================*
        // 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();
        }