예제 #1
0
        //============================================================================*
        // SetInputParameters()
        //============================================================================*

        private void SetInputParameters()
        {
            cDataFiles.SetInputParameters(StartingWeightTextBox, cDataFiles.eDataType.PowderWeight);

            double dMinWeight = 0.0;
            double dMaxWeight = 0.0;

            if (m_Batch != null && m_Batch.Load != null)
            {
                cCharge MinCharge = m_Batch.Load.ChargeList.MinCharge;
                cCharge MaxCharge = m_Batch.Load.ChargeList.MaxCharge;

                if (MinCharge != null)
                {
                    dMinWeight = MinCharge.PowderWeight;
                }

                if (MaxCharge != null)
                {
                    dMaxWeight = MaxCharge.PowderWeight;
                }
            }

            StartingWeightTextBox.MinValue = cDataFiles.StandardToMetric(dMinWeight, cDataFiles.eDataType.PowderWeight);
            StartingWeightTextBox.MaxValue = cDataFiles.StandardToMetric(dMaxWeight, cDataFiles.eDataType.PowderWeight);

            IncrementTextBox.MinValue = 0.1;

            cDataFiles.SetInputParameters(IncrementTextBox, cDataFiles.eDataType.PowderWeight);

            cDataFiles.SetMetricLabel(StartingWeightMeasurementLabel, cDataFiles.eDataType.PowderWeight);
            cDataFiles.SetMetricLabel(IncrementMeasurementLabel, cDataFiles.eDataType.PowderWeight);
        }
예제 #2
0
        //============================================================================*
        // AddCharge()
        //============================================================================*

        public ListViewItem AddCharge(cCharge Charge, bool fSelect = false)
        {
            ListViewItem Item = null;

            Item = new ListViewItem(Charge.ToString());

            SetChargeData(Item, Charge);

            try
            {
                Items.Add(Item);
            }
            catch
            {
            }

            if (Charge.Favorite)
            {
                Item.ImageIndex = 0;
            }
            else
            {
                if (Charge.Reject)
                {
                    Item.ImageIndex = 1;
                }
                else
                {
                    Item.ImageIndex = -1;
                }
            }

            return(Item);
        }
예제 #3
0
        //============================================================================*
        // Populate()
        //============================================================================*

        public void Populate(cLoad Load, cCharge SelectCharge)
        {
            Populating = true;

            //----------------------------------------------------------------------------*
            // Create the format strings
            //----------------------------------------------------------------------------*

            m_strPowderWeightFormat = m_DataFiles.Preferences.FormatString(cDataFiles.eDataType.PowderWeight);

            //----------------------------------------------------------------------------*
            // Reset the list view
            //----------------------------------------------------------------------------*

            Items.Clear();

            ListViewItem SelectItem = null;

            //----------------------------------------------------------------------------*
            // Loop through the charges
            //----------------------------------------------------------------------------*

            foreach (cCharge Charge in Load.ChargeList)
            {
                ListViewItem Item = AddCharge(Charge);

                if (Item != null && SelectCharge != null && SelectCharge.CompareTo(Charge) == 0)
                {
                    SelectItem = Item;
                }
            }

            Focus();

            //----------------------------------------------------------------------------*
            // Select a charge
            //----------------------------------------------------------------------------*

            if (SelectItem != null)
            {
                SelectItem.Selected = true;

                m_DataFiles.Preferences.LastChargeSelected = (cCharge)Items[0].Tag;

                EnsureVisible(SelectItem.Index);
            }
            else
            {
                if (Items.Count > 0)
                {
                    Items[0].Selected = true;

                    EnsureVisible(Items[0].Index);
                }
            }

            Populating = false;
        }
예제 #4
0
        //============================================================================*
        // cCharge() - Copy Constructor
        //============================================================================*

        public cCharge(cCharge Charge)
        {
            m_dPowderWeight = Charge.m_dPowderWeight;
            m_dFillRatio    = Charge.m_dFillRatio;
            m_fFavorite     = Charge.m_fFavorite;
            m_fReject       = Charge.m_fReject;

            m_TestList = new cChargeTestList(Charge.m_TestList);
        }
예제 #5
0
        //============================================================================*
        // ResolveIdentities()
        //============================================================================*

        public bool ResolveIdentities(cDataFiles Datafiles, cCharge Charge)
        {
            bool fChanged = false;

            foreach (cChargeTest ChargeTest in this)
            {
                fChanged = ChargeTest.ResolveIdentities(Datafiles) ? true : fChanged;
            }

            return(fChanged);
        }
예제 #6
0
        //============================================================================*
        // AddCharge()
        //============================================================================*

        public void AddCharge(cCharge NewCharge)
        {
            cCharge Charge = m_ChargeList.AddCharge(NewCharge);

            if (Charge.CompareTo(NewCharge) != 0)
            {
                foreach (cChargeTest ChargeTest in NewCharge.TestList)
                {
                    Charge.AddTest(ChargeTest);
                }
            }
        }
예제 #7
0
        //============================================================================*
        // SetChargeData()
        //============================================================================*

        public void SetChargeData(ListViewItem Item, cCharge Charge)
        {
            Item.SubItems.Clear();

            Item.Text = String.Format(Charge.ToString());

            Item.Tag = Charge;

            Item.SubItems.Add(Charge.TestList.Count > 0 ? String.Format("{0:G}", Charge.TestList.Count) : "-");
            Item.SubItems.Add(Charge.FillRatio != 0.0 ? String.Format("{0:F2}", Charge.FillRatio) : "-");
            Item.SubItems.Add(Charge.Favorite ? "Y" : "");
            Item.SubItems.Add(Charge.Reject ? "Y" : "");
        }
예제 #8
0
        //============================================================================*
        // CompareTo()
        //============================================================================*

        public int CompareTo(cCharge Charge)
        {
            if (Charge == null)
            {
                return(1);
            }

            //----------------------------------------------------------------------------*
            // Charge
            //----------------------------------------------------------------------------*

            int rc = m_dPowderWeight.CompareTo(Charge.m_dPowderWeight);

            //----------------------------------------------------------------------------*
            // Return results
            //----------------------------------------------------------------------------*

            return(rc);
        }
예제 #9
0
        //============================================================================*
        // Comparer()
        //============================================================================*

        public static int Comparer(cCharge Charge1, cCharge Charge2)
        {
            if (Charge1 == null)
            {
                if (Charge2 != null)
                {
                    return(-1);
                }
                else
                {
                    return(0);
                }
            }
            else
            {
                if (Charge2 == null)
                {
                    return(1);
                }
            }

            return(Charge1.CompareTo(Charge2));
        }
예제 #10
0
        //============================================================================*
        // cEvaluationItem() - Constructor
        //============================================================================*

        public cEvaluationItem(cLoad Load, cCharge Charge, cChargeTest ChargeTest)
        {
            m_Load       = Load;
            m_Charge     = Charge;
            m_ChargeTest = ChargeTest;
        }
예제 #11
0
        //============================================================================*
        // cChargeForm() - Constructor
        //============================================================================*

        public cChargeForm(cCharge Charge, cLoad Load, cDataFiles DataFiles, bool fViewOnly = false)
        {
            InitializeComponent();

            m_Load      = Load;
            m_DataFiles = DataFiles;

            m_fViewOnly   = fViewOnly;
            m_fEditCharge = !m_fViewOnly;

            //----------------------------------------------------------------------------*
            // Get starting load info
            //----------------------------------------------------------------------------*

            if (Charge == null)
            {
                Text = "Add Charge";

                ChargeOKButton.Text = "Add";

                if (m_DataFiles.Preferences.LastCharge == null)
                {
                    m_Charge = new cCharge();
                }
                else
                {
                    m_Charge = new cCharge(m_DataFiles.Preferences.LastCharge);

                    m_Charge.PowderWeight = 0.0;
                    m_Charge.Favorite     = false;
                    m_Charge.Reject       = false;
                    m_Charge.TestList.Clear();
                }

                m_fAdd        = true;
                m_fEditCharge = true;
            }
            else
            {
                m_Charge = new cCharge(Charge);

                if (!m_fViewOnly)
                {
                    Text = "Edit Charge";

                    ChargeOKButton.Text = "Update";
                }
                else
                {
                    Text = "View Charge";

                    ChargeOKButton.Visible = false;

                    int nButtonX = (this.Size.Width / 2) - (ChargeCancelButton.Width / 2);

                    ChargeCancelButton.Location = new Point(nButtonX, ChargeCancelButton.Location.Y);

                    ChargeCancelButton.Text = "Close";
                }
            }

            SetClientSizeCore(LoadDataGroupBox.Location.X + LoadDataGroupBox.Width + 10, ChargeCancelButton.Location.Y + ChargeCancelButton.Height + 20);

            m_dOriginalCharge = m_Charge.PowderWeight;

            //----------------------------------------------------------------------------*
            // Set Control Event Handlers
            //----------------------------------------------------------------------------*

            ChargeTestListView.ListViewItemSorter    = new cListViewChargeTestComparer(m_DataFiles.Preferences.ChargeTestSortColumn, m_DataFiles.Preferences.ChargeTestSortOrder);
            ChargeTestListView.ColumnWidthChanged   += OnChargeTestListViewColumnWidthChanged;
            ChargeTestListView.SelectedIndexChanged += OnTestSelected;
            ChargeTestListView.ColumnWidthChanged   += OnChargeTestListViewColumnWidthChanged;

            if (!m_fViewOnly)
            {
                PowderWeightTextBox.TextChanged += OnPowderWeightChanged;
                FillRatioTextBox.TextChanged    += OnFillRatioChanged;

                AddChargeTestButton.Click    += OnAddChargeTest;
                EditChargeTestButton.Click   += OnEditChargeTest;
                RemoveChargeTestButton.Click += OnRemoveChargeTest;

                FavoriteRadioButton.Click += OnFavoriteClicked;
                RejectRadioButton.Click   += OnRejectClicked;

                PowderWeightTextBox.ReadOnly = false;
                FillRatioTextBox.ReadOnly    = false;

                AddChargeTestButton.Enabled    = true;
                EditChargeTestButton.Enabled   = true;
                RemoveChargeTestButton.Enabled = true;
            }
            else
            {
                PowderWeightTextBox.ReadOnly = true;
                FillRatioTextBox.ReadOnly    = true;

                AddChargeTestButton.Enabled    = false;
                EditChargeTestButton.Enabled   = false;
                RemoveChargeTestButton.Enabled = false;
            }

            //----------------------------------------------------------------------------*
            // Set Column Headers
            //----------------------------------------------------------------------------*

            ChargeTestListView.Columns[1].Text += String.Format(" ({0})", cDataFiles.MetricString(cDataFiles.eDataType.Firearm));
            ChargeTestListView.Columns[3].Text += String.Format(" ({0})", cDataFiles.MetricString(cDataFiles.eDataType.Velocity));
            ChargeTestListView.Columns[5].Text += String.Format(" ({0})", cDataFiles.MetricString(cDataFiles.eDataType.GroupSize));
            ChargeTestListView.Columns[6].Text += String.Format(" ({0})", cDataFiles.MetricString(cDataFiles.eDataType.Range));

            //----------------------------------------------------------------------------*
            // Fill in load data
            //----------------------------------------------------------------------------*

            FirearmTypeLabel.Text = cFirearm.FirearmTypeString(m_Load.FirearmType);

            if (m_Load != null)
            {
                if (m_Load.Caliber != null)
                {
                    CaliberLabel.Text = m_Load.Caliber.ToString();
                }

                if (m_Load.Bullet != null)
                {
                    BulletLabel.Text = m_Load.Bullet.ToString();
                }

                if (m_Load.Powder != null)
                {
                    PowderLabel.Text = m_Load.Powder.ToString();
                }

                if (m_Load.Primer != null)
                {
                    PrimerLabel.Text = m_Load.Primer.ToString();
                }

                if (m_Load.Case != null)
                {
                    CaseLabel.Text = m_Load.Case.ToString();
                }
            }

            SetStaticToolTips();

            SetInputParameters();

            PopulateChargeData();

            if (!m_fViewOnly)
            {
                PowderWeightTextBox.Focus();
            }
            else
            {
                ChargeCancelButton.Focus();
            }

            UpdateButtons();

            m_fInitialized = true;
        }
예제 #12
0
        //============================================================================*
        // OnDrawSubItem()
        //============================================================================*

        protected override void OnDrawSubItem(DrawListViewSubItemEventArgs args)
        {
            if (args.ColumnIndex < 3)
            {
                args.DrawDefault = true;

                return;
            }

            cLoad       Load       = (cLoad)args.Item.Tag;
            cChargeList ChargeList = Load.ChargeList;
            cCharge     Charge     = ChargeList[args.ColumnIndex - 3];

            Color StartColor = cm_StartColor;
            Color EndColor   = cm_EndColor;

            if (args.ColumnIndex == 3)
            {
                if (ChargeList.Count > 1)
                {
                    EndColor = cm_MidColor;
                }
            }
            else
            {
                StartColor = cm_MidColor;

                if (ChargeList.Count > args.ColumnIndex - 2)
                {
                    EndColor = cm_MidColor;
                }
            }

            LinearGradientBrush brush = new LinearGradientBrush(args.Bounds, StartColor, EndColor, LinearGradientMode.Horizontal);

            args.Graphics.FillRectangle(brush, args.Bounds);

            SizeF TextSize = args.Graphics.MeasureString(args.SubItem.Text, SystemFonts.DefaultFont, args.Bounds.Width);

            float x = args.Bounds.Left + (args.Bounds.Width / 2) - (TextSize.Width / 2) - (Charge.Favorite ? (Properties.Resources.Favorite.Width / 2) : 0);
            float y = args.Bounds.Top + (args.Bounds.Height / 2) - (TextSize.Height / 2);

            if (StartColor == cm_StartColor && EndColor == cm_MidColor)
            {
                x = args.Bounds.Left;
            }

            if (StartColor == cm_MidColor && EndColor == cm_EndColor)
            {
                x = args.Bounds.Left + args.Bounds.Width - TextSize.Width;

                if (Charge.Favorite && EndColor != cm_EndColor)
                {
                    x -= Properties.Resources.Favorite.Width;
                }

                if (Charge.Reject && EndColor != cm_EndColor)
                {
                    x -= Properties.Resources.Reject.Width;
                }
            }

            Brush ItemBrush = SystemBrushes.WindowText;

            if (StartColor == cm_StartColor || EndColor == cm_EndColor)
            {
                ItemBrush = SystemBrushes.HighlightText;
            }

            Font TextFont;

            if (Charge.Reject)
            {
                TextFont = new Font(SystemFonts.DefaultFont, FontStyle.Strikeout);
            }
            else
            {
                if (Charge.Favorite)
                {
                    TextFont = new Font(SystemFonts.DefaultFont, FontStyle.Bold);
                }
                else
                {
                    TextFont = new Font(SystemFonts.DefaultFont, FontStyle.Regular);
                }
            }

            args.Graphics.DrawString(args.SubItem.Text, TextFont, ItemBrush, x, y);

            if (Charge.Favorite)
            {
                Bitmap FavoriteBitmap = Properties.Resources.Favorite;
                FavoriteBitmap.MakeTransparent(Color.White);

                if (EndColor == cm_EndColor)
                {
                    args.Graphics.DrawImage(FavoriteBitmap, x - FavoriteBitmap.Width, y, FavoriteBitmap.Width, FavoriteBitmap.Height);
                }
                else
                {
                    args.Graphics.DrawImage(FavoriteBitmap, x + TextSize.Width, y, FavoriteBitmap.Width, FavoriteBitmap.Height);
                }
            }

            if (Charge.Reject)
            {
                Bitmap RejectBitmap = Properties.Resources.Reject;
                RejectBitmap.MakeTransparent(Color.White);

                if (EndColor == cm_EndColor)
                {
                    args.Graphics.DrawImage(RejectBitmap, x - RejectBitmap.Width, y, RejectBitmap.Width, RejectBitmap.Height);
                }
                else
                {
                    args.Graphics.DrawImage(RejectBitmap, x + TextSize.Width, y, RejectBitmap.Width, RejectBitmap.Height);
                }
            }
        }
        //============================================================================*
        // Compare()
        //============================================================================*

        public override int Compare(Object Object1, Object Object2)
        {
            if (Object1 == null)
            {
                if (Object2 == null)
                {
                    return(0);
                }
                else
                {
                    return(-1);
                }
            }
            else
            {
                if (Object2 == null)
                {
                    return(1);
                }
            }

            cCharge Charge1 = (cCharge)(Object1 as ListViewItem).Tag;
            cCharge Charge2 = (cCharge)(Object2 as ListViewItem).Tag;

            if (Charge1 == null)
            {
                if (Charge2 == null)
                {
                    return(0);
                }
                else
                {
                    return(-1);
                }
            }
            else
            {
                if (Charge2 == null)
                {
                    return(1);
                }
            }

            //----------------------------------------------------------------------------*
            // Compare the SortColumns
            //----------------------------------------------------------------------------*

            bool fSpecial = false;
            int  rc       = 0;

            switch (SortColumn)
            {
            //----------------------------------------------------------------------------*
            // Powder Weight
            //----------------------------------------------------------------------------*

            case 0:
                rc = Charge1.PowderWeight.CompareTo(Charge2.PowderWeight);

                fSpecial = true;

                break;

            //----------------------------------------------------------------------------*
            // # Tests
            //----------------------------------------------------------------------------*

            case 1:
                rc = Charge1.TestList.Count.CompareTo(Charge2.TestList.Count);

                fSpecial = true;

                break;

            //----------------------------------------------------------------------------*
            // Fill Ratio
            //----------------------------------------------------------------------------*

            case 2:
                rc = Charge1.FillRatio.CompareTo(Charge2.FillRatio);

                fSpecial = true;

                break;

            //----------------------------------------------------------------------------*
            // Favorite
            //----------------------------------------------------------------------------*

            case 3:
                rc = Charge1.Favorite.CompareTo(Charge2.Favorite);

                fSpecial = true;

                break;

            //----------------------------------------------------------------------------*
            // Reject
            //----------------------------------------------------------------------------*

            case 4:
                rc = Charge1.Reject.CompareTo(Charge2.Reject);

                fSpecial = true;

                break;
            }

            if (fSpecial)
            {
                if (SortingOrder == SortOrder.Descending)
                {
                    return(0 - rc);
                }

                return(rc);
            }

            return(base.Compare(Object1, Object2));
        }
        //============================================================================*
        // OnDrawSubItem()
        //============================================================================*

        protected override void OnDrawSubItem(DrawListViewSubItemEventArgs args)
        {
            //----------------------------------------------------------------------------*
            // If it's not a charge item, just draw it normally
            //----------------------------------------------------------------------------*

            if (args.ColumnIndex < 5)
            {
                base.OnDrawSubItem(args);

                return;
            }

            //----------------------------------------------------------------------------*
            // Get the load and charge data
            //----------------------------------------------------------------------------*

            cLoad   Load   = (cLoad)args.Item.Tag;
            cCharge Charge = Load.ChargeList[args.ColumnIndex - 5];

            //----------------------------------------------------------------------------*
            // Set up the background color for the item
            //----------------------------------------------------------------------------*

            Color StartColor = cm_StartColor;
            Color EndColor   = cm_EndColor;

            if (args.ColumnIndex == 5)
            {
                if (Load.ChargeList.Count > 1)
                {
                    EndColor = cm_MidColor;
                }
            }
            else
            {
                StartColor = cm_MidColor;

                if (Load.ChargeList.Count > args.ColumnIndex - 4)
                {
                    EndColor = cm_MidColor;
                }
            }

            LinearGradientBrush brush = new LinearGradientBrush(args.Bounds, StartColor, EndColor, LinearGradientMode.Horizontal);

            args.Graphics.FillRectangle(brush, args.Bounds);

            //----------------------------------------------------------------------------*
            // Set up the font for the item
            //----------------------------------------------------------------------------*

            Font ChargeFont = SystemFonts.DefaultFont;

            SizeF TextSize = args.Graphics.MeasureString(args.SubItem.Text, ChargeFont, args.Bounds.Width);

            float x = args.Bounds.Left + (args.Bounds.Width / 2) - (TextSize.Width / 2) - (Charge.Favorite ? (Properties.Resources.Favorite.Width / 2) : 0);
            float y = args.Bounds.Top + (args.Bounds.Height / 2) - (TextSize.Height / 2);

            if (StartColor == cm_StartColor && EndColor == cm_MidColor)
            {
                x = args.Bounds.Left;
            }

            if (StartColor == cm_MidColor && EndColor == cm_EndColor)
            {
                x = args.Bounds.Left + args.Bounds.Width - TextSize.Width;

                if (Charge.Favorite && EndColor != cm_EndColor)
                {
                    x -= Properties.Resources.Favorite.Width;
                }

                if (Charge.Reject && EndColor != cm_EndColor)
                {
                    x -= Properties.Resources.Reject.Width;
                }
            }

            Brush ItemBrush = SystemBrushes.WindowText;

            if (StartColor == cm_StartColor || EndColor == cm_EndColor)
            {
                ItemBrush = SystemBrushes.HighlightText;
            }

            //----------------------------------------------------------------------------*
            // See if this charge has been used in a batch
            //----------------------------------------------------------------------------*

            bool fUsed = false;

            foreach (cBatch Batch in m_DataFiles.BatchList)
            {
                if (Batch.Load.CompareTo(Load) == 0)
                {
                    if (Batch.PowderWeight == Charge.PowderWeight)
                    {
                        fUsed = true;

                        break;
                    }
                }
            }

            //----------------------------------------------------------------------------*
            // Make any modifications needed to the font
            //----------------------------------------------------------------------------*

            Font TextFont;

            if (Charge.Reject)
            {
                TextFont = new Font(SystemFonts.DefaultFont, FontStyle.Strikeout | (fUsed ? FontStyle.Bold : FontStyle.Strikeout));
            }
            else
            {
                if (Charge.Favorite)
                {
                    TextFont = new Font(SystemFonts.DefaultFont, FontStyle.Bold);
                }
                else
                {
                    TextFont = new Font(SystemFonts.DefaultFont, (fUsed) ? FontStyle.Bold : FontStyle.Regular);
                }
            }

            args.Graphics.DrawString(args.SubItem.Text, TextFont, ItemBrush, x, y);

            if (Charge.Favorite)
            {
                Bitmap FavoriteBitmap = Properties.Resources.Favorite;
                FavoriteBitmap.MakeTransparent(Color.White);

                if (EndColor == cm_EndColor)
                {
                    args.Graphics.DrawImage(FavoriteBitmap, x - FavoriteBitmap.Width, y, FavoriteBitmap.Width, FavoriteBitmap.Height);
                }
                else
                {
                    args.Graphics.DrawImage(FavoriteBitmap, x + TextSize.Width, y, FavoriteBitmap.Width, FavoriteBitmap.Height);
                }
            }

            if (Charge.Reject)
            {
                Bitmap RejectBitmap = Properties.Resources.Reject;
                RejectBitmap.MakeTransparent(Color.White);

                if (EndColor == cm_EndColor)
                {
                    args.Graphics.DrawImage(RejectBitmap, x - RejectBitmap.Width, y, RejectBitmap.Width, RejectBitmap.Height);
                }
                else
                {
                    args.Graphics.DrawImage(RejectBitmap, x + TextSize.Width, y, RejectBitmap.Width, RejectBitmap.Height);
                }
            }
        }